@haven-fi/solauto-sdk 1.0.233 → 1.0.234
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/constants/solautoConstants.d.ts +1 -0
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +2 -1
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +11 -3
- package/dist/utils/solanaUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.d.ts +1 -0
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +1 -0
- package/package.json +1 -1
- package/src/constants/solautoConstants.ts +1 -0
- package/src/transactions/transactionUtils.ts +32 -11
- package/src/utils/solanaUtils.ts +1 -2
- package/src/utils/solauto/rebalanceUtils.ts +4 -1
- package/tests/transactions/solautoMarginfi.ts +0 -7
@@ -5,6 +5,7 @@ export declare const BASIS_POINTS = 10000;
|
|
5
5
|
export declare const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
6
6
|
export declare const MIN_REPAY_GAP_BPS = 50;
|
7
7
|
export declare const MIN_BOOST_GAP_BPS = 50;
|
8
|
+
export declare const MIN_USD_SUPPORTED_POSITION = 500;
|
8
9
|
export declare const PRICES: {
|
9
10
|
[key: string]: {
|
10
11
|
price: number;
|
@@ -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;AASzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;
|
1
|
+
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AASzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAE9C,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO,CAAC;AAE7E,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAC1E,eAAO,MAAM,qBAAqB,UAYR,CAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.STANDARD_LUT_ACCOUNTS = exports.SOLAUTO_LUT = exports.PRICES = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.BASIS_POINTS = exports.SOLAUTO_TEST_PROGRAM = exports.SOLAUTO_PROD_PROGRAM = void 0;
|
3
|
+
exports.STANDARD_LUT_ACCOUNTS = exports.SOLAUTO_LUT = exports.PRICES = exports.MIN_USD_SUPPORTED_POSITION = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.BASIS_POINTS = exports.SOLAUTO_TEST_PROGRAM = exports.SOLAUTO_PROD_PROGRAM = 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";
|
@@ -13,6 +13,7 @@ exports.BASIS_POINTS = 10000;
|
|
13
13
|
exports.MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
14
14
|
exports.MIN_REPAY_GAP_BPS = 50;
|
15
15
|
exports.MIN_BOOST_GAP_BPS = 50;
|
16
|
+
exports.MIN_USD_SUPPORTED_POSITION = 500;
|
16
17
|
exports.PRICES = {};
|
17
18
|
exports.SOLAUTO_LUT = "9D4xwZwDf46n9ft5gQxZzq3rBbdRXsXojKQLZbBdskPY";
|
18
19
|
exports.STANDARD_LUT_ACCOUNTS = [
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAmBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAmBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAsCzD,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAO7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAqLjD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAkH7B;AA2LD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,8BAA8B,CAAC,MAAM,EAAE,aAAa,oBA2CzE;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAiI5C;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsC5C;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG;;;;EAuDxE"}
|
@@ -186,7 +186,8 @@ function transactionChoresAfter(client, solautoActions, cancellingDcaIn) {
|
|
186
186
|
}
|
187
187
|
function getRebalanceInstructions(umi, tx) {
|
188
188
|
return tx.getInstructions().filter((x) => {
|
189
|
-
if (x.programId.toString() ===
|
189
|
+
if (x.programId.toString() ===
|
190
|
+
umi.programs.get("solauto").publicKey.toString()) {
|
190
191
|
try {
|
191
192
|
const serializer = (0, generated_1.getMarginfiRebalanceInstructionDataSerializer)();
|
192
193
|
const discriminator = serializer.serialize({
|
@@ -207,7 +208,8 @@ function getRebalanceInstructions(umi, tx) {
|
|
207
208
|
function getSolautoActions(umi, tx) {
|
208
209
|
let solautoActions = [];
|
209
210
|
tx.getInstructions().forEach((x) => {
|
210
|
-
if (x.programId.toString() ===
|
211
|
+
if (x.programId.toString() ===
|
212
|
+
umi.programs.get("solauto").publicKey.toString()) {
|
211
213
|
try {
|
212
214
|
const serializer = (0, generated_1.getMarginfiProtocolInteractionInstructionDataSerializer)();
|
213
215
|
const discriminator = serializer.serialize({
|
@@ -362,6 +364,11 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
362
364
|
}
|
363
365
|
const values = (0, rebalanceUtils_1.getRebalanceValues)(client.solautoPositionState, client.solautoPositionSettings(), client.solautoPositionActiveDca(), (0, generalUtils_1.currentUnixSeconds)(), (0, generalUtils_1.safeGetPrice)(client.supplyMint), (0, generalUtils_1.safeGetPrice)(client.debtMint), targetLiqUtilizationRateBps);
|
364
366
|
client.log("Rebalance values: ", values);
|
367
|
+
if (targetLiqUtilizationRateBps === undefined &&
|
368
|
+
(0, numberUtils_1.fromBaseUnit)(client.solautoPositionState?.netWorth.baseAmountUsdValue ?? BigInt(0), constants_1.USD_DECIMALS) < constants_1.MIN_USD_SUPPORTED_POSITION &&
|
369
|
+
values.feesUsd < 0.5) {
|
370
|
+
return undefined;
|
371
|
+
}
|
365
372
|
const swapDetails = (0, rebalanceUtils_1.getJupSwapRebalanceDetails)(client, values, targetLiqUtilizationRateBps, attemptNum);
|
366
373
|
const { jupQuote, lookupTableAddresses, setupInstructions, tokenLedgerIx, swapIx, } = await (0, jupiterUtils_1.getJupSwapTransaction)(client.signer, swapDetails, attemptNum);
|
367
374
|
const flashLoan = (0, rebalanceUtils_1.getFlashLoanDetails)(client, values, jupQuote);
|
@@ -441,7 +448,8 @@ function getErrorInfo(umi, tx, error) {
|
|
441
448
|
const errCode = typeof err[1] === "object" ? err[1]["Custom"] : undefined;
|
442
449
|
const errName = errCode === undefined ? err[1] : undefined;
|
443
450
|
let programName = "";
|
444
|
-
if (errIx.programId.toString() ===
|
451
|
+
if (errIx.programId.toString() ===
|
452
|
+
umi.programs.get("solauto").publicKey.toString()) {
|
445
453
|
programError = (0, generated_1.getSolautoErrorFromCode)(errCode, (0, generated_1.createSolautoProgram)());
|
446
454
|
programName = "Haven";
|
447
455
|
if (programError?.name ===
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBA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AG,EACR,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,kBAAkB,EACtB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,cAAc,GAAE,MAAc,EAC9B,eAAe,GAAE,kBAA+C,EAChE,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAyEjC"}
|
@@ -12,6 +12,7 @@ export interface RebalanceValues {
|
|
12
12
|
dcaTokenType?: TokenType;
|
13
13
|
rebalanceAction: RebalanceAction;
|
14
14
|
rebalanceDirection: RebalanceDirection;
|
15
|
+
feesUsd: number;
|
15
16
|
}
|
16
17
|
export declare function getRebalanceValues(state: PositionState, settings: SolautoSettingsParameters | undefined, dca: DCASettings | undefined, currentUnixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number): RebalanceValues;
|
17
18
|
export interface FlashLoanDetails {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,kBAAkB,EAClB,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,kBAAkB,EAClB,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAajD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAkI9C,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAyB,GAAG,SAAS,EAC/C,GAAG,EAAE,WAAW,GAAG,SAAS,EAC5B,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM,GACnC,eAAe,CAiDjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,GACtB,gBAAgB,GAAG,SAAS,CA0D9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAyChB"}
|
@@ -98,6 +98,7 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
|
|
98
98
|
dcaTokenType: dca?.tokenType,
|
99
99
|
rebalanceAction: (amountToDcaIn ?? 0) > 0 ? "dca" : rebalanceDirection === generated_1.RebalanceDirection.Boost ? "boost" : "repay",
|
100
100
|
rebalanceDirection,
|
101
|
+
feesUsd: debtAdjustmentUsd * (0, numberUtils_1.fromBps)(adjustmentFeeBps)
|
101
102
|
};
|
102
103
|
}
|
103
104
|
function getFlashLoanDetails(client, values, jupQuote) {
|
package/package.json
CHANGED
@@ -27,6 +27,7 @@ export const BASIS_POINTS = 10000;
|
|
27
27
|
export const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
|
28
28
|
export const MIN_REPAY_GAP_BPS = 50;
|
29
29
|
export const MIN_BOOST_GAP_BPS = 50;
|
30
|
+
export const MIN_USD_SUPPORTED_POSITION = 500;
|
30
31
|
|
31
32
|
export const PRICES: { [key: string]: { price: number; time: number } } = {};
|
32
33
|
|
@@ -46,6 +46,7 @@ import {
|
|
46
46
|
} from "../utils/generalUtils";
|
47
47
|
import { SolautoMarginfiClient } from "../clients/solautoMarginfiClient";
|
48
48
|
import {
|
49
|
+
fromBaseUnit,
|
49
50
|
getMaxLiqUtilizationRateBps,
|
50
51
|
uint8ArrayToBigInt,
|
51
52
|
} from "../utils/numberUtils";
|
@@ -53,10 +54,7 @@ import {
|
|
53
54
|
eligibleForRebalance,
|
54
55
|
positionStateWithLatestPrices,
|
55
56
|
} from "../utils/solauto/generalUtils";
|
56
|
-
import {
|
57
|
-
getTokenAccount,
|
58
|
-
getTokenAccountData,
|
59
|
-
} from "../utils/accountUtils";
|
57
|
+
import { getTokenAccount, getTokenAccountData } from "../utils/accountUtils";
|
60
58
|
import {
|
61
59
|
createMarginfiProgram,
|
62
60
|
getLendingAccountBorrowInstructionDataSerializer,
|
@@ -72,7 +70,7 @@ import {
|
|
72
70
|
getJupiterErrorFromName,
|
73
71
|
JUPITER_PROGRAM_ID,
|
74
72
|
} from "../jupiter-sdk";
|
75
|
-
import { PRICES } from "../constants";
|
73
|
+
import { MIN_USD_SUPPORTED_POSITION, PRICES, USD_DECIMALS } from "../constants";
|
76
74
|
import { TransactionItemInputs } from "../types";
|
77
75
|
|
78
76
|
interface wSolTokenUsage {
|
@@ -400,9 +398,15 @@ function transactionChoresAfter(
|
|
400
398
|
return chores;
|
401
399
|
}
|
402
400
|
|
403
|
-
function getRebalanceInstructions(
|
401
|
+
function getRebalanceInstructions(
|
402
|
+
umi: Umi,
|
403
|
+
tx: TransactionBuilder
|
404
|
+
): Instruction[] {
|
404
405
|
return tx.getInstructions().filter((x) => {
|
405
|
-
if (
|
406
|
+
if (
|
407
|
+
x.programId.toString() ===
|
408
|
+
umi.programs.get("solauto").publicKey.toString()
|
409
|
+
) {
|
406
410
|
try {
|
407
411
|
const serializer = getMarginfiRebalanceInstructionDataSerializer();
|
408
412
|
const discriminator = serializer.serialize({
|
@@ -424,7 +428,10 @@ function getSolautoActions(umi: Umi, tx: TransactionBuilder): SolautoAction[] {
|
|
424
428
|
let solautoActions: SolautoAction[] = [];
|
425
429
|
|
426
430
|
tx.getInstructions().forEach((x) => {
|
427
|
-
if (
|
431
|
+
if (
|
432
|
+
x.programId.toString() ===
|
433
|
+
umi.programs.get("solauto").publicKey.toString()
|
434
|
+
) {
|
428
435
|
try {
|
429
436
|
const serializer =
|
430
437
|
getMarginfiProtocolInteractionInstructionDataSerializer();
|
@@ -658,6 +665,17 @@ export async function buildSolautoRebalanceTransaction(
|
|
658
665
|
);
|
659
666
|
client.log("Rebalance values: ", values);
|
660
667
|
|
668
|
+
if (
|
669
|
+
targetLiqUtilizationRateBps === undefined &&
|
670
|
+
fromBaseUnit(
|
671
|
+
client.solautoPositionState?.netWorth.baseAmountUsdValue ?? BigInt(0),
|
672
|
+
USD_DECIMALS
|
673
|
+
) < MIN_USD_SUPPORTED_POSITION &&
|
674
|
+
values.feesUsd < 0.5
|
675
|
+
) {
|
676
|
+
return undefined;
|
677
|
+
}
|
678
|
+
|
661
679
|
const swapDetails = getJupSwapRebalanceDetails(
|
662
680
|
client,
|
663
681
|
values,
|
@@ -806,11 +824,14 @@ export function getErrorInfo(umi: Umi, tx: TransactionBuilder, error: any) {
|
|
806
824
|
const err = (error as any)["InstructionError"];
|
807
825
|
const errIx = tx.getInstructions()[Math.max(0, err[0] - 2)];
|
808
826
|
const errCode = typeof err[1] === "object" ? err[1]["Custom"] : undefined;
|
809
|
-
const errName = errCode === undefined ? err[1] as string : undefined;
|
827
|
+
const errName = errCode === undefined ? (err[1] as string) : undefined;
|
810
828
|
let programName = "";
|
811
829
|
|
812
|
-
if (
|
813
|
-
|
830
|
+
if (
|
831
|
+
errIx.programId.toString() ===
|
832
|
+
umi.programs.get("solauto").publicKey.toString()
|
833
|
+
) {
|
834
|
+
programError = getSolautoErrorFromCode(errCode, createSolautoProgram());
|
814
835
|
programName = "Haven";
|
815
836
|
if (
|
816
837
|
programError?.name ===
|
package/src/utils/solanaUtils.ts
CHANGED
@@ -418,7 +418,6 @@ export async function sendSingleOptimizedTransaction(
|
|
418
418
|
// },
|
419
419
|
// confirm: { commitment: "confirmed" },
|
420
420
|
// });
|
421
|
-
|
422
421
|
const blockhash = await connection.getLatestBlockhash("confirmed");
|
423
422
|
const signedTx = await assembleFinalTransaction(
|
424
423
|
umi.identity,
|
@@ -428,13 +427,13 @@ export async function sendSingleOptimizedTransaction(
|
|
428
427
|
)
|
429
428
|
.setBlockhash(blockhash)
|
430
429
|
.buildAndSign(umi);
|
431
|
-
|
432
430
|
const txSig = await spamSendTransactionUntilConfirmed(
|
433
431
|
connection,
|
434
432
|
toWeb3JsTransaction(signedTx),
|
435
433
|
blockhash,
|
436
434
|
confirmTimeout
|
437
435
|
);
|
436
|
+
|
438
437
|
consoleLog(`Transaction signature: ${txSig}`);
|
439
438
|
consoleLog(`https://solscan.io/tx/${txSig}`);
|
440
439
|
return bs58.decode(txSig);
|
@@ -19,6 +19,7 @@ import { JupSwapDetails } from "../jupiterUtils";
|
|
19
19
|
import { currentUnixSeconds, safeGetPrice } from "../generalUtils";
|
20
20
|
import {
|
21
21
|
fromBaseUnit,
|
22
|
+
fromBps,
|
22
23
|
getDebtAdjustmentUsd,
|
23
24
|
getLiqUtilzationRateBps,
|
24
25
|
getMaxLiqUtilizationRateBps,
|
@@ -164,7 +165,8 @@ export interface RebalanceValues {
|
|
164
165
|
amountUsdToDcaIn: number;
|
165
166
|
dcaTokenType?: TokenType;
|
166
167
|
rebalanceAction: RebalanceAction;
|
167
|
-
rebalanceDirection: RebalanceDirection
|
168
|
+
rebalanceDirection: RebalanceDirection;
|
169
|
+
feesUsd: number;
|
168
170
|
}
|
169
171
|
|
170
172
|
export function getRebalanceValues(
|
@@ -222,6 +224,7 @@ export function getRebalanceValues(
|
|
222
224
|
rebalanceAction:
|
223
225
|
(amountToDcaIn ?? 0) > 0 ? "dca" : rebalanceDirection === RebalanceDirection.Boost ? "boost" : "repay",
|
224
226
|
rebalanceDirection,
|
227
|
+
feesUsd: debtAdjustmentUsd * fromBps(adjustmentFeeBps)
|
225
228
|
};
|
226
229
|
}
|
227
230
|
|
@@ -133,13 +133,6 @@ describe("Solauto Marginfi tests", async () => {
|
|
133
133
|
)
|
134
134
|
);
|
135
135
|
|
136
|
-
// transactionItems.push(
|
137
|
-
// new TransactionItem(
|
138
|
-
// async (attemptNum) => await buildSolautoRebalanceTransaction(client, 0),
|
139
|
-
// "repay all debt"
|
140
|
-
// )
|
141
|
-
// );
|
142
|
-
|
143
136
|
// transactionItems.push(
|
144
137
|
// new TransactionItem(
|
145
138
|
// async () => ({
|