@t2000/sdk 0.9.7 → 0.9.9
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 +12 -1
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +12 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +17 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -126,7 +126,7 @@ function mapMoveAbortCode(code) {
|
|
|
126
126
|
10: "Already at current version",
|
|
127
127
|
// NAVI Protocol abort codes
|
|
128
128
|
1502: "Oracle price is stale \u2014 try again in a moment",
|
|
129
|
-
1503:
|
|
129
|
+
1503: 'Withdrawal amount is invalid (zero or dust) \u2014 try a specific amount instead of "all"',
|
|
130
130
|
1600: "Health factor too low \u2014 withdrawal would risk liquidation",
|
|
131
131
|
1605: "Asset borrowing is disabled or at capacity on this protocol",
|
|
132
132
|
// Cetus DEX abort codes
|
|
@@ -625,7 +625,8 @@ async function refreshStableOracles(tx, client, config, pools) {
|
|
|
625
625
|
config.oracle.wormholeStateId
|
|
626
626
|
);
|
|
627
627
|
await pythClient.updatePriceFeeds(tx, priceUpdateData, pythFeedIds);
|
|
628
|
-
} catch {
|
|
628
|
+
} catch (err) {
|
|
629
|
+
console.error("[t2000] Pyth oracle push failed, falling back to cached prices:", err.message ?? err);
|
|
629
630
|
}
|
|
630
631
|
}
|
|
631
632
|
for (const pool of stablePools) {
|
|
@@ -743,6 +744,9 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
743
744
|
const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
|
|
744
745
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
745
746
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
747
|
+
if (rawAmount <= 0) {
|
|
748
|
+
throw new T2000Error("INVALID_AMOUNT", `Withdrawal amount rounds to zero \u2014 balance is dust`);
|
|
749
|
+
}
|
|
746
750
|
const tx = new Transaction();
|
|
747
751
|
tx.setSender(address);
|
|
748
752
|
await refreshStableOracles(tx, client, config, pools);
|
|
@@ -783,6 +787,13 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
783
787
|
const effectiveAmount = Math.min(amount, Math.max(0, deposited - WITHDRAW_DUST_BUFFER));
|
|
784
788
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
785
789
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
790
|
+
if (rawAmount <= 0) {
|
|
791
|
+
const [coin2] = tx.moveCall({
|
|
792
|
+
target: "0x2::coin::zero",
|
|
793
|
+
typeArguments: [pool.suiCoinType]
|
|
794
|
+
});
|
|
795
|
+
return { coin: coin2, effectiveAmount: 0 };
|
|
796
|
+
}
|
|
786
797
|
await refreshStableOracles(tx, client, config, pools);
|
|
787
798
|
const [balance] = tx.moveCall({
|
|
788
799
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
@@ -2874,7 +2885,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2874
2885
|
const withdrawable = [];
|
|
2875
2886
|
for (const pos of allPositions) {
|
|
2876
2887
|
for (const supply of pos.positions.supplies) {
|
|
2877
|
-
if (supply.amount >
|
|
2888
|
+
if (supply.amount > 0.01) {
|
|
2878
2889
|
withdrawable.push({ protocolId: pos.protocolId, asset: supply.asset, amount: supply.amount });
|
|
2879
2890
|
}
|
|
2880
2891
|
}
|
|
@@ -2887,8 +2898,9 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2887
2898
|
const adapter = this.registry.getLending(entry.protocolId);
|
|
2888
2899
|
if (!adapter) continue;
|
|
2889
2900
|
const maxResult = await adapter.maxWithdraw(this._address, entry.asset);
|
|
2890
|
-
|
|
2891
|
-
|
|
2901
|
+
const perAssetMax = Math.min(entry.amount, maxResult.maxAmount);
|
|
2902
|
+
if (perAssetMax > 0.01) {
|
|
2903
|
+
entries.push({ ...entry, maxAmount: perAssetMax, adapter });
|
|
2892
2904
|
}
|
|
2893
2905
|
}
|
|
2894
2906
|
if (entries.length === 0) {
|