@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.d.cts
CHANGED
|
@@ -227,6 +227,7 @@ declare class PortfolioManager {
|
|
|
227
227
|
} & StoredPosition>;
|
|
228
228
|
recordEarn(asset: string, protocol: string, apy: number): void;
|
|
229
229
|
recordUnearn(asset: string): void;
|
|
230
|
+
closePosition(asset: string): void;
|
|
230
231
|
isEarning(asset: string): boolean;
|
|
231
232
|
getRealizedPnL(): number;
|
|
232
233
|
recordStrategyBuy(strategyKey: string, trade: InvestmentTrade): void;
|
|
@@ -235,6 +236,7 @@ declare class PortfolioManager {
|
|
|
235
236
|
asset: string;
|
|
236
237
|
} & StoredPosition>;
|
|
237
238
|
getAllStrategyKeys(): string[];
|
|
239
|
+
clearStrategy(strategyKey: string): void;
|
|
238
240
|
hasStrategyPositions(strategyKey: string): boolean;
|
|
239
241
|
}
|
|
240
242
|
|
package/dist/index.d.ts
CHANGED
|
@@ -227,6 +227,7 @@ declare class PortfolioManager {
|
|
|
227
227
|
} & StoredPosition>;
|
|
228
228
|
recordEarn(asset: string, protocol: string, apy: number): void;
|
|
229
229
|
recordUnearn(asset: string): void;
|
|
230
|
+
closePosition(asset: string): void;
|
|
230
231
|
isEarning(asset: string): boolean;
|
|
231
232
|
getRealizedPnL(): number;
|
|
232
233
|
recordStrategyBuy(strategyKey: string, trade: InvestmentTrade): void;
|
|
@@ -235,6 +236,7 @@ declare class PortfolioManager {
|
|
|
235
236
|
asset: string;
|
|
236
237
|
} & StoredPosition>;
|
|
237
238
|
getAllStrategyKeys(): string[];
|
|
239
|
+
clearStrategy(strategyKey: string): void;
|
|
238
240
|
hasStrategyPositions(strategyKey: string): boolean;
|
|
239
241
|
}
|
|
240
242
|
|
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;
|
|
@@ -2960,6 +2967,20 @@ var PortfolioManager = class {
|
|
|
2960
2967
|
this.data.positions[asset] = pos;
|
|
2961
2968
|
this.save();
|
|
2962
2969
|
}
|
|
2970
|
+
closePosition(asset) {
|
|
2971
|
+
this.load();
|
|
2972
|
+
const pos = this.data.positions[asset];
|
|
2973
|
+
if (pos) {
|
|
2974
|
+
pos.totalAmount = 0;
|
|
2975
|
+
pos.costBasis = 0;
|
|
2976
|
+
pos.avgPrice = 0;
|
|
2977
|
+
pos.earning = false;
|
|
2978
|
+
pos.earningProtocol = void 0;
|
|
2979
|
+
pos.earningApy = void 0;
|
|
2980
|
+
this.data.positions[asset] = pos;
|
|
2981
|
+
this.save();
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2963
2984
|
isEarning(asset) {
|
|
2964
2985
|
this.load();
|
|
2965
2986
|
const pos = this.data.positions[asset];
|
|
@@ -3024,6 +3045,11 @@ var PortfolioManager = class {
|
|
|
3024
3045
|
this.load();
|
|
3025
3046
|
return Object.keys(this.data.strategies);
|
|
3026
3047
|
}
|
|
3048
|
+
clearStrategy(strategyKey) {
|
|
3049
|
+
this.load();
|
|
3050
|
+
delete this.data.strategies[strategyKey];
|
|
3051
|
+
this.save();
|
|
3052
|
+
}
|
|
3027
3053
|
hasStrategyPositions(strategyKey) {
|
|
3028
3054
|
this.load();
|
|
3029
3055
|
const bucket = this.data.strategies[strategyKey];
|
|
@@ -4278,6 +4304,9 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4278
4304
|
tx: swapResult.tx,
|
|
4279
4305
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4280
4306
|
});
|
|
4307
|
+
if (params.usdAmount === "all") {
|
|
4308
|
+
this.portfolio.closePosition(params.asset);
|
|
4309
|
+
}
|
|
4281
4310
|
const updatedPos = this.portfolio.getPosition(params.asset);
|
|
4282
4311
|
const position = {
|
|
4283
4312
|
asset: params.asset,
|
|
@@ -4415,8 +4444,9 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4415
4444
|
if (!swapAdapter?.addSwapToTx) {
|
|
4416
4445
|
throw new T2000Error("PROTOCOL_UNAVAILABLE", "Swap adapter does not support composable PTB");
|
|
4417
4446
|
}
|
|
4418
|
-
|
|
4447
|
+
let swapMetas = [];
|
|
4419
4448
|
const gasResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
4449
|
+
swapMetas = [];
|
|
4420
4450
|
const tx = new Transaction();
|
|
4421
4451
|
tx.setSender(this._address);
|
|
4422
4452
|
const usdcCoins = await this._fetchCoins(SUPPORTED_ASSETS.USDC.type);
|
|
@@ -4495,12 +4525,13 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
|
|
|
4495
4525
|
let totalGas = 0;
|
|
4496
4526
|
let gasMethod = "self-funded";
|
|
4497
4527
|
for (const pos of stratPositions) {
|
|
4528
|
+
const fullAmount = pos.totalAmount;
|
|
4498
4529
|
const result = await this.investSell({ asset: pos.asset, usdAmount: "all" });
|
|
4499
4530
|
const pnl = this.portfolio.recordStrategySell(params.strategy, {
|
|
4500
4531
|
id: `strat_sell_${Date.now()}_${pos.asset}`,
|
|
4501
4532
|
type: "sell",
|
|
4502
4533
|
asset: pos.asset,
|
|
4503
|
-
amount:
|
|
4534
|
+
amount: fullAmount,
|
|
4504
4535
|
price: result.price,
|
|
4505
4536
|
usdValue: result.usdValue,
|
|
4506
4537
|
fee: result.fee,
|