@t2000/sdk 0.9.8 → 0.10.0
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 +10 -29
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +10 -29
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +15 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -11,7 +11,6 @@ var promises = require('fs/promises');
|
|
|
11
11
|
var path = require('path');
|
|
12
12
|
var os = require('os');
|
|
13
13
|
var bcs = require('@mysten/sui/bcs');
|
|
14
|
-
var pythSuiJs = require('@pythnetwork/pyth-sui-js');
|
|
15
14
|
var aggregatorSdk = require('@cetusprotocol/aggregator-sdk');
|
|
16
15
|
|
|
17
16
|
// src/t2000.ts
|
|
@@ -128,7 +127,7 @@ function mapMoveAbortCode(code) {
|
|
|
128
127
|
10: "Already at current version",
|
|
129
128
|
// NAVI Protocol abort codes
|
|
130
129
|
1502: "Oracle price is stale \u2014 try again in a moment",
|
|
131
|
-
1503:
|
|
130
|
+
1503: 'Withdrawal amount is invalid (zero or dust) \u2014 try a specific amount instead of "all"',
|
|
132
131
|
1600: "Health factor too low \u2014 withdrawal would risk liquidation",
|
|
133
132
|
1605: "Asset borrowing is disabled or at capacity on this protocol",
|
|
134
133
|
// Cetus DEX abort codes
|
|
@@ -511,7 +510,6 @@ var NAVI_BALANCE_DECIMALS = 9;
|
|
|
511
510
|
var CONFIG_API = "https://open-api.naviprotocol.io/api/navi/config?env=prod";
|
|
512
511
|
var POOLS_API = "https://open-api.naviprotocol.io/api/navi/pools?env=prod";
|
|
513
512
|
var PACKAGE_API = "https://open-api.naviprotocol.io/api/package";
|
|
514
|
-
var PYTH_HERMES_URL = "https://hermes.pyth.network/";
|
|
515
513
|
var packageCache = null;
|
|
516
514
|
function toBigInt(v) {
|
|
517
515
|
if (typeof v === "bigint") return v;
|
|
@@ -606,31 +604,12 @@ function addOracleUpdate(tx, config, pool) {
|
|
|
606
604
|
]
|
|
607
605
|
});
|
|
608
606
|
}
|
|
609
|
-
|
|
607
|
+
function refreshStableOracles(tx, config, pools) {
|
|
610
608
|
const stableTypes = STABLE_ASSETS.map((a) => SUPPORTED_ASSETS[a].type);
|
|
611
609
|
const stablePools = pools.filter((p) => {
|
|
612
610
|
const ct = p.suiCoinType || p.coinType || "";
|
|
613
611
|
return stableTypes.some((t) => matchesCoinType(ct, t));
|
|
614
612
|
});
|
|
615
|
-
const feeds = (config.oracle.feeds ?? []).filter(
|
|
616
|
-
(f2) => stablePools.some((p) => p.id === f2.assetId)
|
|
617
|
-
);
|
|
618
|
-
if (feeds.length === 0) return;
|
|
619
|
-
const pythFeedIds = feeds.map((f2) => f2.pythPriceFeedId).filter(Boolean);
|
|
620
|
-
if (pythFeedIds.length > 0 && config.oracle.pythStateId && config.oracle.wormholeStateId) {
|
|
621
|
-
try {
|
|
622
|
-
const connection = new pythSuiJs.SuiPriceServiceConnection(PYTH_HERMES_URL);
|
|
623
|
-
const priceUpdateData = await connection.getPriceFeedsUpdateData(pythFeedIds);
|
|
624
|
-
const pythClient = new pythSuiJs.SuiPythClient(
|
|
625
|
-
client,
|
|
626
|
-
config.oracle.pythStateId,
|
|
627
|
-
config.oracle.wormholeStateId
|
|
628
|
-
);
|
|
629
|
-
await pythClient.updatePriceFeeds(tx, priceUpdateData, pythFeedIds);
|
|
630
|
-
} catch (err) {
|
|
631
|
-
console.error("[t2000] Pyth oracle push failed, falling back to cached prices:", err.message ?? err);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
613
|
for (const pool of stablePools) {
|
|
635
614
|
addOracleUpdate(tx, config, pool);
|
|
636
615
|
}
|
|
@@ -747,12 +726,11 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
747
726
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
748
727
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
749
728
|
if (rawAmount <= 0) {
|
|
750
|
-
throw new T2000Error("INVALID_AMOUNT", `Withdrawal amount
|
|
729
|
+
throw new T2000Error("INVALID_AMOUNT", `Withdrawal amount rounds to zero \u2014 balance is dust`);
|
|
751
730
|
}
|
|
752
|
-
console.error(`[t2000] withdraw: asset=${asset} poolId=${pool.id} amount=${amount} deposited=${deposited} effective=${effectiveAmount} raw=${rawAmount} supplyBal=${assetState?.supplyBalance} index=${pool.currentSupplyIndex}`);
|
|
753
731
|
const tx = new transactions.Transaction();
|
|
754
732
|
tx.setSender(address);
|
|
755
|
-
|
|
733
|
+
refreshStableOracles(tx, config, pools);
|
|
756
734
|
const [balance] = tx.moveCall({
|
|
757
735
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
758
736
|
arguments: [
|
|
@@ -791,10 +769,13 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
791
769
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
792
770
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
793
771
|
if (rawAmount <= 0) {
|
|
794
|
-
|
|
772
|
+
const [coin2] = tx.moveCall({
|
|
773
|
+
target: "0x2::coin::zero",
|
|
774
|
+
typeArguments: [pool.suiCoinType]
|
|
775
|
+
});
|
|
776
|
+
return { coin: coin2, effectiveAmount: 0 };
|
|
795
777
|
}
|
|
796
|
-
|
|
797
|
-
await refreshStableOracles(tx, client, config, pools);
|
|
778
|
+
refreshStableOracles(tx, config, pools);
|
|
798
779
|
const [balance] = tx.moveCall({
|
|
799
780
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
800
781
|
arguments: [
|
|
@@ -882,7 +863,7 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
882
863
|
]);
|
|
883
864
|
const tx = new transactions.Transaction();
|
|
884
865
|
tx.setSender(address);
|
|
885
|
-
|
|
866
|
+
refreshStableOracles(tx, config, pools);
|
|
886
867
|
const [balance] = tx.moveCall({
|
|
887
868
|
target: `${config.package}::incentive_v3::borrow_v2`,
|
|
888
869
|
arguments: [
|
|
@@ -2885,7 +2866,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2885
2866
|
const withdrawable = [];
|
|
2886
2867
|
for (const pos of allPositions) {
|
|
2887
2868
|
for (const supply of pos.positions.supplies) {
|
|
2888
|
-
if (supply.amount >
|
|
2869
|
+
if (supply.amount > 0.01) {
|
|
2889
2870
|
withdrawable.push({ protocolId: pos.protocolId, asset: supply.asset, amount: supply.amount });
|
|
2890
2871
|
}
|
|
2891
2872
|
}
|
|
@@ -2898,8 +2879,9 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2898
2879
|
const adapter = this.registry.getLending(entry.protocolId);
|
|
2899
2880
|
if (!adapter) continue;
|
|
2900
2881
|
const maxResult = await adapter.maxWithdraw(this._address, entry.asset);
|
|
2901
|
-
|
|
2902
|
-
|
|
2882
|
+
const perAssetMax = Math.min(entry.amount, maxResult.maxAmount);
|
|
2883
|
+
if (perAssetMax > 0.01) {
|
|
2884
|
+
entries.push({ ...entry, maxAmount: perAssetMax, adapter });
|
|
2903
2885
|
}
|
|
2904
2886
|
}
|
|
2905
2887
|
if (entries.length === 0) {
|