@t2000/sdk 0.17.12 → 0.17.13
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 +44 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4281,13 +4281,28 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4281
4281
|
if (bal.available < params.usdAmount) {
|
|
4282
4282
|
throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient checking balance. Available: $${bal.available.toFixed(2)}, requested: $${params.usdAmount.toFixed(2)}`);
|
|
4283
4283
|
}
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4284
|
+
let swapResult;
|
|
4285
|
+
const maxRetries = 3;
|
|
4286
|
+
for (let attempt = 0; ; attempt++) {
|
|
4287
|
+
try {
|
|
4288
|
+
swapResult = await this.exchange({
|
|
4289
|
+
from: "USDC",
|
|
4290
|
+
to: params.asset,
|
|
4291
|
+
amount: params.usdAmount,
|
|
4292
|
+
maxSlippage: params.maxSlippage ?? defaultSlippage(params.asset),
|
|
4293
|
+
_bypassInvestmentGuard: true
|
|
4294
|
+
});
|
|
4295
|
+
break;
|
|
4296
|
+
} catch (err) {
|
|
4297
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
4298
|
+
const isSlippage = msg.includes("slippage") || msg.includes("amount_out_slippage");
|
|
4299
|
+
if (isSlippage && attempt < maxRetries) {
|
|
4300
|
+
await new Promise((r) => setTimeout(r, 2e3 * (attempt + 1)));
|
|
4301
|
+
continue;
|
|
4302
|
+
}
|
|
4303
|
+
throw err;
|
|
4304
|
+
}
|
|
4305
|
+
}
|
|
4291
4306
|
if (swapResult.toAmount === 0) {
|
|
4292
4307
|
throw new T2000Error("SWAP_FAILED", "Swap returned zero tokens \u2014 try a different amount or check liquidity");
|
|
4293
4308
|
}
|
|
@@ -4385,13 +4400,28 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4385
4400
|
if (sellAmountAsset <= 0) {
|
|
4386
4401
|
throw new T2000Error("INSUFFICIENT_INVESTMENT", "Nothing to sell after gas reserve");
|
|
4387
4402
|
}
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4403
|
+
let swapResult;
|
|
4404
|
+
const maxRetries = 3;
|
|
4405
|
+
for (let attempt = 0; ; attempt++) {
|
|
4406
|
+
try {
|
|
4407
|
+
swapResult = await this.exchange({
|
|
4408
|
+
from: params.asset,
|
|
4409
|
+
to: "USDC",
|
|
4410
|
+
amount: sellAmountAsset,
|
|
4411
|
+
maxSlippage: params.maxSlippage ?? defaultSlippage(params.asset),
|
|
4412
|
+
_bypassInvestmentGuard: true
|
|
4413
|
+
});
|
|
4414
|
+
break;
|
|
4415
|
+
} catch (err) {
|
|
4416
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
4417
|
+
const isSlippage = msg.includes("slippage") || msg.includes("amount_out_slippage");
|
|
4418
|
+
if (isSlippage && attempt < maxRetries) {
|
|
4419
|
+
await new Promise((r) => setTimeout(r, 2e3 * (attempt + 1)));
|
|
4420
|
+
continue;
|
|
4421
|
+
}
|
|
4422
|
+
throw err;
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4395
4425
|
const price = swapResult.toAmount / sellAmountAsset;
|
|
4396
4426
|
const realizedPnL = this.portfolio.recordSell({
|
|
4397
4427
|
id: `inv_${Date.now()}`,
|