@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.
Files changed (241) hide show
  1. package/dist/@codegen/klend/accounts/LendingMarket.d.ts +3 -144
  2. package/dist/@codegen/klend/accounts/LendingMarket.d.ts.map +1 -1
  3. package/dist/@codegen/klend/accounts/LendingMarket.js +3 -105
  4. package/dist/@codegen/klend/accounts/LendingMarket.js.map +1 -1
  5. package/dist/@codegen/klend/accounts/Obligation.d.ts +15 -30
  6. package/dist/@codegen/klend/accounts/Obligation.d.ts.map +1 -1
  7. package/dist/@codegen/klend/accounts/Obligation.js +21 -31
  8. package/dist/@codegen/klend/accounts/Obligation.js.map +1 -1
  9. package/dist/@codegen/klend/accounts/Reserve.d.ts +0 -6
  10. package/dist/@codegen/klend/accounts/Reserve.d.ts.map +1 -1
  11. package/dist/@codegen/klend/accounts/Reserve.js +2 -9
  12. package/dist/@codegen/klend/accounts/Reserve.js.map +1 -1
  13. package/dist/@codegen/klend/accounts/UserState.d.ts +75 -0
  14. package/dist/@codegen/klend/accounts/UserState.d.ts.map +1 -1
  15. package/dist/@codegen/klend/accounts/UserState.js +25 -0
  16. package/dist/@codegen/klend/accounts/UserState.js.map +1 -1
  17. package/dist/@codegen/klend/accounts/index.d.ts +0 -6
  18. package/dist/@codegen/klend/accounts/index.d.ts.map +1 -1
  19. package/dist/@codegen/klend/accounts/index.js +1 -7
  20. package/dist/@codegen/klend/accounts/index.js.map +1 -1
  21. package/dist/@codegen/klend/errors/custom.d.ts +2 -226
  22. package/dist/@codegen/klend/errors/custom.d.ts.map +1 -1
  23. package/dist/@codegen/klend/errors/custom.js +3 -396
  24. package/dist/@codegen/klend/errors/custom.js.map +1 -1
  25. package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts +2 -1
  26. package/dist/@codegen/klend/instructions/idlMissingTypes.d.ts.map +1 -1
  27. package/dist/@codegen/klend/instructions/idlMissingTypes.js +2 -6
  28. package/dist/@codegen/klend/instructions/idlMissingTypes.js.map +1 -1
  29. package/dist/@codegen/klend/instructions/index.d.ts +0 -16
  30. package/dist/@codegen/klend/instructions/index.d.ts.map +1 -1
  31. package/dist/@codegen/klend/instructions/index.js +1 -18
  32. package/dist/@codegen/klend/instructions/index.js.map +1 -1
  33. package/dist/@codegen/klend/instructions/initReserve.d.ts +1 -1
  34. package/dist/@codegen/klend/instructions/initReserve.d.ts.map +1 -1
  35. package/dist/@codegen/klend/instructions/initReserve.js +5 -1
  36. package/dist/@codegen/klend/instructions/initReserve.js.map +1 -1
  37. package/dist/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateral.js +1 -1
  38. package/dist/@codegen/klend/instructions/updateGlobalConfig.d.ts +1 -1
  39. package/dist/@codegen/klend/instructions/updateGlobalConfig.d.ts.map +1 -1
  40. package/dist/@codegen/klend/instructions/updateGlobalConfig.js +0 -1
  41. package/dist/@codegen/klend/instructions/updateGlobalConfig.js.map +1 -1
  42. package/dist/@codegen/klend/instructions/updateReserveConfig.d.ts +1 -1
  43. package/dist/@codegen/klend/instructions/updateReserveConfig.d.ts.map +1 -1
  44. package/dist/@codegen/klend/instructions/updateReserveConfig.js +0 -1
  45. package/dist/@codegen/klend/instructions/updateReserveConfig.js.map +1 -1
  46. package/dist/@codegen/klend/instructions/withdrawObligationCollateral.js +1 -1
  47. package/dist/@codegen/klend/instructions/withdrawObligationCollateralV2.js +1 -1
  48. package/dist/@codegen/klend/types/AssetTier.d.ts +45 -0
  49. package/dist/@codegen/klend/types/AssetTier.d.ts.map +1 -0
  50. package/dist/@codegen/klend/types/AssetTier.js +132 -0
  51. package/dist/@codegen/klend/types/AssetTier.js.map +1 -0
  52. package/dist/@codegen/klend/types/ObligationLiquidity.d.ts +5 -35
  53. package/dist/@codegen/klend/types/ObligationLiquidity.d.ts.map +1 -1
  54. package/dist/@codegen/klend/types/ObligationLiquidity.js +7 -17
  55. package/dist/@codegen/klend/types/ObligationLiquidity.js.map +1 -1
  56. package/dist/@codegen/klend/types/ObligationOrder.d.ts +4 -4
  57. package/dist/@codegen/klend/types/ObligationOrder.js +2 -2
  58. package/dist/@codegen/klend/types/ReserveConfig.d.ts +29 -141
  59. package/dist/@codegen/klend/types/ReserveConfig.d.ts.map +1 -1
  60. package/dist/@codegen/klend/types/ReserveConfig.js +25 -89
  61. package/dist/@codegen/klend/types/ReserveConfig.js.map +1 -1
  62. package/dist/@codegen/klend/types/ReserveFees.d.ts +8 -8
  63. package/dist/@codegen/klend/types/ReserveFees.d.ts.map +1 -1
  64. package/dist/@codegen/klend/types/ReserveFees.js +8 -8
  65. package/dist/@codegen/klend/types/ReserveFees.js.map +1 -1
  66. package/dist/@codegen/klend/types/ReserveLiquidity.d.ts +8 -26
  67. package/dist/@codegen/klend/types/ReserveLiquidity.d.ts.map +1 -1
  68. package/dist/@codegen/klend/types/ReserveLiquidity.js +8 -14
  69. package/dist/@codegen/klend/types/ReserveLiquidity.js.map +1 -1
  70. package/dist/@codegen/klend/types/UpdateConfigMode.d.ts +14 -92
  71. package/dist/@codegen/klend/types/UpdateConfigMode.d.ts.map +1 -1
  72. package/dist/@codegen/klend/types/UpdateConfigMode.js +23 -168
  73. package/dist/@codegen/klend/types/UpdateConfigMode.js.map +1 -1
  74. package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts +0 -130
  75. package/dist/@codegen/klend/types/UpdateLendingMarketMode.d.ts.map +1 -1
  76. package/dist/@codegen/klend/types/UpdateLendingMarketMode.js +1 -241
  77. package/dist/@codegen/klend/types/UpdateLendingMarketMode.js.map +1 -1
  78. package/dist/@codegen/klend/types/index.d.ts +8 -10
  79. package/dist/@codegen/klend/types/index.d.ts.map +1 -1
  80. package/dist/@codegen/klend/types/index.js +3 -7
  81. package/dist/@codegen/klend/types/index.js.map +1 -1
  82. package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts +4 -9
  83. package/dist/@codegen/klend/zero_padding/ObligationZP.d.ts.map +1 -1
  84. package/dist/@codegen/klend/zero_padding/ObligationZP.js +13 -22
  85. package/dist/@codegen/klend/zero_padding/ObligationZP.js.map +1 -1
  86. package/dist/classes/action.d.ts +3 -30
  87. package/dist/classes/action.d.ts.map +1 -1
  88. package/dist/classes/action.js +10 -364
  89. package/dist/classes/action.js.map +1 -1
  90. package/dist/classes/manager.d.ts +3 -2
  91. package/dist/classes/manager.d.ts.map +1 -1
  92. package/dist/classes/manager.js +3 -12
  93. package/dist/classes/manager.js.map +1 -1
  94. package/dist/classes/market.d.ts +2 -6
  95. package/dist/classes/market.d.ts.map +1 -1
  96. package/dist/classes/market.js +6 -26
  97. package/dist/classes/market.js.map +1 -1
  98. package/dist/classes/obligation.js +1 -1
  99. package/dist/classes/obligation.js.map +1 -1
  100. package/dist/classes/reserve.d.ts.map +1 -1
  101. package/dist/classes/reserve.js +7 -13
  102. package/dist/classes/reserve.js.map +1 -1
  103. package/dist/classes/unstakingPool.d.ts +3 -20
  104. package/dist/classes/unstakingPool.d.ts.map +1 -1
  105. package/dist/classes/unstakingPool.js +8 -62
  106. package/dist/classes/unstakingPool.js.map +1 -1
  107. package/dist/classes/vault.d.ts +2 -1
  108. package/dist/classes/vault.d.ts.map +1 -1
  109. package/dist/classes/vault.js +59 -38
  110. package/dist/classes/vault.js.map +1 -1
  111. package/dist/idl/klend.json +293 -2186
  112. package/dist/lending_operations/index.d.ts +0 -1
  113. package/dist/lending_operations/index.d.ts.map +1 -1
  114. package/dist/lending_operations/index.js +0 -1
  115. package/dist/lending_operations/index.js.map +1 -1
  116. package/dist/manager/client_kamino_manager.js +9 -12
  117. package/dist/manager/client_kamino_manager.js.map +1 -1
  118. package/dist/utils/ata.d.ts +10 -1
  119. package/dist/utils/ata.d.ts.map +1 -1
  120. package/dist/utils/ata.js +47 -0
  121. package/dist/utils/ata.js.map +1 -1
  122. package/dist/utils/managerTypes.d.ts.map +1 -1
  123. package/dist/utils/managerTypes.js +4 -9
  124. package/dist/utils/managerTypes.js.map +1 -1
  125. package/dist/utils/seeds.d.ts +14 -10
  126. package/dist/utils/seeds.d.ts.map +1 -1
  127. package/dist/utils/seeds.js +22 -25
  128. package/dist/utils/seeds.js.map +1 -1
  129. package/package.json +1 -1
  130. package/src/@codegen/klend/accounts/LendingMarket.ts +5 -210
  131. package/src/@codegen/klend/accounts/Obligation.ts +31 -53
  132. package/src/@codegen/klend/accounts/Reserve.ts +2 -13
  133. package/src/@codegen/klend/accounts/UserState.ts +75 -0
  134. package/src/@codegen/klend/accounts/index.ts +0 -6
  135. package/src/@codegen/klend/errors/custom.ts +2 -427
  136. package/src/@codegen/klend/instructions/idlMissingTypes.ts +4 -7
  137. package/src/@codegen/klend/instructions/index.ts +0 -34
  138. package/src/@codegen/klend/instructions/initReserve.ts +6 -2
  139. package/src/@codegen/klend/instructions/liquidateObligationAndRedeemReserveCollateral.ts +1 -1
  140. package/src/@codegen/klend/instructions/updateGlobalConfig.ts +1 -2
  141. package/src/@codegen/klend/instructions/updateReserveConfig.ts +1 -2
  142. package/src/@codegen/klend/instructions/withdrawObligationCollateral.ts +1 -1
  143. package/src/@codegen/klend/instructions/withdrawObligationCollateralV2.ts +1 -1
  144. package/src/@codegen/klend/types/AssetTier.ts +119 -0
  145. package/src/@codegen/klend/types/ObligationLiquidity.ts +9 -39
  146. package/src/@codegen/klend/types/ObligationOrder.ts +4 -4
  147. package/src/@codegen/klend/types/ReserveConfig.ts +39 -171
  148. package/src/@codegen/klend/types/ReserveFees.ts +12 -12
  149. package/src/@codegen/klend/types/ReserveLiquidity.ts +12 -30
  150. package/src/@codegen/klend/types/UpdateConfigMode.ts +26 -206
  151. package/src/@codegen/klend/types/UpdateLendingMarketMode.ts +0 -300
  152. package/src/@codegen/klend/types/index.ts +16 -45
  153. package/src/@codegen/klend/zero_padding/ObligationZP.ts +13 -22
  154. package/src/classes/action.ts +8 -577
  155. package/src/classes/manager.ts +7 -13
  156. package/src/classes/market.ts +5 -36
  157. package/src/classes/obligation.ts +1 -1
  158. package/src/classes/reserve.ts +8 -13
  159. package/src/classes/unstakingPool.ts +6 -83
  160. package/src/classes/vault.ts +75 -54
  161. package/src/idl/klend.json +294 -2187
  162. package/src/lending_operations/index.ts +0 -1
  163. package/src/manager/client_kamino_manager.ts +9 -13
  164. package/src/utils/ata.ts +79 -0
  165. package/src/utils/managerTypes.ts +4 -9
  166. package/src/utils/seeds.ts +26 -28
  167. package/dist/@codegen/klend/accounts/PoolState.d.ts +0 -53
  168. package/dist/@codegen/klend/accounts/PoolState.d.ts.map +0 -1
  169. package/dist/@codegen/klend/accounts/PoolState.js +0 -167
  170. package/dist/@codegen/klend/accounts/PoolState.js.map +0 -1
  171. package/dist/@codegen/klend/accounts/UnstakeTicket.d.ts +0 -41
  172. package/dist/@codegen/klend/accounts/UnstakeTicket.d.ts.map +0 -1
  173. package/dist/@codegen/klend/accounts/UnstakeTicket.js +0 -143
  174. package/dist/@codegen/klend/accounts/UnstakeTicket.js.map +0 -1
  175. package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts +0 -132
  176. package/dist/@codegen/klend/accounts/WithdrawTicket.d.ts.map +0 -1
  177. package/dist/@codegen/klend/accounts/WithdrawTicket.js +0 -191
  178. package/dist/@codegen/klend/accounts/WithdrawTicket.js.map +0 -1
  179. package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts +0 -39
  180. package/dist/@codegen/klend/instructions/enqueueToWithdraw.d.ts.map +0 -1
  181. package/dist/@codegen/klend/instructions/enqueueToWithdraw.js +0 -67
  182. package/dist/@codegen/klend/instructions/enqueueToWithdraw.js.map +0 -1
  183. package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts +0 -36
  184. package/dist/@codegen/klend/instructions/fillBorrowOrder.d.ts.map +0 -1
  185. package/dist/@codegen/klend/instructions/fillBorrowOrder.js +0 -49
  186. package/dist/@codegen/klend/instructions/fillBorrowOrder.js.map +0 -1
  187. package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts +0 -47
  188. package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.d.ts.map +0 -1
  189. package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js +0 -66
  190. package/dist/@codegen/klend/instructions/recoverInvalidTicketCollateral.js.map +0 -1
  191. package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts +0 -31
  192. package/dist/@codegen/klend/instructions/setBorrowOrder.d.ts.map +0 -1
  193. package/dist/@codegen/klend/instructions/setBorrowOrder.js +0 -64
  194. package/dist/@codegen/klend/instructions/setBorrowOrder.js.map +0 -1
  195. package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.d.ts +0 -53
  196. package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.d.ts.map +0 -1
  197. package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.js +0 -190
  198. package/dist/@codegen/klend/instructions/unstakeLstCollateralEnd.js.map +0 -1
  199. package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.d.ts +0 -70
  200. package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.d.ts.map +0 -1
  201. package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.js +0 -261
  202. package/dist/@codegen/klend/instructions/unstakeLstCollateralStart.js.map +0 -1
  203. package/dist/@codegen/klend/instructions/withdrawObligationUsol.d.ts +0 -41
  204. package/dist/@codegen/klend/instructions/withdrawObligationUsol.d.ts.map +0 -1
  205. package/dist/@codegen/klend/instructions/withdrawObligationUsol.js +0 -135
  206. package/dist/@codegen/klend/instructions/withdrawObligationUsol.js.map +0 -1
  207. package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts +0 -51
  208. package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.d.ts.map +0 -1
  209. package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js +0 -28
  210. package/dist/@codegen/klend/instructions/withdrawQueuedLiquidity.js.map +0 -1
  211. package/dist/@codegen/klend/types/BorrowOrder.d.ts +0 -192
  212. package/dist/@codegen/klend/types/BorrowOrder.d.ts.map +0 -1
  213. package/dist/@codegen/klend/types/BorrowOrder.js +0 -194
  214. package/dist/@codegen/klend/types/BorrowOrder.js.map +0 -1
  215. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts +0 -39
  216. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.d.ts.map +0 -1
  217. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js +0 -100
  218. package/dist/@codegen/klend/types/BorrowOrderConfigArgs.js.map +0 -1
  219. package/dist/@codegen/klend/types/WithdrawQueue.d.ts +0 -64
  220. package/dist/@codegen/klend/types/WithdrawQueue.d.ts.map +0 -1
  221. package/dist/@codegen/klend/types/WithdrawQueue.js +0 -104
  222. package/dist/@codegen/klend/types/WithdrawQueue.js.map +0 -1
  223. package/dist/lending_operations/unstake_lst_collateral.d.ts +0 -12
  224. package/dist/lending_operations/unstake_lst_collateral.d.ts.map +0 -1
  225. package/dist/lending_operations/unstake_lst_collateral.js +0 -104
  226. package/dist/lending_operations/unstake_lst_collateral.js.map +0 -1
  227. package/src/@codegen/klend/accounts/PoolState.ts +0 -192
  228. package/src/@codegen/klend/accounts/UnstakeTicket.ts +0 -160
  229. package/src/@codegen/klend/accounts/WithdrawTicket.ts +0 -256
  230. package/src/@codegen/klend/instructions/enqueueToWithdraw.ts +0 -89
  231. package/src/@codegen/klend/instructions/fillBorrowOrder.ts +0 -96
  232. package/src/@codegen/klend/instructions/recoverInvalidTicketCollateral.ts +0 -96
  233. package/src/@codegen/klend/instructions/setBorrowOrder.ts +0 -77
  234. package/src/@codegen/klend/instructions/unstakeLstCollateralEnd.ts +0 -251
  235. package/src/@codegen/klend/instructions/unstakeLstCollateralStart.ts +0 -353
  236. package/src/@codegen/klend/instructions/withdrawObligationUsol.ts +0 -168
  237. package/src/@codegen/klend/instructions/withdrawQueuedLiquidity.ts +0 -92
  238. package/src/@codegen/klend/types/BorrowOrder.ts +0 -267
  239. package/src/@codegen/klend/types/BorrowOrderConfigArgs.ts +0 -87
  240. package/src/@codegen/klend/types/WithdrawQueue.ts +0 -117
  241. package/src/lending_operations/unstake_lst_collateral.ts +0 -174
