@t2000/sdk 0.16.17 → 0.16.19

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.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;
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;
package/dist/index.js CHANGED
@@ -2960,6 +2960,20 @@ var PortfolioManager = class {
2960
2960
  this.data.positions[asset] = pos;
2961
2961
  this.save();
2962
2962
  }
2963
+ closePosition(asset) {
2964
+ this.load();
2965
+ const pos = this.data.positions[asset];
2966
+ if (pos) {
2967
+ pos.totalAmount = 0;
2968
+ pos.costBasis = 0;
2969
+ pos.avgPrice = 0;
2970
+ pos.earning = false;
2971
+ pos.earningProtocol = void 0;
2972
+ pos.earningApy = void 0;
2973
+ this.data.positions[asset] = pos;
2974
+ this.save();
2975
+ }
2976
+ }
2963
2977
  isEarning(asset) {
2964
2978
  this.load();
2965
2979
  const pos = this.data.positions[asset];
@@ -4278,6 +4292,9 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
4278
4292
  tx: swapResult.tx,
4279
4293
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
4280
4294
  });
4295
+ if (params.usdAmount === "all") {
4296
+ this.portfolio.closePosition(params.asset);
4297
+ }
4281
4298
  const updatedPos = this.portfolio.getPosition(params.asset);
4282
4299
  const position = {
4283
4300
  asset: params.asset,
@@ -4495,12 +4512,13 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
4495
4512
  let totalGas = 0;
4496
4513
  let gasMethod = "self-funded";
4497
4514
  for (const pos of stratPositions) {
4515
+ const fullAmount = pos.totalAmount;
4498
4516
  const result = await this.investSell({ asset: pos.asset, usdAmount: "all" });
4499
4517
  const pnl = this.portfolio.recordStrategySell(params.strategy, {
4500
4518
  id: `strat_sell_${Date.now()}_${pos.asset}`,
4501
4519
  type: "sell",
4502
4520
  asset: pos.asset,
4503
- amount: result.amount,
4521
+ amount: fullAmount,
4504
4522
  price: result.price,
4505
4523
  usdValue: result.usdValue,
4506
4524
  fee: result.fee,