@kamino-finance/klend-sdk 7.1.4-beta.0 → 7.1.5
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 -144
- package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/LendingMarket.js +3 -105
- package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
- package/dist/@codegen/klend/accounts/Obligation.d.ts +15 -30
- package/dist/@codegen/klend/accounts/Obligation.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/Obligation.js +21 -31
- package/dist/@codegen/klend/accounts/Obligation.js.map +1 -1
- package/dist/@codegen/klend/accounts/Reserve.d.ts +0 -6
- package/dist/@codegen/klend/accounts/Reserve.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/Reserve.js +2 -9
- package/dist/@codegen/klend/accounts/Reserve.js.map +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/accounts/index.d.ts +0 -6
- package/dist/@codegen/klend/accounts/index.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/index.js +1 -7
- package/dist/@codegen/klend/accounts/index.js.map +1 -1
- package/dist/@codegen/klend/errors/custom.d.ts +2 -226
- package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
- package/dist/@codegen/klend/errors/custom.js +3 -396
- package/dist/@codegen/klend/errors/custom.js.map +1 -1
- package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts +2 -1
- package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/idlMissingTypes.js +2 -6
- package/dist/@codegen/klend/instructions/idlMissingTypes.js.map +1 -1
- package/dist/@codegen/klend/instructions/index.d.ts +0 -16
- package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/index.js +1 -18
- package/dist/@codegen/klend/instructions/index.js.map +1 -1
- package/dist/@codegen/klend/instructions/initReserve.d.ts +1 -1
- package/dist/@codegen/klend/instructions/initReserve.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/initReserve.js +5 -1
- package/dist/@codegen/klend/instructions/initReserve.js.map +1 -1
- package/dist/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateral.js +1 -1
- package/dist/@codegen/klend/instructions/updateGlobalConfig.d.ts +1 -1
- package/dist/@codegen/klend/instructions/updateGlobalConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/updateGlobalConfig.js +0 -1
- package/dist/@codegen/klend/instructions/updateGlobalConfig.js.map +1 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.d.ts +1 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.js +0 -1
- package/dist/@codegen/klend/instructions/updateReserveConfig.js.map +1 -1
- package/dist/@codegen/klend/instructions/withdrawObligationCollateral.js +1 -1
- package/dist/@codegen/klend/instructions/withdrawObligationCollateralV2.js +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 +29 -141
- package/dist/@codegen/klend/types/ReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveConfig.js +25 -89
- package/dist/@codegen/klend/types/ReserveConfig.js.map +1 -1
- package/dist/@codegen/klend/types/ReserveFees.d.ts +8 -8
- package/dist/@codegen/klend/types/ReserveFees.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveFees.js +8 -8
- package/dist/@codegen/klend/types/ReserveFees.js.map +1 -1
- package/dist/@codegen/klend/types/ReserveLiquidity.d.ts +8 -26
- package/dist/@codegen/klend/types/ReserveLiquidity.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveLiquidity.js +8 -14
- package/dist/@codegen/klend/types/ReserveLiquidity.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts +14 -92
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.js +23 -168
- package/dist/@codegen/klend/types/UpdateConfigMode.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +0 -130
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +1 -241
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/@codegen/klend/types/index.d.ts +8 -10
- package/dist/@codegen/klend/types/index.d.ts.map +1 -1
- package/dist/@codegen/klend/types/index.js +3 -7
- package/dist/@codegen/klend/types/index.js.map +1 -1
- package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts +4 -9
- package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/@codegen/klend/zero_padding/ObligationZP.js +13 -22
- package/dist/@codegen/klend/zero_padding/ObligationZP.js.map +1 -1
- package/dist/classes/action.d.ts +3 -30
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +10 -364
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +3 -2
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +3 -12
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +2 -6
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +6 -26
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.js +1 -1
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/reserve.d.ts.map +1 -1
- package/dist/classes/reserve.js +7 -13
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/unstakingPool.d.ts +3 -20
- package/dist/classes/unstakingPool.d.ts.map +1 -1
- package/dist/classes/unstakingPool.js +8 -62
- package/dist/classes/unstakingPool.js.map +1 -1
- package/dist/classes/vault.d.ts +2 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +59 -38
- package/dist/classes/vault.js.map +1 -1
- package/dist/idl/klend.json +293 -2186
- package/dist/lending_operations/index.d.ts +0 -1
- package/dist/lending_operations/index.d.ts.map +1 -1
- package/dist/lending_operations/index.js +0 -1
- package/dist/lending_operations/index.js.map +1 -1
- package/dist/manager/client_kamino_manager.js +9 -12
- package/dist/manager/client_kamino_manager.js.map +1 -1
- package/dist/utils/ata.d.ts +10 -1
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +47 -0
- package/dist/utils/ata.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +4 -9
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/seeds.d.ts +14 -10
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +22 -25
- package/dist/utils/seeds.js.map +1 -1
- package/package.json +1 -1
- package/src/@codegen/klend/accounts/LendingMarket.ts +5 -210
- package/src/@codegen/klend/accounts/Obligation.ts +31 -53
- package/src/@codegen/klend/accounts/Reserve.ts +2 -13
- package/src/@codegen/klend/accounts/UserState.ts +75 -0
- package/src/@codegen/klend/accounts/index.ts +0 -6
- package/src/@codegen/klend/errors/custom.ts +2 -427
- package/src/@codegen/klend/instructions/idlMissingTypes.ts +4 -7
- package/src/@codegen/klend/instructions/index.ts +0 -34
- package/src/@codegen/klend/instructions/initReserve.ts +6 -2
- package/src/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateral.ts +1 -1
- package/src/@codegen/klend/instructions/updateGlobalConfig.ts +1 -2
- package/src/@codegen/klend/instructions/updateReserveConfig.ts +1 -2
- package/src/@codegen/klend/instructions/withdrawObligationCollateral.ts +1 -1
- package/src/@codegen/klend/instructions/withdrawObligationCollateralV2.ts +1 -1
- 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 +39 -171
- package/src/@codegen/klend/types/ReserveFees.ts +12 -12
- package/src/@codegen/klend/types/ReserveLiquidity.ts +12 -30
- package/src/@codegen/klend/types/UpdateConfigMode.ts +26 -206
- package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +0 -300
- package/src/@codegen/klend/types/index.ts +16 -45
- package/src/@codegen/klend/zero_padding/ObligationZP.ts +13 -22
- package/src/classes/action.ts +8 -577
- package/src/classes/manager.ts +7 -13
- package/src/classes/market.ts +5 -36
- package/src/classes/obligation.ts +1 -1
- package/src/classes/reserve.ts +8 -13
- package/src/classes/unstakingPool.ts +6 -83
- package/src/classes/vault.ts +75 -54
- package/src/idl/klend.json +294 -2187
- package/src/lending_operations/index.ts +0 -1
- package/src/manager/client_kamino_manager.ts +9 -13
- package/src/utils/ata.ts +79 -0
- package/src/utils/managerTypes.ts +4 -9
- package/src/utils/seeds.ts +26 -28
- package/dist/@codegen/klend/accounts/PoolState.d.ts +0 -53
- package/dist/@codegen/klend/accounts/PoolState.d.ts.map +0 -1
- package/dist/@codegen/klend/accounts/PoolState.js +0 -167
- package/dist/@codegen/klend/accounts/PoolState.js.map +0 -1
- package/dist/@codegen/klend/accounts/UnstakeTicket.d.ts +0 -41
- package/dist/@codegen/klend/accounts/UnstakeTicket.d.ts.map +0 -1
- package/dist/@codegen/klend/accounts/UnstakeTicket.js +0 -143
- package/dist/@codegen/klend/accounts/UnstakeTicket.js.map +0 -1
- package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts +0 -132
- package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts.map +0 -1
- package/dist/@codegen/klend/accounts/WithdrawTicket.js +0 -191
- package/dist/@codegen/klend/accounts/WithdrawTicket.js.map +0 -1
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts +0 -39
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.js +0 -67
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.js.map +0 -1
- 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/recoverInvalidTicketCollateral.d.ts +0 -47
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js +0 -66
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js.map +0 -1
- package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts +0 -31
- package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/setBorrowOrder.js +0 -64
- package/dist/@codegen/klend/instructions/setBorrowOrder.js.map +0 -1
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.d.ts +0 -53
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.js +0 -190
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.js.map +0 -1
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.d.ts +0 -70
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.js +0 -261
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.js.map +0 -1
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.d.ts +0 -41
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.js +0 -135
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.js.map +0 -1
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts +0 -51
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts.map +0 -1
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js +0 -28
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.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/dist/@codegen/klend/types/WithdrawQueue.d.ts +0 -64
- package/dist/@codegen/klend/types/WithdrawQueue.d.ts.map +0 -1
- package/dist/@codegen/klend/types/WithdrawQueue.js +0 -104
- package/dist/@codegen/klend/types/WithdrawQueue.js.map +0 -1
- package/dist/lending_operations/unstake_lst_collateral.d.ts +0 -12
- package/dist/lending_operations/unstake_lst_collateral.d.ts.map +0 -1
- package/dist/lending_operations/unstake_lst_collateral.js +0 -104
- package/dist/lending_operations/unstake_lst_collateral.js.map +0 -1
- package/src/@codegen/klend/accounts/PoolState.ts +0 -192
- package/src/@codegen/klend/accounts/UnstakeTicket.ts +0 -160
- package/src/@codegen/klend/accounts/WithdrawTicket.ts +0 -256
- package/src/@codegen/klend/instructions/enqueueToWithdraw.ts +0 -89
- package/src/@codegen/klend/instructions/fillBorrowOrder.ts +0 -96
- package/src/@codegen/klend/instructions/recoverInvalidTicketCollateral.ts +0 -96
- package/src/@codegen/klend/instructions/setBorrowOrder.ts +0 -77
- package/src/@codegen/klend/instructions/unstakeLstCollateralEnd.ts +0 -251
- package/src/@codegen/klend/instructions/unstakeLstCollateralStart.ts +0 -353
- package/src/@codegen/klend/instructions/withdrawObligationUsol.ts +0 -168
- package/src/@codegen/klend/instructions/withdrawQueuedLiquidity.ts +0 -92
- package/src/@codegen/klend/types/BorrowOrder.ts +0 -267
- package/src/@codegen/klend/types/BorrowOrderConfigArgs.ts +0 -87
- package/src/@codegen/klend/types/WithdrawQueue.ts +0 -117
- package/src/lending_operations/unstake_lst_collateral.ts +0 -174
package/src/classes/action.ts
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
AccountRole,
|
|
3
3
|
Address,
|
|
4
4
|
fetchEncodedAccount,
|
|
5
|
-
generateKeyPairSigner,
|
|
6
5
|
AccountMeta,
|
|
7
6
|
Instruction,
|
|
8
7
|
isNone,
|
|
@@ -45,10 +44,8 @@ import {
|
|
|
45
44
|
RequestElevationGroupAccounts,
|
|
46
45
|
RequestElevationGroupArgs,
|
|
47
46
|
setObligationOrder,
|
|
48
|
-
unstakeLstCollateralStart,
|
|
49
47
|
withdrawObligationCollateralAndRedeemReserveCollateral,
|
|
50
48
|
withdrawObligationCollateralAndRedeemReserveCollateralV2,
|
|
51
|
-
withdrawObligationUsol,
|
|
52
49
|
withdrawReferrerFees,
|
|
53
50
|
} from '../@codegen/klend/instructions';
|
|
54
51
|
import {
|
|
@@ -65,7 +62,6 @@ import {
|
|
|
65
62
|
ScopePriceRefreshConfig,
|
|
66
63
|
SOL_PADDING_FOR_INTEREST,
|
|
67
64
|
U64_MAX,
|
|
68
|
-
unstakingPoolMarketAuthorityPda,
|
|
69
65
|
userMetadataPda,
|
|
70
66
|
WRAPPED_SOL_MINT,
|
|
71
67
|
} from '../utils';
|
|
@@ -81,14 +77,8 @@ import { ObligationOrderAtIndex } from './obligationOrder';
|
|
|
81
77
|
import { ASSOCIATED_TOKEN_PROGRAM_ADDRESS, TOKEN_PROGRAM_ADDRESS } from '@solana-program/token';
|
|
82
78
|
import { SYSVAR_INSTRUCTIONS_ADDRESS, SYSVAR_RENT_ADDRESS } from '@solana/sysvars';
|
|
83
79
|
import { getCloseAccountInstruction, getSyncNativeInstruction } from '@solana-program/token-2022';
|
|
84
|
-
import {
|
|
80
|
+
import { getTransferSolInstruction, SYSTEM_PROGRAM_ADDRESS } from '@solana-program/system';
|
|
85
81
|
import { noopSigner } from '../utils/signer';
|
|
86
|
-
import { PROGRAM_ID as UNSTAKING_POOL_ID } from '../@codegen/unstaking_pool/programId';
|
|
87
|
-
import { UNSTAKING_POOL_STAGING_ID, UnstakingPool, unstakingPoolBaseAuthorityPda } from './unstakingPool';
|
|
88
|
-
import { PROGRAM_ID } from '../@codegen/klend/programId';
|
|
89
|
-
import { UnstakeTicket } from '../@codegen/unstaking_pool/accounts/UnstakeTicket';
|
|
90
|
-
import { burn } from '../@codegen/unstaking_pool/instructions';
|
|
91
|
-
import { unstakeLstCollateralEnd } from '../@codegen/klend/instructions/unstakeLstCollateralEnd';
|
|
92
82
|
|
|
93
83
|
export type ActionType =
|
|
94
84
|
| 'deposit'
|
|
@@ -105,14 +95,12 @@ export type ActionType =
|
|
|
105
95
|
| 'requestElevationGroup'
|
|
106
96
|
| 'withdrawReferrerFees'
|
|
107
97
|
| 'repayAndWithdrawV2'
|
|
108
|
-
| 'depositAndWithdraw'
|
|
109
|
-
| 'unstakeLstCollateralStart';
|
|
98
|
+
| 'depositAndWithdraw';
|
|
110
99
|
|
|
111
100
|
export type AuxiliaryIx = 'setup' | 'inBetween' | 'cleanup';
|
|
112
101
|
|
|
113
102
|
export class KaminoAction {
|
|
114
103
|
kaminoMarket: KaminoMarket;
|
|
115
|
-
unstakingPool: UnstakingPool | undefined;
|
|
116
104
|
|
|
117
105
|
reserve: KaminoReserve;
|
|
118
106
|
|
|
@@ -175,7 +163,6 @@ export class KaminoAction {
|
|
|
175
163
|
borrowReserves: Array<Address>,
|
|
176
164
|
reserveState: KaminoReserve,
|
|
177
165
|
currentSlot: Slot,
|
|
178
|
-
unstakingPool?: UnstakingPool,
|
|
179
166
|
secondaryMint?: Address,
|
|
180
167
|
outflowReserveState?: KaminoReserve,
|
|
181
168
|
outflowAmount?: string | BN,
|
|
@@ -210,7 +197,6 @@ export class KaminoAction {
|
|
|
210
197
|
this.preLoadedDepositReservesSameTx = [];
|
|
211
198
|
this.referrer = referrer;
|
|
212
199
|
this.currentSlot = currentSlot;
|
|
213
|
-
this.unstakingPool = unstakingPool;
|
|
214
200
|
}
|
|
215
201
|
|
|
216
202
|
static async initialize(
|
|
@@ -222,8 +208,7 @@ export class KaminoAction {
|
|
|
222
208
|
obligation: KaminoObligation | ObligationType,
|
|
223
209
|
referrer: Option<Address> = none(),
|
|
224
210
|
currentSlot: Slot = 0n,
|
|
225
|
-
payer: TransactionSigner = owner
|
|
226
|
-
needsUnstakingPool: boolean = false
|
|
211
|
+
payer: TransactionSigner = owner
|
|
227
212
|
) {
|
|
228
213
|
const reserve = kaminoMarket.getReserveByMint(mint);
|
|
229
214
|
if (reserve === undefined) {
|
|
@@ -235,15 +220,6 @@ export class KaminoAction {
|
|
|
235
220
|
|
|
236
221
|
const referrerKey = await this.getReferrerKey(kaminoMarket, owner.address, kaminoObligation, referrer);
|
|
237
222
|
|
|
238
|
-
let unstakingPool = undefined;
|
|
239
|
-
if (needsUnstakingPool) {
|
|
240
|
-
const unstakingPoolPk = kaminoMarket.state.unstakingPoolState;
|
|
241
|
-
const unstakingPoolProgramId =
|
|
242
|
-
kaminoMarket.programId == PROGRAM_ID ? UNSTAKING_POOL_ID : UNSTAKING_POOL_STAGING_ID;
|
|
243
|
-
unstakingPool = new UnstakingPool(unstakingPoolPk, undefined, unstakingPoolProgramId);
|
|
244
|
-
await unstakingPool.reloadState(kaminoMarket.getRpc());
|
|
245
|
-
}
|
|
246
|
-
|
|
247
223
|
return new KaminoAction(
|
|
248
224
|
kaminoMarket,
|
|
249
225
|
owner,
|
|
@@ -255,7 +231,6 @@ export class KaminoAction {
|
|
|
255
231
|
borrowReserves,
|
|
256
232
|
reserve,
|
|
257
233
|
currentSlot,
|
|
258
|
-
unstakingPool,
|
|
259
234
|
undefined,
|
|
260
235
|
undefined,
|
|
261
236
|
undefined,
|
|
@@ -963,61 +938,6 @@ export class KaminoAction {
|
|
|
963
938
|
return axn;
|
|
964
939
|
}
|
|
965
940
|
|
|
966
|
-
static async buildUnstakeLstCollateralStartTxns(
|
|
967
|
-
kaminoMarket: KaminoMarket,
|
|
968
|
-
lstToConvert: string | BN,
|
|
969
|
-
usolMint: Address,
|
|
970
|
-
lstMint: Address,
|
|
971
|
-
payer: TransactionSigner,
|
|
972
|
-
currentSlot: Slot,
|
|
973
|
-
obligation: KaminoObligation | ObligationType,
|
|
974
|
-
depositStakedSolRemainingAccounts: AccountMeta[],
|
|
975
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
976
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
|
|
977
|
-
includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas,
|
|
978
|
-
initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
|
|
979
|
-
skipInitialization: false,
|
|
980
|
-
skipLutCreation: false,
|
|
981
|
-
},
|
|
982
|
-
referrer: Option<Address> = none()
|
|
983
|
-
) {
|
|
984
|
-
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
985
|
-
kaminoMarket,
|
|
986
|
-
'unstakeLstCollateralStart',
|
|
987
|
-
lstToConvert,
|
|
988
|
-
usolMint,
|
|
989
|
-
lstMint,
|
|
990
|
-
payer,
|
|
991
|
-
payer.address,
|
|
992
|
-
obligation,
|
|
993
|
-
undefined,
|
|
994
|
-
referrer,
|
|
995
|
-
currentSlot,
|
|
996
|
-
true
|
|
997
|
-
);
|
|
998
|
-
const addInitObligationForFarm = true;
|
|
999
|
-
const twoTokenAction = true;
|
|
1000
|
-
const requestElevationGroup = false;
|
|
1001
|
-
const useV2Ixs = true;
|
|
1002
|
-
if (extraComputeBudget > 0) {
|
|
1003
|
-
axn.addComputeBudgetIx(extraComputeBudget);
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
await axn.addSupportIxs(
|
|
1007
|
-
'unstakeLstCollateralStart',
|
|
1008
|
-
includeAtaIxs,
|
|
1009
|
-
requestElevationGroup,
|
|
1010
|
-
addInitObligationForFarm,
|
|
1011
|
-
useV2Ixs,
|
|
1012
|
-
scopeRefreshConfig,
|
|
1013
|
-
initUserMetadata,
|
|
1014
|
-
twoTokenAction
|
|
1015
|
-
);
|
|
1016
|
-
await axn.addUnstakeLstCollateralStartIxs(depositStakedSolRemainingAccounts);
|
|
1017
|
-
|
|
1018
|
-
return axn;
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
941
|
static async buildWithdrawTxns(
|
|
1022
942
|
kaminoMarket: KaminoMarket,
|
|
1023
943
|
amount: string | BN,
|
|
@@ -1084,85 +1004,6 @@ export class KaminoAction {
|
|
|
1084
1004
|
return axn;
|
|
1085
1005
|
}
|
|
1086
1006
|
|
|
1087
|
-
static async buildWithdrawUsolTxns(
|
|
1088
|
-
kaminoMarket: KaminoMarket,
|
|
1089
|
-
amount: string | BN,
|
|
1090
|
-
mint: Address,
|
|
1091
|
-
owner: TransactionSigner,
|
|
1092
|
-
obligation: KaminoObligation | ObligationType,
|
|
1093
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined,
|
|
1094
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
|
|
1095
|
-
includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas,
|
|
1096
|
-
requestElevationGroup: boolean = false, // to be requested *after* the withdraw
|
|
1097
|
-
initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
|
|
1098
|
-
skipInitialization: false,
|
|
1099
|
-
skipLutCreation: false,
|
|
1100
|
-
},
|
|
1101
|
-
referrer: Option<Address> = none(),
|
|
1102
|
-
currentSlot: Slot = 0n,
|
|
1103
|
-
overrideElevationGroupRequest?: number,
|
|
1104
|
-
// Optional customizations which may be needed if the obligation was mutated by some previous ix.
|
|
1105
|
-
obligationCustomizations?: {
|
|
1106
|
-
// Any newly-added deposit reserves.
|
|
1107
|
-
addedDepositReserves?: Address[];
|
|
1108
|
-
},
|
|
1109
|
-
burnUsol: boolean = false
|
|
1110
|
-
) {
|
|
1111
|
-
const axn = await KaminoAction.initialize(
|
|
1112
|
-
'withdraw',
|
|
1113
|
-
amount,
|
|
1114
|
-
mint,
|
|
1115
|
-
owner,
|
|
1116
|
-
kaminoMarket,
|
|
1117
|
-
obligation,
|
|
1118
|
-
referrer,
|
|
1119
|
-
currentSlot,
|
|
1120
|
-
undefined,
|
|
1121
|
-
true
|
|
1122
|
-
);
|
|
1123
|
-
|
|
1124
|
-
if (extraComputeBudget > 0) {
|
|
1125
|
-
axn.addComputeBudgetIx(extraComputeBudget);
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
axn.depositReserves.push(...(obligationCustomizations?.addedDepositReserves || []));
|
|
1129
|
-
const addInitObligationForFarm = true;
|
|
1130
|
-
const useV2Ixs = true;
|
|
1131
|
-
await axn.addSupportIxs(
|
|
1132
|
-
'withdraw',
|
|
1133
|
-
includeAtaIxs,
|
|
1134
|
-
requestElevationGroup,
|
|
1135
|
-
addInitObligationForFarm,
|
|
1136
|
-
useV2Ixs,
|
|
1137
|
-
scopeRefreshConfig,
|
|
1138
|
-
initUserMetadata,
|
|
1139
|
-
false,
|
|
1140
|
-
overrideElevationGroupRequest
|
|
1141
|
-
);
|
|
1142
|
-
// We need user SOL ata to be initialized so they can receive the SOL
|
|
1143
|
-
// No need for other support ix (such as refresh reserve) as this burnUsolIx is called from unstaking pool
|
|
1144
|
-
if (burnUsol) {
|
|
1145
|
-
const [userAta, createUserTokenAccountIx] = await createAssociatedTokenAccountIdempotentInstruction(
|
|
1146
|
-
axn.owner,
|
|
1147
|
-
WRAPPED_SOL_MINT,
|
|
1148
|
-
axn.owner.address
|
|
1149
|
-
);
|
|
1150
|
-
|
|
1151
|
-
axn.setupIxs.unshift(createUserTokenAccountIx);
|
|
1152
|
-
axn.setupIxsLabels.unshift(`CreateLiquidityUserAta[${userAta}]`);
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
|
|
1156
|
-
const unstakeTicket = await axn.addWithdrawUsolIx(collateralAmount);
|
|
1157
|
-
if (burnUsol) {
|
|
1158
|
-
await axn.addBurnAllUsolIx(unstakeTicket);
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
1162
|
-
|
|
1163
|
-
return axn;
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
1007
|
/**
|
|
1167
1008
|
*
|
|
1168
1009
|
* @param kaminoMarket
|
|
@@ -1295,67 +1136,6 @@ export class KaminoAction {
|
|
|
1295
1136
|
return axn;
|
|
1296
1137
|
}
|
|
1297
1138
|
|
|
1298
|
-
static async buildUnstakeLstCollateralEndTxns(
|
|
1299
|
-
kaminoMarket: KaminoMarket,
|
|
1300
|
-
amount: string | BN,
|
|
1301
|
-
minCollateralReceiveAmount: string | BN,
|
|
1302
|
-
repayTokenMint: Address,
|
|
1303
|
-
withdrawTokenMint: Address,
|
|
1304
|
-
liquidator: TransactionSigner,
|
|
1305
|
-
obligationOwner: Address,
|
|
1306
|
-
obligation: KaminoObligation | ObligationType,
|
|
1307
|
-
scopeRefreshConfig: ScopePriceRefreshConfig | undefined = undefined,
|
|
1308
|
-
extraComputeBudget: number = 1_000_000, // if > 0 then adds the ix
|
|
1309
|
-
includeAtaIxs: boolean = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
|
|
1310
|
-
requestElevationGroup: boolean = false,
|
|
1311
|
-
initUserMetadata: { skipInitialization: boolean; skipLutCreation: boolean } = {
|
|
1312
|
-
skipInitialization: false,
|
|
1313
|
-
skipLutCreation: false,
|
|
1314
|
-
},
|
|
1315
|
-
referrer: Option<Address> = none(),
|
|
1316
|
-
maxAllowedLtvOverridePercent: number = 0,
|
|
1317
|
-
currentSlot: Slot = 0n,
|
|
1318
|
-
burnUsol: boolean = false
|
|
1319
|
-
): Promise<KaminoAction> {
|
|
1320
|
-
const axn = await KaminoAction.initializeMultiTokenAction(
|
|
1321
|
-
kaminoMarket,
|
|
1322
|
-
'liquidate',
|
|
1323
|
-
amount,
|
|
1324
|
-
repayTokenMint,
|
|
1325
|
-
withdrawTokenMint,
|
|
1326
|
-
liquidator,
|
|
1327
|
-
obligationOwner,
|
|
1328
|
-
obligation,
|
|
1329
|
-
minCollateralReceiveAmount,
|
|
1330
|
-
referrer,
|
|
1331
|
-
currentSlot,
|
|
1332
|
-
true
|
|
1333
|
-
);
|
|
1334
|
-
const addInitObligationForFarm = true;
|
|
1335
|
-
const useV2Ixs = true;
|
|
1336
|
-
|
|
1337
|
-
if (extraComputeBudget > 0) {
|
|
1338
|
-
axn.addComputeBudgetIx(extraComputeBudget);
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
await axn.addSupportIxs(
|
|
1342
|
-
'liquidate',
|
|
1343
|
-
includeAtaIxs,
|
|
1344
|
-
requestElevationGroup,
|
|
1345
|
-
addInitObligationForFarm,
|
|
1346
|
-
useV2Ixs,
|
|
1347
|
-
scopeRefreshConfig,
|
|
1348
|
-
initUserMetadata
|
|
1349
|
-
);
|
|
1350
|
-
const unstakeTicket = await axn.addUnstakeLstCollateralEndIx(maxAllowedLtvOverridePercent);
|
|
1351
|
-
if (burnUsol) {
|
|
1352
|
-
await axn.addBurnAllUsolIx(unstakeTicket);
|
|
1353
|
-
}
|
|
1354
|
-
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
1355
|
-
|
|
1356
|
-
return axn;
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
1139
|
static async buildWithdrawReferrerFeeTxns(
|
|
1360
1140
|
owner: TransactionSigner,
|
|
1361
1141
|
tokenMint: Address,
|
|
@@ -1537,128 +1317,6 @@ export class KaminoAction {
|
|
|
1537
1317
|
);
|
|
1538
1318
|
}
|
|
1539
1319
|
|
|
1540
|
-
async addUnstakeLstCollateralStartIxs(depositStakedSolRemainingAccounts: AccountMeta[]) {
|
|
1541
|
-
// Deposit USOL - our custom token issued by unstaking pool program
|
|
1542
|
-
// and withdraw some kind of staked sol
|
|
1543
|
-
this.lendingIxsLabels.push(
|
|
1544
|
-
`unstakeLstCollateral(depositReserve=${this.reserve!.address})(withdrawReserve=${
|
|
1545
|
-
this.outflowReserve!.address
|
|
1546
|
-
})(obligation=${this.getObligationPda()})`
|
|
1547
|
-
);
|
|
1548
|
-
|
|
1549
|
-
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1550
|
-
|
|
1551
|
-
const depositReserveAccountMetas: AccountMeta[] = depositReservesList.map((reserve) => {
|
|
1552
|
-
return { address: reserve, role: AccountRole.WRITABLE };
|
|
1553
|
-
});
|
|
1554
|
-
const borrowReserveAccountMetas: AccountMeta[] = this.borrowReserves.map((reserve) => {
|
|
1555
|
-
return { address: reserve, role: AccountRole.WRITABLE };
|
|
1556
|
-
});
|
|
1557
|
-
|
|
1558
|
-
if (!this.outflowReserve) {
|
|
1559
|
-
throw new Error(`outflowReserve not set`);
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
if (!this.unstakingPool || !this.unstakingPool.state) {
|
|
1563
|
-
throw new Error(`unstaking pool not set`);
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
|
-
const basePoolAuthority = (
|
|
1567
|
-
await unstakingPoolBaseAuthorityPda(this.unstakingPool.address, this.unstakingPool.programId)
|
|
1568
|
-
)[0];
|
|
1569
|
-
const ownerUsolToken = await this.getUserTokenAccountAddress(this.reserve);
|
|
1570
|
-
const ownerLstToken = await this.getUserTokenAccountAddress(this.outflowReserve);
|
|
1571
|
-
const unstakingPoolAuthority = (
|
|
1572
|
-
await unstakingPoolMarketAuthorityPda(this.kaminoMarket.address, this.kaminoMarket.programId)
|
|
1573
|
-
)[0];
|
|
1574
|
-
|
|
1575
|
-
const obligationPda = await this.getObligationPda();
|
|
1576
|
-
const { collateralFarmAccounts: depositFarmsAccounts } = await KaminoAction.getFarmAccountsForReserve(
|
|
1577
|
-
obligationPda,
|
|
1578
|
-
this.reserve
|
|
1579
|
-
);
|
|
1580
|
-
const { collateralFarmAccounts: withdrawFarmsAccounts } = await KaminoAction.getFarmAccountsForReserve(
|
|
1581
|
-
obligationPda,
|
|
1582
|
-
this.outflowReserve
|
|
1583
|
-
);
|
|
1584
|
-
|
|
1585
|
-
// Create unstake ticket
|
|
1586
|
-
const unstakeTicket = await generateKeyPairSigner();
|
|
1587
|
-
const unstakeTicketSize = UnstakeTicket.layout.span + 8;
|
|
1588
|
-
const createUnstakeTicketIx = getCreateAccountInstruction({
|
|
1589
|
-
payer: this.owner,
|
|
1590
|
-
newAccount: unstakeTicket,
|
|
1591
|
-
lamports: await this.kaminoMarket.getRpc().getMinimumBalanceForRentExemption(BigInt(unstakeTicketSize)).send(),
|
|
1592
|
-
space: unstakeTicketSize,
|
|
1593
|
-
programAddress: this.unstakingPool.programId,
|
|
1594
|
-
});
|
|
1595
|
-
this.lendingIxs.push(createUnstakeTicketIx);
|
|
1596
|
-
|
|
1597
|
-
const unstakeLstCollateralStartIx = unstakeLstCollateralStart(
|
|
1598
|
-
{
|
|
1599
|
-
lstToConvert: this.amount,
|
|
1600
|
-
},
|
|
1601
|
-
{
|
|
1602
|
-
depositAndWithdrawAccounts: {
|
|
1603
|
-
depositAccounts: {
|
|
1604
|
-
owner: this.owner,
|
|
1605
|
-
obligation: obligationPda,
|
|
1606
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1607
|
-
lendingMarketAuthority: await this.kaminoMarket.getLendingMarketAuthority(),
|
|
1608
|
-
reserve: this.reserve.address,
|
|
1609
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1610
|
-
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1611
|
-
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1612
|
-
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1613
|
-
userSourceLiquidity: ownerUsolToken,
|
|
1614
|
-
placeholderUserDestinationCollateral: none(),
|
|
1615
|
-
collateralTokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
1616
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1617
|
-
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_ADDRESS,
|
|
1618
|
-
},
|
|
1619
|
-
withdrawAccounts: {
|
|
1620
|
-
owner: this.owner,
|
|
1621
|
-
obligation: obligationPda,
|
|
1622
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1623
|
-
lendingMarketAuthority: await this.kaminoMarket.getLendingMarketAuthority(),
|
|
1624
|
-
withdrawReserve: this.outflowReserve.address,
|
|
1625
|
-
reserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1626
|
-
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1627
|
-
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1628
|
-
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
1629
|
-
userDestinationLiquidity: ownerLstToken,
|
|
1630
|
-
placeholderUserDestinationCollateral: none(),
|
|
1631
|
-
collateralTokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
1632
|
-
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1633
|
-
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_ADDRESS,
|
|
1634
|
-
},
|
|
1635
|
-
depositFarmsAccounts,
|
|
1636
|
-
withdrawFarmsAccounts,
|
|
1637
|
-
farmsProgram: FARMS_PROGRAM_ID,
|
|
1638
|
-
},
|
|
1639
|
-
depositStakedSolAccounts: {
|
|
1640
|
-
owner: this.owner,
|
|
1641
|
-
unstakingPoolAuthority,
|
|
1642
|
-
ownerStakedSolToken: ownerLstToken,
|
|
1643
|
-
ownerUnstakingSolToken: ownerUsolToken,
|
|
1644
|
-
stakedSolMint: this.outflowReserve.getLiquidityMint(),
|
|
1645
|
-
poolState: this.unstakingPool.address,
|
|
1646
|
-
unstakingSolMint: this.reserve.getLiquidityMint(),
|
|
1647
|
-
basePoolAuthority,
|
|
1648
|
-
systemProgram: SYSTEM_PROGRAM_ADDRESS,
|
|
1649
|
-
unstakingSolTokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
1650
|
-
stakedSolTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
1651
|
-
unstakeTicket: unstakeTicket.address,
|
|
1652
|
-
unstakingTicketBurnAuthority: unstakingPoolAuthority,
|
|
1653
|
-
},
|
|
1654
|
-
unstakingPoolProgram: this.unstakingPool.programId,
|
|
1655
|
-
},
|
|
1656
|
-
[...depositStakedSolRemainingAccounts, ...depositReserveAccountMetas, ...borrowReserveAccountMetas],
|
|
1657
|
-
this.kaminoMarket.programId
|
|
1658
|
-
);
|
|
1659
|
-
this.lendingIxs.push(unstakeLstCollateralStartIx);
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
1320
|
/// @deprecated -- use addDepositObligationCollateralIxV2 instead
|
|
1663
1321
|
async addDepositObligationCollateralIx() {
|
|
1664
1322
|
this.lendingIxsLabels.push(`depositObligationCollateral`);
|
|
@@ -1878,76 +1536,6 @@ export class KaminoAction {
|
|
|
1878
1536
|
);
|
|
1879
1537
|
}
|
|
1880
1538
|
|
|
1881
|
-
async addWithdrawUsolIx(collateralAmount: BN): Promise<Address> {
|
|
1882
|
-
if (!isKaminoObligation(this.obligation)) {
|
|
1883
|
-
throw new Error(`obligation is not a KaminoObligation`);
|
|
1884
|
-
}
|
|
1885
|
-
if (!this.unstakingPool || !this.unstakingPool.state) {
|
|
1886
|
-
throw new Error(`unstaking pool not set`);
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1889
|
-
const obligationAddress = await this.getObligationPda();
|
|
1890
|
-
const { collateralFarmAccounts: farmsAccounts } = await KaminoAction.getFarmAccountsForReserve(
|
|
1891
|
-
obligationAddress,
|
|
1892
|
-
this.reserve
|
|
1893
|
-
);
|
|
1894
|
-
this.lendingIxsLabels.push(`withdrawUsol`);
|
|
1895
|
-
|
|
1896
|
-
const newUnstakeTicket = await generateKeyPairSigner();
|
|
1897
|
-
const unstakeTicketSize = UnstakeTicket.layout.span + 8;
|
|
1898
|
-
const createUnstakeTicketIx = getCreateAccountInstruction({
|
|
1899
|
-
payer: this.owner,
|
|
1900
|
-
newAccount: newUnstakeTicket,
|
|
1901
|
-
lamports: await this.kaminoMarket.getRpc().getMinimumBalanceForRentExemption(BigInt(unstakeTicketSize)).send(),
|
|
1902
|
-
space: unstakeTicketSize,
|
|
1903
|
-
programAddress: this.unstakingPool.programId,
|
|
1904
|
-
});
|
|
1905
|
-
this.lendingIxs.push(createUnstakeTicketIx);
|
|
1906
|
-
|
|
1907
|
-
const unstakingPoolAuthority = (
|
|
1908
|
-
await unstakingPoolMarketAuthorityPda(this.kaminoMarket.address, this.kaminoMarket.programId)
|
|
1909
|
-
)[0];
|
|
1910
|
-
this.lendingIxs.push(
|
|
1911
|
-
withdrawObligationUsol(
|
|
1912
|
-
{
|
|
1913
|
-
collateralAmount,
|
|
1914
|
-
},
|
|
1915
|
-
{
|
|
1916
|
-
withdrawAccounts: {
|
|
1917
|
-
withdrawAccounts: {
|
|
1918
|
-
owner: this.owner,
|
|
1919
|
-
obligation: obligationAddress,
|
|
1920
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1921
|
-
lendingMarketAuthority: await this.kaminoMarket.getLendingMarketAuthority(),
|
|
1922
|
-
withdrawReserve: this.reserve.address,
|
|
1923
|
-
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1924
|
-
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1925
|
-
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1926
|
-
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
1927
|
-
userDestinationLiquidity: await this.getUserTokenAccountAddress(this.reserve),
|
|
1928
|
-
placeholderUserDestinationCollateral: none(),
|
|
1929
|
-
collateralTokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
1930
|
-
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1931
|
-
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_ADDRESS,
|
|
1932
|
-
},
|
|
1933
|
-
farmsAccounts: farmsAccounts,
|
|
1934
|
-
farmsProgram: FARMS_PROGRAM_ID,
|
|
1935
|
-
},
|
|
1936
|
-
extraAccounts: {
|
|
1937
|
-
unstakeTicket: this.obligation.state.unstakeTicket,
|
|
1938
|
-
emptyUnstakeTicket: newUnstakeTicket.address,
|
|
1939
|
-
unstakingPoolAuthority: unstakingPoolAuthority,
|
|
1940
|
-
unstakingPoolProgram: this.unstakingPool.programId,
|
|
1941
|
-
systemProgram: SYSTEM_PROGRAM_ADDRESS,
|
|
1942
|
-
},
|
|
1943
|
-
},
|
|
1944
|
-
[],
|
|
1945
|
-
this.kaminoMarket.programId
|
|
1946
|
-
)
|
|
1947
|
-
);
|
|
1948
|
-
return newUnstakeTicket.address;
|
|
1949
|
-
}
|
|
1950
|
-
|
|
1951
1539
|
/// @deprecated -- use addRepayIxV2 instead
|
|
1952
1540
|
async addRepayIx() {
|
|
1953
1541
|
const obligationAddress = await this.getObligationPda();
|
|
@@ -2553,39 +2141,6 @@ export class KaminoAction {
|
|
|
2553
2141
|
);
|
|
2554
2142
|
}
|
|
2555
2143
|
|
|
2556
|
-
async addBurnAllUsolIx(unstakeTicket: Address): Promise<void> {
|
|
2557
|
-
this.lendingIxsLabels.push(`burnUsolIx`);
|
|
2558
|
-
if (!this.unstakingPool || !this.unstakingPool.state) {
|
|
2559
|
-
throw new Error(`unstaking pool not set`);
|
|
2560
|
-
}
|
|
2561
|
-
|
|
2562
|
-
this.lendingIxs.push(
|
|
2563
|
-
burn(
|
|
2564
|
-
{
|
|
2565
|
-
sharesToBurn: new BN(U64_MAX),
|
|
2566
|
-
minWsolToReceive: new BN(0), // TODO: find a way to compute a reasonable slippage
|
|
2567
|
-
},
|
|
2568
|
-
{
|
|
2569
|
-
user: this.owner,
|
|
2570
|
-
userUnstakingSolToken: await getAssociatedTokenAddress(
|
|
2571
|
-
this.unstakingPool.state.unstakingSolMint,
|
|
2572
|
-
this.owner.address,
|
|
2573
|
-
TOKEN_PROGRAM_ADDRESS
|
|
2574
|
-
),
|
|
2575
|
-
userWsolToken: await getAssociatedTokenAddress(WRAPPED_SOL_MINT, this.owner.address, TOKEN_PROGRAM_ADDRESS),
|
|
2576
|
-
wsolVault: this.unstakingPool.state.wsolVault,
|
|
2577
|
-
wsolMint: WRAPPED_SOL_MINT,
|
|
2578
|
-
poolState: this.unstakingPool.address,
|
|
2579
|
-
unstakeTicket,
|
|
2580
|
-
unstakingSolMint: this.unstakingPool.state.unstakingSolMint,
|
|
2581
|
-
basePoolAuthority: this.unstakingPool.state.basePoolAuthority,
|
|
2582
|
-
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
2583
|
-
},
|
|
2584
|
-
this.unstakingPool.programId
|
|
2585
|
-
)
|
|
2586
|
-
);
|
|
2587
|
-
}
|
|
2588
|
-
|
|
2589
2144
|
async addLiquidateIx(maxAllowedLtvOverridePercent: number = 0): Promise<void> {
|
|
2590
2145
|
this.lendingIxsLabels.push(`liquidateObligationAndRedeemReserveCollateral`);
|
|
2591
2146
|
if (!this.outflowReserve) {
|
|
@@ -2715,100 +2270,6 @@ export class KaminoAction {
|
|
|
2715
2270
|
this.lendingIxs.push(liquidateIx);
|
|
2716
2271
|
}
|
|
2717
2272
|
|
|
2718
|
-
async addUnstakeLstCollateralEndIx(maxAllowedLtvOverridePercent: number = 0): Promise<Address> {
|
|
2719
|
-
this.lendingIxsLabels.push(`unstakeLstCollateralEnd`);
|
|
2720
|
-
if (!this.outflowReserve) {
|
|
2721
|
-
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
2722
|
-
}
|
|
2723
|
-
|
|
2724
|
-
if (!isKaminoObligation(this.obligation)) {
|
|
2725
|
-
throw new Error(`obligation is not a KaminoObligation`);
|
|
2726
|
-
}
|
|
2727
|
-
|
|
2728
|
-
if (!this.unstakingPool || !this.unstakingPool.state) {
|
|
2729
|
-
throw new Error(`unstaking pool not set`);
|
|
2730
|
-
}
|
|
2731
|
-
|
|
2732
|
-
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
2733
|
-
const depositReserveAccountMetas: AccountMeta[] = depositReservesList.map((reserve) => {
|
|
2734
|
-
return { address: reserve, role: AccountRole.WRITABLE };
|
|
2735
|
-
});
|
|
2736
|
-
|
|
2737
|
-
const obligationAddress = await this.getObligationPda();
|
|
2738
|
-
const { collateralFarmAccounts: collateralFarmsAccounts } = await KaminoAction.getFarmAccountsForReserve(
|
|
2739
|
-
obligationAddress,
|
|
2740
|
-
this.outflowReserve
|
|
2741
|
-
);
|
|
2742
|
-
const { debtFarmAccounts: debtFarmsAccounts } = await KaminoAction.getFarmAccountsForReserve(
|
|
2743
|
-
await this.getObligationPda(),
|
|
2744
|
-
this.reserve
|
|
2745
|
-
);
|
|
2746
|
-
|
|
2747
|
-
const newUnstakeTicket = await generateKeyPairSigner();
|
|
2748
|
-
const unstakeTicketSize = UnstakeTicket.layout.span + 8;
|
|
2749
|
-
const createUnstakeTicketIx = getCreateAccountInstruction({
|
|
2750
|
-
payer: this.owner,
|
|
2751
|
-
newAccount: newUnstakeTicket,
|
|
2752
|
-
lamports: await this.kaminoMarket.getRpc().getMinimumBalanceForRentExemption(BigInt(unstakeTicketSize)).send(),
|
|
2753
|
-
space: unstakeTicketSize,
|
|
2754
|
-
programAddress: this.unstakingPool.programId,
|
|
2755
|
-
});
|
|
2756
|
-
this.lendingIxs.push(createUnstakeTicketIx);
|
|
2757
|
-
|
|
2758
|
-
const unstakingPoolAuthority = (
|
|
2759
|
-
await unstakingPoolMarketAuthorityPda(this.kaminoMarket.address, this.kaminoMarket.programId)
|
|
2760
|
-
)[0];
|
|
2761
|
-
const extraAccounts = this.obligation!.state.elevationGroup > 0 ? depositReserveAccountMetas : [];
|
|
2762
|
-
const liquidateIx = unstakeLstCollateralEnd(
|
|
2763
|
-
{
|
|
2764
|
-
liquidityAmount: this.amount,
|
|
2765
|
-
// TODO: Configure this when updating liquidator with new interface
|
|
2766
|
-
minAcceptableReceivedLiquidityAmount: this.outflowAmount || new BN(0),
|
|
2767
|
-
maxAllowedLtvOverridePercent: new BN(maxAllowedLtvOverridePercent),
|
|
2768
|
-
},
|
|
2769
|
-
{
|
|
2770
|
-
liquidationAccounts: {
|
|
2771
|
-
liquidationAccounts: {
|
|
2772
|
-
liquidator: this.owner,
|
|
2773
|
-
obligation: obligationAddress,
|
|
2774
|
-
lendingMarket: this.kaminoMarket.getAddress(),
|
|
2775
|
-
lendingMarketAuthority: await this.kaminoMarket.getLendingMarketAuthority(),
|
|
2776
|
-
repayReserve: this.reserve.address,
|
|
2777
|
-
repayReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
2778
|
-
repayReserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
2779
|
-
withdrawReserve: this.outflowReserve.address,
|
|
2780
|
-
withdrawReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
2781
|
-
withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
2782
|
-
withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
|
|
2783
|
-
withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
2784
|
-
userSourceLiquidity: await this.getUserTokenAccountAddress(this.reserve),
|
|
2785
|
-
userDestinationCollateral: await this.getUserCollateralAccountAddress(this.outflowReserve),
|
|
2786
|
-
userDestinationLiquidity: await this.getUserTokenAccountAddress(this.outflowReserve),
|
|
2787
|
-
withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
2788
|
-
collateralTokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
2789
|
-
repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
2790
|
-
withdrawLiquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
2791
|
-
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_ADDRESS,
|
|
2792
|
-
},
|
|
2793
|
-
debtFarmsAccounts,
|
|
2794
|
-
collateralFarmsAccounts,
|
|
2795
|
-
farmsProgram: FARMS_PROGRAM_ID,
|
|
2796
|
-
},
|
|
2797
|
-
extraAccounts: {
|
|
2798
|
-
unstakeTicket: this.obligation.state.unstakeTicket,
|
|
2799
|
-
emptyUnstakeTicket: newUnstakeTicket.address,
|
|
2800
|
-
unstakingPoolAuthority: unstakingPoolAuthority,
|
|
2801
|
-
unstakingPoolProgram: this.unstakingPool.programId,
|
|
2802
|
-
systemProgram: SYSTEM_PROGRAM_ADDRESS,
|
|
2803
|
-
},
|
|
2804
|
-
},
|
|
2805
|
-
extraAccounts,
|
|
2806
|
-
this.kaminoMarket.programId
|
|
2807
|
-
);
|
|
2808
|
-
this.lendingIxs.push(liquidateIx);
|
|
2809
|
-
return newUnstakeTicket.address;
|
|
2810
|
-
}
|
|
2811
|
-
|
|
2812
2273
|
async addInBetweenIxs(
|
|
2813
2274
|
action: ActionType,
|
|
2814
2275
|
includeAtaIxs: boolean,
|
|
@@ -2877,7 +2338,6 @@ export class KaminoAction {
|
|
|
2877
2338
|
'repayAndWithdrawV2',
|
|
2878
2339
|
'refreshObligation',
|
|
2879
2340
|
'depositAndWithdraw',
|
|
2880
|
-
'unstakeLstCollateralStart',
|
|
2881
2341
|
].includes(action)
|
|
2882
2342
|
) {
|
|
2883
2343
|
// The support ixs in order are:
|
|
@@ -2899,21 +2359,15 @@ export class KaminoAction {
|
|
|
2899
2359
|
action === 'liquidate' ||
|
|
2900
2360
|
action === 'depositAndBorrow' ||
|
|
2901
2361
|
action === 'repayAndWithdraw' ||
|
|
2902
|
-
action === 'repayAndWithdrawV2'
|
|
2903
|
-
action === 'unstakeLstCollateralStart'
|
|
2362
|
+
action === 'repayAndWithdrawV2'
|
|
2904
2363
|
) {
|
|
2905
2364
|
if (!this.outflowReserve) {
|
|
2906
2365
|
throw new Error('outflowReserve is undefined');
|
|
2907
2366
|
}
|
|
2908
2367
|
|
|
2909
|
-
if (
|
|
2910
|
-
action === 'depositAndBorrow' ||
|
|
2911
|
-
action === 'repayAndWithdraw' ||
|
|
2912
|
-
action === 'repayAndWithdrawV2' ||
|
|
2913
|
-
action === 'unstakeLstCollateralStart'
|
|
2914
|
-
) {
|
|
2368
|
+
if (action === 'depositAndBorrow' || action === 'repayAndWithdraw' || action === 'repayAndWithdrawV2') {
|
|
2915
2369
|
currentReserves = [this.reserve, this.outflowReserve];
|
|
2916
|
-
if (action === 'depositAndBorrow'
|
|
2370
|
+
if (action === 'depositAndBorrow') {
|
|
2917
2371
|
if (isKaminoObligation(this.obligation)) {
|
|
2918
2372
|
const deposit = this.obligation.getDepositByReserve(this.reserve.address);
|
|
2919
2373
|
if (!deposit) {
|
|
@@ -2968,11 +2422,6 @@ export class KaminoAction {
|
|
|
2968
2422
|
if (this.outflowReserve) {
|
|
2969
2423
|
await this.addInitObligationForFarm(this.outflowReserve, ReserveFarmKind.Collateral, addAsSupportIx);
|
|
2970
2424
|
}
|
|
2971
|
-
} else if (action === 'unstakeLstCollateralStart') {
|
|
2972
|
-
await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Collateral, addAsSupportIx);
|
|
2973
|
-
if (this.outflowReserve) {
|
|
2974
|
-
await this.addInitObligationForFarm(this.outflowReserve, ReserveFarmKind.Collateral, addAsSupportIx);
|
|
2975
|
-
}
|
|
2976
2425
|
} else {
|
|
2977
2426
|
await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Collateral, addAsSupportIx);
|
|
2978
2427
|
await this.addInitObligationForFarm(this.reserve, ReserveFarmKind.Debt, addAsSupportIx);
|
|
@@ -2996,12 +2445,6 @@ export class KaminoAction {
|
|
|
2996
2445
|
? [repayObligationLiquidity.reserveAddress]
|
|
2997
2446
|
: [];
|
|
2998
2447
|
await this.addRefreshObligationIx(addAsSupportIx, repaidBorrowReservesToSkip);
|
|
2999
|
-
} else if (action == 'unstakeLstCollateralStart') {
|
|
3000
|
-
if (!isKaminoObligation(this.obligation)) {
|
|
3001
|
-
throw new Error(`obligation is not a KaminoObligation`);
|
|
3002
|
-
}
|
|
3003
|
-
// Usol reserve doesn't exist yet
|
|
3004
|
-
await this.addRefreshObligationIx(addAsSupportIx, [this.reserve.address]);
|
|
3005
2448
|
} else {
|
|
3006
2449
|
await this.addRefreshObligationIx(addAsSupportIx);
|
|
3007
2450
|
}
|
|
@@ -3910,8 +3353,7 @@ export class KaminoAction {
|
|
|
3910
3353
|
obligation: KaminoObligation | ObligationType,
|
|
3911
3354
|
outflowAmount?: string | BN,
|
|
3912
3355
|
referrer: Option<Address> = none(),
|
|
3913
|
-
currentSlot: Slot = 0n
|
|
3914
|
-
needsUnstakingPool: boolean = false
|
|
3356
|
+
currentSlot: Slot = 0n
|
|
3915
3357
|
) {
|
|
3916
3358
|
const inflowReserve = kaminoMarket.getExistingReserveByMint(inflowTokenMint);
|
|
3917
3359
|
const outflowReserve = kaminoMarket.getExistingReserveByMint(outflowTokenMint);
|
|
@@ -3929,24 +3371,15 @@ export class KaminoAction {
|
|
|
3929
3371
|
|
|
3930
3372
|
let secondaryMint: Address;
|
|
3931
3373
|
let primaryMint: Address;
|
|
3932
|
-
let unstakingPool: UnstakingPool | undefined = undefined;
|
|
3933
3374
|
|
|
3934
3375
|
if (
|
|
3935
3376
|
action === 'liquidate' ||
|
|
3936
3377
|
action === 'depositAndBorrow' ||
|
|
3937
3378
|
action === 'repayAndWithdraw' ||
|
|
3938
|
-
action === 'repayAndWithdrawV2'
|
|
3939
|
-
action === 'unstakeLstCollateralStart'
|
|
3379
|
+
action === 'repayAndWithdrawV2'
|
|
3940
3380
|
) {
|
|
3941
3381
|
primaryMint = inflowTokenMint;
|
|
3942
3382
|
secondaryMint = outflowTokenMint;
|
|
3943
|
-
if (needsUnstakingPool) {
|
|
3944
|
-
const unstakingPoolPk = kaminoMarket.state.unstakingPoolState;
|
|
3945
|
-
const unstakingPoolProgramId =
|
|
3946
|
-
kaminoMarket.programId == PROGRAM_ID ? UNSTAKING_POOL_ID : UNSTAKING_POOL_STAGING_ID;
|
|
3947
|
-
unstakingPool = new UnstakingPool(unstakingPoolPk, undefined, unstakingPoolProgramId);
|
|
3948
|
-
await unstakingPool.reloadState(kaminoMarket.getRpc());
|
|
3949
|
-
}
|
|
3950
3383
|
} else {
|
|
3951
3384
|
throw new Error('Invalid action');
|
|
3952
3385
|
}
|
|
@@ -3962,7 +3395,6 @@ export class KaminoAction {
|
|
|
3962
3395
|
borrowReserves,
|
|
3963
3396
|
inflowReserve,
|
|
3964
3397
|
currentSlot,
|
|
3965
|
-
unstakingPool,
|
|
3966
3398
|
secondaryMint,
|
|
3967
3399
|
outflowReserve,
|
|
3968
3400
|
outflowAmount,
|
|
@@ -4004,7 +3436,6 @@ export class KaminoAction {
|
|
|
4004
3436
|
undefined,
|
|
4005
3437
|
undefined,
|
|
4006
3438
|
undefined,
|
|
4007
|
-
undefined,
|
|
4008
3439
|
undefined
|
|
4009
3440
|
),
|
|
4010
3441
|
createAtaIxs: [createAtaIx],
|