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