@t2000/sdk 0.18.3 → 0.18.4
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/adapters/index.cjs +6 -1
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +6 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +24 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1672,15 +1672,20 @@ var ProtocolRegistry = class {
|
|
|
1672
1672
|
}
|
|
1673
1673
|
async allPositions(address) {
|
|
1674
1674
|
const results = [];
|
|
1675
|
+
const errors = [];
|
|
1675
1676
|
for (const adapter of this.lending.values()) {
|
|
1676
1677
|
try {
|
|
1677
1678
|
const positions = await adapter.getPositions(address);
|
|
1678
1679
|
if (positions.supplies.length > 0 || positions.borrows.length > 0) {
|
|
1679
1680
|
results.push({ protocol: adapter.name, protocolId: adapter.id, positions });
|
|
1680
1681
|
}
|
|
1681
|
-
} catch {
|
|
1682
|
+
} catch (err) {
|
|
1683
|
+
errors.push(`${adapter.name}: ${err instanceof Error ? err.message : String(err)}`);
|
|
1682
1684
|
}
|
|
1683
1685
|
}
|
|
1686
|
+
if (results.length === 0 && errors.length > 0) {
|
|
1687
|
+
throw new T2000Error("PROTOCOL_UNAVAILABLE", `Protocol queries failed (${errors.length}/${this.lending.size}): ${errors.join("; ")}`);
|
|
1688
|
+
}
|
|
1684
1689
|
return results;
|
|
1685
1690
|
}
|
|
1686
1691
|
getLending(id) {
|
|
@@ -3846,7 +3851,7 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
3846
3851
|
);
|
|
3847
3852
|
try {
|
|
3848
3853
|
const positions = await this.positions();
|
|
3849
|
-
const savings = positions.positions.filter((p) => p.type === "save").filter((p) => !earningAssets.has(p.asset)).reduce((sum, p) => sum + p.amount, 0);
|
|
3854
|
+
const savings = positions.positions.filter((p) => p.type === "save").filter((p) => !earningAssets.has(p.asset)).filter((p) => !(p.asset in INVESTMENT_ASSETS)).reduce((sum, p) => sum + p.amount, 0);
|
|
3850
3855
|
const debt = positions.positions.filter((p) => p.type === "borrow").reduce((sum, p) => sum + p.amount, 0);
|
|
3851
3856
|
bal.savings = savings;
|
|
3852
3857
|
bal.debt = debt;
|
|
@@ -4182,7 +4187,8 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
4182
4187
|
if (entries.length === 0) {
|
|
4183
4188
|
throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
|
|
4184
4189
|
}
|
|
4185
|
-
const
|
|
4190
|
+
const hasNonUsdc = entries.some((e) => e.asset !== "USDC");
|
|
4191
|
+
const swapAdapter = hasNonUsdc ? this.registry.listSwap()[0] : void 0;
|
|
4186
4192
|
const canPTB = entries.every((e) => e.adapter.addWithdrawToTx) && (!swapAdapter || swapAdapter.addSwapToTx);
|
|
4187
4193
|
let totalUsdcReceived = 0;
|
|
4188
4194
|
const gasResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
@@ -4190,7 +4196,6 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
4190
4196
|
const tx = new Transaction();
|
|
4191
4197
|
tx.setSender(this._address);
|
|
4192
4198
|
const usdcCoins = [];
|
|
4193
|
-
const nonUsdcCoins = [];
|
|
4194
4199
|
for (const entry of entries) {
|
|
4195
4200
|
const { coin, effectiveAmount } = await entry.adapter.addWithdrawToTx(
|
|
4196
4201
|
tx,
|
|
@@ -4201,9 +4206,20 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
4201
4206
|
if (entry.asset === "USDC") {
|
|
4202
4207
|
totalUsdcReceived += effectiveAmount;
|
|
4203
4208
|
usdcCoins.push(coin);
|
|
4209
|
+
} else if (swapAdapter?.addSwapToTx) {
|
|
4210
|
+
const { outputCoin, estimatedOut, toDecimals } = await swapAdapter.addSwapToTx(
|
|
4211
|
+
tx,
|
|
4212
|
+
this._address,
|
|
4213
|
+
coin,
|
|
4214
|
+
entry.asset,
|
|
4215
|
+
"USDC",
|
|
4216
|
+
effectiveAmount
|
|
4217
|
+
);
|
|
4218
|
+
totalUsdcReceived += estimatedOut / 10 ** toDecimals;
|
|
4219
|
+
usdcCoins.push(outputCoin);
|
|
4204
4220
|
} else {
|
|
4205
4221
|
totalUsdcReceived += effectiveAmount;
|
|
4206
|
-
|
|
4222
|
+
tx.transferObjects([coin], this._address);
|
|
4207
4223
|
}
|
|
4208
4224
|
}
|
|
4209
4225
|
if (usdcCoins.length > 1) {
|
|
@@ -4212,9 +4228,6 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
4212
4228
|
if (usdcCoins.length > 0) {
|
|
4213
4229
|
tx.transferObjects([usdcCoins[0]], this._address);
|
|
4214
4230
|
}
|
|
4215
|
-
for (const coin of nonUsdcCoins) {
|
|
4216
|
-
tx.transferObjects([coin], this._address);
|
|
4217
|
-
}
|
|
4218
4231
|
return tx;
|
|
4219
4232
|
}
|
|
4220
4233
|
let lastTx;
|
|
@@ -4223,6 +4236,9 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
4223
4236
|
totalUsdcReceived += built.effectiveAmount;
|
|
4224
4237
|
lastTx = built.tx;
|
|
4225
4238
|
}
|
|
4239
|
+
if (hasNonUsdc && swapAdapter) {
|
|
4240
|
+
await this._convertWalletStablesToUsdc(await queryBalance(this.client, this._address));
|
|
4241
|
+
}
|
|
4226
4242
|
return lastTx;
|
|
4227
4243
|
});
|
|
4228
4244
|
if (totalUsdcReceived <= 0) {
|