@voltr/vault-sdk 1.1.0 → 2.1.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.
Files changed (508) hide show
  1. package/dist/extensions/batchFetchers.d.ts +7 -0
  2. package/dist/extensions/batchFetchers.d.ts.map +1 -0
  3. package/dist/extensions/batchFetchers.js +63 -0
  4. package/dist/extensions/batchFetchers.js.map +1 -0
  5. package/dist/extensions/decimal.d.ts +11 -0
  6. package/dist/extensions/decimal.d.ts.map +1 -0
  7. package/dist/extensions/decimal.js +19 -0
  8. package/dist/extensions/decimal.js.map +1 -0
  9. package/dist/extensions/events.d.ts +33 -0
  10. package/dist/extensions/events.d.ts.map +1 -0
  11. package/dist/extensions/events.js +203 -0
  12. package/dist/extensions/events.js.map +1 -0
  13. package/dist/extensions/fees.d.ts +6 -0
  14. package/dist/extensions/fees.d.ts.map +1 -0
  15. package/dist/extensions/fees.js +23 -0
  16. package/dist/extensions/fees.js.map +1 -0
  17. package/dist/extensions/index.d.ts +11 -0
  18. package/dist/extensions/index.d.ts.map +1 -0
  19. package/dist/extensions/index.js +27 -0
  20. package/dist/extensions/index.js.map +1 -0
  21. package/dist/extensions/lpEconomics.d.ts +27 -0
  22. package/dist/extensions/lpEconomics.d.ts.map +1 -0
  23. package/dist/extensions/lpEconomics.js +140 -0
  24. package/dist/extensions/lpEconomics.js.map +1 -0
  25. package/dist/extensions/math.d.ts +90 -0
  26. package/dist/extensions/math.d.ts.map +1 -0
  27. package/dist/extensions/math.js +182 -0
  28. package/dist/extensions/math.js.map +1 -0
  29. package/dist/extensions/metadataPda.d.ts +18 -0
  30. package/dist/extensions/metadataPda.d.ts.map +1 -0
  31. package/dist/extensions/metadataPda.js +34 -0
  32. package/dist/extensions/metadataPda.js.map +1 -0
  33. package/dist/extensions/position.d.ts +19 -0
  34. package/dist/extensions/position.d.ts.map +1 -0
  35. package/dist/extensions/position.js +28 -0
  36. package/dist/extensions/position.js.map +1 -0
  37. package/dist/extensions/rpc.d.ts +8 -0
  38. package/dist/extensions/rpc.d.ts.map +1 -0
  39. package/dist/{types/voltr_vault.js → extensions/rpc.js} +1 -0
  40. package/dist/extensions/rpc.js.map +1 -0
  41. package/dist/extensions/withdrawals.d.ts +16 -0
  42. package/dist/extensions/withdrawals.d.ts.map +1 -0
  43. package/dist/extensions/withdrawals.js +59 -0
  44. package/dist/extensions/withdrawals.js.map +1 -0
  45. package/dist/generated/accounts/adaptorAddReceipt.d.ts +57 -0
  46. package/dist/generated/accounts/adaptorAddReceipt.d.ts.map +1 -0
  47. package/dist/generated/accounts/adaptorAddReceipt.js +82 -0
  48. package/dist/generated/accounts/adaptorAddReceipt.js.map +1 -0
  49. package/dist/generated/accounts/directWithdrawInitReceipt.d.ts +60 -0
  50. package/dist/generated/accounts/directWithdrawInitReceipt.d.ts.map +1 -0
  51. package/dist/generated/accounts/directWithdrawInitReceipt.js +95 -0
  52. package/dist/generated/accounts/directWithdrawInitReceipt.js.map +1 -0
  53. package/dist/generated/accounts/index.d.ts +14 -0
  54. package/dist/generated/accounts/index.d.ts.map +1 -0
  55. package/dist/generated/accounts/index.js +30 -0
  56. package/dist/generated/accounts/index.js.map +1 -0
  57. package/dist/generated/accounts/protocol.d.ts +57 -0
  58. package/dist/generated/accounts/protocol.d.ts.map +1 -0
  59. package/dist/generated/accounts/protocol.js +82 -0
  60. package/dist/generated/accounts/protocol.js.map +1 -0
  61. package/dist/generated/accounts/requestWithdrawVaultReceipt.d.ts +43 -0
  62. package/dist/generated/accounts/requestWithdrawVaultReceipt.d.ts.map +1 -0
  63. package/dist/generated/accounts/requestWithdrawVaultReceipt.js +85 -0
  64. package/dist/generated/accounts/requestWithdrawVaultReceipt.js.map +1 -0
  65. package/dist/generated/accounts/strategyInitReceipt.d.ts +69 -0
  66. package/dist/generated/accounts/strategyInitReceipt.d.ts.map +1 -0
  67. package/dist/generated/accounts/strategyInitReceipt.js +91 -0
  68. package/dist/generated/accounts/strategyInitReceipt.js.map +1 -0
  69. package/dist/generated/accounts/vault.d.ts +100 -0
  70. package/dist/generated/accounts/vault.d.ts.map +1 -0
  71. package/dist/generated/accounts/vault.js +105 -0
  72. package/dist/generated/accounts/vault.js.map +1 -0
  73. package/dist/generated/errors/index.d.ts +9 -0
  74. package/dist/generated/errors/index.d.ts.map +1 -0
  75. package/dist/{types → generated/errors}/index.js +9 -2
  76. package/dist/generated/errors/index.js.map +1 -0
  77. package/dist/generated/errors/voltrVault.d.ts +52 -0
  78. package/dist/generated/errors/voltrVault.d.ts.map +1 -0
  79. package/dist/generated/errors/voltrVault.js +77 -0
  80. package/dist/generated/errors/voltrVault.js.map +1 -0
  81. package/dist/generated/index.d.ts +14 -0
  82. package/dist/generated/index.d.ts.map +1 -0
  83. package/dist/generated/index.js +30 -0
  84. package/dist/generated/index.js.map +1 -0
  85. package/dist/generated/instructions/acceptProtocolAdmin.d.ts +47 -0
  86. package/dist/generated/instructions/acceptProtocolAdmin.d.ts.map +1 -0
  87. package/dist/generated/instructions/acceptProtocolAdmin.js +103 -0
  88. package/dist/generated/instructions/acceptProtocolAdmin.js.map +1 -0
  89. package/dist/generated/instructions/acceptVaultAdmin.d.ts +40 -0
  90. package/dist/generated/instructions/acceptVaultAdmin.d.ts.map +1 -0
  91. package/dist/generated/instructions/acceptVaultAdmin.js +75 -0
  92. package/dist/generated/instructions/acceptVaultAdmin.js.map +1 -0
  93. package/dist/generated/instructions/addAdaptor.d.ts +67 -0
  94. package/dist/generated/instructions/addAdaptor.d.ts.map +1 -0
  95. package/dist/generated/instructions/addAdaptor.js +149 -0
  96. package/dist/generated/instructions/addAdaptor.js.map +1 -0
  97. package/dist/generated/instructions/calibrateHighWaterMark.d.ts +63 -0
  98. package/dist/generated/instructions/calibrateHighWaterMark.d.ts.map +1 -0
  99. package/dist/generated/instructions/calibrateHighWaterMark.js +150 -0
  100. package/dist/generated/instructions/calibrateHighWaterMark.js.map +1 -0
  101. package/dist/generated/instructions/calibrateHighWaterMarkUnsafe.d.ts +55 -0
  102. package/dist/generated/instructions/calibrateHighWaterMarkUnsafe.d.ts.map +1 -0
  103. package/dist/generated/instructions/calibrateHighWaterMarkUnsafe.js +121 -0
  104. package/dist/generated/instructions/calibrateHighWaterMarkUnsafe.js.map +1 -0
  105. package/dist/generated/instructions/cancelRequestWithdrawVault.d.ts +84 -0
  106. package/dist/generated/instructions/cancelRequestWithdrawVault.d.ts.map +1 -0
  107. package/dist/generated/instructions/cancelRequestWithdrawVault.js +208 -0
  108. package/dist/generated/instructions/cancelRequestWithdrawVault.js.map +1 -0
  109. package/dist/generated/instructions/closeStrategy.d.ts +67 -0
  110. package/dist/generated/instructions/closeStrategy.d.ts.map +1 -0
  111. package/dist/generated/instructions/closeStrategy.js +149 -0
  112. package/dist/generated/instructions/closeStrategy.js.map +1 -0
  113. package/dist/generated/instructions/createLpMetadata.d.ts +88 -0
  114. package/dist/generated/instructions/createLpMetadata.d.ts.map +1 -0
  115. package/dist/generated/instructions/createLpMetadata.js +194 -0
  116. package/dist/generated/instructions/createLpMetadata.js.map +1 -0
  117. package/dist/generated/instructions/depositStrategy.d.ts +111 -0
  118. package/dist/generated/instructions/depositStrategy.d.ts.map +1 -0
  119. package/dist/generated/instructions/depositStrategy.js +277 -0
  120. package/dist/generated/instructions/depositStrategy.js.map +1 -0
  121. package/dist/generated/instructions/depositVault.d.ts +108 -0
  122. package/dist/generated/instructions/depositVault.d.ts.map +1 -0
  123. package/dist/generated/instructions/depositVault.js +258 -0
  124. package/dist/generated/instructions/depositVault.js.map +1 -0
  125. package/dist/generated/instructions/directWithdrawStrategy.d.ts +125 -0
  126. package/dist/generated/instructions/directWithdrawStrategy.d.ts.map +1 -0
  127. package/dist/generated/instructions/directWithdrawStrategy.js +338 -0
  128. package/dist/generated/instructions/directWithdrawStrategy.js.map +1 -0
  129. package/dist/generated/instructions/directWithdrawStrategyWithTolerance.d.ts +129 -0
  130. package/dist/generated/instructions/directWithdrawStrategyWithTolerance.d.ts.map +1 -0
  131. package/dist/generated/instructions/directWithdrawStrategyWithTolerance.js +338 -0
  132. package/dist/generated/instructions/directWithdrawStrategyWithTolerance.js.map +1 -0
  133. package/dist/generated/instructions/harvestFee.d.ts +87 -0
  134. package/dist/generated/instructions/harvestFee.d.ts.map +1 -0
  135. package/dist/generated/instructions/harvestFee.js +220 -0
  136. package/dist/generated/instructions/harvestFee.js.map +1 -0
  137. package/dist/generated/instructions/index.d.ts +35 -0
  138. package/dist/generated/instructions/index.d.ts.map +1 -0
  139. package/dist/generated/instructions/index.js +51 -0
  140. package/dist/generated/instructions/index.js.map +1 -0
  141. package/dist/generated/instructions/initProtocol.d.ts +60 -0
  142. package/dist/generated/instructions/initProtocol.d.ts.map +1 -0
  143. package/dist/generated/instructions/initProtocol.js +130 -0
  144. package/dist/generated/instructions/initProtocol.js.map +1 -0
  145. package/dist/generated/instructions/initializeDirectWithdrawStrategy.d.ts +92 -0
  146. package/dist/generated/instructions/initializeDirectWithdrawStrategy.d.ts.map +1 -0
  147. package/dist/generated/instructions/initializeDirectWithdrawStrategy.js +214 -0
  148. package/dist/generated/instructions/initializeDirectWithdrawStrategy.js.map +1 -0
  149. package/dist/generated/instructions/initializeStrategy.d.ts +88 -0
  150. package/dist/generated/instructions/initializeStrategy.d.ts.map +1 -0
  151. package/dist/generated/instructions/initializeStrategy.js +210 -0
  152. package/dist/generated/instructions/initializeStrategy.js.map +1 -0
  153. package/dist/generated/instructions/initializeVault.d.ts +172 -0
  154. package/dist/generated/instructions/initializeVault.d.ts.map +1 -0
  155. package/dist/generated/instructions/initializeVault.js +289 -0
  156. package/dist/generated/instructions/initializeVault.js.map +1 -0
  157. package/dist/generated/instructions/instantWithdrawStrategy.d.ts +133 -0
  158. package/dist/generated/instructions/instantWithdrawStrategy.d.ts.map +1 -0
  159. package/dist/generated/instructions/instantWithdrawStrategy.js +320 -0
  160. package/dist/generated/instructions/instantWithdrawStrategy.js.map +1 -0
  161. package/dist/generated/instructions/instantWithdrawStrategyWithTolerance.d.ts +137 -0
  162. package/dist/generated/instructions/instantWithdrawStrategyWithTolerance.d.ts.map +1 -0
  163. package/dist/generated/instructions/instantWithdrawStrategyWithTolerance.js +320 -0
  164. package/dist/generated/instructions/instantWithdrawStrategyWithTolerance.js.map +1 -0
  165. package/dist/generated/instructions/instantWithdrawVault.d.ts +112 -0
  166. package/dist/generated/instructions/instantWithdrawVault.d.ts.map +1 -0
  167. package/dist/generated/instructions/instantWithdrawVault.js +249 -0
  168. package/dist/generated/instructions/instantWithdrawVault.js.map +1 -0
  169. package/dist/generated/instructions/removeAdaptor.d.ts +63 -0
  170. package/dist/generated/instructions/removeAdaptor.d.ts.map +1 -0
  171. package/dist/generated/instructions/removeAdaptor.js +144 -0
  172. package/dist/generated/instructions/removeAdaptor.js.map +1 -0
  173. package/dist/generated/instructions/requestWithdrawVault.d.ts +104 -0
  174. package/dist/generated/instructions/requestWithdrawVault.d.ts.map +1 -0
  175. package/dist/generated/instructions/requestWithdrawVault.js +225 -0
  176. package/dist/generated/instructions/requestWithdrawVault.js.map +1 -0
  177. package/dist/generated/instructions/updateProtocol.d.ts +57 -0
  178. package/dist/generated/instructions/updateProtocol.d.ts.map +1 -0
  179. package/dist/generated/instructions/updateProtocol.js +111 -0
  180. package/dist/generated/instructions/updateProtocol.js.map +1 -0
  181. package/dist/generated/instructions/updateVaultConfig.d.ts +65 -0
  182. package/dist/generated/instructions/updateVaultConfig.d.ts.map +1 -0
  183. package/dist/generated/instructions/updateVaultConfig.js +133 -0
  184. package/dist/generated/instructions/updateVaultConfig.js.map +1 -0
  185. package/dist/generated/instructions/updateVaultProtocolFee.d.ts +65 -0
  186. package/dist/generated/instructions/updateVaultProtocolFee.d.ts.map +1 -0
  187. package/dist/generated/instructions/updateVaultProtocolFee.js +132 -0
  188. package/dist/generated/instructions/updateVaultProtocolFee.js.map +1 -0
  189. package/dist/generated/instructions/withdrawStrategy.d.ts +111 -0
  190. package/dist/generated/instructions/withdrawStrategy.d.ts.map +1 -0
  191. package/dist/generated/instructions/withdrawStrategy.js +277 -0
  192. package/dist/generated/instructions/withdrawStrategy.js.map +1 -0
  193. package/dist/generated/instructions/withdrawVault.d.ts +103 -0
  194. package/dist/generated/instructions/withdrawVault.d.ts.map +1 -0
  195. package/dist/generated/instructions/withdrawVault.js +258 -0
  196. package/dist/generated/instructions/withdrawVault.js.map +1 -0
  197. package/dist/generated/pdas/adaptorAddReceipt.d.ts +16 -0
  198. package/dist/generated/pdas/adaptorAddReceipt.d.ts.map +1 -0
  199. package/dist/generated/pdas/adaptorAddReceipt.js +26 -0
  200. package/dist/generated/pdas/adaptorAddReceipt.js.map +1 -0
  201. package/dist/generated/pdas/directWithdrawInitReceipt.d.ts +16 -0
  202. package/dist/generated/pdas/directWithdrawInitReceipt.d.ts.map +1 -0
  203. package/dist/generated/pdas/directWithdrawInitReceipt.js +26 -0
  204. package/dist/generated/pdas/directWithdrawInitReceipt.js.map +1 -0
  205. package/dist/generated/pdas/index.d.ts +17 -0
  206. package/dist/generated/pdas/index.d.ts.map +1 -0
  207. package/dist/generated/pdas/index.js +33 -0
  208. package/dist/generated/pdas/index.js.map +1 -0
  209. package/dist/generated/pdas/protocol.d.ts +12 -0
  210. package/dist/generated/pdas/protocol.d.ts.map +1 -0
  211. package/dist/generated/pdas/protocol.js +21 -0
  212. package/dist/generated/pdas/protocol.js.map +1 -0
  213. package/dist/generated/pdas/requestWithdrawVaultReceipt.d.ts +16 -0
  214. package/dist/generated/pdas/requestWithdrawVaultReceipt.d.ts.map +1 -0
  215. package/dist/generated/pdas/requestWithdrawVaultReceipt.js +27 -0
  216. package/dist/generated/pdas/requestWithdrawVaultReceipt.js.map +1 -0
  217. package/dist/generated/pdas/strategyInitReceipt.d.ts +16 -0
  218. package/dist/generated/pdas/strategyInitReceipt.d.ts.map +1 -0
  219. package/dist/generated/pdas/strategyInitReceipt.js +26 -0
  220. package/dist/generated/pdas/strategyInitReceipt.js.map +1 -0
  221. package/dist/generated/pdas/vaultAssetIdleAuth.d.ts +15 -0
  222. package/dist/generated/pdas/vaultAssetIdleAuth.d.ts.map +1 -0
  223. package/dist/generated/pdas/vaultAssetIdleAuth.js +25 -0
  224. package/dist/generated/pdas/vaultAssetIdleAuth.js.map +1 -0
  225. package/dist/generated/pdas/vaultLpMint.d.ts +15 -0
  226. package/dist/generated/pdas/vaultLpMint.d.ts.map +1 -0
  227. package/dist/generated/pdas/vaultLpMint.js +24 -0
  228. package/dist/generated/pdas/vaultLpMint.js.map +1 -0
  229. package/dist/generated/pdas/vaultLpMintAuth.d.ts +15 -0
  230. package/dist/generated/pdas/vaultLpMintAuth.d.ts.map +1 -0
  231. package/dist/generated/pdas/vaultLpMintAuth.js +25 -0
  232. package/dist/generated/pdas/vaultLpMintAuth.js.map +1 -0
  233. package/dist/generated/pdas/vaultStrategyAuth.d.ts +16 -0
  234. package/dist/generated/pdas/vaultStrategyAuth.d.ts.map +1 -0
  235. package/dist/generated/pdas/vaultStrategyAuth.js +26 -0
  236. package/dist/generated/pdas/vaultStrategyAuth.js.map +1 -0
  237. package/dist/generated/programs/index.d.ts +9 -0
  238. package/dist/generated/programs/index.d.ts.map +1 -0
  239. package/dist/generated/programs/index.js +25 -0
  240. package/dist/generated/programs/index.js.map +1 -0
  241. package/dist/generated/programs/voltrVault.d.ts +172 -0
  242. package/dist/generated/programs/voltrVault.d.ts.map +1 -0
  243. package/dist/generated/programs/voltrVault.js +447 -0
  244. package/dist/generated/programs/voltrVault.js.map +1 -0
  245. package/dist/generated/types/acceptProtocolAdminEvent.d.ts +24 -0
  246. package/dist/generated/types/acceptProtocolAdminEvent.d.ts.map +1 -0
  247. package/dist/generated/types/acceptProtocolAdminEvent.js +33 -0
  248. package/dist/generated/types/acceptProtocolAdminEvent.js.map +1 -0
  249. package/dist/generated/types/acceptVaultAdminEvent.d.ts +24 -0
  250. package/dist/generated/types/acceptVaultAdminEvent.d.ts.map +1 -0
  251. package/dist/generated/types/acceptVaultAdminEvent.js +33 -0
  252. package/dist/generated/types/acceptVaultAdminEvent.js.map +1 -0
  253. package/dist/generated/types/addAdaptorEvent.d.ts +28 -0
  254. package/dist/generated/types/addAdaptorEvent.d.ts.map +1 -0
  255. package/dist/generated/types/addAdaptorEvent.js +37 -0
  256. package/dist/generated/types/addAdaptorEvent.js.map +1 -0
  257. package/dist/generated/types/calibrateHighWaterMarkEvent.d.ts +34 -0
  258. package/dist/generated/types/calibrateHighWaterMarkEvent.d.ts.map +1 -0
  259. package/dist/generated/types/calibrateHighWaterMarkEvent.js +43 -0
  260. package/dist/generated/types/calibrateHighWaterMarkEvent.js.map +1 -0
  261. package/dist/generated/types/calibrateHighWaterMarkUnsafeEvent.d.ts +30 -0
  262. package/dist/generated/types/calibrateHighWaterMarkUnsafeEvent.d.ts.map +1 -0
  263. package/dist/generated/types/calibrateHighWaterMarkUnsafeEvent.js +39 -0
  264. package/dist/generated/types/calibrateHighWaterMarkUnsafeEvent.js.map +1 -0
  265. package/dist/generated/types/cancelRequestWithdrawVaultEvent.d.ts +32 -0
  266. package/dist/generated/types/cancelRequestWithdrawVaultEvent.d.ts.map +1 -0
  267. package/dist/generated/types/cancelRequestWithdrawVaultEvent.js +41 -0
  268. package/dist/generated/types/cancelRequestWithdrawVaultEvent.js.map +1 -0
  269. package/dist/generated/types/closeStrategyEvent.d.ts +26 -0
  270. package/dist/generated/types/closeStrategyEvent.d.ts.map +1 -0
  271. package/dist/generated/types/closeStrategyEvent.js +35 -0
  272. package/dist/generated/types/closeStrategyEvent.js.map +1 -0
  273. package/dist/generated/types/depositStrategyEvent.d.ts +52 -0
  274. package/dist/generated/types/depositStrategyEvent.d.ts.map +1 -0
  275. package/dist/generated/types/depositStrategyEvent.js +61 -0
  276. package/dist/generated/types/depositStrategyEvent.js.map +1 -0
  277. package/dist/generated/types/depositVaultEvent.d.ts +48 -0
  278. package/dist/generated/types/depositVaultEvent.d.ts.map +1 -0
  279. package/dist/generated/types/depositVaultEvent.js +57 -0
  280. package/dist/generated/types/depositVaultEvent.js.map +1 -0
  281. package/dist/generated/types/directWithdrawStrategyEvent.d.ts +62 -0
  282. package/dist/generated/types/directWithdrawStrategyEvent.d.ts.map +1 -0
  283. package/dist/generated/types/directWithdrawStrategyEvent.js +71 -0
  284. package/dist/generated/types/directWithdrawStrategyEvent.js.map +1 -0
  285. package/dist/generated/types/feeConfiguration.d.ts +33 -0
  286. package/dist/generated/types/feeConfiguration.d.ts.map +1 -0
  287. package/dist/generated/types/feeConfiguration.js +43 -0
  288. package/dist/generated/types/feeConfiguration.js.map +1 -0
  289. package/dist/generated/types/feeState.d.ts +32 -0
  290. package/dist/generated/types/feeState.d.ts.map +1 -0
  291. package/dist/generated/types/feeState.js +33 -0
  292. package/dist/generated/types/feeState.js.map +1 -0
  293. package/dist/generated/types/feeUpdate.d.ts +24 -0
  294. package/dist/generated/types/feeUpdate.d.ts.map +1 -0
  295. package/dist/generated/types/feeUpdate.js +29 -0
  296. package/dist/generated/types/feeUpdate.js.map +1 -0
  297. package/dist/generated/types/harvestFeeEvent.d.ts +32 -0
  298. package/dist/generated/types/harvestFeeEvent.d.ts.map +1 -0
  299. package/dist/generated/types/harvestFeeEvent.js +41 -0
  300. package/dist/generated/types/harvestFeeEvent.js.map +1 -0
  301. package/dist/generated/types/highWaterMark.d.ts +28 -0
  302. package/dist/generated/types/highWaterMark.d.ts.map +1 -0
  303. package/dist/generated/types/highWaterMark.js +31 -0
  304. package/dist/generated/types/highWaterMark.js.map +1 -0
  305. package/dist/generated/types/index.d.ts +44 -0
  306. package/dist/generated/types/index.d.ts.map +1 -0
  307. package/dist/generated/types/index.js +60 -0
  308. package/dist/generated/types/index.js.map +1 -0
  309. package/dist/generated/types/initProtocolEvent.d.ts +22 -0
  310. package/dist/generated/types/initProtocolEvent.d.ts.map +1 -0
  311. package/dist/generated/types/initProtocolEvent.js +31 -0
  312. package/dist/generated/types/initProtocolEvent.js.map +1 -0
  313. package/dist/generated/types/initializeDirectWithdrawStrategyEvent.d.ts +34 -0
  314. package/dist/generated/types/initializeDirectWithdrawStrategyEvent.d.ts.map +1 -0
  315. package/dist/generated/types/initializeDirectWithdrawStrategyEvent.js +55 -0
  316. package/dist/generated/types/initializeDirectWithdrawStrategyEvent.js.map +1 -0
  317. package/dist/generated/types/initializeStrategyEvent.d.ts +32 -0
  318. package/dist/generated/types/initializeStrategyEvent.d.ts.map +1 -0
  319. package/dist/generated/types/initializeStrategyEvent.js +41 -0
  320. package/dist/generated/types/initializeStrategyEvent.js.map +1 -0
  321. package/dist/generated/types/initializeVaultEvent.d.ts +56 -0
  322. package/dist/generated/types/initializeVaultEvent.d.ts.map +1 -0
  323. package/dist/generated/types/initializeVaultEvent.js +71 -0
  324. package/dist/generated/types/initializeVaultEvent.js.map +1 -0
  325. package/dist/generated/types/instantWithdrawStrategyEvent.d.ts +68 -0
  326. package/dist/generated/types/instantWithdrawStrategyEvent.d.ts.map +1 -0
  327. package/dist/generated/types/instantWithdrawStrategyEvent.js +77 -0
  328. package/dist/generated/types/instantWithdrawStrategyEvent.js.map +1 -0
  329. package/dist/generated/types/instantWithdrawVaultEvent.d.ts +56 -0
  330. package/dist/generated/types/instantWithdrawVaultEvent.d.ts.map +1 -0
  331. package/dist/generated/types/instantWithdrawVaultEvent.js +65 -0
  332. package/dist/generated/types/instantWithdrawVaultEvent.js.map +1 -0
  333. package/dist/generated/types/lockedProfitState.d.ts +20 -0
  334. package/dist/generated/types/lockedProfitState.d.ts.map +1 -0
  335. package/dist/generated/types/lockedProfitState.js +29 -0
  336. package/dist/generated/types/lockedProfitState.js.map +1 -0
  337. package/dist/generated/types/protocolConfigField.d.ts +17 -0
  338. package/dist/generated/types/protocolConfigField.d.ts.map +1 -0
  339. package/dist/generated/types/protocolConfigField.js +29 -0
  340. package/dist/generated/types/protocolConfigField.js.map +1 -0
  341. package/dist/generated/types/protocolFeeField.d.ts +17 -0
  342. package/dist/generated/types/protocolFeeField.d.ts.map +1 -0
  343. package/dist/generated/types/protocolFeeField.js +29 -0
  344. package/dist/generated/types/protocolFeeField.js.map +1 -0
  345. package/dist/generated/types/removeAdaptorEvent.d.ts +26 -0
  346. package/dist/generated/types/removeAdaptorEvent.d.ts.map +1 -0
  347. package/dist/generated/types/removeAdaptorEvent.js +35 -0
  348. package/dist/generated/types/removeAdaptorEvent.js.map +1 -0
  349. package/dist/generated/types/requestWithdrawVaultEvent.d.ts +44 -0
  350. package/dist/generated/types/requestWithdrawVaultEvent.d.ts.map +1 -0
  351. package/dist/generated/types/requestWithdrawVaultEvent.js +53 -0
  352. package/dist/generated/types/requestWithdrawVaultEvent.js.map +1 -0
  353. package/dist/generated/types/updateProtocolEvent.d.ts +28 -0
  354. package/dist/generated/types/updateProtocolEvent.d.ts.map +1 -0
  355. package/dist/generated/types/updateProtocolEvent.js +37 -0
  356. package/dist/generated/types/updateProtocolEvent.js.map +1 -0
  357. package/dist/generated/types/updateVaultConfigEvent.d.ts +28 -0
  358. package/dist/generated/types/updateVaultConfigEvent.d.ts.map +1 -0
  359. package/dist/generated/types/updateVaultConfigEvent.js +37 -0
  360. package/dist/generated/types/updateVaultConfigEvent.js.map +1 -0
  361. package/dist/generated/types/updateVaultEvent.d.ts +62 -0
  362. package/dist/generated/types/updateVaultEvent.d.ts.map +1 -0
  363. package/dist/generated/types/updateVaultEvent.js +71 -0
  364. package/dist/generated/types/updateVaultEvent.js.map +1 -0
  365. package/dist/generated/types/updateVaultProtocolFeeEvent.d.ts +28 -0
  366. package/dist/generated/types/updateVaultProtocolFeeEvent.d.ts.map +1 -0
  367. package/dist/generated/types/updateVaultProtocolFeeEvent.js +37 -0
  368. package/dist/generated/types/updateVaultProtocolFeeEvent.js.map +1 -0
  369. package/dist/generated/types/vaultAsset.d.ts +36 -0
  370. package/dist/generated/types/vaultAsset.d.ts.map +1 -0
  371. package/dist/generated/types/vaultAsset.js +35 -0
  372. package/dist/generated/types/vaultAsset.js.map +1 -0
  373. package/dist/generated/types/vaultConfigField.d.ts +28 -0
  374. package/dist/generated/types/vaultConfigField.d.ts.map +1 -0
  375. package/dist/generated/types/vaultConfigField.js +40 -0
  376. package/dist/generated/types/vaultConfigField.js.map +1 -0
  377. package/dist/generated/types/vaultConfiguration.d.ts +40 -0
  378. package/dist/generated/types/vaultConfiguration.d.ts.map +1 -0
  379. package/dist/generated/types/vaultConfiguration.js +37 -0
  380. package/dist/generated/types/vaultConfiguration.js.map +1 -0
  381. package/dist/generated/types/vaultLp.d.ts +23 -0
  382. package/dist/generated/types/vaultLp.d.ts.map +1 -0
  383. package/dist/generated/types/vaultLp.js +33 -0
  384. package/dist/generated/types/vaultLp.js.map +1 -0
  385. package/dist/generated/types/withdrawStrategyEvent.d.ts +52 -0
  386. package/dist/generated/types/withdrawStrategyEvent.d.ts.map +1 -0
  387. package/dist/generated/types/withdrawStrategyEvent.js +61 -0
  388. package/dist/generated/types/withdrawStrategyEvent.js.map +1 -0
  389. package/dist/generated/types/withdrawVaultEvent.d.ts +50 -0
  390. package/dist/generated/types/withdrawVaultEvent.d.ts.map +1 -0
  391. package/dist/generated/types/withdrawVaultEvent.js +59 -0
  392. package/dist/generated/types/withdrawVaultEvent.js.map +1 -0
  393. package/dist/index.d.ts +3 -4
  394. package/dist/index.d.ts.map +1 -0
  395. package/dist/index.js +3 -4
  396. package/dist/index.js.map +1 -0
  397. package/package.json +31 -27
  398. package/src/extensions/batchFetchers.ts +121 -0
  399. package/src/extensions/decimal.ts +15 -0
  400. package/src/extensions/events.ts +328 -0
  401. package/src/extensions/fees.ts +36 -0
  402. package/src/extensions/index.ts +10 -0
  403. package/src/extensions/lpEconomics.ts +225 -0
  404. package/src/extensions/math.ts +338 -0
  405. package/src/extensions/metadataPda.ts +47 -0
  406. package/src/extensions/position.ts +54 -0
  407. package/src/extensions/rpc.ts +17 -0
  408. package/src/extensions/withdrawals.ts +113 -0
  409. package/src/generated/accounts/adaptorAddReceipt.ts +194 -0
  410. package/src/generated/accounts/directWithdrawInitReceipt.ts +235 -0
  411. package/src/generated/accounts/index.ts +14 -0
  412. package/src/generated/accounts/protocol.ts +176 -0
  413. package/src/generated/accounts/requestWithdrawVaultReceipt.ts +197 -0
  414. package/src/generated/accounts/strategyInitReceipt.ts +221 -0
  415. package/src/generated/accounts/vault.ts +274 -0
  416. package/src/generated/errors/index.ts +9 -0
  417. package/src/generated/errors/voltrVault.ts +112 -0
  418. package/src/generated/index.ts +14 -0
  419. package/src/generated/instructions/acceptProtocolAdmin.ts +248 -0
  420. package/src/generated/instructions/acceptVaultAdmin.ts +187 -0
  421. package/src/generated/instructions/addAdaptor.ts +391 -0
  422. package/src/generated/instructions/calibrateHighWaterMark.ts +394 -0
  423. package/src/generated/instructions/calibrateHighWaterMarkUnsafe.ts +311 -0
  424. package/src/generated/instructions/cancelRequestWithdrawVault.ts +546 -0
  425. package/src/generated/instructions/closeStrategy.ts +395 -0
  426. package/src/generated/instructions/createLpMetadata.ts +501 -0
  427. package/src/generated/instructions/depositStrategy.ts +737 -0
  428. package/src/generated/instructions/depositVault.ts +686 -0
  429. package/src/generated/instructions/directWithdrawStrategy.ts +903 -0
  430. package/src/generated/instructions/directWithdrawStrategyWithTolerance.ts +913 -0
  431. package/src/generated/instructions/harvestFee.ts +599 -0
  432. package/src/generated/instructions/index.ts +35 -0
  433. package/src/generated/instructions/initProtocol.ts +329 -0
  434. package/src/generated/instructions/initializeDirectWithdrawStrategy.ts +576 -0
  435. package/src/generated/instructions/initializeStrategy.ts +557 -0
  436. package/src/generated/instructions/initializeVault.ts +784 -0
  437. package/src/generated/instructions/instantWithdrawStrategy.ts +870 -0
  438. package/src/generated/instructions/instantWithdrawStrategyWithTolerance.ts +878 -0
  439. package/src/generated/instructions/instantWithdrawVault.ts +670 -0
  440. package/src/generated/instructions/removeAdaptor.ts +371 -0
  441. package/src/generated/instructions/requestWithdrawVault.ts +608 -0
  442. package/src/generated/instructions/updateProtocol.ts +270 -0
  443. package/src/generated/instructions/updateVaultConfig.ts +343 -0
  444. package/src/generated/instructions/updateVaultProtocolFee.ts +344 -0
  445. package/src/generated/instructions/withdrawStrategy.ts +737 -0
  446. package/src/generated/instructions/withdrawVault.ts +685 -0
  447. package/src/generated/pdas/adaptorAddReceipt.ts +42 -0
  448. package/src/generated/pdas/directWithdrawInitReceipt.ts +42 -0
  449. package/src/generated/pdas/index.ts +17 -0
  450. package/src/generated/pdas/protocol.ts +30 -0
  451. package/src/generated/pdas/requestWithdrawVaultReceipt.ts +43 -0
  452. package/src/generated/pdas/strategyInitReceipt.ts +42 -0
  453. package/src/generated/pdas/vaultAssetIdleAuth.ts +40 -0
  454. package/src/generated/pdas/vaultLpMint.ts +39 -0
  455. package/src/generated/pdas/vaultLpMintAuth.ts +40 -0
  456. package/src/generated/pdas/vaultStrategyAuth.ts +42 -0
  457. package/src/generated/programs/index.ts +9 -0
  458. package/src/generated/programs/voltrVault.ts +1261 -0
  459. package/src/generated/types/acceptProtocolAdminEvent.ts +63 -0
  460. package/src/generated/types/acceptVaultAdminEvent.ts +63 -0
  461. package/src/generated/types/addAdaptorEvent.ts +68 -0
  462. package/src/generated/types/calibrateHighWaterMarkEvent.ts +85 -0
  463. package/src/generated/types/calibrateHighWaterMarkUnsafeEvent.ts +77 -0
  464. package/src/generated/types/cancelRequestWithdrawVaultEvent.ts +81 -0
  465. package/src/generated/types/closeStrategyEvent.ts +67 -0
  466. package/src/generated/types/depositStrategyEvent.ts +121 -0
  467. package/src/generated/types/depositVaultEvent.ts +113 -0
  468. package/src/generated/types/directWithdrawStrategyEvent.ts +141 -0
  469. package/src/generated/types/feeConfiguration.ts +84 -0
  470. package/src/generated/types/feeState.ts +67 -0
  471. package/src/generated/types/feeUpdate.ts +50 -0
  472. package/src/generated/types/harvestFeeEvent.ts +76 -0
  473. package/src/generated/types/highWaterMark.ts +66 -0
  474. package/src/generated/types/index.ts +44 -0
  475. package/src/generated/types/initProtocolEvent.ts +61 -0
  476. package/src/generated/types/initializeDirectWithdrawStrategyEvent.ts +104 -0
  477. package/src/generated/types/initializeStrategyEvent.ts +81 -0
  478. package/src/generated/types/initializeVaultEvent.ts +141 -0
  479. package/src/generated/types/instantWithdrawStrategyEvent.ts +155 -0
  480. package/src/generated/types/instantWithdrawVaultEvent.ts +131 -0
  481. package/src/generated/types/lockedProfitState.ts +52 -0
  482. package/src/generated/types/protocolConfigField.ts +41 -0
  483. package/src/generated/types/protocolFeeField.ts +41 -0
  484. package/src/generated/types/removeAdaptorEvent.ts +67 -0
  485. package/src/generated/types/requestWithdrawVaultEvent.ts +107 -0
  486. package/src/generated/types/updateProtocolEvent.ts +77 -0
  487. package/src/generated/types/updateVaultConfigEvent.ts +77 -0
  488. package/src/generated/types/updateVaultEvent.ts +141 -0
  489. package/src/generated/types/updateVaultProtocolFeeEvent.ts +79 -0
  490. package/src/generated/types/vaultAsset.ts +81 -0
  491. package/src/generated/types/vaultConfigField.ts +52 -0
  492. package/src/generated/types/vaultConfiguration.ts +87 -0
  493. package/src/generated/types/vaultLp.ts +61 -0
  494. package/src/generated/types/withdrawStrategyEvent.ts +121 -0
  495. package/src/generated/types/withdrawVaultEvent.ts +117 -0
  496. package/src/index.ts +2 -0
  497. package/README.md +0 -453
  498. package/dist/client.d.ts +0 -1544
  499. package/dist/client.js +0 -1962
  500. package/dist/constants.d.ts +0 -20
  501. package/dist/constants.js +0 -27
  502. package/dist/decimals.d.ts +0 -3
  503. package/dist/decimals.js +0 -10
  504. package/dist/idl/voltr_vault.json +0 -9029
  505. package/dist/types/index.d.ts +0 -2
  506. package/dist/types/vault.d.ts +0 -70
  507. package/dist/types/vault.js +0 -29
  508. package/dist/types/voltr_vault.d.ts +0 -9035
