@t2000/sdk 0.16.19 → 0.16.21
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.map +1 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +27 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +27 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -182,10 +182,17 @@ function parseMoveAbortMessage(msg) {
|
|
|
182
182
|
const abortMatch = msg.match(/abort code:\s*(\d+)/i) ?? msg.match(/MoveAbort[^,]*,\s*(\d+)/);
|
|
183
183
|
if (abortMatch) {
|
|
184
184
|
const code = parseInt(abortMatch[1], 10);
|
|
185
|
-
const mapped = mapMoveAbortCode(code);
|
|
186
185
|
const moduleMatch = msg.match(/Identifier\("([^"]+)"\)/) ?? msg.match(/in '([^']+)'/);
|
|
187
186
|
const fnMatch = msg.match(/function_name:\s*Some\("([^"]+)"\)/);
|
|
187
|
+
const context = `${moduleMatch?.[1] ?? ""}${fnMatch ? `::${fnMatch[1]}` : ""}`.toLowerCase();
|
|
188
188
|
const suffix = moduleMatch ? ` [${moduleMatch[1]}${fnMatch ? `::${fnMatch[1]}` : ""}]` : "";
|
|
189
|
+
if (context.includes("slippage")) {
|
|
190
|
+
return `Swap slippage too high \u2014 price moved during execution${suffix}`;
|
|
191
|
+
}
|
|
192
|
+
if (context.includes("balance::split") || context.includes("balance::ENotEnough")) {
|
|
193
|
+
return `Insufficient on-chain balance${suffix}`;
|
|
194
|
+
}
|
|
195
|
+
const mapped = mapMoveAbortCode(code);
|
|
189
196
|
return `${mapped}${suffix}`;
|
|
190
197
|
}
|
|
191
198
|
return msg;
|
|
@@ -3038,6 +3045,11 @@ var PortfolioManager = class {
|
|
|
3038
3045
|
this.load();
|
|
3039
3046
|
return Object.keys(this.data.strategies);
|
|
3040
3047
|
}
|
|
3048
|
+
clearStrategy(strategyKey) {
|
|
3049
|
+
this.load();
|
|
3050
|
+
delete this.data.strategies[strategyKey];
|
|
3051
|
+
this.save();
|
|
3052
|
+
}
|
|
3041
3053
|
hasStrategyPositions(strategyKey) {
|
|
3042
3054
|
this.load();
|
|
3043
3055
|
const bucket = this.data.strategies[strategyKey];
|
|
@@ -4242,16 +4254,22 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4242
4254
|
if (!pos || pos.totalAmount <= 0) {
|
|
4243
4255
|
throw new T2000Error("INSUFFICIENT_INVESTMENT", `No ${params.asset} position to sell`);
|
|
4244
4256
|
}
|
|
4245
|
-
|
|
4257
|
+
const didAutoWithdraw = !!(pos.earning && pos.earningProtocol);
|
|
4258
|
+
if (didAutoWithdraw) {
|
|
4246
4259
|
await this.investUnearn({ asset: params.asset });
|
|
4247
4260
|
}
|
|
4248
4261
|
const assetInfo = SUPPORTED_ASSETS[params.asset];
|
|
4249
|
-
const assetBalance = await this.client.getBalance({
|
|
4250
|
-
owner: this._address,
|
|
4251
|
-
coinType: assetInfo.type
|
|
4252
|
-
});
|
|
4253
|
-
const walletAmount = Number(assetBalance.totalBalance) / 10 ** assetInfo.decimals;
|
|
4254
4262
|
const gasReserve = params.asset === "SUI" ? GAS_RESERVE_MIN : 0;
|
|
4263
|
+
let walletAmount = 0;
|
|
4264
|
+
for (let attempt = 0; ; attempt++) {
|
|
4265
|
+
const assetBalance = await this.client.getBalance({
|
|
4266
|
+
owner: this._address,
|
|
4267
|
+
coinType: assetInfo.type
|
|
4268
|
+
});
|
|
4269
|
+
walletAmount = Number(assetBalance.totalBalance) / 10 ** assetInfo.decimals;
|
|
4270
|
+
if (!didAutoWithdraw || walletAmount > gasReserve || attempt >= 3) break;
|
|
4271
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
4272
|
+
}
|
|
4255
4273
|
const maxSellable = Math.max(0, walletAmount - gasReserve);
|
|
4256
4274
|
let sellAmountAsset;
|
|
4257
4275
|
if (params.usdAmount === "all") {
|
|
@@ -4432,8 +4450,9 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4432
4450
|
if (!swapAdapter?.addSwapToTx) {
|
|
4433
4451
|
throw new T2000Error("PROTOCOL_UNAVAILABLE", "Swap adapter does not support composable PTB");
|
|
4434
4452
|
}
|
|
4435
|
-
|
|
4453
|
+
let swapMetas = [];
|
|
4436
4454
|
const gasResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
4455
|
+
swapMetas = [];
|
|
4437
4456
|
const tx = new Transaction();
|
|
4438
4457
|
tx.setSender(this._address);
|
|
4439
4458
|
const usdcCoins = await this._fetchCoins(SUPPORTED_ASSETS.USDC.type);
|