@t2000/sdk 0.16.26 → 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.cjs +19 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3760,14 +3760,20 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3760
3760
|
if (withdrawable.length === 0) {
|
|
3761
3761
|
throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
|
|
3762
3762
|
}
|
|
3763
|
+
const protocolMaxes = /* @__PURE__ */ new Map();
|
|
3763
3764
|
const entries = [];
|
|
3764
3765
|
for (const entry of withdrawable) {
|
|
3765
3766
|
const adapter = this.registry.getLending(entry.protocolId);
|
|
3766
3767
|
if (!adapter) continue;
|
|
3767
|
-
|
|
3768
|
-
|
|
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);
|
|
3769
3774
|
if (perAssetMax > 0.01) {
|
|
3770
3775
|
entries.push({ ...entry, maxAmount: perAssetMax, adapter });
|
|
3776
|
+
protocolMaxes.set(entry.protocolId, remaining - perAssetMax);
|
|
3771
3777
|
}
|
|
3772
3778
|
}
|
|
3773
3779
|
if (entries.length === 0) {
|
|
@@ -3781,6 +3787,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3781
3787
|
const tx = new Transaction();
|
|
3782
3788
|
tx.setSender(this._address);
|
|
3783
3789
|
const usdcCoins = [];
|
|
3790
|
+
const nonUsdcCoins = [];
|
|
3784
3791
|
for (const entry of entries) {
|
|
3785
3792
|
const { coin, effectiveAmount } = await entry.adapter.addWithdrawToTx(
|
|
3786
3793
|
tx,
|
|
@@ -3788,26 +3795,23 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3788
3795
|
entry.maxAmount,
|
|
3789
3796
|
entry.asset
|
|
3790
3797
|
);
|
|
3791
|
-
if (entry.asset
|
|
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 {
|
|
3798
|
+
if (entry.asset === "USDC") {
|
|
3803
3799
|
totalUsdcReceived += effectiveAmount;
|
|
3804
3800
|
usdcCoins.push(coin);
|
|
3801
|
+
} else {
|
|
3802
|
+
totalUsdcReceived += effectiveAmount;
|
|
3803
|
+
nonUsdcCoins.push(coin);
|
|
3805
3804
|
}
|
|
3806
3805
|
}
|
|
3807
3806
|
if (usdcCoins.length > 1) {
|
|
3808
3807
|
tx.mergeCoins(usdcCoins[0], usdcCoins.slice(1));
|
|
3809
3808
|
}
|
|
3810
|
-
|
|
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
|
+
}
|
|
3811
3815
|
return tx;
|
|
3812
3816
|
}
|
|
3813
3817
|
let lastTx;
|