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