@haven-fi/solauto-sdk 1.0.52 → 1.0.54
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 +4 -5
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +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.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/utils/solauto/generalUtils.js +21 -17
- 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/utils/generalUtils.ts +0 -1
- package/src/utils/solauto/generalUtils.ts +13 -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 +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,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,GAC7B,OAAO,CAET;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,kBAAkB,EAC9B,oBAAoB,EAAE,MAAM,UAY7B;AAED,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,EACnC,kBAAkB,EAAE,MAAM,GACzB,yBAAyB,CAgB3B;AAED,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,OAAO,EACnB,OAAO,EAAE,OAAO,GACf;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAYA;AAED,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,yBAAyB,EAC3C,WAAW,EAAE,WAAW,GACvB,eAAe,GAAG,SAAS,
|
1
|
+
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"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"}
|
@@ -1,6 +1,19 @@
|
|
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;
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
4
17
|
const umi_1 = require("@metaplex-foundation/umi");
|
5
18
|
const generated_1 = require("../../generated");
|
6
19
|
const generalUtils_1 = require("../generalUtils");
|
@@ -20,11 +33,9 @@ function nextAutomationPeriodTimestamp(automation) {
|
|
20
33
|
: Number(automation.unixStartDate) +
|
21
34
|
automation.periodsPassed * Number(automation.intervalSeconds);
|
22
35
|
}
|
23
|
-
exports.nextAutomationPeriodTimestamp = nextAutomationPeriodTimestamp;
|
24
36
|
function eligibleForNextAutomationPeriod(automation) {
|
25
37
|
return (0, generalUtils_1.currentUnixSeconds)() >= nextAutomationPeriodTimestamp(automation);
|
26
38
|
}
|
27
|
-
exports.eligibleForNextAutomationPeriod = eligibleForNextAutomationPeriod;
|
28
39
|
function getUpdatedValueFromAutomation(currValue, targetValue, automation, currentUnixTimestamp) {
|
29
40
|
const currRateDiff = currValue - targetValue;
|
30
41
|
const progressPct = 1 /
|
@@ -33,7 +44,6 @@ function getUpdatedValueFromAutomation(currValue, targetValue, automation, curre
|
|
33
44
|
const newValue = currValue - currRateDiff * progressPct;
|
34
45
|
return newValue;
|
35
46
|
}
|
36
|
-
exports.getUpdatedValueFromAutomation = getUpdatedValueFromAutomation;
|
37
47
|
function getAdjustedSettingsFromAutomation(settings, currentUnixSeconds) {
|
38
48
|
const boostToBps = settings.automation.targetPeriods > 0 &&
|
39
49
|
eligibleForNextAutomationPeriod(settings.automation)
|
@@ -44,7 +54,6 @@ function getAdjustedSettingsFromAutomation(settings, currentUnixSeconds) {
|
|
44
54
|
boostToBps,
|
45
55
|
};
|
46
56
|
}
|
47
|
-
exports.getAdjustedSettingsFromAutomation = getAdjustedSettingsFromAutomation;
|
48
57
|
function getSolautoFeesBps(isReferred, feeType) {
|
49
58
|
const fees = feeType === generated_1.FeeType.Small ? 100 : 500;
|
50
59
|
let referrer = 0;
|
@@ -57,11 +66,10 @@ function getSolautoFeesBps(isReferred, feeType) {
|
|
57
66
|
total: fees,
|
58
67
|
};
|
59
68
|
}
|
60
|
-
exports.getSolautoFeesBps = getSolautoFeesBps;
|
61
69
|
function eligibleForRebalance(positionState, positionSettings, positionDca) {
|
62
70
|
if (positionDca.automation.targetPeriods > 0 &&
|
63
71
|
eligibleForNextAutomationPeriod(positionDca.automation)) {
|
64
|
-
return
|
72
|
+
return "dca";
|
65
73
|
}
|
66
74
|
if (positionState.supply.amountUsed.baseUnit === BigInt(0)) {
|
67
75
|
return undefined;
|
@@ -73,14 +81,13 @@ function eligibleForRebalance(positionState, positionSettings, positionDca) {
|
|
73
81
|
const repayFrom = positionSettings.repayToBps + positionSettings.repayGap;
|
74
82
|
const boostFrom = boostToBps - positionSettings.boostGap;
|
75
83
|
if (positionState.liqUtilizationRateBps <= boostFrom) {
|
76
|
-
return
|
84
|
+
return "boost";
|
77
85
|
}
|
78
86
|
else if (positionState.liqUtilizationRateBps >= repayFrom) {
|
79
|
-
return
|
87
|
+
return "repay";
|
80
88
|
}
|
81
89
|
return undefined;
|
82
90
|
}
|
83
|
-
exports.eligibleForRebalance = eligibleForRebalance;
|
84
91
|
function eligibleForRefresh(positionState, positionSettings) {
|
85
92
|
if (positionSettings.automation.targetPeriods > 0) {
|
86
93
|
return eligibleForNextAutomationPeriod(positionSettings.automation);
|
@@ -90,7 +97,6 @@ function eligibleForRefresh(positionState, positionSettings) {
|
|
90
97
|
60 * 60 * 24 * 7);
|
91
98
|
}
|
92
99
|
}
|
93
|
-
exports.eligibleForRefresh = eligibleForRefresh;
|
94
100
|
async function getSolautoManagedPositions(umi, authority) {
|
95
101
|
// bump: [u8; 1]
|
96
102
|
// position_id: [u8; 1]
|
@@ -139,7 +145,6 @@ async function getSolautoManagedPositions(umi, authority) {
|
|
139
145
|
};
|
140
146
|
});
|
141
147
|
}
|
142
|
-
exports.getSolautoManagedPositions = getSolautoManagedPositions;
|
143
148
|
async function getAllReferralStates(umi) {
|
144
149
|
const accounts = await umi.rpc.getProgramAccounts(generated_1.SOLAUTO_PROGRAM_ID, {
|
145
150
|
commitment: "finalized",
|
@@ -155,7 +160,6 @@ async function getAllReferralStates(umi) {
|
|
155
160
|
});
|
156
161
|
return accounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
|
157
162
|
}
|
158
|
-
exports.getAllReferralStates = getAllReferralStates;
|
159
163
|
async function getReferralsByUser(umi, user) {
|
160
164
|
// bump: [u8; 1],
|
161
165
|
// padding: [u8; 7],
|
@@ -182,7 +186,6 @@ async function getReferralsByUser(umi, user) {
|
|
182
186
|
});
|
183
187
|
return accounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
|
184
188
|
}
|
185
|
-
exports.getReferralsByUser = getReferralsByUser;
|
186
189
|
async function getAllPositionsByAuthority(umi, user) {
|
187
190
|
const allPositions = [];
|
188
191
|
const solautoManagedPositions = await getSolautoManagedPositions(umi, user);
|
@@ -192,7 +195,10 @@ async function getAllPositionsByAuthority(umi, user) {
|
|
192
195
|
positionId: x.positionId,
|
193
196
|
lendingPlatform: x.lendingPlatform,
|
194
197
|
})));
|
195
|
-
|
198
|
+
let marginfiPositions = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(umi, user, true);
|
199
|
+
marginfiPositions = marginfiPositions.filter((x) => x.supplyMint &&
|
200
|
+
(x.debtMint.equals(web3_js_1.PublicKey.default) ||
|
201
|
+
constants_1.ALL_SUPPORTED_TOKENS.includes(x.debtMint.toString())));
|
196
202
|
allPositions.push(...marginfiPositions.map((x) => ({
|
197
203
|
publicKey: x.marginfiAccount,
|
198
204
|
authority: user,
|
@@ -205,7 +211,6 @@ async function getAllPositionsByAuthority(umi, user) {
|
|
205
211
|
// TODO support other platforms
|
206
212
|
return allPositions;
|
207
213
|
}
|
208
|
-
exports.getAllPositionsByAuthority = getAllPositionsByAuthority;
|
209
214
|
async function positionStateWithLatestPrices(umi, state, protocolAccount, lendingPlatform) {
|
210
215
|
if ((0, generalUtils_1.currentUnixSeconds)() - Number(state.lastUpdated) > 60 * 60 * 24 * 7) {
|
211
216
|
if (lendingPlatform === generated_1.LendingPlatform.Marginfi) {
|
@@ -246,7 +251,6 @@ async function positionStateWithLatestPrices(umi, state, protocolAccount, lendin
|
|
246
251
|
},
|
247
252
|
};
|
248
253
|
}
|
249
|
-
exports.positionStateWithLatestPrices = positionStateWithLatestPrices;
|
250
254
|
class LivePositionUpdates {
|
251
255
|
constructor() {
|
252
256
|
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.54",
|
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
|
},
|
@@ -3,7 +3,6 @@ import { MaybeRpcAccount, publicKey, Umi } from "@metaplex-foundation/umi";
|
|
3
3
|
import { PYTH_PRICE_FEED_IDS } from "../constants/pythConstants";
|
4
4
|
import { fromBaseUnit, toBaseUnit } from "./numberUtils";
|
5
5
|
import { PRICES } from "../constants/solautoConstants";
|
6
|
-
import { ResponseError } from "@jup-ag/api";
|
7
6
|
|
8
7
|
export function generateRandomU8(): number {
|
9
8
|
return Math.floor(Math.random() * 255 + 1);
|
@@ -22,7 +22,7 @@ import {
|
|
22
22
|
} from "../numberUtils";
|
23
23
|
import { getReferralState } from "../accountUtils";
|
24
24
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
25
|
-
import { USD_DECIMALS } from "../../constants";
|
25
|
+
import { ALL_SUPPORTED_TOKENS, USD_DECIMALS } from "../../constants";
|
26
26
|
import {
|
27
27
|
getAllMarginfiAccountsByAuthority,
|
28
28
|
getMarginfiAccountPositionState,
|
@@ -127,7 +127,7 @@ export function eligibleForRebalance(
|
|
127
127
|
positionDca.automation.targetPeriods > 0 &&
|
128
128
|
eligibleForNextAutomationPeriod(positionDca.automation)
|
129
129
|
) {
|
130
|
-
return
|
130
|
+
return "dca";
|
131
131
|
}
|
132
132
|
|
133
133
|
if (positionState.supply.amountUsed.baseUnit === BigInt(0)) {
|
@@ -148,11 +148,9 @@ export function eligibleForRebalance(
|
|
148
148
|
const boostFrom = boostToBps - positionSettings.boostGap;
|
149
149
|
|
150
150
|
if (positionState.liqUtilizationRateBps <= boostFrom) {
|
151
|
-
return
|
152
|
-
} else if (
|
153
|
-
|
154
|
-
) {
|
155
|
-
return 'repay';
|
151
|
+
return "boost";
|
152
|
+
} else if (positionState.liqUtilizationRateBps >= repayFrom) {
|
153
|
+
return "repay";
|
156
154
|
}
|
157
155
|
|
158
156
|
return undefined;
|
@@ -293,11 +291,17 @@ export async function getAllPositionsByAuthority(
|
|
293
291
|
}))
|
294
292
|
);
|
295
293
|
|
296
|
-
|
294
|
+
let marginfiPositions = await getAllMarginfiAccountsByAuthority(
|
297
295
|
umi,
|
298
296
|
user,
|
299
297
|
true
|
300
298
|
);
|
299
|
+
marginfiPositions = marginfiPositions.filter(
|
300
|
+
(x) =>
|
301
|
+
x.supplyMint &&
|
302
|
+
(x.debtMint!.equals(PublicKey.default) ||
|
303
|
+
ALL_SUPPORTED_TOKENS.includes(x.debtMint!.toString()))
|
304
|
+
);
|
301
305
|
allPositions.push(
|
302
306
|
...marginfiPositions.map((x) => ({
|
303
307
|
publicKey: x.marginfiAccount,
|
@@ -327,7 +331,7 @@ export async function positionStateWithLatestPrices(
|
|
327
331
|
umi,
|
328
332
|
protocolAccount,
|
329
333
|
toWeb3JsPublicKey(state.supply.mint),
|
330
|
-
toWeb3JsPublicKey(state.debt.mint)
|
334
|
+
toWeb3JsPublicKey(state.debt.mint)
|
331
335
|
);
|
332
336
|
} else {
|
333
337
|
throw new Error("Lending platorm not yet supported");
|