@t2000/sdk 0.17.0 → 0.17.2

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.
@@ -278,7 +278,9 @@ function addCollectFeeToTx(tx, paymentCoin, operation) {
278
278
  var RATE_DECIMALS = 27;
279
279
  var LTV_DECIMALS = 27;
280
280
  var MIN_HEALTH_FACTOR = 1.5;
281
- var WITHDRAW_DUST_BUFFER = 1e-3;
281
+ function withdrawDustBuffer(decimals) {
282
+ return 1e3 / 10 ** decimals;
283
+ }
282
284
  var CLOCK = "0x06";
283
285
  var SUI_SYSTEM_STATE = "0x05";
284
286
  var NAVI_BALANCE_DECIMALS = 9;
@@ -401,6 +403,16 @@ function rateToApy(rawRate) {
401
403
  if (!rawRate || rawRate === "0") return 0;
402
404
  return Number(BigInt(rawRate)) / 10 ** RATE_DECIMALS * 100;
403
405
  }
406
+ function poolSaveApy(pool) {
407
+ const incentive = parseFloat(pool.supplyIncentiveApyInfo?.apy ?? "0");
408
+ if (incentive > 0) return incentive;
409
+ return rateToApy(pool.currentSupplyRate);
410
+ }
411
+ function poolBorrowApy(pool) {
412
+ const incentive = parseFloat(pool.borrowIncentiveApyInfo?.apy ?? "0");
413
+ if (incentive > 0) return incentive;
414
+ return rateToApy(pool.currentBorrowRate);
415
+ }
404
416
  function parseLtv(rawLtv) {
405
417
  if (!rawLtv || rawLtv === "0") return 0.75;
406
418
  return Number(BigInt(rawLtv)) / 10 ** LTV_DECIMALS;
@@ -510,7 +522,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
510
522
  ]);
511
523
  const assetState = states.find((s) => s.assetId === pool.id);
512
524
  const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex, pool) : 0;
513
- const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
525
+ const effectiveAmount = Math.min(amount, Math.max(0, deposited - withdrawDustBuffer(assetInfo.decimals)));
514
526
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
515
527
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
516
528
  if (rawAmount <= 0) {
@@ -553,7 +565,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
553
565
  ]);
554
566
  const assetState = states.find((s) => s.assetId === pool.id);
555
567
  const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex, pool) : 0;
556
- const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
568
+ const effectiveAmount = Math.min(amount, Math.max(0, deposited - withdrawDustBuffer(assetInfo.decimals)));
557
569
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
558
570
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
559
571
  if (rawAmount <= 0) {
@@ -791,10 +803,10 @@ async function getRates(client) {
791
803
  const targetType = SUPPORTED_ASSETS[asset].type;
792
804
  const pool = pools.find((p) => matchesCoinType(p.suiCoinType || p.coinType || "", targetType));
793
805
  if (!pool) continue;
794
- let saveApy = rateToApy(pool.currentSupplyRate);
795
- let borrowApy = rateToApy(pool.currentBorrowRate);
796
- if (saveApy <= 0 || saveApy > 100) saveApy = 0;
797
- if (borrowApy <= 0 || borrowApy > 100) borrowApy = 0;
806
+ let saveApy = poolSaveApy(pool);
807
+ let borrowApy = poolBorrowApy(pool);
808
+ if (saveApy <= 0 || saveApy > 200) saveApy = 0;
809
+ if (borrowApy <= 0 || borrowApy > 200) borrowApy = 0;
798
810
  result[asset] = { saveApy, borrowApy };
799
811
  }
800
812
  if (!result.USDC) result.USDC = { saveApy: 4, borrowApy: 6 };
@@ -819,7 +831,7 @@ async function getPositions(client, addressOrKeypair) {
819
831
  asset: symbol,
820
832
  type: "save",
821
833
  amount: supplyBal,
822
- apy: rateToApy(pool.currentSupplyRate)
834
+ apy: poolSaveApy(pool)
823
835
  });
824
836
  }
825
837
  if (borrowBal > 1e-4) {
@@ -828,7 +840,7 @@ async function getPositions(client, addressOrKeypair) {
828
840
  asset: symbol,
829
841
  type: "borrow",
830
842
  amount: borrowBal,
831
- apy: rateToApy(pool.currentBorrowRate)
843
+ apy: poolBorrowApy(pool)
832
844
  });
833
845
  }
834
846
  }