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