@haven-fi/solauto-sdk 1.0.629 → 1.0.631

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.
Files changed (72) hide show
  1. package/README.md +32 -2
  2. package/dist/constants/marginfiAccounts.d.ts.map +1 -1
  3. package/dist/constants/solautoConstants.d.ts +2 -1
  4. package/dist/constants/solautoConstants.d.ts.map +1 -1
  5. package/dist/generated/instructions/marginfiRebalance.d.ts +5 -3
  6. package/dist/generated/instructions/marginfiRebalance.d.ts.map +1 -1
  7. package/dist/generated/instructions/marginfiRebalance.js +2 -1
  8. package/dist/generated/instructions/marginfiRefreshData.d.ts +7 -2
  9. package/dist/generated/instructions/marginfiRefreshData.d.ts.map +1 -1
  10. package/dist/generated/instructions/marginfiRefreshData.js +8 -4
  11. package/dist/generated/types/index.d.ts +1 -0
  12. package/dist/generated/types/index.d.ts.map +1 -1
  13. package/dist/generated/types/index.js +1 -0
  14. package/dist/generated/types/priceType.d.ts +15 -0
  15. package/dist/generated/types/priceType.d.ts.map +1 -0
  16. package/dist/generated/types/priceType.js +22 -0
  17. package/dist/services/rebalance/rebalanceSwapManager.d.ts.map +1 -1
  18. package/dist/services/rebalance/rebalanceSwapManager.js +8 -8
  19. package/dist/services/rebalance/rebalanceTxBuilder.d.ts +2 -0
  20. package/dist/services/rebalance/rebalanceTxBuilder.d.ts.map +1 -1
  21. package/dist/services/rebalance/rebalanceTxBuilder.js +21 -10
  22. package/dist/services/rebalance/rebalanceValues.d.ts +2 -2
  23. package/dist/services/rebalance/rebalanceValues.d.ts.map +1 -1
  24. package/dist/services/rebalance/rebalanceValues.js +17 -17
  25. package/dist/services/solauto/solautoClient.d.ts +2 -2
  26. package/dist/services/solauto/solautoClient.d.ts.map +1 -1
  27. package/dist/services/solauto/solautoClient.js +27 -28
  28. package/dist/services/solauto/solautoMarginfiClient.d.ts +2 -2
  29. package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
  30. package/dist/services/solauto/solautoMarginfiClient.js +12 -10
  31. package/dist/services/transactions/transactionUtils.d.ts.map +1 -1
  32. package/dist/services/transactions/transactionUtils.js +10 -9
  33. package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts +3 -3
  34. package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -1
  35. package/dist/solautoPosition/marginfiSolautoPositionEx.js +9 -9
  36. package/dist/solautoPosition/solautoPositionEx.d.ts +44 -33
  37. package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
  38. package/dist/solautoPosition/solautoPositionEx.js +112 -90
  39. package/dist/types/solauto.d.ts +2 -1
  40. package/dist/types/solauto.d.ts.map +1 -1
  41. package/dist/utils/instructionUtils.js +2 -2
  42. package/dist/utils/marginfiUtils.d.ts +2 -2
  43. package/dist/utils/marginfiUtils.d.ts.map +1 -1
  44. package/dist/utils/marginfiUtils.js +5 -5
  45. package/dist/utils/priceUtils.d.ts +11 -5
  46. package/dist/utils/priceUtils.d.ts.map +1 -1
  47. package/dist/utils/priceUtils.js +45 -21
  48. package/local/logPositions.ts +12 -12
  49. package/local/shared.ts +1 -1
  50. package/local/txSandbox.ts +29 -27
  51. package/local/updateMarginfiLUT.ts +13 -6
  52. package/package.json +1 -1
  53. package/src/constants/marginfiAccounts.ts +0 -1
  54. package/src/constants/solautoConstants.ts +1 -1
  55. package/src/generated/instructions/marginfiRebalance.ts +9 -3
  56. package/src/generated/instructions/marginfiRefreshData.ts +27 -7
  57. package/src/generated/types/index.ts +1 -0
  58. package/src/generated/types/priceType.ts +22 -0
  59. package/src/services/rebalance/rebalanceSwapManager.ts +8 -12
  60. package/src/services/rebalance/rebalanceTxBuilder.ts +41 -11
  61. package/src/services/rebalance/rebalanceValues.ts +22 -16
  62. package/src/services/solauto/solautoClient.ts +30 -30
  63. package/src/services/solauto/solautoMarginfiClient.ts +13 -10
  64. package/src/services/transactions/transactionUtils.ts +11 -9
  65. package/src/solautoPosition/marginfiSolautoPositionEx.ts +11 -10
  66. package/src/solautoPosition/solautoPositionEx.ts +145 -117
  67. package/src/types/solauto.ts +2 -0
  68. package/src/utils/instructionUtils.ts +2 -2
  69. package/src/utils/marginfiUtils.ts +12 -8
  70. package/src/utils/priceUtils.ts +66 -22
  71. package/tests/transactions/shared.ts +2 -5
  72. package/tests/unit/rebalanceCalculations.ts +9 -12
