@t2000/sdk 0.16.25 → 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 +23 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3670,7 +3670,9 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3670
3670
|
for (const pos of allPositions) {
|
|
3671
3671
|
if (params.protocol && pos.protocolId !== params.protocol) continue;
|
|
3672
3672
|
for (const s of pos.positions.supplies) {
|
|
3673
|
-
if (s.amount > 1e-3
|
|
3673
|
+
if (s.amount > 1e-3 && !(s.asset in INVESTMENT_ASSETS)) {
|
|
3674
|
+
supplies.push({ protocolId: pos.protocolId, asset: s.asset, amount: s.amount, apy: s.apy });
|
|
3675
|
+
}
|
|
3674
3676
|
}
|
|
3675
3677
|
}
|
|
3676
3678
|
if (supplies.length === 0) {
|
|
@@ -3752,7 +3754,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3752
3754
|
const withdrawable = [];
|
|
3753
3755
|
for (const pos of allPositions) {
|
|
3754
3756
|
for (const supply of pos.positions.supplies) {
|
|
3755
|
-
if (supply.amount > 0.01 && !earningAssets.has(supply.asset)) {
|
|
3757
|
+
if (supply.amount > 0.01 && !earningAssets.has(supply.asset) && !(supply.asset in INVESTMENT_ASSETS)) {
|
|
3756
3758
|
withdrawable.push({ protocolId: pos.protocolId, asset: supply.asset, amount: supply.amount });
|
|
3757
3759
|
}
|
|
3758
3760
|
}
|
|
@@ -3760,14 +3762,20 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3760
3762
|
if (withdrawable.length === 0) {
|
|
3761
3763
|
throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
|
|
3762
3764
|
}
|
|
3765
|
+
const protocolMaxes = /* @__PURE__ */ new Map();
|
|
3763
3766
|
const entries = [];
|
|
3764
3767
|
for (const entry of withdrawable) {
|
|
3765
3768
|
const adapter = this.registry.getLending(entry.protocolId);
|
|
3766
3769
|
if (!adapter) continue;
|
|
3767
|
-
|
|
3768
|
-
|
|
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);
|
|
3769
3776
|
if (perAssetMax > 0.01) {
|
|
3770
3777
|
entries.push({ ...entry, maxAmount: perAssetMax, adapter });
|
|
3778
|
+
protocolMaxes.set(entry.protocolId, remaining - perAssetMax);
|
|
3771
3779
|
}
|
|
3772
3780
|
}
|
|
3773
3781
|
if (entries.length === 0) {
|
|
@@ -3781,6 +3789,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3781
3789
|
const tx = new transactions.Transaction();
|
|
3782
3790
|
tx.setSender(this._address);
|
|
3783
3791
|
const usdcCoins = [];
|
|
3792
|
+
const nonUsdcCoins = [];
|
|
3784
3793
|
for (const entry of entries) {
|
|
3785
3794
|
const { coin, effectiveAmount } = await entry.adapter.addWithdrawToTx(
|
|
3786
3795
|
tx,
|
|
@@ -3788,26 +3797,23 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3788
3797
|
entry.maxAmount,
|
|
3789
3798
|
entry.asset
|
|
3790
3799
|
);
|
|
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 {
|
|
3800
|
+
if (entry.asset === "USDC") {
|
|
3803
3801
|
totalUsdcReceived += effectiveAmount;
|
|
3804
3802
|
usdcCoins.push(coin);
|
|
3803
|
+
} else {
|
|
3804
|
+
totalUsdcReceived += effectiveAmount;
|
|
3805
|
+
nonUsdcCoins.push(coin);
|
|
3805
3806
|
}
|
|
3806
3807
|
}
|
|
3807
3808
|
if (usdcCoins.length > 1) {
|
|
3808
3809
|
tx.mergeCoins(usdcCoins[0], usdcCoins.slice(1));
|
|
3809
3810
|
}
|
|
3810
|
-
|
|
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
|
+
}
|
|
3811
3817
|
return tx;
|
|
3812
3818
|
}
|
|
3813
3819
|
let lastTx;
|