@haven-fi/solauto-sdk 1.0.608 → 1.0.609

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.
@@ -65,12 +65,13 @@ export declare abstract class SolautoPositionEx {
65
65
  protected canRefreshPositionState(): boolean;
66
66
  abstract refreshPositionState(): Promise<void>;
67
67
  utilizationRateBpsDrift(): Promise<number>;
68
+ updateSupply(newSupplyUsd: number, supplyPrice?: number): void;
69
+ updateDebt(newDebtUsd: number, debtPrice?: number): void;
70
+ updateNetWorth(supplyPrice?: number): void;
71
+ updateLiqUtilizationRate(): void;
68
72
  updateWithLatestPrices(supplyPrice?: number, debtPrice?: number): Promise<void>;
69
- refetchPositionData(): Promise<void>;
70
- updateNetWorth(supplyPrice: number, debtPrice: number): void;
71
- updateSupply(newSupplyUsd: number, supplyPrice: number): void;
72
- updateDebt(newDebtUsd: number, debtPrice: number): void;
73
73
  simulateRebalance(unixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number): void;
74
+ refetchPositionData(): Promise<void>;
74
75
  }
75
76
  export {};
76
77
  //# 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,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAQL,cAAc,EAYf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAM3C,OAAO,EAAqC,SAAS,EAAE,MAAM,cAAc,CAAC;AAM5E,MAAM,WAAW,kBAAkB;IACjC,eAAe,EAAE,eAAe,CAAC;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,YAAY;IAIZ,UAAU;IAOV,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;IAiB7B,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;IASvD,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;IASjD,cAAc,CAAC,WAAW,CAAC,EAAE,MAAM;IAUnC,wBAAwB;IAQlB,sBAAsB,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;IAiBrE,iBAAiB,CACf,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM;IAkBhC,mBAAmB;CAM1B"}
@@ -147,34 +147,49 @@ class SolautoPositionEx {
147
147
  const newState = await (0, utils_1.positionStateWithLatestPrices)(this.state(), supplyPrice, debtPrice);
148
148
  return newState.liqUtilizationRateBps - oldState.liqUtilizationRateBps;
149
149
  }
150
- async updateWithLatestPrices(supplyPrice, debtPrice) {
151
- this._data.state = await (0, utils_1.positionStateWithLatestPrices)(this.state(), supplyPrice, debtPrice);
152
- }
153
- async refetchPositionData() {
154
- this._data = await (0, generated_1.fetchSolautoPosition)(this.umi, (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(this.publicKey));
155
- }
156
- updateNetWorth(supplyPrice, debtPrice) {
157
- const netWorthUsd = this.supplyUsd() - this.debtUsd();
158
- this._data.state.netWorth.baseAmountUsdValue =
159
- (0, utils_1.toRoundedUsdValue)(netWorthUsd);
160
- this._data.state.netWorth.baseUnit = (0, utils_1.toBaseUnit)(netWorthUsd / supplyPrice, this.supplyMintInfo().decimals);
161
- }
162
150
  updateSupply(newSupplyUsd, supplyPrice) {
163
151
  this._data.state.supply.amountUsed.baseAmountUsdValue =
164
152
  (0, utils_1.toRoundedUsdValue)(newSupplyUsd);
165
- this._data.state.supply.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newSupplyUsd / supplyPrice, this.supplyMintInfo().decimals);
153
+ this._data.state.supply.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newSupplyUsd / (supplyPrice ?? (0, utils_1.safeGetPrice)(this.supplyMint()) ?? 0), this.supplyMintInfo().decimals);
166
154
  }
167
155
  updateDebt(newDebtUsd, debtPrice) {
168
156
  this._data.state.debt.amountUsed.baseAmountUsdValue =
169
157
  (0, utils_1.toRoundedUsdValue)(newDebtUsd);
170
- this._data.state.debt.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newDebtUsd / debtPrice, this.debtMintInfo().decimals);
158
+ this._data.state.debt.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newDebtUsd / (debtPrice ?? (0, utils_1.safeGetPrice)(this.debtMint()) ?? 0), this.debtMintInfo().decimals);
159
+ }
160
+ updateNetWorth(supplyPrice) {
161
+ const netWorthUsd = this.supplyUsd() - this.debtUsd();
162
+ this._data.state.netWorth.baseAmountUsdValue =
163
+ (0, utils_1.toRoundedUsdValue)(netWorthUsd);
164
+ this._data.state.netWorth.baseUnit = (0, utils_1.toBaseUnit)(netWorthUsd / (supplyPrice ?? (0, utils_1.safeGetPrice)(this.supplyMint()) ?? 0), this.supplyMintInfo().decimals);
165
+ }
166
+ updateLiqUtilizationRate() {
167
+ this._data.state.liqUtilizationRateBps = (0, utils_1.getLiqUtilzationRateBps)(this.supplyUsd(), this.debtUsd(), this.state().liqThresholdBps);
168
+ }
169
+ async updateWithLatestPrices(supplyPrice, debtPrice) {
170
+ if (!supplyPrice || !debtPrice) {
171
+ [supplyPrice, debtPrice] = await (0, utils_1.fetchTokenPrices)([
172
+ this.supplyMint(),
173
+ this.debtMint(),
174
+ ]);
175
+ }
176
+ const supplyUsd = this.totalSupply() * supplyPrice;
177
+ const debtUsd = this.totalDebt() * debtPrice;
178
+ this.updateSupply(supplyUsd, supplyPrice);
179
+ this.updateDebt(debtUsd, debtPrice);
180
+ this.updateNetWorth(supplyPrice);
181
+ this.updateLiqUtilizationRate();
171
182
  }
