@kamino-finance/klend-sdk 5.11.6-beta.0 → 5.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/classes/action.d.ts +27 -35
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +198 -344
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/index.d.ts +1 -0
- package/dist/classes/index.d.ts.map +1 -1
- package/dist/classes/index.js +1 -0
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/manager.d.ts +6 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +16 -1
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +3 -3
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +30 -16
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +2 -0
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +5 -0
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/classes/vault.d.ts +1 -0
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +26 -20
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +11 -0
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +6 -3
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +13 -7
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +25 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.js +43 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +13 -0
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +25 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/index.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/types/index.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/index.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +10 -8
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +2 -2
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +11 -6
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +9 -7
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +78 -66
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +4 -4
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/utils/ObligationType.d.ts +1 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/accountListing.d.ts +4 -4
- package/dist/utils/accountListing.d.ts.map +1 -1
- package/dist/utils/accountListing.js +3 -3
- package/dist/utils/accountListing.js.map +1 -1
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +7 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +7 -52
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/oracle.d.ts +3 -3
- package/dist/utils/oracle.d.ts.map +1 -1
- package/dist/utils/oracle.js +4 -3
- package/dist/utils/oracle.js.map +1 -1
- package/package.json +2 -2
- package/src/classes/action.ts +225 -400
- package/src/classes/index.ts +1 -0
- package/src/classes/manager.ts +27 -1
- package/src/classes/market.ts +34 -25
- package/src/classes/obligation.ts +6 -0
- package/src/classes/types.ts +1 -1
- package/src/classes/vault.ts +28 -24
- package/src/client.ts +40 -9
- package/src/client_kamino_manager.ts +15 -0
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +17 -9
- package/src/idl_codegen_kamino_vault/errors/custom.ts +42 -0
- package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/initVault.ts +2 -0
- package/src/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/updateSharesMetadata.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/updateVaultConfig.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/withdrawPendingFees.ts +2 -2
- package/src/idl_codegen_kamino_vault/types/VaultConfigField.ts +30 -0
- package/src/idl_codegen_kamino_vault/types/index.ts +2 -0
- package/src/idl_kamino_vault.json +35 -8
- package/src/lending_operations/repay_with_collateral_operations.ts +15 -11
- package/src/lending_operations/swap_collateral_operations.ts +19 -7
- package/src/leverage/operations.ts +114 -66
- package/src/leverage/types.ts +4 -4
- package/src/utils/ObligationType.ts +1 -1
- package/src/utils/accountListing.ts +11 -7
- package/src/utils/constants.ts +7 -0
- package/src/utils/managerTypes.ts +10 -52
- package/src/utils/oracle.ts +7 -6
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
2
|
import { KaminoMarket, KaminoObligation, KaminoReserve } from '../classes';
|
|
3
|
+
import { ObligationType, ScopePriceRefreshConfig } from '../utils';
|
|
3
4
|
import { StrategyWithAddress } from '@kamino-finance/kliquidity-sdk';
|
|
4
5
|
import { AdjustLeverageInitialInputs, AdjustLeverageIxsResponse, AdjustLeverageProps, AdjustLeverageSwapInputsProps, DepositLeverageInitialInputs, DepositWithLeverageProps, DepositWithLeverageSwapInputsProps, DepositLeverageIxsResponse, SwapInputs, SwapIxs, WithdrawLeverageCalcsResult, WithdrawLeverageInitialInputs, WithdrawLeverageIxsResponse, WithdrawWithLeverageProps, WithdrawWithLeverageSwapInputsProps } from './types';
|
|
5
|
-
export declare function getDepositWithLeverageSwapInputs<QuoteResponse>({ owner, kaminoMarket, debtTokenMint, collTokenMint, depositAmount, priceDebtToColl, slippagePct, obligation, referrer, currentSlot, targetLeverage, selectedTokenMint, kamino, obligationTypeTagOverride,
|
|
6
|
+
export declare function getDepositWithLeverageSwapInputs<QuoteResponse>({ owner, kaminoMarket, debtTokenMint, collTokenMint, depositAmount, priceDebtToColl, slippagePct, obligation, referrer, currentSlot, targetLeverage, selectedTokenMint, kamino, obligationTypeTagOverride, scopeRefreshConfig, budgetAndPriorityFeeIxs, quoteBufferBps, priceAinB, isKtoken, quoter, useV2Ixs, elevationGroupOverride, }: DepositWithLeverageSwapInputsProps<QuoteResponse>): Promise<{
|
|
6
7
|
swapInputs: SwapInputs;
|
|
7
8
|
initialInputs: DepositLeverageInitialInputs<QuoteResponse>;
|
|
8
9
|
}>;
|
|
9
|
-
export declare function getDepositWithLeverageIxns<QuoteResponse>({ owner, kaminoMarket, debtTokenMint, collTokenMint, depositAmount, priceDebtToColl, slippagePct, obligation, referrer, currentSlot, targetLeverage, selectedTokenMint, kamino, obligationTypeTagOverride,
|
|
10
|
-
export declare function getWithdrawWithLeverageSwapInputs<QuoteResponse>({ owner, kaminoMarket, debtTokenMint, collTokenMint, deposited, borrowed, obligation, referrer, currentSlot, withdrawAmount, priceCollToDebt, slippagePct, isClosingPosition, selectedTokenMint, budgetAndPriorityFeeIxs, kamino,
|
|
10
|
+
export declare function getDepositWithLeverageIxns<QuoteResponse>({ owner, kaminoMarket, debtTokenMint, collTokenMint, depositAmount, priceDebtToColl, slippagePct, obligation, referrer, currentSlot, targetLeverage, selectedTokenMint, kamino, obligationTypeTagOverride, scopeRefreshConfig, budgetAndPriorityFeeIxs, quoteBufferBps, priceAinB, isKtoken, quoter, swapper, elevationGroupOverride, useV2Ixs, }: DepositWithLeverageProps<QuoteResponse>): Promise<DepositLeverageIxsResponse<QuoteResponse>>;
|
|
11
|
+
export declare function getWithdrawWithLeverageSwapInputs<QuoteResponse>({ owner, kaminoMarket, debtTokenMint, collTokenMint, deposited, borrowed, obligation, referrer, currentSlot, withdrawAmount, priceCollToDebt, slippagePct, isClosingPosition, selectedTokenMint, budgetAndPriorityFeeIxs, kamino, scopeRefreshConfig, quoteBufferBps, isKtoken, quoter, useV2Ixs, }: WithdrawWithLeverageSwapInputsProps<QuoteResponse>): Promise<{
|
|
11
12
|
swapInputs: SwapInputs;
|
|
12
13
|
initialInputs: WithdrawLeverageInitialInputs<QuoteResponse>;
|
|
13
14
|
}>;
|
|
14
|
-
export declare function getWithdrawWithLeverageIxns<QuoteResponse>({ owner, kaminoMarket, debtTokenMint, collTokenMint, obligation, deposited, borrowed, referrer, currentSlot, withdrawAmount, priceCollToDebt, slippagePct, isClosingPosition, selectedTokenMint, budgetAndPriorityFeeIxs, kamino,
|
|
15
|
-
export declare function buildWithdrawWithLeverageIxns(market: KaminoMarket, debtReserve: KaminoReserve, collReserve: KaminoReserve, owner: PublicKey, obligation: KaminoObligation, referrer: PublicKey, currentSlot: number, isClosingPosition: boolean, depositTokenIsSol: boolean,
|
|
16
|
-
export declare function getAdjustLeverageSwapInputs<QuoteResponse>({ owner, kaminoMarket, debtTokenMint, collTokenMint, obligation, depositedLamports, borrowedLamports, referrer, currentSlot, targetLeverage, priceCollToDebt, priceDebtToColl, slippagePct, budgetAndPriorityFeeIxs, kamino,
|
|
15
|
+
export declare function getWithdrawWithLeverageIxns<QuoteResponse>({ owner, kaminoMarket, debtTokenMint, collTokenMint, obligation, deposited, borrowed, referrer, currentSlot, withdrawAmount, priceCollToDebt, slippagePct, isClosingPosition, selectedTokenMint, budgetAndPriorityFeeIxs, kamino, scopeRefreshConfig, quoteBufferBps, isKtoken, quoter, swapper, useV2Ixs, }: WithdrawWithLeverageProps<QuoteResponse>): Promise<WithdrawLeverageIxsResponse<QuoteResponse>>;
|
|
16
|
+
export declare function buildWithdrawWithLeverageIxns(market: KaminoMarket, debtReserve: KaminoReserve, collReserve: KaminoReserve, owner: PublicKey, obligation: KaminoObligation, referrer: PublicKey, currentSlot: number, isClosingPosition: boolean, depositTokenIsSol: boolean, scopeRefreshConfig: ScopePriceRefreshConfig | undefined, calcs: WithdrawLeverageCalcsResult, budgetAndPriorityFeeIxs: TransactionInstruction[] | undefined, swapQuoteIxs: SwapIxs, strategy: StrategyWithAddress | undefined, collIsKtoken: boolean, useV2Ixs: boolean): Promise<TransactionInstruction[]>;
|
|
17
|
+
export declare function getAdjustLeverageSwapInputs<QuoteResponse>({ owner, kaminoMarket, debtTokenMint, collTokenMint, obligation, depositedLamports, borrowedLamports, referrer, currentSlot, targetLeverage, priceCollToDebt, priceDebtToColl, slippagePct, budgetAndPriorityFeeIxs, kamino, scopeRefreshConfig, quoteBufferBps, isKtoken, quoter, useV2Ixs, }: AdjustLeverageSwapInputsProps<QuoteResponse>): Promise<{
|
|
17
18
|
swapInputs: SwapInputs;
|
|
18
19
|
initialInputs: AdjustLeverageInitialInputs<QuoteResponse>;
|
|
19
20
|
}>;
|
|
20
|
-
export declare function getAdjustLeverageIxns<QuoteResponse>({ owner, kaminoMarket, debtTokenMint, collTokenMint, obligation, depositedLamports, borrowedLamports, referrer, currentSlot, targetLeverage, priceCollToDebt, priceDebtToColl, slippagePct, budgetAndPriorityFeeIxs, kamino,
|
|
21
|
+
export declare function getAdjustLeverageIxns<QuoteResponse>({ owner, kaminoMarket, debtTokenMint, collTokenMint, obligation, depositedLamports, borrowedLamports, referrer, currentSlot, targetLeverage, priceCollToDebt, priceDebtToColl, slippagePct, budgetAndPriorityFeeIxs, kamino, scopeRefreshConfig, quoteBufferBps, priceAinB, isKtoken, quoter, swapper, useV2Ixs, }: AdjustLeverageProps<QuoteResponse>): Promise<AdjustLeverageIxsResponse<QuoteResponse>>;
|
|
22
|
+
export declare const getScopeRefreshIx: (market: KaminoMarket, collReserve: KaminoReserve, debtReserve: KaminoReserve, obligation: KaminoObligation | ObligationType | undefined, scopeRefreshConfig: ScopePriceRefreshConfig | undefined) => Promise<TransactionInstruction[]>;
|
|
21
23
|
//# sourceMappingURL=operations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/leverage/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,SAAS,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEtF,OAAO,EAEL,YAAY,EACZ,gBAAgB,EAChB,aAAa,
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/leverage/operations.ts"],"names":[],"mappings":"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"}
|
|
@@ -3,6 +3,7 @@ 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.getScopeRefreshIx = void 0;
|
|
6
7
|
exports.getDepositWithLeverageSwapInputs = getDepositWithLeverageSwapInputs;
|
|
7
8
|
exports.getDepositWithLeverageIxns = getDepositWithLeverageIxns;
|
|
8
9
|
exports.getWithdrawWithLeverageSwapInputs = getWithdrawWithLeverageSwapInputs;
|
|
@@ -20,7 +21,7 @@ const calcs_1 = require("./calcs");
|
|
|
20
21
|
const spl_token_1 = require("@solana/spl-token");
|
|
21
22
|
const utils_2 = require("./utils");
|
|
22
23
|
const CreationParameters_1 = require("@kamino-finance/kliquidity-sdk/dist/utils/CreationParameters");
|
|
23
|
-
async function getDepositWithLeverageSwapInputs({ owner, kaminoMarket, debtTokenMint, collTokenMint, depositAmount, priceDebtToColl, slippagePct, obligation, referrer, currentSlot, targetLeverage, selectedTokenMint, kamino, obligationTypeTagOverride,
|
|
24
|
+
async function getDepositWithLeverageSwapInputs({ owner, kaminoMarket, debtTokenMint, collTokenMint, depositAmount, priceDebtToColl, slippagePct, obligation, referrer, currentSlot, targetLeverage, selectedTokenMint, kamino, obligationTypeTagOverride, scopeRefreshConfig, budgetAndPriorityFeeIxs, quoteBufferBps, priceAinB, isKtoken, quoter, useV2Ixs, elevationGroupOverride, }) {
|
|
24
25
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
25
26
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
26
27
|
const solTokenReserve = kaminoMarket.getReserveByMint(spl_token_1.NATIVE_MINT);
|
|
@@ -44,7 +45,7 @@ async function getDepositWithLeverageSwapInputs({ owner, kaminoMarket, debtToken
|
|
|
44
45
|
throw Error('Obligation type tag not supported for leverage, please use 1 - multiply or 3 - leverage');
|
|
45
46
|
}
|
|
46
47
|
// Build the repay & withdraw collateral tx to get the number of accounts
|
|
47
|
-
const klendIxs = await buildDepositWithLeverageIxns(kaminoMarket, debtReserve, collReserve, owner, obligation ? obligation : obligationType, referrer, currentSlot, depositTokenIsSol,
|
|
48
|
+
const klendIxs = await buildDepositWithLeverageIxns(kaminoMarket, debtReserve, collReserve, owner, obligation ? obligation : obligationType, referrer, currentSlot, depositTokenIsSol, scopeRefreshConfig, calcs, budgetAndPriorityFeeIxs, {
|
|
48
49
|
preActionIxs: [],
|
|
49
50
|
swapIxs: [],
|
|
50
51
|
lookupTables: [],
|
|
@@ -122,7 +123,7 @@ async function getDepositWithLeverageCalcs(depositAmount, selectedTokenIsCollTok
|
|
|
122
123
|
}
|
|
123
124
|
return calcs;
|
|
124
125
|
}
|
|
125
|
-
async function getDepositWithLeverageIxns({ owner, kaminoMarket, debtTokenMint, collTokenMint, depositAmount, priceDebtToColl, slippagePct, obligation, referrer, currentSlot, targetLeverage, selectedTokenMint, kamino, obligationTypeTagOverride,
|
|
126
|
+
async function getDepositWithLeverageIxns({ owner, kaminoMarket, debtTokenMint, collTokenMint, depositAmount, priceDebtToColl, slippagePct, obligation, referrer, currentSlot, targetLeverage, selectedTokenMint, kamino, obligationTypeTagOverride, scopeRefreshConfig, budgetAndPriorityFeeIxs, quoteBufferBps, priceAinB, isKtoken, quoter, swapper, elevationGroupOverride, useV2Ixs, }) {
|
|
126
127
|
const { swapInputs, initialInputs } = await getDepositWithLeverageSwapInputs({
|
|
127
128
|
owner,
|
|
128
129
|
kaminoMarket,
|
|
@@ -138,7 +139,7 @@ async function getDepositWithLeverageIxns({ owner, kaminoMarket, debtTokenMint,
|
|
|
138
139
|
selectedTokenMint,
|
|
139
140
|
kamino,
|
|
140
141
|
obligationTypeTagOverride,
|
|
141
|
-
|
|
142
|
+
scopeRefreshConfig,
|
|
142
143
|
budgetAndPriorityFeeIxs,
|
|
143
144
|
quoteBufferBps,
|
|
144
145
|
priceAinB,
|
|
@@ -170,7 +171,7 @@ async function getDepositWithLeverageIxns({ owner, kaminoMarket, debtTokenMint,
|
|
|
170
171
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
171
172
|
const solTokenReserve = kaminoMarket.getReserveByMint(spl_token_1.NATIVE_MINT);
|
|
172
173
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint.equals(solTokenReserve.getLiquidityMint());
|
|
173
|
-
const ixs = await buildDepositWithLeverageIxns(kaminoMarket, debtReserve, collReserve, owner, initialInputs.obligation, referrer, currentSlot, depositTokenIsSol,
|
|
174
|
+
const ixs = await buildDepositWithLeverageIxns(kaminoMarket, debtReserve, collReserve, owner, initialInputs.obligation, referrer, currentSlot, depositTokenIsSol, scopeRefreshConfig, initialInputs.calcs, budgetAndPriorityFeeIxs, {
|
|
174
175
|
preActionIxs: [],
|
|
175
176
|
swapIxs: swapIxs,
|
|
176
177
|
lookupTables: lookupTables,
|
|
@@ -182,13 +183,13 @@ async function getDepositWithLeverageIxns({ owner, kaminoMarket, debtTokenMint,
|
|
|
182
183
|
initialInputs,
|
|
183
184
|
};
|
|
184
185
|
}
|
|
185
|
-
async function buildDepositWithLeverageIxns(market, debtReserve, collReserve, owner, obligation, referrer, currentSlot, depositTokenIsSol,
|
|
186
|
+
async function buildDepositWithLeverageIxns(market, debtReserve, collReserve, owner, obligation, referrer, currentSlot, depositTokenIsSol, scopeRefreshConfig, calcs, budgetAndPriorityFeeIxs, swapQuoteIxs, strategy, collIsKtoken, useV2Ixs, elevationGroupOverride) {
|
|
186
187
|
const budgetIxns = budgetAndPriorityFeeIxs || (0, utils_1.getComputeBudgetAndPriorityFeeIxns)(3000000);
|
|
187
188
|
const collTokenMint = collReserve.getLiquidityMint();
|
|
188
189
|
const debtTokenMint = debtReserve.getLiquidityMint();
|
|
189
190
|
const collTokenAta = (0, spl_token_1.getAssociatedTokenAddressSync)(collTokenMint, owner, false, collReserve.getLiquidityTokenProgram());
|
|
190
191
|
const debtTokenAta = (0, spl_token_1.getAssociatedTokenAddressSync)(debtTokenMint, owner, false, debtReserve.getLiquidityTokenProgram());
|
|
191
|
-
// 1. Create atas & budget
|
|
192
|
+
// 1. Create atas & budget ixns
|
|
192
193
|
let mintsToCreateAtas;
|
|
193
194
|
if (collIsKtoken) {
|
|
194
195
|
const secondTokenAta = strategy.strategy.tokenAMint.equals(debtTokenMint)
|
|
@@ -241,10 +242,11 @@ async function buildDepositWithLeverageIxns(market, debtReserve, collReserve, ow
|
|
|
241
242
|
if (depositTokenIsSol) {
|
|
242
243
|
fillWsolAtaIxns.push(...(0, utils_1.getTransferWsolIxns)(owner, (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, owner), (0, classes_2.numberToLamportsDecimal)(calcs.initDepositInSol, utils_1.SOL_DECIMALS).ceil()));
|
|
243
244
|
}
|
|
245
|
+
const scopeRefreshIxn = await (0, exports.getScopeRefreshIx)(market, collReserve, debtReserve, obligation, scopeRefreshConfig);
|
|
244
246
|
// 2. Flash borrow & repay the collateral amount needed for given leverage
|
|
245
247
|
// if user deposits coll, then we borrow the diff, else we borrow the entire amount
|
|
246
248
|
const { flashBorrowIxn, flashRepayIxn } = (0, instructions_1.getFlashLoanInstructions)({
|
|
247
|
-
borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length + fillWsolAtaIxns.length,
|
|
249
|
+
borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length + fillWsolAtaIxns.length + (scopeRefreshIxn.length > 0 ? 1 : 0),
|
|
248
250
|
walletPublicKey: owner,
|
|
249
251
|
lendingMarketAuthority: market.getLendingMarketAuthority(),
|
|
250
252
|
lendingMarketAddress: market.getAddress(),
|
|
@@ -257,33 +259,32 @@ async function buildDepositWithLeverageIxns(market, debtReserve, collReserve, ow
|
|
|
257
259
|
programId: market.programId,
|
|
258
260
|
});
|
|
259
261
|
// 3. Deposit initial tokens + borrowed tokens into reserve
|
|
260
|
-
const scopeRefresh = scopeFeed ? { includeScopeRefresh: true, scopeFeed: scopeFeed } : undefined;
|
|
261
262
|
const kaminoDepositAndBorrowAction = await classes_1.KaminoAction.buildDepositAndBorrowTxns(market, (0, classes_2.numberToLamportsDecimal)(!collIsKtoken ? calcs.collTokenToDeposit : calcs.collTokenToDeposit, collReserve.stats.decimals)
|
|
262
263
|
.floor()
|
|
263
264
|
.toString(), collTokenMint, (0, classes_2.numberToLamportsDecimal)(!collIsKtoken ? calcs.debtTokenToBorrow : calcs.debtTokenToBorrow, debtReserve.stats.decimals)
|
|
264
265
|
.ceil()
|
|
265
|
-
.toString(), debtTokenMint, owner, obligation, useV2Ixs, 0, false, elevationGroupOverride === 0 ? false : true, // emode
|
|
266
|
+
.toString(), debtTokenMint, owner, obligation, useV2Ixs, undefined, 0, false, elevationGroupOverride === 0 ? false : true, // emode
|
|
266
267
|
false, // to be checked and created in a setup tx in the UI
|
|
267
268
|
false, // to be checked and created in a setup tx in the UI
|
|
268
|
-
referrer, currentSlot
|
|
269
|
+
referrer, currentSlot);
|
|
269
270
|
// 4. Swap
|
|
270
271
|
const { swapIxs } = swapQuoteIxs;
|
|
271
272
|
const swapInstructions = (0, utils_1.removeBudgetAndAtaIxns)(swapIxs, []);
|
|
272
273
|
if (!collIsKtoken) {
|
|
273
274
|
return [
|
|
275
|
+
...scopeRefreshIxn,
|
|
274
276
|
...budgetIxns,
|
|
275
277
|
...atasAndCreateIxns.map((x) => x.createAtaIx),
|
|
276
278
|
...fillWsolAtaIxns,
|
|
277
279
|
...[flashBorrowIxn],
|
|
278
|
-
...kaminoDepositAndBorrowAction
|
|
279
|
-
...classes_1.KaminoAction.actionToLendingIxs(kaminoDepositAndBorrowAction),
|
|
280
|
-
...kaminoDepositAndBorrowAction.cleanupIxs,
|
|
280
|
+
...classes_1.KaminoAction.actionToIxs(kaminoDepositAndBorrowAction),
|
|
281
281
|
...swapInstructions,
|
|
282
282
|
...[flashRepayIxn],
|
|
283
283
|
];
|
|
284
284
|
}
|
|
285
285
|
else {
|
|
286
286
|
return [
|
|
287
|
+
...scopeRefreshIxn,
|
|
287
288
|
...budgetIxns,
|
|
288
289
|
...atasAndCreateIxns.map((x) => x.createAtaIx),
|
|
289
290
|
...fillWsolAtaIxns,
|
|
@@ -296,7 +297,7 @@ async function buildDepositWithLeverageIxns(market, debtReserve, collReserve, ow
|
|
|
296
297
|
];
|
|
297
298
|
}
|
|
298
299
|
}
|
|
299
|
-
async function getWithdrawWithLeverageSwapInputs({ owner, kaminoMarket, debtTokenMint, collTokenMint, deposited, borrowed, obligation, referrer, currentSlot, withdrawAmount, priceCollToDebt, slippagePct, isClosingPosition, selectedTokenMint, budgetAndPriorityFeeIxs, kamino,
|
|
300
|
+
async function getWithdrawWithLeverageSwapInputs({ owner, kaminoMarket, debtTokenMint, collTokenMint, deposited, borrowed, obligation, referrer, currentSlot, withdrawAmount, priceCollToDebt, slippagePct, isClosingPosition, selectedTokenMint, budgetAndPriorityFeeIxs, kamino, scopeRefreshConfig, quoteBufferBps, isKtoken, quoter, useV2Ixs, }) {
|
|
300
301
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
301
302
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
302
303
|
const flashLoanFee = debtReserve.getFlashLoanFee() || new decimal_js_1.default(0);
|
|
@@ -306,7 +307,7 @@ async function getWithdrawWithLeverageSwapInputs({ owner, kaminoMarket, debtToke
|
|
|
306
307
|
const solTokenReserve = kaminoMarket.getReserveByMint(spl_token_1.NATIVE_MINT);
|
|
307
308
|
const depositTokenIsSol = !solTokenReserve ? false : selectedTokenMint.equals(solTokenReserve.getLiquidityMint());
|
|
308
309
|
const calcs = (0, calcs_1.withdrawLeverageCalcs)(kaminoMarket, collReserve, debtReserve, priceCollToDebt, withdrawAmount, deposited, borrowed, currentSlot, isClosingPosition, selectedTokenIsCollToken, selectedTokenMint, obligation, flashLoanFee, slippagePct);
|
|
309
|
-
const klendIxs = await buildWithdrawWithLeverageIxns(kaminoMarket, debtReserve, collReserve, owner, obligation, referrer, currentSlot, isClosingPosition, depositTokenIsSol,
|
|
310
|
+
const klendIxs = await buildWithdrawWithLeverageIxns(kaminoMarket, debtReserve, collReserve, owner, obligation, referrer, currentSlot, isClosingPosition, depositTokenIsSol, scopeRefreshConfig, calcs, budgetAndPriorityFeeIxs, {
|
|
310
311
|
preActionIxs: [],
|
|
311
312
|
swapIxs: [],
|
|
312
313
|
lookupTables: [],
|
|
@@ -341,7 +342,7 @@ async function getWithdrawWithLeverageSwapInputs({ owner, kaminoMarket, debtToke
|
|
|
341
342
|
},
|
|
342
343
|
};
|
|
343
344
|
}
|
|
344
|
-
async function getWithdrawWithLeverageIxns({ owner, kaminoMarket, debtTokenMint, collTokenMint, obligation, deposited, borrowed, referrer, currentSlot, withdrawAmount, priceCollToDebt, slippagePct, isClosingPosition, selectedTokenMint, budgetAndPriorityFeeIxs, kamino,
|
|
345
|
+
async function getWithdrawWithLeverageIxns({ owner, kaminoMarket, debtTokenMint, collTokenMint, obligation, deposited, borrowed, referrer, currentSlot, withdrawAmount, priceCollToDebt, slippagePct, isClosingPosition, selectedTokenMint, budgetAndPriorityFeeIxs, kamino, scopeRefreshConfig, quoteBufferBps, isKtoken, quoter, swapper, useV2Ixs, }) {
|
|
345
346
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
346
347
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
347
348
|
const solTokenReserve = kaminoMarket.getReserveByMint(spl_token_1.NATIVE_MINT);
|
|
@@ -363,7 +364,7 @@ async function getWithdrawWithLeverageIxns({ owner, kaminoMarket, debtTokenMint,
|
|
|
363
364
|
selectedTokenMint,
|
|
364
365
|
budgetAndPriorityFeeIxs,
|
|
365
366
|
kamino,
|
|
366
|
-
|
|
367
|
+
scopeRefreshConfig,
|
|
367
368
|
quoteBufferBps,
|
|
368
369
|
isKtoken,
|
|
369
370
|
quoter,
|
|
@@ -389,7 +390,7 @@ async function getWithdrawWithLeverageIxns({ owner, kaminoMarket, debtTokenMint,
|
|
|
389
390
|
console.log('Strategy lookup table not found');
|
|
390
391
|
}
|
|
391
392
|
}
|
|
392
|
-
const ixs = await buildWithdrawWithLeverageIxns(kaminoMarket, debtReserve, collReserve, owner, obligation, referrer, currentSlot, isClosingPosition, depositTokenIsSol,
|
|
393
|
+
const ixs = await buildWithdrawWithLeverageIxns(kaminoMarket, debtReserve, collReserve, owner, obligation, referrer, currentSlot, isClosingPosition, depositTokenIsSol, scopeRefreshConfig, initialInputs.calcs, budgetAndPriorityFeeIxs, {
|
|
393
394
|
preActionIxs: [],
|
|
394
395
|
swapIxs,
|
|
395
396
|
lookupTables,
|
|
@@ -402,7 +403,7 @@ async function getWithdrawWithLeverageIxns({ owner, kaminoMarket, debtTokenMint,
|
|
|
402
403
|
initialInputs: initialInputs,
|
|
403
404
|
};
|
|
404
405
|
}
|
|
405
|
-
async function buildWithdrawWithLeverageIxns(market, debtReserve, collReserve, owner, obligation, referrer, currentSlot, isClosingPosition, depositTokenIsSol,
|
|
406
|
+
async function buildWithdrawWithLeverageIxns(market, debtReserve, collReserve, owner, obligation, referrer, currentSlot, isClosingPosition, depositTokenIsSol, scopeRefreshConfig, calcs, budgetAndPriorityFeeIxs, swapQuoteIxs, strategy, collIsKtoken, useV2Ixs) {
|
|
406
407
|
const collTokenMint = collReserve.getLiquidityMint();
|
|
407
408
|
const debtTokenMint = debtReserve.getLiquidityMint();
|
|
408
409
|
const debtTokenAta = (0, spl_token_1.getAssociatedTokenAddressSync)(debtTokenMint, owner, false, debtReserve.getLiquidityTokenProgram());
|
|
@@ -461,7 +462,7 @@ async function buildWithdrawWithLeverageIxns(market, debtReserve, collReserve, o
|
|
|
461
462
|
closeWsolAtaIxns.push((0, spl_token_1.createCloseAccountInstruction)(wsolAta, owner, owner, [], spl_token_1.TOKEN_PROGRAM_ID));
|
|
462
463
|
}
|
|
463
464
|
const budgetIxns = budgetAndPriorityFeeIxs || (0, utils_1.getComputeBudgetAndPriorityFeeIxns)(3000000);
|
|
464
|
-
// TODO:
|
|
465
|
+
// TODO: Mihai/Marius check if we can improve this logic and not convert any SOL
|
|
465
466
|
// This is here so that we have enough wsol to repay in case the kAB swapped to sol after estimates is not enough
|
|
466
467
|
const fillWsolAtaIxns = [];
|
|
467
468
|
if (debtTokenMint.equals(spl_token_1.NATIVE_MINT)) {
|
|
@@ -469,11 +470,12 @@ async function buildWithdrawWithLeverageIxns(market, debtReserve, collReserve, o
|
|
|
469
470
|
const balanceToWrap = halfSolBalance < 0.1 ? halfSolBalance : 0.1;
|
|
470
471
|
fillWsolAtaIxns.push(...(0, utils_1.getTransferWsolIxns)(owner, (0, spl_token_1.getAssociatedTokenAddressSync)(spl_token_1.NATIVE_MINT, owner), (0, classes_2.numberToLamportsDecimal)(balanceToWrap, utils_1.SOL_DECIMALS).ceil()));
|
|
471
472
|
}
|
|
473
|
+
const scopeRefreshIxn = await (0, exports.getScopeRefreshIx)(market, collReserve, debtReserve, obligation, scopeRefreshConfig);
|
|
472
474
|
// 2. Prepare the flash borrow and flash repay amounts and ixns
|
|
473
475
|
// We borrow exactly how much we need to repay
|
|
474
476
|
// and repay that + flash amount fee
|
|
475
477
|
const { flashBorrowIxn, flashRepayIxn } = (0, instructions_1.getFlashLoanInstructions)({
|
|
476
|
-
borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length + fillWsolAtaIxns.length,
|
|
478
|
+
borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length + fillWsolAtaIxns.length + (scopeRefreshIxn.length > 0 ? 1 : 0),
|
|
477
479
|
walletPublicKey: owner,
|
|
478
480
|
lendingMarketAuthority: market.getLendingMarketAuthority(),
|
|
479
481
|
lendingMarketAddress: market.getAddress(),
|
|
@@ -485,27 +487,26 @@ async function buildWithdrawWithLeverageIxns(market, debtReserve, collReserve, o
|
|
|
485
487
|
referrerTokenState: market.programId,
|
|
486
488
|
programId: market.programId,
|
|
487
489
|
});
|
|
488
|
-
//
|
|
490
|
+
// 3. Repay borrowed tokens and Withdraw tokens from reserve that will be swapped to repay flash loan
|
|
489
491
|
const repayAndWithdrawAction = await classes_1.KaminoAction.buildRepayAndWithdrawTxns(market, isClosingPosition ? utils_1.U64_MAX : (0, classes_2.numberToLamportsDecimal)(calcs.repayAmount, debtReserve.stats.decimals).floor().toString(), debtTokenMint, isClosingPosition
|
|
490
492
|
? utils_1.U64_MAX
|
|
491
|
-
: (0, classes_2.numberToLamportsDecimal)(calcs.depositTokenWithdrawAmount, collReserve.stats.decimals).ceil().toString(), collTokenMint, owner, currentSlot, obligation, useV2Ixs, 0, false, false, // to be checked and created in a setup tx in the UI (won't be the case for withdraw anyway as this would be created in deposit)
|
|
493
|
+
: (0, classes_2.numberToLamportsDecimal)(calcs.depositTokenWithdrawAmount, collReserve.stats.decimals).ceil().toString(), collTokenMint, owner, currentSlot, obligation, useV2Ixs, undefined, 0, false, false, // to be checked and created in a setup tx in the UI (won't be the case for withdraw anyway as this would be created in deposit)
|
|
492
494
|
false, // to be checked and created in a setup tx in the UI (won't be the case for withdraw anyway as this would be created in deposit)
|
|
493
|
-
isClosingPosition, referrer
|
|
495
|
+
isClosingPosition, referrer);
|
|
494
496
|
const swapInstructions = (0, utils_1.removeBudgetAndAtaIxns)(swapQuoteIxs.swapIxs, []);
|
|
495
497
|
return [
|
|
498
|
+
...scopeRefreshIxn,
|
|
496
499
|
...budgetIxns,
|
|
497
500
|
...atasAndCreateIxns.map((x) => x.createAtaIx),
|
|
498
501
|
...fillWsolAtaIxns,
|
|
499
502
|
...[flashBorrowIxn],
|
|
500
|
-
...repayAndWithdrawAction
|
|
501
|
-
...classes_1.KaminoAction.actionToLendingIxs(repayAndWithdrawAction),
|
|
502
|
-
...repayAndWithdrawAction.cleanupIxs,
|
|
503
|
+
...classes_1.KaminoAction.actionToIxs(repayAndWithdrawAction),
|
|
503
504
|
...swapInstructions,
|
|
504
505
|
...[flashRepayIxn],
|
|
505
506
|
...closeWsolAtaIxns,
|
|
506
507
|
];
|
|
507
508
|
}
|
|
508
|
-
async function getAdjustLeverageSwapInputs({ owner, kaminoMarket, debtTokenMint, collTokenMint, obligation, depositedLamports, borrowedLamports, referrer, currentSlot, targetLeverage, priceCollToDebt, priceDebtToColl, slippagePct, budgetAndPriorityFeeIxs, kamino,
|
|
509
|
+
async function getAdjustLeverageSwapInputs({ owner, kaminoMarket, debtTokenMint, collTokenMint, obligation, depositedLamports, borrowedLamports, referrer, currentSlot, targetLeverage, priceCollToDebt, priceDebtToColl, slippagePct, budgetAndPriorityFeeIxs, kamino, scopeRefreshConfig, quoteBufferBps, isKtoken, quoter, useV2Ixs, }) {
|
|
509
510
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
510
511
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
511
512
|
const deposited = (0, classes_1.lamportsToNumberDecimal)(depositedLamports, collReserve.stats.decimals);
|
|
@@ -536,7 +537,7 @@ async function getAdjustLeverageSwapInputs({ owner, kaminoMarket, debtTokenMint,
|
|
|
536
537
|
if (isDeposit) {
|
|
537
538
|
const calcs = await (0, calcs_1.adjustDepositLeverageCalcs)(kaminoMarket, owner, debtReserve, adjustDepositPosition, adjustBorrowPosition, priceDebtToColl, flashLoanFee, slippagePct, collIsKtoken);
|
|
538
539
|
// Build the repay & withdraw collateral tx to get the number of accounts
|
|
539
|
-
const klendIxs = await buildIncreaseLeverageIxns(owner, kaminoMarket, collTokenMint, debtTokenMint, obligation, referrer, currentSlot, calcs, strategy,
|
|
540
|
+
const klendIxs = await buildIncreaseLeverageIxns(owner, kaminoMarket, collTokenMint, debtTokenMint, obligation, referrer, currentSlot, calcs, strategy, scopeRefreshConfig, collIsKtoken, {
|
|
540
541
|
preActionIxs: [],
|
|
541
542
|
swapIxs: [],
|
|
542
543
|
lookupTables: [],
|
|
@@ -585,7 +586,7 @@ async function getAdjustLeverageSwapInputs({ owner, kaminoMarket, debtTokenMint,
|
|
|
585
586
|
}
|
|
586
587
|
else {
|
|
587
588
|
const calcs = (0, calcs_1.adjustWithdrawLeverageCalcs)(adjustDepositPosition, adjustBorrowPosition, flashLoanFee, slippagePct);
|
|
588
|
-
const klendIxs = await buildDecreaseLeverageIxns(owner, kaminoMarket, collTokenMint, debtTokenMint, obligation, referrer, currentSlot, calcs, strategy,
|
|
589
|
+
const klendIxs = await buildDecreaseLeverageIxns(owner, kaminoMarket, collTokenMint, debtTokenMint, obligation, referrer, currentSlot, calcs, strategy, scopeRefreshConfig, collIsKtoken, {
|
|
589
590
|
preActionIxs: [],
|
|
590
591
|
swapIxs: [],
|
|
591
592
|
lookupTables: [],
|
|
@@ -629,7 +630,7 @@ async function getAdjustLeverageSwapInputs({ owner, kaminoMarket, debtTokenMint,
|
|
|
629
630
|
};
|
|
630
631
|
}
|
|
631
632
|
}
|
|
632
|
-
async function getAdjustLeverageIxns({ owner, kaminoMarket, debtTokenMint, collTokenMint, obligation, depositedLamports, borrowedLamports, referrer, currentSlot, targetLeverage, priceCollToDebt, priceDebtToColl, slippagePct, budgetAndPriorityFeeIxs, kamino,
|
|
633
|
+
async function getAdjustLeverageIxns({ owner, kaminoMarket, debtTokenMint, collTokenMint, obligation, depositedLamports, borrowedLamports, referrer, currentSlot, targetLeverage, priceCollToDebt, priceDebtToColl, slippagePct, budgetAndPriorityFeeIxs, kamino, scopeRefreshConfig, quoteBufferBps, priceAinB, isKtoken, quoter, swapper, useV2Ixs, }) {
|
|
633
634
|
const { swapInputs, initialInputs } = await getAdjustLeverageSwapInputs({
|
|
634
635
|
owner,
|
|
635
636
|
kaminoMarket,
|
|
@@ -646,7 +647,7 @@ async function getAdjustLeverageIxns({ owner, kaminoMarket, debtTokenMint, collT
|
|
|
646
647
|
slippagePct,
|
|
647
648
|
budgetAndPriorityFeeIxs,
|
|
648
649
|
kamino,
|
|
649
|
-
|
|
650
|
+
scopeRefreshConfig,
|
|
650
651
|
quoteBufferBps,
|
|
651
652
|
priceAinB,
|
|
652
653
|
isKtoken,
|
|
@@ -667,7 +668,7 @@ async function getAdjustLeverageIxns({ owner, kaminoMarket, debtTokenMint, collT
|
|
|
667
668
|
}
|
|
668
669
|
const { swapIxs, lookupTables } = await depositSwapper(swapInputs, initialInputs.klendAccounts, initialInputs.swapQuote);
|
|
669
670
|
// TODO: marius why are we not using both adjustDepositPosition & adjustBorrowPosition
|
|
670
|
-
const ixs = await buildIncreaseLeverageIxns(owner, kaminoMarket, collTokenMint, debtTokenMint, obligation, referrer, currentSlot, initialInputs.calcs, initialInputs.strategy,
|
|
671
|
+
const ixs = await buildIncreaseLeverageIxns(owner, kaminoMarket, collTokenMint, debtTokenMint, obligation, referrer, currentSlot, initialInputs.calcs, initialInputs.strategy, scopeRefreshConfig, initialInputs.collIsKtoken, {
|
|
671
672
|
preActionIxs: [],
|
|
672
673
|
swapIxs,
|
|
673
674
|
lookupTables,
|
|
@@ -693,7 +694,7 @@ async function getAdjustLeverageIxns({ owner, kaminoMarket, debtTokenMint, collT
|
|
|
693
694
|
}
|
|
694
695
|
// 5. Get swap ixns
|
|
695
696
|
const { swapIxs, lookupTables } = await withdrawSwapper(swapInputs, initialInputs.klendAccounts, initialInputs.swapQuote);
|
|
696
|
-
const ixs = await buildDecreaseLeverageIxns(owner, kaminoMarket, collTokenMint, debtTokenMint, obligation, referrer, currentSlot, initialInputs.calcs, initialInputs.strategy,
|
|
697
|
+
const ixs = await buildDecreaseLeverageIxns(owner, kaminoMarket, collTokenMint, debtTokenMint, obligation, referrer, currentSlot, initialInputs.calcs, initialInputs.strategy, scopeRefreshConfig, initialInputs.collIsKtoken, {
|
|
697
698
|
preActionIxs: [],
|
|
698
699
|
swapIxs,
|
|
699
700
|
lookupTables,
|
|
@@ -709,7 +710,7 @@ async function getAdjustLeverageIxns({ owner, kaminoMarket, debtTokenMint, collT
|
|
|
709
710
|
/**
|
|
710
711
|
* Deposit and borrow tokens if leverage increased
|
|
711
712
|
*/
|
|
712
|
-
async function buildIncreaseLeverageIxns(owner, kaminoMarket, collTokenMint, debtTokenMint, obligation, referrer, currentSlot, calcs, strategy,
|
|
713
|
+
async function buildIncreaseLeverageIxns(owner, kaminoMarket, collTokenMint, debtTokenMint, obligation, referrer, currentSlot, calcs, strategy, scopeRefreshConfig, collIsKtoken, swapQuoteIxs, budgetAndPriorityFeeIxns, useV2Ixs) {
|
|
713
714
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
714
715
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
715
716
|
const debtTokenAta = (0, spl_token_1.getAssociatedTokenAddressSync)(debtTokenMint, owner, false, debtReserve.getLiquidityTokenProgram());
|
|
@@ -764,9 +765,10 @@ async function buildIncreaseLeverageIxns(owner, kaminoMarket, collTokenMint, deb
|
|
|
764
765
|
];
|
|
765
766
|
}
|
|
766
767
|
const atasAndCreateIxns = (0, utils_1.createAtasIdempotent)(owner, mintsToCreateAtas);
|
|
768
|
+
const scopeRefreshIxn = await (0, exports.getScopeRefreshIx)(kaminoMarket, collReserve, debtReserve, obligation, scopeRefreshConfig);
|
|
767
769
|
// 2. Create borrow flash loan instruction
|
|
768
770
|
const { flashBorrowIxn, flashRepayIxn } = (0, instructions_1.getFlashLoanInstructions)({
|
|
769
|
-
borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length, // TODO: how about user metadata ixns
|
|
771
|
+
borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length + (scopeRefreshIxn.length > 0 ? 1 : 0), // TODO: how about user metadata ixns
|
|
770
772
|
walletPublicKey: owner,
|
|
771
773
|
lendingMarketAuthority: kaminoMarket.getLendingMarketAuthority(),
|
|
772
774
|
lendingMarketAddress: kaminoMarket.getAddress(),
|
|
@@ -778,39 +780,33 @@ async function buildIncreaseLeverageIxns(owner, kaminoMarket, collTokenMint, deb
|
|
|
778
780
|
referrerTokenState: kaminoMarket.programId,
|
|
779
781
|
programId: kaminoMarket.programId,
|
|
780
782
|
});
|
|
781
|
-
const depositAction = await classes_1.KaminoAction.buildDepositTxns(kaminoMarket, (0, classes_2.numberToLamportsDecimal)(calcs.adjustDepositPosition, collReserve.stats.decimals).floor().toString(), collTokenMint, owner, obligation, useV2Ixs, 0, false, false, false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
783
|
+
const depositAction = await classes_1.KaminoAction.buildDepositTxns(kaminoMarket, (0, classes_2.numberToLamportsDecimal)(calcs.adjustDepositPosition, collReserve.stats.decimals).floor().toString(), collTokenMint, owner, obligation, useV2Ixs, undefined, 0, false, false, false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
782
784
|
false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
783
|
-
referrer, currentSlot
|
|
785
|
+
referrer, currentSlot);
|
|
784
786
|
// 4. Borrow tokens in borrow token reserve that will be swapped to repay flash loan
|
|
785
|
-
const borrowAction = await classes_1.KaminoAction.buildBorrowTxns(kaminoMarket, (0, classes_2.numberToLamportsDecimal)(calcs.borrowAmount, debtReserve.stats.decimals).ceil().toString(), debtTokenMint, owner, obligation, useV2Ixs, 0, false, false, false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
787
|
+
const borrowAction = await classes_1.KaminoAction.buildBorrowTxns(kaminoMarket, (0, classes_2.numberToLamportsDecimal)(calcs.borrowAmount, debtReserve.stats.decimals).ceil().toString(), debtTokenMint, owner, obligation, useV2Ixs, undefined, 0, false, false, false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
786
788
|
false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
787
|
-
referrer, currentSlot
|
|
789
|
+
referrer, currentSlot);
|
|
788
790
|
const swapInstructions = (0, utils_1.removeBudgetAndAtaIxns)(swapQuoteIxs.swapIxs, []);
|
|
789
791
|
const ixs = !collIsKtoken
|
|
790
792
|
? [
|
|
793
|
+
...scopeRefreshIxn,
|
|
791
794
|
...budgetIxns,
|
|
792
795
|
...atasAndCreateIxns.map((x) => x.createAtaIx),
|
|
793
796
|
...[flashBorrowIxn],
|
|
794
|
-
...depositAction
|
|
795
|
-
...
|
|
796
|
-
...depositAction.cleanupIxs,
|
|
797
|
-
...borrowAction.setupIxs,
|
|
798
|
-
...borrowAction.lendingIxs,
|
|
799
|
-
...borrowAction.cleanupIxs,
|
|
797
|
+
...classes_1.KaminoAction.actionToIxs(depositAction),
|
|
798
|
+
...classes_1.KaminoAction.actionToIxs(borrowAction),
|
|
800
799
|
...swapInstructions,
|
|
801
800
|
...[flashRepayIxn],
|
|
802
801
|
]
|
|
803
802
|
: [
|
|
803
|
+
...scopeRefreshIxn,
|
|
804
804
|
...budgetIxns,
|
|
805
805
|
...atasAndCreateIxns.map((x) => x.createAtaIx),
|
|
806
806
|
...[flashBorrowIxn],
|
|
807
807
|
...swapInstructions,
|
|
808
|
-
...depositAction
|
|
809
|
-
...
|
|
810
|
-
...depositAction.cleanupIxs,
|
|
811
|
-
...borrowAction.setupIxs,
|
|
812
|
-
...borrowAction.lendingIxs,
|
|
813
|
-
...borrowAction.cleanupIxs,
|
|
808
|
+
...classes_1.KaminoAction.actionToIxs(depositAction),
|
|
809
|
+
...classes_1.KaminoAction.actionToIxs(borrowAction),
|
|
814
810
|
...[flashRepayIxn],
|
|
815
811
|
];
|
|
816
812
|
return ixs;
|
|
@@ -818,7 +814,7 @@ async function buildIncreaseLeverageIxns(owner, kaminoMarket, collTokenMint, deb
|
|
|
818
814
|
/**
|
|
819
815
|
* Withdraw and repay tokens if leverage decreased
|
|
820
816
|
*/
|
|
821
|
-
async function buildDecreaseLeverageIxns(owner, kaminoMarket, collTokenMint, debtTokenMint, obligation, referrer, currentSlot, calcs, strategy,
|
|
817
|
+
async function buildDecreaseLeverageIxns(owner, kaminoMarket, collTokenMint, debtTokenMint, obligation, referrer, currentSlot, calcs, strategy, scopeRefreshConfig, collIsKtoken, swapQuoteIxs, budgetAndPriorityFeeIxns, useV2Ixs) {
|
|
822
818
|
const collReserve = kaminoMarket.getReserveByMint(collTokenMint);
|
|
823
819
|
const debtReserve = kaminoMarket.getReserveByMint(debtTokenMint);
|
|
824
820
|
const debtTokenAta = (0, spl_token_1.getAssociatedTokenAddressSync)(debtTokenMint, owner, false, debtReserve.getLiquidityTokenProgram());
|
|
@@ -883,9 +879,10 @@ async function buildDecreaseLeverageIxns(owner, kaminoMarket, collTokenMint, deb
|
|
|
883
879
|
const balanceToWrap = halfSolBalance < 0.1 ? halfSolBalance : 0.1;
|
|
884
880
|
fillWsolAtaIxns.push(...(0, utils_1.getTransferWsolIxns)(owner, wsolAta, (0, classes_2.numberToLamportsDecimal)(balanceToWrap, debtReserve.stats.decimals).ceil()));
|
|
885
881
|
}
|
|
882
|
+
const scopeRefreshIxn = await (0, exports.getScopeRefreshIx)(kaminoMarket, collReserve, debtReserve, obligation, scopeRefreshConfig);
|
|
886
883
|
// 3. Flash borrow & repay amount to repay (debt)
|
|
887
884
|
const { flashBorrowIxn, flashRepayIxn } = (0, instructions_1.getFlashLoanInstructions)({
|
|
888
|
-
borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length + fillWsolAtaIxns.length,
|
|
885
|
+
borrowIxnIndex: budgetIxns.length + atasAndCreateIxns.length + fillWsolAtaIxns.length + (scopeRefreshIxn.length > 0 ? 1 : 0),
|
|
889
886
|
walletPublicKey: owner,
|
|
890
887
|
lendingMarketAuthority: kaminoMarket.getLendingMarketAuthority(),
|
|
891
888
|
lendingMarketAddress: kaminoMarket.getAddress(),
|
|
@@ -898,30 +895,45 @@ async function buildDecreaseLeverageIxns(owner, kaminoMarket, collTokenMint, deb
|
|
|
898
895
|
programId: kaminoMarket.programId,
|
|
899
896
|
});
|
|
900
897
|
// 4. Actually do the repay of the flash borrowed amounts
|
|
901
|
-
const
|
|
902
|
-
const repayAction = await classes_1.KaminoAction.buildRepayTxns(kaminoMarket, (0, classes_2.numberToLamportsDecimal)(decimal_js_1.default.abs(calcs.adjustBorrowPosition), debtReserve.stats.decimals).floor().toString(), debtTokenMint, owner, obligation, useV2Ixs, currentSlot, undefined, 0, false, false, false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
898
|
+
const repayAction = await classes_1.KaminoAction.buildRepayTxns(kaminoMarket, (0, classes_2.numberToLamportsDecimal)(decimal_js_1.default.abs(calcs.adjustBorrowPosition), debtReserve.stats.decimals).floor().toString(), debtTokenMint, owner, obligation, useV2Ixs, undefined, currentSlot, undefined, 0, false, false, false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
903
899
|
false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
904
|
-
referrer
|
|
900
|
+
referrer);
|
|
905
901
|
// 6. Withdraw collateral (a little bit more to be able to pay for the slippage on swap)
|
|
906
|
-
const withdrawAction = await classes_1.KaminoAction.buildWithdrawTxns(kaminoMarket, (0, classes_2.numberToLamportsDecimal)(calcs.withdrawAmountWithSlippageAndFlashLoanFee, collReserve.stats.decimals).ceil().toString(), collTokenMint, owner, obligation, useV2Ixs, 0, false, false, false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
902
|
+
const withdrawAction = await classes_1.KaminoAction.buildWithdrawTxns(kaminoMarket, (0, classes_2.numberToLamportsDecimal)(calcs.withdrawAmountWithSlippageAndFlashLoanFee, collReserve.stats.decimals).ceil().toString(), collTokenMint, owner, obligation, useV2Ixs, undefined, 0, false, false, false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
907
903
|
false, // to be checked and create in a setup tx in the UI (won't be the case for adjust anyway as this would be created in deposit)
|
|
908
|
-
referrer, currentSlot
|
|
904
|
+
referrer, currentSlot);
|
|
909
905
|
const swapInstructions = (0, utils_1.removeBudgetAndAtaIxns)(swapQuoteIxs.swapIxs, []);
|
|
910
906
|
const ixns = [
|
|
907
|
+
...scopeRefreshIxn,
|
|
911
908
|
...budgetIxns,
|
|
912
909
|
...atasAndCreateIxns.map((x) => x.createAtaIx),
|
|
913
910
|
...fillWsolAtaIxns,
|
|
914
911
|
...[flashBorrowIxn],
|
|
915
|
-
...repayAction
|
|
916
|
-
...
|
|
917
|
-
...repayAction.cleanupIxs,
|
|
918
|
-
...withdrawAction.setupIxs,
|
|
919
|
-
...withdrawAction.lendingIxs,
|
|
920
|
-
...withdrawAction.cleanupIxs,
|
|
912
|
+
...classes_1.KaminoAction.actionToIxs(repayAction),
|
|
913
|
+
...classes_1.KaminoAction.actionToIxs(withdrawAction),
|
|
921
914
|
...swapInstructions,
|
|
922
915
|
...[flashRepayIxn],
|
|
923
916
|
...closeWsolAtaIxns,
|
|
924
917
|
];
|
|
925
918
|
return ixns;
|
|
926
919
|
}
|
|
920
|
+
const getScopeRefreshIx = async (market, collReserve, debtReserve, obligation, scopeRefreshConfig) => {
|
|
921
|
+
const allReserves = obligation && (0, classes_1.isKaminoObligation)(obligation)
|
|
922
|
+
? new utils_1.PublicKeySet([
|
|
923
|
+
...obligation.getDeposits().map((x) => x.reserveAddress),
|
|
924
|
+
...obligation.getBorrows().map((x) => x.reserveAddress),
|
|
925
|
+
collReserve.address,
|
|
926
|
+
debtReserve.address,
|
|
927
|
+
]).toArray()
|
|
928
|
+
: new utils_1.PublicKeySet([collReserve.address, debtReserve.address]).toArray();
|
|
929
|
+
const tokenIds = (0, classes_1.getTokenIdsForScopeRefresh)(market, allReserves);
|
|
930
|
+
const scopeRefreshIxns = [];
|
|
931
|
+
if (tokenIds.length > 0 && scopeRefreshConfig) {
|
|
932
|
+
scopeRefreshIxns.push(await scopeRefreshConfig.scope.refreshPriceListIx({
|
|
933
|
+
feed: scopeRefreshConfig.scopeFeed,
|
|
934
|
+
}, tokenIds));
|
|
935
|
+
}
|
|
936
|
+
return scopeRefreshIxns;
|
|
937
|
+
};
|
|
938
|
+
exports.getScopeRefreshIx = getScopeRefreshIx;
|
|
927
939
|
//# sourceMappingURL=operations.js.map
|