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