172
183
  simulateRebalance(unixTime, supplyPrice, debtPrice, targetLiqUtilizationRateBps) {
173
184
  this._data.state.lastRefreshed = BigInt(unixTime);
174
185
  const rebalance = (0, rebalance_1.getRebalanceValues)(this, targetLiqUtilizationRateBps, rebalance_1.SolautoFeesBps.create(true, targetLiqUtilizationRateBps, this.netWorthUsd()));
175
186
  this.updateSupply(rebalance.endResult.supplyUsd, supplyPrice);
176
187
  this.updateDebt(rebalance.endResult.debtUsd, debtPrice);
177
- this.updateNetWorth(supplyPrice, debtPrice);
188
+ this.updateNetWorth(supplyPrice);
189
+ this.updateLiqUtilizationRate();
190
+ }
191
+ async refetchPositionData() {
192
+ this._data = await (0, generated_1.fetchSolautoPosition)(this.umi, (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(this.publicKey));
178
193
  }
179
194
  }
180
195
  exports.SolautoPositionEx = SolautoPositionEx;
@@ -1 +1 @@
1
- {"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAIV,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EACL,MAAM,EAC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AAM,EAAE,GAAG,SAAS,CAAC,CA+F/B"}
@@ -119,7 +119,13 @@ async function pollBundleStatus(umi, bundleId, interval = 1000, timeout = 40000)
119
119
  const endTime = Date.now() + timeout;
