@kamino-finance/klend-sdk 7.4.0-beta.0 → 7.4.0-beta.1
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/@codegen/klend/accounts/LendingMarket.d.ts +3 -51
- package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/LendingMarket.js +6 -39
- package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
- package/dist/@codegen/klend/accounts/Obligation.d.ts +15 -24
- package/dist/@codegen/klend/accounts/Obligation.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/Obligation.js +21 -24
- package/dist/@codegen/klend/accounts/Obligation.js.map +1 -1
- package/dist/@codegen/klend/accounts/Reserve.js +1 -1
- package/dist/@codegen/klend/accounts/UserState.d.ts +75 -0
- package/dist/@codegen/klend/accounts/UserState.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/UserState.js +25 -0
- package/dist/@codegen/klend/accounts/UserState.js.map +1 -1
- package/dist/@codegen/klend/errors/custom.d.ts +1 -89
- package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
- package/dist/@codegen/klend/errors/custom.js +1 -155
- package/dist/@codegen/klend/errors/custom.js.map +1 -1
- package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts +1 -0
- package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/idlMissingTypes.js +2 -0
- package/dist/@codegen/klend/instructions/idlMissingTypes.js.map +1 -1
- package/dist/@codegen/klend/instructions/index.d.ts +0 -4
- package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/index.js +1 -6
- package/dist/@codegen/klend/instructions/index.js.map +1 -1
- package/dist/@codegen/klend/types/AssetTier.d.ts +45 -0
- package/dist/@codegen/klend/types/AssetTier.d.ts.map +1 -0
- package/dist/@codegen/klend/types/AssetTier.js +132 -0
- package/dist/@codegen/klend/types/AssetTier.js.map +1 -0
- package/dist/@codegen/klend/types/ObligationLiquidity.d.ts +5 -35
- package/dist/@codegen/klend/types/ObligationLiquidity.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ObligationLiquidity.js +7 -17
- package/dist/@codegen/klend/types/ObligationLiquidity.js.map +1 -1
- package/dist/@codegen/klend/types/ObligationOrder.d.ts +4 -4
- package/dist/@codegen/klend/types/ObligationOrder.js +2 -2
- package/dist/@codegen/klend/types/ReserveConfig.d.ts +5 -60
- package/dist/@codegen/klend/types/ReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveConfig.js +7 -36
- package/dist/@codegen/klend/types/ReserveConfig.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts +7 -33
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.js +13 -61
- package/dist/@codegen/klend/types/UpdateConfigMode.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +0 -52
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +1 -97
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/@codegen/klend/types/index.d.ts +8 -8
- package/dist/@codegen/klend/types/index.d.ts.map +1 -1
- package/dist/@codegen/klend/types/index.js +3 -5
- package/dist/@codegen/klend/types/index.js.map +1 -1
- package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts +5 -8
- package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/@codegen/klend/zero_padding/ObligationZP.js +14 -17
- package/dist/@codegen/klend/zero_padding/ObligationZP.js.map +1 -1
- package/dist/classes/action.d.ts +21 -91
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +141 -119
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/actionTypes.d.ts +310 -0
- package/dist/classes/actionTypes.d.ts.map +1 -0
- package/dist/classes/actionTypes.js +3 -0
- package/dist/classes/actionTypes.js.map +1 -0
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +0 -4
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +5 -11
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +29 -21
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +9 -9
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +49 -51
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/obligationOrder.d.ts.map +1 -1
- package/dist/classes/obligationOrder.js +6 -3
- package/dist/classes/obligationOrder.js.map +1 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +1 -3
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/shared.d.ts +1 -0
- package/dist/classes/shared.d.ts.map +1 -1
- package/dist/client/commands/borrow.d.ts +1 -1
- package/dist/client/commands/borrow.d.ts.map +1 -1
- package/dist/client/commands/borrow.js +11 -2
- package/dist/client/commands/borrow.js.map +1 -1
- package/dist/client/commands/deposit.d.ts +1 -1
- package/dist/client/commands/deposit.d.ts.map +1 -1
- package/dist/client/commands/deposit.js +11 -2
- package/dist/client/commands/deposit.js.map +1 -1
- package/dist/client/commands/printReserve.d.ts +1 -1
- package/dist/client/commands/printReserve.d.ts.map +1 -1
- package/dist/client/commands/printReserve.js +2 -4
- package/dist/client/commands/printReserve.js.map +1 -1
- package/dist/client/commands/repay.d.ts +1 -1
- package/dist/client/commands/repay.d.ts.map +1 -1
- package/dist/client/commands/repay.js +12 -2
- package/dist/client/commands/repay.js.map +1 -1
- package/dist/client/commands/withdraw.d.ts +1 -1
- package/dist/client/commands/withdraw.d.ts.map +1 -1
- package/dist/client/commands/withdraw.js +11 -2
- package/dist/client/commands/withdraw.js.map +1 -1
- package/dist/idl/klend.json +54 -581
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
- package/dist/lending_operations/repay_with_collateral_calcs.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 +43 -10
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +40 -21
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +6 -6
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +167 -52
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +2 -2
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/manager/client_kamino_manager.js +6 -12
- package/dist/manager/client_kamino_manager.js.map +1 -1
- package/dist/obligation_orders/price_based.js +1 -0
- package/dist/obligation_orders/price_based.js.map +1 -1
- package/dist/utils/ObligationType.d.ts +33 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/ObligationType.js +81 -2
- package/dist/utils/ObligationType.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +1 -3
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/userMetadata.d.ts +2 -2
- package/dist/utils/userMetadata.d.ts.map +1 -1
- package/dist/utils/userMetadata.js +49 -25
- package/dist/utils/userMetadata.js.map +1 -1
- package/package.json +1 -1
- package/src/@codegen/klend/accounts/LendingMarket.ts +8 -79
- package/src/@codegen/klend/accounts/Obligation.ts +31 -42
- package/src/@codegen/klend/accounts/Reserve.ts +1 -1
- package/src/@codegen/klend/accounts/UserState.ts +75 -0
- package/src/@codegen/klend/errors/custom.ts +0 -172
- package/src/@codegen/klend/instructions/idlMissingTypes.ts +3 -0
- package/src/@codegen/klend/instructions/index.ts +0 -7
- package/src/@codegen/klend/types/AssetTier.ts +119 -0
- package/src/@codegen/klend/types/ObligationLiquidity.ts +9 -39
- package/src/@codegen/klend/types/ObligationOrder.ts +4 -4
- package/src/@codegen/klend/types/ReserveConfig.ts +9 -72
- package/src/@codegen/klend/types/UpdateConfigMode.ts +13 -73
- package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +0 -120
- package/src/@codegen/klend/types/index.ts +14 -21
- package/src/@codegen/klend/zero_padding/ObligationZP.ts +14 -17
- package/src/classes/action.ts +321 -347
- package/src/classes/actionTypes.ts +295 -0
- package/src/classes/manager.ts +0 -5
- package/src/classes/market.ts +42 -32
- package/src/classes/obligation.ts +55 -54
- package/src/classes/obligationOrder.ts +6 -3
- package/src/classes/reserve.ts +1 -3
- package/src/classes/shared.ts +2 -0
- package/src/client/client.ts +17 -18
- package/src/client/commands/borrow.ts +10 -9
- package/src/client/commands/deposit.ts +10 -9
- package/src/client/commands/printReserve.ts +2 -4
- package/src/client/commands/repay.ts +11 -10
- package/src/client/commands/withdraw.ts +15 -9
- package/src/idl/klend.json +54 -581
- package/src/lending_operations/repay_with_collateral_calcs.ts +3 -4
- package/src/lending_operations/repay_with_collateral_operations.ts +40 -38
- package/src/lending_operations/swap_collateral_operations.ts +47 -41
- package/src/leverage/operations.ts +168 -129
- package/src/leverage/types.ts +2 -2
- package/src/manager/client_kamino_manager.ts +6 -12
- package/src/obligation_orders/price_based.ts +1 -0
- package/src/utils/ObligationType.ts +92 -1
- package/src/utils/managerTypes.ts +1 -3
- package/src/utils/userMetadata.ts +64 -30
- package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts +0 -36
- package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/fillBorrowOrder.js +0 -49
- package/dist/@codegen/klend/instructions/fillBorrowOrder.js.map +0 -1
- package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts +0 -33
- package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/setBorrowOrder.js +0 -66
- package/dist/@codegen/klend/instructions/setBorrowOrder.js.map +0 -1
- package/dist/@codegen/klend/types/BorrowOrder.d.ts +0 -192
- package/dist/@codegen/klend/types/BorrowOrder.d.ts.map +0 -1
- package/dist/@codegen/klend/types/BorrowOrder.js +0 -194
- package/dist/@codegen/klend/types/BorrowOrder.js.map +0 -1
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts +0 -39
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts.map +0 -1
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js +0 -100
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js.map +0 -1
- package/src/@codegen/klend/instructions/fillBorrowOrder.ts +0 -96
- package/src/@codegen/klend/instructions/setBorrowOrder.ts +0 -81
- package/src/@codegen/klend/types/BorrowOrder.ts +0 -267
- package/src/@codegen/klend/types/BorrowOrderConfigArgs.ts +0 -87
|
@@ -174,7 +174,7 @@ export function estimateDebtRepaymentWithColl(props: {
|
|
|
174
174
|
slippagePct: Decimal;
|
|
175
175
|
flashLoanFeePct: Decimal;
|
|
176
176
|
kaminoMarket: KaminoMarket;
|
|
177
|
-
|
|
177
|
+
debtReserveAddress: Address;
|
|
178
178
|
obligation: KaminoObligation;
|
|
179
179
|
currentSlot: Slot;
|
|
180
180
|
}): Decimal {
|
|
@@ -184,15 +184,14 @@ export function estimateDebtRepaymentWithColl(props: {
|
|
|
184
184
|
slippagePct,
|
|
185
185
|
flashLoanFeePct,
|
|
186
186
|
kaminoMarket,
|
|
187
|
-
|
|
187
|
+
debtReserveAddress,
|
|
188
188
|
obligation,
|
|
189
189
|
currentSlot,
|
|
190
190
|
} = props;
|
|
191
191
|
const slippageMultiplier = new Decimal(1.0).add(slippagePct.div('100'));
|
|
192
192
|
const flashLoanFeeMultiplier = new Decimal(1.0).add(flashLoanFeePct.div('100'));
|
|
193
193
|
|
|
194
|
-
const debtReserve = kaminoMarket.
|
|
195
|
-
|
|
194
|
+
const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
|
|
196
195
|
const debtAfterSwap = collAmount.div(slippageMultiplier).div(priceDebtToColl);
|
|
197
196
|
const debtAfterFlashLoanRepay = debtAfterSwap.div(flashLoanFeeMultiplier);
|
|
198
197
|
|
|
@@ -47,8 +47,8 @@ export type RepayWithCollInitialInputs<QuoteResponse> = {
|
|
|
47
47
|
|
|
48
48
|
interface RepayWithCollSwapInputsProps<QuoteResponse> {
|
|
49
49
|
kaminoMarket: KaminoMarket;
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
debtReserveAddress: Address;
|
|
51
|
+
collReserveAddress: Address;
|
|
52
52
|
owner: TransactionSigner;
|
|
53
53
|
obligation: KaminoObligation;
|
|
54
54
|
referrer: Option<Address>;
|
|
@@ -67,9 +67,9 @@ export enum MaxWithdrawLtvCheck {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export async function getRepayWithCollSwapInputs<QuoteResponse>({
|
|
70
|
-
|
|
70
|
+
collReserveAddress,
|
|
71
71
|
currentSlot,
|
|
72
|
-
|
|
72
|
+
debtReserveAddress,
|
|
73
73
|
kaminoMarket,
|
|
74
74
|
owner,
|
|
75
75
|
obligation,
|
|
@@ -85,8 +85,10 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
|
|
|
85
85
|
flashLoanInfo: FlashLoanInfo;
|
|
86
86
|
initialInputs: RepayWithCollInitialInputs<QuoteResponse>;
|
|
87
87
|
}> {
|
|
88
|
-
const collReserve = kaminoMarket.
|
|
89
|
-
const debtReserve = kaminoMarket.
|
|
88
|
+
const collReserve = kaminoMarket.getExistingReserveByAddress(collReserveAddress);
|
|
89
|
+
const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
|
|
90
|
+
const collTokenMint = collReserve.getLiquidityMint();
|
|
91
|
+
const debtTokenMint = debtReserve.getLiquidityMint();
|
|
90
92
|
|
|
91
93
|
const {
|
|
92
94
|
repayAmountLamports,
|
|
@@ -188,9 +190,9 @@ export async function getRepayWithCollIxs<QuoteResponse>({
|
|
|
188
190
|
repayAmount,
|
|
189
191
|
isClosingPosition,
|
|
190
192
|
budgetAndPriorityFeeIxs,
|
|
191
|
-
|
|
193
|
+
collReserveAddress,
|
|
192
194
|
currentSlot,
|
|
193
|
-
|
|
195
|
+
debtReserveAddress,
|
|
194
196
|
kaminoMarket,
|
|
195
197
|
owner,
|
|
196
198
|
obligation,
|
|
@@ -202,9 +204,9 @@ export async function getRepayWithCollIxs<QuoteResponse>({
|
|
|
202
204
|
logger = console.log,
|
|
203
205
|
}: RepayWithCollIxsProps<QuoteResponse>): Promise<Array<RepayWithCollIxsResponse<QuoteResponse>>> {
|
|
204
206
|
const { swapInputs, initialInputs } = await getRepayWithCollSwapInputs({
|
|
205
|
-
|
|
207
|
+
collReserveAddress,
|
|
206
208
|
currentSlot,
|
|
207
|
-
|
|
209
|
+
debtReserveAddress,
|
|
208
210
|
kaminoMarket,
|
|
209
211
|
owner,
|
|
210
212
|
obligation,
|
|
@@ -219,8 +221,8 @@ export async function getRepayWithCollIxs<QuoteResponse>({
|
|
|
219
221
|
const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
|
|
220
222
|
const { inputAmountLamports: collSwapInLamports } = swapInputs;
|
|
221
223
|
|
|
222
|
-
const collReserve = kaminoMarket.
|
|
223
|
-
const debtReserve = kaminoMarket.
|
|
224
|
+
const collReserve = kaminoMarket.getExistingReserveByAddress(collReserveAddress);
|
|
225
|
+
const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
|
|
224
226
|
|
|
225
227
|
// the client should use these values to prevent this input, but the tx may succeed, so we don't want to fail
|
|
226
228
|
// there is also a chance that the tx will consume debt token from the user's ata which they would not expect
|
|
@@ -328,40 +330,40 @@ async function buildRepayWithCollateralIxs<QuoteResponse>(
|
|
|
328
330
|
// 3. Repay using the flash borrowed funds & withdraw collateral to swap and pay the flash loan
|
|
329
331
|
let repayAndWithdrawAction;
|
|
330
332
|
if (maxWithdrawLtvCheck === MaxWithdrawLtvCheck.MAX_LTV) {
|
|
331
|
-
repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
|
|
332
|
-
market,
|
|
333
|
-
isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
|
|
334
|
-
debtReserve.
|
|
335
|
-
isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
|
|
336
|
-
collReserve.
|
|
337
|
-
owner,
|
|
333
|
+
repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns({
|
|
334
|
+
kaminoMarket: market,
|
|
335
|
+
repayAmount: isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
|
|
336
|
+
repayReserveAddress: debtReserve.address,
|
|
337
|
+
withdrawAmount: isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
|
|
338
|
+
withdrawReserveAddress: collReserve.address,
|
|
339
|
+
payer: owner,
|
|
338
340
|
currentSlot,
|
|
339
341
|
obligation,
|
|
340
342
|
useV2Ixs,
|
|
341
|
-
undefined,
|
|
342
|
-
0,
|
|
343
|
-
false,
|
|
343
|
+
scopeRefreshConfig: undefined,
|
|
344
|
+
extraComputeBudget: 0,
|
|
345
|
+
includeAtaIxs: false,
|
|
344
346
|
requestElevationGroup,
|
|
345
|
-
undefined,
|
|
346
|
-
referrer
|
|
347
|
-
);
|
|
347
|
+
initUserMetadata: undefined,
|
|
348
|
+
referrer,
|
|
349
|
+
});
|
|
348
350
|
} else {
|
|
349
|
-
repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawV2Txns(
|
|
350
|
-
market,
|
|
351
|
-
isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
|
|
352
|
-
debtReserve.
|
|
353
|
-
isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
|
|
354
|
-
collReserve.
|
|
355
|
-
owner,
|
|
351
|
+
repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawV2Txns({
|
|
352
|
+
kaminoMarket: market,
|
|
353
|
+
repayAmount: isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
|
|
354
|
+
repayReserveAddress: debtReserve.address,
|
|
355
|
+
withdrawAmount: isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
|
|
356
|
+
withdrawReserveAddress: collReserve.address,
|
|
357
|
+
payer: owner,
|
|
356
358
|
currentSlot,
|
|
357
359
|
obligation,
|
|
358
|
-
undefined,
|
|
359
|
-
0,
|
|
360
|
-
false,
|
|
360
|
+
scopeRefreshConfig: undefined,
|
|
361
|
+
extraComputeBudget: 0,
|
|
362
|
+
includeAtaIxs: false,
|
|
361
363
|
requestElevationGroup,
|
|
362
|
-
undefined,
|
|
363
|
-
referrer
|
|
364
|
-
);
|
|
364
|
+
initUserMetadata: undefined,
|
|
365
|
+
referrer,
|
|
366
|
+
});
|
|
365
367
|
}
|
|
366
368
|
|
|
367
369
|
// 4. Swap collateral to debt to repay flash loan
|
|
@@ -40,14 +40,14 @@ export interface SwapCollIxsInputs<QuoteResponse> {
|
|
|
40
40
|
isClosingSourceColl: boolean;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* The
|
|
43
|
+
* The address of the source collateral reserve (i.e. the current one).
|
|
44
44
|
*/
|
|
45
|
-
|
|
45
|
+
sourceCollReserveAddress: Address;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* The
|
|
48
|
+
* The address of the target collateral reserve (i.e. the new one).
|
|
49
49
|
*/
|
|
50
|
-
|
|
50
|
+
targetCollReserveAddress: Address;
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* An elevation group ID that the obligation should end up with after the collateral swap - it will be requested by
|
|
@@ -220,7 +220,7 @@ type SwapCollContext<QuoteResponse> = {
|
|
|
220
220
|
function extractArgsAndContext<QuoteResponse>(
|
|
221
221
|
inputs: SwapCollIxsInputs<QuoteResponse>
|
|
222
222
|
): [SwapCollArgs, SwapCollContext<QuoteResponse>] {
|
|
223
|
-
if (inputs.
|
|
223
|
+
if (inputs.sourceCollReserveAddress === inputs.targetCollReserveAddress) {
|
|
224
224
|
throw new Error(`Cannot swap from/to the same collateral`);
|
|
225
225
|
}
|
|
226
226
|
if (inputs.sourceCollSwapAmount.lte(0)) {
|
|
@@ -235,8 +235,14 @@ function extractArgsAndContext<QuoteResponse>(
|
|
|
235
235
|
{
|
|
236
236
|
budgetAndPriorityFeeIxs:
|
|
237
237
|
inputs.budgetAndPriorityFeeIxs || getComputeBudgetAndPriorityFeeIxs(DEFAULT_MAX_COMPUTE_UNITS),
|
|
238
|
-
sourceCollReserve: inputs.market.
|
|
239
|
-
|
|
238
|
+
sourceCollReserve: inputs.market.getExistingReserveByAddress(
|
|
239
|
+
inputs.sourceCollReserveAddress,
|
|
240
|
+
'Current collateral'
|
|
241
|
+
),
|
|
242
|
+
targetCollReserve: inputs.market.getExistingReserveByAddress(
|
|
243
|
+
inputs.targetCollReserveAddress,
|
|
244
|
+
'Target collateral'
|
|
245
|
+
),
|
|
240
246
|
logger: console.log,
|
|
241
247
|
market: inputs.market,
|
|
242
248
|
obligation: inputs.obligation,
|
|
@@ -395,22 +401,22 @@ async function getDepositTargetCollIxs(
|
|
|
395
401
|
context: SwapCollContext<any>
|
|
396
402
|
): Promise<DepositTargetCollIxs> {
|
|
397
403
|
const removesElevationGroup = mustRemoveElevationGroupBeforeDeposit(context);
|
|
398
|
-
const depositCollAction = await KaminoAction.buildDepositTxns(
|
|
399
|
-
context.market,
|
|
400
|
-
targetCollAmount.mul(context.targetCollReserve.getMintFactor()).toString(), // in lamports
|
|
401
|
-
context.targetCollReserve.
|
|
402
|
-
context.owner,
|
|
403
|
-
context.obligation,
|
|
404
|
-
context.useV2Ixs,
|
|
405
|
-
undefined, // we create the scope refresh ix outside of KaminoAction
|
|
406
|
-
0, // no extra compute budget
|
|
407
|
-
false, // we do not need ATA ixs here (we construct and close them ourselves)
|
|
408
|
-
removesElevationGroup, // we may need to (temporarily) remove the elevation group; the same or a different one will be set on withdraw, if requested
|
|
409
|
-
{ skipInitialization: true, skipLutCreation: true }, // we are dealing with an existing obligation, no need to create user metadata
|
|
410
|
-
context.referrer,
|
|
411
|
-
context.currentSlot,
|
|
412
|
-
removesElevationGroup ? 0 : undefined // only applicable when removing the group
|
|
413
|
-
);
|
|
404
|
+
const depositCollAction = await KaminoAction.buildDepositTxns({
|
|
405
|
+
kaminoMarket: context.market,
|
|
406
|
+
amount: targetCollAmount.mul(context.targetCollReserve.getMintFactor()).toString(), // in lamports
|
|
407
|
+
reserveAddress: context.targetCollReserve.address,
|
|
408
|
+
owner: context.owner,
|
|
409
|
+
obligation: context.obligation,
|
|
410
|
+
useV2Ixs: context.useV2Ixs,
|
|
411
|
+
scopeRefreshConfig: undefined, // we create the scope refresh ix outside of KaminoAction
|
|
412
|
+
extraComputeBudget: 0, // no extra compute budget
|
|
413
|
+
includeAtaIxs: false, // we do not need ATA ixs here (we construct and close them ourselves)
|
|
414
|
+
requestElevationGroup: removesElevationGroup, // we may need to (temporarily) remove the elevation group; the same or a different one will be set on withdraw, if requested
|
|
415
|
+
initUserMetadata: { skipInitialization: true, skipLutCreation: true }, // we are dealing with an existing obligation, no need to create user metadata
|
|
416
|
+
referrer: context.referrer,
|
|
417
|
+
currentSlot: context.currentSlot,
|
|
418
|
+
overrideElevationGroupRequest: removesElevationGroup ? 0 : undefined, // only applicable when removing the group
|
|
419
|
+
});
|
|
414
420
|
return {
|
|
415
421
|
ixs: KaminoAction.actionToIxs(depositCollAction),
|
|
416
422
|
removesElevationGroup,
|
|
@@ -444,27 +450,27 @@ async function getWithdrawSourceCollIxs(
|
|
|
444
450
|
? U64_MAX
|
|
445
451
|
: args.sourceCollSwapAmount.mul(context.sourceCollReserve.getMintFactor()).toString();
|
|
446
452
|
const requestedElevationGroup = elevationGroupIdToRequestAfterWithdraw(args, depositRemovedElevationGroup, context);
|
|
447
|
-
const withdrawCollAction = await KaminoAction.buildWithdrawTxns(
|
|
448
|
-
context.market,
|
|
449
|
-
withdrawnSourceCollLamports,
|
|
450
|
-
context.sourceCollReserve.
|
|
451
|
-
context.owner,
|
|
452
|
-
context.obligation,
|
|
453
|
-
context.useV2Ixs,
|
|
454
|
-
undefined, // we create the scope refresh ix outside of KaminoAction
|
|
455
|
-
0, // no extra compute budget
|
|
456
|
-
false, // we do not need ATA ixs here (we construct and close them ourselves)
|
|
457
|
-
requestedElevationGroup !== undefined, // the `elevationGroupIdToRequestAfterWithdraw()` has already decided on this
|
|
458
|
-
{ skipInitialization: true, skipLutCreation: true }, // we are dealing with an existing obligation, no need to create user metadata
|
|
459
|
-
context.referrer,
|
|
460
|
-
context.currentSlot,
|
|
461
|
-
requestedElevationGroup,
|
|
462
|
-
context.obligation.deposits.has(context.targetCollReserve.address) // if our obligation already had the target coll...
|
|
453
|
+
const withdrawCollAction = await KaminoAction.buildWithdrawTxns({
|
|
454
|
+
kaminoMarket: context.market,
|
|
455
|
+
amount: withdrawnSourceCollLamports,
|
|
456
|
+
reserveAddress: context.sourceCollReserve.address,
|
|
457
|
+
owner: context.owner,
|
|
458
|
+
obligation: context.obligation,
|
|
459
|
+
useV2Ixs: context.useV2Ixs,
|
|
460
|
+
scopeRefreshConfig: undefined, // we create the scope refresh ix outside of KaminoAction
|
|
461
|
+
extraComputeBudget: 0, // no extra compute budget
|
|
462
|
+
includeAtaIxs: false, // we do not need ATA ixs here (we construct and close them ourselves)
|
|
463
|
+
requestElevationGroup: requestedElevationGroup !== undefined, // the `elevationGroupIdToRequestAfterWithdraw()` has already decided on this
|
|
464
|
+
initUserMetadata: { skipInitialization: true, skipLutCreation: true }, // we are dealing with an existing obligation, no need to create user metadata
|
|
465
|
+
referrer: context.referrer,
|
|
466
|
+
currentSlot: context.currentSlot,
|
|
467
|
+
overrideElevationGroupRequest: requestedElevationGroup,
|
|
468
|
+
obligationCustomizations: context.obligation.deposits.has(context.targetCollReserve.address) // if our obligation already had the target coll...
|
|
463
469
|
? undefined // ... then we need no customizations here, but otherwise...
|
|
464
470
|
: {
|
|
465
471
|
addedDepositReserves: [context.targetCollReserve.address], // ... we need to inform our infra that the obligation now has one more reserve that needs refreshing.
|
|
466
|
-
}
|
|
467
|
-
);
|
|
472
|
+
},
|
|
473
|
+
});
|
|
468
474
|
return KaminoAction.actionToIxs(withdrawCollAction);
|
|
469
475
|
}
|
|
470
476
|
|