@haven-fi/solauto-sdk 1.0.64 → 1.0.66
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/transactions/transactionUtils.js +1 -1
- package/dist/utils/marginfiUtils.d.ts +2 -2
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +3 -3
- package/dist/utils/numberUtils.d.ts +3 -3
- package/dist/utils/numberUtils.d.ts.map +1 -1
- package/dist/utils/numberUtils.js +8 -8
- package/dist/utils/solauto/rebalanceUtils.js +1 -1
- package/package.json +1 -1
- package/src/transactions/transactionUtils.ts +2 -2
- package/src/utils/marginfiUtils.ts +5 -5
- package/src/utils/numberUtils.ts +6 -6
- package/src/utils/solauto/rebalanceUtils.ts +2 -2
- package/tests/transactions/solautoMarginfi.ts +2 -2
@@ -366,7 +366,7 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
366
366
|
]);
|
367
367
|
}
|
368
368
|
if (client.solautoPositionState.liqUtilizationRateBps >
|
369
|
-
(0, numberUtils_1.
|
369
|
+
(0, numberUtils_1.getMaxLiqUtilizationRateBps)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps)) {
|
370
370
|
tx = tx.prepend(client.refresh());
|
371
371
|
}
|
372
372
|
return {
|
@@ -10,10 +10,10 @@ export declare function findMarginfiAccounts({ mint, bank, }: {
|
|
10
10
|
}): MarginfiAssetAccounts;
|
11
11
|
export declare function getMaxLtvAndLiqThreshold(umi: Umi, supply: {
|
12
12
|
mint: PublicKey;
|
13
|
-
bank
|
13
|
+
bank?: Bank | null;
|
14
14
|
}, debt: {
|
15
15
|
mint: PublicKey;
|
16
|
-
bank
|
16
|
+
bank?: Bank | null;
|
17
17
|
}, supplyPrice?: number): Promise<[number, number]>;
|
18
18
|
export declare function getAllMarginfiAccountsByAuthority(umi: Umi, authority: PublicKey, compatibleWithSolauto?: boolean): Promise<{
|
19
19
|
marginfiAccount: PublicKey;
|
@@ -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;AAUzB,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,EACnC,IAAI,EACJ,IAAI,GACL,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,qBAAqB,CAWxB;AAED,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE;IACN,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,IAAI,GAAG,IAAI,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;AAUzB,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,EACnC,IAAI,EACJ,IAAI,GACL,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,qBAAqB,CAWxB;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,CA8D3B;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"}
|
@@ -28,12 +28,12 @@ function findMarginfiAccounts({ mint, bank, }) {
|
|
28
28
|
throw new Error(`Marginfi accounts not found by the mint: ${mint}`);
|
29
29
|
}
|
30
30
|
async function getMaxLtvAndLiqThreshold(umi, supply, debt, supplyPrice) {
|
31
|
-
if (!supply.bank) {
|
31
|
+
if (!supply.bank || supply.bank === null) {
|
32
32
|
supply.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(findMarginfiAccounts({
|
33
33
|
mint: supply.mint.toString(),
|
34
34
|
}).bank));
|
35
35
|
}
|
36
|
-
if (!debt.bank && !debt.mint.equals(web3_js_1.PublicKey.default)) {
|
36
|
+
if ((!debt.bank || debt.bank === null) && !debt.mint.equals(web3_js_1.PublicKey.default)) {
|
37
37
|
debt.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(findMarginfiAccounts({
|
38
38
|
mint: debt.mint.toString(),
|
39
39
|
}).bank));
|
@@ -44,7 +44,7 @@ async function getMaxLtvAndLiqThreshold(umi, supply, debt, supplyPrice) {
|
|
44
44
|
]);
|
45
45
|
supplyPrice = price;
|
46
46
|
}
|
47
|
-
if (debt.bank === null) {
|
47
|
+
if (!debt.bank || debt.bank === null) {
|
48
48
|
return [0, 0];
|
49
49
|
}
|
50
50
|
let maxLtv = (0, numberUtils_1.bytesToI80F48)(supply.bank.config.assetWeightInit.value) /
|
@@ -6,7 +6,7 @@ export declare function toBps(value: number): number;
|
|
6
6
|
export declare function bytesToI80F48(bytes: number[]): number;
|
7
7
|
export declare function uint8ArrayToBigInt(uint8Array: Uint8Array): bigint;
|
8
8
|
export declare function getDebtAdjustmentUsd(liqThresholdBps: number, supplyUsd: number, debtUsd: number, targetLiqUtilizationRateBps: number, adjustmentFeeBps?: number): number;
|
9
|
-
export declare function
|
10
|
-
export declare function
|
11
|
-
export declare function
|
9
|
+
export declare function getMaxLiqUtilizationRateBps(maxLtvBps: number, liqThresholdBps: number): number;
|
10
|
+
export declare function maxRepayFromBps(maxLtvBps: number, liqThresholdBps: number): number;
|
11
|
+
export declare function maxRepayToBps(maxLtvBps: number, liqThresholdBps: number): number;
|
12
12
|
//# sourceMappingURL=numberUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"numberUtils.d.ts","sourceRoot":"","sources":["../../src/utils/numberUtils.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MA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AAG,MAAM,CAqBrD;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAajE;AAED,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,2BAA2B,EAAE,MAAM,EACnC,gBAAgB,CAAC,EAAE,MAAM,UAQ1B;AAED,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,GACtB,MAAM,CAER;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKzE;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKvE"}
|
@@ -8,9 +8,9 @@ exports.toBps = toBps;
|
|
8
8
|
exports.bytesToI80F48 = bytesToI80F48;
|
9
9
|
exports.uint8ArrayToBigInt = uint8ArrayToBigInt;
|
10
10
|
exports.getDebtAdjustmentUsd = getDebtAdjustmentUsd;
|
11
|
-
exports.
|
12
|
-
exports.
|
13
|
-
exports.
|
11
|
+
exports.getMaxLiqUtilizationRateBps = getMaxLiqUtilizationRateBps;
|
12
|
+
exports.maxRepayFromBps = maxRepayFromBps;
|
13
|
+
exports.maxRepayToBps = maxRepayToBps;
|
14
14
|
const constants_1 = require("../constants");
|
15
15
|
function getLiqUtilzationRateBps(supplyUsd, debtUsd, liqThresholdBps) {
|
16
16
|
if (supplyUsd === 0) {
|
@@ -63,12 +63,12 @@ function getDebtAdjustmentUsd(liqThresholdBps, supplyUsd, debtUsd, targetLiqUtil
|
|
63
63
|
const debtAdjustmentUsd = (targetLiqUtilizationRate * supplyUsd * liqThreshold - debtUsd) / (1 - targetLiqUtilizationRate * (1 - adjustmentFee) * liqThreshold);
|
64
64
|
return debtAdjustmentUsd;
|
65
65
|
}
|
66
|
-
function
|
66
|
+
function getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps) {
|
67
67
|
return toBps((fromBps(maxLtvBps) - 0.015) / fromBps(liqThresholdBps)) - 1; // -1 to account for any rounding issues
|
68
68
|
}
|
69
|
-
function
|
70
|
-
return Math.min(9000,
|
69
|
+
function maxRepayFromBps(maxLtvBps, liqThresholdBps) {
|
70
|
+
return Math.min(9000, getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps - 1000));
|
71
71
|
}
|
72
|
-
function
|
73
|
-
return Math.min(
|
72
|
+
function maxRepayToBps(maxLtvBps, liqThresholdBps) {
|
73
|
+
return Math.min(maxRepayFromBps(maxLtvBps, liqThresholdBps) - constants_1.MAX_REPAY_GAP_BPS, getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps));
|
74
74
|
}
|
@@ -134,7 +134,7 @@ function getFlashLoanDetails(client, values, jupQuote) {
|
|
134
134
|
const tempLiqUtilizationRateBps = (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, client.solautoPositionState.liqThresholdBps);
|
135
135
|
const requiresFlashLoan = supplyUsd <= 0 ||
|
136
136
|
tempLiqUtilizationRateBps >
|
137
|
-
(0, numberUtils_1.
|
137
|
+
(0, numberUtils_1.getMaxLiqUtilizationRateBps)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps);
|
138
138
|
let flashLoanToken = undefined;
|
139
139
|
let flashLoanTokenPrice = 0;
|
140
140
|
if (values.increasingLeverage) {
|
package/package.json
CHANGED
@@ -45,7 +45,7 @@ import {
|
|
45
45
|
} from "../utils/generalUtils";
|
46
46
|
import { SolautoMarginfiClient } from "../clients/solautoMarginfiClient";
|
47
47
|
import {
|
48
|
-
|
48
|
+
getMaxLiqUtilizationRateBps,
|
49
49
|
uint8ArrayToBigInt,
|
50
50
|
} from "../utils/numberUtils";
|
51
51
|
import { eligibleForRebalance } from "../utils/solauto/generalUtils";
|
@@ -670,7 +670,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
670
670
|
|
671
671
|
if (
|
672
672
|
client.solautoPositionState!.liqUtilizationRateBps >
|
673
|
-
|
673
|
+
getMaxLiqUtilizationRateBps(
|
674
674
|
client.solautoPositionState!.maxLtvBps,
|
675
675
|
client.solautoPositionState!.liqThresholdBps
|
676
676
|
)
|
@@ -46,15 +46,15 @@ export async function getMaxLtvAndLiqThreshold(
|
|
46
46
|
umi: Umi,
|
47
47
|
supply: {
|
48
48
|
mint: PublicKey;
|
49
|
-
bank
|
49
|
+
bank?: Bank | null;
|
50
50
|
},
|
51
51
|
debt: {
|
52
52
|
mint: PublicKey;
|
53
|
-
bank
|
53
|
+
bank?: Bank | null;
|
54
54
|
},
|
55
55
|
supplyPrice?: number
|
56
56
|
): Promise<[number, number]> {
|
57
|
-
if (!supply.bank) {
|
57
|
+
if (!supply.bank || supply.bank === null) {
|
58
58
|
supply.bank = await safeFetchBank(
|
59
59
|
umi,
|
60
60
|
publicKey(
|
@@ -65,7 +65,7 @@ export async function getMaxLtvAndLiqThreshold(
|
|
65
65
|
);
|
66
66
|
}
|
67
67
|
|
68
|
-
if (!debt.bank && !debt.mint.equals(PublicKey.default)) {
|
68
|
+
if ((!debt.bank || debt.bank === null) && !debt.mint.equals(PublicKey.default)) {
|
69
69
|
debt.bank = await safeFetchBank(
|
70
70
|
umi,
|
71
71
|
publicKey(
|
@@ -83,7 +83,7 @@ export async function getMaxLtvAndLiqThreshold(
|
|
83
83
|
supplyPrice = price;
|
84
84
|
}
|
85
85
|
|
86
|
-
if (debt.bank === null) {
|
86
|
+
if (!debt.bank || debt.bank === null) {
|
87
87
|
return [0, 0];
|
88
88
|
}
|
89
89
|
|
package/src/utils/numberUtils.ts
CHANGED
@@ -77,23 +77,23 @@ export function getDebtAdjustmentUsd(
|
|
77
77
|
return debtAdjustmentUsd;
|
78
78
|
}
|
79
79
|
|
80
|
-
export function
|
80
|
+
export function getMaxLiqUtilizationRateBps(
|
81
81
|
maxLtvBps: number,
|
82
82
|
liqThresholdBps: number
|
83
83
|
): number {
|
84
84
|
return toBps((fromBps(maxLtvBps) - 0.015) / fromBps(liqThresholdBps)) - 1; // -1 to account for any rounding issues
|
85
85
|
}
|
86
86
|
|
87
|
-
export function
|
87
|
+
export function maxRepayFromBps(maxLtvBps: number, liqThresholdBps: number) {
|
88
88
|
return Math.min(
|
89
89
|
9000,
|
90
|
-
|
90
|
+
getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps - 1000)
|
91
91
|
);
|
92
92
|
}
|
93
93
|
|
94
|
-
export function
|
94
|
+
export function maxRepayToBps(maxLtvBps: number, liqThresholdBps: number) {
|
95
95
|
return Math.min(
|
96
|
-
|
97
|
-
|
96
|
+
maxRepayFromBps(maxLtvBps, liqThresholdBps) - MAX_REPAY_GAP_BPS,
|
97
|
+
getMaxLiqUtilizationRateBps(maxLtvBps, liqThresholdBps)
|
98
98
|
);
|
99
99
|
}
|
@@ -22,7 +22,7 @@ import {
|
|
22
22
|
fromBps,
|
23
23
|
getDebtAdjustmentUsd,
|
24
24
|
getLiqUtilzationRateBps,
|
25
|
-
|
25
|
+
getMaxLiqUtilizationRateBps,
|
26
26
|
toBaseUnit,
|
27
27
|
} from "../numberUtils";
|
28
28
|
import { USD_DECIMALS } from "../../constants/generalAccounts";
|
@@ -289,7 +289,7 @@ export function getFlashLoanDetails(
|
|
289
289
|
const requiresFlashLoan =
|
290
290
|
supplyUsd <= 0 ||
|
291
291
|
tempLiqUtilizationRateBps >
|
292
|
-
|
292
|
+
getMaxLiqUtilizationRateBps(
|
293
293
|
client.solautoPositionState!.maxLtvBps,
|
294
294
|
client.solautoPositionState!.liqThresholdBps
|
295
295
|
);
|
@@ -10,7 +10,7 @@ import {
|
|
10
10
|
SolautoSettingsParametersInpArgs,
|
11
11
|
} from "../../src/generated";
|
12
12
|
import { buildSolautoRebalanceTransaction } from "../../src/transactions/transactionUtils";
|
13
|
-
import {
|
13
|
+
import { getMaxLiqUtilizationRateBps, toBaseUnit } from "../../src/utils/numberUtils";
|
14
14
|
import { NATIVE_MINT } from "@solana/spl-token";
|
15
15
|
import { getTokenPrices } from "../../src/utils/generalUtils";
|
16
16
|
import {
|
@@ -82,7 +82,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
82
82
|
// );
|
83
83
|
// }
|
84
84
|
|
85
|
-
// const maxLiqRate =
|
85
|
+
// const maxLiqRate = getMaxLiqUtilizationRateBps(client.solautoPositionState!.maxLtvBps, client.solautoPositionState!.liqThresholdBps);
|
86
86
|
// transactionItems.push(
|
87
87
|
// new TransactionItem(
|
88
88
|
// async () => ({
|