@t2000/sdk 0.16.30 → 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/README.md +4 -1
- package/dist/adapters/index.cjs +32 -13
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +32 -13
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +46 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +46 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/adapters/index.js
CHANGED
|
@@ -49,6 +49,12 @@ var SUPPORTED_ASSETS = {
|
|
|
49
49
|
decimals: 8,
|
|
50
50
|
symbol: "ETH",
|
|
51
51
|
displayName: "Ethereum"
|
|
52
|
+
},
|
|
53
|
+
GOLD: {
|
|
54
|
+
type: "0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM",
|
|
55
|
+
decimals: 9,
|
|
56
|
+
symbol: "GOLD",
|
|
57
|
+
displayName: "Gold"
|
|
52
58
|
}
|
|
53
59
|
};
|
|
54
60
|
var STABLE_ASSETS = ["USDC", "USDT", "USDe", "USDsui"];
|
|
@@ -61,7 +67,8 @@ var CETUS_PACKAGE = "0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35
|
|
|
61
67
|
var INVESTMENT_ASSETS = {
|
|
62
68
|
SUI: SUPPORTED_ASSETS.SUI,
|
|
63
69
|
BTC: SUPPORTED_ASSETS.BTC,
|
|
64
|
-
ETH: SUPPORTED_ASSETS.ETH
|
|
70
|
+
ETH: SUPPORTED_ASSETS.ETH,
|
|
71
|
+
GOLD: SUPPORTED_ASSETS.GOLD
|
|
65
72
|
};
|
|
66
73
|
var SENTINEL = {
|
|
67
74
|
PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7"};
|
|
@@ -271,7 +278,9 @@ function addCollectFeeToTx(tx, paymentCoin, operation) {
|
|
|
271
278
|
var RATE_DECIMALS = 27;
|
|
272
279
|
var LTV_DECIMALS = 27;
|
|
273
280
|
var MIN_HEALTH_FACTOR = 1.5;
|
|
274
|
-
|
|
281
|
+
function withdrawDustBuffer(decimals) {
|
|
282
|
+
return 1e3 / 10 ** decimals;
|
|
283
|
+
}
|
|
275
284
|
var CLOCK = "0x06";
|
|
276
285
|
var SUI_SYSTEM_STATE = "0x05";
|
|
277
286
|
var NAVI_BALANCE_DECIMALS = 9;
|
|
@@ -394,6 +403,16 @@ function rateToApy(rawRate) {
|
|
|
394
403
|
if (!rawRate || rawRate === "0") return 0;
|
|
395
404
|
return Number(BigInt(rawRate)) / 10 ** RATE_DECIMALS * 100;
|
|
396
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
|
+
}
|
|
397
416
|
function parseLtv(rawLtv) {
|
|
398
417
|
if (!rawLtv || rawLtv === "0") return 0.75;
|
|
399
418
|
return Number(BigInt(rawLtv)) / 10 ** LTV_DECIMALS;
|
|
@@ -503,7 +522,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
503
522
|
]);
|
|
504
523
|
const assetState = states.find((s) => s.assetId === pool.id);
|
|
505
524
|
const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex, pool) : 0;
|
|
506
|
-
const effectiveAmount = Math.min(amount, Math.max(0, deposited -
|
|
525
|
+
const effectiveAmount = Math.min(amount, Math.max(0, deposited - withdrawDustBuffer(assetInfo.decimals)));
|
|
507
526
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
508
527
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
509
528
|
if (rawAmount <= 0) {
|
|
@@ -546,7 +565,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
546
565
|
]);
|
|
547
566
|
const assetState = states.find((s) => s.assetId === pool.id);
|
|
548
567
|
const deposited = assetState ? compoundBalance(assetState.supplyBalance, pool.currentSupplyIndex, pool) : 0;
|
|
549
|
-
const effectiveAmount = Math.min(amount, Math.max(0, deposited -
|
|
568
|
+
const effectiveAmount = Math.min(amount, Math.max(0, deposited - withdrawDustBuffer(assetInfo.decimals)));
|
|
550
569
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
551
570
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
552
571
|
if (rawAmount <= 0) {
|
|
@@ -775,7 +794,7 @@ async function getHealthFactor(client, addressOrKeypair) {
|
|
|
775
794
|
liquidationThreshold: liqThreshold
|
|
776
795
|
};
|
|
777
796
|
}
|
|
778
|
-
var NAVI_SUPPORTED_ASSETS = [...STABLE_ASSETS, "SUI", "ETH"];
|
|
797
|
+
var NAVI_SUPPORTED_ASSETS = [...STABLE_ASSETS, "SUI", "ETH", "GOLD"];
|
|
779
798
|
async function getRates(client) {
|
|
780
799
|
try {
|
|
781
800
|
const pools = await getPools();
|
|
@@ -784,10 +803,10 @@ async function getRates(client) {
|
|
|
784
803
|
const targetType = SUPPORTED_ASSETS[asset].type;
|
|
785
804
|
const pool = pools.find((p) => matchesCoinType(p.suiCoinType || p.coinType || "", targetType));
|
|
786
805
|
if (!pool) continue;
|
|
787
|
-
let saveApy =
|
|
788
|
-
let borrowApy =
|
|
789
|
-
if (saveApy <= 0 || saveApy >
|
|
790
|
-
if (borrowApy <= 0 || borrowApy >
|
|
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;
|
|
791
810
|
result[asset] = { saveApy, borrowApy };
|
|
792
811
|
}
|
|
793
812
|
if (!result.USDC) result.USDC = { saveApy: 4, borrowApy: 6 };
|
|
@@ -812,7 +831,7 @@ async function getPositions(client, addressOrKeypair) {
|
|
|
812
831
|
asset: symbol,
|
|
813
832
|
type: "save",
|
|
814
833
|
amount: supplyBal,
|
|
815
|
-
apy:
|
|
834
|
+
apy: poolSaveApy(pool)
|
|
816
835
|
});
|
|
817
836
|
}
|
|
818
837
|
if (borrowBal > 1e-4) {
|
|
@@ -821,7 +840,7 @@ async function getPositions(client, addressOrKeypair) {
|
|
|
821
840
|
asset: symbol,
|
|
822
841
|
type: "borrow",
|
|
823
842
|
amount: borrowBal,
|
|
824
|
-
apy:
|
|
843
|
+
apy: poolBorrowApy(pool)
|
|
825
844
|
});
|
|
826
845
|
}
|
|
827
846
|
}
|
|
@@ -869,7 +888,7 @@ var NaviAdapter = class {
|
|
|
869
888
|
name = "NAVI Protocol";
|
|
870
889
|
version = "1.0.0";
|
|
871
890
|
capabilities = ["save", "withdraw", "borrow", "repay"];
|
|
872
|
-
supportedAssets = [...STABLE_ASSETS, "SUI", "ETH"];
|
|
891
|
+
supportedAssets = [...STABLE_ASSETS, "SUI", "ETH", "GOLD"];
|
|
873
892
|
supportsSameAssetBorrow = true;
|
|
874
893
|
client;
|
|
875
894
|
async init(client) {
|
|
@@ -1275,7 +1294,7 @@ var SuilendAdapter = class {
|
|
|
1275
1294
|
name = "Suilend";
|
|
1276
1295
|
version = "2.0.0";
|
|
1277
1296
|
capabilities = ["save", "withdraw", "borrow", "repay"];
|
|
1278
|
-
supportedAssets = [...STABLE_ASSETS, "SUI", "ETH", "BTC"];
|
|
1297
|
+
supportedAssets = [...STABLE_ASSETS, "SUI", "ETH", "BTC", "GOLD"];
|
|
1279
1298
|
supportsSameAssetBorrow = false;
|
|
1280
1299
|
client;
|
|
1281
1300
|
publishedAt = null;
|