120
120
  while (Date.now() < endTime) {
121
121
  await new Promise((resolve) => setTimeout(resolve, interval));
122
- const statuses = await getBundleStatus(umi, bundleId);
122
+ const statuses = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
123
+ const resp = await getBundleStatus(umi, bundleId);
124
+ if (resp?.value?.length > 0 && resp.value[0] === null) {
125
+ throw new Error("No confirmation status");
126
+ }
127
+ return resp;
128
+ }, 3, 250);
123
129
  if (statuses?.value?.length > 0) {
124
130
  (0, generalUtils_1.consoleLog)("Statuses:", statuses);
125
131
  const status = statuses.value[0].confirmation_status;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.608",
3
+ "version": "1.0.609",
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",
@@ -19,6 +19,8 @@ import {
19
19
  ContextUpdates,
20
20
  currentUnixSeconds,
21
21
  debtLiquidityUsdAvailable,
22
+ fetchTokenPrices,
23
+ getLiqUtilzationRateBps,
22
24
  maxBoostToBps,
23
25
  maxRepayToBps,
24
26
  positionStateWithLatestPrices,
@@ -289,47 +291,57 @@ export abstract class SolautoPositionEx {
289
291
  return newState.liqUtilizationRateBps - oldState.liqUtilizationRateBps;
290
292
  }
291
293
 
292
- async updateWithLatestPrices(supplyPrice?: number, debtPrice?: number) {
293
- this._data.state = await positionStateWithLatestPrices(
294
- this.state(),
295
- supplyPrice,
296
- debtPrice
294
+ updateSupply(newSupplyUsd: number, supplyPrice?: number) {
295
+ this._data.state.supply.amountUsed.baseAmountUsdValue =
296
+ toRoundedUsdValue(newSupplyUsd);
297
+ this._data.state.supply.amountUsed.baseUnit = toBaseUnit(
298
+ newSupplyUsd / (supplyPrice ?? safeGetPrice(this.supplyMint()) ?? 0),
299
+ this.supplyMintInfo().decimals
297
300
  );
298
301
  }
299
302
 
300
- async refetchPositionData() {
301
- this._data = await fetchSolautoPosition(
302
- this.umi,
303
- fromWeb3JsPublicKey(this.publicKey)
303
+ updateDebt(newDebtUsd: number, debtPrice?: number) {
304
+ this._data.state.debt.amountUsed.baseAmountUsdValue =
305
+ toRoundedUsdValue(newDebtUsd);
306
+ this._data.state.debt.amountUsed.baseUnit = toBaseUnit(
307
+ newDebtUsd / (debtPrice ?? safeGetPrice(this.debtMint()) ?? 0),
308
+ this.debtMintInfo().decimals
304
309
  );
305
310
  }
306
311
 
307
- updateNetWorth(supplyPrice: number, debtPrice: number) {
312
+ updateNetWorth(supplyPrice?: number) {
308
313
  const netWorthUsd = this.supplyUsd() - this.debtUsd();
309
314
  this._data.state.netWorth.baseAmountUsdValue =
310
315
  toRoundedUsdValue(netWorthUsd);
311
316
  this._data.state.netWorth.baseUnit = toBaseUnit(
312
- netWorthUsd / supplyPrice,
317
+ netWorthUsd / (supplyPrice ?? safeGetPrice(this.supplyMint()) ?? 0),
313
318
  this.supplyMintInfo().decimals
314
319
  );
315
320
  }
316
321
 
317
- updateSupply(newSupplyUsd: number, supplyPrice: number) {
318
- this._data.state.supply.amountUsed.baseAmountUsdValue =
319
- toRoundedUsdValue(newSupplyUsd);
320
- this._data.state.supply.amountUsed.baseUnit = toBaseUnit(
321
- newSupplyUsd / supplyPrice,
322
- this.supplyMintInfo().decimals
322
+ updateLiqUtilizationRate() {
323
+ this._data.state.liqUtilizationRateBps = getLiqUtilzationRateBps(
324
+ this.supplyUsd(),
325
+ this.debtUsd(),
326
+ this.state().liqThresholdBps
323
327
  );
324
328
  }
325
329
 
326
- updateDebt(newDebtUsd: number, debtPrice: number) {
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
- );
330
+ async updateWithLatestPrices(supplyPrice?: number, debtPrice?: number) {
331
+ if (!supplyPrice || !debtPrice) {
332
+ [supplyPrice, debtPrice] = await fetchTokenPrices([
333
+ this.supplyMint(),
334
+ this.debtMint(),
335
+ ]);
336
+ }
337
+
338
+ const supplyUsd = this.totalSupply() * supplyPrice;
339
+ const debtUsd = this.totalDebt() * debtPrice;
340
+
341
+ this.updateSupply(supplyUsd, supplyPrice);
342
+ this.updateDebt(debtUsd, debtPrice);
343
+ this.updateNetWorth(supplyPrice);
344
+ this.updateLiqUtilizationRate();
333
345
  }
334
346
 
335
347
  simulateRebalance(
@@ -350,6 +362,14 @@ export abstract class SolautoPositionEx {
350
362
  );
351
363
  this.updateSupply(rebalance.endResult.supplyUsd, supplyPrice);
352
364
  this.updateDebt(rebalance.endResult.debtUsd, debtPrice);
353
- this.updateNetWorth(supplyPrice, debtPrice);
365
+ this.updateNetWorth(supplyPrice);
366
+ this.updateLiqUtilizationRate();
367
+ }
368
+
369
+ async refetchPositionData() {
370
+ this._data = await fetchSolautoPosition(
371
+ this.umi,
372
+ fromWeb3JsPublicKey(this.publicKey)
373
+ );
354
374
  }
355
375
  }
@@ -6,9 +6,7 @@ import {
6
6
  VersionedTransaction,
7
7
  } from "@solana/web3.js";
8
8
  import { toWeb3JsTransaction } from "@metaplex-foundation/umi-web3js-adapters";
9
- import {
10
- JITO_TIP_ACCOUNTS,
11
- } from "../constants/solautoConstants";
9
+ import { JITO_TIP_ACCOUNTS } from "../constants/solautoConstants";
12
10
  import {
13
11
  Signer,
14
12
  TransactionBuilder,
@@ -191,7 +189,15 @@ async function pollBundleStatus(
191
189
  const endTime = Date.now() + timeout;
192
190
  while (Date.now() < endTime) {
193
191
  await new Promise((resolve) => setTimeout(resolve, interval));
194
- const statuses = await getBundleStatus(umi, bundleId);
192
+
193
+ const statuses = await retryWithExponentialBackoff(async () => {
194
+ const resp = await getBundleStatus(umi, bundleId);
195
+ if (resp?.value?.length > 0 && resp.value[0] === null) {
196
+ throw new Error("No confirmation status");
197
+ }
198
+ return resp;
199
+ }, 3, 250);
200
+
195
201
  if (statuses?.value?.length > 0) {
196
202
  consoleLog("Statuses:", statuses);
197
203
  const status = statuses.value[0].confirmation_status;