@@ -9,6 +9,7 @@ import {
9
9
  fetchSolautoPosition,
10
10
  LendingPlatform,
11
11
  PositionState,
12
+ PriceType,
12
13
  SolautoPosition,
13
14
  SolautoSettingsParameters,
14
15
  } from "../generated";
@@ -27,6 +28,7 @@ import {
27
28
  fetchTokenPrices,
28
29
  getLiqUtilzationRateBps,
29
30
  maxBoostToBps,
31
+ maxRepayFromBps,
30
32
  maxRepayToBps,
31
33
  positionStateWithLatestPrices,
32
34
  safeGetPrice,
@@ -97,155 +99,175 @@ export abstract class SolautoPositionEx {
97
99
 
98
100
  abstract lendingPool(): Promise<PublicKey>;
99
101
 
100
- exists() {
102
+ get exists() {
101
103
  return this._data.position !== undefined;
102
104
  }
103
105
 
104
- authority() {
106
+ get authority() {
105
107
  return this._data.authority
106
108
  ? toWeb3JsPublicKey(this._data.authority)
107
- : undefined;
109
+ : PublicKey.default;
108
110
  }
109
111
 
110
- positionId() {
112
+ get positionId() {
111
113
  return this._data.positionId ? this._data.positionId[0] : undefined;
112
114
  }
113
115
 
114
- strategyName() {
115
- return solautoStrategyName(
116
- toWeb3JsPublicKey(this.state().supply.mint),
117
- toWeb3JsPublicKey(this.state().debt.mint)
116
+ get positionType() {
117
+ return this._data.positionType;
118
+ }
119
+
120
+ get strategyName() {
121
+ return solautoStrategyName(this.supplyMint, this.debtMint);
122
+ }
123
+
124
+ liqUtilizationRateBps(priceType?: PriceType): number {
125
+ return getLiqUtilzationRateBps(
126
+ this.supplyUsd(priceType),
127
+ this.debtUsd(priceType),
128
+ this.state.liqThresholdBps
118
129
  );
119
130
  }
120
131
 
121
- data(): SolautoPositionExData {
132
+ protected get data(): SolautoPositionExData {
122
133
  return this._data;
123
134
  }
124
135
 
125
- state(): PositionState {
126
- return this.data().state;
136
+ get state(): PositionState {
137
+ return this.data.state;
127
138
  }
128
139
 
129
- settings(): SolautoSettingsParameters | undefined {
130
- return this.contextUpdates?.settings ?? this.data().position?.settings;
140
+ get settings(): SolautoSettingsParameters | undefined {
141
+ return this.contextUpdates?.settings ?? this.data.position?.settings;
131
142
  }
132
143
 
133
- dca(): DCASettings | undefined {
134
- return this.contextUpdates?.dca ?? this.data().position?.dca;
144
+ updateSettings(settings: SolautoSettingsParameters) {
145
+ this.data.position!.settings = settings;
135
146
  }
136
147
 
137
- supplyMint(): PublicKey {
138
- return toWeb3JsPublicKey(this.state().supply.mint);
148
+ get dca(): DCASettings | undefined {
149
+ return this.contextUpdates?.dca ?? this.data.position?.dca;
139
150
  }
140
151
 
141
- supplyMintInfo(): TokenInfo {
142
- return tokenInfo(this.supplyMint());
152
+ updateDca(dca: DCASettings) {
153
+ this.data.position!.dca = dca;
143
154
  }
144
155
 
145
- debtMint(): PublicKey {
146
- return toWeb3JsPublicKey(this.state().debt.mint);
156
+ get supplyMint(): PublicKey {
157
+ return toWeb3JsPublicKey(this.state.supply.mint);
147
158
  }
148
159
 
149
- debtMintInfo(): TokenInfo {
150
- return tokenInfo(this.debtMint());
160
+ get supplyMintInfo(): TokenInfo {
161
+ return tokenInfo(this.supplyMint);
151
162
  }
152
163
 
153
- boostToBps() {
154
- return Math.min(
155
- this.settings()?.boostToBps ?? 0,
156
- maxBoostToBps(this.state().maxLtvBps, this.state().liqThresholdBps)
157
- );
164
+ get debtMint(): PublicKey {
165
+ return toWeb3JsPublicKey(this.state.debt.mint);
158
166
  }
159
167
 
160
- boostFromBps() {
161
- return this.boostToBps() - (this.settings()?.boostGap ?? 0);
168
+ get debtMintInfo(): TokenInfo {
169
+ return tokenInfo(this.debtMint);
162
170
  }
163
171
 
164
- repayToBps() {
165
- return Math.min(
166
- this.settings()?.repayToBps ?? 0,
167
- maxRepayToBps(this.state().maxLtvBps, this.state().liqThresholdBps)
168
- );
172
+ get boostToBps() {
173
+ return Math.min(this.settings?.boostToBps ?? 0, this.maxBoostToBps);
169
174
  }
170
175
 
171
- repayFromBps() {
172
- return (
173
- (this.settings()?.repayToBps ?? 0) + (this.settings()?.repayGap ?? 0)
174
- );
176
+ get maxBoostToBps() {
177
+ return maxBoostToBps(this.state.maxLtvBps, this.state.liqThresholdBps);
175
178
  }
176
179
 
177
- netWorth() {
178
- return calcNetWorth(this.state());
180
+ get boostFromBps() {
181
+ return this.boostToBps - (this.settings?.boostGap ?? 0);
179
182
  }
180
183
 
181
- netWorthUsd() {
182
- return calcNetWorthUsd(this.state());
184
+ get repayToBps() {
185
+ return Math.min(this.settings?.repayToBps ?? 0, this.maxRepayToBps);
183
186
  }
184
187
 
185
- totalSupply() {
186
- return calcTotalSupply(this.state());
188
+ get maxRepayToBps() {
189
+ return maxRepayToBps(this.state.maxLtvBps, this.state.liqThresholdBps);
187
190
  }
188
191
 
189
- supplyUsd() {
190
- const supplyPrice = safeGetPrice(this.supplyMint());
192
+ get repayFromBps() {
193
+ return (this.settings?.repayToBps ?? 0) + (this.settings?.repayGap ?? 0);
194
+ }
195
+
196
+ get maxRepayFromBps() {
197
+ return maxRepayFromBps(this.state.maxLtvBps, this.state.liqThresholdBps);
198
+ }
199
+
200
+ get netWorth() {
201
+ return calcNetWorth(this.state);
202
+ }
203
+
204
+ get netWorthUsd() {
205
+ return calcNetWorthUsd(this.state);
206
+ }
207
+
208
+ get totalSupply() {
209
+ return calcTotalSupply(this.state);
210
+ }
211
+
212
+ supplyUsd(priceType?: PriceType) {
213
+ const supplyPrice = safeGetPrice(this.supplyMint, priceType);
191
214
  return supplyPrice
192
- ? calcTotalSupply(this.state()) * supplyPrice
193
- : calcSupplyUsd(this.state());
215
+ ? calcTotalSupply(this.state) * supplyPrice
216
+ : calcSupplyUsd(this.state);
194
217
  }
195
218
 
196
- totalDebt() {
197
- return calcTotalDebt(this.state());
219
+ get totalDebt() {
220
+ return calcTotalDebt(this.state);
198
221
  }
199
222
 
200
- debtUsd() {
201
- const debtPrice = safeGetPrice(this.debtMint());
223
+ debtUsd(priceType?: PriceType) {
224
+ const debtPrice = safeGetPrice(this.debtMint, priceType);
202
225
  return debtPrice
203
- ? calcTotalDebt(this.state()) * debtPrice
204
- : calcDebtUsd(this.state());
226
+ ? calcTotalDebt(this.state) * debtPrice
227
+ : calcDebtUsd(this.state);
205
228
  }
206
229
 
207
- supplyLiquidityDepositable() {
208
- return supplyLiquidityDepositable(this.state());
230
+ get supplyLiquidityDepositable() {
231
+ return supplyLiquidityDepositable(this.state);
209
232
  }
210
233
 
211
- supplyLiquidityUsdDepositable() {
212
- return supplyLiquidityUsdDepositable(this.state());
234
+ get supplyLiquidityUsdDepositable() {
235
+ return supplyLiquidityUsdDepositable(this.state);
213
236
  }
214
237
 
215
- supplyLiquidityUsdAvailable() {
216
- return (
217
- this.supplyLiquidityAvailable() * (safeGetPrice(this.supplyMint()) ?? 0)
218
- );
238
+ get supplyLiquidityUsdAvailable() {
239
+ return this.supplyLiquidityAvailable * (safeGetPrice(this.supplyMint) ?? 0);
219
240
  }
220
241
 
221
- debtLiquidityAvailable() {
222
- return debtLiquidityAvailable(this.state());
242
+ get debtLiquidityAvailable() {
243
+ return debtLiquidityAvailable(this.state);
223
244
  }
224
245
 
225
- debtLiquidityUsdAvailable() {
226
- return debtLiquidityUsdAvailable(this.state());
246
+ get debtLiquidityUsdAvailable() {
247
+ return debtLiquidityUsdAvailable(this.state);
227
248
  }
228
249
 
250
+ abstract get supplyLiquidityAvailable(): number;
251
+
229
252
  abstract maxLtvAndLiqThresholdBps(): Promise<[number, number]>;
230
253
  abstract priceOracles(): Promise<PublicKey[]>;
231
- abstract supplyLiquidityAvailable(): number;
232
254
 
233
- sufficientLiquidityToBoost() {
255
+ private sufficientLiquidityToBoost() {
234
256
  const limitsUpToDate =
235
- this.debtLiquidityUsdAvailable() !== 0 ||
236
- this.supplyLiquidityUsdDepositable() !== 0;
257
+ this.debtLiquidityUsdAvailable !== 0 ||
258
+ this.supplyLiquidityUsdDepositable !== 0;
237
259
 
238
260
  if (limitsUpToDate) {
239
261
  const { debtAdjustmentUsd } = getDebtAdjustment(
240
- this.state().liqThresholdBps,
262
+ this.state.liqThresholdBps,
241
263
  { supplyUsd: this.supplyUsd(), debtUsd: this.debtUsd() },
242
- this.boostToBps(),
264
+ this.boostToBps,
243
265
  { solauto: 50, lpBorrow: 50, flashLoan: 50 } // TODO: get true data here instead of magic numbers
244
266
  );
245
267
 
246
268
  const sufficientLiquidity =
247
- this.debtLiquidityUsdAvailable() * 0.95 > debtAdjustmentUsd &&
248
- this.supplyLiquidityUsdDepositable() * 0.95 > debtAdjustmentUsd;
269
+ this.debtLiquidityUsdAvailable * 0.95 > debtAdjustmentUsd &&
270
+ this.supplyLiquidityUsdDepositable * 0.95 > debtAdjustmentUsd;
249
271
 
250
272
  if (!sufficientLiquidity) {
251
273
  consoleLog("Insufficient liquidity to further boost");
@@ -257,21 +279,23 @@ export abstract class SolautoPositionEx {
257
279
  }
258
280
 
259
281
  eligibleForRebalance(bpsDistanceThreshold = 0): RebalanceAction | undefined {
260
- if (!this.settings() || !this.supplyUsd()) {
282
+ if (!this.settings || !this.supplyUsd()) {
261
283
  return undefined;
262
284
  }
263
285
 
264
- if (
265
- this.state().liqUtilizationRateBps - this.boostFromBps() <=
266
- bpsDistanceThreshold
286
+ const realtimeLiqUtilRateBps = this.liqUtilizationRateBps(
287
+ PriceType.Realtime
288
+ );
289
+ const emaLiqUtilRateBps = this.liqUtilizationRateBps(PriceType.Ema);
290
+
291
+ if (this.repayFromBps - realtimeLiqUtilRateBps <= bpsDistanceThreshold) {
292
+ return "repay";
293
+ } else if (
294
+ realtimeLiqUtilRateBps - this.boostFromBps <= bpsDistanceThreshold ||
295
+ emaLiqUtilRateBps - this.boostFromBps <= bpsDistanceThreshold
267
296
  ) {
268
297
  const sufficientLiquidity = this.sufficientLiquidityToBoost();
269
298
  return sufficientLiquidity ? "boost" : undefined;
270
- } else if (
271
- this.repayFromBps() - this.state().liqUtilizationRateBps <=
272
- bpsDistanceThreshold
273
- ) {
274
- return "repay";
275
299
  }
276
300
 
277
301
  return undefined;
@@ -281,14 +305,13 @@ export abstract class SolautoPositionEx {
281
305
  if (this._data.selfManaged) return false;
282
306
 
283
307
  return (
284
- currentUnixSeconds() - Number(this.state().lastRefreshed) >
285
- 60 * 60 * 24 * 7
308
+ currentUnixSeconds() - Number(this.state.lastRefreshed) > 60 * 60 * 24 * 7
286
309
  );
287
310
  }
288
311
 
289
312
  protected canRefreshPositionState() {
290
313
  if (
291
- Number(this.state().lastRefreshed) >
314
+ Number(this.state.lastRefreshed) >
292
315
  currentUnixSeconds() - MIN_POSITION_STATE_FRESHNESS_SECS &&
293
316
  !this.contextUpdates?.positionUpdates()
294
317
  ) {
@@ -297,18 +320,18 @@ export abstract class SolautoPositionEx {
297
320
  return true;
298
321
  }
299
322
 
300
- abstract refreshPositionState(): Promise<void>;
323
+ abstract refreshPositionState(priceType?: PriceType): Promise<void>;
301
324
 
302
325
  async utilizationRateBpsDrift() {
303
- const supplyPrice = safeGetPrice(this.state().supply.mint) ?? 0;
304
- const debtPrice = safeGetPrice(this.state().debt.mint) ?? 0;
326
+ const supplyPrice = safeGetPrice(this.state.supply.mint) ?? 0;
327
+ const debtPrice = safeGetPrice(this.state.debt.mint) ?? 0;
305
328
  const oldState = await positionStateWithLatestPrices(
306
329
  this.firstState,
307
330
  supplyPrice,
308
331
  debtPrice
309
332
  );
310
333
  const newState = await positionStateWithLatestPrices(
311
- this.state(),
334
+ this.state,
312
335
  supplyPrice,
313
336
  debtPrice
314
337
  );
@@ -320,8 +343,8 @@ export abstract class SolautoPositionEx {
320
343
  this._data.state.supply.amountUsed.baseAmountUsdValue =
321
344
  toRoundedUsdValue(newSupplyUsd);
322
345
  this._data.state.supply.amountUsed.baseUnit = toBaseUnit(
323
- newSupplyUsd / (supplyPrice ?? safeGetPrice(this.supplyMint()) ?? 0),
324
- this.supplyMintInfo().decimals
346
+ newSupplyUsd / (supplyPrice ?? safeGetPrice(this.supplyMint) ?? 0),
347
+ this.supplyMintInfo.decimals
325
348
  );
326
349
  }
327
350
 
@@ -329,8 +352,8 @@ export abstract class SolautoPositionEx {
329
352
  this._data.state.debt.amountUsed.baseAmountUsdValue =
330
353
  toRoundedUsdValue(newDebtUsd);
331
354
  this._data.state.debt.amountUsed.baseUnit = toBaseUnit(
332
- newDebtUsd / (debtPrice ?? safeGetPrice(this.debtMint()) ?? 0),
333
- this.debtMintInfo().decimals
355
+ newDebtUsd / (debtPrice ?? safeGetPrice(this.debtMint) ?? 0),
356
+ this.debtMintInfo.decimals
334
357
  );
335
358
  }
336
359
 
@@ -339,33 +362,41 @@ export abstract class SolautoPositionEx {
339
362
  this._data.state.netWorth.baseAmountUsdValue =
340
363
  toRoundedUsdValue(netWorthUsd);
341
364
  this._data.state.netWorth.baseUnit = toBaseUnit(
342
- netWorthUsd / (supplyPrice ?? safeGetPrice(this.supplyMint()) ?? 0),
343
- this.supplyMintInfo().decimals
365
+ netWorthUsd / (supplyPrice ?? safeGetPrice(this.supplyMint) ?? 0),
366
+ this.supplyMintInfo.decimals
344
367
  );
345
368
  }
346
369
 
347
- updateLiqUtilizationRate() {
370
+ updateLiqUtilizationRate(priceType?: PriceType) {
348
371
  this._data.state.liqUtilizationRateBps = getLiqUtilzationRateBps(
349
- this.supplyUsd(),
350
- this.debtUsd(),
351
- this.state().liqThresholdBps
372
+ this.supplyUsd(priceType),
373
+ this.debtUsd(priceType),
374
+ this.state.liqThresholdBps
352
375
  );
353
376
  }
354
377
 
355
- async updateWithLatestPrices(supplyPrice?: number, debtPrice?: number) {
356
- if (!supplyPrice || !debtPrice) {
357
- [supplyPrice, debtPrice] = await fetchTokenPrices([
358
- this.supplyMint(),
359
- this.debtMint(),
360
- ]);
378
+ async updateWithLatestPrices(data?: {
379
+ priceType?: PriceType;
380
+ supplyPrice?: number;
381
+ debtPrice?: number;
382
+ }) {
383
+ if (!data) {
384
+ data = {};
361
385
  }
362
386
 
363
- const supplyUsd = this.totalSupply() * supplyPrice;
364
- const debtUsd = this.totalDebt() * debtPrice;
387
+ if (!data.supplyPrice || !data.debtPrice) {
388
+ [data.supplyPrice, data.debtPrice] = await fetchTokenPrices(
389
+ [this.supplyMint, this.debtMint],
390
+ data.priceType
391
+ );
392
+ }
365
393
 
366
- this.updateSupply(supplyUsd, supplyPrice);
367
- this.updateDebt(debtUsd, debtPrice);
368
- this.updateNetWorth(supplyPrice);
394
+ const supplyUsd = this.totalSupply * data.supplyPrice;
395
+ const debtUsd = this.totalDebt * data.debtPrice;
396
+
397
+ this.updateSupply(supplyUsd, data.supplyPrice);
398
+ this.updateDebt(debtUsd, data.debtPrice);
399
+ this.updateNetWorth(data.supplyPrice);
369
400
  this.updateLiqUtilizationRate();
370
401
  }
371
402
 
@@ -378,12 +409,9 @@ export abstract class SolautoPositionEx {
378
409
  this._data.state.lastRefreshed = BigInt(unixTime);
379
410
  const rebalance = getRebalanceValues(
380
411
  this,
412
+ PriceType.Realtime,
381
413
  targetLiqUtilizationRateBps,
382
- SolautoFeesBps.create(
383
- true,
384
- targetLiqUtilizationRateBps,
385
- this.netWorthUsd()
386
- )
414
+ SolautoFeesBps.create(true, targetLiqUtilizationRateBps, this.netWorthUsd)
387
415
  );
388
416
  this.updateSupply(rebalance.endResult.supplyUsd, supplyPrice);
389
417
  this.updateDebt(rebalance.endResult.debtUsd, debtPrice);
@@ -2,6 +2,7 @@ import { PublicKey } from "@solana/web3.js";
2
2
  import {
3
3
  LendingPlatform,
4
4
  PositionType,
5
+ PriceType,
5
6
  SolautoRebalanceType,
6
7
  TokenType,
7
8
  } from "../generated";
@@ -60,6 +61,7 @@ export interface RebalanceDetails {
60
61
  flashLoan?: FlashLoanDetails;
61
62
  swapQuote: QuoteResponse;
62
63
  targetLiqUtilizationRateBps?: number;
64
+ priceType: PriceType;
63
65
  }
64
66
 
65
67
  export type ProgramEnv = "Prod" | "Staging";
@@ -139,10 +139,10 @@ export function swapThenDeposit(
139
139
  ) {
140
140
  return [
141
141
  new TransactionItem(async () => {
142
- const memeSwap = tokenInfo(client.pos.supplyMint()).isMeme;
142
+ const memeSwap = tokenInfo(client.pos.supplyMint).isMeme;
143
143
  const swapInput: SwapInput = {
144
144
  inputMint: depositMint,
145
- outputMint: client.pos.supplyMint(),
145
+ outputMint: client.pos.supplyMint,
146
146
  amount: depositAmountBaseUnit,
147
147
  exactIn: true,
148
148
  slippageBps: memeSwap ? 300 : 50,
@@ -5,7 +5,7 @@ import {
5
5
  toWeb3JsPublicKey,
6
6
  } from "@metaplex-foundation/umi-web3js-adapters";
7
7
  import { ProgramEnv, MarginfiAssetAccounts } from "../types";
8
- import { PositionState, PositionTokenState } from "../generated";
8
+ import { PositionState, PositionTokenState, PriceType } from "../generated";
9
9
  import {
10
10
  ALL_SUPPORTED_TOKENS,
11
11
  getMarginfiAccounts,
@@ -407,7 +407,8 @@ async function getTokenUsage(
407
407
  bank: Bank | null,
408
408
  isAsset: boolean,
409
409
  shares: number,
410
- amountUsedAdjustment?: bigint
410
+ amountUsedAdjustment?: bigint,
411
+ priceType?: PriceType
411
412
  ): Promise<PositionTokenState> {
412
413
  let amountUsed = 0;
413
414
  let amountCanBeUsed = BigInt(0);
@@ -415,7 +416,7 @@ async function getTokenUsage(
415
416
  let originationFee = 0;
416
417
 
417
418
  if (bank !== null) {
418
- [marketPrice] = await fetchTokenPrices([toWeb3JsPublicKey(bank.mint)]);
419
+ [marketPrice] = await fetchTokenPrices([toWeb3JsPublicKey(bank.mint)], priceType);
419
420
  const [assetShareValue, liabilityShareValue] = getUpToDateShareValues(bank);
420
421
  const shareValue = isAsset ? assetShareValue : liabilityShareValue;
421
422
  amountUsed = shares * shareValue + Number(amountUsedAdjustment ?? 0);
@@ -489,7 +490,8 @@ export async function getMarginfiAccountPositionState(
489
490
  supply?: BankSelection,
490
491
  debt?: BankSelection,
491
492
  programEnv?: ProgramEnv,
492
- contextUpdates?: ContextUpdates
493
+ contextUpdates?: ContextUpdates,
494
+ priceType?: PriceType
493
495
  ): Promise<
494
496
  | { supplyBank: Bank | null; debtBank: Bank | null; state: PositionState }
495
497
  | undefined
@@ -550,7 +552,8 @@ export async function getMarginfiAccountPositionState(
550
552
  supplyBank!,
551
553
  true,
552
554
  bytesToI80F48(supplyBalances[0].assetShares.value),
553
- contextUpdates?.supplyAdjustment
555
+ contextUpdates?.supplyAdjustment,
556
+ priceType
554
557
  );
555
558
  }
556
559
 
@@ -567,7 +570,8 @@ export async function getMarginfiAccountPositionState(
567
570
  debtBank!,
568
571
  false,
569
572
  bytesToI80F48(debtBalances[0].liabilityShares.value),
570
- contextUpdates?.debtAdjustment
573
+ contextUpdates?.debtAdjustment,
574
+ priceType
571
575
  );
572
576
  }
573
577
  }
@@ -581,7 +585,7 @@ export async function getMarginfiAccountPositionState(
581
585
  supplyBank,
582
586
  true,
583
587
  0,
584
- contextUpdates?.supplyAdjustment
588
+ contextUpdates?.supplyAdjustment,
585
589
  );
586
590
  }
587
591
 
@@ -609,7 +613,7 @@ export async function getMarginfiAccountPositionState(
609
613
  debtBank,
610
614
  false,
611
615
  0,
612
- contextUpdates?.debtAdjustment
616
+ contextUpdates?.debtAdjustment,
613
617
  );
614
618
  }
615
619