package/dist/client.js DELETED
@@ -1,1962 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.VoltrClient = void 0;
40
- const anchor_1 = require("@coral-xyz/anchor");
41
- const bn_js_1 = __importDefault(require("bn.js"));
42
- const web3_js_1 = require("@solana/web3.js");
43
- const spl_token_1 = require("@solana/spl-token");
44
- const constants_1 = require("./constants");
45
- const types_1 = require("./types");
46
- // Import IDL files
47
- const vaultIdl = __importStar(require("./idl/voltr_vault.json"));
48
- const decimals_1 = require("./decimals");
49
- class CustomWallet {
50
- constructor(payer) {
51
- this.payer = payer;
52
- }
53
- async signTransaction(tx) {
54
- tx.partialSign(this.payer);
55
- return tx;
56
- }
57
- async signAllTransactions(txs) {
58
- return txs.map((t) => {
59
- t.partialSign(this.payer);
60
- return t;
61
- });
62
- }
63
- get publicKey() {
64
- return this.payer.publicKey;
65
- }
66
- }
67
- class AccountUtils {
68
- constructor(conn) {
69
- this.conn = conn;
70
- }
71
- /**
72
- * Gets the balance of a Solana account
73
- * @param publicKey - Public key to check balance for
74
- * @returns Promise resolving to the account balance in lamports
75
- * @throws {Error} If fetching balance fails
76
- */
77
- async getBalance(publicKey) {
78
- try {
79
- return await this.conn.getBalance(publicKey);
80
- }
81
- catch (error) {
82
- throw new Error(`Failed to get account balance: ${error}`);
83
- }
84
- }
85
- }
86
- /**
87
- * Main client for interacting with the Voltr protocol
88
- *
89
- * @remarks
90
- * The VoltrClient provides methods for initializing and managing vaults,
91
- * handling strategies, and performing deposits/withdrawals. It requires
92
- * a Solana connection and optionally accepts a wallet for signing transactions.
93
- *
94
- * @example
95
- * ```typescript
96
- * import { VoltrClient } from '@voltr/vault-sdk';
97
- * import { Connection } from '@solana/web3.js';
98
- *
99
- * const connection = new Connection('https://api.mainnet-beta.solana.com');
100
- * const client = new VoltrClient(connection);
101
- * ```
102
- */
103
- class VoltrClient extends AccountUtils {
104
- /**
105
- * Creates a new VoltrClient instance
106
- * @param conn - Solana connection instance
107
- * @param wallet - Optional keypair for signing transactions
108
- */
109
- constructor(conn, wallet, opts) {
110
- super(conn);
111
- // Initialize programs
112
- this.setProvider(wallet, opts);
113
- this.setPrograms(vaultIdl);
114
- }
115
- setProvider(wallet, opts) {
116
- /// we are creating instructions with this client without signing
117
- let kp;
118
- if (!wallet) {
119
- const leakedKp = web3_js_1.Keypair.fromSecretKey(Uint8Array.from([
120
- 208, 175, 150, 242, 88, 34, 108, 88, 177, 16, 168, 75, 115, 181, 199,
121
- 242, 120, 4, 78, 75, 19, 227, 13, 215, 184, 108, 226, 53, 111, 149,
122
- 179, 84, 137, 121, 79, 1, 160, 223, 124, 241, 202, 203, 220, 237, 50,
123
- 242, 57, 158, 226, 207, 203, 188, 43, 28, 70, 110, 214, 234, 251, 15,
124
- 249, 157, 62, 80,
125
- ]));
126
- kp = leakedKp;
127
- }
128
- else {
129
- kp = wallet;
130
- }
131
- this.provider = new anchor_1.AnchorProvider(this.conn, new CustomWallet(kp), opts ?? anchor_1.AnchorProvider.defaultOptions());
132
- (0, anchor_1.setProvider)(this.provider);
133
- }
134
- setPrograms(vaultIdl) {
135
- this.vaultProgram = new anchor_1.Program(vaultIdl, this.provider);
136
- }
137
- // --------------------------------------- Find PDA addresses
138
- /**
139
- * Finds the vault LP mint address for a given vault
140
- * @param vault - Public key of the vault
141
- * @returns The PDA for the vault's LP mint
142
- */
143
- findVaultLpMint(vault) {
144
- const [vaultLpMint] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.VAULT_LP_MINT, vault.toBuffer()], this.vaultProgram.programId);
145
- return vaultLpMint;
146
- }
147
- /**
148
- * Finds the vault's asset idle authority address
149
- * @param vault - Public key of the vault
150
- * @returns The PDA for the vault's asset idle authority
151
- */
152
- findVaultAssetIdleAuth(vault) {
153
- const [vaultAssetIdleAuth] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.VAULT_ASSET_IDLE_AUTH, vault.toBuffer()], this.vaultProgram.programId);
154
- return vaultAssetIdleAuth;
155
- }
156
- /**
157
- * Finds all vault-related addresses
158
- * @param vault - Public key of the vault
159
- * @returns Object containing all vault-related PDAs
160
- *
161
- * @example
162
- * ```typescript
163
- * const addresses = client.findVaultAddresses(vaultPubkey);
164
- * console.log(addresses.vaultLpMint.toBase58());
165
- * console.log(addresses.vaultAssetIdleAuth.toBase58());
166
- * console.log(addresses.vaultLpFeeAuth.toBase58());
167
- * ```
168
- */
169
- findVaultAddresses(vault) {
170
- const vaultLpMint = this.findVaultLpMint(vault);
171
- const vaultAssetIdleAuth = this.findVaultAssetIdleAuth(vault);
172
- return {
173
- vaultLpMint,
174
- vaultAssetIdleAuth,
175
- };
176
- }
177
- /**
178
- * Finds the vault strategy auth address
179
- * @param vault - Public key of the vault
180
- * @param strategy - Public key of the strategy
181
- * @returns The PDA for the vault strategy auth
182
- *
183
- * @example
184
- * ```typescript
185
- * const vaultStrategyAuth = client.findVaultStrategyAuth(vaultPubkey, strategyPubkey);
186
- * ```
187
- */
188
- findVaultStrategyAuth(vault, strategy) {
189
- const [vaultStrategyAuth] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.VAULT_STRATEGY_AUTH, vault.toBuffer(), strategy.toBuffer()], this.vaultProgram.programId);
190
- return vaultStrategyAuth;
191
- }
192
- /**
193
- * Finds the strategy init receipt address
194
- * @param vault - Public key of the vault
195
- * @param strategy - Public key of the strategy
196
- * @returns The PDA for the strategy init receipt
197
- *
198
- * @example
199
- * ```typescript
200
- * const strategyInitReceipt = client.findStrategyInitReceipt(vaultPubkey, strategyPubkey);
201
- * ```
202
- */
203
- findStrategyInitReceipt(vault, strategy) {
204
- const [strategyInitReceipt] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.STRATEGY_INIT_RECEIPT, vault.toBuffer(), strategy.toBuffer()], this.vaultProgram.programId);
205
- return strategyInitReceipt;
206
- }
207
- /**
208
- * Finds the direct withdraw init receipt address
209
- * @param vault - Public key of the vault
210
- * @param strategy - Public key of the strategy
211
- * @returns The PDA for the direct withdraw init receipt
212
- *
213
- * @example
214
- * ```typescript
215
- * const directWithdrawInitReceipt = client.findDirectWithdrawInitReceipt(vaultPubkey, strategyPubkey);
216
- * ```
217
- */
218
- findDirectWithdrawInitReceipt(vault, strategy) {
219
- const [directWithdrawInitReceipt] = web3_js_1.PublicKey.findProgramAddressSync([
220
- constants_1.SEEDS.DIRECT_WITHDRAW_INIT_RECEIPT_SEED,
221
- vault.toBuffer(),
222
- strategy.toBuffer(),
223
- ], this.vaultProgram.programId);
224
- return directWithdrawInitReceipt;
225
- }
226
- findVaultStrategyAddresses(vault, strategy) {
227
- const vaultStrategyAuth = this.findVaultStrategyAuth(vault, strategy);
228
- const strategyInitReceipt = this.findStrategyInitReceipt(vault, strategy);
229
- const directWithdrawInitReceipt = this.findDirectWithdrawInitReceipt(vault, strategy);
230
- return {
231
- vaultStrategyAuth,
232
- strategyInitReceipt,
233
- directWithdrawInitReceipt,
234
- };
235
- }
236
- /**
237
- * Finds the request withdraw vault receipt address
238
- * @param vault - Public key of the vault
239
- * @param user - Public key of the user
240
- * @returns The PDA for the request withdraw vault receipt
241
- *
242
- * @example
243
- * ```typescript
244
- * const requestWithdrawVaultReceipt = client.findRequestWithdrawVaultReceipt(vaultPubkey, userPubkey);
245
- * ```
246
- */
247
- findRequestWithdrawVaultReceipt(vault, user) {
248
- const [requestWithdrawVaultReceipt] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.REQUEST_WITHDRAW_VAULT_RECEIPT, vault.toBuffer(), user.toBuffer()], this.vaultProgram.programId);
249
- return requestWithdrawVaultReceipt;
250
- }
251
- /**
252
- * Finds the LP metadata account for a given vault
253
- * @param vault - Public key of the vault
254
- * @returns The PDA for the LP metadata account
255
- *
256
- * @example
257
- * ```typescript
258
- * const lpMetadataAccount = client.findLpMetadataAccount(vaultPubkey);
259
- * ```
260
- */
261
- findLpMetadataAccount(vault) {
262
- const lpMint = this.findVaultLpMint(vault);
263
- const [lpMetadataAccount] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.METADATA, constants_1.METADATA_PROGRAM_ID.toBuffer(), lpMint.toBuffer()], constants_1.METADATA_PROGRAM_ID);
264
- return lpMetadataAccount;
265
- }
266
- /**
267
- * Finds the protocol PDA address
268
- * @returns The PDA for the protocol account
269
- *
270
- * @example
271
- * ```typescript
272
- * const protocol = client.findProtocol();
273
- * ```
274
- */
275
- findProtocol() {
276
- const [protocol] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.PROTOCOL], this.vaultProgram.programId);
277
- return protocol;
278
- }
279
- // --------------------------------------- Protocol Instructions
280
- /**
281
- * Creates an instruction to initialize the protocol
282
- *
283
- * @param {number} operationalState - Bitflags for allowed operations (e.g., CREATE_VAULT = 1, DEPOSIT_VAULT = 2, etc.)
284
- * @param {Object} params - Parameters for initializing the protocol
285
- * @param {PublicKey} params.payer - Public key of the fee payer
286
- * @param {PublicKey} params.admin - Public key of the protocol admin
287
- * @returns {Promise<TransactionInstruction>} Transaction instruction for initializing the protocol
288
- *
289
- * @example
290
- * ```typescript
291
- * const ix = await client.createInitProtocolIx(
292
- * 0xFFFF, // enable all operations
293
- * {
294
- * payer: payerPubkey,
295
- * admin: adminPubkey,
296
- * }
297
- * );
298
- * ```
299
- */
300
- async createInitProtocolIx(operationalState, { payer, admin, }) {
301
- return await this.vaultProgram.methods
302
- .initProtocol(operationalState)
303
- .accounts({
304
- payer,
305
- admin,
306
- })
307
- .instruction();
308
- }
309
- /**
310
- * Creates an instruction to update the protocol configuration
311
- *
312
- * @param {ProtocolConfigField} field - The protocol configuration field to update
313
- * @param {Buffer} data - The serialized data for the new value
314
- * @param {Object} params - Parameters for updating the protocol
315
- * @param {PublicKey} params.admin - Public key of the protocol admin
316
- * @returns {Promise<TransactionInstruction>} Transaction instruction for updating the protocol
317
- *
318
- * @throws {Error} If the field is unknown
319
- *
320
- * @example Update operational state
321
- * ```typescript
322
- * const data = Buffer.alloc(2);
323
- * data.writeUInt16LE(0xFFFF, 0);
324
- * const ix = await client.createUpdateProtocolIx(
325
- * ProtocolConfigField.OperationalState,
326
- * data,
327
- * { admin: adminPubkey }
328
- * );
329
- * ```
330
- *
331
- * @example Set pending admin for 2-step transfer
332
- * ```typescript
333
- * const data = newAdmin.toBuffer();
334
- * const ix = await client.createUpdateProtocolIx(
335
- * ProtocolConfigField.PendingAdmin,
336
- * data,
337
- * { admin: adminPubkey }
338
- * );
339
- * ```
340
- */
341
- async createUpdateProtocolIx(field, data, { admin, }) {
342
- const fieldToVariant = {
343
- [types_1.ProtocolConfigField.OperationalState]: { operationalState: {} },
344
- [types_1.ProtocolConfigField.PendingAdmin]: { pendingAdmin: {} },
345
- };
346
- const fieldVariant = fieldToVariant[field];
347
- if (!fieldVariant) {
348
- throw new Error(`Unknown protocol config field: ${field}`);
349
- }
350
- return await this.vaultProgram.methods
351
- .updateProtocol(fieldVariant, data)
352
- .accounts({
353
- admin,
354
- })
355
- .instruction();
356
- }
357
- /**
358
- * Creates an instruction to accept a protocol admin transfer (2-step admin transfer)
359
- *
360
- * @param {Object} params - Parameters for accepting protocol admin
361
- * @param {PublicKey} params.pendingAdmin - Public key of the pending admin (must be signer)
362
- * @returns {Promise<TransactionInstruction>} Transaction instruction for accepting protocol admin
363
- *
364
- * @example
365
- * ```typescript
366
- * const ix = await client.createAcceptProtocolAdminIx({
367
- * pendingAdmin: pendingAdminPubkey,
368
- * });
369
- * ```
370
- */
371
- async createAcceptProtocolAdminIx({ pendingAdmin, }) {
372
- return await this.vaultProgram.methods
373
- .acceptProtocolAdmin()
374
- .accounts({
375
- pendingAdmin,
376
- })
377
- .instruction();
378
- }
379
- // --------------------------------------- Vault Instructions
380
- /**
381
- * Creates an instruction to initialize a new vault
382
- *
383
- * @param {VaultParams} vaultParams - Configuration parameters for the vault
384
- * @param {VaultConfig} vaultParams.config - Vault configuration settings
385
- * @param {BN} vaultParams.config.maxCap - Maximum capacity of the vault
386
- * @param {BN} vaultParams.config.startAtTs - Vault start timestamp in seconds
387
- * @param {BN} vaultParams.config.lockedProfitDegradationDuration - Locked profit degradation duration in seconds
388
- * @param {number} vaultParams.config.managerManagementFee - Manager's management fee in basis points (e.g., 50 = 0.5%)
389
- * @param {number} vaultParams.config.managerPerformanceFee - Manager's performance fee in basis points (e.g., 1000 = 10%)
390
- * @param {number} vaultParams.config.adminManagementFee - Admin's management fee in basis points (e.g., 50 = 0.5%)
391
- * @param {number} vaultParams.config.adminPerformanceFee - Admin's performance fee in basis points (e.g., 1000 = 10%)
392
- * @param {number} vaultParams.config.redemptionFee - Redemption fee in basis points (e.g., 10 = 0.1%)
393
- * @param {number} vaultParams.config.issuanceFee - Issuance fee in basis points (e.g., 10 = 0.1%)
394
- * @param {BN} vaultParams.config.withdrawalWaitingPeriod - Withdrawal waiting period in seconds
395
- * @param {string} vaultParams.name - Name of the vault
396
- * @param {string} vaultParams.description - Description of the vault
397
- * @param {Object} params - Additional parameters for initializing the vault
398
- * @param {Keypair} params.vault - Keypair for the new vault
399
- * @param {PublicKey} params.vaultAssetMint - Public key of the vault's asset mint
400
- * @param {PublicKey} params.admin - Public key of the vault admin
401
- * @param {PublicKey} params.manager - Public key of the vault manager
402
- * @param {PublicKey} params.payer - Public key of the fee payer
403
- * @returns {Promise<TransactionInstruction>} Transaction instruction for initializing the vault
404
- *
405
- * @example
406
- * ```typescript
407
- * const ix = await client.createInitializeVaultIx(
408
- * {
409
- * config: {
410
- * maxCap: new BN('1000000000'),
411
- * startAtTs: new BN(Math.floor(Date.now() / 1000)),
412
- * lockedProfitDegradationDuration: new BN(3600), // 1 hour
413
- * redemptionFee: 10,
414
- * issuanceFee: 10,
415
- * withdrawalWaitingPeriod: new BN(3600), // 1 hour
416
- * managerManagementFee: 50, // 0.5%
417
- * managerPerformanceFee: 1000, // 10%
418
- * adminManagementFee: 50, // 0.5%
419
- * adminPerformanceFee: 1000, // 10%
420
- * },
421
- * name: "My Vault",
422
- * description: "Example vault"
423
- * },
424
- * {
425
- * vault: vaultKeypair,
426
- * vaultAssetMint: new PublicKey('...'),
427
- * admin: adminPubkey,
428
- * manager: managerPubkey,
429
- * payer: payerPubkey
430
- * }
431
- * );
432
- * ```
433
- */
434
- async createInitializeVaultIx(vaultParams, { vault, vaultAssetMint, admin, manager, payer, }) {
435
- const addresses = this.findVaultAddresses(vault);
436
- const vaultAssetMintAccount = await this.provider.connection.getAccountInfo(vaultAssetMint);
437
- const assetTokenProgram = vaultAssetMintAccount?.owner;
438
- if (!assetTokenProgram) {
439
- throw new Error("Vault asset mint not found");
440
- }
441
- const vaultAssetIdleAta = (0, spl_token_1.getAssociatedTokenAddressSync)(vaultAssetMint, addresses.vaultAssetIdleAuth, true, assetTokenProgram);
442
- return await this.vaultProgram.methods
443
- .initializeVault(vaultParams.config, vaultParams.name, vaultParams.description)
444
- .accounts({
445
- payer,
446
- admin,
447
- manager,
448
- vault,
449
- vaultAssetMint,
450
- vaultAssetIdleAta,
451
- assetTokenProgram,
452
- })
453
- .instruction();
454
- }
455
- /**
456
- * Creates an instruction to update a specific vault configuration field
457
- *
458
- * @param {VaultConfigField} field - The configuration field to update
459
- * @param {Buffer} data - The serialized data for the new value
460
- * @param {Object} params - Parameters for updating the vault config
461
- * @param {PublicKey} params.vault - Public key of the vault
462
- * @param {PublicKey} params.admin - Public key of the vault admin
463
- * @param {PublicKey} [params.vaultLpMint] - Required when updating management fees
464
- * @returns {Promise<TransactionInstruction>} Transaction instruction for updating the vault config
465
- *
466
- * @throws {Error} If the field requires LP mint but it's not provided
467
- *
468
- * @example Update max cap
469
- * ```typescript
470
- * const newMaxCap = new BN(20_000_000_000_000);
471
- * const data = newMaxCap.toArrayLike(Buffer, "le", 8);
472
- *
473
- * const ix = await client.createUpdateVaultConfigIx(
474
- * VaultConfigField.MaxCap,
475
- * data,
476
- * {
477
- * vault: vaultPubkey,
478
- * admin: adminPubkey
479
- * }
480
- * );
481
- * ```
482
- *
483
- * @example Update manager management fee (requires LP mint)
484
- * ```typescript
485
- * const newManagerManagementFee = 1000; // 10%
486
- * const data = Buffer.alloc(2);
487
- * data.writeUInt16LE(newManagerManagementFee, 0);
488
- *
489
- * const vaultLpMint = client.findVaultLpMint(vaultPubkey);
490
- *
491
- * const ix = await client.createUpdateVaultConfigIx(
492
- * VaultConfigField.ManagerManagementFee,
493
- * data,
494
- * {
495
- * vault: vaultPubkey,
496
- * admin: adminPubkey,
497
- * vaultLpMint: vaultLpMint
498
- * }
499
- * );
500
- * ```
501
- *
502
- * @example Update manager (requires Pubkey)
503
- * ```typescript
504
- * const newManager = new PublicKey('...');
505
- * const data = newManager.toBuffer();
506
- *
507
- * const ix = await client.createUpdateVaultConfigIx(
508
- * VaultConfigField.Manager,
509
- * data,
510
- * {
511
- * vault: vaultPubkey,
512
- * admin: adminPubkey
513
- * }
514
- * );
515
- * ```
516
- */
517
- async createUpdateVaultConfigIx(field, data, { vault, admin, vaultLpMint, }) {
518
- // Check if LP mint is required for this field
519
- const requiresLpMint = field === types_1.VaultConfigField.ManagerManagementFee ||
520
- field === types_1.VaultConfigField.AdminManagementFee;
521
- if (requiresLpMint && !vaultLpMint) {
522
- throw new Error(`LP mint is required when updating ${field}. Please provide vaultLpMint parameter.`);
523
- }
524
- // Build remaining accounts array
525
- const remainingAccounts = [];
526
- if (requiresLpMint && vaultLpMint) {
527
- remainingAccounts.push({
528
- pubkey: vaultLpMint,
529
- isSigner: false,
530
- isWritable: false,
531
- });
532
- }
533
- const fieldToVariant = {
534
- [types_1.VaultConfigField.MaxCap]: { maxCap: {} },
535
- [types_1.VaultConfigField.StartAtTs]: { startAtTs: {} },
536
- [types_1.VaultConfigField.LockedProfitDegradationDuration]: {
537
- lockedProfitDegradationDuration: {},
538
- },
539
- [types_1.VaultConfigField.WithdrawalWaitingPeriod]: {
540
- withdrawalWaitingPeriod: {},
541
- },
542
- [types_1.VaultConfigField.ManagerPerformanceFee]: { managerPerformanceFee: {} },
543
- [types_1.VaultConfigField.AdminPerformanceFee]: { adminPerformanceFee: {} },
544
- [types_1.VaultConfigField.ManagerManagementFee]: { managerManagementFee: {} },
545
- [types_1.VaultConfigField.AdminManagementFee]: { adminManagementFee: {} },
546
- [types_1.VaultConfigField.RedemptionFee]: { redemptionFee: {} },
547
- [types_1.VaultConfigField.IssuanceFee]: { issuanceFee: {} },
548
- [types_1.VaultConfigField.Manager]: { manager: {} },
549
- [types_1.VaultConfigField.PendingAdmin]: { pendingAdmin: {} },
550
- [types_1.VaultConfigField.DisabledOperations]: { disabledOperations: {} },
551
- };
552
- const fieldVariant = fieldToVariant[field];
553
- if (!fieldVariant) {
554
- throw new Error(`Unknown vault config field: ${field}`);
555
- }
556
- return await this.vaultProgram.methods
557
- .updateVaultConfig(fieldVariant, data)
558
- .accountsPartial({
559
- admin,
560
- vault,
561
- })
562
- .remainingAccounts(remainingAccounts)
563
- .instruction();
564
- }
565
- /**
566
- * Creates an instruction for the pending admin to accept the vault admin role
567
- *
568
- * @param {Object} params - Parameters for accepting vault admin
569
- * @param {PublicKey} params.pendingAdmin - Public key of the pending admin (must be signer)
570
- * @param {PublicKey} params.vault - Public key of the vault
571
- * @returns {Promise<TransactionInstruction>} Transaction instruction for accepting vault admin
572
- * @throws {Error} If instruction creation fails
573
- *
574
- * @example
575
- * ```typescript
576
- * const ix = await client.createAcceptVaultAdminIx({
577
- * pendingAdmin: pendingAdminPubkey,
578
- * vault: vaultPubkey,
579
- * });
580
- * ```
581
- */
582
- async createAcceptVaultAdminIx({ pendingAdmin, vault, }) {
583
- return await this.vaultProgram.methods
584
- .acceptVaultAdmin()
585
- .accountsStrict({
586
- pendingAdmin,
587
- vault,
588
- })
589
- .instruction();
590
- }
591
- /**
592
- * Creates a deposit instruction for a vault
593
- *
594
- * @param {BN} amount - Amount of tokens to deposit
595
- * @param {Object} params - Deposit parameters
596
- * @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
597
- * @param {PublicKey} params.vault - Public key of the vault
598
- * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
599
- * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
600
- * @returns {Promise<TransactionInstruction>} Transaction instruction for depositing tokens
601
- * @throws {Error} If instruction creation fails
602
- *
603
- * @example
604
- * ```typescript
605
- * const ix = await client.createDepositVaultIx(
606
- * new BN('1000000000'),
607
- * {
608
- * userTransferAuthority: userPubkey,
609
- * vault: vaultPubkey,
610
- * vaultAssetMint: mintPubkey,
611
- * assetTokenProgram: tokenProgramPubkey
612
- * }
613
- * );
614
- * ```
615
- */
616
- async createDepositVaultIx(amount, { userTransferAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
617
- return await this.vaultProgram.methods
618
- .depositVault(amount)
619
- .accounts({
620
- userTransferAuthority,
621
- vault,
622
- vaultAssetMint,
623
- assetTokenProgram,
624
- })
625
- .instruction();
626
- }
627
- /**
628
- * Creates a request withdraw instruction for a vault
629
- *
630
- * @param {RequestWithdrawVaultArgs} requestWithdrawArgs - Arguments for withdrawing from the vault
631
- * @param {BN} requestWithdrawArgs.amount - Amount of LP tokens to withdraw
632
- * @param {boolean} requestWithdrawArgs.isAmountInLp - Whether the amount is in LP tokens
633
- * @param {boolean} requestWithdrawArgs.isWithdrawAll - Whether to withdraw all assets
634
- * @param {Object} params - Request withdraw parameters
635
- * @param {PublicKey} params.payer - Public key of the payer
636
- * @param {PublicKey} params.userTransferAuthority - Public key of the user authority
637
- * @param {PublicKey} params.vault - Public key of the vault
638
- * @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
639
- *
640
- * @throws {Error} If the instruction creation fails
641
- *
642
- * @example
643
- * const ix = await client.createRequestWithdrawVaultIx(
644
- * {
645
- * amount: new BN('1000000000'),
646
- * isAmountInLp: true,
647
- * isWithdrawAll: false,
648
- * },
649
- * {
650
- * payer: payerPubkey,
651
- * userTransferAuthority: userPubkey,
652
- * vault: vaultPubkey,
653
- * }
654
- * );
655
- */
656
- async createRequestWithdrawVaultIx({ amount, isAmountInLp, isWithdrawAll }, { payer, userTransferAuthority, vault, }) {
657
- return await this.vaultProgram.methods
658
- .requestWithdrawVault(amount, isAmountInLp, isWithdrawAll)
659
- .accounts({
660
- payer,
661
- userTransferAuthority,
662
- vault,
663
- })
664
- .instruction();
665
- }
666
- /**
667
- * Creates a cancel withdraw instruction for a vault
668
- *
669
- * @param {Object} params - Cancel withdraw request parameters
670
- * @param {PublicKey} params.userTransferAuthority - Public key of the user authority
671
- * @param {PublicKey} params.vault - Public key of the vault
672
- * @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
673
- *
674
- * @throws {Error} If the instruction creation fails
675
- *
676
- * @example
677
- * const ix = await client.createCancelRequestWithdrawVaultIx(
678
- * {
679
- * userTransferAuthority: userPubkey,
680
- * vault: vaultPubkey,
681
- * }
682
- * );
683
- */
684
- async createCancelRequestWithdrawVaultIx({ userTransferAuthority, vault, }) {
685
- return await this.vaultProgram.methods
686
- .cancelRequestWithdrawVault()
687
- .accounts({
688
- userTransferAuthority,
689
- vault,
690
- })
691
- .instruction();
692
- }
693
- /**
694
- * Creates a withdraw instruction for a vault
695
- *
696
- * @param {Object} params - Withdraw parameters
697
- * @param {PublicKey} params.userTransferAuthority - Public key of the user authority
698
- * @param {PublicKey} params.vault - Public key of the vault
699
- * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
700
- * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
701
- * @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
702
- *
703
- * @throws {Error} If the instruction creation fails
704
- *
705
- * @example
706
- * const ix = await client.createWithdrawVaultIx(
707
- * {
708
- * userTransferAuthority: userPubkey,
709
- * vault: vaultPubkey,
710
- * vaultAssetMint: mintPubkey,
711
- * assetTokenProgram: tokenProgramPubkey
712
- * }
713
- * );
714
- */
715
- async createWithdrawVaultIx({ userTransferAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
716
- return await this.vaultProgram.methods
717
- .withdrawVault()
718
- .accounts({
719
- userTransferAuthority,
720
- vault,
721
- vaultAssetMint,
722
- assetTokenProgram,
723
- })
724
- .instruction();
725
- }
726
- /**
727
- * Creates an instant withdraw instruction for a vault (no waiting period required)
728
- *
729
- * @param {InstantWithdrawVaultArgs} args - Instant withdrawal arguments
730
- * @param {BN} args.amount - Amount to withdraw (in LP tokens or asset, depending on isAmountInLp)
731
- * @param {boolean} args.isAmountInLp - Whether the amount is denominated in LP tokens
732
- * @param {boolean} args.isWithdrawAll - Whether to withdraw all user's LP tokens
733
- * @param {Object} params - Instant withdraw parameters
734
- * @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
735
- * @param {PublicKey} params.vault - Public key of the vault
736
- * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
737
- * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
738
- * @returns {Promise<TransactionInstruction>} Transaction instruction for instant withdrawal
739
- *
740
- * @throws {Error} If the vault's withdrawal waiting period is not zero
741
- *
742
- * @example
743
- * ```typescript
744
- * const ix = await client.createInstantWithdrawVaultIx(
745
- * {
746
- * amount: new BN('1000000000'),
747
- * isAmountInLp: true,
748
- * isWithdrawAll: false,
749
- * },
750
- * {
751
- * userTransferAuthority: userPubkey,
752
- * vault: vaultPubkey,
753
- * vaultAssetMint: mintPubkey,
754
- * assetTokenProgram: tokenProgramPubkey,
755
- * }
756
- * );
757
- * ```
758
- */
759
- async createInstantWithdrawVaultIx({ amount, isAmountInLp, isWithdrawAll }, { userTransferAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
760
- return await this.vaultProgram.methods
761
- .instantWithdrawVault(amount, isAmountInLp, isWithdrawAll)
762
- .accounts({
763
- userTransferAuthority,
764
- vault,
765
- vaultAssetMint,
766
- assetTokenProgram,
767
- })
768
- .instruction();
769
- }
770
- // --------------------------------------- Strategy Instructions
771
- /**
772
- * Creates an instruction to add an adaptor to a vault
773
- * @param {Object} params - Parameters for adding adaptor to vault
774
- * @param {PublicKey} params.vault - Public key of the vault
775
- * @param {PublicKey} params.payer - Public key of the payer
776
- * @param {PublicKey} params.admin - Public key of the admin
777
- * @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
778
- * @returns {Promise<TransactionInstruction>} Transaction instruction for adding adaptor to vault
779
- *
780
- * @throws {Error} If the instruction creation fails
781
- *
782
- * @example
783
- * ```typescript
784
- * const ix = await client.createAddAdaptorIx({
785
- * vault: vaultPubkey,
786
- * payer: payerPubkey,
787
- * admin: adminPubkey,
788
- * adaptorProgram: adaptorProgramPubkey
789
- * });
790
- * ```
791
- */
792
- async createAddAdaptorIx({ vault, payer, admin, adaptorProgram, }) {
793
- return await this.vaultProgram.methods
794
- .addAdaptor()
795
- .accountsPartial({
796
- payer,
797
- admin,
798
- vault,
799
- adaptorProgram,
800
- })
801
- .instruction();
802
- }
803
- /**
804
- * Creates an instruction to initialize a strategy to a vault
805
- * @param {InitializeStrategyArgs} initArgs - Arguments for strategy initialization
806
- * @param {Buffer | null} [initArgs.instructionDiscriminator] - Optional discriminator for the instruction
807
- * @param {Buffer | null} [initArgs.additionalArgs] - Optional additional arguments for the instruction
808
- * @param {Object} params - Parameters for initializing strategy to vault
809
- * @param {PublicKey} params.payer - Public key of the payer
810
- * @param {PublicKey} params.vault - Public key of the vault
811
- * @param {PublicKey} params.manager - Public key of the manager
812
- * @param {PublicKey} params.strategy - Public key of the strategy
813
- * @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
814
- * @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
815
- * @returns {Promise<TransactionInstruction>} Transaction instruction for initializing strategy to vault
816
- * @throws {Error} If the instruction creation fails
817
- *
818
- * @example
819
- * ```typescript
820
- * const ix = await client.createInitializeStrategyIx(
821
- * {
822
- * instructionDiscriminator: Buffer.from('...'), // optional
823
- * additionalArgs: Buffer.from('...') // optional
824
- * },
825
- * {
826
- * payer: payerPubkey,
827
- * vault: vaultPubkey,
828
- * manager: managerPubkey,
829
- * strategy: strategyPubkey,
830
- * adaptorProgram: adaptorProgramPubkey,
831
- * remainingAccounts: []
832
- * }
833
- * );
834
- * ```
835
- */
836
- async createInitializeStrategyIx({ instructionDiscriminator = null, additionalArgs = null, }, { payer, vault, manager, strategy, adaptorProgram, remainingAccounts, }) {
837
- return await this.vaultProgram.methods
838
- .initializeStrategy(instructionDiscriminator ?? null, additionalArgs ?? null)
839
- .accounts({
840
- payer,
841
- vault,
842
- manager,
843
- strategy,
844
- adaptorProgram,
845
- })
846
- .remainingAccounts(remainingAccounts)
847
- .instruction();
848
- }
849
- /**
850
- * Creates an instruction to deposit assets into a strategy
851
- *
852
- * @param {DepositStrategyArgs} depositArgs - Deposit arguments
853
- * @param {BN} depositArgs.depositAmount - Amount of assets to deposit
854
- * @param {Buffer | null} [depositArgs.instructionDiscriminator] - Optional discriminator for the instruction
855
- * @param {Buffer | null} [depositArgs.additionalArgs] - Optional additional arguments for the instruction
856
- * @param {Object} params - Strategy deposit parameters
857
- * @param {PublicKey} params.manager - Public key of the manager
858
- * @param {PublicKey} params.vault - Public key of the vault
859
- * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
860
- * @param {PublicKey} params.strategy - Public key of the strategy
861
- * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
862
- * @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
863
- * @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
864
- * @returns {Promise<TransactionInstruction>} Transaction instruction for depositing assets into strategy
865
- * @throws {Error} If the instruction creation fails
866
- *
867
- * @example
868
- * ```typescript
869
- * const ix = await client.createDepositStrategyIx(
870
- * {
871
- * depositAmount: new BN('1000000000'),
872
- * instructionDiscriminator: Buffer.from('...'),
873
- * additionalArgs: Buffer.from('...')
874
- * },
875
- * {
876
- * manager: managerPubkey,
877
- * vault: vaultPubkey,
878
- * vaultAssetMint: mintPubkey,
879
- * strategy: strategyPubkey,
880
- * assetTokenProgram: tokenProgramPubkey,
881
- * adaptorProgram: adaptorProgramPubkey,
882
- * remainingAccounts: []
883
- * }
884
- * );
885
- * ```
886
- */
887
- async createDepositStrategyIx({ depositAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
888
- return await this.vaultProgram.methods
889
- .depositStrategy(depositAmount, instructionDiscriminator, additionalArgs)
890
- .accounts({
891
- manager,
892
- vault,
893
- vaultAssetMint,
894
- adaptorProgram,
895
- strategy,
896
- assetTokenProgram,
897
- })
898
- .remainingAccounts(remainingAccounts)
899
- .instruction();
900
- }
901
- /**
902
- * Creates an instruction to withdraw assets from a strategy
903
- *
904
- * @param {WithdrawStrategyArgs} withdrawArgs - Withdrawal arguments
905
- * @param {BN} withdrawArgs.withdrawAmount - Amount of assets to withdraw
906
- * @param {Buffer | null} [withdrawArgs.instructionDiscriminator] - Optional discriminator for the instruction
907
- * @param {Buffer | null} [withdrawArgs.additionalArgs] - Optional additional arguments for the instruction
908
- * @param {Object} params - Strategy withdrawal parameters
909
- * @param {PublicKey} params.vault - Public key of the vault
910
- * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
911
- * @param {PublicKey} params.strategy - Public key of the strategy
912
- * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
913
- * @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
914
- * @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
915
- * @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawing assets from strategy
916
- * @throws {Error} If the instruction creation fails
917
- *
918
- * @example
919
- * ```typescript
920
- * const ix = await client.createWithdrawStrategyIx(
921
- * {
922
- * withdrawAmount: new BN('1000000000'),
923
- * instructionDiscriminator: Buffer.from('...'),
924
- * additionalArgs: Buffer.from('...')
925
- * },
926
- * {
927
- * vault: vaultPubkey,
928
- * vaultAssetMint: mintPubkey,
929
- * strategy: strategyPubkey,
930
- * assetTokenProgram: tokenProgramPubkey,
931
- * adaptorProgram: adaptorProgramPubkey,
932
- * remainingAccounts: []
933
- * }
934
- * );
935
- * ```
936
- */
937
- async createWithdrawStrategyIx({ withdrawAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
938
- return await this.vaultProgram.methods
939
- .withdrawStrategy(withdrawAmount, instructionDiscriminator, additionalArgs)
940
- .accounts({
941
- manager,
942
- vault,
943
- vaultAssetMint,
944
- adaptorProgram,
945
- strategy,
946
- assetTokenProgram,
947
- })
948
- .remainingAccounts(remainingAccounts)
949
- .instruction();
950
- }
951
- /**
952
- * Creates an instruction to remove a strategy from a vault
953
- * @param {Object} params - Parameters for removing strategy
954
- * @param {PublicKey} params.vault - Public key of the vault
955
- * @param {PublicKey} params.admin - Public key of the admin
956
- * @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
957
- * @returns {Promise<TransactionInstruction>} Transaction instruction for removing adaptor from vault
958
- * @throws {Error} If instruction creation fails
959
- *
960
- * @example
961
- * ```typescript
962
- * const ix = await client.createRemoveAdaptorIx({
963
- * vault: vaultPubkey,
964
- * admin: adminPubkey,
965
- * adaptorProgram: adaptorProgramPubkey
966
- * });
967
- * ```
968
- */
969
- async createRemoveAdaptorIx({ vault, admin, adaptorProgram, }) {
970
- return await this.vaultProgram.methods
971
- .removeAdaptor()
972
- .accountsPartial({
973
- vault,
974
- admin,
975
- adaptorProgram,
976
- })
977
- .instruction();
978
- }
979
- /**
980
- * Creates an instruction to initialize a direct withdraw strategy
981
- * @param {InitializeDirectWithdrawStrategyArgs} initArgs - Arguments for initializing direct withdraw strategy
982
- * @param {Buffer | null} initArgs.instructionDiscriminator - Optional discriminator for the instruction
983
- * @param {Buffer | null} initArgs.additionalArgs - Optional additional arguments for the instruction
984
- * @param {boolean} initArgs.allowUserArgs - Whether to allow user arguments
985
- * @param {Object} params - Parameters for initializing direct withdraw strategy
986
- * @param {PublicKey} params.payer - Public key of the payer
987
- * @param {PublicKey} params.admin - Public key of the admin
988
- * @param {PublicKey} params.vault - Public key of the vault
989
- * @param {PublicKey} params.strategy - Public key of the strategy
990
- * @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
991
- * @returns {Promise<TransactionInstruction>} Transaction instruction for initializing direct withdraw strategy
992
- * @throws {Error} If instruction creation fails
993
- *
994
- * @example
995
- * ```typescript
996
- * const ix = await client.createInitializeDirectWithdrawStrategyIx(
997
- * {
998
- * instructionDiscriminator: Buffer.from('...'),
999
- * additionalArgs: Buffer.from('...'),
1000
- * allowUserArgs: true
1001
- * },
1002
- * {
1003
- * payer: payerPubkey,
1004
- * admin: adminPubkey,
1005
- * vault: vaultPubkey,
1006
- * strategy: strategyPubkey,
1007
- * adaptorProgram: adaptorProgramPubkey
1008
- * }
1009
- * );
1010
- * ```
1011
- */
1012
- async createInitializeDirectWithdrawStrategyIx({ instructionDiscriminator = null, additionalArgs = null, allowUserArgs = false, }, { payer, admin, vault, strategy, adaptorProgram, }) {
1013
- return await this.vaultProgram.methods
1014
- .initializeDirectWithdrawStrategy(instructionDiscriminator, additionalArgs, allowUserArgs)
1015
- .accountsPartial({
1016
- payer,
1017
- admin,
1018
- vault,
1019
- strategy,
1020
- adaptorProgram,
1021
- })
1022
- .instruction();
1023
- }
1024
- /**
1025
- * Creates an instruction to withdraw assets from a direct withdraw strategy
1026
- * @param {Object} directWithdrawArgs - Withdrawal arguments
1027
- * @param {Buffer | null} [directWithdrawArgs.userArgs] - Optional user arguments for the instruction
1028
- * @param {Object} params - Parameters for withdrawing assets from direct withdraw strategy
1029
- * @param {PublicKey} params.user - Public key of the user
1030
- * @param {PublicKey} params.vault - Public key of the vault
1031
- * @param {PublicKey} params.strategy - Public key of the strategy
1032
- * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
1033
- * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
1034
- * @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
1035
- * @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
1036
- * @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawing assets from direct withdraw strategy
1037
- * @throws {Error} If instruction creation fails
1038
- *
1039
- * @example
1040
- * ```typescript
1041
- * const ix = await client.createDirectWithdrawStrategyIx(
1042
- * {
1043
- * userArgs: Buffer.from('...')
1044
- * },
1045
- * {
1046
- * user: userPubkey,
1047
- * vault: vaultPubkey,
1048
- * strategy: strategyPubkey,
1049
- * vaultAssetMint: mintPubkey,
1050
- * assetTokenProgram: tokenProgramPubkey,
1051
- * adaptorProgram: adaptorProgramPubkey,
1052
- * remainingAccounts: []
1053
- * }
1054
- * );
1055
- * ```
1056
- */
1057
- async createDirectWithdrawStrategyIx({ userArgs = null }, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
1058
- return await this.vaultProgram.methods
1059
- .directWithdrawStrategy(userArgs)
1060
- .accounts({
1061
- userTransferAuthority: user,
1062
- strategy,
1063
- adaptorProgram,
1064
- vault,
1065
- vaultAssetMint,
1066
- assetTokenProgram,
1067
- })
1068
- .remainingAccounts(remainingAccounts)
1069
- .instruction();
1070
- }
1071
- /**
1072
- * Creates an instruction to withdraw assets from a direct withdraw strategy with slippage tolerance
1073
- *
1074
- * @param {Object} directWithdrawArgs - Withdrawal arguments
1075
- * @param {Buffer | null} [directWithdrawArgs.userArgs] - Optional user arguments for the instruction
1076
- * @param {BN} directWithdrawArgs.tolerance - Slippage tolerance in asset amount (max difference between requested and actual)
1077
- * @param {Object} params - Parameters for withdrawing assets from direct withdraw strategy
1078
- * @param {PublicKey} params.user - Public key of the user
1079
- * @param {PublicKey} params.vault - Public key of the vault
1080
- * @param {PublicKey} params.strategy - Public key of the strategy
1081
- * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
1082
- * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
1083
- * @param {PublicKey} [params.adaptorProgram] - Public key of the adaptor program (defaults to lending adaptor)
1084
- * @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
1085
- * @returns {Promise<TransactionInstruction>} Transaction instruction for direct withdraw with tolerance
1086
- * @throws {Error} If instruction creation fails
1087
- *
1088
- * @example
1089
- * ```typescript
1090
- * const ix = await client.createDirectWithdrawStrategyWithToleranceIx(
1091
- * {
1092
- * userArgs: Buffer.from('...'),
1093
- * tolerance: new BN(1000),
1094
- * },
1095
- * {
1096
- * user: userPubkey,
1097
- * vault: vaultPubkey,
1098
- * strategy: strategyPubkey,
1099
- * vaultAssetMint: mintPubkey,
1100
- * assetTokenProgram: tokenProgramPubkey,
1101
- * remainingAccounts: [],
1102
- * }
1103
- * );
1104
- * ```
1105
- */
1106
- async createDirectWithdrawStrategyWithToleranceIx({ userArgs = null, tolerance }, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
1107
- return await this.vaultProgram.methods
1108
- .directWithdrawStrategyWithTolerance(userArgs, tolerance)
1109
- .accounts({
1110
- userTransferAuthority: user,
1111
- strategy,
1112
- adaptorProgram,
1113
- vault,
1114
- vaultAssetMint,
1115
- assetTokenProgram,
1116
- })
1117
- .remainingAccounts(remainingAccounts)
1118
- .instruction();
1119
- }
1120
- /**
1121
- * Creates an instant withdraw instruction for a strategy (no waiting period, withdraws directly from strategy)
1122
- *
1123
- * @param {InstantWithdrawStrategyArgs} args - Instant withdrawal arguments
1124
- * @param {BN} args.amount - Amount to withdraw (in LP tokens or asset, depending on isAmountInLp)
1125
- * @param {boolean} args.isAmountInLp - Whether the amount is denominated in LP tokens
1126
- * @param {boolean} args.isWithdrawAll - Whether to withdraw all user's LP tokens
1127
- * @param {Buffer | null} [args.userArgs] - Optional user arguments passed to the adaptor
1128
- * @param {Object} params - Instant withdraw strategy parameters
1129
- * @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
1130
- * @param {PublicKey} params.vault - Public key of the vault
1131
- * @param {PublicKey} params.strategy - Public key of the strategy
1132
- * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
1133
- * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
1134
- * @param {PublicKey} [params.adaptorProgram] - Public key of the adaptor program (defaults to lending adaptor)
1135
- * @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
1136
- * @returns {Promise<TransactionInstruction>} Transaction instruction for instant strategy withdrawal
1137
- * @throws {Error} If the vault's withdrawal waiting period is not zero
1138
- *
1139
- * @example
1140
- * ```typescript
1141
- * const ix = await client.createInstantWithdrawStrategyIx(
1142
- * {
1143
- * amount: new BN('1000000000'),
1144
- * isAmountInLp: true,
1145
- * isWithdrawAll: false,
1146
- * },
1147
- * {
1148
- * userTransferAuthority: userPubkey,
1149
- * vault: vaultPubkey,
1150
- * strategy: strategyPubkey,
1151
- * vaultAssetMint: mintPubkey,
1152
- * assetTokenProgram: tokenProgramPubkey,
1153
- * remainingAccounts: [],
1154
- * }
1155
- * );
1156
- * ```
1157
- */
1158
- async createInstantWithdrawStrategyIx({ amount, isAmountInLp, isWithdrawAll, userArgs = null, }, { userTransferAuthority, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
1159
- return await this.vaultProgram.methods
1160
- .instantWithdrawStrategy(amount, isAmountInLp, isWithdrawAll, userArgs ?? null)
1161
- .accounts({
1162
- userTransferAuthority,
1163
- vault,
1164
- strategy,
1165
- vaultAssetMint,
1166
- assetTokenProgram,
1167
- adaptorProgram,
1168
- })
1169
- .remainingAccounts(remainingAccounts)
1170
- .instruction();
1171
- }
1172
- /**
1173
- * Creates an instant withdraw instruction for a strategy with slippage tolerance
1174
- *
1175
- * @param {InstantWithdrawStrategyArgs & { tolerance: BN }} args - Instant withdrawal arguments with tolerance
1176
- * @param {BN} args.amount - Amount to withdraw (in LP tokens or asset, depending on isAmountInLp)
1177
- * @param {boolean} args.isAmountInLp - Whether the amount is denominated in LP tokens
1178
- * @param {boolean} args.isWithdrawAll - Whether to withdraw all user's LP tokens
1179
- * @param {Buffer | null} [args.userArgs] - Optional user arguments passed to the adaptor
1180
- * @param {BN} args.tolerance - Slippage tolerance in asset amount (max difference between requested and actual)
1181
- * @param {Object} params - Instant withdraw strategy parameters
1182
- * @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
1183
- * @param {PublicKey} params.vault - Public key of the vault
1184
- * @param {PublicKey} params.strategy - Public key of the strategy
1185
- * @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
1186
- * @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
1187
- * @param {PublicKey} [params.adaptorProgram] - Public key of the adaptor program (defaults to lending adaptor)
1188
- * @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
1189
- * @returns {Promise<TransactionInstruction>} Transaction instruction for instant strategy withdrawal with tolerance
1190
- * @throws {Error} If the vault's withdrawal waiting period is not zero
1191
- *
1192
- * @example
1193
- * ```typescript
1194
- * const ix = await client.createInstantWithdrawStrategyWithToleranceIx(
1195
- * {
1196
- * amount: new BN('1000000000'),
1197
- * isAmountInLp: true,
1198
- * isWithdrawAll: false,
1199
- * tolerance: new BN(1000),
1200
- * },
1201
- * {
1202
- * userTransferAuthority: userPubkey,
1203
- * vault: vaultPubkey,
1204
- * strategy: strategyPubkey,
1205
- * vaultAssetMint: mintPubkey,
1206
- * assetTokenProgram: tokenProgramPubkey,
1207
- * remainingAccounts: [],
1208
- * }
1209
- * );
1210
- * ```
1211
- */
1212
- async createInstantWithdrawStrategyWithToleranceIx({ amount, isAmountInLp, isWithdrawAll, userArgs = null, tolerance, }, { userTransferAuthority, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
1213
- return await this.vaultProgram.methods
1214
- .instantWithdrawStrategyWithTolerance(amount, isAmountInLp, isWithdrawAll, userArgs ?? null, tolerance)
1215
- .accounts({
1216
- userTransferAuthority,
1217
- vault,
1218
- strategy,
1219
- vaultAssetMint,
1220
- assetTokenProgram,
1221
- adaptorProgram,
1222
- })
1223
- .remainingAccounts(remainingAccounts)
1224
- .instruction();
1225
- }
1226
- /**
1227
- * Creates an instruction to harvest fees from a vault
1228
- * @param {Object} params - Parameters for harvesting fees
1229
- * @param {PublicKey} params.harvester - Public key of the harvester
1230
- * @param {PublicKey} params.vaultManager - Public key of the vault manager
1231
- * @param {PublicKey} params.vaultAdmin - Public key of the vault admin
1232
- * @param {PublicKey} params.protocolAdmin - Public key of the protocol admin
1233
- * @param {PublicKey} params.vault - Public key of the vault
1234
- * @returns {Promise<TransactionInstruction>} Transaction instruction for harvesting fees
1235
- * @throws {Error} If instruction creation fails
1236
- *
1237
- * @example
1238
- * ```typescript
1239
- * const ix = await client.createHarvestFeeIx({
1240
- * harvester: harvesterPubkey,
1241
- * vaultManager: vaultManagerPubkey,
1242
- * vaultAdmin: vaultAdminPubkey,
1243
- * protocolAdmin: protocolAdminPubkey,
1244
- * vault: vaultPubkey,
1245
- * });
1246
- * ```
1247
- */
1248
- async createHarvestFeeIx({ harvester, vaultManager, vaultAdmin, protocolAdmin, vault, }) {
1249
- return await this.vaultProgram.methods
1250
- .harvestFee()
1251
- .accounts({
1252
- harvester,
1253
- vaultManager,
1254
- vaultAdmin,
1255
- vault,
1256
- protocolAdmin,
1257
- })
1258
- .instruction();
1259
- }
1260
- /**
1261
- * Creates an instruction to close a strategy
1262
- * @param {Object} params - Parameters for closing strategy
1263
- * @param {PublicKey} params.payer - Public key of the payer
1264
- * @param {PublicKey} params.manager - Public key of the manager
1265
- * @param {PublicKey} params.vault - Public key of the vault
1266
- * @param {PublicKey} params.strategy - Public key of the strategy
1267
- * @returns {Promise<TransactionInstruction>} Transaction instruction for closing strategy
1268
- * @throws {Error} If instruction creation fails
1269
- *
1270
- * @example
1271
- * ```typescript
1272
- * const ix = await client.createCloseStrategyIx({
1273
- * payer: payerPubkey,
1274
- * manager: managerPubkey,
1275
- * vault: vaultPubkey,
1276
- * strategy: strategyPubkey,
1277
- * });
1278
- * ```
1279
- */
1280
- async createCloseStrategyIx({ payer, manager, vault, strategy, }) {
1281
- return await this.vaultProgram.methods
1282
- .closeStrategy()
1283
- .accounts({
1284
- payer,
1285
- manager,
1286
- vault,
1287
- strategy,
1288
- })
1289
- .instruction();
1290
- }
1291
- /**
1292
- * Creates an instruction to calibrate the high water mark
1293
- * @param {Object} params - Parameters for calibrating the high water mark
1294
- * @param {PublicKey} params.vault - Public key of the vault
1295
- * @param {PublicKey} params.admin - Public key of the admin
1296
- * @returns {Promise<TransactionInstruction>} Transaction instruction for calibrating the high water mark
1297
- * @throws {Error} If instruction creation fails
1298
- *
1299
- * @example
1300
- * ```typescript
1301
- * const ix = await client.createCalibrateHighWaterMarkIx({
1302
- * vault: vaultPubkey,
1303
- * admin: adminPubkey,
1304
- * });
1305
- * ```
1306
- */
1307
- async createCalibrateHighWaterMarkIx({ vault, admin, }) {
1308
- return await this.vaultProgram.methods
1309
- .calibrateHighWaterMark()
1310
- .accountsPartial({
1311
- vault,
1312
- admin,
1313
- })
1314
- .instruction();
1315
- }
1316
- /**
1317
- * Creates an instruction to calibrate the high water mark without fee clawback (unsafe)
1318
- * @param {Object} params - Parameters for calibrating the high water mark
1319
- * @param {PublicKey} params.vault - Public key of the vault (must be whitelisted)
1320
- * @param {PublicKey} params.admin - Public key of the admin
1321
- * @returns {Promise<TransactionInstruction>} Transaction instruction for unsafe calibration
1322
- * @throws {Error} If instruction creation fails or vault is not whitelisted
1323
- *
1324
- * @example
1325
- * ```typescript
1326
- * const ix = await client.createCalibrateHighWaterMarkUnsafeIx({
1327
- * vault: vaultPubkey,
1328
- * admin: adminPubkey,
1329
- * });
1330
- * ```
1331
- */
1332
- async createCalibrateHighWaterMarkUnsafeIx({ vault, admin, }) {
1333
- return await this.vaultProgram.methods
1334
- .calibrateHighWaterMarkUnsafe()
1335
- .accountsPartial({
1336
- vault,
1337
- admin,
1338
- })
1339
- .instruction();
1340
- }
1341
- /**
1342
- * Creates an instruction to create LP metadata
1343
- * @param {Object} createLpMetadataArgs - Parameters for creating LP metadata
1344
- * @param {string} createLpMetadataArgs.name - Name of the LP
1345
- * @param {string} createLpMetadataArgs.symbol - Symbol of the LP
1346
- * @param {string} createLpMetadataArgs.uri - URI of the LP metadata
1347
- * @param {Object} params - Parameters for creating LP metadata
1348
- * @param {PublicKey} params.payer - Public key of the payer
1349
- * @param {PublicKey} params.admin - Public key of the admin
1350
- * @param {PublicKey} params.vault - Public key of the vault
1351
- * @returns {Promise<TransactionInstruction>} Transaction instruction for creating LP metadata
1352
- * @throws {Error} If instruction creation fails
1353
- *
1354
- * @example
1355
- * ```typescript
1356
- * const ix = await client.createCreateLpMetadataIx({
1357
- * name: "My LP",
1358
- * symbol: "MYLP",
1359
- * uri: "https://mylp.com/metadata",
1360
- * });
1361
- * ```
1362
- */
1363
- async createCreateLpMetadataIx({ name, symbol, uri, }, { payer, admin, vault, }) {
1364
- const metadataAccount = this.findLpMetadataAccount(vault);
1365
- return await this.vaultProgram.methods
1366
- .createLpMetadata(name, symbol, uri)
1367
- .accountsPartial({
1368
- payer,
1369
- vault,
1370
- admin,
1371
- metadataAccount,
1372
- })
1373
- .instruction();
1374
- }
1375
- /**
1376
- * Creates an instruction to update per-vault protocol fees (admin-only, protocol level)
1377
- *
1378
- * @param {ProtocolFeeField} field - The protocol fee field to update
1379
- * @param {number} feeBps - The new fee value in basis points
1380
- * @param {Object} params - Parameters for updating the protocol fee
1381
- * @param {PublicKey} params.admin - Public key of the protocol admin
1382
- * @param {PublicKey} params.vault - Public key of the vault
1383
- * @returns {Promise<TransactionInstruction>} Transaction instruction for updating the protocol fee
1384
- *
1385
- * @throws {Error} If the total fee (protocol + admin + manager) exceeds 10000 BPS
1386
- *
1387
- * @example
1388
- * ```typescript
1389
- * const ix = await client.createUpdateVaultProtocolFeeIx(
1390
- * ProtocolFeeField.ProtocolPerformanceFee,
1391
- * 500, // 5%
1392
- * {
1393
- * admin: protocolAdminPubkey,
1394
- * vault: vaultPubkey,
1395
- * }
1396
- * );
1397
- * ```
1398
- */
1399
- async createUpdateVaultProtocolFeeIx(field, feeBps, { admin, vault, }) {
1400
- const fieldToVariant = {
1401
- [types_1.ProtocolFeeField.ProtocolPerformanceFee]: {
1402
- protocolPerformanceFee: {},
1403
- },
1404
- [types_1.ProtocolFeeField.ProtocolManagementFee]: {
1405
- protocolManagementFee: {},
1406
- },
1407
- };
1408
- const fieldVariant = fieldToVariant[field];
1409
- if (!fieldVariant) {
1410
- throw new Error(`Unknown protocol fee field: ${field}`);
1411
- }
1412
- return await this.vaultProgram.methods
1413
- .updateVaultProtocolFee(fieldVariant, feeBps)
1414
- .accountsPartial({
1415
- admin,
1416
- vault,
1417
- })
1418
- .instruction();
1419
- }
1420
- // --------------------------------------- Account Fetching All
1421
- /**
1422
- * Fetches all strategy init receipt accounts
1423
- * @returns Promise resolving to an array of strategy init receipt accounts
1424
- *
1425
- * @example
1426
- * ```typescript
1427
- * const strategyInitReceiptAccounts = await client.fetchAllStrategyInitReceiptAccounts();
1428
- * ```
1429
- */
1430
- async fetchAllStrategyInitReceiptAccounts() {
1431
- return await this.vaultProgram.account.strategyInitReceipt.all();
1432
- }
1433
- /**
1434
- * Fetches all strategy init receipt accounts of a vault
1435
- * @param vault - Public key of the vault
1436
- * @returns Promise resolving to an array of strategy init receipt accounts
1437
- *
1438
- * @example
1439
- * ```typescript
1440
- * const strategyInitReceiptAccounts = await client.fetchAllStrategyInitReceiptAccountsOfVault(vaultPubkey);
1441
- * ```
1442
- */
1443
- async fetchAllStrategyInitReceiptAccountsOfVault(vault) {
1444
- return await this.vaultProgram.account.strategyInitReceipt.all([
1445
- {
1446
- memcmp: {
1447
- offset: 8, // 8 for discriminator
1448
- bytes: vault.toBase58(),
1449
- },
1450
- },
1451
- ]);
1452
- }
1453
- /**
1454
- * Fetches all request withdraw vault receipt accounts of a vault
1455
- * @param vault - Public key of the vault
1456
- * @returns Promise resolving to an array of request withdraw vault receipt accounts
1457
- *
1458
- * @example
1459
- * ```typescript
1460
- * const requestWithdrawVaultReceiptAccounts = await client.fetchAllRequestWithdrawVaultReceiptsOfVault(vaultPubkey);
1461
- * ```
1462
- */
1463
- async fetchAllRequestWithdrawVaultReceiptsOfVault(vault) {
1464
- return await this.vaultProgram.account.requestWithdrawVaultReceipt.all([
1465
- {
1466
- memcmp: {
1467
- offset: 8, // 8 for discriminator
1468
- bytes: vault.toBase58(),
1469
- },
1470
- },
1471
- ]);
1472
- }
1473
- /**
1474
- * Fetches all adaptor add receipt accounts of a vault
1475
- * @param vault - Public key of the vault
1476
- * @returns Promise resolving to an array of adaptor add receipt accounts
1477
- *
1478
- * @example
1479
- * ```typescript
1480
- * const adaptorAddReceiptAccounts = await client.fetchAllAdaptorAddReceiptAccountsOfVault(vaultPubkey);
1481
- * ```
1482
- */
1483
- async fetchAllAdaptorAddReceiptAccountsOfVault(vault) {
1484
- return await this.vaultProgram.account.adaptorAddReceipt.all([
1485
- {
1486
- memcmp: {
1487
- offset: 8, // 8 for discriminator
1488
- bytes: vault.toBase58(),
1489
- },
1490
- },
1491
- ]);
1492
- }
1493
- // --------------------------------------- Account Fetching
1494
- /**
1495
- * Fetches a vault account's data
1496
- * @param vault - Public key of the vault
1497
- * @returns Promise resolving to the vault account data
1498
- */
1499
- /**
1500
- * Fetches the protocol account's data
1501
- * @returns Promise resolving to the protocol account data
1502
- *
1503
- * @example
1504
- * ```typescript
1505
- * const protocolAccount = await client.fetchProtocolAccount();
1506
- * ```
1507
- */
1508
- async fetchProtocolAccount() {
1509
- const protocol = this.findProtocol();
1510
- return await this.vaultProgram.account.protocol.fetch(protocol, this.provider.opts.commitment);
1511
- }
1512
- async fetchVaultAccount(vault) {
1513
- return await this.vaultProgram.account.vault.fetch(vault, this.provider.opts.commitment);
1514
- }
1515
- /**
1516
- * Fetches a strategy init receipt account's data
1517
- * @param strategyInitReceipt - Public key of the strategy init receipt account
1518
- * @returns Promise resolving to the strategy init receipt account data
1519
- *
1520
- * @example
1521
- * ```typescript
1522
- * const strategyInitReceiptAccount = await client.fetchStrategyInitReceiptAccount(strategyInitReceiptPubkey);
1523
- * ```
1524
- */
1525
- async fetchStrategyInitReceiptAccount(strategyInitReceipt) {
1526
- return await this.vaultProgram.account.strategyInitReceipt.fetch(strategyInitReceipt, this.provider.opts.commitment);
1527
- }
1528
- /**
1529
- * Fetches an adaptor add receipt account's data
1530
- * @param adaptorAddReceipt - Public key of the adaptor add receipt account
1531
- * @returns Promise resolving to the adaptor add receipt account data
1532
- *
1533
- * @example
1534
- * ```typescript
1535
- * const adaptorAddReceiptAccount = await client.fetchAdaptorAddReceiptAccount(adaptorAddReceiptPubkey);
1536
- * ```
1537
- */
1538
- async fetchAdaptorAddReceiptAccount(adaptorAddReceipt) {
1539
- return await this.vaultProgram.account.adaptorAddReceipt.fetch(adaptorAddReceipt, this.provider.opts.commitment);
1540
- }
1541
- /**
1542
- * Fetches a request withdraw vault receipt account's data
1543
- * @param requestWithdrawVaultReceipt - Public key of the request withdraw vault receipt account
1544
- * @returns Promise resolving to the request withdraw vault receipt account data
1545
- *
1546
- * @example
1547
- * ```typescript
1548
- * const requestWithdrawVaultReceiptAccount = await client.fetchRequestWithdrawVaultReceiptAccount(requestWithdrawVaultReceiptPubkey);
1549
- * ```
1550
- */
1551
- async fetchRequestWithdrawVaultReceiptAccount(requestWithdrawVaultReceipt) {
1552
- return await this.vaultProgram.account.requestWithdrawVaultReceipt.fetch(requestWithdrawVaultReceipt, this.provider.opts.commitment);
1553
- }
1554
- // --------------------------------------- Helpers
1555
- /**
1556
- * Fetches the position and total values for a vault
1557
- * @param vault - Public key of the vault
1558
- * @returns Promise resolving to the position and total values
1559
- *
1560
- * @example
1561
- * ```typescript
1562
- * const positionAndTotalValues = await client.getPositionAndTotalValuesForVault(vaultPubkey);
1563
- * ```
1564
- */
1565
- async getPositionAndTotalValuesForVault(vault) {
1566
- const vaultAccount = await this.fetchVaultAccount(vault);
1567
- const totalAssetValue = vaultAccount.asset.totalValue;
1568
- const strategyInitReceiptAccounts = await this.fetchAllStrategyInitReceiptAccountsOfVault(vault);
1569
- const strategyInfo = strategyInitReceiptAccounts.map((vaultStrategyAccount) => ({
1570
- strategyId: vaultStrategyAccount.account.strategy.toBase58(),
1571
- amount: vaultStrategyAccount.account.positionValue.toNumber(),
1572
- }));
1573
- return {
1574
- totalValue: totalAssetValue.toNumber(),
1575
- strategies: strategyInfo,
1576
- };
1577
- }
1578
- /**
1579
- * Fetches the accumulated admin fees for a vault
1580
- * @param vault - Public key of the vault
1581
- * @returns Promise resolving to the accumulated admin fees
1582
- *
1583
- * @example
1584
- * ```typescript
1585
- * const accumulatedAdminFees = await client.getAccumulatedAdminFeesForVault(vaultPubkey);
1586
- * ```
1587
- */
1588
- async getAccumulatedAdminFeesForVault(vault) {
1589
- const vaultAccount = await this.fetchVaultAccount(vault);
1590
- return vaultAccount.feeState.accumulatedLpAdminFees;
1591
- }
1592
- /**
1593
- * Fetches the accumulated manager fees for a vault
1594
- * @param vault - Public key of the vault
1595
- * @returns Promise resolving to the accumulated manager fees
1596
- *
1597
- * @example
1598
- * ```typescript
1599
- * const accumulatedManagerFees = await client.getAccumulatedManagerFeesForVault(vaultPubkey);
1600
- * ```
1601
- */
1602
- async getAccumulatedManagerFeesForVault(vault) {
1603
- const vaultAccount = await this.fetchVaultAccount(vault);
1604
- return vaultAccount.feeState.accumulatedLpManagerFees;
1605
- }
1606
- /**
1607
- * Fetches the accumulated protocol fees for a vault
1608
- * @param vault - Public key of the vault
1609
- * @returns Promise resolving to the accumulated protocol fees
1610
- *
1611
- * @example
1612
- * ```typescript
1613
- * const accumulatedProtocolFees = await client.getAccumulatedProtocolFeesForVault(vaultPubkey);
1614
- * ```
1615
- */
1616
- async getAccumulatedProtocolFeesForVault(vault) {
1617
- const vaultAccount = await this.fetchVaultAccount(vault);
1618
- return vaultAccount.feeState.accumulatedLpProtocolFees;
1619
- }
1620
- /**
1621
- * Fetches the current asset per LP for a vault
1622
- * @param vault - Public key of the vault
1623
- * @returns Promise resolving to the current asset per LP
1624
- *
1625
- * @example
1626
- * ```typescript
1627
- * const currentAssetPerLp = await client.getCurrentAssetPerLpForVault(vaultPubkey);
1628
- * ```
1629
- */
1630
- async getCurrentAssetPerLpForVault(vault) {
1631
- const vaultLpMint = this.findVaultLpMint(vault);
1632
- const vaultAccount = await this.fetchVaultAccount(vault);
1633
- const lpSupply = await (0, spl_token_1.getMint)(this.conn, vaultLpMint, this.provider.opts.commitment).then((lp) => new bn_js_1.default(lp.supply.toString()));
1634
- const unharvestedFeesLp = vaultAccount.feeState.accumulatedLpAdminFees
1635
- .add(vaultAccount.feeState.accumulatedLpManagerFees)
1636
- .add(vaultAccount.feeState.accumulatedLpProtocolFees);
1637
- const deadWeight = vaultAccount.deadWeight;
1638
- const totalLpSupply = unharvestedFeesLp.add(lpSupply).add(deadWeight);
1639
- const currentAssetPerLp = vaultAccount.asset.totalValue.toNumber() / totalLpSupply.toNumber();
1640
- return currentAssetPerLp;
1641
- }
1642
- /**
1643
- * Fetches the high water mark for a vault
1644
- * @param vault - Public key of the vault
1645
- * @returns Promise resolving to the high water mark
1646
- *
1647
- * @example
1648
- * ```typescript
1649
- * const highWaterMark = await client.getHighWaterMarkForVault(vaultPubkey);
1650
- * ```
1651
- */
1652
- async getHighWaterMarkForVault(vault) {
1653
- const vaultAccount = await this.fetchVaultAccount(vault);
1654
- const highWaterMarkValue = (0, decimals_1.convertDecimalBitsToDecimal)(vaultAccount.highWaterMark.highestAssetPerLpDecimalBits);
1655
- return {
1656
- highestAssetPerLp: highWaterMarkValue.toNumber(),
1657
- lastUpdatedTs: vaultAccount.highWaterMark.lastUpdatedTs.toNumber(),
1658
- };
1659
- }
1660
- /**
1661
- * Fetches the breakdown of the LP supply for a vault
1662
- * @param vault - Public key of the vault
1663
- * @returns Promise resolving to the breakdown of the LP supply
1664
- *
1665
- * @example
1666
- * ```typescript
1667
- * const lpSupplyBreakdown = await client.getVaultLpSupplyBreakdown(vaultPubkey);
1668
- * ```
1669
- */
1670
- async getVaultLpSupplyBreakdown(vault) {
1671
- const [vaultAccount, lpMintInfo] = await Promise.all([
1672
- this.fetchVaultAccount(vault),
1673
- (0, spl_token_1.getMint)(this.conn, this.findVaultLpMint(vault), this.provider.opts.commitment),
1674
- ]);
1675
- const circulating = new bn_js_1.default(lpMintInfo.supply.toString());
1676
- const unharvestedFees = vaultAccount.feeState.accumulatedLpAdminFees
1677
- .add(vaultAccount.feeState.accumulatedLpManagerFees)
1678
- .add(vaultAccount.feeState.accumulatedLpProtocolFees);
1679
- const deadWeight = vaultAccount.deadWeight;
1680
- const currentTotalLp = circulating.add(unharvestedFees).add(deadWeight);
1681
- const unrealisedFees = this.calculateUnrealisedLpFees(currentTotalLp, vaultAccount.asset.totalValue, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vaultAccount.feeConfiguration.managerManagementFee +
1682
- vaultAccount.feeConfiguration.adminManagementFee +
1683
- vaultAccount.feeConfiguration.protocolManagementFee));
1684
- const total = currentTotalLp.add(unrealisedFees);
1685
- return {
1686
- circulating,
1687
- unharvestedFees,
1688
- unrealisedFees,
1689
- total,
1690
- };
1691
- }
1692
- /**
1693
- * Processes a withdrawal receipt into a standardized withdrawal info object
1694
- * @private
1695
- */
1696
- async processWithdrawalReceipt(receipt, vaultAccount, lpSupply) {
1697
- const amountAssetToWithdrawDecimal = (0, decimals_1.convertDecimalBitsToDecimal)(receipt.account.amountAssetToWithdrawDecimalBits);
1698
- const amountAssetToWithdrawAtRequest = amountAssetToWithdrawDecimal.toNumber();
1699
- const amountLpEscrowed = receipt.account.amountLpEscrowed;
1700
- const amountAssetToWithdrawAtPresent = this.calculateAssetsForWithdrawHelper(vaultAccount.asset.totalValue, vaultAccount.lockedProfitState.lastUpdatedLockedProfit, vaultAccount.lockedProfitState.lastReport, vaultAccount.vaultConfiguration.lockedProfitDegradationDuration, vaultAccount.feeState.accumulatedLpAdminFees, vaultAccount.feeState.accumulatedLpManagerFees, vaultAccount.feeState.accumulatedLpProtocolFees, vaultAccount.feeConfiguration.redemptionFee, vaultAccount.feeConfiguration.managerManagementFee +
1701
- vaultAccount.feeConfiguration.adminManagementFee +
1702
- vaultAccount.feeConfiguration.protocolManagementFee, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, lpSupply, amountLpEscrowed, vaultAccount.deadWeight).toNumber();
1703
- // Cap the withdrawal amount to the initial request amount
1704
- const amountAssetToWithdrawEffective = Math.min(amountAssetToWithdrawAtPresent, amountAssetToWithdrawAtRequest);
1705
- return {
1706
- user: receipt.account.user,
1707
- amountAssetToWithdrawEffective,
1708
- amountAssetToWithdrawAtRequest,
1709
- amountAssetToWithdrawAtPresent,
1710
- amountLpEscrowed: amountLpEscrowed.toNumber(),
1711
- withdrawableFromTs: receipt.account.withdrawableFromTs.toNumber(),
1712
- };
1713
- }
1714
- /**
1715
- * Fetches the pending withdrawal for a user
1716
- * @param vault - Public key of the vault
1717
- * @param user - Public key of the user
1718
- * @returns Promise resolving to the pending withdrawal
1719
- *
1720
- * @example
1721
- * ```typescript
1722
- * const pendingWithdrawal = await client.getPendingWithdrawalForUser(vaultPubkey, userPubkey);
1723
- * ```
1724
- */
1725
- async getPendingWithdrawalForUser(vault, user) {
1726
- const [vaultAccount, lp] = await Promise.all([
1727
- this.fetchVaultAccount(vault),
1728
- (0, spl_token_1.getMint)(this.conn, this.findVaultLpMint(vault), this.provider.opts.commitment),
1729
- ]);
1730
- const requestWithdrawVaultReceiptAddress = this.findRequestWithdrawVaultReceipt(vault, user);
1731
- const receipt = await this.fetchRequestWithdrawVaultReceiptAccount(requestWithdrawVaultReceiptAddress);
1732
- return this.processWithdrawalReceipt({ account: receipt }, vaultAccount, new bn_js_1.default(lp.supply.toString()));
1733
- }
1734
- /**
1735
- * Fetches all pending withdrawals for a vault
1736
- * @param vault - Public key of the vault
1737
- * @returns Promise resolving to an array of pending withdrawals
1738
- *
1739
- * @example
1740
- * ```typescript
1741
- * const pendingWithdrawals = await client.getAllPendingWithdrawalsForVault(vaultPubkey);
1742
- * ```
1743
- */
1744
- async getAllPendingWithdrawalsForVault(vault) {
1745
- const [requestWithdrawVaultReceipts, vaultAccount, lp] = await Promise.all([
1746
- this.fetchAllRequestWithdrawVaultReceiptsOfVault(vault),
1747
- this.fetchVaultAccount(vault),
1748
- (0, spl_token_1.getMint)(this.conn, this.findVaultLpMint(vault), this.provider.opts.commitment),
1749
- ]);
1750
- const lpSupply = new bn_js_1.default(lp.supply.toString());
1751
- return Promise.all(requestWithdrawVaultReceipts.map((receipt) => this.processWithdrawalReceipt(receipt, vaultAccount, lpSupply)));
1752
- }
1753
- calculateLockedProfit(lastUpdatedLockedProfit, lastReport, lockedProfitDegradationDuration, currentTime) {
1754
- if (lockedProfitDegradationDuration.eq(new bn_js_1.default(0)))
1755
- return new bn_js_1.default(0);
1756
- const duration = currentTime.sub(lastReport);
1757
- if (duration.gt(lockedProfitDegradationDuration))
1758
- return new bn_js_1.default(0);
1759
- return lastUpdatedLockedProfit
1760
- .mul(lockedProfitDegradationDuration.sub(duration))
1761
- .div(lockedProfitDegradationDuration);
1762
- }
1763
- /**
1764
- * Helper to calculate only the pending (unrealised) LP fees based on time elapsed.
1765
- */
1766
- calculateUnrealisedLpFees(currentTotalLp, assetTotalValue, lastManagementFeeUpdateTs, managementFeeBps) {
1767
- if (lastManagementFeeUpdateTs.eq(new bn_js_1.default(0)) ||
1768
- assetTotalValue.eq(new bn_js_1.default(0)) ||
1769
- managementFeeBps.eq(new bn_js_1.default(0))) {
1770
- return new bn_js_1.default(0);
1771
- }
1772
- const nowBn = new bn_js_1.default(Math.floor(Date.now() / 1000));
1773
- const timeElapsed = bn_js_1.default.max(new bn_js_1.default(0), nowBn.sub(lastManagementFeeUpdateTs));
1774
- if (timeElapsed.eq(new bn_js_1.default(0))) {
1775
- return new bn_js_1.default(0);
1776
- }
1777
- const feeAmountInAsset = assetTotalValue
1778
- .mul(timeElapsed)
1779
- .mul(managementFeeBps)
1780
- .div(constants_1.MAX_FEE_BPS_BN)
1781
- .div(constants_1.ONE_YEAR_BN);
1782
- const lpNumerator = feeAmountInAsset.mul(currentTotalLp);
1783
- const lpDenominator = assetTotalValue.sub(feeAmountInAsset);
1784
- if (lpDenominator.lte(new bn_js_1.default(0))) {
1785
- return new bn_js_1.default(0);
1786
- }
1787
- const pendingLpToMint = lpNumerator
1788
- .add(lpDenominator)
1789
- .sub(new bn_js_1.default(1))
1790
- .div(lpDenominator);
1791
- return pendingLpToMint;
1792
- }
1793
- calculateAssetsForWithdrawHelper(vaultTotalValue, vaultLastUpdatedLockedProfit, vaultLastReport, vaultLockedProfitDegradationDuration, vaultAccumulatedLpAdminFees, vaultAccumulatedLpManagerFees, vaultAccumulatedLpProtocolFees, vaultRedemptionFeeBps, vaultManagementFeeBps, vaultLastManagementFeeUpdateTs, lpSupply, lpAmount, deadWeight = new bn_js_1.default(0)) {
1794
- if (lpSupply <= new bn_js_1.default(0))
1795
- throw new Error("Invalid LP supply");
1796
- if (vaultTotalValue <= new bn_js_1.default(0))
1797
- throw new Error("Invalid total assets");
1798
- const lockedProfit = this.calculateLockedProfit(vaultLastUpdatedLockedProfit, vaultLastReport, vaultLockedProfitDegradationDuration, new bn_js_1.default(Math.floor(Date.now() / 1000)));
1799
- const totalUnlockedValue = vaultTotalValue.sub(lockedProfit);
1800
- const unharvestedFeesLp = vaultAccumulatedLpAdminFees
1801
- .add(vaultAccumulatedLpManagerFees)
1802
- .add(vaultAccumulatedLpProtocolFees);
1803
- const lpSupplyInclAccumulatedFees = lpSupply
1804
- .add(unharvestedFeesLp)
1805
- .add(deadWeight);
1806
- const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, vaultTotalValue, vaultLastManagementFeeUpdateTs, new bn_js_1.default(vaultManagementFeeBps));
1807
- const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
1808
- // asset_to_redeem_pre_fee = amount * (total_asset_pre_withdraw / total_lp_supply_pre_withdraw)
1809
- // asset_to_redeem_post_fee = asset_to_redeem_pre_fee * (10000 - redemption_fee_bps) / 10000
1810
- const assetToRedeemNumerator = lpAmount
1811
- .mul(totalUnlockedValue)
1812
- .mul(new bn_js_1.default(10000 - vaultRedemptionFeeBps));
1813
- const assetToRedeemDenominator = lpSupplyInclFees.mul(new bn_js_1.default(10000));
1814
- const amount = assetToRedeemNumerator.div(assetToRedeemDenominator);
1815
- return amount;
1816
- }
1817
- /**
1818
- * Calculates the amount of assets that would be received for a given LP token amount
1819
- *
1820
- * @param vaultPk - Public key of the vault
1821
- * @param lpAmount - Amount of LP tokens to calculate for
1822
- * @returns Promise resolving to the amount of assets that would be received
1823
- *
1824
- * @throws {Error} If LP supply or total assets are invalid
1825
- * @throws {Error} If math overflow occurs during calculation
1826
- *
1827
- * @example
1828
- * ```typescript
1829
- * const assetsToReceive = await client.calculateAssetsForWithdraw(
1830
- * vaultPubkey,
1831
- * new BN('1000000000')
1832
- * );
1833
- * ```
1834
- */
1835
- async calculateAssetsForWithdraw(vaultPk, lpAmount) {
1836
- try {
1837
- const vault = await this.fetchVaultAccount(vaultPk);
1838
- const lpMint = this.findVaultLpMint(vaultPk);
1839
- const lp = await (0, spl_token_1.getMint)(this.conn, lpMint, this.provider.opts.commitment);
1840
- const amount = this.calculateAssetsForWithdrawHelper(vault.asset.totalValue, vault.lockedProfitState.lastUpdatedLockedProfit, vault.lockedProfitState.lastReport, vault.vaultConfiguration.lockedProfitDegradationDuration, vault.feeState.accumulatedLpAdminFees, vault.feeState.accumulatedLpManagerFees, vault.feeState.accumulatedLpProtocolFees, vault.feeConfiguration.redemptionFee, vault.feeConfiguration.managerManagementFee +
1841
- vault.feeConfiguration.adminManagementFee +
1842
- vault.feeConfiguration.protocolManagementFee, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(lp.supply.toString()), lpAmount, vault.deadWeight);
1843
- return amount;
1844
- }
1845
- catch (e) {
1846
- throw new Error("Math overflow in asset calculation for withdraw");
1847
- }
1848
- }
1849
- /**
1850
- * Calculates the amount of LP tokens that would be burned for a given asset amount
1851
- *
1852
- * @param vaultPk - Public key of the vault
1853
- * @param assetAmount - Amount of assets to calculate for
1854
- * @returns Promise resolving to the amount of LP tokens that would be burned
1855
- *
1856
- * @throws {Error} If LP supply or total assets are invalid
1857
- * @throws {Error} If math overflow occurs during calculation
1858
- *
1859
- * @example
1860
- * ```typescript
1861
- * const lpTokensToBurn = await client.calculateLpForWithdraw(
1862
- * vaultPubkey,
1863
- * new BN('1000000000')
1864
- * );
1865
- * ```
1866
- */
1867
- async calculateLpForWithdraw(vaultPk, assetAmount) {
1868
- try {
1869
- const vault = await this.fetchVaultAccount(vaultPk);
1870
- const totalValue = vault.asset.totalValue;
1871
- const lockedProfit = this.calculateLockedProfit(vault.lockedProfitState.lastUpdatedLockedProfit, vault.lockedProfitState.lastReport, vault.vaultConfiguration.lockedProfitDegradationDuration, new bn_js_1.default(Math.floor(Date.now() / 1000)));
1872
- const totalUnlockedValue = totalValue.sub(lockedProfit);
1873
- const lpMint = this.findVaultLpMint(vaultPk);
1874
- const lp = await (0, spl_token_1.getMint)(this.conn, lpMint, this.provider.opts.commitment);
1875
- const lpSupply = new bn_js_1.default(lp.supply.toString());
1876
- // Validate inputs
1877
- if (lpSupply <= new bn_js_1.default(0))
1878
- throw new Error("Invalid LP supply");
1879
- if (totalValue <= new bn_js_1.default(0))
1880
- throw new Error("Invalid total assets");
1881
- const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
1882
- .add(vault.feeState.accumulatedLpManagerFees)
1883
- .add(vault.feeState.accumulatedLpProtocolFees);
1884
- const lpSupplyInclAccumulatedFees = lpSupply
1885
- .add(unharvestedFeesLp)
1886
- .add(vault.deadWeight);
1887
- const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
1888
- vault.feeConfiguration.adminManagementFee +
1889
- vault.feeConfiguration.protocolManagementFee));
1890
- const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
1891
- // lp_to_burn_pre_fee = redeem_amount * (total_lp_supply_pre_withdraw / total_asset_pre_withdraw)
1892
- // lp_to_burn_post_fee = lp_to_burn_pre_fee * (10000 / (10000 - redemption_fee_bps))
1893
- const lpToBurnNumerator = assetAmount
1894
- .mul(lpSupplyInclFees)
1895
- .mul(new bn_js_1.default(10000));
1896
- const lpToBurnDenominator = totalUnlockedValue.mul(new bn_js_1.default(10000 - vault.feeConfiguration.redemptionFee));
1897
- const lpToBurn = lpToBurnNumerator.div(lpToBurnDenominator);
1898
- return lpToBurn;
1899
- }
1900
- catch (e) {
1901
- throw new Error("Math overflow in LP token calculation for withdraw");
1902
- }
1903
- }
1904
- /**
1905
- * Calculates the amount of LP tokens that would be received for a given asset deposit
1906
- *
1907
- * @param vaultPk - Public key of the vault
1908
- * @param assetAmount - Amount of assets to deposit
1909
- * @returns Promise resolving to the amount of LP tokens that would be received
1910
- *
1911
- * @throws {Error} If math overflow occurs during calculation
1912
- *
1913
- * @example
1914
- * ```typescript
1915
- * const lpTokens = await client.calculateLpTokensForDeposit(
1916
- * vaultPubkey
1917
- * new BN('1000000000'),
1918
- * );
1919
- * ```
1920
- */
1921
- async calculateLpForDeposit(vaultPk, assetAmount) {
1922
- const vault = await this.fetchVaultAccount(vaultPk);
1923
- const totalValue = vault.asset.totalValue;
1924
- const lpMint = this.findVaultLpMint(vaultPk);
1925
- const lp = await (0, spl_token_1.getMint)(this.conn, lpMint, this.provider.opts.commitment);
1926
- const lpSupply = new bn_js_1.default(lp.supply.toString());
1927
- const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
1928
- .add(vault.feeState.accumulatedLpManagerFees)
1929
- .add(vault.feeState.accumulatedLpProtocolFees);
1930
- const lpSupplyInclAccumulatedFees = lpSupply
1931
- .add(unharvestedFeesLp)
1932
- .add(vault.deadWeight);
1933
- const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
1934
- vault.feeConfiguration.adminManagementFee +
1935
- vault.feeConfiguration.protocolManagementFee));
1936
- const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
1937
- // If the pool is empty, mint LP tokens 1:1 with deposit
1938
- if (lpSupplyInclFees.eq(new bn_js_1.default(0))) {
1939
- const assetMint = await (0, spl_token_1.getMint)(this.conn, vault.asset.mint, this.provider.opts.commitment);
1940
- const assetDecimals = assetMint.decimals;
1941
- const lpDecimals = lp.decimals;
1942
- return assetAmount
1943
- .mul(new bn_js_1.default(10 ** lpDecimals))
1944
- .div(new bn_js_1.default(10 ** assetDecimals));
1945
- }
1946
- try {
1947
- const lpToMintNumerator = assetAmount
1948
- .mul(lpSupplyInclFees)
1949
- .mul(new bn_js_1.default(10000 - vault.feeConfiguration.issuanceFee));
1950
- const totalAssetPostDeposit = totalValue.add(assetAmount);
1951
- const lpToMintDenominator = totalAssetPostDeposit
1952
- .mul(new bn_js_1.default(10000))
1953
- .sub(assetAmount.mul(new bn_js_1.default(10000 - vault.feeConfiguration.issuanceFee)));
1954
- const lpToMint = lpToMintNumerator.div(lpToMintDenominator);
1955
- return lpToMint;
1956
- }
1957
- catch (e) {
1958
- throw new Error("Math overflow in LP token calculation for deposit");
1959
- }
1960
- }
1961
- }
1962
- exports.VoltrClient = VoltrClient;