@t2000/sdk 0.16.7 → 0.16.9
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 +7 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3665,10 +3665,13 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3665
3665
|
}
|
|
3666
3666
|
async withdrawAllProtocols() {
|
|
3667
3667
|
const allPositions = await this.registry.allPositions(this._address);
|
|
3668
|
+
const earningAssets = new Set(
|
|
3669
|
+
this.portfolio.getPositions().filter((p) => p.earning).map((p) => p.asset)
|
|
3670
|
+
);
|
|
3668
3671
|
const withdrawable = [];
|
|
3669
3672
|
for (const pos of allPositions) {
|
|
3670
3673
|
for (const supply of pos.positions.supplies) {
|
|
3671
|
-
if (supply.amount > 0.01) {
|
|
3674
|
+
if (supply.amount > 0.01 && !earningAssets.has(supply.asset)) {
|
|
3672
3675
|
withdrawable.push({ protocolId: pos.protocolId, asset: supply.asset, amount: supply.amount });
|
|
3673
3676
|
}
|
|
3674
3677
|
}
|
|
@@ -4319,9 +4322,7 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4319
4322
|
if (!adapter) {
|
|
4320
4323
|
throw new T2000Error("PROTOCOL_UNAVAILABLE", `Lending protocol ${pos.earningProtocol} not found`);
|
|
4321
4324
|
}
|
|
4322
|
-
const
|
|
4323
|
-
const supply = positions.supplies.find((s) => s.asset === params.asset);
|
|
4324
|
-
const withdrawAmount = supply?.amount ?? pos.totalAmount;
|
|
4325
|
+
const withdrawAmount = pos.totalAmount;
|
|
4325
4326
|
const protocolName = adapter.name;
|
|
4326
4327
|
let effectiveAmount = withdrawAmount;
|
|
4327
4328
|
const gasResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
@@ -5064,7 +5065,8 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
5064
5065
|
const balance = await this.client.getBalance({ owner: this._address, coinType: assetInfo.type });
|
|
5065
5066
|
const walletAmount = Number(balance.totalBalance) / 10 ** assetInfo.decimals;
|
|
5066
5067
|
const gasReserve = asset === "SUI" ? GAS_RESERVE_MIN : 0;
|
|
5067
|
-
|
|
5068
|
+
const walletInvested = pos?.earning ? 0 : invested;
|
|
5069
|
+
return Math.max(0, walletAmount - walletInvested - gasReserve);
|
|
5068
5070
|
}
|
|
5069
5071
|
async resolveLending(protocol, asset, capability) {
|
|
5070
5072
|
if (protocol) {
|