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