@haven-fi/solauto-sdk 1.0.607 → 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,9 +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
73
  simulateRebalance(unixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number): void;
74
+ refetchPositionData(): Promise<void>;
71
75
  }
72
76
  export {};
73
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;IACjC,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,WAAW,CAAC,EAAE,SAAS,CAAC;IAC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I,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"}
@@ -100,7 +100,8 @@ class SolautoPositionEx {
100
100
  const limitsUpToDate = this.debtLiquidityUsdAvailable() !== 0 ||
101
101
  this.supplyLiquidityUsdDepositable() !== 0;
102
102
  if (limitsUpToDate) {
103
- const { debtAdjustmentUsd } = (0, rebalance_1.getDebtAdjustment)(this.state().liqThresholdBps, { supplyUsd: this.supplyUsd(), debtUsd: this.debtUsd() }, this.boostToBps(), { solauto: 50, lpBorrow: 50, flashLoan: 50 });
103
+ const { debtAdjustmentUsd } = (0, rebalance_1.getDebtAdjustment)(this.state().liqThresholdBps, { supplyUsd: this.supplyUsd(), debtUsd: this.debtUsd() }, this.boostToBps(), { solauto: 50, lpBorrow: 50, flashLoan: 50 } // TODO: get true data here instead of magic numbers
104
+ );
104
105
  const sufficientLiquidity = this.debtLiquidityUsdAvailable() * 0.95 > debtAdjustmentUsd &&
105
106
  this.supplyLiquidityUsdDepositable() * 0.95 > debtAdjustmentUsd;
106
107
  if (!sufficientLiquidity) {
@@ -146,25 +147,49 @@ class SolautoPositionEx {
146
147
  const newState = await (0, utils_1.positionStateWithLatestPrices)(this.state(), supplyPrice, debtPrice);
147
148
  return newState.liqUtilizationRateBps - oldState.liqUtilizationRateBps;
148
149
  }
149
- async updateWithLatestPrices(supplyPrice, debtPrice) {
150
- this._data.state = await (0, utils_1.positionStateWithLatestPrices)(this.state(), supplyPrice, debtPrice);
150
+ updateSupply(newSupplyUsd, supplyPrice) {
151
+ this._data.state.supply.amountUsed.baseAmountUsdValue =
152
+ (0, utils_1.toRoundedUsdValue)(newSupplyUsd);
153
+ this._data.state.supply.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newSupplyUsd / (supplyPrice ?? (0, utils_1.safeGetPrice)(this.supplyMint()) ?? 0), this.supplyMintInfo().decimals);
151
154
  }
152
- async refetchPositionData() {
153
- this._data = await (0, generated_1.fetchSolautoPosition)(this.umi, (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(this.publicKey));
155
+ updateDebt(newDebtUsd, debtPrice) {
156
+ this._data.state.debt.amountUsed.baseAmountUsdValue =
157
+ (0, utils_1.toRoundedUsdValue)(newDebtUsd);
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();
154
182
  }
155
183
  simulateRebalance(unixTime, supplyPrice, debtPrice, targetLiqUtilizationRateBps) {
156
184
  this._data.state.lastRefreshed = BigInt(unixTime);
157
185
  const rebalance = (0, rebalance_1.getRebalanceValues)(this, targetLiqUtilizationRateBps, rebalance_1.SolautoFeesBps.create(true, targetLiqUtilizationRateBps, this.netWorthUsd()));
158
- const newDebtUsd = rebalance.endResult.debtUsd;
159
- const newSupplyUsd = rebalance.endResult.supplyUsd;
160
- this._data.state.debt.amountUsed.baseAmountUsdValue =
161
- (0, utils_1.toRoundedUsdValue)(newDebtUsd);
162
- this._data.state.debt.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newDebtUsd / debtPrice, this.debtMintInfo().decimals);
163
- this._data.state.supply.amountUsed.baseAmountUsdValue =
164
- (0, utils_1.toRoundedUsdValue)(newSupplyUsd);
165
- this._data.state.supply.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newSupplyUsd / supplyPrice, this.supplyMintInfo().decimals);
166
- this._data.state.netWorth.baseAmountUsdValue = (0, utils_1.toRoundedUsdValue)(newSupplyUsd - newDebtUsd);
167
- this._data.state.netWorth.baseUnit = (0, utils_1.toBaseUnit)((newSupplyUsd - newDebtUsd) / supplyPrice, this.supplyMintInfo().decimals);
186
+ this.updateSupply(rebalance.endResult.supplyUsd, supplyPrice);
187
+ this.updateDebt(rebalance.endResult.debtUsd, 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));
168
193
  }
169
194
  }
170
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,EACN,kBAAkB,EAClB,GAAG,EAEH,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAYlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAKlE,wBAAgB,mBAAmB,IAAI,SAAS,CAG/C;AA0MD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB;;;;IAkB7D;AAED,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,EACtB,GAAG,EAAE,kBAAkB,EAAE,EACzB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CA+F/B"}
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;AAGzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEH,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAYlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAKlE,wBAAgB,mBAAmB,IAAI,SAAS,CAG/C;AAkND,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB;;;;IAkB7D;AAED,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,EACtB,GAAG,EAAE,kBAAkB,EAAE,EACzB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,MAAM,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.607",
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,
@@ -213,7 +215,7 @@ export abstract class SolautoPositionEx {
213
215
  this.state().liqThresholdBps,
214
216
  { supplyUsd: this.supplyUsd(), debtUsd: this.debtUsd() },
215
217
  this.boostToBps(),
216
- { solauto: 50, lpBorrow: 50, flashLoan: 50 }, // TODO: get true data here instead of magic numbers
218
+ { solauto: 50, lpBorrow: 50, flashLoan: 50 } // TODO: get true data here instead of magic numbers
217
219
  );
218
220
 
219
221
  const sufficientLiquidity =
@@ -289,21 +291,59 @@ 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
 
312
+ updateNetWorth(supplyPrice?: number) {
313
+ const netWorthUsd = this.supplyUsd() - this.debtUsd();
314
+ this._data.state.netWorth.baseAmountUsdValue =
315
+ toRoundedUsdValue(netWorthUsd);
316
+ this._data.state.netWorth.baseUnit = toBaseUnit(
317
+ netWorthUsd / (supplyPrice ?? safeGetPrice(this.supplyMint()) ?? 0),
318
+ this.supplyMintInfo().decimals
319
+ );
320
+ }
321
+
322
+ updateLiqUtilizationRate() {
323
+ this._data.state.liqUtilizationRateBps = getLiqUtilzationRateBps(
324
+ this.supplyUsd(),
325
+ this.debtUsd(),
326
+ this.state().liqThresholdBps
327
+ );
328
+ }
329
+
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();
345
+ }
346
+
307
347
  simulateRebalance(
308
348
  unixTime: number,
309
349
  supplyPrice: number,
@@ -320,30 +360,16 @@ export abstract class SolautoPositionEx {
320
360
  this.netWorthUsd()
321
361
  )
322
362
  );
363
+ this.updateSupply(rebalance.endResult.supplyUsd, supplyPrice);
364
+ this.updateDebt(rebalance.endResult.debtUsd, debtPrice);
365
+ this.updateNetWorth(supplyPrice);
366
+ this.updateLiqUtilizationRate();
367
+ }
323
368
 
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
369
+ async refetchPositionData() {
370
+ this._data = await fetchSolautoPosition(
371
+ this.umi,
372
+ fromWeb3JsPublicKey(this.publicKey)
347
373
  );
348
374
  }
349
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;