@haven-fi/solauto-sdk 1.0.51 → 1.0.53
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +1 -7
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +3 -1
- package/dist/generated/accounts/referralState.d.ts.map +1 -1
- package/dist/generated/accounts/referralState.js +8 -9
- package/dist/generated/accounts/solautoPosition.d.ts.map +1 -1
- package/dist/generated/accounts/solautoPosition.js +8 -9
- package/dist/generated/errors/solauto.js +3 -3
- package/dist/generated/instructions/cancelDCA.js +2 -3
- package/dist/generated/instructions/claimReferralFees.js +2 -3
- package/dist/generated/instructions/closePosition.js +2 -3
- package/dist/generated/instructions/convertReferralFees.js +2 -3
- package/dist/generated/instructions/marginfiOpenPosition.d.ts +1 -0
- package/dist/generated/instructions/marginfiOpenPosition.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiOpenPosition.js +22 -18
- package/dist/generated/instructions/marginfiProtocolInteraction.js +2 -3
- package/dist/generated/instructions/marginfiRebalance.js +2 -3
- package/dist/generated/instructions/marginfiRefreshData.js +2 -3
- package/dist/generated/instructions/updatePosition.js +2 -3
- package/dist/generated/instructions/updateReferralStates.js +2 -3
- package/dist/generated/programs/solauto.d.ts.map +1 -1
- package/dist/generated/programs/solauto.js +4 -4
- package/dist/generated/shared/index.js +4 -5
- package/dist/generated/types/automationSettings.js +1 -2
- package/dist/generated/types/automationSettingsInp.js +1 -2
- package/dist/generated/types/dCASettings.js +1 -2
- package/dist/generated/types/dCASettingsInp.js +1 -2
- package/dist/generated/types/feeType.js +3 -3
- package/dist/generated/types/lendingPlatform.js +3 -3
- package/dist/generated/types/podBool.js +1 -2
- package/dist/generated/types/positionData.js +1 -2
- package/dist/generated/types/positionState.js +1 -2
- package/dist/generated/types/positionTokenUsage.js +1 -2
- package/dist/generated/types/rebalanceData.js +1 -2
- package/dist/generated/types/solautoAction.js +3 -4
- package/dist/generated/types/solautoRebalanceType.js +3 -3
- package/dist/generated/types/solautoSettingsParameters.js +1 -2
- package/dist/generated/types/solautoSettingsParametersInp.js +1 -2
- package/dist/generated/types/tokenAmount.js +1 -2
- package/dist/generated/types/tokenBalanceAmount.js +3 -4
- package/dist/generated/types/updatePositionData.js +1 -2
- package/dist/marginfi-sdk/accounts/bank.d.ts.map +1 -1
- package/dist/marginfi-sdk/accounts/bank.js +8 -9
- package/dist/marginfi-sdk/accounts/marginfiAccount.d.ts.map +1 -1
- package/dist/marginfi-sdk/accounts/marginfiAccount.js +8 -9
- package/dist/marginfi-sdk/accounts/marginfiGroup.d.ts.map +1 -1
- package/dist/marginfi-sdk/accounts/marginfiGroup.js +8 -9
- package/dist/marginfi-sdk/errors/marginfi.js +3 -3
- package/dist/marginfi-sdk/instructions/lendingAccountBorrow.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingAccountCloseBalance.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingAccountDeposit.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingAccountEndFlashloan.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingAccountLiquidate.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingAccountRepay.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingAccountSettleEmissions.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingAccountStartFlashloan.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingAccountWithdraw.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingAccountWithdrawEmissions.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingPoolAccrueBankInterest.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingPoolAddBank.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingPoolAddBankWithSeed.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingPoolCollectBankFees.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingPoolConfigureBank.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingPoolHandleBankruptcy.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingPoolSetupEmissions.js +2 -3
- package/dist/marginfi-sdk/instructions/lendingPoolUpdateEmissionsParameters.js +2 -3
- package/dist/marginfi-sdk/instructions/marginfiAccountInitialize.js +2 -3
- package/dist/marginfi-sdk/instructions/marginfiGroupConfigure.js +2 -3
- package/dist/marginfi-sdk/instructions/marginfiGroupInitialize.js +2 -3
- package/dist/marginfi-sdk/instructions/setAccountFlag.js +2 -3
- package/dist/marginfi-sdk/instructions/setNewAccountAuthority.js +2 -3
- package/dist/marginfi-sdk/instructions/unsetAccountFlag.js +2 -3
- package/dist/marginfi-sdk/programs/marginfi.d.ts.map +1 -1
- package/dist/marginfi-sdk/programs/marginfi.js +4 -4
- package/dist/marginfi-sdk/shared/index.js +4 -5
- package/dist/marginfi-sdk/types/accountEventHeader.js +1 -2
- package/dist/marginfi-sdk/types/balance.js +1 -2
- package/dist/marginfi-sdk/types/balanceDecreaseType.js +3 -3
- package/dist/marginfi-sdk/types/balanceIncreaseType.js +3 -3
- package/dist/marginfi-sdk/types/balanceSide.js +3 -3
- package/dist/marginfi-sdk/types/bankConfig.js +1 -2
- package/dist/marginfi-sdk/types/bankConfigCompact.js +1 -2
- package/dist/marginfi-sdk/types/bankOperationalState.js +3 -3
- package/dist/marginfi-sdk/types/bankVaultType.js +3 -3
- package/dist/marginfi-sdk/types/groupEventHeader.js +1 -2
- package/dist/marginfi-sdk/types/interestRateConfig.js +1 -2
- package/dist/marginfi-sdk/types/interestRateConfigCompact.js +1 -2
- package/dist/marginfi-sdk/types/interestRateConfigOpt.js +1 -2
- package/dist/marginfi-sdk/types/lendingAccount.js +1 -2
- package/dist/marginfi-sdk/types/liquidationBalances.js +1 -2
- package/dist/marginfi-sdk/types/oracleConfig.js +1 -2
- package/dist/marginfi-sdk/types/oraclePriceType.js +3 -3
- package/dist/marginfi-sdk/types/oracleSetup.js +3 -3
- package/dist/marginfi-sdk/types/priceBias.js +3 -3
- package/dist/marginfi-sdk/types/requirementType.js +3 -3
- package/dist/marginfi-sdk/types/riskRequirementType.js +3 -3
- package/dist/marginfi-sdk/types/riskTier.js +3 -3
- package/dist/marginfi-sdk/types/wrappedI80F48.js +1 -2
- package/dist/transactions/transactionUtils.js +5 -6
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +1 -1
- package/dist/types/solauto.d.ts +1 -0
- package/dist/types/solauto.d.ts.map +1 -1
- package/dist/types/solauto.js +1 -1
- package/dist/utils/accountUtils.d.ts +0 -1
- package/dist/utils/accountUtils.d.ts.map +1 -1
- package/dist/utils/accountUtils.js +7 -8
- package/dist/utils/generalUtils.js +8 -9
- package/dist/utils/jupiterUtils.js +1 -2
- package/dist/utils/marginfiUtils.js +5 -6
- package/dist/utils/numberUtils.js +11 -12
- package/dist/utils/solanaUtils.js +13 -14
- 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 +19 -20
- package/dist/utils/solauto/rebalanceUtils.js +3 -4
- package/package.json +3 -2
- package/src/clients/solautoClient.ts +1 -10
- package/src/clients/solautoMarginfiClient.ts +2 -0
- package/src/generated/instructions/marginfiOpenPosition.ts +21 -15
- package/src/transactions/transactionUtils.ts +2 -2
- package/src/types/solauto.ts +3 -1
- package/src/utils/solauto/generalUtils.ts +8 -9
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getJupSwapTransaction =
|
3
|
+
exports.getJupSwapTransaction = getJupSwapTransaction;
|
4
4
|
const umi_1 = require("@metaplex-foundation/umi");
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
6
6
|
const solanaUtils_1 = require("./solanaUtils");
|
@@ -61,4 +61,3 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
|
|
61
61
|
swapIx: (0, umi_1.transactionBuilder)().add((0, solanaUtils_1.getWrappedInstruction)(signer, createTransactionInstruction(instructions.swapInstruction))),
|
62
62
|
};
|
63
63
|
}
|
64
|
-
exports.getJupSwapTransaction = getJupSwapTransaction;
|
@@ -1,6 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.findMarginfiAccounts = findMarginfiAccounts;
|
4
|
+
exports.getMaxLtvAndLiqThreshold = getMaxLtvAndLiqThreshold;
|
5
|
+
exports.getAllMarginfiAccountsByAuthority = getAllMarginfiAccountsByAuthority;
|
6
|
+
exports.getMarginfiAccountPositionState = getMarginfiAccountPositionState;
|
7
|
+
exports.getUpToDateShareValues = getUpToDateShareValues;
|
4
8
|
const web3_js_1 = require("@solana/web3.js");
|
5
9
|
const umi_1 = require("@metaplex-foundation/umi");
|
6
10
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
@@ -23,7 +27,6 @@ function findMarginfiAccounts({ mint, bank, }) {
|
|
23
27
|
}
|
24
28
|
throw new Error(`Marginfi accounts not found by the mint: ${mint}`);
|
25
29
|
}
|
26
|
-
exports.findMarginfiAccounts = findMarginfiAccounts;
|
27
30
|
async function getMaxLtvAndLiqThreshold(umi, supply, debt, supplyPrice) {
|
28
31
|
if (!supply.bank) {
|
29
32
|
supply.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(findMarginfiAccounts({
|
@@ -58,7 +61,6 @@ async function getMaxLtvAndLiqThreshold(umi, supply, debt, supplyPrice) {
|
|
58
61
|
}
|
59
62
|
return [maxLtv, liqThreshold];
|
60
63
|
}
|
61
|
-
exports.getMaxLtvAndLiqThreshold = getMaxLtvAndLiqThreshold;
|
62
64
|
async function getAllMarginfiAccountsByAuthority(umi, authority, compatibleWithSolauto) {
|
63
65
|
const marginfiAccounts = await umi.rpc.getProgramAccounts(marginfi_sdk_1.MARGINFI_PROGRAM_ID, {
|
64
66
|
commitment: "finalized",
|
@@ -97,7 +99,6 @@ async function getAllMarginfiAccountsByAuthority(umi, authority, compatibleWithS
|
|
97
99
|
}));
|
98
100
|
}
|
99
101
|
}
|
100
|
-
exports.getAllMarginfiAccountsByAuthority = getAllMarginfiAccountsByAuthority;
|
101
102
|
async function getTokenUsage(umi, bank, isAsset, shares, amountUsedAdjustment) {
|
102
103
|
let amountUsed = 0;
|
103
104
|
let amountCanBeUsed = 0;
|
@@ -209,7 +210,6 @@ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, supplyMin
|
|
209
210
|
padding: [],
|
210
211
|
};
|
211
212
|
}
|
212
|
-
exports.getMarginfiAccountPositionState = getMarginfiAccountPositionState;
|
213
213
|
function marginfiInterestRateCurve(bank, utilizationRatio) {
|
214
214
|
const optimalUr = (0, numberUtils_1.bytesToI80F48)(bank.config.interestRateConfig.optimalUtilizationRate.value);
|
215
215
|
const plateauIr = (0, numberUtils_1.bytesToI80F48)(bank.config.interestRateConfig.plateauInterestRate.value);
|
@@ -253,4 +253,3 @@ async function getUpToDateShareValues(umi, bank) {
|
|
253
253
|
calcAccruedInterestPaymentPerPeriod(borrowingApr, timeDelta, (0, numberUtils_1.bytesToI80F48)(bank.liabilityShareValue.value)),
|
254
254
|
];
|
255
255
|
}
|
256
|
-
exports.getUpToDateShareValues = getUpToDateShareValues;
|
@@ -1,6 +1,16 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.getLiqUtilzationRateBps = getLiqUtilzationRateBps;
|
4
|
+
exports.toBaseUnit = toBaseUnit;
|
5
|
+
exports.fromBaseUnit = fromBaseUnit;
|
6
|
+
exports.fromBps = fromBps;
|
7
|
+
exports.toBps = toBps;
|
8
|
+
exports.bytesToI80F48 = bytesToI80F48;
|
9
|
+
exports.uint8ArrayToBigInt = uint8ArrayToBigInt;
|
10
|
+
exports.getDebtAdjustmentUsd = getDebtAdjustmentUsd;
|
11
|
+
exports.getMaxLiqUtilizationRate = getMaxLiqUtilizationRate;
|
12
|
+
exports.maxRepayFrom = maxRepayFrom;
|
13
|
+
exports.maxRepayTo = maxRepayTo;
|
4
14
|
const constants_1 = require("../constants");
|
5
15
|
function getLiqUtilzationRateBps(supplyUsd, debtUsd, liqThresholdBps) {
|
6
16
|
if (supplyUsd === 0) {
|
@@ -8,23 +18,18 @@ function getLiqUtilzationRateBps(supplyUsd, debtUsd, liqThresholdBps) {
|
|
8
18
|
}
|
9
19
|
return toBps(debtUsd / (supplyUsd * fromBps(liqThresholdBps)));
|
10
20
|
}
|
11
|
-
exports.getLiqUtilzationRateBps = getLiqUtilzationRateBps;
|
12
21
|
function toBaseUnit(value, decimals) {
|
13
22
|
return BigInt(Math.round(value * Math.pow(10, decimals)));
|
14
23
|
}
|
15
|
-
exports.toBaseUnit = toBaseUnit;
|
16
24
|
function fromBaseUnit(value, decimals) {
|
17
25
|
return Number(value) / Math.pow(10, decimals);
|
18
26
|
}
|
19
|
-
exports.fromBaseUnit = fromBaseUnit;
|
20
27
|
function fromBps(value) {
|
21
28
|
return value / 10000;
|
22
29
|
}
|
23
|
-
exports.fromBps = fromBps;
|
24
30
|
function toBps(value) {
|
25
31
|
return Math.round(value * 10000);
|
26
32
|
}
|
27
|
-
exports.toBps = toBps;
|
28
33
|
function bytesToI80F48(bytes) {
|
29
34
|
if (bytes.length !== 16) {
|
30
35
|
throw new Error('Byte array must be exactly 16 bytes.');
|
@@ -41,7 +46,6 @@ function bytesToI80F48(bytes) {
|
|
41
46
|
const fullValue = integerPart * BigInt(2 ** 48) + fractionalPart;
|
42
47
|
return Number(fullValue) / (2 ** 48);
|
43
48
|
}
|
44
|
-
exports.bytesToI80F48 = bytesToI80F48;
|
45
49
|
function uint8ArrayToBigInt(uint8Array) {
|
46
50
|
if (uint8Array.length !== 8) {
|
47
51
|
throw new Error('Uint8Array must be exactly 8 bytes long to convert to u64.');
|
@@ -52,7 +56,6 @@ function uint8ArrayToBigInt(uint8Array) {
|
|
52
56
|
const high = dataView.getUint32(4, true);
|
53
57
|
return BigInt(high) << 32n | BigInt(low);
|
54
58
|
}
|
55
|
-
exports.uint8ArrayToBigInt = uint8ArrayToBigInt;
|
56
59
|
function getDebtAdjustmentUsd(liqThresholdBps, supplyUsd, debtUsd, targetLiqUtilizationRateBps, adjustmentFeeBps) {
|
57
60
|
const adjustmentFee = adjustmentFeeBps && adjustmentFeeBps > 0 ? fromBps(adjustmentFeeBps) : 0;
|
58
61
|
const liqThreshold = fromBps(liqThresholdBps);
|
@@ -60,16 +63,12 @@ function getDebtAdjustmentUsd(liqThresholdBps, supplyUsd, debtUsd, targetLiqUtil
|
|
60
63
|
const debtAdjustmentUsd = (targetLiqUtilizationRate * supplyUsd * liqThreshold - debtUsd) / (1 - targetLiqUtilizationRate * (1 - adjustmentFee) * liqThreshold);
|
61
64
|
return debtAdjustmentUsd;
|
62
65
|
}
|
63
|
-
exports.getDebtAdjustmentUsd = getDebtAdjustmentUsd;
|
64
66
|
function getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps) {
|
65
67
|
return toBps((fromBps(maxLtvBps) - 0.015) / fromBps(liqThresholdBps)) - 1; // -1 to account for any rounding issues
|
66
68
|
}
|
67
|
-
exports.getMaxLiqUtilizationRate = getMaxLiqUtilizationRate;
|
68
69
|
function maxRepayFrom(maxLtvBps, liqThresholdBps) {
|
69
70
|
return Math.min(9000, getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps - 1000));
|
70
71
|
}
|
71
|
-
exports.maxRepayFrom = maxRepayFrom;
|
72
72
|
function maxRepayTo(maxLtvBps, liqThresholdBps) {
|
73
73
|
return Math.min(maxRepayFrom(maxLtvBps, liqThresholdBps) - constants_1.MAX_REPAY_GAP_BPS, getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps));
|
74
74
|
}
|
75
|
-
exports.maxRepayTo = maxRepayTo;
|
@@ -3,7 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.
|
6
|
+
exports.getSolanaRpcConnection = getSolanaRpcConnection;
|
7
|
+
exports.currentUnixSecondsSolana = currentUnixSecondsSolana;
|
8
|
+
exports.getWrappedInstruction = getWrappedInstruction;
|
9
|
+
exports.setComputeUnitLimitUmiIx = setComputeUnitLimitUmiIx;
|
10
|
+
exports.setComputeUnitPriceUmiIx = setComputeUnitPriceUmiIx;
|
11
|
+
exports.createAssociatedTokenAccountUmiIx = createAssociatedTokenAccountUmiIx;
|
12
|
+
exports.systemTransferUmiIx = systemTransferUmiIx;
|
13
|
+
exports.closeTokenAccountUmiIx = closeTokenAccountUmiIx;
|
14
|
+
exports.splTokenTransferUmiIx = splTokenTransferUmiIx;
|
15
|
+
exports.getAdressLookupInputs = getAdressLookupInputs;
|
16
|
+
exports.assembleFinalTransaction = assembleFinalTransaction;
|
17
|
+
exports.getComputeUnitPriceEstimate = getComputeUnitPriceEstimate;
|
18
|
+
exports.sendSingleOptimizedTransaction = sendSingleOptimizedTransaction;
|
7
19
|
const bs58_1 = __importDefault(require("bs58"));
|
8
20
|
const umi_1 = require("@metaplex-foundation/umi");
|
9
21
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
@@ -19,7 +31,6 @@ function getSolanaRpcConnection(heliusApiKey) {
|
|
19
31
|
const umi = (0, umi_bundle_defaults_1.createUmi)(connection);
|
20
32
|
return [connection, umi];
|
21
33
|
}
|
22
|
-
exports.getSolanaRpcConnection = getSolanaRpcConnection;
|
23
34
|
async function currentUnixSecondsSolana(umi) {
|
24
35
|
return await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
25
36
|
const blockTime = await umi.rpc.getBlockTime(await umi.rpc.getSlot());
|
@@ -29,7 +40,6 @@ async function currentUnixSecondsSolana(umi) {
|
|
29
40
|
return Number(blockTime);
|
30
41
|
});
|
31
42
|
}
|
32
|
-
exports.currentUnixSecondsSolana = currentUnixSecondsSolana;
|
33
43
|
function getWrappedInstruction(signer, ix) {
|
34
44
|
return {
|
35
45
|
instruction: (0, umi_web3js_adapters_1.fromWeb3JsInstruction)(ix),
|
@@ -37,23 +47,19 @@ function getWrappedInstruction(signer, ix) {
|
|
37
47
|
bytesCreatedOnChain: 0,
|
38
48
|
};
|
39
49
|
}
|
40
|
-
exports.getWrappedInstruction = getWrappedInstruction;
|
41
50
|
function setComputeUnitLimitUmiIx(signer, maxComputeUnits) {
|
42
51
|
return getWrappedInstruction(signer, web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
43
52
|
units: maxComputeUnits,
|
44
53
|
}));
|
45
54
|
}
|
46
|
-
exports.setComputeUnitLimitUmiIx = setComputeUnitLimitUmiIx;
|
47
55
|
function setComputeUnitPriceUmiIx(signer, lamports) {
|
48
56
|
return getWrappedInstruction(signer, web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
49
57
|
microLamports: lamports,
|
50
58
|
}));
|
51
59
|
}
|
52
|
-
exports.setComputeUnitPriceUmiIx = setComputeUnitPriceUmiIx;
|
53
60
|
function createAssociatedTokenAccountUmiIx(signer, wallet, mint) {
|
54
61
|
return getWrappedInstruction(signer, (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey), (0, accountUtils_1.getTokenAccount)(wallet, mint), wallet, mint));
|
55
62
|
}
|
56
|
-
exports.createAssociatedTokenAccountUmiIx = createAssociatedTokenAccountUmiIx;
|
57
63
|
function systemTransferUmiIx(signer, destination, lamports) {
|
58
64
|
return getWrappedInstruction(signer, web3_js_1.SystemProgram.transfer({
|
59
65
|
fromPubkey: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey),
|
@@ -61,15 +67,12 @@ function systemTransferUmiIx(signer, destination, lamports) {
|
|
61
67
|
lamports,
|
62
68
|
}));
|
63
69
|
}
|
64
|
-
exports.systemTransferUmiIx = systemTransferUmiIx;
|
65
70
|
function closeTokenAccountUmiIx(signer, tokenAccount, authority) {
|
66
71
|
return getWrappedInstruction(signer, (0, spl_token_1.createCloseAccountInstruction)(tokenAccount, authority, authority));
|
67
72
|
}
|
68
|
-
exports.closeTokenAccountUmiIx = closeTokenAccountUmiIx;
|
69
73
|
function splTokenTransferUmiIx(signer, fromTa, toTa, authority, amount) {
|
70
74
|
return getWrappedInstruction(signer, (0, spl_token_1.createTransferInstruction)(fromTa, toTa, authority, amount));
|
71
75
|
}
|
72
|
-
exports.splTokenTransferUmiIx = splTokenTransferUmiIx;
|
73
76
|
async function getAdressLookupInputs(umi, lookupTableAddresses) {
|
74
77
|
const addressLookupTableAccountInfos = await umi.rpc.getAccounts(lookupTableAddresses.map((key) => (0, umi_1.publicKey)(key)));
|
75
78
|
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
|
@@ -83,7 +86,6 @@ async function getAdressLookupInputs(umi, lookupTableAddresses) {
|
|
83
86
|
return acc;
|
84
87
|
}, new Array());
|
85
88
|
}
|
86
|
-
exports.getAdressLookupInputs = getAdressLookupInputs;
|
87
89
|
function assembleFinalTransaction(signer, tx, computeUnitPrice, computeUnitLimit) {
|
88
90
|
tx = tx
|
89
91
|
.prepend(setComputeUnitPriceUmiIx(signer, computeUnitPrice))
|
@@ -125,7 +127,6 @@ function assembleFinalTransaction(signer, tx, computeUnitPrice, computeUnitLimit
|
|
125
127
|
}
|
126
128
|
return tx;
|
127
129
|
}
|
128
|
-
exports.assembleFinalTransaction = assembleFinalTransaction;
|
129
130
|
async function simulateTransaction(connection, transaction) {
|
130
131
|
const simulationResult = await connection.simulateTransaction(transaction, {
|
131
132
|
sigVerify: false,
|
@@ -153,7 +154,6 @@ async function getComputeUnitPriceEstimate(umi, tx, prioritySetting, attemptNum)
|
|
153
154
|
const feeEstimate = Math.round(resp.priorityFeeEstimate);
|
154
155
|
return feeEstimate;
|
155
156
|
}
|
156
|
-
exports.getComputeUnitPriceEstimate = getComputeUnitPriceEstimate;
|
157
157
|
async function sendSingleOptimizedTransaction(umi, connection, tx, simulateOnly, attemptNum, prioritySetting = types_1.PriorityFeeSetting.Default) {
|
158
158
|
console.log("Sending single optimized transaction...");
|
159
159
|
console.log("Instructions: ", tx.getInstructions().length);
|
@@ -179,4 +179,3 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, simulateOnly,
|
|
179
179
|
}
|
180
180
|
return undefined;
|
181
181
|
}
|
182
|
-
exports.sendSingleOptimizedTransaction = sendSingleOptimizedTransaction;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { Umi } from "@metaplex-foundation/umi";
|
3
3
|
import { AutomationSettings, DCASettings, DCASettingsInpArgs, FeeType, LendingPlatform, PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs } from "../../generated";
|
4
|
-
import { SolautoPositionDetails } from "../../types/solauto";
|
4
|
+
import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
|
5
5
|
export declare function nextAutomationPeriodTimestamp(automation: AutomationSettings): number;
|
6
6
|
export declare function eligibleForNextAutomationPeriod(automation: AutomationSettings): boolean;
|
7
7
|
export declare function getUpdatedValueFromAutomation(currValue: number, targetValue: number, automation: AutomationSettings, currentUnixTimestamp: number): number;
|
@@ -11,7 +11,7 @@ export declare function getSolautoFeesBps(isReferred: boolean, feeType: FeeType)
|
|
11
11
|
referrer: number;
|
12
12
|
total: number;
|
13
13
|
};
|
14
|
-
export declare function
|
14
|
+
export declare function eligibleForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings): RebalanceAction | undefined;
|
15
15
|
export declare function eligibleForRefresh(positionState: PositionState, positionSettings: SolautoSettingsParameters): boolean;
|
16
16
|
export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicKey): Promise<SolautoPositionDetails[]>;
|
17
17
|
export declare function getAllReferralStates(umi: Umi): Promise<PublicKey[]>;
|
@@ -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,EAAoB,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,eAAe,EACf,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;AAczB,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;
|
1
|
+
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"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"}
|
@@ -1,6 +1,18 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.LivePositionUpdates =
|
3
|
+
exports.LivePositionUpdates = void 0;
|
4
|
+
exports.nextAutomationPeriodTimestamp = nextAutomationPeriodTimestamp;
|
5
|
+
exports.eligibleForNextAutomationPeriod = eligibleForNextAutomationPeriod;
|
6
|
+
exports.getUpdatedValueFromAutomation = getUpdatedValueFromAutomation;
|
7
|
+
exports.getAdjustedSettingsFromAutomation = getAdjustedSettingsFromAutomation;
|
8
|
+
exports.getSolautoFeesBps = getSolautoFeesBps;
|
9
|
+
exports.eligibleForRebalance = eligibleForRebalance;
|
10
|
+
exports.eligibleForRefresh = eligibleForRefresh;
|
11
|
+
exports.getSolautoManagedPositions = getSolautoManagedPositions;
|
12
|
+
exports.getAllReferralStates = getAllReferralStates;
|
13
|
+
exports.getReferralsByUser = getReferralsByUser;
|
14
|
+
exports.getAllPositionsByAuthority = getAllPositionsByAuthority;
|
15
|
+
exports.positionStateWithLatestPrices = positionStateWithLatestPrices;
|
4
16
|
const umi_1 = require("@metaplex-foundation/umi");
|
5
17
|
const generated_1 = require("../../generated");
|
6
18
|
const generalUtils_1 = require("../generalUtils");
|
@@ -20,11 +32,9 @@ function nextAutomationPeriodTimestamp(automation) {
|
|
20
32
|
: Number(automation.unixStartDate) +
|
21
33
|
automation.periodsPassed * Number(automation.intervalSeconds);
|
22
34
|
}
|
23
|
-
exports.nextAutomationPeriodTimestamp = nextAutomationPeriodTimestamp;
|
24
35
|
function eligibleForNextAutomationPeriod(automation) {
|
25
36
|
return (0, generalUtils_1.currentUnixSeconds)() >= nextAutomationPeriodTimestamp(automation);
|
26
37
|
}
|
27
|
-
exports.eligibleForNextAutomationPeriod = eligibleForNextAutomationPeriod;
|
28
38
|
function getUpdatedValueFromAutomation(currValue, targetValue, automation, currentUnixTimestamp) {
|
29
39
|
const currRateDiff = currValue - targetValue;
|
30
40
|
const progressPct = 1 /
|
@@ -33,7 +43,6 @@ function getUpdatedValueFromAutomation(currValue, targetValue, automation, curre
|
|
33
43
|
const newValue = currValue - currRateDiff * progressPct;
|
34
44
|
return newValue;
|
35
45
|
}
|
36
|
-
exports.getUpdatedValueFromAutomation = getUpdatedValueFromAutomation;
|
37
46
|
function getAdjustedSettingsFromAutomation(settings, currentUnixSeconds) {
|
38
47
|
const boostToBps = settings.automation.targetPeriods > 0 &&
|
39
48
|
eligibleForNextAutomationPeriod(settings.automation)
|
@@ -44,7 +53,6 @@ function getAdjustedSettingsFromAutomation(settings, currentUnixSeconds) {
|
|
44
53
|
boostToBps,
|
45
54
|
};
|
46
55
|
}
|
47
|
-
exports.getAdjustedSettingsFromAutomation = getAdjustedSettingsFromAutomation;
|
48
56
|
function getSolautoFeesBps(isReferred, feeType) {
|
49
57
|
const fees = feeType === generated_1.FeeType.Small ? 100 : 500;
|
50
58
|
let referrer = 0;
|
@@ -57,14 +65,13 @@ function getSolautoFeesBps(isReferred, feeType) {
|
|
57
65
|
total: fees,
|
58
66
|
};
|
59
67
|
}
|
60
|
-
|
61
|
-
function eligibileForRebalance(positionState, positionSettings, positionDca) {
|
68
|
+
function eligibleForRebalance(positionState, positionSettings, positionDca) {
|
62
69
|
if (positionDca.automation.targetPeriods > 0 &&
|
63
70
|
eligibleForNextAutomationPeriod(positionDca.automation)) {
|
64
|
-
return
|
71
|
+
return 'dca';
|
65
72
|
}
|
66
73
|
if (positionState.supply.amountUsed.baseUnit === BigInt(0)) {
|
67
|
-
return
|
74
|
+
return undefined;
|
68
75
|
}
|
69
76
|
const boostToBps = eligibleForRefresh(positionState, positionSettings) &&
|
70
77
|
positionSettings.automation.targetPeriods > 0
|
@@ -73,15 +80,13 @@ function eligibileForRebalance(positionState, positionSettings, positionDca) {
|
|
73
80
|
const repayFrom = positionSettings.repayToBps + positionSettings.repayGap;
|
74
81
|
const boostFrom = boostToBps - positionSettings.boostGap;
|
75
82
|
if (positionState.liqUtilizationRateBps <= boostFrom) {
|
76
|
-
return
|
83
|
+
return 'boost';
|
77
84
|
}
|
78
85
|
else if (positionState.liqUtilizationRateBps >= repayFrom) {
|
79
|
-
|
80
|
-
return true;
|
86
|
+
return 'repay';
|
81
87
|
}
|
82
|
-
return
|
88
|
+
return undefined;
|
83
89
|
}
|
84
|
-
exports.eligibileForRebalance = eligibileForRebalance;
|
85
90
|
function eligibleForRefresh(positionState, positionSettings) {
|
86
91
|
if (positionSettings.automation.targetPeriods > 0) {
|
87
92
|
return eligibleForNextAutomationPeriod(positionSettings.automation);
|
@@ -91,7 +96,6 @@ function eligibleForRefresh(positionState, positionSettings) {
|
|
91
96
|
60 * 60 * 24 * 7);
|
92
97
|
}
|
93
98
|
}
|
94
|
-
exports.eligibleForRefresh = eligibleForRefresh;
|
95
99
|
async function getSolautoManagedPositions(umi, authority) {
|
96
100
|
// bump: [u8; 1]
|
97
101
|
// position_id: [u8; 1]
|
@@ -140,7 +144,6 @@ async function getSolautoManagedPositions(umi, authority) {
|
|
140
144
|
};
|
141
145
|
});
|
142
146
|
}
|
143
|
-
exports.getSolautoManagedPositions = getSolautoManagedPositions;
|
144
147
|
async function getAllReferralStates(umi) {
|
145
148
|
const accounts = await umi.rpc.getProgramAccounts(generated_1.SOLAUTO_PROGRAM_ID, {
|
146
149
|
commitment: "finalized",
|
@@ -156,7 +159,6 @@ async function getAllReferralStates(umi) {
|
|
156
159
|
});
|
157
160
|
return accounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
|
158
161
|
}
|
159
|
-
exports.getAllReferralStates = getAllReferralStates;
|
160
162
|
async function getReferralsByUser(umi, user) {
|
161
163
|
// bump: [u8; 1],
|
162
164
|
// padding: [u8; 7],
|
@@ -183,7 +185,6 @@ async function getReferralsByUser(umi, user) {
|
|
183
185
|
});
|
184
186
|
return accounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
|
185
187
|
}
|
186
|
-
exports.getReferralsByUser = getReferralsByUser;
|
187
188
|
async function getAllPositionsByAuthority(umi, user) {
|
188
189
|
const allPositions = [];
|
189
190
|
const solautoManagedPositions = await getSolautoManagedPositions(umi, user);
|
@@ -206,7 +207,6 @@ async function getAllPositionsByAuthority(umi, user) {
|
|
206
207
|
// TODO support other platforms
|
207
208
|
return allPositions;
|
208
209
|
}
|
209
|
-
exports.getAllPositionsByAuthority = getAllPositionsByAuthority;
|
210
210
|
async function positionStateWithLatestPrices(umi, state, protocolAccount, lendingPlatform) {
|
211
211
|
if ((0, generalUtils_1.currentUnixSeconds)() - Number(state.lastUpdated) > 60 * 60 * 24 * 7) {
|
212
212
|
if (lendingPlatform === generated_1.LendingPlatform.Marginfi) {
|
@@ -247,7 +247,6 @@ async function positionStateWithLatestPrices(umi, state, protocolAccount, lendin
|
|
247
247
|
},
|
248
248
|
};
|
249
249
|
}
|
250
|
-
exports.positionStateWithLatestPrices = positionStateWithLatestPrices;
|
251
250
|
class LivePositionUpdates {
|
252
251
|
constructor() {
|
253
252
|
this.supplyAdjustment = BigInt(0);
|
@@ -1,6 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.getRebalanceValues = getRebalanceValues;
|
4
|
+
exports.getFlashLoanDetails = getFlashLoanDetails;
|
5
|
+
exports.getJupSwapRebalanceDetails = getJupSwapRebalanceDetails;
|
4
6
|
const generated_1 = require("../../generated");
|
5
7
|
const generalUtils_1 = require("./generalUtils");
|
6
8
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
@@ -127,7 +129,6 @@ function getRebalanceValues(client, targetLiqUtilizationRateBps, limitGapBps) {
|
|
127
129
|
amountUsdToDcaIn,
|
128
130
|
};
|
129
131
|
}
|
130
|
-
exports.getRebalanceValues = getRebalanceValues;
|
131
132
|
function getFlashLoanDetails(client, values, jupQuote) {
|
132
133
|
let supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
133
134
|
let debtUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
@@ -168,7 +169,6 @@ function getFlashLoanDetails(client, values, jupQuote) {
|
|
168
169
|
}
|
169
170
|
: undefined;
|
170
171
|
}
|
171
|
-
exports.getFlashLoanDetails = getFlashLoanDetails;
|
172
172
|
function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps, attemptNum) {
|
173
173
|
const input = values.increasingLeverage
|
174
174
|
? client.solautoPositionState.debt
|
@@ -196,4 +196,3 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
196
196
|
exactOut: rebalancingToZero,
|
197
197
|
};
|
198
198
|
}
|
199
|
-
exports.getJupSwapRebalanceDetails = getJupSwapRebalanceDetails;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@haven-fi/solauto-sdk",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.53",
|
4
4
|
"main": "dist/index.js",
|
5
5
|
"types": "dist/index.d.ts",
|
6
6
|
"description": "Typescript SDK for the Solauto program on the Solana blockchain",
|
@@ -32,6 +32,7 @@
|
|
32
32
|
"@types/mocha": "^9.1.1",
|
33
33
|
"chai": "^4.3.4",
|
34
34
|
"mocha": "^9.2.2",
|
35
|
-
"ts-mocha": "^10.0.0"
|
35
|
+
"ts-mocha": "^10.0.0",
|
36
|
+
"typescript": "^5.5.4"
|
36
37
|
}
|
37
38
|
}
|
@@ -419,8 +419,6 @@ export abstract class SolautoClient {
|
|
419
419
|
settingParams?: SolautoSettingsParametersInpArgs,
|
420
420
|
dca?: DCASettingsInpArgs
|
421
421
|
): TransactionBuilder {
|
422
|
-
let tx = transactionBuilder();
|
423
|
-
|
424
422
|
if (dca && dca.debtToAddBaseUnit > 0) {
|
425
423
|
this.livePositionUpdates.new({
|
426
424
|
type: "debtDcaIn",
|
@@ -440,14 +438,7 @@ export abstract class SolautoClient {
|
|
440
438
|
});
|
441
439
|
}
|
442
440
|
|
443
|
-
|
444
|
-
// Tip Solauto Manager
|
445
|
-
tx = tx.add(
|
446
|
-
systemTransferUmiIx(this.signer, SOLAUTO_MANAGER, toBaseUnit(0.1, 9))
|
447
|
-
);
|
448
|
-
}
|
449
|
-
|
450
|
-
return tx;
|
441
|
+
return transactionBuilder();
|
451
442
|
}
|
452
443
|
|
453
444
|
updatePositionIx(args: UpdatePositionDataArgs): TransactionBuilder {
|
@@ -53,6 +53,7 @@ import {
|
|
53
53
|
getMarginfiAccountPositionState,
|
54
54
|
} from "../utils/marginfiUtils";
|
55
55
|
import { bytesToI80F48 } from "../utils/numberUtils";
|
56
|
+
import { SOLAUTO_MANAGER } from "../constants";
|
56
57
|
|
57
58
|
export interface SolautoMarginfiClientArgs extends SolautoClientArgs {
|
58
59
|
marginfiAccount?: PublicKey | Signer;
|
@@ -204,6 +205,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
204
205
|
return marginfiOpenPosition(this.umi, {
|
205
206
|
signer: this.signer,
|
206
207
|
marginfiProgram: publicKey(MARGINFI_PROGRAM_ID),
|
208
|
+
solautoManager: publicKey(SOLAUTO_MANAGER),
|
207
209
|
solautoFeesWallet: publicKey(this.solautoFeesWallet),
|
208
210
|
solautoFeesSupplyTa: publicKey(this.solautoFeesSupplyTa),
|
209
211
|
signerReferralState: publicKey(this.authorityReferralState),
|
@@ -44,6 +44,7 @@ export type MarginfiOpenPositionInstructionAccounts = {
|
|
44
44
|
tokenProgram?: PublicKey | Pda;
|
45
45
|
ataProgram?: PublicKey | Pda;
|
46
46
|
rent?: PublicKey | Pda;
|
47
|
+
solautoManager: PublicKey | Pda;
|
47
48
|
solautoFeesWallet: PublicKey | Pda;
|
48
49
|
solautoFeesSupplyTa: PublicKey | Pda;
|
49
50
|
signerReferralState: PublicKey | Pda;
|
@@ -141,78 +142,83 @@ export function marginfiOpenPosition(
|
|
141
142
|
value: input.ataProgram ?? null,
|
142
143
|
},
|
143
144
|
rent: { index: 5, isWritable: false as boolean, value: input.rent ?? null },
|
144
|
-
|
145
|
+
solautoManager: {
|
145
146
|
index: 6,
|
147
|
+
isWritable: true as boolean,
|
148
|
+
value: input.solautoManager ?? null,
|
149
|
+
},
|
150
|
+
solautoFeesWallet: {
|
151
|
+
index: 7,
|
146
152
|
isWritable: false as boolean,
|
147
153
|
value: input.solautoFeesWallet ?? null,
|
148
154
|
},
|
149
155
|
solautoFeesSupplyTa: {
|
150
|
-
index:
|
156
|
+
index: 8,
|
151
157
|
isWritable: true as boolean,
|
152
158
|
value: input.solautoFeesSupplyTa ?? null,
|
153
159
|
},
|
154
160
|
signerReferralState: {
|
155
|
-
index:
|
161
|
+
index: 9,
|
156
162
|
isWritable: false as boolean,
|
157
163
|
value: input.signerReferralState ?? null,
|
158
164
|
},
|
159
165
|
referredByState: {
|
160
|
-
index:
|
166
|
+
index: 10,
|
161
167
|
isWritable: false as boolean,
|
162
168
|
value: input.referredByState ?? null,
|
163
169
|
},
|
164
170
|
referredBySupplyTa: {
|
165
|
-
index:
|
171
|
+
index: 11,
|
166
172
|
isWritable: true as boolean,
|
167
173
|
value: input.referredBySupplyTa ?? null,
|
168
174
|
},
|
169
175
|
solautoPosition: {
|
170
|
-
index:
|
176
|
+
index: 12,
|
171
177
|
isWritable: true as boolean,
|
172
178
|
value: input.solautoPosition ?? null,
|
173
179
|
},
|
174
180
|
marginfiGroup: {
|
175
|
-
index:
|
181
|
+
index: 13,
|
176
182
|
isWritable: false as boolean,
|
177
183
|
value: input.marginfiGroup ?? null,
|
178
184
|
},
|
179
185
|
marginfiAccount: {
|
180
|
-
index:
|
186
|
+
index: 14,
|
181
187
|
isWritable: true as boolean,
|
182
188
|
value: input.marginfiAccount ?? null,
|
183
189
|
},
|
184
190
|
supplyMint: {
|
185
|
-
index:
|
191
|
+
index: 15,
|
186
192
|
isWritable: false as boolean,
|
187
193
|
value: input.supplyMint ?? null,
|
188
194
|
},
|
189
195
|
supplyBank: {
|
190
|
-
index:
|
196
|
+
index: 16,
|
191
197
|
isWritable: false as boolean,
|
192
198
|
value: input.supplyBank ?? null,
|
193
199
|
},
|
194
200
|
positionSupplyTa: {
|
195
|
-
index:
|
201
|
+
index: 17,
|
196
202
|
isWritable: true as boolean,
|
197
203
|
value: input.positionSupplyTa ?? null,
|
198
204
|
},
|
199
205
|
debtMint: {
|
200
|
-
index:
|
206
|
+
index: 18,
|
201
207
|
isWritable: false as boolean,
|
202
208
|
value: input.debtMint ?? null,
|
203
209
|
},
|
204
210
|
debtBank: {
|
205
|
-
index:
|
211
|
+
index: 19,
|
206
212
|
isWritable: false as boolean,
|
207
213
|
value: input.debtBank ?? null,
|
208
214
|
},
|
209
215
|
positionDebtTa: {
|
210
|
-
index:
|
216
|
+
index: 20,
|
211
217
|
isWritable: true as boolean,
|
212
218
|
value: input.positionDebtTa ?? null,
|
213
219
|
},
|
214
220
|
signerDebtTa: {
|
215
|
-
index:
|
221
|
+
index: 21,
|
216
222
|
isWritable: true as boolean,
|
217
223
|
value: input.signerDebtTa ?? null,
|
218
224
|
},
|
@@ -46,7 +46,7 @@ import {
|
|
46
46
|
getMaxLiqUtilizationRate,
|
47
47
|
uint8ArrayToBigInt,
|
48
48
|
} from "../utils/numberUtils";
|
49
|
-
import {
|
49
|
+
import { eligibleForRebalance } from "../utils/solauto/generalUtils";
|
50
50
|
import { getTokenAccount } from "../utils/accountUtils";
|
51
51
|
import {
|
52
52
|
getLendingAccountBorrowInstructionDataSerializer,
|
@@ -563,7 +563,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
563
563
|
if (
|
564
564
|
client.solautoPositionState?.supply.amountUsed.baseUnit === BigInt(0) ||
|
565
565
|
(targetLiqUtilizationRateBps === undefined &&
|
566
|
-
!
|
566
|
+
!eligibleForRebalance(
|
567
567
|
client.solautoPositionState!,
|
568
568
|
client.livePositionUpdates.settings ??
|
569
569
|
client.solautoPositionData?.position.settingParams!,
|