@haven-fi/solauto-sdk 1.0.65 → 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/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/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 {
|
@@ -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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AAM,CAE3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,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
|
)
|
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 () => ({
|