@@ -1,256 +0,0 @@
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
- }
@@ -1,89 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import {
3
- Address,
4
- isSome,
5
- AccountMeta,
6
- AccountSignerMeta,
7
- Instruction,
8
- Option,
9
- TransactionSigner,
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 const DISCRIMINATOR = Buffer.from([134, 113, 160, 207, 90, 75, 213, 219])
19
-
20
- export interface EnqueueToWithdrawArgs {
21
- collateralAmount: BN
22
- }
23
-
24
- export interface EnqueueToWithdrawAccounts {
25
- /** The depositor holding ctokens. */
26
- owner: TransactionSigner
27
- lendingMarket: Address
28
- /** The market's authority, needed to initialize the [Self::owner_queued_collateral_vault]. */
29
- lendingMarketAuthority: Address
30
- reserve: Address
31
- /** The source of collateral to be enqueued. */
32
- userSourceCollateralTa: Address
33
- /**
34
- * The account to which the liquidity should be finally transferred later (to be recorded in
35
- * the ticket).
36
- */
37
- userDestinationLiquidityTa: Address
38
- reserveCollateralMint: Address
39
- /**
40
- * The collateral's program - needed for invoking the transfer to the vault *and* (implicitly)
41
- * for handling the `init_if_needed`.
42
- */
43
- collateralTokenProgram: Address
44
- /** The new account to be initialized with the issued ticket's data. */
45
- withdrawTicket: Address
46
- /**
47
- * The per-owner "this reserve's queued collateral" vault (in which the collateral will be
48
- * locked).
49
- */
50
- ownerQueuedCollateralVault: Address
51
- /** The System program - needed only for `init` / `init_if_needed` of the accounts above. */
52
- systemProgram: Address
53
- }
54
-
55
- export const layout = borsh.struct<EnqueueToWithdrawArgs>([
56
- borsh.u64("collateralAmount"),
57
- ])
58
-
59
- export function enqueueToWithdraw(
60
- args: EnqueueToWithdrawArgs,
61
- accounts: EnqueueToWithdrawAccounts,
62
- remainingAccounts: Array<AccountMeta | AccountSignerMeta> = [],
63
- programAddress: Address = PROGRAM_ID
64
- ) {
65
- const keys: Array<AccountMeta | AccountSignerMeta> = [
66
- { address: accounts.owner.address, role: 3, signer: accounts.owner },
67
- { address: accounts.lendingMarket, role: 0 },
68
- { address: accounts.lendingMarketAuthority, role: 0 },
69
- { address: accounts.reserve, role: 1 },
70
- { address: accounts.userSourceCollateralTa, role: 1 },
71
- { address: accounts.userDestinationLiquidityTa, role: 0 },
72
- { address: accounts.reserveCollateralMint, role: 0 },
73
- { address: accounts.collateralTokenProgram, role: 0 },
74
- { address: accounts.withdrawTicket, role: 1 },
75
- { address: accounts.ownerQueuedCollateralVault, role: 1 },
76
- { address: accounts.systemProgram, role: 0 },
77
- ...remainingAccounts,
78
- ]
79
- const buffer = Buffer.alloc(1000)
80
- const len = layout.encode(
81
- {
82
- collateralAmount: args.collateralAmount,
83
- },
84
- buffer
85
- )
86
- const data = Buffer.concat([DISCRIMINATOR, buffer]).slice(0, 8 + len)
87
- const ix: Instruction = { accounts: keys, programAddress, data }
88
- return ix
89
- }
@@ -1,96 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import {
3
- Address,
4
- isSome,
5
- AccountMeta,
6
- AccountSignerMeta,
7
- Instruction,
8
- Option,
9
- TransactionSigner,
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 const DISCRIMINATOR = Buffer.from([102, 4, 167, 76, 131, 170, 93, 19])
19
-
20
- export interface FillBorrowOrderAccounts {
21
- borrowAccounts: {
22
- payer: TransactionSigner
23
- /** The obligation with a [BorrowOrder]. */
24
- obligation: Address
25
- /** The [Self::obligation]'s market - needed for borrowing-related configuration. */
26
- lendingMarket: Address
27
- /** The [Self::lending_market]'s authority, needed to transfer the newly-borrowed funds out of the [Self::reserve_source_liquidity]. */
28
- lendingMarketAuthority: Address
29
- /** The reserve to borrow from. Its mint must match the asset requested by the [BorrowOrder::debt_liquidity_mint]. */
30
- borrowReserve: Address
31
- /** The mint of [Self::borrow_reserve] - needed to execute the transfer. */
32
- borrowReserveLiquidityMint: Address
33
- /** The vault of [Self::borrow_reserve], from which the funds are transferred. */
34
- reserveSourceLiquidity: Address
35
- /** The fee vault of [Self::borrow_reserve], to which the fees are transferred. */
36
- borrowReserveLiquidityFeeReceiver: Address
37
- /** The destination token account that should receive the newly borrowed funds. It must match [BorrowOrder::filled_debt_destination], owner and mint. **Warning:** An altered destination account will prevent an order from being filled. */
38
- userDestinationLiquidity: Address
39
- /** The referrer's account, for accumulating fees - needed if the [Obligation::has_referrer]. */
40
- referrerTokenState: Option<Address>
41
- /** The token program of [Self::borrow_reserve] - needed to execute the transfer. */
42
- tokenProgram: Address
43
- }
44
- farmsAccounts: {
45
- obligationFarmUserState: Option<Address>
46
- reserveFarmState: Option<Address>
47
- }
48
- farmsProgram: Address
49
- eventAuthority: Address
50
- program: Address
51
- }
52
-
53
- export function fillBorrowOrder(
54
- accounts: FillBorrowOrderAccounts,
55
- remainingAccounts: Array<AccountMeta | AccountSignerMeta> = [],
56
- programAddress: Address = PROGRAM_ID
57
- ) {
58
- const keys: Array<AccountMeta | AccountSignerMeta> = [
59
- {
60
- address: accounts.borrowAccounts.payer.address,
61
- role: 2,
62
- signer: accounts.borrowAccounts.payer,
63
- },
64
- { address: accounts.borrowAccounts.obligation, role: 1 },
65
- { address: accounts.borrowAccounts.lendingMarket, role: 0 },
66
- { address: accounts.borrowAccounts.lendingMarketAuthority, role: 0 },
67
- { address: accounts.borrowAccounts.borrowReserve, role: 1 },
68
- { address: accounts.borrowAccounts.borrowReserveLiquidityMint, role: 0 },
69
- { address: accounts.borrowAccounts.reserveSourceLiquidity, role: 1 },
70
- {
71
- address: accounts.borrowAccounts.borrowReserveLiquidityFeeReceiver,
72
- role: 1,
73
- },
74
- { address: accounts.borrowAccounts.userDestinationLiquidity, role: 1 },
75
- isSome(accounts.borrowAccounts.referrerTokenState)
76
- ? { address: accounts.borrowAccounts.referrerTokenState.value, role: 1 }
77
- : { address: programAddress, role: 0 },
78
- { address: accounts.borrowAccounts.tokenProgram, role: 0 },
79
- isSome(accounts.farmsAccounts.obligationFarmUserState)
80
- ? {
81
- address: accounts.farmsAccounts.obligationFarmUserState.value,
82
- role: 1,
83
- }
84
- : { address: programAddress, role: 0 },
85
- isSome(accounts.farmsAccounts.reserveFarmState)
86
- ? { address: accounts.farmsAccounts.reserveFarmState.value, role: 1 }
87
- : { address: programAddress, role: 0 },
88
- { address: accounts.farmsProgram, role: 0 },
89
- { address: accounts.eventAuthority, role: 0 },
90
- { address: accounts.program, role: 0 },
91
- ...remainingAccounts,
92
- ]
93
- const data = DISCRIMINATOR
94
- const ix: Instruction = { accounts: keys, programAddress, data }
95
- return ix
96
- }
@@ -1,96 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import {
3
- Address,
4
- isSome,
5
- AccountMeta,
6
- AccountSignerMeta,
7
- Instruction,
8
- Option,
9
- TransactionSigner,
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 const DISCRIMINATOR = Buffer.from([28, 48, 176, 102, 159, 206, 210, 246])
19
-
20
- export interface RecoverInvalidTicketCollateralArgs {
21
- ticketSequenceNumber: BN
22
- }
23
-
24
- export interface RecoverInvalidTicketCollateralAccounts {
25
- /**
26
- * The executor of the permissionless tx (not necessarily the ticket owner).
27
- *
28
- * Note: `mut` is only needed for closing the [Self::withdraw_ticket].
29
- */
30
- payer: TransactionSigner
31
- /** The lending market. */
32
- lendingMarket: Address
33
- /**
34
- * The market's authority, needed for transferring the collateral (from
35
- * [Self::owner_queued_collateral_vault]).
36
- */
37
- lendingMarketAuthority: Address
38
- /** The reserve, needed only to validate the other accounts. */
39
- reserve: Address
40
- /** The collateral mint, needed to invoke the transfer. */
41
- reserveCollateralMint: Address
42
- /**
43
- * The per-owner "this reserve's queued collateral" vault (from which the collateral will be
44
- * recovered).
45
- */
46
- ownerQueuedCollateralVault: Address
47
- /** The ticket's owner token account to which the ticket-locked collateral should be returned. */
48
- userSourceCollateral: Address
49
- /** The program of [Self::reserve_collateral_mint], needed for transfer. */
50
- collateralTokenProgram: Address
51
- /**
52
- * The ticket's account, necessarily marked as [WithdrawTicket::invalid] first (by the
53
- * `handler_withdraw_queued_liquidity`).
54
- */
55
- withdrawTicket: Address
56
- /**
57
- * The owner of the [Self::withdraw_ticket]; needed only to return the rent of the
58
- * [WithdrawTicket] account.
59
- */
60
- withdrawTicketOwner: Address
61
- }
62
-
63
- export const layout = borsh.struct<RecoverInvalidTicketCollateralArgs>([
64
- borsh.u64("ticketSequenceNumber"),
65
- ])
66
-
67
- export function recoverInvalidTicketCollateral(
68
- args: RecoverInvalidTicketCollateralArgs,
69
- accounts: RecoverInvalidTicketCollateralAccounts,
70
- remainingAccounts: Array<AccountMeta | AccountSignerMeta> = [],
71
- programAddress: Address = PROGRAM_ID
72
- ) {
73
- const keys: Array<AccountMeta | AccountSignerMeta> = [
74
- { address: accounts.payer.address, role: 3, signer: accounts.payer },
75
- { address: accounts.lendingMarket, role: 0 },
76
- { address: accounts.lendingMarketAuthority, role: 0 },
77
- { address: accounts.reserve, role: 0 },
78
- { address: accounts.reserveCollateralMint, role: 0 },
79
- { address: accounts.ownerQueuedCollateralVault, role: 1 },
80
- { address: accounts.userSourceCollateral, role: 1 },
81
- { address: accounts.collateralTokenProgram, role: 0 },
82
- { address: accounts.withdrawTicket, role: 1 },
83
- { address: accounts.withdrawTicketOwner, role: 1 },
84
- ...remainingAccounts,
85
- ]
86
- const buffer = Buffer.alloc(1000)
87
- const len = layout.encode(
88
- {
89
- ticketSequenceNumber: args.ticketSequenceNumber,
90
- },
91
- buffer
92
- )
93
- const data = Buffer.concat([DISCRIMINATOR, buffer]).slice(0, 8 + len)
94
- const ix: Instruction = { accounts: keys, programAddress, data }
95
- return ix
96
- }
@@ -1,77 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import {
3
- Address,
4
- isSome,
5
- AccountMeta,
6
- AccountSignerMeta,
7
- Instruction,
8
- Option,
9
- TransactionSigner,
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 const DISCRIMINATOR = Buffer.from([177, 186, 45, 61, 235, 91, 68, 139])
19
-
20
- export interface SetBorrowOrderArgs {
21
- orderConfig: types.BorrowOrderConfigArgsFields
22
- }
23
-
24
- export interface SetBorrowOrderAccounts {
25
- /** The [Self::obligation]'s owner. */
26
- owner: TransactionSigner
27
- /** The obligation to set the [BorrowOrder] on. */
28
- obligation: Address
29
- /** The [Self::obligation]'s market - needed only to validate the borrow orders' feature flag. */
30
- lendingMarket: Address
31
- /**
32
- * The [BorrowOrder::filled_debt_destination] to set.
33
- * Can be freely changed throughout the order's lifetime - of course, affects the future fills
34
- * only.
35
- * Ignored when cancelling the order.
36
- */
37
- filledDebtDestination: Address
38
- /**
39
- * The [BorrowOrder::debt_liquidity_mint] to set.
40
- * Ignored when cancelling the order.
41
- */
42
- debtLiquidityMint: Address
43
- eventAuthority: Address
44
- program: Address
45
- }
46
-
47
- export const layout = borsh.struct<SetBorrowOrderArgs>([
48
- types.BorrowOrderConfigArgs.layout("orderConfig"),
49
- ])
50
-
51
- export function setBorrowOrder(
52
- args: SetBorrowOrderArgs,
53
- accounts: SetBorrowOrderAccounts,
54
- remainingAccounts: Array<AccountMeta | AccountSignerMeta> = [],
55
- programAddress: Address = PROGRAM_ID
56
- ) {
57
- const keys: Array<AccountMeta | AccountSignerMeta> = [
58
- { address: accounts.owner.address, role: 2, signer: accounts.owner },
59
- { address: accounts.obligation, role: 1 },
60
- { address: accounts.lendingMarket, role: 0 },
61
- { address: accounts.filledDebtDestination, role: 0 },
62
- { address: accounts.debtLiquidityMint, role: 0 },
63
- { address: accounts.eventAuthority, role: 0 },
64
- { address: accounts.program, role: 0 },
65
- ...remainingAccounts,
66
- ]
67
- const buffer = Buffer.alloc(1000)
68
- const len = layout.encode(
69
- {
70
- orderConfig: types.BorrowOrderConfigArgs.toEncodable(args.orderConfig),
71
- },
72
- buffer
73
- )
74
- const data = Buffer.concat([DISCRIMINATOR, buffer]).slice(0, 8 + len)
75
- const ix: Instruction = { accounts: keys, programAddress, data }
76
- return ix
77
- }