@t2000/sdk 0.16.26 → 0.16.28

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
@@ -3487,6 +3487,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3487
3487
  }
3488
3488
  let investmentValue = 0;
3489
3489
  let investmentCostBasis = 0;
3490
+ let trackedValue = 0;
3490
3491
  const trackedAmounts = {};
3491
3492
  const trackedCostBasis = {};
3492
3493
  const earningAssetSet = /* @__PURE__ */ new Set();
@@ -3510,6 +3511,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3510
3511
  if (asset === "SUI") {
3511
3512
  const actualSui = earningAssetSet.has("SUI") ? tracked : Math.min(tracked, bal.gasReserve.sui);
3512
3513
  investmentValue += actualSui * price;
3514
+ trackedValue += actualSui * price;
3513
3515
  if (actualSui < tracked && tracked > 0) {
3514
3516
  investmentCostBasis += costBasis * (actualSui / tracked);
3515
3517
  } else {
@@ -3523,11 +3525,12 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3523
3525
  const onChainAmount = bal.assets[asset] ?? 0;
3524
3526
  const effectiveAmount = Math.max(tracked, onChainAmount);
3525
3527
  investmentValue += effectiveAmount * price;
3528
+ trackedValue += tracked * price;
3526
3529
  investmentCostBasis += costBasis;
3527
3530
  }
3528
3531
  }
3529
3532
  bal.investment = investmentValue;
3530
- bal.investmentPnL = investmentValue - investmentCostBasis;
3533
+ bal.investmentPnL = trackedValue - investmentCostBasis;
3531
3534
  } catch {
3532
3535
  bal.investment = 0;
3533
3536
  bal.investmentPnL = 0;
@@ -3762,14 +3765,20 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3762
3765
  if (withdrawable.length === 0) {
3763
3766
  throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
3764
3767
  }
3768
+ const protocolMaxes = /* @__PURE__ */ new Map();
3765
3769
  const entries = [];
3766
3770
  for (const entry of withdrawable) {
3767
3771
  const adapter = this.registry.getLending(entry.protocolId);
3768
3772
  if (!adapter) continue;
3769
- const maxResult = await adapter.maxWithdraw(this._address, entry.asset);
3770
- const perAssetMax = Math.min(entry.amount, maxResult.maxAmount);
3773
+ if (!protocolMaxes.has(entry.protocolId)) {
3774
+ const maxResult = await adapter.maxWithdraw(this._address, entry.asset);
3775
+ protocolMaxes.set(entry.protocolId, maxResult.maxAmount);
3776
+ }
3777
+ const remaining = protocolMaxes.get(entry.protocolId);
3778
+ const perAssetMax = Math.min(entry.amount, remaining);
3771
3779
  if (perAssetMax > 0.01) {
3772
3780
  entries.push({ ...entry, maxAmount: perAssetMax, adapter });
3781
+ protocolMaxes.set(entry.protocolId, remaining - perAssetMax);
3773
3782
  }
3774
3783
  }
3775
3784
  if (entries.length === 0) {
@@ -3783,6 +3792,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3783
3792
  const tx = new transactions.Transaction();
3784
3793
  tx.setSender(this._address);
3785
3794
  const usdcCoins = [];
3795
+ const nonUsdcCoins = [];
3786
3796
  for (const entry of entries) {
3787
3797
  const { coin, effectiveAmount } = await entry.adapter.addWithdrawToTx(
3788
3798
  tx,
@@ -3790,26 +3800,23 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
3790
3800
  entry.maxAmount,
3791
3801
  entry.asset
3792
3802
  );
3793
- if (entry.asset !== "USDC" && swapAdapter?.addSwapToTx) {
3794
- const { outputCoin, estimatedOut, toDecimals } = await swapAdapter.addSwapToTx(
3795
- tx,
3796
- this._address,
3797
- coin,
3798
- entry.asset,
3799
- "USDC",
3800
- effectiveAmount
3801
- );
3802
- totalUsdcReceived += estimatedOut / 10 ** toDecimals;
3803
- usdcCoins.push(outputCoin);
3804
- } else {
3803
+ if (entry.asset === "USDC") {
3805
3804
  totalUsdcReceived += effectiveAmount;
3806
3805
  usdcCoins.push(coin);
3806
+ } else {
3807
+ totalUsdcReceived += effectiveAmount;
3808
+ nonUsdcCoins.push(coin);
3807
3809
  }
3808
3810
  }
3809
3811
  if (usdcCoins.length > 1) {
3810
3812
  tx.mergeCoins(usdcCoins[0], usdcCoins.slice(1));
3811
3813
  }
3812
- tx.transferObjects([usdcCoins[0]], this._address);
3814
+ if (usdcCoins.length > 0) {
3815
+ tx.transferObjects([usdcCoins[0]], this._address);
3816
+ }
3817
+ for (const coin of nonUsdcCoins) {
3818
+ tx.transferObjects([coin], this._address);
3819
+ }
3813
3820
  return tx;
3814
3821
  }
3815
3822
  let lastTx;