@t2000/sdk 0.16.25 → 0.16.27

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.js CHANGED
@@ -3668,7 +3668,9 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3668
3668
  for (const pos of allPositions) {
3669
3669
  if (params.protocol && pos.protocolId !== params.protocol) continue;
3670
3670
  for (const s of pos.positions.supplies) {
3671
- if (s.amount > 1e-3) supplies.push({ protocolId: pos.protocolId, asset: s.asset, amount: s.amount, apy: s.apy });
3671
+ if (s.amount > 1e-3 && !(s.asset in INVESTMENT_ASSETS)) {
3672
+ supplies.push({ protocolId: pos.protocolId, asset: s.asset, amount: s.amount, apy: s.apy });
3673
+ }
3672
3674
  }
3673
3675
  }
3674
3676
  if (supplies.length === 0) {
@@ -3750,7 +3752,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3750
3752
  const withdrawable = [];
3751
3753
  for (const pos of allPositions) {
3752
3754
  for (const supply of pos.positions.supplies) {
3753
- if (supply.amount > 0.01 && !earningAssets.has(supply.asset)) {
3755
+ if (supply.amount > 0.01 && !earningAssets.has(supply.asset) && !(supply.asset in INVESTMENT_ASSETS)) {
3754
3756
  withdrawable.push({ protocolId: pos.protocolId, asset: supply.asset, amount: supply.amount });
3755
3757
  }
3756
3758
  }
@@ -3758,14 +3760,20 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3758
3760
  if (withdrawable.length === 0) {
3759
3761
  throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
3760
3762
  }
3763
+ const protocolMaxes = /* @__PURE__ */ new Map();
3761
3764
  const entries = [];
3762
3765
  for (const entry of withdrawable) {
3763
3766
  const adapter = this.registry.getLending(entry.protocolId);
3764
3767
  if (!adapter) continue;
3765
- const maxResult = await adapter.maxWithdraw(this._address, entry.asset);
3766
- const perAssetMax = Math.min(entry.amount, maxResult.maxAmount);
3768
+ if (!protocolMaxes.has(entry.protocolId)) {
3769
+ const maxResult = await adapter.maxWithdraw(this._address, entry.asset);
3770
+ protocolMaxes.set(entry.protocolId, maxResult.maxAmount);
3771
+ }
3772
+ const remaining = protocolMaxes.get(entry.protocolId);
3773
+ const perAssetMax = Math.min(entry.amount, remaining);
3767
3774
  if (perAssetMax > 0.01) {
3768
3775
  entries.push({ ...entry, maxAmount: perAssetMax, adapter });
3776
+ protocolMaxes.set(entry.protocolId, remaining - perAssetMax);
3769
3777
  }
3770
3778
  }
3771
3779
  if (entries.length === 0) {
@@ -3779,6 +3787,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3779
3787
  const tx = new Transaction();
3780
3788
  tx.setSender(this._address);
3781
3789
  const usdcCoins = [];
3790
+ const nonUsdcCoins = [];
3782
3791
  for (const entry of entries) {
3783
3792
  const { coin, effectiveAmount } = await entry.adapter.addWithdrawToTx(
3784
3793
  tx,
@@ -3786,26 +3795,23 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3786
3795
  entry.maxAmount,
3787
3796
  entry.asset
3788
3797
  );
3789
- if (entry.asset !== "USDC" && swapAdapter?.addSwapToTx) {
3790
- const { outputCoin, estimatedOut, toDecimals } = await swapAdapter.addSwapToTx(
3791
- tx,
3792
- this._address,
3793
- coin,
3794
- entry.asset,
3795
- "USDC",
3796
- effectiveAmount
3797
- );
3798
- totalUsdcReceived += estimatedOut / 10 ** toDecimals;
3799
- usdcCoins.push(outputCoin);
3800
- } else {
3798
+ if (entry.asset === "USDC") {
3801
3799
  totalUsdcReceived += effectiveAmount;
3802
3800
  usdcCoins.push(coin);
3801
+ } else {
3802
+ totalUsdcReceived += effectiveAmount;
3803
+ nonUsdcCoins.push(coin);
3803
3804
  }
3804
3805
  }
3805
3806
  if (usdcCoins.length > 1) {
3806
3807
  tx.mergeCoins(usdcCoins[0], usdcCoins.slice(1));
3807
3808
  }
3808
- tx.transferObjects([usdcCoins[0]], this._address);
3809
+ if (usdcCoins.length > 0) {
3810
+ tx.transferObjects([usdcCoins[0]], this._address);
3811
+ }
3812
+ for (const coin of nonUsdcCoins) {
3813
+ tx.transferObjects([coin], this._address);
3814
+ }
3809
3815
  return tx;
3810
3816
  }
3811
3817
  let lastTx;