@haven-fi/solauto-sdk 1.0.593 → 1.0.595

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.
@@ -1,3 +1,4 @@
1
1
  export * from "./rebalanceTxBuilder";
2
2
  export * from "./rebalanceValues";
3
+ export * from "./solautoFees";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC"}
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./rebalanceTxBuilder"), exports);
18
18
  __exportStar(require("./rebalanceValues"), exports);
19
+ __exportStar(require("./solautoFees"), exports);
@@ -67,6 +67,7 @@ export declare abstract class SolautoPositionEx {
67
67
  utilizationRateBpsDrift(): Promise<number>;
68
68
  updateWithLatestPrices(supplyPrice?: number, debtPrice?: number): Promise<void>;
69
69
  refetchPositionData(): Promise<void>;
70
+ simulateRebalance(unixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number): void;
70
71
  }
71
72
  export {};
72
73
  //# sourceMappingURL=solautoPositionEx.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"solautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/solautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,WAAW,EAEX,eAAe,EACf,aAAa,EACb,eAAe,EACf,yBAAyB,EAC1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YAAY;IAMZ,QAAQ;IAIR,WAAW;IAIX,WAAW;IAIX,SAAS;IAIT,SAAS;IAIT,OAAO;IAIP,6BAA6B;IAI7B,yBAAyB;IAIzB,QAAQ,CAAC,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9D,QAAQ,CAAC,0BAA0B,IAAI,MAAM;IAC7C,QAAQ,CAAC,wBAAwB,IAAI,MAAM;IAC3C,QAAQ,CAAC,sBAAsB,IAAI,MAAM;IAEzC,0BAA0B;IA0B1B,oBAAoB,CAAC,oBAAoB,SAAI,GAAG,eAAe,GAAG,SAAS;IAqB3E,kBAAkB,IAAI,OAAO;IAS7B,SAAS,CAAC,uBAAuB;IAWjC,QAAQ,CAAC,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAExC,uBAAuB;IAiBvB,sBAAsB,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;IAQ/D,mBAAmB;IAOzB,iBAAiB,CACf,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM;CAsCvC"}
@@ -153,5 +153,19 @@ class SolautoPositionEx {
153
153
  async refetchPositionData() {
154
154
  this._data = await (0, generated_1.fetchSolautoPosition)(this.umi, (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(this.publicKey));
155
155
  }
156
+ simulateRebalance(unixTime, supplyPrice, debtPrice, targetLiqUtilizationRateBps) {
157
+ this._data.state.lastRefreshed = BigInt(unixTime);
158
+ const rebalance = (0, rebalance_1.getRebalanceValues)(this, targetLiqUtilizationRateBps, rebalance_1.SolautoFeesBps.create(true, targetLiqUtilizationRateBps, this.netWorthUsd()));
159
+ const newDebtUsd = rebalance.endResult.debtUsd;
160
+ const newSupplyUsd = rebalance.endResult.supplyUsd;
161
+ this._data.state.debt.amountUsed.baseAmountUsdValue =
162
+ (0, utils_1.toRoundedUsdValue)(newDebtUsd);
163
+ this._data.state.debt.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newDebtUsd / debtPrice, this.debtMintInfo().decimals);
164
+ this._data.state.supply.amountUsed.baseAmountUsdValue =
165
+ (0, utils_1.toRoundedUsdValue)(newSupplyUsd);
166
+ this._data.state.supply.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newSupplyUsd / supplyPrice, this.supplyMintInfo().decimals);
167
+ this._data.state.netWorth.baseAmountUsdValue = (0, utils_1.toRoundedUsdValue)(newSupplyUsd - newDebtUsd);
168
+ this._data.state.netWorth.baseUnit = (0, utils_1.toBaseUnit)(newSupplyUsd - newDebtUsd / supplyPrice, this.supplyMintInfo().decimals);
169
+ }
156
170
  }
157
171
  exports.SolautoPositionEx = SolautoPositionEx;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.593",
3
+ "version": "1.0.595",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Typescript SDK for the Solauto program on the Solana blockchain",
@@ -1,2 +1,3 @@
1
1
  export * from "./rebalanceTxBuilder";
2
2
  export * from "./rebalanceValues";
3
+ export * from "./solautoFees";
@@ -25,10 +25,16 @@ import {
25
25
  safeGetPrice,
26
26
  solautoStrategyName,
27
27
  supplyLiquidityUsdDepositable,
28
+ toBaseUnit,
28
29
  tokenInfo,
30
+ toRoundedUsdValue,
29
31
  } from "../utils";
30
32
  import { RebalanceAction } from "../types";
31
- import { getDebtAdjustment } from "../services/rebalance";
33
+ import {
34
+ getDebtAdjustment,
35
+ getRebalanceValues,
36
+ SolautoFeesBps,
37
+ } from "../services/rebalance";
32
38
  import { MIN_POSITION_STATE_FRESHNESS_SECS, TokenInfo } from "../constants";
33
39
  import {
34
40
  fromWeb3JsPublicKey,
@@ -297,4 +303,47 @@ export abstract class SolautoPositionEx {
297
303
  fromWeb3JsPublicKey(this.publicKey)
298
304
  );
299
305
  }
306
+
307
+ simulateRebalance(
308
+ unixTime: number,
309
+ supplyPrice: number,
310
+ debtPrice: number,
311
+ targetLiqUtilizationRateBps?: number
312
+ ) {
313
+ this._data.state.lastRefreshed = BigInt(unixTime);
314
+ const rebalance = getRebalanceValues(
315
+ this,
316
+ targetLiqUtilizationRateBps,
317
+ SolautoFeesBps.create(
318
+ true,
319
+ targetLiqUtilizationRateBps,
320
+ this.netWorthUsd()
321
+ )
322
+ );
323
+
324
+ const newDebtUsd = rebalance.endResult.debtUsd;
325
+ const newSupplyUsd = rebalance.endResult.supplyUsd;
326
+
327
+ this._data.state.debt.amountUsed.baseAmountUsdValue =
328
+ toRoundedUsdValue(newDebtUsd);
329
+ this._data.state.debt.amountUsed.baseUnit = toBaseUnit(
330
+ newDebtUsd / debtPrice,
331
+ this.debtMintInfo().decimals
332
+ );
333
+
334
+ this._data.state.supply.amountUsed.baseAmountUsdValue =
335
+ toRoundedUsdValue(newSupplyUsd);
336
+ this._data.state.supply.amountUsed.baseUnit = toBaseUnit(
337
+ newSupplyUsd / supplyPrice,
338
+ this.supplyMintInfo().decimals
339
+ );
340
+
341
+ this._data.state.netWorth.baseAmountUsdValue = toRoundedUsdValue(
342
+ newSupplyUsd - newDebtUsd
343
+ );
344
+ this._data.state.netWorth.baseUnit = toBaseUnit(
345
+ newSupplyUsd - newDebtUsd / supplyPrice,
346
+ this.supplyMintInfo().decimals
347
+ );
348
+ }
300
349
  }