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