@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.js
CHANGED
|
@@ -56159,19 +56159,14 @@ async function trySponsored(client, keypair, tx) {
|
|
|
56159
56159
|
};
|
|
56160
56160
|
}
|
|
56161
56161
|
async function waitForIndexer(client, digest) {
|
|
56162
|
-
const start = Date.now();
|
|
56163
56162
|
for (let i = 0; i < 3; i++) {
|
|
56164
56163
|
try {
|
|
56165
56164
|
await client.getTransactionBlock({ digest, options: { showObjectChanges: true } });
|
|
56166
|
-
|
|
56165
|
+
return;
|
|
56167
56166
|
} catch {
|
|
56168
56167
|
await new Promise((r) => setTimeout(r, 500));
|
|
56169
56168
|
}
|
|
56170
56169
|
}
|
|
56171
|
-
const elapsed = Date.now() - start;
|
|
56172
|
-
if (elapsed < 2e3) {
|
|
56173
|
-
await new Promise((r) => setTimeout(r, 2e3 - elapsed));
|
|
56174
|
-
}
|
|
56175
56170
|
}
|
|
56176
56171
|
async function executeWithGas(client, keypair, buildTx, options) {
|
|
56177
56172
|
if (options?.enforcer && options?.metadata) {
|
|
@@ -57243,10 +57238,17 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
57243
57238
|
reportFee(this._address, "save", fee.amount, fee.rate, gasResult.digest);
|
|
57244
57239
|
this.emitBalanceChange(asset, saveAmount, "save", gasResult.digest);
|
|
57245
57240
|
let savingsBalance = saveAmount;
|
|
57246
|
-
|
|
57247
|
-
|
|
57248
|
-
|
|
57249
|
-
|
|
57241
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
57242
|
+
try {
|
|
57243
|
+
const positions = await this.positions();
|
|
57244
|
+
const actual = positions.positions.filter((p) => p.type === "save" && p.asset === asset).reduce((sum, p) => sum + p.amount, 0);
|
|
57245
|
+
if (actual > 0) {
|
|
57246
|
+
savingsBalance = actual;
|
|
57247
|
+
break;
|
|
57248
|
+
}
|
|
57249
|
+
} catch {
|
|
57250
|
+
}
|
|
57251
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
57250
57252
|
}
|
|
57251
57253
|
return {
|
|
57252
57254
|
success: true,
|
|
@@ -57353,6 +57355,14 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
57353
57355
|
}
|
|
57354
57356
|
}
|
|
57355
57357
|
this.emitBalanceChange("USDC", finalAmount, "withdraw", gasResult.digest);
|
|
57358
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
57359
|
+
try {
|
|
57360
|
+
const bal = await queryBalance(this.client, this._address);
|
|
57361
|
+
if ((bal.stables.USDC ?? 0) > 0.5) break;
|
|
57362
|
+
} catch {
|
|
57363
|
+
}
|
|
57364
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
57365
|
+
}
|
|
57356
57366
|
return {
|
|
57357
57367
|
success: true,
|
|
57358
57368
|
tx: gasResult.digest,
|
|
@@ -57473,6 +57483,14 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
57473
57483
|
if (totalUsdcReceived <= 0) {
|
|
57474
57484
|
throw new T2000Error("NO_COLLATERAL", "No savings to withdraw across any protocol");
|
|
57475
57485
|
}
|
|
57486
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
57487
|
+
try {
|
|
57488
|
+
const bal = await queryBalance(this.client, this._address);
|
|
57489
|
+
if ((bal.stables.USDC ?? 0) > 0.5) break;
|
|
57490
|
+
} catch {
|
|
57491
|
+
}
|
|
57492
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
57493
|
+
}
|
|
57476
57494
|
return {
|
|
57477
57495
|
success: true,
|
|
57478
57496
|
tx: gasResult.digest,
|
|
@@ -58942,7 +58960,7 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
58942
58960
|
const earningAssets = new Set(
|
|
58943
58961
|
this.portfolio.getPositions().filter((p) => p.earning).map((p) => p.asset)
|
|
58944
58962
|
);
|
|
58945
|
-
|
|
58963
|
+
let savePositions = allPositions.flatMap(
|
|
58946
58964
|
(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) => ({
|
|
58947
58965
|
protocolId: p.protocolId,
|
|
58948
58966
|
protocol: p.protocol,
|
|
@@ -58952,7 +58970,22 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
58952
58970
|
}))
|
|
58953
58971
|
);
|
|
58954
58972
|
if (savePositions.length === 0) {
|
|
58955
|
-
|
|
58973
|
+
for (let retry = 0; retry < 2 && savePositions.length === 0; retry++) {
|
|
58974
|
+
await new Promise((r) => setTimeout(r, 3e3));
|
|
58975
|
+
const freshPositions = await this.registry.allPositions(this._address);
|
|
58976
|
+
savePositions = freshPositions.flatMap(
|
|
58977
|
+
(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) => ({
|
|
58978
|
+
protocolId: p.protocolId,
|
|
58979
|
+
protocol: p.protocol,
|
|
58980
|
+
asset: s.asset,
|
|
58981
|
+
amount: s.amount,
|
|
58982
|
+
apy: s.apy
|
|
58983
|
+
}))
|
|
58984
|
+
);
|
|
58985
|
+
}
|
|
58986
|
+
if (savePositions.length === 0) {
|
|
58987
|
+
throw new T2000Error("NO_COLLATERAL", "No savings positions to rebalance. Use `t2000 save <amount>` first.");
|
|
58988
|
+
}
|
|
58956
58989
|
}
|
|
58957
58990
|
const borrowPositions = allPositions.flatMap(
|
|
58958
58991
|
(p) => p.positions.borrows.filter((b2) => b2.amount > 0.01)
|
|
@@ -59181,6 +59214,17 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
59181
59214
|
txDigests.push(depositResult.digest);
|
|
59182
59215
|
totalGasCost += depositResult.gasCostSui;
|
|
59183
59216
|
}
|
|
59217
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
59218
|
+
try {
|
|
59219
|
+
const positions = await this.positions();
|
|
59220
|
+
const newPos = positions.positions.find(
|
|
59221
|
+
(p) => p.type === "save" && p.asset === bestRate.asset && p.amount > 0.01
|
|
59222
|
+
);
|
|
59223
|
+
if (newPos) break;
|
|
59224
|
+
} catch {
|
|
59225
|
+
}
|
|
59226
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
59227
|
+
}
|
|
59184
59228
|
return {
|
|
59185
59229
|
executed: true,
|
|
59186
59230
|
steps,
|