@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/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: "Oracle validation failed during withdrawal \u2014 try again in a moment",
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
@@ -747,9 +747,8 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
747
747
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
748
748
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
749
749
  if (rawAmount <= 0) {
750
- throw new T2000Error("INVALID_AMOUNT", `Withdrawal amount too small to represent (effective=${effectiveAmount}, raw=${rawAmount}, decimals=${assetInfo.decimals})`);
750
+ throw new T2000Error("INVALID_AMOUNT", `Withdrawal amount rounds to zero \u2014 balance is dust`);
751
751
  }
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
752
  const tx = new transactions.Transaction();
754
753
  tx.setSender(address);
755
754
  await refreshStableOracles(tx, client, config, pools);
@@ -791,9 +790,12 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
791
790
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on NAVI`);
792
791
  const rawAmount = Number(stableToRaw(effectiveAmount, assetInfo.decimals));
793
792
  if (rawAmount <= 0) {
794
- throw new T2000Error("INVALID_AMOUNT", `Withdrawal amount too small to represent (effective=${effectiveAmount}, raw=${rawAmount}, decimals=${assetInfo.decimals})`);
793
+ const [coin2] = tx.moveCall({
794
+ target: "0x2::coin::zero",
795
+ typeArguments: [pool.suiCoinType]
796
+ });
797
+ return { coin: coin2, effectiveAmount: 0 };
795
798
  }
796
- console.error(`[t2000] withdraw: asset=${asset} poolId=${pool.id} amount=${amount} deposited=${deposited} effective=${effectiveAmount} raw=${rawAmount} supplyBal=${assetState?.supplyBalance} index=${pool.currentSupplyIndex}`);
797
799
  await refreshStableOracles(tx, client, config, pools);
798
800
  const [balance] = tx.moveCall({
799
801
  target: `${config.package}::incentive_v3::withdraw_v2`,
@@ -2885,7 +2887,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2885
2887
  const withdrawable = [];
2886
2888
  for (const pos of allPositions) {
2887
2889
  for (const supply of pos.positions.supplies) {
2888
- if (supply.amount > 1e-3) {
2890
+ if (supply.amount > 0.01) {
2889
2891
  withdrawable.push({ protocolId: pos.protocolId, asset: supply.asset, amount: supply.amount });
2890
2892
  }
2891
2893
  }
@@ -2898,8 +2900,9 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
2898
2900
  const adapter = this.registry.getLending(entry.protocolId);
2899
2901
  if (!adapter) continue;
2900
2902
  const maxResult = await adapter.maxWithdraw(this._address, entry.asset);
2901
- if (maxResult.maxAmount > 1e-3) {
2902
- entries.push({ ...entry, maxAmount: maxResult.maxAmount, adapter });
2903
+ const perAssetMax = Math.min(entry.amount, maxResult.maxAmount);
2904
+ if (perAssetMax > 0.01) {
2905
+ entries.push({ ...entry, maxAmount: perAssetMax, adapter });
2903
2906
  }
2904
2907
  }
2905
2908
  if (entries.length === 0) {