@t2000/sdk 0.18.24 → 0.18.26
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 +56 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +56 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -56162,19 +56162,14 @@ async function trySponsored(client, keypair, tx) {
|
|
|
56162
56162
|
};
|
|
56163
56163
|
}
|
|
56164
56164
|
async function waitForIndexer(client, digest) {
|
|
56165
|
-
const start = Date.now();
|
|
56166
56165
|
for (let i = 0; i < 3; i++) {
|
|
56167
56166
|
try {
|
|
56168
56167
|
await client.getTransactionBlock({ digest, options: { showObjectChanges: true } });
|
|
56169
|
-
|
|
56168
|
+
return;
|
|
56170
56169
|
} catch {
|
|
56171
56170
|
await new Promise((r) => setTimeout(r, 500));
|
|
56172
56171
|
}
|
|
56173
56172
|
}
|
|
56174
|
-
const elapsed = Date.now() - start;
|
|
56175
|
-
if (elapsed < 2e3) {
|
|
56176
|
-
await new Promise((r) => setTimeout(r, 2e3 - elapsed));
|
|
56177
|
-
}
|
|
56178
56173
|
}
|
|
56179
56174
|
async function executeWithGas(client, keypair, buildTx, options) {
|
|
56180
56175
|
if (options?.enforcer && options?.metadata) {
|
|
@@ -57246,10 +57241,17 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
57246
57241
|
reportFee(this._address, "save", fee.amount, fee.rate, gasResult.digest);
|
|
57247
57242
|
this.emitBalanceChange(asset, saveAmount, "save", gasResult.digest);
|
|
57248
57243
|
let savingsBalance = saveAmount;
|
|
57249
|
-
|
|
57250
|
-
|
|
57251
|
-
|
|
57252
|
-
|
|
57244
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
57245
|
+
try {
|
|
57246
|
+
const positions = await this.positions();
|
|
57247
|
+
const actual = positions.positions.filter((p) => p.type === "save" && p.asset === asset).reduce((sum, p) => sum + p.amount, 0);
|
|
57248
|
+
if (actual > 0) {
|
|
57249
|
+
savingsBalance = actual;
|
|
57250
|
+
break;
|
|
57251
|
+
}
|
|
57252
|
+
} catch {
|
|
57253
|
+
}
|
|
57254
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
57253
57255
|
}
|
|
57254
57256
|
return {
|
|
57255
57257
|
success: true,
|
|
@@ -57356,6 +57358,14 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
57356
57358
|
}
|
|
57357
57359
|
}
|
|
57358
57360
|
this.emitBalanceChange("USDC", finalAmount, "withdraw", gasResult.digest);
|
|
57361
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
57362
|
+
try {
|
|
57363
|
+
const bal = await queryBalance(this.client, this._address);
|
|
57364
|
+
if ((bal.stables.USDC ?? 0) > 0.5) break;
|
|
57365
|
+
} catch {
|
|
57366
|
+
}
|
|
57367
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
57368
|
+
}
|
|
57359
57369
|
return {
|
|
57360
57370
|
success: true,
|
|
57361
57371
|
tx: gasResult.digest,
|
|
@@ -57476,6 +57486,14 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
57476
57486
|
if (totalUsdcReceived <= 0) {
|
|
57477
57487
|
throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
|
|
57478
57488
|
}
|
|
57489
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
57490
|
+
try {
|
|
57491
|
+
const bal = await queryBalance(this.client, this._address);
|
|
57492
|
+
if ((bal.stables.USDC ?? 0) > 0.5) break;
|
|
57493
|
+
} catch {
|
|
57494
|
+
}
|
|
57495
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
57496
|
+
}
|
|
57479
57497
|
return {
|
|
57480
57498
|
success: true,
|
|
57481
57499
|
tx: gasResult.digest,
|
|
@@ -58945,7 +58963,7 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
58945
58963
|
const earningAssets = new Set(
|
|
58946
58964
|
this.portfolio.getPositions().filter((p) => p.earning).map((p) => p.asset)
|
|
58947
58965
|
);
|
|
58948
|
-
|
|
58966
|
+
let savePositions = allPositions.flatMap(
|
|
58949
58967
|
(p) => p.positions.supplies.filter((s) => s.amount > 0.01).filter((s) => !earningAssets.has(s.asset)).filter((s) => !(s.asset in INVESTMENT_ASSETS)).map((s) => ({
|
|
58950
58968
|
protocolId: p.protocolId,
|
|
58951
58969
|
protocol: p.protocol,
|
|
@@ -58955,7 +58973,22 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
58955
58973
|
}))
|
|
58956
58974
|
);
|
|
58957
58975
|
if (savePositions.length === 0) {
|
|
58958
|
-
|
|
58976
|
+
for (let retry = 0; retry < 2 && savePositions.length === 0; retry++) {
|
|
58977
|
+
await new Promise((r) => setTimeout(r, 3e3));
|
|
58978
|
+
const freshPositions = await this.registry.allPositions(this._address);
|
|
58979
|
+
savePositions = freshPositions.flatMap(
|
|
58980
|
+
(p) => p.positions.supplies.filter((s) => s.amount > 0.01).filter((s) => !earningAssets.has(s.asset)).filter((s) => !(s.asset in INVESTMENT_ASSETS)).map((s) => ({
|
|
58981
|
+
protocolId: p.protocolId,
|
|
58982
|
+
protocol: p.protocol,
|
|
58983
|
+
asset: s.asset,
|
|
58984
|
+
amount: s.amount,
|
|
58985
|
+
apy: s.apy
|
|
58986
|
+
}))
|
|
58987
|
+
);
|
|
58988
|
+
}
|
|
58989
|
+
if (savePositions.length === 0) {
|
|
58990
|
+
throw new T2000Error("NO_COLLATERAL", "No savings positions to rebalance. Use `t2000 save <amount>` first.");
|
|
58991
|
+
}
|
|
58959
58992
|
}
|
|
58960
58993
|
const borrowPositions = allPositions.flatMap(
|
|
58961
58994
|
(p) => p.positions.borrows.filter((b2) => b2.amount > 0.01)
|
|
@@ -59184,6 +59217,17 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
59184
59217
|
txDigests.push(depositResult.digest);
|
|
59185
59218
|
totalGasCost += depositResult.gasCostSui;
|
|
59186
59219
|
}
|
|
59220
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
59221
|
+
try {
|
|
59222
|
+
const positions = await this.positions();
|
|
59223
|
+
const newPos = positions.positions.find(
|
|
59224
|
+
(p) => p.type === "save" && p.asset === bestRate.asset && p.amount > 0.01
|
|
59225
|
+
);
|
|
59226
|
+
if (newPos) break;
|
|
59227
|
+
} catch {
|
|
59228
|
+
}
|
|
59229
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
59230
|
+
}
|
|
59187
59231
|
return {
|
|
59188
59232
|
executed: true,
|
|
59189
59233
|
steps,
|