@haven-fi/solauto-sdk 1.0.72 → 1.0.74
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/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +5 -0
- package/dist/constants/solautoConstants.d.ts +3 -2
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +4 -3
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +3 -3
- package/dist/utils/numberUtils.js +3 -3
- package/dist/utils/solauto/generalUtils.d.ts +2 -2
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +11 -9
- package/package.json +1 -1
- package/src/clients/solautoMarginfiClient.ts +49 -27
- package/src/constants/solautoConstants.ts +4 -2
- package/src/utils/marginfiUtils.ts +4 -3
- package/src/utils/numberUtils.ts +4 -4
- package/src/utils/solauto/generalUtils.ts +14 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAM1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAGL,eAAe,EAYhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MA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C;IAC1C,2BAA2B,CAAC,EAAE,eAAe,CAAC;IAE/C,UAAU,CAAC,IAAI,EAAE,yBAAyB;IAkE1C,8BAA8B;IA0CpC,mBAAmB,IAAI,MAAM,EAAE;IAI/B,gBAAgB,IAAI,SAAS,EAAE;IAU/B,yBAAyB,IAAI,kBAAkB;IAS/C,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA8C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA0D5C,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IA2DrB,WAAW,CACT,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAoFlE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAiBlE"}
|
|
@@ -13,6 +13,7 @@ const marginfi_sdk_1 = require("../marginfi-sdk");
|
|
|
13
13
|
const marginfiUtils_1 = require("../utils/marginfiUtils");
|
|
14
14
|
const numberUtils_1 = require("../utils/numberUtils");
|
|
15
15
|
const constants_1 = require("../constants");
|
|
16
|
+
const utils_1 = require("../utils");
|
|
16
17
|
class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
17
18
|
constructor() {
|
|
18
19
|
super(...arguments);
|
|
@@ -52,6 +53,10 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
|
52
53
|
// this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
|
|
53
54
|
this.supplyPriceOracle = new web3_js_1.PublicKey(this.marginfiSupplyAccounts.priceOracle);
|
|
54
55
|
this.debtPriceOracle = new web3_js_1.PublicKey(this.marginfiDebtAccounts.priceOracle);
|
|
56
|
+
if (!this.solautoPositionState) {
|
|
57
|
+
const [maxLtv, liqThreshold] = await (0, marginfiUtils_1.getMaxLtvAndLiqThreshold)(this.umi, { mint: this.supplyMint }, { mint: this.debtMint });
|
|
58
|
+
this.solautoPositionState = (0, utils_1.createFakePositionState)({ mint: this.supplyMint }, { mint: this.debtMint }, (0, numberUtils_1.toBps)(maxLtv), (0, numberUtils_1.toBps)(liqThreshold));
|
|
59
|
+
}
|
|
55
60
|
if (!this.initialized) {
|
|
56
61
|
await this.setIntermediaryMarginfiDetails();
|
|
57
62
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const BASIS_POINTS = 10000;
|
|
2
2
|
export declare const DEFAULT_LIMIT_GAP_BPS = 1000;
|
|
3
3
|
export declare const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const MIN_REPAY_GAP_BPS = 100;
|
|
5
|
+
export declare const MIN_BOOST_GAP_BPS = 50;
|
|
5
6
|
export declare const PRICES: {
|
|
6
7
|
[key: string]: {
|
|
7
8
|
price: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAQpC,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;KAAE,CAAA;CAAO,CAAC;AAE9E,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAE1E,eAAO,MAAM,kBAAkB,gDAAgD,CAAC;AAEhF,eAAO,MAAM,qBAAqB,UAWjC,CAAC"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STANDARD_LUT_ACCOUNTS = exports.JUPITER_PROGRAM_ID = exports.SOLAUTO_LUT = exports.PRICES = exports.
|
|
3
|
+
exports.STANDARD_LUT_ACCOUNTS = exports.JUPITER_PROGRAM_ID = exports.SOLAUTO_LUT = exports.PRICES = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.DEFAULT_LIMIT_GAP_BPS = exports.BASIS_POINTS = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const spl_token_1 = require("@solana/spl-token");
|
|
6
6
|
// import { JitoRpcConnection } from "jito-ts";
|
|
7
7
|
const generated_1 = require("../generated");
|
|
8
8
|
const generalAccounts_1 = require("./generalAccounts");
|
|
9
|
-
exports.
|
|
9
|
+
exports.BASIS_POINTS = 10000;
|
|
10
10
|
exports.DEFAULT_LIMIT_GAP_BPS = 1000;
|
|
11
11
|
exports.MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
|
12
|
-
exports.
|
|
12
|
+
exports.MIN_REPAY_GAP_BPS = 100;
|
|
13
|
+
exports.MIN_BOOST_GAP_BPS = 50;
|
|
13
14
|
// export const JITO_BLOCK_ENGINE = "ny.mainnet.block-engine.jito.wtf";
|
|
14
15
|
// export const JITO_CONNECTION = new JitoRpcConnection(
|
|
15
16
|
// `https://${JITO_BLOCK_ENGINE}`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAKL,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAKL,MAAM,iBAAiB,CAAC;AAWzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,GAAG,qBAAqB,CAU3E;AAED,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE;IACN,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB,EACD,IAAI,EAAE;IACJ,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB,EACD,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA2D3B;AAED,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CACR;IAAE,eAAe,EAAE,SAAS,CAAC;IAAC,UAAU,CAAC,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,EAAE,CAC/E,CA6CA;AAgED,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,SAAS,EAC5B,UAAU,CAAC,EAAE,SAAS,EACtB,QAAQ,CAAC,EAAE,SAAS,EACpB,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA+IpC;AA+DD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA0B3B"}
|
|
@@ -189,15 +189,15 @@ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, supplyMin
|
|
|
189
189
|
const supplyUsd = (0, numberUtils_1.fromBaseUnit)(supplyUsage.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
|
190
190
|
const debtUsd = (0, numberUtils_1.fromBaseUnit)(debtUsage?.amountUsed?.baseAmountUsdValue ?? BigInt(0), generalAccounts_1.USD_DECIMALS);
|
|
191
191
|
return {
|
|
192
|
-
liqUtilizationRateBps: (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd,
|
|
192
|
+
liqUtilizationRateBps: (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, (0, numberUtils_1.toBps)(liqThreshold)),
|
|
193
193
|
netWorth: {
|
|
194
194
|
baseAmountUsdValue: (0, numberUtils_1.toBaseUnit)(supplyUsd - debtUsd, generalAccounts_1.USD_DECIMALS),
|
|
195
195
|
baseUnit: (0, numberUtils_1.toBaseUnit)((supplyUsd - debtUsd) / supplyPrice, supplyUsage.decimals),
|
|
196
196
|
},
|
|
197
197
|
supply: supplyUsage,
|
|
198
198
|
debt: debtUsage,
|
|
199
|
-
maxLtvBps:
|
|
200
|
-
liqThresholdBps:
|
|
199
|
+
maxLtvBps: (0, numberUtils_1.toBps)(maxLtv),
|
|
200
|
+
liqThresholdBps: (0, numberUtils_1.toBps)(liqThreshold),
|
|
201
201
|
lastUpdated: BigInt((0, generalUtils_1.currentUnixSeconds)()),
|
|
202
202
|
padding1: [],
|
|
203
203
|
padding2: [],
|
|
@@ -28,10 +28,10 @@ function fromBaseUnit(value, decimals) {
|
|
|
28
28
|
return Number(value) / Math.pow(10, decimals);
|
|
29
29
|
}
|
|
30
30
|
function fromBps(value) {
|
|
31
|
-
return value /
|
|
31
|
+
return value / constants_1.BASIS_POINTS;
|
|
32
32
|
}
|
|
33
33
|
function toBps(value) {
|
|
34
|
-
return Math.round(value *
|
|
34
|
+
return Math.round(value * constants_1.BASIS_POINTS);
|
|
35
35
|
}
|
|
36
36
|
function bytesToI80F48(bytes) {
|
|
37
37
|
if (bytes.length !== 16) {
|
|
@@ -107,5 +107,5 @@ function maxRepayFromBps(maxLtvBps, liqThresholdBps) {
|
|
|
107
107
|
return Math.min(9000, getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps - 1000, 0.005));
|
|
108
108
|
}
|
|
109
109
|
function maxRepayToBps(maxLtvBps, liqThresholdBps) {
|
|
110
|
-
return Math.min(maxRepayFromBps(maxLtvBps, liqThresholdBps) - constants_1.
|
|
110
|
+
return Math.min(maxRepayFromBps(maxLtvBps, liqThresholdBps) - constants_1.MIN_REPAY_GAP_BPS, getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps, 0.005));
|
|
111
111
|
}
|
|
@@ -15,8 +15,8 @@ export declare function getAllPositionsByAuthority(umi: Umi, user: PublicKey): P
|
|
|
15
15
|
export declare function positionStateWithLatestPrices(state: PositionState, supplyPrice?: number, debtPrice?: number): Promise<PositionState>;
|
|
16
16
|
interface AssetProps {
|
|
17
17
|
mint: PublicKey;
|
|
18
|
-
price
|
|
19
|
-
amountUsed
|
|
18
|
+
price?: number;
|
|
19
|
+
amountUsed?: number;
|
|
20
20
|
}
|
|
21
21
|
export declare function createFakePositionState(supply: AssetProps, debt: AssetProps, maxLtvBps: number, liqThresholdBps: number): PositionState;
|
|
22
22
|
type PositionAdjustment = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAA+B,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAElB,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAA+B,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAElB,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;AAezB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAgB9E,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,kBAAkB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAET;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,kBAAkB,EAC9B,oBAAoB,EA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,aAAa,CA8Df;AAED,KAAK,kBAAkB,GACnB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,gCAAgC,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAE/C,qBAAa,mBAAmB;IACvB,gBAAgB,EAAE,MAAM,CAAa;IACrC,cAAc,EAAE,MAAM,CAAa;IACnC,uBAAuB,EAAE,MAAM,CAAa;IAC5C,QAAQ,EAAE,yBAAyB,GAAG,SAAS,CAAa;IAC5D,SAAS,EAAE,WAAW,GAAG,SAAS,CAAa;IAEtD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IAyD9B,KAAK;IAQL,UAAU,IAAI,OAAO;CAQtB"}
|
|
@@ -237,20 +237,20 @@ async function positionStateWithLatestPrices(state, supplyPrice, debtPrice) {
|
|
|
237
237
|
function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
|
|
238
238
|
const supplyDecimals = constants_1.TOKEN_INFO[supply.mint.toString()].decimals;
|
|
239
239
|
const debtDecimals = constants_1.TOKEN_INFO[debt.mint.toString()].decimals;
|
|
240
|
-
const supplyUsd = supply.amountUsed * supply.price;
|
|
241
|
-
const debtUsd = debt.amountUsed * debt.price;
|
|
240
|
+
const supplyUsd = (supply.amountUsed ?? 0) * (supply.price ?? 0);
|
|
241
|
+
const debtUsd = (debt.amountUsed ?? 0) * (debt.price ?? 0);
|
|
242
242
|
return {
|
|
243
243
|
liqUtilizationRateBps: (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, liqThresholdBps),
|
|
244
244
|
supply: {
|
|
245
245
|
amountUsed: {
|
|
246
|
-
baseUnit: (0, numberUtils_1.toBaseUnit)(supply.amountUsed, supplyDecimals),
|
|
246
|
+
baseUnit: (0, numberUtils_1.toBaseUnit)(supply.amountUsed ?? 0, supplyDecimals),
|
|
247
247
|
baseAmountUsdValue: (0, numberUtils_1.toBaseUnit)(supplyUsd, constants_1.USD_DECIMALS),
|
|
248
248
|
},
|
|
249
249
|
amountCanBeUsed: {
|
|
250
250
|
baseUnit: (0, numberUtils_1.toBaseUnit)(1000000, supplyDecimals),
|
|
251
|
-
baseAmountUsdValue: BigInt(Math.round(1000000 * supply.price)),
|
|
251
|
+
baseAmountUsdValue: BigInt(Math.round(1000000 * (supply.price ?? 0))),
|
|
252
252
|
},
|
|
253
|
-
baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(supply.price, constants_1.USD_DECIMALS),
|
|
253
|
+
baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(supply.price ?? 0, constants_1.USD_DECIMALS),
|
|
254
254
|
borrowFeeBps: 0,
|
|
255
255
|
decimals: supplyDecimals,
|
|
256
256
|
flashLoanFeeBps: 0,
|
|
@@ -261,14 +261,14 @@ function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
|
|
|
261
261
|
},
|
|
262
262
|
debt: {
|
|
263
263
|
amountUsed: {
|
|
264
|
-
baseUnit: (0, numberUtils_1.toBaseUnit)(debt.amountUsed, debtDecimals),
|
|
264
|
+
baseUnit: (0, numberUtils_1.toBaseUnit)(debt.amountUsed ?? 0, debtDecimals),
|
|
265
265
|
baseAmountUsdValue: (0, numberUtils_1.toBaseUnit)(debtUsd, constants_1.USD_DECIMALS),
|
|
266
266
|
},
|
|
267
267
|
amountCanBeUsed: {
|
|
268
268
|
baseUnit: (0, numberUtils_1.toBaseUnit)(1000000, debtDecimals),
|
|
269
|
-
baseAmountUsdValue: BigInt(Math.round(1000000 * debt.price)),
|
|
269
|
+
baseAmountUsdValue: BigInt(Math.round(1000000 * (debt.price ?? 0))),
|
|
270
270
|
},
|
|
271
|
-
baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(debt.price, constants_1.USD_DECIMALS),
|
|
271
|
+
baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(debt.price ?? 0, constants_1.USD_DECIMALS),
|
|
272
272
|
borrowFeeBps: 0,
|
|
273
273
|
decimals: debtDecimals,
|
|
274
274
|
flashLoanFeeBps: 0,
|
|
@@ -278,7 +278,9 @@ function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
|
|
|
278
278
|
padding: new Uint8Array([]),
|
|
279
279
|
},
|
|
280
280
|
netWorth: {
|
|
281
|
-
baseUnit:
|
|
281
|
+
baseUnit: supply.price
|
|
282
|
+
? (0, numberUtils_1.toBaseUnit)((supplyUsd - debtUsd) / supply.price, supplyDecimals)
|
|
283
|
+
: BigInt(0),
|
|
282
284
|
baseAmountUsdValue: (0, numberUtils_1.toBaseUnit)(supplyUsd - debtUsd, constants_1.USD_DECIMALS),
|
|
283
285
|
},
|
|
284
286
|
maxLtvBps,
|
package/package.json
CHANGED
|
@@ -55,9 +55,11 @@ import {
|
|
|
55
55
|
findMarginfiAccounts,
|
|
56
56
|
getAllMarginfiAccountsByAuthority,
|
|
57
57
|
getMarginfiAccountPositionState,
|
|
58
|
+
getMaxLtvAndLiqThreshold,
|
|
58
59
|
} from "../utils/marginfiUtils";
|
|
59
|
-
import { bytesToI80F48 } from "../utils/numberUtils";
|
|
60
|
+
import { bytesToI80F48, toBps } from "../utils/numberUtils";
|
|
60
61
|
import { SOLAUTO_MANAGER } from "../constants";
|
|
62
|
+
import { createFakePositionState } from "../utils";
|
|
61
63
|
|
|
62
64
|
export interface SolautoMarginfiClientArgs extends SolautoClientArgs {
|
|
63
65
|
marginfiAccount?: PublicKey | Signer;
|
|
@@ -127,9 +129,25 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
127
129
|
// this.supplyPriceOracle = toWeb3JsPublicKey(supplyBank.config.oracleKeys[0]);
|
|
128
130
|
// this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
|
|
129
131
|
|
|
130
|
-
this.supplyPriceOracle = new PublicKey(
|
|
132
|
+
this.supplyPriceOracle = new PublicKey(
|
|
133
|
+
this.marginfiSupplyAccounts.priceOracle
|
|
134
|
+
);
|
|
131
135
|
this.debtPriceOracle = new PublicKey(this.marginfiDebtAccounts.priceOracle);
|
|
132
136
|
|
|
137
|
+
if (!this.solautoPositionState) {
|
|
138
|
+
const [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(
|
|
139
|
+
this.umi,
|
|
140
|
+
{ mint: this.supplyMint },
|
|
141
|
+
{ mint: this.debtMint }
|
|
142
|
+
);
|
|
143
|
+
this.solautoPositionState = createFakePositionState(
|
|
144
|
+
{ mint: this.supplyMint },
|
|
145
|
+
{ mint: this.debtMint },
|
|
146
|
+
toBps(maxLtv),
|
|
147
|
+
toBps(liqThreshold)
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
133
151
|
if (!this.initialized) {
|
|
134
152
|
await this.setIntermediaryMarginfiDetails();
|
|
135
153
|
}
|
|
@@ -510,33 +528,37 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
510
528
|
let includedFlashLoanToken = false;
|
|
511
529
|
|
|
512
530
|
if (this.intermediaryMarginfiAccount) {
|
|
513
|
-
this.intermediaryMarginfiAccount.lendingAccount.balances.forEach(
|
|
514
|
-
|
|
515
|
-
if (x.
|
|
516
|
-
|
|
531
|
+
this.intermediaryMarginfiAccount.lendingAccount.balances.forEach(
|
|
532
|
+
async (x) => {
|
|
533
|
+
if (x.active) {
|
|
534
|
+
if (x.bankPk === accounts.data.bank) {
|
|
535
|
+
includedFlashLoanToken = true;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
|
539
|
+
// const bankData = await safeFetchBank(this.umi, publicKey(accounts.data.bank));
|
|
540
|
+
// const priceOracle = bankData!.config.oracleKeys[0];
|
|
541
|
+
const priceOracle = publicKey(
|
|
542
|
+
findMarginfiAccounts(toWeb3JsPublicKey(x.bankPk)).priceOracle
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
remainingAccounts.push(
|
|
546
|
+
...[
|
|
547
|
+
{
|
|
548
|
+
pubkey: x.bankPk,
|
|
549
|
+
isSigner: false,
|
|
550
|
+
isWritable: false,
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
pubkey: priceOracle,
|
|
554
|
+
isSigner: false,
|
|
555
|
+
isWritable: false,
|
|
556
|
+
},
|
|
557
|
+
]
|
|
558
|
+
);
|
|
517
559
|
}
|
|
518
|
-
|
|
519
|
-
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
|
520
|
-
// const bankData = await safeFetchBank(this.umi, publicKey(accounts.data.bank));
|
|
521
|
-
// const priceOracle = bankData!.config.oracleKeys[0];
|
|
522
|
-
const priceOracle = publicKey(findMarginfiAccounts(toWeb3JsPublicKey(x.bankPk)).priceOracle);
|
|
523
|
-
|
|
524
|
-
remainingAccounts.push(
|
|
525
|
-
...[
|
|
526
|
-
{
|
|
527
|
-
pubkey: x.bankPk,
|
|
528
|
-
isSigner: false,
|
|
529
|
-
isWritable: false,
|
|
530
|
-
},
|
|
531
|
-
{
|
|
532
|
-
pubkey: priceOracle,
|
|
533
|
-
isSigner: false,
|
|
534
|
-
isWritable: false,
|
|
535
|
-
},
|
|
536
|
-
]
|
|
537
|
-
);
|
|
538
560
|
}
|
|
539
|
-
|
|
561
|
+
);
|
|
540
562
|
}
|
|
541
563
|
if (!this.intermediaryMarginfiAccount || !includedFlashLoanToken) {
|
|
542
564
|
remainingAccounts.push(
|
|
@@ -13,10 +13,12 @@ import {
|
|
|
13
13
|
import { SOLAUTO_PROGRAM_ID } from "../generated";
|
|
14
14
|
import { SOLAUTO_MANAGER } from "./generalAccounts";
|
|
15
15
|
|
|
16
|
-
export const
|
|
16
|
+
export const BASIS_POINTS = 10000;
|
|
17
|
+
|
|
17
18
|
export const DEFAULT_LIMIT_GAP_BPS = 1000;
|
|
18
19
|
export const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
|
19
|
-
export const
|
|
20
|
+
export const MIN_REPAY_GAP_BPS = 100;
|
|
21
|
+
export const MIN_BOOST_GAP_BPS = 50;
|
|
20
22
|
|
|
21
23
|
// export const JITO_BLOCK_ENGINE = "ny.mainnet.block-engine.jito.wtf";
|
|
22
24
|
// export const JITO_CONNECTION = new JitoRpcConnection(
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
fromBaseUnit,
|
|
15
15
|
getLiqUtilzationRateBps,
|
|
16
16
|
toBaseUnit,
|
|
17
|
+
toBps,
|
|
17
18
|
} from "./numberUtils";
|
|
18
19
|
import { PRICES } from "../constants/solautoConstants";
|
|
19
20
|
import { MARGINFI_ACCOUNTS } from "../constants/marginfiAccounts";
|
|
@@ -353,7 +354,7 @@ export async function getMarginfiAccountPositionState(
|
|
|
353
354
|
liqUtilizationRateBps: getLiqUtilzationRateBps(
|
|
354
355
|
supplyUsd,
|
|
355
356
|
debtUsd,
|
|
356
|
-
|
|
357
|
+
toBps(liqThreshold)
|
|
357
358
|
),
|
|
358
359
|
netWorth: {
|
|
359
360
|
baseAmountUsdValue: toBaseUnit(supplyUsd - debtUsd, USD_DECIMALS),
|
|
@@ -364,8 +365,8 @@ export async function getMarginfiAccountPositionState(
|
|
|
364
365
|
},
|
|
365
366
|
supply: supplyUsage!,
|
|
366
367
|
debt: debtUsage!,
|
|
367
|
-
maxLtvBps:
|
|
368
|
-
liqThresholdBps:
|
|
368
|
+
maxLtvBps: toBps(maxLtv),
|
|
369
|
+
liqThresholdBps: toBps(liqThreshold),
|
|
369
370
|
lastUpdated: BigInt(currentUnixSeconds()),
|
|
370
371
|
padding1: [],
|
|
371
372
|
padding2: [],
|
package/src/utils/numberUtils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BASIS_POINTS, MIN_REPAY_GAP_BPS } from "../constants";
|
|
2
2
|
import { FeeType } from "../generated";
|
|
3
3
|
|
|
4
4
|
export function getLiqUtilzationRateBps(
|
|
@@ -22,11 +22,11 @@ export function fromBaseUnit(value: bigint, decimals: number): number {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export function fromBps(value: number): number {
|
|
25
|
-
return value /
|
|
25
|
+
return value / BASIS_POINTS;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function toBps(value: number): number {
|
|
29
|
-
return Math.round(value *
|
|
29
|
+
return Math.round(value * BASIS_POINTS);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export function bytesToI80F48(bytes: number[]): number {
|
|
@@ -148,7 +148,7 @@ export function maxRepayFromBps(maxLtvBps: number, liqThresholdBps: number) {
|
|
|
148
148
|
|
|
149
149
|
export function maxRepayToBps(maxLtvBps: number, liqThresholdBps: number) {
|
|
150
150
|
return Math.min(
|
|
151
|
-
maxRepayFromBps(maxLtvBps, liqThresholdBps) -
|
|
151
|
+
maxRepayFromBps(maxLtvBps, liqThresholdBps) - MIN_REPAY_GAP_BPS,
|
|
152
152
|
getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps, 0.005)
|
|
153
153
|
);
|
|
154
154
|
}
|
|
@@ -26,9 +26,7 @@ import {
|
|
|
26
26
|
TOKEN_INFO,
|
|
27
27
|
USD_DECIMALS,
|
|
28
28
|
} from "../../constants";
|
|
29
|
-
import {
|
|
30
|
-
getAllMarginfiAccountsByAuthority,
|
|
31
|
-
} from "../marginfiUtils";
|
|
29
|
+
import { getAllMarginfiAccountsByAuthority } from "../marginfiUtils";
|
|
32
30
|
import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
|
|
33
31
|
|
|
34
32
|
function newPeriodsPassed(
|
|
@@ -358,8 +356,8 @@ export async function positionStateWithLatestPrices(
|
|
|
358
356
|
|
|
359
357
|
interface AssetProps {
|
|
360
358
|
mint: PublicKey;
|
|
361
|
-
price
|
|
362
|
-
amountUsed
|
|
359
|
+
price?: number;
|
|
360
|
+
amountUsed?: number;
|
|
363
361
|
}
|
|
364
362
|
|
|
365
363
|
export function createFakePositionState(
|
|
@@ -371,8 +369,8 @@ export function createFakePositionState(
|
|
|
371
369
|
const supplyDecimals = TOKEN_INFO[supply.mint.toString()].decimals;
|
|
372
370
|
const debtDecimals = TOKEN_INFO[debt.mint.toString()].decimals;
|
|
373
371
|
|
|
374
|
-
const supplyUsd = supply.amountUsed * supply.price;
|
|
375
|
-
const debtUsd = debt.amountUsed * debt.price;
|
|
372
|
+
const supplyUsd = (supply.amountUsed ?? 0) * (supply.price ?? 0);
|
|
373
|
+
const debtUsd = (debt.amountUsed ?? 0) * (debt.price ?? 0);
|
|
376
374
|
|
|
377
375
|
return {
|
|
378
376
|
liqUtilizationRateBps: getLiqUtilzationRateBps(
|
|
@@ -382,14 +380,14 @@ export function createFakePositionState(
|
|
|
382
380
|
),
|
|
383
381
|
supply: {
|
|
384
382
|
amountUsed: {
|
|
385
|
-
baseUnit: toBaseUnit(supply.amountUsed, supplyDecimals),
|
|
383
|
+
baseUnit: toBaseUnit(supply.amountUsed ?? 0, supplyDecimals),
|
|
386
384
|
baseAmountUsdValue: toBaseUnit(supplyUsd, USD_DECIMALS),
|
|
387
385
|
},
|
|
388
386
|
amountCanBeUsed: {
|
|
389
387
|
baseUnit: toBaseUnit(1000000, supplyDecimals),
|
|
390
|
-
baseAmountUsdValue: BigInt(Math.round(1000000 * supply.price)),
|
|
388
|
+
baseAmountUsdValue: BigInt(Math.round(1000000 * (supply.price ?? 0))),
|
|
391
389
|
},
|
|
392
|
-
baseAmountMarketPriceUsd: toBaseUnit(supply.price, USD_DECIMALS),
|
|
390
|
+
baseAmountMarketPriceUsd: toBaseUnit(supply.price ?? 0, USD_DECIMALS),
|
|
393
391
|
borrowFeeBps: 0,
|
|
394
392
|
decimals: supplyDecimals,
|
|
395
393
|
flashLoanFeeBps: 0,
|
|
@@ -400,14 +398,14 @@ export function createFakePositionState(
|
|
|
400
398
|
},
|
|
401
399
|
debt: {
|
|
402
400
|
amountUsed: {
|
|
403
|
-
baseUnit: toBaseUnit(debt.amountUsed, debtDecimals),
|
|
401
|
+
baseUnit: toBaseUnit(debt.amountUsed ?? 0, debtDecimals),
|
|
404
402
|
baseAmountUsdValue: toBaseUnit(debtUsd, USD_DECIMALS),
|
|
405
403
|
},
|
|
406
404
|
amountCanBeUsed: {
|
|
407
405
|
baseUnit: toBaseUnit(1000000, debtDecimals),
|
|
408
|
-
baseAmountUsdValue: BigInt(Math.round(1000000 * debt.price)),
|
|
406
|
+
baseAmountUsdValue: BigInt(Math.round(1000000 * (debt.price ?? 0))),
|
|
409
407
|
},
|
|
410
|
-
baseAmountMarketPriceUsd: toBaseUnit(debt.price, USD_DECIMALS),
|
|
408
|
+
baseAmountMarketPriceUsd: toBaseUnit(debt.price ?? 0, USD_DECIMALS),
|
|
411
409
|
borrowFeeBps: 0,
|
|
412
410
|
decimals: debtDecimals,
|
|
413
411
|
flashLoanFeeBps: 0,
|
|
@@ -417,10 +415,9 @@ export function createFakePositionState(
|
|
|
417
415
|
padding: new Uint8Array([]),
|
|
418
416
|
},
|
|
419
417
|
netWorth: {
|
|
420
|
-
baseUnit:
|
|
421
|
-
(supplyUsd - debtUsd) / supply.price,
|
|
422
|
-
|
|
423
|
-
),
|
|
418
|
+
baseUnit: supply.price
|
|
419
|
+
? toBaseUnit((supplyUsd - debtUsd) / supply.price, supplyDecimals)
|
|
420
|
+
: BigInt(0),
|
|
424
421
|
baseAmountUsdValue: toBaseUnit(supplyUsd - debtUsd, USD_DECIMALS),
|
|
425
422
|
},
|
|
426
423
|
maxLtvBps,
|