@haven-fi/solauto-sdk 1.0.628 → 1.0.630
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/README.md +35 -6
- package/dist/constants/marginfiAccounts.d.ts.map +1 -1
- package/dist/constants/solautoConstants.d.ts +2 -1
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiRebalance.d.ts +5 -3
- package/dist/generated/instructions/marginfiRebalance.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiRebalance.js +2 -1
- package/dist/generated/instructions/marginfiRefreshData.d.ts +7 -2
- package/dist/generated/instructions/marginfiRefreshData.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiRefreshData.js +8 -4
- package/dist/generated/types/index.d.ts +1 -0
- package/dist/generated/types/index.d.ts.map +1 -1
- package/dist/generated/types/index.js +1 -0
- package/dist/generated/types/priceType.d.ts +15 -0
- package/dist/generated/types/priceType.d.ts.map +1 -0
- package/dist/generated/types/priceType.js +22 -0
- package/dist/services/rebalance/rebalanceSwapManager.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceSwapManager.js +8 -8
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts +2 -0
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceTxBuilder.js +21 -10
- package/dist/services/rebalance/rebalanceValues.d.ts +2 -2
- package/dist/services/rebalance/rebalanceValues.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceValues.js +17 -17
- package/dist/services/solauto/solautoClient.d.ts +2 -2
- package/dist/services/solauto/solautoClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoClient.js +27 -28
- package/dist/services/solauto/solautoMarginfiClient.d.ts +2 -2
- package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoMarginfiClient.js +12 -10
- package/dist/services/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/services/transactions/transactionUtils.js +10 -9
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts +3 -3
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.js +9 -9
- package/dist/solautoPosition/solautoPositionEx.d.ts +44 -33
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/solautoPositionEx.js +109 -90
- package/dist/types/solauto.d.ts +2 -1
- package/dist/types/solauto.d.ts.map +1 -1
- package/dist/utils/instructionUtils.js +2 -2
- package/dist/utils/marginfiUtils.d.ts +2 -2
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +5 -5
- package/dist/utils/priceUtils.d.ts +11 -5
- package/dist/utils/priceUtils.d.ts.map +1 -1
- package/dist/utils/priceUtils.js +45 -21
- package/local/logPositions.ts +12 -12
- package/local/shared.ts +1 -1
- package/local/txSandbox.ts +27 -32
- package/local/updateMarginfiLUT.ts +13 -6
- package/package.json +2 -1
- package/src/constants/marginfiAccounts.ts +0 -1
- package/src/constants/solautoConstants.ts +1 -1
- package/src/generated/instructions/marginfiRebalance.ts +9 -3
- package/src/generated/instructions/marginfiRefreshData.ts +27 -7
- package/src/generated/types/index.ts +1 -0
- package/src/generated/types/priceType.ts +22 -0
- package/src/services/rebalance/rebalanceSwapManager.ts +8 -12
- package/src/services/rebalance/rebalanceTxBuilder.ts +41 -11
- package/src/services/rebalance/rebalanceValues.ts +22 -16
- package/src/services/solauto/solautoClient.ts +30 -30
- package/src/services/solauto/solautoMarginfiClient.ts +13 -10
- package/src/services/transactions/transactionUtils.ts +11 -9
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +11 -10
- package/src/solautoPosition/solautoPositionEx.ts +141 -117
- package/src/types/solauto.ts +2 -0
- package/src/utils/instructionUtils.ts +2 -2
- package/src/utils/marginfiUtils.ts +12 -8
- package/src/utils/priceUtils.ts +66 -22
- package/tests/transactions/shared.ts +2 -5
- 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
|
-
:
|
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
|
-
|
115
|
-
return
|
116
|
-
|
117
|
-
|
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
|
136
|
+
get state(): PositionState {
|
137
|
+
return this.data.state;
|
127
138
|
}
|
128
139
|
|
129
|
-
settings(): SolautoSettingsParameters | undefined {
|
130
|
-
return this.contextUpdates?.settings ?? this.data
|
140
|
+
get settings(): SolautoSettingsParameters | undefined {
|
141
|
+
return this.contextUpdates?.settings ?? this.data.position?.settings;
|
131
142
|
}
|
132
143
|
|
133
|
-
|
134
|
-
|
144
|
+
updateSettings(settings: SolautoSettingsParameters) {
|
145
|
+
this.data.position!.settings = settings;
|
135
146
|
}
|
136
147
|
|
137
|
-
|
138
|
-
return
|
148
|
+
get dca(): DCASettings | undefined {
|
149
|
+
return this.contextUpdates?.dca ?? this.data.position?.dca;
|
139
150
|
}
|
140
151
|
|
141
|
-
|
142
|
-
|
152
|
+
updateDca(dca: DCASettings) {
|
153
|
+
this.data.position!.dca = dca;
|
143
154
|
}
|
144
155
|
|
145
|
-
|
146
|
-
return toWeb3JsPublicKey(this.state
|
156
|
+
get supplyMint(): PublicKey {
|
157
|
+
return toWeb3JsPublicKey(this.state.supply.mint);
|
147
158
|
}
|
148
159
|
|
149
|
-
|
150
|
-
return tokenInfo(this.
|
160
|
+
get supplyMintInfo(): TokenInfo {
|
161
|
+
return tokenInfo(this.supplyMint);
|
151
162
|
}
|
152
163
|
|
153
|
-
|
154
|
-
return
|
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
|
-
|
161
|
-
return
|
168
|
+
get debtMintInfo(): TokenInfo {
|
169
|
+
return tokenInfo(this.debtMint);
|
162
170
|
}
|
163
171
|
|
164
|
-
|
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
|
-
|
172
|
-
return (
|
173
|
-
|
174
|
-
|
176
|
+
get maxBoostToBps() {
|
177
|
+
return maxBoostToBps(this.state.maxLtvBps, this.state.liqThresholdBps);
|
178
|
+
}
|
179
|
+
|
180
|
+
get boostFromBps() {
|
181
|
+
return this.boostToBps - (this.settings?.boostGap ?? 0);
|
182
|
+
}
|
183
|
+
|
184
|
+
get repayToBps() {
|
185
|
+
return Math.min(this.settings?.repayToBps ?? 0, this.maxRepayToBps);
|
186
|
+
}
|
187
|
+
|
188
|
+
get maxRepayToBps() {
|
189
|
+
return maxRepayToBps(this.state.maxLtvBps, this.state.liqThresholdBps);
|
190
|
+
}
|
191
|
+
|
192
|
+
get repayFromBps() {
|
193
|
+
return (this.settings?.repayToBps ?? 0) + (this.settings?.repayGap ?? 0);
|
175
194
|
}
|
176
195
|
|
177
|
-
|
178
|
-
return
|
196
|
+
get maxRepayFromBps() {
|
197
|
+
return maxRepayFromBps(this.state.maxLtvBps, this.state.liqThresholdBps);
|
179
198
|
}
|
180
199
|
|
181
|
-
|
182
|
-
return
|
200
|
+
get netWorth() {
|
201
|
+
return calcNetWorth(this.state);
|
183
202
|
}
|
184
203
|
|
185
|
-
|
186
|
-
return
|
204
|
+
get netWorthUsd() {
|
205
|
+
return calcNetWorthUsd(this.state);
|
187
206
|
}
|
188
207
|
|
189
|
-
|
190
|
-
|
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
|
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
|
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
|
236
|
-
this.supplyLiquidityUsdDepositable
|
257
|
+
this.debtLiquidityUsdAvailable !== 0 ||
|
258
|
+
this.supplyLiquidityUsdDepositable !== 0;
|
237
259
|
|
238
260
|
if (limitsUpToDate) {
|
239
261
|
const { debtAdjustmentUsd } = getDebtAdjustment(
|
240
|
-
this.state
|
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
|
248
|
-
this.supplyLiquidityUsdDepositable
|
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
|
282
|
+
if (!this.settings || !this.supplyUsd()) {
|
261
283
|
return undefined;
|
262
284
|
}
|
263
285
|
|
264
|
-
|
265
|
-
|
266
|
-
|
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
|
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
|
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
|
304
|
-
const debtPrice = safeGetPrice(this.state
|
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
|
324
|
-
this.supplyMintInfo
|
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
|
333
|
-
this.debtMintInfo
|
355
|
+
newDebtUsd / (debtPrice ?? safeGetPrice(this.debtMint) ?? 0),
|
356
|
+
this.debtMintInfo.decimals
|
334
357
|
);
|
335
358
|
}
|
336
359
|
|
@@ -339,33 +362,37 @@ 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
|
343
|
-
this.supplyMintInfo
|
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
|
372
|
+
this.supplyUsd(priceType),
|
373
|
+
this.debtUsd(priceType),
|
374
|
+
this.state.liqThresholdBps
|
352
375
|
);
|
353
376
|
}
|
354
377
|
|
355
|
-
async updateWithLatestPrices(
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
378
|
+
async updateWithLatestPrices(data: {
|
379
|
+
priceType?: PriceType;
|
380
|
+
supplyPrice?: number;
|
381
|
+
debtPrice?: number;
|
382
|
+
}) {
|
383
|
+
if (!data.supplyPrice || !data.debtPrice) {
|
384
|
+
[data.supplyPrice, data.debtPrice] = await fetchTokenPrices(
|
385
|
+
[this.supplyMint, this.debtMint],
|
386
|
+
data.priceType
|
387
|
+
);
|
361
388
|
}
|
362
389
|
|
363
|
-
const supplyUsd = this.totalSupply
|
364
|
-
const debtUsd = this.totalDebt
|
390
|
+
const supplyUsd = this.totalSupply * data.supplyPrice;
|
391
|
+
const debtUsd = this.totalDebt * data.debtPrice;
|
365
392
|
|
366
|
-
this.updateSupply(supplyUsd, supplyPrice);
|
367
|
-
this.updateDebt(debtUsd, debtPrice);
|
368
|
-
this.updateNetWorth(supplyPrice);
|
393
|
+
this.updateSupply(supplyUsd, data.supplyPrice);
|
394
|
+
this.updateDebt(debtUsd, data.debtPrice);
|
395
|
+
this.updateNetWorth(data.supplyPrice);
|
369
396
|
this.updateLiqUtilizationRate();
|
370
397
|
}
|
371
398
|
|
@@ -378,12 +405,9 @@ export abstract class SolautoPositionEx {
|
|
378
405
|
this._data.state.lastRefreshed = BigInt(unixTime);
|
379
406
|
const rebalance = getRebalanceValues(
|
380
407
|
this,
|
408
|
+
PriceType.Realtime,
|
381
409
|
targetLiqUtilizationRateBps,
|
382
|
-
SolautoFeesBps.create(
|
383
|
-
true,
|
384
|
-
targetLiqUtilizationRateBps,
|
385
|
-
this.netWorthUsd()
|
386
|
-
)
|
410
|
+
SolautoFeesBps.create(true, targetLiqUtilizationRateBps, this.netWorthUsd)
|
387
411
|
);
|
388
412
|
this.updateSupply(rebalance.endResult.supplyUsd, supplyPrice);
|
389
413
|
this.updateDebt(rebalance.endResult.debtUsd, debtPrice);
|
package/src/types/solauto.ts
CHANGED
@@ -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
|
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
|
|