@t2000/sdk 0.16.7 → 0.16.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
@@ -3667,10 +3667,13 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3667
3667
  }
3668
3668
  async withdrawAllProtocols() {
3669
3669
  const allPositions = await this.registry.allPositions(this._address);
3670
+ const earningAssets = new Set(
3671
+ this.portfolio.getPositions().filter((p) => p.earning).map((p) => p.asset)
3672
+ );
3670
3673
  const withdrawable = [];
3671
3674
  for (const pos of allPositions) {
3672
3675
  for (const supply of pos.positions.supplies) {
3673
- if (supply.amount > 0.01) {
3676
+ if (supply.amount > 0.01 && !earningAssets.has(supply.asset)) {
3674
3677
  withdrawable.push({ protocolId: pos.protocolId, asset: supply.asset, amount: supply.amount });
3675
3678
  }
3676
3679
  }
@@ -4321,9 +4324,7 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
4321
4324
  if (!adapter) {
4322
4325
  throw new T2000Error("PROTOCOL_UNAVAILABLE", `Lending protocol ${pos.earningProtocol} not found`);
4323
4326
  }
4324
- const positions = await adapter.getPositions(this._address);
4325
- const supply = positions.supplies.find((s) => s.asset === params.asset);
4326
- const withdrawAmount = supply?.amount ?? pos.totalAmount;
4327
+ const withdrawAmount = pos.totalAmount;
4327
4328
  const protocolName = adapter.name;
4328
4329
  let effectiveAmount = withdrawAmount;
4329
4330
  const gasResult = await executeWithGas(this.client, this.keypair, async () => {
@@ -5066,7 +5067,8 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
5066
5067
  const balance = await this.client.getBalance({ owner: this._address, coinType: assetInfo.type });
5067
5068
  const walletAmount = Number(balance.totalBalance) / 10 ** assetInfo.decimals;
5068
5069
  const gasReserve = asset === "SUI" ? GAS_RESERVE_MIN : 0;
5069
- return Math.max(0, walletAmount - invested - gasReserve);
5070
+ const walletInvested = pos?.earning ? 0 : invested;
5071
+ return Math.max(0, walletAmount - walletInvested - gasReserve);
5070
5072
  }
5071
5073
  async resolveLending(protocol, asset, capability) {
5072
5074
  if (protocol) {