@haven-fi/solauto-sdk 1.0.693 → 1.0.695
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/dist/constants/solautoConstants.d.ts +9 -5
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceSwapManager.js +2 -2
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceTxBuilder.js +1 -7
- package/dist/services/transactions/transactionUtils.js +1 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts +4 -2
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.js +6 -0
- package/dist/solautoPosition/solautoPositionEx.d.ts +4 -4
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/solautoPositionEx.js +1 -1
- package/dist/utils/priceUtils.d.ts +5 -2
- package/dist/utils/priceUtils.d.ts.map +1 -1
- package/dist/utils/priceUtils.js +26 -19
- package/dist/utils/switchboardUtils.d.ts.map +1 -1
- package/dist/utils/switchboardUtils.js +2 -0
- package/local/shared.ts +2 -4
- package/local/txSandbox.ts +10 -75
- package/package.json +1 -1
- package/src/constants/solautoConstants.ts +9 -2
- package/src/services/rebalance/rebalanceSwapManager.ts +2 -2
- package/src/services/rebalance/rebalanceTxBuilder.ts +2 -10
- package/src/services/transactions/transactionUtils.ts +1 -1
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +11 -3
- package/src/solautoPosition/solautoPositionEx.ts +5 -5
- package/src/utils/priceUtils.ts +35 -22
- package/src/utils/switchboardUtils.ts +2 -0
@@ -6,15 +6,19 @@ export declare const MIN_BOOST_GAP_BPS = 50;
|
|
6
6
|
export declare const MIN_USD_SUPPORTED_POSITION = 1000;
|
7
7
|
export declare const OFFSET_FROM_MAX_LTV = 0.005;
|
8
8
|
export declare const REFERRER_PERCENTAGE = 0.15;
|
9
|
+
interface PriceCache {
|
10
|
+
realtimePrice: number;
|
11
|
+
confInterval: number;
|
12
|
+
emaPrice: number;
|
13
|
+
emaConfInterval: number;
|
14
|
+
time: number;
|
15
|
+
}
|
9
16
|
export declare const PRICES: {
|
10
|
-
[key: string]:
|
11
|
-
realtimePrice: number;
|
12
|
-
emaPrice: number;
|
13
|
-
time: number;
|
14
|
-
};
|
17
|
+
[key: string]: PriceCache;
|
15
18
|
};
|
16
19
|
export declare const CHORES_TX_NAME = "account chores";
|
17
20
|
export declare const JITO_TIP_ACCOUNTS: string[];
|
18
21
|
export declare const SOLAUTO_LUT = "8b7KefQDroVLGao71J5H3hFwABeyMCgCrLpXWssNFhk9";
|
19
22
|
export declare const STANDARD_LUT_ACCOUNTS: string[];
|
23
|
+
export {};
|
20
24
|
//# sourceMappingURL=solautoConstants.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AAQzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,
|
1
|
+
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AAQzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,UAAU,UAAU;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;CACd;AACD,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAO,CAAC;AAExD,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAE/C,eAAO,MAAM,iBAAiB,UAS7B,CAAC;AAEF,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAC1E,eAAO,MAAM,qBAAqB,UAYR,CAAC"}
|
@@ -22,14 +22,14 @@ class RebalanceSwapManager {
|
|
22
22
|
}
|
23
23
|
postRebalanceLiqUtilizationRateBps(swapOutputAmount) {
|
24
24
|
let supplyUsd = this.client.pos.supplyUsd(this.priceType);
|
25
|
-
// TODO: add token balance change
|
26
25
|
let debtUsd = this.client.pos.debtUsd(this.priceType);
|
26
|
+
// TODO: add token balance change
|
27
27
|
const outputToken = this.isBoost()
|
28
28
|
? this.client.pos.supplyMint
|
29
29
|
: this.client.pos.debtMint;
|
30
30
|
const swapOutputUsd = swapOutputAmount
|
31
31
|
? (0, utils_1.fromBaseUnit)(swapOutputAmount, (0, utils_1.tokenInfo)(outputToken).decimals) *
|
32
|
-
(
|
32
|
+
(0, utils_1.safeGetPrice)(outputToken, this.priceType)
|
33
33
|
: this.usdToSwap();
|
34
34
|
supplyUsd = this.isBoost()
|
35
35
|
? supplyUsd + swapOutputUsd
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;
|
1
|
+
{"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;AA8BrB,qBAAa,kBAAkB;IAQ3B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,2BAA2B,CAAC;IACpC,OAAO,CAAC,YAAY,CAAC;IATvB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAC,CAAwB;IAC/C,OAAO,CAAC,SAAS,CAAiC;gBAGxC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,YAAA,EACpC,YAAY,CAAC,EAAE,OAAO,YAAA;IAGhC,OAAO,CAAC,0BAA0B;IAclC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,oBAAoB;IAwC5B,OAAO,CAAC,iCAAiC;YAgC3B,qBAAqB;IA0CnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,yBAAyB;YAqBnB,mBAAmB;YAyBnB,sBAAsB;YAyBtB,mBAAmB;IAwEpB,gBAAgB,CAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;CAe9C"}
|
@@ -199,13 +199,7 @@ class RebalanceTxBuilder {
|
|
199
199
|
priceType: this.priceType,
|
200
200
|
};
|
201
201
|
(0, utils_1.consoleLog)("Rebalance details:", rebalanceDetails);
|
202
|
-
(0, utils_1.consoleLog)("Prices:",
|
203
|
-
// TODO: remove me
|
204
|
-
if ((0, utils_1.isMarginfiPosition)(this.client.pos)) {
|
205
|
-
const weightedAssets = this.values.endResult.supplyUsd * (0, utils_1.bytesToI80F48)(this.client.pos.supplyBank.config.assetWeightInit.value);
|
206
|
-
const weightedLiabs = this.values.endResult.debtUsd * (0, utils_1.bytesToI80F48)(this.client.pos.debtBank.config.liabilityWeightInit.value);
|
207
|
-
(0, utils_1.consoleLog)("Weighted assets & liabs:", weightedAssets, weightedLiabs);
|
208
|
-
}
|
202
|
+
(0, utils_1.consoleLog)("Prices:", this.client.pos.supplyPrice(this.priceType), this.client.pos.debtPrice(this.priceType));
|
209
203
|
const firstRebalance = this.client.rebalanceIx(generated_1.RebalanceStep.PreSwap, rebalanceDetails);
|
210
204
|
const lastRebalance = this.client.rebalanceIx(generated_1.RebalanceStep.PostSwap, rebalanceDetails);
|
211
205
|
if (!flashLoanDetails) {
|
@@ -348,7 +348,7 @@ function getErrorInfo(umi, txs, error, simulationSuccessful) {
|
|
348
348
|
let errCode;
|
349
349
|
let errName;
|
350
350
|
// sub ixs to account for computeUnitLimit and computeUnitPrice that get added
|
351
|
-
const getComputeIxs = (txIdx) => (0, utils_1.addTxOptimizations)(umi, txs[txIdx], 1,
|
351
|
+
const getComputeIxs = (txIdx) => (0, utils_1.addTxOptimizations)(umi, txs[txIdx], 1, simulationSuccessful ? 1 : undefined).getInstructions().length - txs[txIdx].getInstructions().length;
|
352
352
|
try {
|
353
353
|
if (error instanceof types_1.BundleSimulationError) {
|
354
354
|
errTxIdx = error.details.transactionIdx;
|
@@ -5,8 +5,10 @@ import { LendingPlatform, PriceType } from "../generated";
|
|
5
5
|
export declare class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
6
6
|
lendingPlatform: LendingPlatform;
|
7
7
|
maxLtvPriceType: PriceType;
|
8
|
-
supplyBank
|
9
|
-
debtBank
|
8
|
+
private supplyBank;
|
9
|
+
private debtBank;
|
10
|
+
supplyPrice(priceType?: PriceType): number | undefined;
|
11
|
+
debtPrice(priceType?: PriceType): number | undefined;
|
10
12
|
private getBankAccounts;
|
11
13
|
getBanks(): Promise<Bank[]>;
|
12
14
|
priceOracles(): Promise<PublicKey[]>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,
|
1
|
+
{"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAA+B,MAAM,iBAAiB,CAAC;AAepE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1D,qBAAa,yBAA0B,SAAQ,iBAAiB;IAC9D,eAAe,kBAA4B;IAC3C,eAAe,YAAiB;IAEhC,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,QAAQ,CAAqB;IAErC,WAAW,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAItD,SAAS,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAIpD,OAAO,CAAC,eAAe;IAMjB,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAW3B,YAAY,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IASpC,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAa3D,OAAO,CAAC,6BAA6B;IAwBrC,gCAAgC,CAAC,KAAK,EAAE,IAAI,EAAE;IAK9C,4BAA4B,CAAC,KAAK,EAAE,IAAI,EAAE;IAQ1C,IAAI,eAAe,cAElB;IAED,IAAI,aAAa,cAEhB;IAED,IAAI,wBAAwB,IAAI,MAAM,CAKrC;IAEK,oBAAoB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BjE"}
|
@@ -16,6 +16,12 @@ class MarginfiSolautoPositionEx extends solautoPositionEx_1.SolautoPositionEx {
|
|
16
16
|
this.supplyBank = null;
|
17
17
|
this.debtBank = null;
|
18
18
|
}
|
19
|
+
supplyPrice(priceType) {
|
20
|
+
return this._supplyPrice ?? (0, utils_1.safeGetPrice)(this.supplyMint, priceType, marginfi_sdk_1.PriceBias.Low);
|
21
|
+
}
|
22
|
+
debtPrice(priceType) {
|
23
|
+
return this._debtPrice ?? (0, utils_1.safeGetPrice)(this.debtMint, priceType, marginfi_sdk_1.PriceBias.High);
|
24
|
+
}
|
19
25
|
getBankAccounts(mint) {
|
20
26
|
const group = this.lpPoolAccount.toString();
|
21
27
|
const bankAccounts = (0, constants_1.getMarginfiAccounts)(this.lpEnv).bankAccounts;
|
@@ -39,8 +39,8 @@ export declare abstract class SolautoPositionEx {
|
|
39
39
|
private _debtMint?;
|
40
40
|
protected _data: SolautoPositionExData;
|
41
41
|
private readonly firstState;
|
42
|
-
|
43
|
-
|
42
|
+
protected _supplyPrice?: number;
|
43
|
+
protected _debtPrice?: number;
|
44
44
|
rebalance: PositionRebalanceHelper;
|
45
45
|
maxLtvPriceType: PriceType;
|
46
46
|
constructor(args: PositionExArgs);
|
@@ -69,10 +69,10 @@ export declare abstract class SolautoPositionEx {
|
|
69
69
|
netWorthUsd(priceType?: PriceType): number;
|
70
70
|
get totalSupply(): number;
|
71
71
|
supplyUsd(priceType?: PriceType): number;
|
72
|
-
|
72
|
+
supplyPrice(priceType?: PriceType): number | undefined;
|
73
73
|
get totalDebt(): number;
|
74
74
|
debtUsd(priceType?: PriceType): number;
|
75
|
-
|
75
|
+
debtPrice(priceType?: PriceType): number | undefined;
|
76
76
|
get supplyLiquidityDepositable(): number;
|
77
77
|
get supplyLiquidityUsdDepositable(): number;
|
78
78
|
get supplyLiquidityUsdAvailable(): number;
|
@@ -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,EAEL,eAAe,EACf,aAAa,EACb,SAAS,EACT,eAAe,EACf,yBAAyB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAOL,cAAc,EAkBf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAMvD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,WAAW,kBAAkB;IACjC,eAAe,EAAE,eAAe,CAAC;IACjC,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,SAAS,CAAC;IAC1B,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,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,qBAAqB,CAAC;IAC5B,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,8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gB,wBAEnB;IAED,oBAAoB,CAClB,oBAAoB,GAAE,MAAU,EAChC,eAAe,CAAC,EAAE,OAAO,GACxB,eAAe,GAAG,SAAS;IAO9B,kBAAkB,IAAI,OAAO;IAQ7B,SAAS,CAAC,uBAAuB;IAUjC,QAAQ,CAAC,oBAAoB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAE7D,uBAAuB,CAAC,SAAS,CAAC,EAAE,SAAS;IAiBnD,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM;IASvD,iBAAiB,CAAC,KAAK,EAAE,MAAM;IAI/B,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;IASjD,eAAe,CAAC,KAAK,EAAE,MAAM;IAI7B,cAAc,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;IA0BhC,mBAAmB;CAM1B;AAED,cAAM,uBAAuB;IACf,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,iBAAiB;IAE1C,OAAO,CAAC,0BAA0B;IA0BlC,wBAAwB,CAAC,iBAAiB,EAAE,MAAM;IAoBlD,OAAO,CAAC,kBAAkB;IAwB1B,oBAAoB,CAClB,oBAAoB,EAAE,MAAM,EAC5B,eAAe,CAAC,EAAE,OAAO,GACxB,eAAe,GAAG,SAAS;CAwB/B"}
|
@@ -182,7 +182,7 @@ class SolautoPositionEx {
|
|
182
182
|
const netWorthUsd = this.supplyUsd() - this.debtUsd();
|
183
183
|
this._data.state.netWorth.baseAmountUsdValue =
|
184
184
|
(0, utils_1.toRoundedUsdValue)(netWorthUsd);
|
185
|
-
this._data.state.netWorth.baseUnit = (0, utils_1.toBaseUnit)(netWorthUsd / (supplyPrice ??
|
185
|
+
this._data.state.netWorth.baseUnit = (0, utils_1.toBaseUnit)(netWorthUsd / (supplyPrice ?? this.supplyPrice()), this.supplyMintInfo.decimals);
|
186
186
|
}
|
187
187
|
updateLiqUtilizationRate(supplyUsd, debtUsd, priceType) {
|
188
188
|
this._data.state.liqUtilizationRateBps = (0, utils_1.getLiqUtilzationRateBps)(supplyUsd ?? this.supplyUsd(priceType), debtUsd ?? this.debtUsd(priceType), this.state.liqThresholdBps);
|
@@ -1,14 +1,17 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { PublicKey as UmiPublicKey } from "@metaplex-foundation/umi";
|
3
3
|
import { PriceType } from "../generated";
|
4
|
+
import { PriceBias } from "../marginfi-sdk";
|
4
5
|
interface PriceResult {
|
5
6
|
realtimePrice: number;
|
7
|
+
confInterval?: number;
|
6
8
|
emaPrice?: number;
|
9
|
+
emaConfInterval?: number;
|
7
10
|
}
|
8
|
-
export declare function fetchTokenPrices(mints: PublicKey[], priceType?: PriceType): Promise<number[]>;
|
11
|
+
export declare function fetchTokenPrices(mints: PublicKey[], priceType?: PriceType, priceBias?: PriceBias): Promise<number[]>;
|
9
12
|
export declare function getPythPrices(mints: PublicKey[]): Promise<Record<string, PriceResult>>;
|
10
13
|
export declare function getSwitchboardPrices(mints: PublicKey[]): Promise<Record<string, PriceResult>>;
|
11
14
|
export declare function getJupTokenPrices(mints: PublicKey[]): Promise<Record<string, PriceResult>>;
|
12
|
-
export declare function safeGetPrice(mint: PublicKey | UmiPublicKey | string | undefined, priceType?: PriceType): number | undefined;
|
15
|
+
export declare function safeGetPrice(mint: PublicKey | UmiPublicKey | string | undefined, priceType?: PriceType, priceBias?: PriceBias): number | undefined;
|
13
16
|
export {};
|
14
17
|
//# sourceMappingURL=priceUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAerE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
1
|
+
{"version":3,"file":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAerE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,UAAU,WAAW;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,SAAS,EAAE,EAClB,SAAS,GAAE,SAA8B,EACzC,SAAS,CAAC,EAAE,SAAS,GACpB,OAAO,CAAC,MAAM,EAAE,CAAC,CA0CnB;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAoDtC;AAkBD,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CA+CtC;AAED,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAiBtC;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,MAAM,GAAG,SAAS,EACnD,SAAS,GAAE,SAA8B,EACzC,SAAS,CAAC,EAAE,SAAS,GACpB,MAAM,GAAG,SAAS,CAsBpB"}
|
package/dist/utils/priceUtils.js
CHANGED
@@ -35,7 +35,8 @@ const numberUtils_1 = require("./numberUtils");
|
|
35
35
|
const generalUtils_1 = require("./generalUtils");
|
36
36
|
const jupiterUtils_1 = require("./jupiterUtils");
|
37
37
|
const generated_1 = require("../generated");
|
38
|
-
|
38
|
+
const marginfi_sdk_1 = require("../marginfi-sdk");
|
39
|
+
async function fetchTokenPrices(mints, priceType = generated_1.PriceType.Realtime, priceBias) {
|
39
40
|
const currentTime = (0, generalUtils_1.currentUnixSeconds)();
|
40
41
|
const mintStrs = mints.map((x) => x.toString());
|
41
42
|
const cachedPrices = Object.fromEntries(Object.entries(constants_1.PRICES).filter(([mint, price]) => mintStrs.includes(mint) && currentTime - price.time <= 3));
|
@@ -51,24 +52,17 @@ async function fetchTokenPrices(mints, priceType = generated_1.PriceType.Realtim
|
|
51
52
|
getJupTokenPrices(otherMints),
|
52
53
|
])));
|
53
54
|
for (const mint of newMints) {
|
54
|
-
const
|
55
|
+
const data = newPrices[mint.toString()];
|
56
|
+
const realtimePrice = data.realtimePrice;
|
55
57
|
constants_1.PRICES[mint.toString()] = {
|
56
58
|
realtimePrice,
|
57
|
-
|
59
|
+
confInterval: data.confInterval ?? 0,
|
60
|
+
emaPrice: data.emaPrice ?? realtimePrice,
|
61
|
+
emaConfInterval: data.emaConfInterval ?? 0,
|
58
62
|
time: (0, generalUtils_1.currentUnixSeconds)(),
|
59
63
|
};
|
60
64
|
}
|
61
|
-
|
62
|
-
...constants_1.PRICES,
|
63
|
-
...newPrices,
|
64
|
-
};
|
65
|
-
return mints.map((x) => {
|
66
|
-
const priceResult = prices[x.toString()];
|
67
|
-
const realtimePrice = priceResult.realtimePrice;
|
68
|
-
return priceType === generated_1.PriceType.Ema
|
69
|
-
? (priceResult.emaPrice ?? realtimePrice)
|
70
|
-
: realtimePrice;
|
71
|
-
});
|
65
|
+
return mints.map((x) => safeGetPrice(x, priceType, priceBias));
|
72
66
|
}
|
73
67
|
async function getPythPrices(mints) {
|
74
68
|
if (mints.length === 0) {
|
@@ -76,7 +70,7 @@ async function getPythPrices(mints) {
|
|
76
70
|
}
|
77
71
|
const priceFeedIds = mints.map((mint) => constants_1.PYTH_PRICE_FEED_IDS[mint.toString()]);
|
78
72
|
const getReq = async () => await fetch(`https://hermes.pyth.network/v2/updates/price/latest?${priceFeedIds.map((x) => `ids%5B%5D=${x}`).join("&")}`);
|
79
|
-
const
|
73
|
+
const deriveValue = (price, exponent) => {
|
80
74
|
if (exponent > 0) {
|
81
75
|
return Number((0, numberUtils_1.toBaseUnit)(Number(price), exponent));
|
82
76
|
}
|
@@ -96,8 +90,10 @@ async function getPythPrices(mints) {
|
|
96
90
|
const json = await resp.json();
|
97
91
|
const prices = json.parsed.map((x) => {
|
98
92
|
return {
|
99
|
-
realtimePrice:
|
100
|
-
|
93
|
+
realtimePrice: deriveValue(x.price.price, x.price.expo),
|
94
|
+
confInterval: deriveValue(x.price.conf, x.price.expo),
|
95
|
+
emaPrice: deriveValue(x.ema_price.price, x.ema_price.expo),
|
96
|
+
emaConfInterval: deriveValue(x.ema_price.conf, x.ema_price.expo),
|
101
97
|
};
|
102
98
|
});
|
103
99
|
return prices;
|
@@ -160,12 +156,23 @@ async function getJupTokenPrices(mints) {
|
|
160
156
|
]));
|
161
157
|
return prices;
|
162
158
|
}
|
163
|
-
function safeGetPrice(mint, priceType = generated_1.PriceType.Realtime) {
|
159
|
+
function safeGetPrice(mint, priceType = generated_1.PriceType.Realtime, priceBias) {
|
164
160
|
if (mint && mint?.toString() in constants_1.PRICES) {
|
165
161
|
const priceData = constants_1.PRICES[mint.toString()];
|
166
|
-
|
162
|
+
let price = priceType === generated_1.PriceType.Ema
|
167
163
|
? priceData.emaPrice
|
168
164
|
: priceData.realtimePrice;
|
165
|
+
if (priceBias !== undefined) {
|
166
|
+
const confInterval = priceType === generated_1.PriceType.Ema ? priceData.confInterval : priceData.emaConfInterval;
|
167
|
+
const conf = Math.min(confInterval * 1.96, price * 0.05);
|
168
|
+
if (priceBias === marginfi_sdk_1.PriceBias.Low) {
|
169
|
+
price = price - conf;
|
170
|
+
}
|
171
|
+
else {
|
172
|
+
price = price + conf;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
return price;
|
169
176
|
}
|
170
177
|
return undefined;
|
171
178
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAsB,MAAM,0BAA0B,CAAC;AAGtE,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AAIvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAOjD,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,qBAuBnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,
|
1
|
+
{"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAsB,MAAM,0BAA0B,CAAC;AAGtE,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AAIvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAOjD,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,qBAuBnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAoC5C;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,CAuB/D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,WAEzD"}
|
@@ -68,7 +68,9 @@ async function buildSwbSubmitResponseTx(conn, signer, mint) {
|
|
68
68
|
const price = responses[0].value.toNumber();
|
69
69
|
constants_1.PRICES[mint.toString()] = {
|
70
70
|
realtimePrice: price,
|
71
|
+
confInterval: price, // TODO: do we need to change if marginfi fixes their stuff?
|
71
72
|
emaPrice: price,
|
73
|
+
emaConfInterval: 0,
|
72
74
|
time: (0, generalUtils_1.currentUnixSeconds)(),
|
73
75
|
};
|
74
76
|
return {
|
package/local/shared.ts
CHANGED
@@ -11,7 +11,7 @@ import {
|
|
11
11
|
import {
|
12
12
|
getSolanaRpcConnection,
|
13
13
|
getBatches,
|
14
|
-
|
14
|
+
LOCAL_IRONFORGE_API_URL,
|
15
15
|
} from "../src";
|
16
16
|
|
17
17
|
function loadSecretKey(keypairPath: string) {
|
@@ -26,9 +26,7 @@ export function getSecretKey(keypairFilename: string = "id"): Uint8Array {
|
|
26
26
|
}
|
27
27
|
|
28
28
|
const keypair = Keypair.fromSecretKey(getSecretKey("solauto-fees"));
|
29
|
-
const [connection, _] = getSolanaRpcConnection(
|
30
|
-
buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY ?? "")
|
31
|
-
);
|
29
|
+
const [connection, _] = getSolanaRpcConnection(LOCAL_IRONFORGE_API_URL);
|
32
30
|
|
33
31
|
export async function createAndSendV0Tx(
|
34
32
|
txInstructions: TransactionInstruction[],
|
package/local/txSandbox.ts
CHANGED
@@ -1,22 +1,16 @@
|
|
1
1
|
import { Keypair, PublicKey } from "@solana/web3.js";
|
2
|
-
import { createSignerFromKeypair
|
2
|
+
import { createSignerFromKeypair } from "@metaplex-foundation/umi";
|
3
3
|
import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
|
4
4
|
import {
|
5
|
-
bytesToI80F48,
|
6
5
|
ClientTransactionsManager,
|
7
6
|
consoleLog,
|
8
|
-
fetchBank,
|
9
|
-
fetchMarginfiAccount,
|
10
7
|
getBatches,
|
11
8
|
getClient,
|
12
|
-
getLiqUtilzationRateBps,
|
13
|
-
getMaxLiqUtilizationRateBps,
|
14
9
|
getPositionExBulk,
|
15
10
|
getSolanaRpcConnection,
|
16
11
|
getSolautoManagedPositions,
|
17
12
|
LendingPlatform,
|
18
13
|
LOCAL_IRONFORGE_API_URL,
|
19
|
-
marginfiAccountEmpty,
|
20
14
|
PriceType,
|
21
15
|
PriorityFeeSetting,
|
22
16
|
ProgramEnv,
|
@@ -60,75 +54,16 @@ export async function main() {
|
|
60
54
|
// ),
|
61
55
|
});
|
62
56
|
|
63
|
-
const
|
64
|
-
umi,
|
65
|
-
publicKey("6cgYhBFWCc5sNHxkvSRhd5H9AdAHR41zKwuF37HmLry5")
|
66
|
-
);
|
67
|
-
const debtBank = await fetchBank(
|
68
|
-
umi,
|
69
|
-
publicKey("3J5rKmCi7JXG6qmiobFJyAidVTnnNAMGj4jomfBxKGRM")
|
70
|
-
);
|
71
|
-
const supplyWeight = bytesToI80F48(supplyBank.config.assetWeightInit.value);
|
72
|
-
const debtWeight = bytesToI80F48(debtBank.config.liabilityWeightInit.value);
|
73
|
-
|
74
|
-
console.log(
|
75
|
-
getLiqUtilzationRateBps(
|
76
|
-
34.36833665228071,
|
77
|
-
23.61750715267401,
|
78
|
-
client.pos.state.liqThresholdBps
|
79
|
-
),
|
80
|
-
34.36833665228071 * supplyWeight,
|
81
|
-
23.61750715267401 * debtWeight
|
82
|
-
);
|
83
|
-
console.log(
|
84
|
-
getLiqUtilzationRateBps(
|
85
|
-
34.328721976,
|
86
|
-
23.575158311,
|
87
|
-
client.pos.state.liqThresholdBps
|
88
|
-
),
|
89
|
-
34.328721976 * supplyWeight,
|
90
|
-
23.575158311 * debtWeight
|
91
|
-
);
|
92
|
-
console.log(
|
93
|
-
getLiqUtilzationRateBps(
|
94
|
-
34.265152701,
|
95
|
-
23.530695876,
|
96
|
-
client.pos.state.liqThresholdBps
|
97
|
-
),
|
98
|
-
34.265152701 * supplyWeight,
|
99
|
-
23.530695876 * debtWeight
|
100
|
-
);
|
101
|
-
console.log(client.pos.maxBoostToBps);
|
102
|
-
console.log(getMaxLiqUtilizationRateBps(client.pos.state.maxLtvBps, client.pos.state.liqThresholdBps, 0));
|
103
|
-
|
104
|
-
// const debtBank = await fetchBank(
|
105
|
-
// umi,
|
106
|
-
// publicKey("3J5rKmCi7JXG6qmiobFJyAidVTnnNAMGj4jomfBxKGRM")
|
107
|
-
// );
|
108
|
-
// const supplyBank = await fetchBank(
|
109
|
-
// umi,
|
110
|
-
// publicKey("6cgYhBFWCc5sNHxkvSRhd5H9AdAHR41zKwuF37HmLry5")
|
111
|
-
// );
|
112
|
-
|
113
|
-
// console.log(
|
114
|
-
// bytesToI80F48(supplyBank.config.assetWeightInit.value),
|
115
|
-
// bytesToI80F48(debtBank.config.liabilityWeightInit.value)
|
116
|
-
// );
|
117
|
-
|
118
|
-
// await client.pos.refreshPositionState();
|
57
|
+
const transactionItems = [rebalance(client)];
|
119
58
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
// retryConfig: { totalRetries: 5 },
|
129
|
-
// });
|
130
|
-
// const statuses = await txManager.send(transactionItems);
|
131
|
-
// consoleLog(statuses);
|
59
|
+
const txManager = new ClientTransactionsManager({
|
60
|
+
txHandler: client,
|
61
|
+
txRunType: payForTransaction ? "normal" : "only-simulate",
|
62
|
+
priorityFeeSetting: PriorityFeeSetting.Default,
|
63
|
+
retryConfig: { totalRetries: 5 },
|
64
|
+
});
|
65
|
+
const statuses = await txManager.send(transactionItems);
|
66
|
+
consoleLog(statuses);
|
132
67
|
}
|
133
68
|
|
134
69
|
async function refreshAll() {
|
package/package.json
CHANGED
@@ -29,7 +29,14 @@ export const OFFSET_FROM_MAX_LTV = 0.005;
|
|
29
29
|
|
30
30
|
export const REFERRER_PERCENTAGE = 0.15;
|
31
31
|
|
32
|
-
|
32
|
+
interface PriceCache {
|
33
|
+
realtimePrice: number;
|
34
|
+
confInterval: number;
|
35
|
+
emaPrice: number;
|
36
|
+
emaConfInterval: number;
|
37
|
+
time: number;
|
38
|
+
}
|
39
|
+
export const PRICES: { [key: string]: PriceCache } = {};
|
33
40
|
|
34
41
|
export const CHORES_TX_NAME = "account chores";
|
35
42
|
|
@@ -57,4 +64,4 @@ export const STANDARD_LUT_ACCOUNTS = [
|
|
57
64
|
SYSVAR_RENT_PUBKEY,
|
58
65
|
SYSVAR_INSTRUCTIONS_PUBKEY,
|
59
66
|
JUPITER_PROGRAM_ID,
|
60
|
-
].map((x) => x.toString());
|
67
|
+
].map((x) => x.toString());
|
@@ -41,15 +41,15 @@ export class RebalanceSwapManager {
|
|
41
41
|
|
42
42
|
private postRebalanceLiqUtilizationRateBps(swapOutputAmount?: bigint) {
|
43
43
|
let supplyUsd = this.client.pos.supplyUsd(this.priceType);
|
44
|
-
// TODO: add token balance change
|
45
44
|
let debtUsd = this.client.pos.debtUsd(this.priceType);
|
45
|
+
// TODO: add token balance change
|
46
46
|
|
47
47
|
const outputToken = this.isBoost()
|
48
48
|
? this.client.pos.supplyMint
|
49
49
|
: this.client.pos.debtMint;
|
50
50
|
const swapOutputUsd = swapOutputAmount
|
51
51
|
? fromBaseUnit(swapOutputAmount, tokenInfo(outputToken).decimals) *
|
52
|
-
|
52
|
+
safeGetPrice(outputToken, this.priceType)!
|
53
53
|
: this.usdToSwap();
|
54
54
|
|
55
55
|
supplyUsd = this.isBoost()
|
@@ -8,7 +8,6 @@ import {
|
|
8
8
|
TransactionItemInputs,
|
9
9
|
} from "../../types";
|
10
10
|
import {
|
11
|
-
bytesToI80F48,
|
12
11
|
consoleLog,
|
13
12
|
fromBaseUnit,
|
14
13
|
fromBps,
|
@@ -16,7 +15,6 @@ import {
|
|
16
15
|
getTokenAccount,
|
17
16
|
hasFirstRebalance,
|
18
17
|
hasLastRebalance,
|
19
|
-
isMarginfiPosition,
|
20
18
|
safeGetPrice,
|
21
19
|
tokenInfo,
|
22
20
|
} from "../../utils";
|
@@ -344,15 +342,9 @@ export class RebalanceTxBuilder {
|
|
344
342
|
consoleLog("Rebalance details:", rebalanceDetails);
|
345
343
|
consoleLog(
|
346
344
|
"Prices:",
|
347
|
-
|
348
|
-
|
345
|
+
this.client.pos.supplyPrice(this.priceType),
|
346
|
+
this.client.pos.debtPrice(this.priceType)
|
349
347
|
);
|
350
|
-
// TODO: remove me
|
351
|
-
if (isMarginfiPosition(this.client.pos)) {
|
352
|
-
const weightedAssets = this.values.endResult.supplyUsd * bytesToI80F48(this.client.pos.supplyBank!.config.assetWeightInit.value);
|
353
|
-
const weightedLiabs = this.values.endResult.debtUsd * bytesToI80F48(this.client.pos.debtBank!.config.liabilityWeightInit.value);
|
354
|
-
consoleLog("Weighted assets & liabs:", weightedAssets, weightedLiabs);
|
355
|
-
}
|
356
348
|
|
357
349
|
const firstRebalance = this.client.rebalanceIx(
|
358
350
|
RebalanceStep.PreSwap,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import { Bank, safeFetchAllBank } from "../marginfi-sdk";
|
2
|
+
import { Bank, PriceBias, safeFetchAllBank } from "../marginfi-sdk";
|
3
3
|
import { publicKey } from "@metaplex-foundation/umi";
|
4
4
|
import {
|
5
5
|
calcMarginfiMaxLtvAndLiqThresholdBps,
|
@@ -21,8 +21,16 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
21
21
|
lendingPlatform = LendingPlatform.Marginfi;
|
22
22
|
maxLtvPriceType = PriceType.Ema;
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
private supplyBank: Bank | null = null;
|
25
|
+
private debtBank: Bank | null = null;
|
26
|
+
|
27
|
+
supplyPrice(priceType?: PriceType): number | undefined {
|
28
|
+
return this._supplyPrice ?? safeGetPrice(this.supplyMint, priceType, PriceBias.Low);
|
29
|
+
}
|
30
|
+
|
31
|
+
debtPrice(priceType?: PriceType): number | undefined {
|
32
|
+
return this._debtPrice ?? safeGetPrice(this.debtMint, priceType, PriceBias.High);
|
33
|
+
}
|
26
34
|
|
27
35
|
private getBankAccounts(mint: PublicKey) {
|
28
36
|
const group = this.lpPoolAccount.toString();
|
@@ -87,8 +87,8 @@ export abstract class SolautoPositionEx {
|
|
87
87
|
|
88
88
|
private readonly firstState!: PositionState;
|
89
89
|
|
90
|
-
|
91
|
-
|
90
|
+
protected _supplyPrice?: number;
|
91
|
+
protected _debtPrice?: number;
|
92
92
|
|
93
93
|
public rebalance!: PositionRebalanceHelper;
|
94
94
|
public maxLtvPriceType!: PriceType;
|
@@ -236,7 +236,7 @@ export abstract class SolautoPositionEx {
|
|
236
236
|
: calcSupplyUsd(this.state);
|
237
237
|
}
|
238
238
|
|
239
|
-
|
239
|
+
supplyPrice(priceType?: PriceType) {
|
240
240
|
return this._supplyPrice ?? safeGetPrice(this.supplyMint, priceType);
|
241
241
|
}
|
242
242
|
|
@@ -251,7 +251,7 @@ export abstract class SolautoPositionEx {
|
|
251
251
|
: calcDebtUsd(this.state);
|
252
252
|
}
|
253
253
|
|
254
|
-
|
254
|
+
debtPrice(priceType?: PriceType) {
|
255
255
|
return this._debtPrice ?? safeGetPrice(this.debtMint, priceType);
|
256
256
|
}
|
257
257
|
|
@@ -364,7 +364,7 @@ export abstract class SolautoPositionEx {
|
|
364
364
|
this._data.state.netWorth.baseAmountUsdValue =
|
365
365
|
toRoundedUsdValue(netWorthUsd);
|
366
366
|
this._data.state.netWorth.baseUnit = toBaseUnit(
|
367
|
-
netWorthUsd / (supplyPrice ??
|
367
|
+
netWorthUsd / (supplyPrice ?? this.supplyPrice()!),
|
368
368
|
this.supplyMintInfo.decimals
|
369
369
|
);
|
370
370
|
}
|
package/src/utils/priceUtils.ts
CHANGED
@@ -15,15 +15,19 @@ import {
|
|
15
15
|
} from "./generalUtils";
|
16
16
|
import { getJupPriceData } from "./jupiterUtils";
|
17
17
|
import { PriceType } from "../generated";
|
18
|
+
import { PriceBias } from "../marginfi-sdk";
|
18
19
|
|
19
20
|
interface PriceResult {
|
20
21
|
realtimePrice: number;
|
22
|
+
confInterval?: number;
|
21
23
|
emaPrice?: number;
|
24
|
+
emaConfInterval?: number;
|
22
25
|
}
|
23
26
|
|
24
27
|
export async function fetchTokenPrices(
|
25
28
|
mints: PublicKey[],
|
26
|
-
priceType: PriceType = PriceType.Realtime
|
29
|
+
priceType: PriceType = PriceType.Realtime,
|
30
|
+
priceBias?: PriceBias
|
27
31
|
): Promise<number[]> {
|
28
32
|
const currentTime = currentUnixSeconds();
|
29
33
|
const mintStrs = mints.map((x) => x.toString());
|
@@ -54,26 +58,18 @@ export async function fetchTokenPrices(
|
|
54
58
|
);
|
55
59
|
|
56
60
|
for (const mint of newMints) {
|
57
|
-
const
|
61
|
+
const data = newPrices[mint.toString()];
|
62
|
+
const realtimePrice = data.realtimePrice;
|
58
63
|
PRICES[mint.toString()] = {
|
59
64
|
realtimePrice,
|
60
|
-
|
65
|
+
confInterval: data.confInterval ?? 0,
|
66
|
+
emaPrice: data.emaPrice ?? realtimePrice,
|
67
|
+
emaConfInterval: data.emaConfInterval ?? 0,
|
61
68
|
time: currentUnixSeconds(),
|
62
69
|
};
|
63
70
|
}
|
64
71
|
|
65
|
-
|
66
|
-
...PRICES,
|
67
|
-
...newPrices,
|
68
|
-
};
|
69
|
-
|
70
|
-
return mints.map((x) => {
|
71
|
-
const priceResult = prices[x.toString()];
|
72
|
-
const realtimePrice = priceResult.realtimePrice;
|
73
|
-
return priceType === PriceType.Ema
|
74
|
-
? (priceResult.emaPrice ?? realtimePrice)
|
75
|
-
: realtimePrice;
|
76
|
-
});
|
72
|
+
return mints.map((x) => safeGetPrice(x, priceType, priceBias)!);
|
77
73
|
}
|
78
74
|
|
79
75
|
export async function getPythPrices(
|
@@ -92,7 +88,7 @@ export async function getPythPrices(
|
|
92
88
|
`https://hermes.pyth.network/v2/updates/price/latest?${priceFeedIds.map((x) => `ids%5B%5D=${x}`).join("&")}`
|
93
89
|
);
|
94
90
|
|
95
|
-
const
|
91
|
+
const deriveValue = (price: number, exponent: number) => {
|
96
92
|
if (exponent > 0) {
|
97
93
|
return Number(toBaseUnit(Number(price), exponent));
|
98
94
|
} else if (exponent < 0) {
|
@@ -113,8 +109,10 @@ export async function getPythPrices(
|
|
113
109
|
const json = await resp.json();
|
114
110
|
const prices = json.parsed.map((x: any) => {
|
115
111
|
return {
|
116
|
-
realtimePrice:
|
117
|
-
|
112
|
+
realtimePrice: deriveValue(x.price.price, x.price.expo),
|
113
|
+
confInterval: deriveValue(x.price.conf, x.price.expo),
|
114
|
+
emaPrice: deriveValue(x.ema_price.price, x.ema_price.expo),
|
115
|
+
emaConfInterval: deriveValue(x.ema_price.conf, x.ema_price.expo),
|
118
116
|
};
|
119
117
|
});
|
120
118
|
|
@@ -220,13 +218,28 @@ export async function getJupTokenPrices(
|
|
220
218
|
|
221
219
|
export function safeGetPrice(
|
222
220
|
mint: PublicKey | UmiPublicKey | string | undefined,
|
223
|
-
priceType: PriceType = PriceType.Realtime
|
221
|
+
priceType: PriceType = PriceType.Realtime,
|
222
|
+
priceBias?: PriceBias
|
224
223
|
): number | undefined {
|
225
224
|
if (mint && mint?.toString() in PRICES) {
|
226
225
|
const priceData = PRICES[mint!.toString()];
|
227
|
-
|
228
|
-
|
229
|
-
|
226
|
+
let price =
|
227
|
+
priceType === PriceType.Ema
|
228
|
+
? priceData.emaPrice
|
229
|
+
: priceData.realtimePrice;
|
230
|
+
|
231
|
+
if (priceBias !== undefined) {
|
232
|
+
const confInterval = priceType === PriceType.Ema ? priceData.confInterval : priceData.emaConfInterval;
|
233
|
+
const conf = Math.min(confInterval * 1.96, price * 0.05);
|
234
|
+
|
235
|
+
if (priceBias === PriceBias.Low) {
|
236
|
+
price = price - conf;
|
237
|
+
} else {
|
238
|
+
price = price + conf;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
return price;
|
230
243
|
}
|
231
244
|
return undefined;
|
232
245
|
}
|
@@ -74,7 +74,9 @@ export async function buildSwbSubmitResponseTx(
|
|
74
74
|
const price = (responses[0].value as Big).toNumber();
|
75
75
|
PRICES[mint.toString()] = {
|
76
76
|
realtimePrice: price,
|
77
|
+
confInterval: price, // TODO: do we need to change if marginfi fixes their stuff?
|
77
78
|
emaPrice: price,
|
79
|
+
emaConfInterval: 0,
|
78
80
|
time: currentUnixSeconds(),
|
79
81
|
};
|
80
82
|
|