@haven-fi/solauto-sdk 1.0.636 → 1.0.638
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.
@@ -32,6 +32,8 @@ export declare abstract class SolautoPositionEx {
|
|
32
32
|
protected lpEnv: ProgramEnv;
|
33
33
|
lpUserAccount?: PublicKey;
|
34
34
|
private readonly firstState;
|
35
|
+
protected _supplyPrice?: number;
|
36
|
+
protected _debtPrice?: number;
|
35
37
|
constructor(args: PositionExArgs);
|
36
38
|
abstract lendingPool(): Promise<PublicKey>;
|
37
39
|
get exists(): boolean;
|
@@ -61,8 +63,10 @@ export declare abstract class SolautoPositionEx {
|
|
61
63
|
get netWorthUsd(): number;
|
62
64
|
get totalSupply(): number;
|
63
65
|
supplyUsd(priceType?: PriceType): number;
|
66
|
+
protected supplyPrice(priceType?: PriceType): number | undefined;
|
64
67
|
get totalDebt(): number;
|
65
68
|
debtUsd(priceType?: PriceType): number;
|
69
|
+
protected debtPrice(priceType?: PriceType): number | undefined;
|
66
70
|
get supplyLiquidityDepositable(): number;
|
67
71
|
get supplyLiquidityUsdDepositable(): number;
|
68
72
|
get supplyLiquidityUsdAvailable(): number;
|
@@ -78,14 +82,11 @@ export declare abstract class SolautoPositionEx {
|
|
78
82
|
abstract refreshPositionState(priceType?: PriceType): Promise<void>;
|
79
83
|
utilizationRateBpsDrift(priceType?: PriceType): Promise<number>;
|
80
84
|
updateSupply(newSupplyUsd: number, supplyPrice?: number): void;
|
85
|
+
updateSupplyPrice(price: number): void;
|
81
86
|
updateDebt(newDebtUsd: number, debtPrice?: number): void;
|
87
|
+
updateDebtPrice(price: number): void;
|
82
88
|
updateNetWorth(supplyPrice?: number): void;
|
83
89
|
updateLiqUtilizationRate(supplyUsd?: number, debtUsd?: number, priceType?: PriceType): void;
|
84
|
-
updateWithLatestPrices(data?: {
|
85
|
-
priceType?: PriceType;
|
86
|
-
supplyPrice?: number;
|
87
|
-
debtPrice?: number;
|
88
|
-
}): Promise<void>;
|
89
90
|
simulateRebalance(unixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number): undefined;
|
90
91
|
refetchPositionData(): Promise<void>;
|
91
92
|
}
|
@@ -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,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAK/C,OAAO,EACL,WAAW,EAEX,eAAe,EACf,aAAa,EACb,SAAS,EACT,eAAe,EACf,yBAAyB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAQL,cAAc,EAiBf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAMvD,OAAO,EAAqC,SAAS,EAAE,MAAM,cAAc,CAAC;AAE5E,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;IACxB,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,UAAU,qBAAsB,SAAQ,OAAO,CAAC,eAAe,CAAC;IAC9D,KAAK,EAAE,aAAa,CAAC;CACtB;AAED,UAAU,cAAc;IACtB,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE,qBAAqB,CAAC;IAC5B,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,8BAAsB,iBAAiB;IAC9B,GAAG,EAAG,GAAG,CAAC;IACjB,SAAS,CAAC,cAAc,CAAC,EAAE,cAA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c,CAAC,WAAW,CAAC,EAAE,MAAM;IAUnC,wBAAwB,CACtB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,SAAS;IASvB,iBAAiB,CACf,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM;IAsBhC,mBAAmB;CAM1B"}
|
@@ -105,20 +105,26 @@ class SolautoPositionEx {
|
|
105
105
|
return (0, utils_1.calcTotalSupply)(this.state);
|
106
106
|
}
|
107
107
|
supplyUsd(priceType) {
|
108
|
-
const supplyPrice =
|
108
|
+
const supplyPrice = this.supplyPrice(priceType);
|
109
109
|
return supplyPrice
|
110
110
|
? (0, utils_1.calcTotalSupply)(this.state) * supplyPrice
|
111
111
|
: (0, utils_1.calcSupplyUsd)(this.state);
|
112
112
|
}
|
113
|
+
supplyPrice(priceType) {
|
114
|
+
return this._supplyPrice ?? (0, utils_1.safeGetPrice)(this.supplyMint, priceType);
|
115
|
+
}
|
113
116
|
get totalDebt() {
|
114
117
|
return (0, utils_1.calcTotalDebt)(this.state);
|
115
118
|
}
|
116
119
|
debtUsd(priceType) {
|
117
|
-
const debtPrice =
|
120
|
+
const debtPrice = this.debtPrice(priceType);
|
118
121
|
return debtPrice
|
119
122
|
? (0, utils_1.calcTotalDebt)(this.state) * debtPrice
|
120
123
|
: (0, utils_1.calcDebtUsd)(this.state);
|
121
124
|
}
|
125
|
+
debtPrice(priceType) {
|
126
|
+
return this._debtPrice ?? (0, utils_1.safeGetPrice)(this.debtMint, priceType);
|
127
|
+
}
|
122
128
|
get supplyLiquidityDepositable() {
|
123
129
|
return (0, utils_1.supplyLiquidityDepositable)(this.state);
|
124
130
|
}
|
@@ -126,7 +132,7 @@ class SolautoPositionEx {
|
|
126
132
|
return (0, utils_1.supplyLiquidityUsdDepositable)(this.state);
|
127
133
|
}
|
128
134
|
get supplyLiquidityUsdAvailable() {
|
129
|
-
return this.supplyLiquidityAvailable * (
|
135
|
+
return this.supplyLiquidityAvailable * (this.supplyPrice() ?? 0);
|
130
136
|
}
|
131
137
|
get debtLiquidityAvailable() {
|
132
138
|
return (0, utils_1.debtLiquidityAvailable)(this.state);
|
@@ -179,8 +185,8 @@ class SolautoPositionEx {
|
|
179
185
|
return true;
|
180
186
|
}
|
181
187
|
async utilizationRateBpsDrift(priceType) {
|
182
|
-
const supplyPrice =
|
183
|
-
const debtPrice =
|
188
|
+
const supplyPrice = this.supplyPrice(priceType) ?? 0;
|
189
|
+
const debtPrice = this.debtPrice(priceType) ?? 0;
|
184
190
|
const oldState = await (0, utils_1.positionStateWithLatestPrices)(this.firstState, supplyPrice, debtPrice);
|
185
191
|
const newState = await (0, utils_1.positionStateWithLatestPrices)(this.state, supplyPrice, debtPrice);
|
186
192
|
return newState.liqUtilizationRateBps - oldState.liqUtilizationRateBps;
|
@@ -188,12 +194,18 @@ class SolautoPositionEx {
|
|
188
194
|
updateSupply(newSupplyUsd, supplyPrice) {
|
189
195
|
this._data.state.supply.amountUsed.baseAmountUsdValue =
|
190
196
|
(0, utils_1.toRoundedUsdValue)(newSupplyUsd);
|
191
|
-
this._data.state.supply.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newSupplyUsd / (supplyPrice ??
|
197
|
+
this._data.state.supply.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newSupplyUsd / (supplyPrice ?? this.supplyPrice() ?? 0), this.supplyMintInfo.decimals);
|
198
|
+
}
|
199
|
+
updateSupplyPrice(price) {
|
200
|
+
this._supplyPrice = price;
|
192
201
|
}
|
193
202
|
updateDebt(newDebtUsd, debtPrice) {
|
194
203
|
this._data.state.debt.amountUsed.baseAmountUsdValue =
|
195
204
|
(0, utils_1.toRoundedUsdValue)(newDebtUsd);
|
196
|
-
this._data.state.debt.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newDebtUsd / (debtPrice ??
|
205
|
+
this._data.state.debt.amountUsed.baseUnit = (0, utils_1.toBaseUnit)(newDebtUsd / (debtPrice ?? this.debtPrice() ?? 0), this.debtMintInfo.decimals);
|
206
|
+
}
|
207
|
+
updateDebtPrice(price) {
|
208
|
+
this._debtPrice = price;
|
197
209
|
}
|
198
210
|
updateNetWorth(supplyPrice) {
|
199
211
|
const netWorthUsd = this.supplyUsd() - this.debtUsd();
|
@@ -204,20 +216,6 @@ class SolautoPositionEx {
|
|
204
216
|
updateLiqUtilizationRate(supplyUsd, debtUsd, priceType) {
|
205
217
|
this._data.state.liqUtilizationRateBps = (0, utils_1.getLiqUtilzationRateBps)(supplyUsd ?? this.supplyUsd(priceType), debtUsd ?? this.debtUsd(priceType), this.state.liqThresholdBps);
|
206
218
|
}
|
207
|
-
async updateWithLatestPrices(data) {
|
208
|
-
if (!data) {
|
209
|
-
data = {};
|
210
|
-
}
|
211
|
-
if (!data.supplyPrice || !data.debtPrice) {
|
212
|
-
[data.supplyPrice, data.debtPrice] = await (0, utils_1.fetchTokenPrices)([this.supplyMint, this.debtMint], data.priceType);
|
213
|
-
}
|
214
|
-
const supplyUsd = this.totalSupply * data.supplyPrice;
|
215
|
-
const debtUsd = this.totalDebt * data.debtPrice;
|
216
|
-
this.updateSupply(supplyUsd, data.supplyPrice);
|
217
|
-
this.updateDebt(debtUsd, data.debtPrice);
|
218
|
-
this.updateNetWorth(data.supplyPrice);
|
219
|
-
this.updateLiqUtilizationRate(this.totalSupply * data.supplyPrice, this.totalDebt * data.debtPrice);
|
220
|
-
}
|
221
219
|
simulateRebalance(unixTime, supplyPrice, debtPrice, targetLiqUtilizationRateBps) {
|
222
220
|
this._data.state.lastRefreshed = BigInt(unixTime);
|
223
221
|
const rebalance = (0, rebalance_1.getRebalanceValues)(this, generated_1.PriceType.Realtime, targetLiqUtilizationRateBps, rebalance_1.SolautoFeesBps.create(true, targetLiqUtilizationRateBps, this.netWorthUsd));
|
package/package.json
CHANGED
@@ -80,6 +80,8 @@ export abstract class SolautoPositionEx {
|
|
80
80
|
public lpUserAccount?: PublicKey = undefined;
|
81
81
|
|
82
82
|
private readonly firstState!: PositionState;
|
83
|
+
protected _supplyPrice?: number;
|
84
|
+
protected _debtPrice?: number;
|
83
85
|
|
84
86
|
constructor(args: PositionExArgs) {
|
85
87
|
this.umi = args.umi;
|
@@ -211,23 +213,31 @@ export abstract class SolautoPositionEx {
|
|
211
213
|
}
|
212
214
|
|
213
215
|
supplyUsd(priceType?: PriceType) {
|
214
|
-
const supplyPrice =
|
216
|
+
const supplyPrice = this.supplyPrice(priceType);
|
215
217
|
return supplyPrice
|
216
218
|
? calcTotalSupply(this.state) * supplyPrice
|
217
219
|
: calcSupplyUsd(this.state);
|
218
220
|
}
|
219
221
|
|
222
|
+
protected supplyPrice(priceType?: PriceType) {
|
223
|
+
return this._supplyPrice ?? safeGetPrice(this.supplyMint, priceType);
|
224
|
+
}
|
225
|
+
|
220
226
|
get totalDebt() {
|
221
227
|
return calcTotalDebt(this.state);
|
222
228
|
}
|
223
229
|
|
224
230
|
debtUsd(priceType?: PriceType) {
|
225
|
-
const debtPrice =
|
231
|
+
const debtPrice = this.debtPrice(priceType);
|
226
232
|
return debtPrice
|
227
233
|
? calcTotalDebt(this.state) * debtPrice
|
228
234
|
: calcDebtUsd(this.state);
|
229
235
|
}
|
230
236
|
|
237
|
+
protected debtPrice(priceType?: PriceType) {
|
238
|
+
return this._debtPrice ?? safeGetPrice(this.debtMint, priceType);
|
239
|
+
}
|
240
|
+
|
231
241
|
get supplyLiquidityDepositable() {
|
232
242
|
return supplyLiquidityDepositable(this.state);
|
233
243
|
}
|
@@ -237,7 +247,7 @@ export abstract class SolautoPositionEx {
|
|
237
247
|
}
|
238
248
|
|
239
249
|
get supplyLiquidityUsdAvailable() {
|
240
|
-
return this.supplyLiquidityAvailable * (
|
250
|
+
return this.supplyLiquidityAvailable * (this.supplyPrice() ?? 0);
|
241
251
|
}
|
242
252
|
|
243
253
|
get debtLiquidityAvailable() {
|
@@ -324,8 +334,8 @@ export abstract class SolautoPositionEx {
|
|
324
334
|
abstract refreshPositionState(priceType?: PriceType): Promise<void>;
|
325
335
|
|
326
336
|
async utilizationRateBpsDrift(priceType?: PriceType) {
|
327
|
-
const supplyPrice =
|
328
|
-
const debtPrice =
|
337
|
+
const supplyPrice = this.supplyPrice(priceType) ?? 0;
|
338
|
+
const debtPrice = this.debtPrice(priceType) ?? 0;
|
329
339
|
const oldState = await positionStateWithLatestPrices(
|
330
340
|
this.firstState,
|
331
341
|
supplyPrice,
|
@@ -344,20 +354,28 @@ export abstract class SolautoPositionEx {
|
|
344
354
|
this._data.state.supply.amountUsed.baseAmountUsdValue =
|
345
355
|
toRoundedUsdValue(newSupplyUsd);
|
346
356
|
this._data.state.supply.amountUsed.baseUnit = toBaseUnit(
|
347
|
-
newSupplyUsd / (supplyPrice ??
|
357
|
+
newSupplyUsd / (supplyPrice ?? this.supplyPrice() ?? 0),
|
348
358
|
this.supplyMintInfo.decimals
|
349
359
|
);
|
350
360
|
}
|
351
361
|
|
362
|
+
updateSupplyPrice(price: number) {
|
363
|
+
this._supplyPrice = price;
|
364
|
+
}
|
365
|
+
|
352
366
|
updateDebt(newDebtUsd: number, debtPrice?: number) {
|
353
367
|
this._data.state.debt.amountUsed.baseAmountUsdValue =
|
354
368
|
toRoundedUsdValue(newDebtUsd);
|
355
369
|
this._data.state.debt.amountUsed.baseUnit = toBaseUnit(
|
356
|
-
newDebtUsd / (debtPrice ??
|
370
|
+
newDebtUsd / (debtPrice ?? this.debtPrice() ?? 0),
|
357
371
|
this.debtMintInfo.decimals
|
358
372
|
);
|
359
373
|
}
|
360
374
|
|
375
|
+
updateDebtPrice(price: number) {
|
376
|
+
this._debtPrice = price;
|
377
|
+
}
|
378
|
+
|
361
379
|
updateNetWorth(supplyPrice?: number) {
|
362
380
|
const netWorthUsd = this.supplyUsd() - this.debtUsd();
|
363
381
|
this._data.state.netWorth.baseAmountUsdValue =
|
@@ -380,34 +398,6 @@ export abstract class SolautoPositionEx {
|
|
380
398
|
);
|
381
399
|
}
|
382
400
|
|
383
|
-
async updateWithLatestPrices(data?: {
|
384
|
-
priceType?: PriceType;
|
385
|
-
supplyPrice?: number;
|
386
|
-
debtPrice?: number;
|
387
|
-
}) {
|
388
|
-
if (!data) {
|
389
|
-
data = {};
|
390
|
-
}
|
391
|
-
|
392
|
-
if (!data.supplyPrice || !data.debtPrice) {
|
393
|
-
[data.supplyPrice, data.debtPrice] = await fetchTokenPrices(
|
394
|
-
[this.supplyMint, this.debtMint],
|
395
|
-
data.priceType
|
396
|
-
);
|
397
|
-
}
|
398
|
-
|
399
|
-
const supplyUsd = this.totalSupply * data.supplyPrice;
|
400
|
-
const debtUsd = this.totalDebt * data.debtPrice;
|
401
|
-
|
402
|
-
this.updateSupply(supplyUsd, data.supplyPrice);
|
403
|
-
this.updateDebt(debtUsd, data.debtPrice);
|
404
|
-
this.updateNetWorth(data.supplyPrice);
|
405
|
-
this.updateLiqUtilizationRate(
|
406
|
-
this.totalSupply * data.supplyPrice,
|
407
|
-
this.totalDebt * data.debtPrice
|
408
|
-
);
|
409
|
-
}
|
410
|
-
|
411
401
|
simulateRebalance(
|
412
402
|
unixTime: number,
|
413
403
|
supplyPrice: number,
|
@@ -428,7 +418,10 @@ export abstract class SolautoPositionEx {
|
|
428
418
|
this.updateSupply(rebalance.endResult.supplyUsd, supplyPrice);
|
429
419
|
this.updateDebt(rebalance.endResult.debtUsd, debtPrice);
|
430
420
|
this.updateNetWorth(supplyPrice);
|
431
|
-
this.updateLiqUtilizationRate(
|
421
|
+
this.updateLiqUtilizationRate(
|
422
|
+
rebalance.endResult.supplyUsd,
|
423
|
+
rebalance.endResult.debtUsd
|
424
|
+
);
|
432
425
|
}
|
433
426
|
|
434
427
|
async refetchPositionData() {
|