@t2000/sdk 0.9.8 → 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 +6 -4
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +6 -4
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +11 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -8
- 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
|
|
@@ -745,9 +745,8 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
745
745
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
746
746
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
747
747
|
if (rawAmount <= 0) {
|
|
748
|
-
throw new T2000Error("INVALID_AMOUNT", `Withdrawal amount
|
|
748
|
+
throw new T2000Error("INVALID_AMOUNT", `Withdrawal amount rounds to zero \u2014 balance is dust`);
|
|
749
749
|
}
|
|
750
|
-
console.error(`[t2000] withdraw: asset=${asset} poolId=${pool.id} amount=${amount} deposited=${deposited} effective=${effectiveAmount} raw=${rawAmount} supplyBal=${assetState?.supplyBalance} index=${pool.currentSupplyIndex}`);
|
|
751
750
|
const tx = new Transaction();
|
|
752
751
|
tx.setSender(address);
|
|
753
752
|
await refreshStableOracles(tx, client, config, pools);
|
|
@@ -789,9 +788,12 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
789
788
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
|
|
790
789
|
const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
|
|
791
790
|
if (rawAmount <= 0) {
|
|
792
|
-
|
|
791
|
+
const [coin2] = tx.moveCall({
|
|
792
|
+
target: "0x2::coin::zero",
|
|
793
|
+
typeArguments: [pool.suiCoinType]
|
|
794
|
+
});
|
|
795
|
+
return { coin: coin2, effectiveAmount: 0 };
|
|
793
796
|
}
|
|
794
|
-
console.error(`[t2000] withdraw: asset=${asset} poolId=${pool.id} amount=${amount} deposited=${deposited} effective=${effectiveAmount} raw=${rawAmount} supplyBal=${assetState?.supplyBalance} index=${pool.currentSupplyIndex}`);
|
|
795
797
|
await refreshStableOracles(tx, client, config, pools);
|
|
796
798
|
const [balance] = tx.moveCall({
|
|
797
799
|
target: `${config.package}::incentive_v3::withdraw_v2`,
|
|
@@ -2883,7 +2885,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2883
2885
|
const withdrawable = [];
|
|
2884
2886
|
for (const pos of allPositions) {
|
|
2885
2887
|
for (const supply of pos.positions.supplies) {
|
|
2886
|
-
if (supply.amount >
|
|
2888
|
+
if (supply.amount > 0.01) {
|
|
2887
2889
|
withdrawable.push({ protocolId: pos.protocolId, asset: supply.asset, amount: supply.amount });
|
|
2888
2890
|
}
|
|
2889
2891
|
}
|
|
@@ -2896,8 +2898,9 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2896
2898
|
const adapter = this.registry.getLending(entry.protocolId);
|
|
2897
2899
|
if (!adapter) continue;
|
|
2898
2900
|
const maxResult = await adapter.maxWithdraw(this._address, entry.asset);
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
+
const perAssetMax = Math.min(entry.amount, maxResult.maxAmount);
|
|
2902
|
+
if (perAssetMax > 0.01) {
|
|
2903
|
+
entries.push({ ...entry, maxAmount: perAssetMax, adapter });
|
|
2901
2904
|
}
|
|
2902
2905
|
}
|
|
2903
2906
|
if (entries.length === 0) {
|