@kamino-finance/klend-sdk 7.1.2 → 7.1.4-beta.0
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 +144 -3
- package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/LendingMarket.js +105 -3
- package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
- package/dist/@codegen/klend/accounts/Obligation.d.ts +30 -15
- package/dist/@codegen/klend/accounts/Obligation.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/Obligation.js +31 -21
- package/dist/@codegen/klend/accounts/Obligation.js.map +1 -1
- package/dist/@codegen/klend/accounts/PoolState.d.ts +53 -0
- package/dist/@codegen/klend/accounts/PoolState.d.ts.map +1 -0
- package/dist/@codegen/klend/accounts/PoolState.js +167 -0
- package/dist/@codegen/klend/accounts/PoolState.js.map +1 -0
- package/dist/@codegen/klend/accounts/Reserve.d.ts +6 -0
- package/dist/@codegen/klend/accounts/Reserve.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/Reserve.js +9 -2
- package/dist/@codegen/klend/accounts/Reserve.js.map +1 -1
- package/dist/@codegen/klend/accounts/UnstakeTicket.d.ts +41 -0
- package/dist/@codegen/klend/accounts/UnstakeTicket.d.ts.map +1 -0
- package/dist/@codegen/klend/accounts/UnstakeTicket.js +143 -0
- package/dist/@codegen/klend/accounts/UnstakeTicket.js.map +1 -0
- package/dist/@codegen/klend/accounts/UserState.d.ts +0 -75
- package/dist/@codegen/klend/accounts/UserState.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/UserState.js +0 -25
- package/dist/@codegen/klend/accounts/UserState.js.map +1 -1
- package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts +132 -0
- package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts.map +1 -0
- package/dist/@codegen/klend/accounts/WithdrawTicket.js +191 -0
- package/dist/@codegen/klend/accounts/WithdrawTicket.js.map +1 -0
- package/dist/@codegen/klend/accounts/index.d.ts +6 -0
- package/dist/@codegen/klend/accounts/index.d.ts.map +1 -1
- package/dist/@codegen/klend/accounts/index.js +7 -1
- package/dist/@codegen/klend/accounts/index.js.map +1 -1
- package/dist/@codegen/klend/errors/custom.d.ts +226 -2
- package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
- package/dist/@codegen/klend/errors/custom.js +396 -3
- package/dist/@codegen/klend/errors/custom.js.map +1 -1
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts +39 -0
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.js +67 -0
- package/dist/@codegen/klend/instructions/enqueueToWithdraw.js.map +1 -0
- package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts +36 -0
- package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/fillBorrowOrder.js +49 -0
- package/dist/@codegen/klend/instructions/fillBorrowOrder.js.map +1 -0
- package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts +1 -2
- package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/idlMissingTypes.js +6 -2
- package/dist/@codegen/klend/instructions/idlMissingTypes.js.map +1 -1
- package/dist/@codegen/klend/instructions/index.d.ts +16 -0
- package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
- package/dist/@codegen/klend/instructions/index.js +18 -1
- 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 +1 -5
- package/dist/@codegen/klend/instructions/initReserve.js.map +1 -1
- package/dist/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateral.js +1 -1
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts +47 -0
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js +66 -0
- package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js.map +1 -0
- package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts +31 -0
- package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/setBorrowOrder.js +64 -0
- package/dist/@codegen/klend/instructions/setBorrowOrder.js.map +1 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.d.ts +53 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.js +190 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.js.map +1 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.d.ts +70 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.js +261 -0
- package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.js.map +1 -0
- 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 +1 -0
- 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 +1 -0
- 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/instructions/withdrawObligationUsol.d.ts +41 -0
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.js +135 -0
- package/dist/@codegen/klend/instructions/withdrawObligationUsol.js.map +1 -0
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts +51 -0
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts.map +1 -0
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js +28 -0
- package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrder.d.ts +192 -0
- package/dist/@codegen/klend/types/BorrowOrder.d.ts.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrder.js +194 -0
- package/dist/@codegen/klend/types/BorrowOrder.js.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts +39 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts.map +1 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js +100 -0
- package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js.map +1 -0
- package/dist/@codegen/klend/types/ObligationLiquidity.d.ts +35 -5
- package/dist/@codegen/klend/types/ObligationLiquidity.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ObligationLiquidity.js +17 -7
- 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 +141 -29
- package/dist/@codegen/klend/types/ReserveConfig.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveConfig.js +89 -25
- 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 +26 -8
- package/dist/@codegen/klend/types/ReserveLiquidity.d.ts.map +1 -1
- package/dist/@codegen/klend/types/ReserveLiquidity.js +14 -8
- package/dist/@codegen/klend/types/ReserveLiquidity.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts +92 -14
- package/dist/@codegen/klend/types/UpdateConfigMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateConfigMode.js +168 -23
- package/dist/@codegen/klend/types/UpdateConfigMode.js.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +130 -0
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +241 -1
- package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
- package/dist/@codegen/klend/types/WithdrawQueue.d.ts +64 -0
- package/dist/@codegen/klend/types/WithdrawQueue.d.ts.map +1 -0
- package/dist/@codegen/klend/types/WithdrawQueue.js +104 -0
- package/dist/@codegen/klend/types/WithdrawQueue.js.map +1 -0
- package/dist/@codegen/klend/types/index.d.ts +10 -8
- package/dist/@codegen/klend/types/index.d.ts.map +1 -1
- package/dist/@codegen/klend/types/index.js +7 -3
- package/dist/@codegen/klend/types/index.js.map +1 -1
- package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts +9 -4
- package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts.map +1 -1
- package/dist/@codegen/klend/zero_padding/ObligationZP.js +22 -13
- package/dist/@codegen/klend/zero_padding/ObligationZP.js.map +1 -1
- package/dist/classes/action.d.ts +30 -3
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +364 -10
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +10 -0
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +6 -2
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +26 -6
- 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 +13 -7
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/unstakingPool.d.ts +20 -3
- package/dist/classes/unstakingPool.d.ts.map +1 -1
- package/dist/classes/unstakingPool.js +62 -8
- package/dist/classes/unstakingPool.js.map +1 -1
- package/dist/idl/klend.json +2125 -232
- package/dist/lending_operations/index.d.ts +1 -0
- package/dist/lending_operations/index.d.ts.map +1 -1
- package/dist/lending_operations/index.js +1 -0
- package/dist/lending_operations/index.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +0 -2
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +0 -1
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/lending_operations/unstake_lst_collateral.d.ts +12 -0
- package/dist/lending_operations/unstake_lst_collateral.d.ts.map +1 -0
- package/dist/lending_operations/unstake_lst_collateral.js +104 -0
- package/dist/lending_operations/unstake_lst_collateral.js.map +1 -0
- package/dist/leverage/calcs.d.ts +2 -27
- package/dist/leverage/calcs.d.ts.map +1 -1
- package/dist/leverage/calcs.js +6 -136
- package/dist/leverage/calcs.js.map +1 -1
- package/dist/leverage/operations.d.ts +8 -9
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +72 -228
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +0 -19
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/leverage/utils.d.ts +2 -19
- package/dist/leverage/utils.d.ts.map +1 -1
- package/dist/leverage/utils.js +0 -164
- package/dist/leverage/utils.js.map +1 -1
- package/dist/manager/client_kamino_manager.js +11 -8
- package/dist/manager/client_kamino_manager.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +9 -4
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/seeds.d.ts +10 -14
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +25 -22
- package/dist/utils/seeds.js.map +1 -1
- package/package.json +2 -2
- package/src/@codegen/klend/accounts/LendingMarket.ts +210 -5
- package/src/@codegen/klend/accounts/Obligation.ts +53 -31
- package/src/@codegen/klend/accounts/PoolState.ts +192 -0
- package/src/@codegen/klend/accounts/Reserve.ts +13 -2
- package/src/@codegen/klend/accounts/UnstakeTicket.ts +160 -0
- package/src/@codegen/klend/accounts/UserState.ts +0 -75
- package/src/@codegen/klend/accounts/WithdrawTicket.ts +256 -0
- package/src/@codegen/klend/accounts/index.ts +6 -0
- package/src/@codegen/klend/errors/custom.ts +427 -2
- package/src/@codegen/klend/instructions/enqueueToWithdraw.ts +89 -0
- package/src/@codegen/klend/instructions/fillBorrowOrder.ts +96 -0
- package/src/@codegen/klend/instructions/idlMissingTypes.ts +7 -4
- package/src/@codegen/klend/instructions/index.ts +34 -0
- package/src/@codegen/klend/instructions/initReserve.ts +2 -6
- package/src/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateral.ts +1 -1
- package/src/@codegen/klend/instructions/recoverInvalidTicketCollateral.ts +96 -0
- package/src/@codegen/klend/instructions/setBorrowOrder.ts +77 -0
- package/src/@codegen/klend/instructions/unstakeLstCollateralEnd.ts +251 -0
- package/src/@codegen/klend/instructions/unstakeLstCollateralStart.ts +353 -0
- package/src/@codegen/klend/instructions/updateGlobalConfig.ts +2 -1
- package/src/@codegen/klend/instructions/updateReserveConfig.ts +2 -1
- package/src/@codegen/klend/instructions/withdrawObligationCollateral.ts +1 -1
- package/src/@codegen/klend/instructions/withdrawObligationCollateralV2.ts +1 -1
- package/src/@codegen/klend/instructions/withdrawObligationUsol.ts +168 -0
- package/src/@codegen/klend/instructions/withdrawQueuedLiquidity.ts +92 -0
- package/src/@codegen/klend/types/BorrowOrder.ts +267 -0
- package/src/@codegen/klend/types/BorrowOrderConfigArgs.ts +87 -0
- package/src/@codegen/klend/types/ObligationLiquidity.ts +39 -9
- package/src/@codegen/klend/types/ObligationOrder.ts +4 -4
- package/src/@codegen/klend/types/ReserveConfig.ts +171 -39
- package/src/@codegen/klend/types/ReserveFees.ts +12 -12
- package/src/@codegen/klend/types/ReserveLiquidity.ts +30 -12
- package/src/@codegen/klend/types/UpdateConfigMode.ts +206 -26
- package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +300 -0
- package/src/@codegen/klend/types/WithdrawQueue.ts +117 -0
- package/src/@codegen/klend/types/index.ts +45 -16
- package/src/@codegen/klend/zero_padding/ObligationZP.ts +22 -13
- package/src/classes/action.ts +577 -8
- package/src/classes/manager.ts +11 -0
- package/src/classes/market.ts +36 -5
- package/src/classes/obligation.ts +1 -1
- package/src/classes/reserve.ts +13 -8
- package/src/classes/unstakingPool.ts +83 -6
- package/src/idl/klend.json +2126 -233
- package/src/lending_operations/index.ts +1 -0
- package/src/lending_operations/repay_with_collateral_operations.ts +0 -2
- package/src/lending_operations/swap_collateral_operations.ts +0 -1
- package/src/lending_operations/unstake_lst_collateral.ts +174 -0
- package/src/leverage/calcs.ts +2 -201
- package/src/leverage/operations.ts +45 -377
- package/src/leverage/types.ts +0 -20
- package/src/leverage/utils.ts +3 -320
- package/src/manager/client_kamino_manager.ts +11 -8
- package/src/utils/managerTypes.ts +9 -4
- package/src/utils/seeds.ts +28 -26
- package/dist/@codegen/klend/types/AssetTier.d.ts +0 -45
- package/dist/@codegen/klend/types/AssetTier.d.ts.map +0 -1
- package/dist/@codegen/klend/types/AssetTier.js +0 -132
- package/dist/@codegen/klend/types/AssetTier.js.map +0 -1
- package/src/@codegen/klend/types/AssetTier.ts +0 -119
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import {
|
|
3
|
+
address,
|
|
4
|
+
Address,
|
|
5
|
+
fetchEncodedAccount,
|
|
6
|
+
fetchEncodedAccounts,
|
|
7
|
+
GetAccountInfoApi,
|
|
8
|
+
GetMultipleAccountsApi,
|
|
9
|
+
Rpc,
|
|
10
|
+
} from "@solana/kit"
|
|
11
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
12
|
+
import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
13
|
+
import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
14
|
+
import { borshAddress } from "../utils" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
15
|
+
import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
16
|
+
import { PROGRAM_ID } from "../programId"
|
|
17
|
+
|
|
18
|
+
export interface WithdrawTicketFields {
|
|
19
|
+
/** This ticket's place in the queue; the same as used for PDA derivation. */
|
|
20
|
+
sequenceNumber: BN
|
|
21
|
+
/** The funds' owner (the user who called the `enqueue_to_withdraw` handler). */
|
|
22
|
+
owner: Address
|
|
23
|
+
/** The reserve to withdraw from. */
|
|
24
|
+
reserve: Address
|
|
25
|
+
/**
|
|
26
|
+
* The token account to which the finally-available liquidity should be transferred (by the
|
|
27
|
+
* `withdraw_queued_liquidity` handler).
|
|
28
|
+
*/
|
|
29
|
+
userDestinationLiquidityTa: Address
|
|
30
|
+
/** The amount of collateral still waiting to be withdrawn using this ticket. */
|
|
31
|
+
queuedCollateralAmount: BN
|
|
32
|
+
/**
|
|
33
|
+
* The timestamp at which the queue was entered.
|
|
34
|
+
*
|
|
35
|
+
* This is currently only a piece of metadata, not used by the logic.
|
|
36
|
+
*/
|
|
37
|
+
createdAtTimestamp: BN
|
|
38
|
+
/**
|
|
39
|
+
* Whether the ticket has been found to be invalid (e.g. the [Self::user_destination_liquidity]
|
|
40
|
+
* has been repurposed) by the `withdraw_queued_liquidity` handler.
|
|
41
|
+
* To be specific: valid = `0`, invalid = `1`.
|
|
42
|
+
*
|
|
43
|
+
* An invalid ticket cannot be made valid again, and can only be passed to the
|
|
44
|
+
* `recover_invalid_ticket_collateral` handler.
|
|
45
|
+
*/
|
|
46
|
+
invalid: number
|
|
47
|
+
/** Inner padding, for alignment. */
|
|
48
|
+
alignmentPadding: Array<number>
|
|
49
|
+
/** Trailing padding, for future developments. */
|
|
50
|
+
endPadding: Array<BN>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface WithdrawTicketJSON {
|
|
54
|
+
/** This ticket's place in the queue; the same as used for PDA derivation. */
|
|
55
|
+
sequenceNumber: string
|
|
56
|
+
/** The funds' owner (the user who called the `enqueue_to_withdraw` handler). */
|
|
57
|
+
owner: string
|
|
58
|
+
/** The reserve to withdraw from. */
|
|
59
|
+
reserve: string
|
|
60
|
+
/**
|
|
61
|
+
* The token account to which the finally-available liquidity should be transferred (by the
|
|
62
|
+
* `withdraw_queued_liquidity` handler).
|
|
63
|
+
*/
|
|
64
|
+
userDestinationLiquidityTa: string
|
|
65
|
+
/** The amount of collateral still waiting to be withdrawn using this ticket. */
|
|
66
|
+
queuedCollateralAmount: string
|
|
67
|
+
/**
|
|
68
|
+
* The timestamp at which the queue was entered.
|
|
69
|
+
*
|
|
70
|
+
* This is currently only a piece of metadata, not used by the logic.
|
|
71
|
+
*/
|
|
72
|
+
createdAtTimestamp: string
|
|
73
|
+
/**
|
|
74
|
+
* Whether the ticket has been found to be invalid (e.g. the [Self::user_destination_liquidity]
|
|
75
|
+
* has been repurposed) by the `withdraw_queued_liquidity` handler.
|
|
76
|
+
* To be specific: valid = `0`, invalid = `1`.
|
|
77
|
+
*
|
|
78
|
+
* An invalid ticket cannot be made valid again, and can only be passed to the
|
|
79
|
+
* `recover_invalid_ticket_collateral` handler.
|
|
80
|
+
*/
|
|
81
|
+
invalid: number
|
|
82
|
+
/** Inner padding, for alignment. */
|
|
83
|
+
alignmentPadding: Array<number>
|
|
84
|
+
/** Trailing padding, for future developments. */
|
|
85
|
+
endPadding: Array<string>
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A finite-lifecycle account representing a specific depositor's place in the withdraw queue of
|
|
90
|
+
* a specific reserve.
|
|
91
|
+
*
|
|
92
|
+
* The lifecycle:
|
|
93
|
+
* 1. The depositor holding ctokens wants to withdraw funds from the reserve, and finds out that
|
|
94
|
+
* the required amount is not available (due to high utilization).
|
|
95
|
+
* 2. The depositor calls the `enqueue_to_withdraw` handler.
|
|
96
|
+
* 3. The handler transfers the depositor's ctokens to the reserve's internal "pending" vault.
|
|
97
|
+
* 4. The handler initializes a new [WithdrawTicket] account, with the next available sequence
|
|
98
|
+
* number.
|
|
99
|
+
* 5. The depositor waits until his ticket is the next expected one for actual withdraw, and until
|
|
100
|
+
* the reserve has enough liquidity.
|
|
101
|
+
* 6. Anyone (the depositor or a bot) calls the permissionless `withdraw_queued_liquidity`
|
|
102
|
+
* handler. If the ticket became invalid (e.g. destination account no longer exists), then the
|
|
103
|
+
* depositor can call the `recover_invalid_ticket_collateral` handler instead.
|
|
104
|
+
* 7. The handler transfers the liquidity amount according to the current exchange rate.
|
|
105
|
+
* 8. The handler closes the ticket account.
|
|
106
|
+
*/
|
|
107
|
+
export class WithdrawTicket {
|
|
108
|
+
/** This ticket's place in the queue; the same as used for PDA derivation. */
|
|
109
|
+
readonly sequenceNumber: BN
|
|
110
|
+
/** The funds' owner (the user who called the `enqueue_to_withdraw` handler). */
|
|
111
|
+
readonly owner: Address
|
|
112
|
+
/** The reserve to withdraw from. */
|
|
113
|
+
readonly reserve: Address
|
|
114
|
+
/**
|
|
115
|
+
* The token account to which the finally-available liquidity should be transferred (by the
|
|
116
|
+
* `withdraw_queued_liquidity` handler).
|
|
117
|
+
*/
|
|
118
|
+
readonly userDestinationLiquidityTa: Address
|
|
119
|
+
/** The amount of collateral still waiting to be withdrawn using this ticket. */
|
|
120
|
+
readonly queuedCollateralAmount: BN
|
|
121
|
+
/**
|
|
122
|
+
* The timestamp at which the queue was entered.
|
|
123
|
+
*
|
|
124
|
+
* This is currently only a piece of metadata, not used by the logic.
|
|
125
|
+
*/
|
|
126
|
+
readonly createdAtTimestamp: BN
|
|
127
|
+
/**
|
|
128
|
+
* Whether the ticket has been found to be invalid (e.g. the [Self::user_destination_liquidity]
|
|
129
|
+
* has been repurposed) by the `withdraw_queued_liquidity` handler.
|
|
130
|
+
* To be specific: valid = `0`, invalid = `1`.
|
|
131
|
+
*
|
|
132
|
+
* An invalid ticket cannot be made valid again, and can only be passed to the
|
|
133
|
+
* `recover_invalid_ticket_collateral` handler.
|
|
134
|
+
*/
|
|
135
|
+
readonly invalid: number
|
|
136
|
+
/** Inner padding, for alignment. */
|
|
137
|
+
readonly alignmentPadding: Array<number>
|
|
138
|
+
/** Trailing padding, for future developments. */
|
|
139
|
+
readonly endPadding: Array<BN>
|
|
140
|
+
|
|
141
|
+
static readonly discriminator = Buffer.from([
|
|
142
|
+
237, 23, 164, 58, 53, 248, 240, 94,
|
|
143
|
+
])
|
|
144
|
+
|
|
145
|
+
static readonly layout = borsh.struct<WithdrawTicket>([
|
|
146
|
+
borsh.u64("sequenceNumber"),
|
|
147
|
+
borshAddress("owner"),
|
|
148
|
+
borshAddress("reserve"),
|
|
149
|
+
borshAddress("userDestinationLiquidityTa"),
|
|
150
|
+
borsh.u64("queuedCollateralAmount"),
|
|
151
|
+
borsh.u64("createdAtTimestamp"),
|
|
152
|
+
borsh.u8("invalid"),
|
|
153
|
+
borsh.array(borsh.u8(), 7, "alignmentPadding"),
|
|
154
|
+
borsh.array(borsh.u64(), 48, "endPadding"),
|
|
155
|
+
])
|
|
156
|
+
|
|
157
|
+
constructor(fields: WithdrawTicketFields) {
|
|
158
|
+
this.sequenceNumber = fields.sequenceNumber
|
|
159
|
+
this.owner = fields.owner
|
|
160
|
+
this.reserve = fields.reserve
|
|
161
|
+
this.userDestinationLiquidityTa = fields.userDestinationLiquidityTa
|
|
162
|
+
this.queuedCollateralAmount = fields.queuedCollateralAmount
|
|
163
|
+
this.createdAtTimestamp = fields.createdAtTimestamp
|
|
164
|
+
this.invalid = fields.invalid
|
|
165
|
+
this.alignmentPadding = fields.alignmentPadding
|
|
166
|
+
this.endPadding = fields.endPadding
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static async fetch(
|
|
170
|
+
rpc: Rpc<GetAccountInfoApi>,
|
|
171
|
+
address: Address,
|
|
172
|
+
programId: Address = PROGRAM_ID
|
|
173
|
+
): Promise<WithdrawTicket | null> {
|
|
174
|
+
const info = await fetchEncodedAccount(rpc, address)
|
|
175
|
+
|
|
176
|
+
if (!info.exists) {
|
|
177
|
+
return null
|
|
178
|
+
}
|
|
179
|
+
if (info.programAddress !== programId) {
|
|
180
|
+
throw new Error(
|
|
181
|
+
`WithdrawTicketFields account ${address} belongs to wrong program ${info.programAddress}, expected ${programId}`
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return this.decode(Buffer.from(info.data))
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
static async fetchMultiple(
|
|
189
|
+
rpc: Rpc<GetMultipleAccountsApi>,
|
|
190
|
+
addresses: Address[],
|
|
191
|
+
programId: Address = PROGRAM_ID
|
|
192
|
+
): Promise<Array<WithdrawTicket | null>> {
|
|
193
|
+
const infos = await fetchEncodedAccounts(rpc, addresses)
|
|
194
|
+
|
|
195
|
+
return infos.map((info) => {
|
|
196
|
+
if (!info.exists) {
|
|
197
|
+
return null
|
|
198
|
+
}
|
|
199
|
+
if (info.programAddress !== programId) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
`WithdrawTicketFields account ${info.address} belongs to wrong program ${info.programAddress}, expected ${programId}`
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return this.decode(Buffer.from(info.data))
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
static decode(data: Buffer): WithdrawTicket {
|
|
210
|
+
if (!data.slice(0, 8).equals(WithdrawTicket.discriminator)) {
|
|
211
|
+
throw new Error("invalid account discriminator")
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const dec = WithdrawTicket.layout.decode(data.slice(8))
|
|
215
|
+
|
|
216
|
+
return new WithdrawTicket({
|
|
217
|
+
sequenceNumber: dec.sequenceNumber,
|
|
218
|
+
owner: dec.owner,
|
|
219
|
+
reserve: dec.reserve,
|
|
220
|
+
userDestinationLiquidityTa: dec.userDestinationLiquidityTa,
|
|
221
|
+
queuedCollateralAmount: dec.queuedCollateralAmount,
|
|
222
|
+
createdAtTimestamp: dec.createdAtTimestamp,
|
|
223
|
+
invalid: dec.invalid,
|
|
224
|
+
alignmentPadding: dec.alignmentPadding,
|
|
225
|
+
endPadding: dec.endPadding,
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
toJSON(): WithdrawTicketJSON {
|
|
230
|
+
return {
|
|
231
|
+
sequenceNumber: this.sequenceNumber.toString(),
|
|
232
|
+
owner: this.owner,
|
|
233
|
+
reserve: this.reserve,
|
|
234
|
+
userDestinationLiquidityTa: this.userDestinationLiquidityTa,
|
|
235
|
+
queuedCollateralAmount: this.queuedCollateralAmount.toString(),
|
|
236
|
+
createdAtTimestamp: this.createdAtTimestamp.toString(),
|
|
237
|
+
invalid: this.invalid,
|
|
238
|
+
alignmentPadding: this.alignmentPadding,
|
|
239
|
+
endPadding: this.endPadding.map((item) => item.toString()),
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
static fromJSON(obj: WithdrawTicketJSON): WithdrawTicket {
|
|
244
|
+
return new WithdrawTicket({
|
|
245
|
+
sequenceNumber: new BN(obj.sequenceNumber),
|
|
246
|
+
owner: address(obj.owner),
|
|
247
|
+
reserve: address(obj.reserve),
|
|
248
|
+
userDestinationLiquidityTa: address(obj.userDestinationLiquidityTa),
|
|
249
|
+
queuedCollateralAmount: new BN(obj.queuedCollateralAmount),
|
|
250
|
+
createdAtTimestamp: new BN(obj.createdAtTimestamp),
|
|
251
|
+
invalid: obj.invalid,
|
|
252
|
+
alignmentPadding: obj.alignmentPadding,
|
|
253
|
+
endPadding: obj.endPadding.map((item) => new BN(item)),
|
|
254
|
+
})
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -19,3 +19,9 @@ export { UserMetadata } from "./UserMetadata"
|
|
|
19
19
|
export type { UserMetadataFields, UserMetadataJSON } from "./UserMetadata"
|
|
20
20
|
export { Reserve } from "./Reserve"
|
|
21
21
|
export type { ReserveFields, ReserveJSON } from "./Reserve"
|
|
22
|
+
export { WithdrawTicket } from "./WithdrawTicket"
|
|
23
|
+
export type { WithdrawTicketFields, WithdrawTicketJSON } from "./WithdrawTicket"
|
|
24
|
+
export { PoolState } from "./PoolState"
|
|
25
|
+
export type { PoolStateFields, PoolStateJSON } from "./PoolState"
|
|
26
|
+
export { UnstakeTicket } from "./UnstakeTicket"
|
|
27
|
+
export type { UnstakeTicketFields, UnstakeTicketJSON } from "./UnstakeTicket"
|