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