@t2000/sdk 0.19.20 → 0.19.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- export { K as AdapterCapability, N as AdapterPositions, O as AdapterTxResult, U as CetusAdapter, X as HealthInfo, L as LendingAdapter, x as LendingRates, Z as NaviAdapter, _ as PerpsAdapter, a4 as ProtocolDescriptor, a5 as ProtocolRegistry, a8 as SuilendAdapter, f as SwapAdapter, a9 as SwapQuote, aa as allDescriptors, ab as cetusDescriptor, ae as naviDescriptor, ah as sentinelDescriptor, ak as suilendDescriptor } from '../index-DAxuyiS2.cjs';
1
+ export { K as AdapterCapability, N as AdapterPositions, O as AdapterTxResult, U as CetusAdapter, X as HealthInfo, L as LendingAdapter, x as LendingRates, Z as NaviAdapter, _ as PerpsAdapter, a4 as ProtocolDescriptor, a5 as ProtocolRegistry, a8 as SuilendAdapter, f as SwapAdapter, a9 as SwapQuote, aa as allDescriptors, ab as cetusDescriptor, ae as naviDescriptor, ah as sentinelDescriptor, ak as suilendDescriptor } from '../index-CRyFiIZm.cjs';
2
2
  import '@mysten/sui/transactions';
3
3
  import '@mysten/sui/jsonRpc';
@@ -1,3 +1,3 @@
1
- export { K as AdapterCapability, N as AdapterPositions, O as AdapterTxResult, U as CetusAdapter, X as HealthInfo, L as LendingAdapter, x as LendingRates, Z as NaviAdapter, _ as PerpsAdapter, a4 as ProtocolDescriptor, a5 as ProtocolRegistry, a8 as SuilendAdapter, f as SwapAdapter, a9 as SwapQuote, aa as allDescriptors, ab as cetusDescriptor, ae as naviDescriptor, ah as sentinelDescriptor, ak as suilendDescriptor } from '../index-DAxuyiS2.js';
1
+ export { K as AdapterCapability, N as AdapterPositions, O as AdapterTxResult, U as CetusAdapter, X as HealthInfo, L as LendingAdapter, x as LendingRates, Z as NaviAdapter, _ as PerpsAdapter, a4 as ProtocolDescriptor, a5 as ProtocolRegistry, a8 as SuilendAdapter, f as SwapAdapter, a9 as SwapQuote, aa as allDescriptors, ab as cetusDescriptor, ae as naviDescriptor, ah as sentinelDescriptor, ak as suilendDescriptor } from '../index-CRyFiIZm.js';
2
2
  import '@mysten/sui/transactions';
3
3
  import '@mysten/sui/jsonRpc';
@@ -292,6 +292,7 @@ function sdkOptions(client) {
292
292
  return { env: "prod", client, cacheTime: 0, disableCache: true };
293
293
  }
294
294
  async function refreshOracle(tx, client, address, options) {
295
+ if (options?.skipOracle) return;
295
296
  const origInfo = console.info;
296
297
  const origWarn = console.warn;
297
298
  console.info = (...args) => {
@@ -459,13 +460,14 @@ async function buildSaveTx(client, address, amount, options = {}) {
459
460
  const assetInfo = resolveAssetInfo(asset);
460
461
  const coins = await fetchCoins(client, address, assetInfo.type);
461
462
  if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins found`);
463
+ const totalBalance = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);
462
464
  const tx = new Transaction();
463
465
  tx.setSender(address);
464
466
  const coinObj = mergeCoins(tx, coins);
465
467
  if (options.collectFee) {
466
468
  addCollectFeeToTx(tx, coinObj, "save");
467
469
  }
468
- const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
470
+ const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
469
471
  try {
470
472
  await depositCoinPTB(tx, assetInfo.type, coinObj, {
471
473
  ...sdkOptions(client),
@@ -586,12 +588,16 @@ async function buildRepayTx(client, address, amount, options = {}) {
586
588
  const assetInfo = resolveAssetInfo(asset);
587
589
  const coins = await fetchCoins(client, address, assetInfo.type);
588
590
  if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with`);
591
+ const totalBalance = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);
589
592
  const tx = new Transaction();
590
593
  tx.setSender(address);
591
594
  const coinObj = mergeCoins(tx, coins);
592
- const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
595
+ const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
593
596
  const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
594
- await refreshOracle(tx, client, address, { skipPythUpdate: options.sponsored });
597
+ await refreshOracle(tx, client, address, {
598
+ skipPythUpdate: options.sponsored,
599
+ skipOracle: options.skipOracle
600
+ });
595
601
  try {
596
602
  await repayCoinPTB(tx, assetInfo.type, repayCoin, {
597
603
  ...sdkOptions(client),
@@ -744,7 +750,11 @@ var NaviAdapter = class {
744
750
  }
745
751
  async buildRepayTx(address, amount, asset, options) {
746
752
  const normalized = normalizeAsset(asset);
747
- const tx = await buildRepayTx(this.client, address, amount, { asset: normalized, sponsored: options?.sponsored });
753
+ const tx = await buildRepayTx(this.client, address, amount, {
754
+ asset: normalized,
755
+ sponsored: options?.sponsored,
756
+ skipOracle: options?.skipOracle
757
+ });
748
758
  return { tx };
749
759
  }
750
760
  async maxWithdraw(address, _asset) {
@@ -1378,16 +1388,23 @@ var SuilendAdapter = class {
1378
1388
  if (obligationOwnerCaps.length === 0 || obligations.length === 0) return [];
1379
1389
  const ob = obligations[0];
1380
1390
  const rewards = [];
1391
+ const WAD = 1e18;
1381
1392
  for (const dep of ob.deposits) {
1382
- for (const rw of dep.reserve.depositsPoolRewardManager.poolRewards) {
1393
+ const urm = dep.userRewardManager;
1394
+ for (const rw of dep.reserve.depositsPoolRewardManager?.poolRewards ?? []) {
1383
1395
  if (rw.endTimeMs <= Date.now()) continue;
1396
+ let claimableAmount = 0;
1397
+ const userReward = urm?.rewards?.[rw.rewardIndex];
1398
+ if (userReward?.earnedRewards) {
1399
+ claimableAmount = Number(BigInt(userReward.earnedRewards.value.toString())) / WAD / 10 ** rw.mintDecimals;
1400
+ }
1384
1401
  const symbol = rw.symbol || rw.coinType.split("::").pop() || "UNKNOWN";
1385
1402
  rewards.push({
1386
1403
  protocol: "suilend",
1387
1404
  asset: this.resolveSymbol(dep.coinType),
1388
1405
  coinType: rw.coinType,
1389
1406
  symbol,
1390
- amount: 0,
1407
+ amount: claimableAmount,
1391
1408
  estimatedValueUsd: 0
1392
1409
  });
1393
1410
  }