@t2000/sdk 0.16.18 → 0.16.20
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 +34 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +34 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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;
|
|
@@ -2962,6 +2969,20 @@ var PortfolioManager = class {
|
|
|
2962
2969
|
this.data.positions[asset] = pos;
|
|
2963
2970
|
this.save();
|
|
2964
2971
|
}
|
|
2972
|
+
closePosition(asset) {
|
|
2973
|
+
this.load();
|
|
2974
|
+
const pos = this.data.positions[asset];
|
|
2975
|
+
if (pos) {
|
|
2976
|
+
pos.totalAmount = 0;
|
|
2977
|
+
pos.costBasis = 0;
|
|
2978
|
+
pos.avgPrice = 0;
|
|
2979
|
+
pos.earning = false;
|
|
2980
|
+
pos.earningProtocol = void 0;
|
|
2981
|
+
pos.earningApy = void 0;
|
|
2982
|
+
this.data.positions[asset] = pos;
|
|
2983
|
+
this.save();
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2965
2986
|
isEarning(asset) {
|
|
2966
2987
|
this.load();
|
|
2967
2988
|
const pos = this.data.positions[asset];
|
|
@@ -3026,6 +3047,11 @@ var PortfolioManager = class {
|
|
|
3026
3047
|
this.load();
|
|
3027
3048
|
return Object.keys(this.data.strategies);
|
|
3028
3049
|
}
|
|
3050
|
+
clearStrategy(strategyKey) {
|
|
3051
|
+
this.load();
|
|
3052
|
+
delete this.data.strategies[strategyKey];
|
|
3053
|
+
this.save();
|
|
3054
|
+
}
|
|
3029
3055
|
hasStrategyPositions(strategyKey) {
|
|
3030
3056
|
this.load();
|
|
3031
3057
|
const bucket = this.data.strategies[strategyKey];
|
|
@@ -4280,6 +4306,9 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4280
4306
|
tx: swapResult.tx,
|
|
4281
4307
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4282
4308
|
});
|
|
4309
|
+
if (params.usdAmount === "all") {
|
|
4310
|
+
this.portfolio.closePosition(params.asset);
|
|
4311
|
+
}
|
|
4283
4312
|
const updatedPos = this.portfolio.getPosition(params.asset);
|
|
4284
4313
|
const position = {
|
|
4285
4314
|
asset: params.asset,
|
|
@@ -4417,8 +4446,9 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4417
4446
|
if (!swapAdapter?.addSwapToTx) {
|
|
4418
4447
|
throw new T2000Error("PROTOCOL_UNAVAILABLE", "Swap adapter does not support composable PTB");
|
|
4419
4448
|
}
|
|
4420
|
-
|
|
4449
|
+
let swapMetas = [];
|
|
4421
4450
|
const gasResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
4451
|
+
swapMetas = [];
|
|
4422
4452
|
const tx = new transactions.Transaction();
|
|
4423
4453
|
tx.setSender(this._address);
|
|
4424
4454
|
const usdcCoins = await this._fetchCoins(SUPPORTED_ASSETS.USDC.type);
|
|
@@ -4497,12 +4527,13 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4497
4527
|
let totalGas = 0;
|
|
4498
4528
|
let gasMethod = "self-funded";
|
|
4499
4529
|
for (const pos of stratPositions) {
|
|
4530
|
+
const fullAmount = pos.totalAmount;
|
|
4500
4531
|
const result = await this.investSell({ asset: pos.asset, usdAmount: "all" });
|
|
4501
4532
|
const pnl = this.portfolio.recordStrategySell(params.strategy, {
|
|
4502
4533
|
id: `strat_sell_${Date.now()}_${pos.asset}`,
|
|
4503
4534
|
type: "sell",
|
|
4504
4535
|
asset: pos.asset,
|
|
4505
|
-
amount:
|
|
4536
|
+
amount: fullAmount,
|
|
4506
4537
|
price: result.price,
|
|
4507
4538
|
usdValue: result.usdValue,
|
|
4508
4539
|
fee: result.fee,
|