@t2000/sdk 0.17.0 → 0.17.1

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.
package/dist/index.js CHANGED
@@ -589,7 +589,9 @@ SUPPORTED_ASSETS.USDC.type;
589
589
  var RATE_DECIMALS = 27;
590
590
  var LTV_DECIMALS = 27;
591
591
  var MIN_HEALTH_FACTOR = 1.5;
592
- var WITHDRAW_DUST_BUFFER = 1e-3;
592
+ function withdrawDustBuffer(decimals) {
593
+ return 1e3 / 10 ** decimals;
594
+ }
593
595
  var CLOCK = "0x06";
594
596
  var SUI_SYSTEM_STATE = "0x05";
595
597
  var NAVI_BALANCE_DECIMALS = 9;
@@ -712,6 +714,16 @@ function rateToApy(rawRate) {
712
714
  if (!rawRate || rawRate === "0") return 0;
713
715
  return Number(BigInt(rawRate)) / 10 ** RATE_DECIMALS * 100;
714
716
  }
717
+ function poolSaveApy(pool) {
718
+ const incentive = parseFloat(pool.supplyIncentiveApyInfo?.apy ?? "0");
719
+ if (incentive > 0) return incentive;
720
+ return rateToApy(pool.currentSupplyRate);
721
+ }
722
+ function poolBorrowApy(pool) {
723
+ const incentive = parseFloat(pool.borrowIncentiveApyInfo?.apy ?? "0");
724
+ if (incentive > 0) return incentive;
725
+ return rateToApy(pool.currentBorrowRate);
726
+ }
715
727
  function parseLtv(rawLtv) {
716
728
  if (!rawLtv || rawLtv === "0") return 0.75;
717
729
  return Number(BigInt(rawLtv)) / 10 ** LTV_DECIMALS;
@@ -821,7 +833,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
821
833
  ]);
822
834
  const assetState = states.find((s) => s.assetId === pool.id);
823
835
  const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex, pool) : 0;
824
- const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
836
+ const effectiveAmount = Math.min(amount, Math.max(0, deposited - withdrawDustBuffer(assetInfo.decimals)));
825
837
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
826
838
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
827
839
  if (rawAmount <= 0) {
@@ -864,7 +876,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
864
876
  ]);
865
877
  const assetState = states.find((s) => s.assetId === pool.id);
866
878
  const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex, pool) : 0;
867
- const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
879
+ const effectiveAmount = Math.min(amount, Math.max(0, deposited - withdrawDustBuffer(assetInfo.decimals)));
868
880
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
869
881
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
870
882
  if (rawAmount <= 0) {
@@ -1102,10 +1114,10 @@ async function getRates(client) {
1102
1114
  const targetType = SUPPORTED_ASSETS[asset].type;
1103
1115
  const pool = pools.find((p) => matchesCoinType(p.suiCoinType || p.coinType || "", targetType));
1104
1116
  if (!pool) continue;
1105
- let saveApy = rateToApy(pool.currentSupplyRate);
1106
- let borrowApy = rateToApy(pool.currentBorrowRate);
1107
- if (saveApy <= 0 || saveApy > 100) saveApy = 0;
1108
- if (borrowApy <= 0 || borrowApy > 100) borrowApy = 0;
1117
+ let saveApy = poolSaveApy(pool);
1118
+ let borrowApy = poolBorrowApy(pool);
1119
+ if (saveApy <= 0 || saveApy > 200) saveApy = 0;
1120
+ if (borrowApy <= 0 || borrowApy > 200) borrowApy = 0;
1109
1121
  result[asset] = { saveApy, borrowApy };
1110
1122
  }
1111
1123
  if (!result.USDC) result.USDC = { saveApy: 4, borrowApy: 6 };
@@ -1130,7 +1142,7 @@ async function getPositions(client, addressOrKeypair) {
1130
1142
  asset: symbol,
1131
1143
  type: "save",
1132
1144
  amount: supplyBal,
1133
- apy: rateToApy(pool.currentSupplyRate)
1145
+ apy: poolSaveApy(pool)
1134
1146
  });
1135
1147
  }
1136
1148
  if (borrowBal > 1e-4) {
@@ -1139,7 +1151,7 @@ async function getPositions(client, addressOrKeypair) {
1139
1151
  asset: symbol,
1140
1152
  type: "borrow",
1141
1153
  amount: borrowBal,
1142
- apy: rateToApy(pool.currentBorrowRate)
1154
+ apy: poolBorrowApy(pool)
1143
1155
  });
1144
1156
  }
1145
1157
  }