@reflectmoney/stable.ts 2.9.0 → 3.0.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 (513) hide show
  1. package/README.md +257 -126
  2. package/dist/classes/Migration.d.ts +66 -0
  3. package/dist/classes/Migration.js +95 -0
  4. package/dist/classes/PdaClient.d.ts +46 -68
  5. package/dist/classes/PdaClient.js +161 -141
  6. package/dist/classes/Reflect.d.ts +19 -5
  7. package/dist/classes/Reflect.js +23 -6
  8. package/dist/classes/ReflectKeeper.d.ts +73 -60
  9. package/dist/classes/ReflectKeeper.js +181 -164
  10. package/dist/classes/ReflectTokenisedBond.d.ts +37 -50
  11. package/dist/classes/ReflectTokenisedBond.js +70 -130
  12. package/dist/classes/Stablecoin.d.ts +90 -130
  13. package/dist/classes/Stablecoin.js +134 -247
  14. package/dist/classes/index.d.ts +1 -0
  15. package/dist/classes/index.js +1 -0
  16. package/dist/constants/devnet.d.ts +4 -4
  17. package/dist/constants/devnet.js +5 -5
  18. package/dist/constants/drift.d.ts +8 -6
  19. package/dist/constants/drift.js +12 -12
  20. package/dist/constants/index.d.ts +4 -2
  21. package/dist/constants/index.js +4 -2
  22. package/dist/constants/jupiter.d.ts +12 -4
  23. package/dist/constants/jupiter.js +17 -6
  24. package/dist/constants/kamino.d.ts +14 -0
  25. package/dist/constants/kamino.js +39 -0
  26. package/dist/constants/lookupTables.d.ts +3 -4
  27. package/dist/constants/lookupTables.js +5 -5
  28. package/dist/constants/mock.d.ts +2 -0
  29. package/dist/constants/mock.js +5 -0
  30. package/dist/constants/usdc.d.ts +6 -7
  31. package/dist/constants/usdc.js +8 -9
  32. package/dist/constants/usdt.d.ts +6 -0
  33. package/dist/constants/usdt.js +9 -0
  34. package/dist/constants/wsol.d.ts +6 -6
  35. package/dist/constants/wsol.js +6 -6
  36. package/dist/generated/reflect_main/accounts/driftUsdcController.d.ts +31 -0
  37. package/dist/generated/reflect_main/accounts/driftUsdcController.js +77 -0
  38. package/dist/generated/reflect_main/accounts/index.d.ts +11 -38
  39. package/dist/generated/reflect_main/accounts/index.js +11 -39
  40. package/dist/generated/reflect_main/accounts/main.d.ts +62 -0
  41. package/dist/generated/reflect_main/accounts/main.js +91 -0
  42. package/dist/generated/reflect_main/accounts/strategyController.d.ts +31 -0
  43. package/dist/generated/reflect_main/accounts/strategyController.js +77 -0
  44. package/dist/generated/reflect_main/accounts/userPermissions.d.ts +44 -0
  45. package/dist/generated/reflect_main/accounts/userPermissions.js +89 -0
  46. package/dist/generated/reflect_main/errors/index.d.ts +5 -966
  47. package/dist/generated/reflect_main/errors/index.js +21 -1663
  48. package/dist/generated/reflect_main/errors/reflectMain.d.ts +215 -0
  49. package/dist/generated/reflect_main/errors/reflectMain.js +323 -0
  50. package/dist/generated/reflect_main/index.d.ts +9 -16
  51. package/dist/generated/reflect_main/index.js +8 -16
  52. package/dist/generated/reflect_main/instructions/addLstDrift.d.ts +62 -45
  53. package/dist/generated/reflect_main/instructions/addLstDrift.js +155 -104
  54. package/dist/generated/reflect_main/instructions/addSubAccount.d.ts +74 -50
  55. package/dist/generated/reflect_main/instructions/addSubAccount.js +166 -119
  56. package/dist/generated/reflect_main/instructions/captureSpreadDrift.d.ts +70 -59
  57. package/dist/generated/reflect_main/instructions/captureSpreadDrift.js +167 -115
  58. package/dist/generated/reflect_main/instructions/createAdminAccount.d.ts +53 -46
  59. package/dist/generated/reflect_main/instructions/createAdminAccount.js +135 -91
  60. package/dist/generated/reflect_main/instructions/createDriftUserAccount.d.ts +78 -0
  61. package/dist/generated/reflect_main/instructions/createDriftUserAccount.js +184 -0
  62. package/dist/generated/reflect_main/instructions/createDriftUserStatsAccount.d.ts +74 -0
  63. package/dist/generated/reflect_main/instructions/createDriftUserStatsAccount.js +173 -0
  64. package/dist/generated/reflect_main/instructions/createKaminoUserAccounts.d.ts +144 -0
  65. package/dist/generated/reflect_main/instructions/createKaminoUserAccounts.js +395 -0
  66. package/dist/generated/reflect_main/instructions/depositDrift.d.ts +96 -66
  67. package/dist/generated/reflect_main/instructions/depositDrift.js +190 -139
  68. package/dist/generated/reflect_main/instructions/freezeProgram.d.ts +56 -47
  69. package/dist/generated/reflect_main/instructions/freezeProgram.js +139 -94
  70. package/dist/generated/reflect_main/instructions/freezeProtocolAction.d.ts +57 -48
  71. package/dist/generated/reflect_main/instructions/freezeProtocolAction.js +140 -95
  72. package/dist/generated/reflect_main/instructions/freezeStrategyAction.d.ts +61 -51
  73. package/dist/generated/reflect_main/instructions/freezeStrategyAction.js +145 -101
  74. package/dist/generated/reflect_main/instructions/increaseAdminSize.d.ts +40 -45
  75. package/dist/generated/reflect_main/instructions/increaseAdminSize.js +81 -90
  76. package/dist/generated/reflect_main/instructions/index.d.ts +45 -33
  77. package/dist/generated/reflect_main/instructions/index.js +19 -7
  78. package/dist/generated/reflect_main/instructions/initDriftControllerS1.d.ts +70 -53
  79. package/dist/generated/reflect_main/instructions/initDriftControllerS1.js +163 -100
  80. package/dist/generated/reflect_main/instructions/initDriftControllerS2.d.ts +75 -0
  81. package/dist/generated/reflect_main/instructions/initDriftControllerS2.js +176 -0
  82. package/dist/generated/reflect_main/instructions/initDriftControllerS3.d.ts +70 -53
  83. package/dist/generated/reflect_main/instructions/initDriftControllerS3.js +163 -100
  84. package/dist/generated/reflect_main/instructions/initMain.d.ts +50 -39
  85. package/dist/generated/reflect_main/instructions/initMain.js +136 -91
  86. package/dist/generated/reflect_main/instructions/migrateS1.d.ts +58 -0
  87. package/dist/generated/reflect_main/instructions/migrateS1.js +145 -0
  88. package/dist/generated/reflect_main/instructions/mintDriftS1.d.ts +118 -81
  89. package/dist/generated/reflect_main/instructions/mintDriftS1.js +244 -169
  90. package/dist/generated/reflect_main/instructions/mintDriftS3.d.ts +118 -81
  91. package/dist/generated/reflect_main/instructions/mintDriftS3.js +244 -169
  92. package/dist/generated/reflect_main/instructions/mintStrategy1.d.ts +95 -0
  93. package/dist/generated/reflect_main/instructions/mintStrategy1.js +236 -0
  94. package/dist/generated/reflect_main/instructions/mintStrategy2.d.ts +95 -0
  95. package/dist/generated/reflect_main/instructions/mintStrategy2.js +236 -0
  96. package/dist/generated/reflect_main/instructions/rebalanceS1.d.ts +74 -0
  97. package/dist/generated/reflect_main/instructions/rebalanceS1.js +211 -0
  98. package/dist/generated/reflect_main/instructions/rebalanceS2.d.ts +74 -0
  99. package/dist/generated/reflect_main/instructions/rebalanceS2.js +211 -0
  100. package/dist/generated/reflect_main/instructions/redeemDriftS1.d.ts +121 -81
  101. package/dist/generated/reflect_main/instructions/redeemDriftS1.js +246 -170
  102. package/dist/generated/reflect_main/instructions/redeemDriftS3.d.ts +121 -81
  103. package/dist/generated/reflect_main/instructions/redeemDriftS3.js +246 -170
  104. package/dist/generated/reflect_main/instructions/redeemStrategy1.d.ts +95 -0
  105. package/dist/generated/reflect_main/instructions/redeemStrategy1.js +236 -0
  106. package/dist/generated/reflect_main/instructions/redeemStrategy2.d.ts +95 -0
  107. package/dist/generated/reflect_main/instructions/redeemStrategy2.js +236 -0
  108. package/dist/generated/reflect_main/instructions/settlePnl.d.ts +62 -46
  109. package/dist/generated/reflect_main/instructions/settlePnl.js +135 -104
  110. package/dist/generated/reflect_main/instructions/suspendSplProtocol.d.ts +57 -48
  111. package/dist/generated/reflect_main/instructions/suspendSplProtocol.js +139 -95
  112. package/dist/generated/reflect_main/instructions/suspendSplStrategy.d.ts +61 -50
  113. package/dist/generated/reflect_main/instructions/suspendSplStrategy.js +144 -100
  114. package/dist/generated/reflect_main/instructions/updateActionRoleProtocol.d.ts +60 -50
  115. package/dist/generated/reflect_main/instructions/updateActionRoleProtocol.js +142 -98
  116. package/dist/generated/reflect_main/instructions/updateActionRoleStrategy.d.ts +64 -52
  117. package/dist/generated/reflect_main/instructions/updateActionRoleStrategy.js +147 -103
  118. package/dist/generated/reflect_main/instructions/updateAttenuation.d.ts +65 -51
  119. package/dist/generated/reflect_main/instructions/updateAttenuation.js +146 -100
  120. package/dist/generated/reflect_main/instructions/updateCap.d.ts +58 -50
  121. package/dist/generated/reflect_main/instructions/updateCap.js +142 -98
  122. package/dist/generated/reflect_main/instructions/updateCapitalConductor.d.ts +79 -0
  123. package/dist/generated/reflect_main/instructions/updateCapitalConductor.js +161 -0
  124. package/dist/generated/reflect_main/instructions/updateRecipients.d.ts +62 -51
  125. package/dist/generated/reflect_main/instructions/updateRecipients.js +144 -100
  126. package/dist/generated/reflect_main/instructions/updateRoleHolderProtocol.d.ts +65 -53
  127. package/dist/generated/reflect_main/instructions/updateRoleHolderProtocol.js +154 -104
  128. package/dist/generated/reflect_main/instructions/updateRoleHolderStrategy.d.ts +65 -53
  129. package/dist/generated/reflect_main/instructions/updateRoleHolderStrategy.js +154 -104
  130. package/dist/generated/reflect_main/programs/index.d.ts +8 -0
  131. package/dist/generated/reflect_main/programs/index.js +24 -0
  132. package/dist/generated/reflect_main/programs/reflectMain.d.ts +139 -0
  133. package/dist/generated/reflect_main/programs/reflectMain.js +190 -0
  134. package/dist/generated/reflect_main/shared/index.d.ts +49 -0
  135. package/dist/generated/reflect_main/shared/index.js +90 -0
  136. package/dist/generated/reflect_main/types/accessControl.d.ts +24 -0
  137. package/dist/generated/reflect_main/types/accessControl.js +29 -0
  138. package/dist/generated/reflect_main/types/accessMap.d.ts +24 -0
  139. package/dist/generated/reflect_main/types/accessMap.js +35 -0
  140. package/dist/generated/reflect_main/types/action.d.ts +32 -0
  141. package/dist/generated/reflect_main/types/action.js +44 -0
  142. package/dist/generated/reflect_main/types/actionMapping.d.ts +22 -0
  143. package/dist/generated/reflect_main/types/actionMapping.js +31 -0
  144. package/dist/generated/reflect_main/types/addedProtocolActionRole.d.ts +20 -0
  145. package/dist/generated/reflect_main/types/addedProtocolActionRole.js +29 -0
  146. package/dist/generated/reflect_main/types/addedProtocolRoleHolder.d.ts +20 -0
  147. package/dist/generated/reflect_main/types/addedProtocolRoleHolder.js +29 -0
  148. package/dist/generated/reflect_main/types/addedStrategyActionRole.d.ts +22 -0
  149. package/dist/generated/reflect_main/types/addedStrategyActionRole.js +31 -0
  150. package/dist/generated/reflect_main/types/addedStrategyRoleHolder.d.ts +22 -0
  151. package/dist/generated/reflect_main/types/addedStrategyRoleHolder.js +31 -0
  152. package/dist/generated/reflect_main/types/attenuation.d.ts +16 -0
  153. package/dist/generated/reflect_main/types/attenuation.js +28 -0
  154. package/dist/generated/reflect_main/types/attenuationUpdated.d.ts +23 -0
  155. package/dist/generated/reflect_main/types/attenuationUpdated.js +32 -0
  156. package/dist/generated/reflect_main/types/autoCompound.d.ts +23 -0
  157. package/dist/generated/reflect_main/types/autoCompound.js +32 -0
  158. package/dist/generated/reflect_main/types/base.d.ts +38 -0
  159. package/dist/generated/reflect_main/types/base.js +47 -0
  160. package/dist/generated/reflect_main/types/capitalConductorComponent.d.ts +28 -0
  161. package/dist/generated/reflect_main/types/capitalConductorComponent.js +43 -0
  162. package/dist/generated/reflect_main/types/capture.d.ts +24 -0
  163. package/dist/generated/reflect_main/types/capture.js +33 -0
  164. package/dist/generated/reflect_main/types/component.d.ts +24 -0
  165. package/dist/generated/reflect_main/types/component.js +33 -0
  166. package/dist/generated/reflect_main/types/componentType.d.ts +24 -0
  167. package/dist/generated/reflect_main/types/componentType.js +36 -0
  168. package/dist/generated/reflect_main/types/currentProtocolBalance.d.ts +20 -0
  169. package/dist/generated/reflect_main/types/currentProtocolBalance.js +29 -0
  170. package/dist/generated/reflect_main/types/currentProtocolRatio.d.ts +24 -0
  171. package/dist/generated/reflect_main/types/currentProtocolRatio.js +33 -0
  172. package/dist/generated/reflect_main/types/driftSpotData.d.ts +17 -0
  173. package/dist/generated/reflect_main/types/driftSpotData.js +30 -0
  174. package/dist/generated/reflect_main/types/driftSpotMarketsComponent.d.ts +20 -0
  175. package/dist/generated/reflect_main/types/driftSpotMarketsComponent.js +29 -0
  176. package/dist/generated/reflect_main/types/driftSubAccountsComponent.d.ts +18 -0
  177. package/dist/generated/reflect_main/types/driftSubAccountsComponent.js +23 -0
  178. package/dist/generated/reflect_main/types/driftSubs.d.ts +17 -0
  179. package/dist/generated/reflect_main/types/driftSubs.js +30 -0
  180. package/dist/generated/reflect_main/types/dustThresholdUpdated.d.ts +21 -0
  181. package/dist/generated/reflect_main/types/dustThresholdUpdated.js +30 -0
  182. package/dist/generated/reflect_main/types/externals.d.ts +18 -0
  183. package/dist/generated/reflect_main/types/externals.js +23 -0
  184. package/dist/generated/reflect_main/types/flowControl.d.ts +20 -0
  185. package/dist/generated/reflect_main/types/flowControl.js +29 -0
  186. package/dist/generated/reflect_main/types/index.d.ts +76 -81
  187. package/dist/generated/reflect_main/types/index.js +76 -81
  188. package/dist/generated/reflect_main/types/issue.d.ts +39 -0
  189. package/dist/generated/reflect_main/types/issue.js +36 -0
  190. package/dist/generated/reflect_main/types/killSwitch.d.ts +20 -0
  191. package/dist/generated/reflect_main/types/killSwitch.js +22 -0
  192. package/dist/generated/reflect_main/types/levelRoles.d.ts +23 -0
  193. package/dist/generated/reflect_main/types/levelRoles.js +23 -0
  194. package/dist/generated/reflect_main/types/maxDeviationBpsUpdated.d.ts +17 -0
  195. package/dist/generated/reflect_main/types/maxDeviationBpsUpdated.js +30 -0
  196. package/dist/generated/reflect_main/types/minPerLegTransferUpdated.d.ts +21 -0
  197. package/dist/generated/reflect_main/types/minPerLegTransferUpdated.js +30 -0
  198. package/dist/generated/reflect_main/types/newAdminAccount.d.ts +15 -0
  199. package/dist/generated/reflect_main/types/newAdminAccount.js +22 -0
  200. package/dist/generated/reflect_main/types/penaltyScaleFactorUpdated.d.ts +17 -0
  201. package/dist/generated/reflect_main/types/penaltyScaleFactorUpdated.js +30 -0
  202. package/dist/generated/reflect_main/types/program.d.ts +22 -0
  203. package/dist/generated/reflect_main/types/program.js +31 -0
  204. package/dist/generated/reflect_main/types/programStatus.d.ts +16 -0
  205. package/dist/generated/reflect_main/types/programStatus.js +28 -0
  206. package/dist/generated/reflect_main/types/programStatusUpdate.d.ts +20 -0
  207. package/dist/generated/reflect_main/types/programStatusUpdate.js +29 -0
  208. package/dist/generated/reflect_main/types/protocolActionUpdate.d.ts +20 -0
  209. package/dist/generated/reflect_main/types/protocolActionUpdate.js +29 -0
  210. package/dist/generated/reflect_main/types/protocolRatiosUpdated.d.ts +22 -0
  211. package/dist/generated/reflect_main/types/protocolRatiosUpdated.js +31 -0
  212. package/dist/generated/reflect_main/types/rack.d.ts +18 -0
  213. package/dist/generated/reflect_main/types/rack.js +27 -0
  214. package/dist/generated/reflect_main/types/recipient.d.ts +19 -0
  215. package/dist/generated/reflect_main/types/recipient.js +28 -0
  216. package/dist/generated/reflect_main/types/recipients.d.ts +20 -0
  217. package/dist/generated/reflect_main/types/recipients.js +29 -0
  218. package/dist/generated/reflect_main/types/redeem.d.ts +39 -0
  219. package/dist/generated/reflect_main/types/redeem.js +36 -0
  220. package/dist/generated/reflect_main/types/removedProtocolActionRole.d.ts +20 -0
  221. package/dist/generated/reflect_main/types/removedProtocolActionRole.js +29 -0
  222. package/dist/generated/reflect_main/types/removedProtocolRoleHolder.d.ts +20 -0
  223. package/dist/generated/reflect_main/types/removedProtocolRoleHolder.js +29 -0
  224. package/dist/generated/reflect_main/types/removedStrategyActionRole.d.ts +22 -0
  225. package/dist/generated/reflect_main/types/removedStrategyActionRole.js +31 -0
  226. package/dist/generated/reflect_main/types/removedStrategyRoleHolder.d.ts +22 -0
  227. package/dist/generated/reflect_main/types/removedStrategyRoleHolder.js +31 -0
  228. package/dist/generated/reflect_main/types/role.d.ts +22 -0
  229. package/dist/generated/reflect_main/types/role.js +34 -0
  230. package/dist/generated/reflect_main/types/settlement.d.ts +17 -0
  231. package/dist/generated/reflect_main/types/settlement.js +30 -0
  232. package/dist/generated/reflect_main/types/splBase.d.ts +17 -0
  233. package/dist/generated/reflect_main/types/splBase.js +30 -0
  234. package/dist/generated/reflect_main/types/splMain.d.ts +43 -0
  235. package/dist/generated/reflect_main/types/splMain.js +44 -0
  236. package/dist/generated/reflect_main/types/splSupport.d.ts +15 -0
  237. package/dist/generated/reflect_main/types/splSupport.js +22 -0
  238. package/dist/generated/reflect_main/types/splSupportStrategy.d.ts +16 -0
  239. package/dist/generated/reflect_main/types/splSupportStrategy.js +28 -0
  240. package/dist/generated/reflect_main/types/splSuspendProtocol.d.ts +16 -0
  241. package/dist/generated/reflect_main/types/splSuspendProtocol.js +28 -0
  242. package/dist/generated/reflect_main/types/splSuspendStrategy.d.ts +17 -0
  243. package/dist/generated/reflect_main/types/splSuspendStrategy.js +30 -0
  244. package/dist/generated/reflect_main/types/spls.d.ts +20 -0
  245. package/dist/generated/reflect_main/types/spls.js +29 -0
  246. package/dist/generated/reflect_main/types/spotDepositDrift.d.ts +19 -0
  247. package/dist/generated/reflect_main/types/spotDepositDrift.js +28 -0
  248. package/dist/generated/reflect_main/types/spreadCapture.d.ts +27 -0
  249. package/dist/generated/reflect_main/types/spreadCapture.js +30 -0
  250. package/dist/generated/reflect_main/types/status.d.ts +17 -0
  251. package/dist/generated/reflect_main/types/status.js +29 -0
  252. package/dist/generated/reflect_main/types/strategyActionUpdate.d.ts +22 -0
  253. package/dist/generated/reflect_main/types/strategyActionUpdate.js +31 -0
  254. package/dist/generated/reflect_main/types/strategyNegative.d.ts +21 -0
  255. package/dist/generated/reflect_main/types/strategyNegative.js +28 -0
  256. package/dist/generated/reflect_main/types/strategyPadding.d.ts +15 -0
  257. package/dist/generated/reflect_main/types/strategyPadding.js +26 -0
  258. package/dist/generated/reflect_main/types/strategyRoleEntry.d.ts +24 -0
  259. package/dist/generated/reflect_main/types/strategyRoleEntry.js +29 -0
  260. package/dist/generated/reflect_main/types/subsVec.d.ts +20 -0
  261. package/dist/generated/reflect_main/types/subsVec.js +29 -0
  262. package/dist/generated/reflect_main/types/update.d.ts +16 -0
  263. package/dist/generated/reflect_main/types/update.js +28 -0
  264. package/dist/generated/reflect_main/types/updateCap.d.ts +21 -0
  265. package/dist/generated/reflect_main/types/updateCap.js +30 -0
  266. package/dist/generated/reflect_main/types/updateRebalanceSlippage.d.ts +17 -0
  267. package/dist/generated/reflect_main/types/updateRebalanceSlippage.js +30 -0
  268. package/dist/generated/reflect_main/types/updateRecipients.d.ts +20 -0
  269. package/dist/generated/reflect_main/types/updateRecipients.js +29 -0
  270. package/dist/generated/reflect_main/types/yieldDistribution.d.ts +16 -0
  271. package/dist/generated/reflect_main/types/yieldDistribution.js +28 -0
  272. package/dist/generated/reflect_main/types/yieldVenue.d.ts +17 -0
  273. package/dist/generated/reflect_main/types/yieldVenue.js +29 -0
  274. package/dist/generated/reflect_main/types/yieldVenueAllocation.d.ts +25 -0
  275. package/dist/generated/reflect_main/types/yieldVenueAllocation.js +29 -0
  276. package/dist/generated/reflect_tokenised_bonds/accounts/Config.d.ts +1 -1
  277. package/dist/generated/reflect_tokenised_bonds/accounts/Vault.d.ts +1 -1
  278. package/dist/helpers/drift/accounts/spotMarket.d.ts +1 -1
  279. package/dist/helpers/drift/accounts/user.d.ts +1 -1
  280. package/dist/helpers/drift/accounts/userStats.d.ts +1 -1
  281. package/dist/index.d.ts +3 -2
  282. package/dist/index.js +6 -3
  283. package/dist/stablecoins/UsdcPlusStablecoin.d.ts +115 -70
  284. package/dist/stablecoins/UsdcPlusStablecoin.js +575 -238
  285. package/dist/stablecoins/UsdcPlusStablecoinLegacy.d.ts +97 -0
  286. package/dist/stablecoins/UsdcPlusStablecoinLegacy.js +386 -0
  287. package/dist/stablecoins/UsdtPlusStablecoin.d.ts +120 -0
  288. package/dist/stablecoins/UsdtPlusStablecoin.js +428 -0
  289. package/dist/stablecoins/index.d.ts +2 -2
  290. package/dist/stablecoins/index.js +2 -2
  291. package/dist/tsconfig.tsbuildinfo +1 -1
  292. package/dist/types/index.d.ts +6 -18
  293. package/dist/utils/getProgramAddress.d.ts +22 -0
  294. package/dist/utils/getProgramAddress.js +27 -0
  295. package/dist/utils/index.d.ts +1 -0
  296. package/dist/utils/index.js +43 -0
  297. package/package.json +8 -3
  298. package/dist/classes/ApiClient.d.ts +0 -84
  299. package/dist/classes/ApiClient.js +0 -139
  300. package/dist/constants/lst.d.ts +0 -3
  301. package/dist/constants/lst.js +0 -6
  302. package/dist/generated/reflect_main/accounts/DriftJlpController.d.ts +0 -110
  303. package/dist/generated/reflect_main/accounts/DriftJlpController.js +0 -175
  304. package/dist/generated/reflect_main/accounts/DriftLstController.d.ts +0 -104
  305. package/dist/generated/reflect_main/accounts/DriftLstController.js +0 -171
  306. package/dist/generated/reflect_main/accounts/DriftUsdcController.d.ts +0 -102
  307. package/dist/generated/reflect_main/accounts/DriftUsdcController.js +0 -168
  308. package/dist/generated/reflect_main/accounts/Main.d.ts +0 -110
  309. package/dist/generated/reflect_main/accounts/Main.js +0 -175
  310. package/dist/generated/reflect_main/accounts/PerpMarket.d.ts +0 -226
  311. package/dist/generated/reflect_main/accounts/PerpMarket.js +0 -317
  312. package/dist/generated/reflect_main/accounts/PrelaunchOracle.d.ts +0 -130
  313. package/dist/generated/reflect_main/accounts/PrelaunchOracle.js +0 -234
  314. package/dist/generated/reflect_main/accounts/PythLazerOracle.d.ts +0 -124
  315. package/dist/generated/reflect_main/accounts/PythLazerOracle.js +0 -220
  316. package/dist/generated/reflect_main/accounts/RebalanceLst.d.ts +0 -111
  317. package/dist/generated/reflect_main/accounts/RebalanceLst.js +0 -185
  318. package/dist/generated/reflect_main/accounts/SpotMarket.d.ts +0 -377
  319. package/dist/generated/reflect_main/accounts/SpotMarket.js +0 -611
  320. package/dist/generated/reflect_main/accounts/User.d.ts +0 -221
  321. package/dist/generated/reflect_main/accounts/User.js +0 -341
  322. package/dist/generated/reflect_main/accounts/UserPermissions.d.ts +0 -106
  323. package/dist/generated/reflect_main/accounts/UserPermissions.js +0 -171
  324. package/dist/generated/reflect_main/accounts/UserStats.d.ts +0 -211
  325. package/dist/generated/reflect_main/accounts/UserStats.js +0 -333
  326. package/dist/generated/reflect_main/instructions/createUserStatsAccount.d.ts +0 -52
  327. package/dist/generated/reflect_main/instructions/createUserStatsAccount.js +0 -126
  328. package/dist/generated/reflect_main/instructions/initDriftAccountsS1.d.ts +0 -54
  329. package/dist/generated/reflect_main/instructions/initDriftAccountsS1.js +0 -131
  330. package/dist/generated/reflect_main/instructions/processSwapDeposit.d.ts +0 -69
  331. package/dist/generated/reflect_main/instructions/processSwapDeposit.js +0 -165
  332. package/dist/generated/reflect_main/instructions/processSwapWithdraw.d.ts +0 -69
  333. package/dist/generated/reflect_main/instructions/processSwapWithdraw.js +0 -165
  334. package/dist/generated/reflect_main/instructions/settlePnlMulti.d.ts +0 -60
  335. package/dist/generated/reflect_main/instructions/settlePnlMulti.js +0 -118
  336. package/dist/generated/reflect_main/instructions/swapOrca.d.ts +0 -81
  337. package/dist/generated/reflect_main/instructions/swapOrca.js +0 -166
  338. package/dist/generated/reflect_main/instructions/swapOrcaTwoHop.d.ts +0 -101
  339. package/dist/generated/reflect_main/instructions/swapOrcaTwoHop.js +0 -213
  340. package/dist/generated/reflect_main/instructions/updateRebalanceSlippage.d.ts +0 -55
  341. package/dist/generated/reflect_main/instructions/updateRebalanceSlippage.js +0 -109
  342. package/dist/generated/reflect_main/types/AMM.d.ts +0 -102
  343. package/dist/generated/reflect_main/types/AMM.js +0 -137
  344. package/dist/generated/reflect_main/types/AccKey.d.ts +0 -15
  345. package/dist/generated/reflect_main/types/AccKey.js +0 -48
  346. package/dist/generated/reflect_main/types/AccessControl.d.ts +0 -18
  347. package/dist/generated/reflect_main/types/AccessControl.js +0 -53
  348. package/dist/generated/reflect_main/types/AccessMap.d.ts +0 -17
  349. package/dist/generated/reflect_main/types/AccessMap.js +0 -52
  350. package/dist/generated/reflect_main/types/Action.d.ts +0 -35
  351. package/dist/generated/reflect_main/types/Action.js +0 -72
  352. package/dist/generated/reflect_main/types/ActionMapping.d.ts +0 -19
  353. package/dist/generated/reflect_main/types/ActionMapping.js +0 -54
  354. package/dist/generated/reflect_main/types/AssetTier.d.ts +0 -23
  355. package/dist/generated/reflect_main/types/AssetTier.js +0 -60
  356. package/dist/generated/reflect_main/types/Attenuation.d.ts +0 -16
  357. package/dist/generated/reflect_main/types/Attenuation.js +0 -51
  358. package/dist/generated/reflect_main/types/AutoCompound.d.ts +0 -18
  359. package/dist/generated/reflect_main/types/AutoCompound.js +0 -53
  360. package/dist/generated/reflect_main/types/BalanceType.d.ts +0 -20
  361. package/dist/generated/reflect_main/types/BalanceType.js +0 -57
  362. package/dist/generated/reflect_main/types/Capture.d.ts +0 -19
  363. package/dist/generated/reflect_main/types/Capture.js +0 -54
  364. package/dist/generated/reflect_main/types/ContractTier.d.ts +0 -24
  365. package/dist/generated/reflect_main/types/ContractTier.js +0 -61
  366. package/dist/generated/reflect_main/types/ContractType.d.ts +0 -20
  367. package/dist/generated/reflect_main/types/ContractType.js +0 -57
  368. package/dist/generated/reflect_main/types/CorpAction.d.ts +0 -19
  369. package/dist/generated/reflect_main/types/CorpAction.js +0 -56
  370. package/dist/generated/reflect_main/types/CustodyInfo.d.ts +0 -20
  371. package/dist/generated/reflect_main/types/CustodyInfo.js +0 -55
  372. package/dist/generated/reflect_main/types/DirectionCollateral.d.ts +0 -20
  373. package/dist/generated/reflect_main/types/DirectionCollateral.js +0 -57
  374. package/dist/generated/reflect_main/types/DirectionPosition.d.ts +0 -20
  375. package/dist/generated/reflect_main/types/DirectionPosition.js +0 -57
  376. package/dist/generated/reflect_main/types/DriftControllerBase.d.ts +0 -15
  377. package/dist/generated/reflect_main/types/DriftControllerBase.js +0 -48
  378. package/dist/generated/reflect_main/types/DriftJlpControllerFixedAccounts.d.ts +0 -18
  379. package/dist/generated/reflect_main/types/DriftJlpControllerFixedAccounts.js +0 -53
  380. package/dist/generated/reflect_main/types/DriftLstData.d.ts +0 -17
  381. package/dist/generated/reflect_main/types/DriftLstData.js +0 -52
  382. package/dist/generated/reflect_main/types/Ema.d.ts +0 -17
  383. package/dist/generated/reflect_main/types/Ema.js +0 -52
  384. package/dist/generated/reflect_main/types/Externals.d.ts +0 -16
  385. package/dist/generated/reflect_main/types/Externals.js +0 -49
  386. package/dist/generated/reflect_main/types/FlowControl.d.ts +0 -17
  387. package/dist/generated/reflect_main/types/FlowControl.js +0 -52
  388. package/dist/generated/reflect_main/types/HistoricalIndexData.d.ts +0 -19
  389. package/dist/generated/reflect_main/types/HistoricalIndexData.js +0 -54
  390. package/dist/generated/reflect_main/types/HistoricalOracleData.d.ts +0 -20
  391. package/dist/generated/reflect_main/types/HistoricalOracleData.js +0 -55
  392. package/dist/generated/reflect_main/types/Holding.d.ts +0 -21
  393. package/dist/generated/reflect_main/types/Holding.js +0 -56
  394. package/dist/generated/reflect_main/types/Holdings.d.ts +0 -17
  395. package/dist/generated/reflect_main/types/Holdings.js +0 -52
  396. package/dist/generated/reflect_main/types/InsuranceClaim.d.ts +0 -19
  397. package/dist/generated/reflect_main/types/InsuranceClaim.js +0 -54
  398. package/dist/generated/reflect_main/types/InsuranceFund.d.ts +0 -24
  399. package/dist/generated/reflect_main/types/InsuranceFund.js +0 -59
  400. package/dist/generated/reflect_main/types/JlpRebalanceSettings.d.ts +0 -15
  401. package/dist/generated/reflect_main/types/JlpRebalanceSettings.js +0 -48
  402. package/dist/generated/reflect_main/types/KillSwitch.d.ts +0 -15
  403. package/dist/generated/reflect_main/types/KillSwitch.js +0 -48
  404. package/dist/generated/reflect_main/types/LevelRoles.d.ts +0 -16
  405. package/dist/generated/reflect_main/types/LevelRoles.js +0 -49
  406. package/dist/generated/reflect_main/types/MarketStatus.d.ts +0 -27
  407. package/dist/generated/reflect_main/types/MarketStatus.js +0 -64
  408. package/dist/generated/reflect_main/types/MarketType.d.ts +0 -20
  409. package/dist/generated/reflect_main/types/MarketType.js +0 -57
  410. package/dist/generated/reflect_main/types/ModifyOrderParams.d.ts +0 -32
  411. package/dist/generated/reflect_main/types/ModifyOrderParams.js +0 -67
  412. package/dist/generated/reflect_main/types/ModifyOrderPolicy.d.ts +0 -20
  413. package/dist/generated/reflect_main/types/ModifyOrderPolicy.js +0 -57
  414. package/dist/generated/reflect_main/types/Movements.d.ts +0 -19
  415. package/dist/generated/reflect_main/types/Movements.js +0 -54
  416. package/dist/generated/reflect_main/types/OracleGuardRails.d.ts +0 -18
  417. package/dist/generated/reflect_main/types/OracleGuardRails.js +0 -53
  418. package/dist/generated/reflect_main/types/OracleSource.d.ts +0 -34
  419. package/dist/generated/reflect_main/types/OracleSource.js +0 -71
  420. package/dist/generated/reflect_main/types/OracleValidity.d.ts +0 -25
  421. package/dist/generated/reflect_main/types/OracleValidity.js +0 -62
  422. package/dist/generated/reflect_main/types/Order.d.ts +0 -43
  423. package/dist/generated/reflect_main/types/Order.js +0 -78
  424. package/dist/generated/reflect_main/types/OrderDirection.d.ts +0 -20
  425. package/dist/generated/reflect_main/types/OrderDirection.js +0 -57
  426. package/dist/generated/reflect_main/types/OrderParams.d.ts +0 -36
  427. package/dist/generated/reflect_main/types/OrderParams.js +0 -71
  428. package/dist/generated/reflect_main/types/OrderStatus.d.ts +0 -22
  429. package/dist/generated/reflect_main/types/OrderStatus.js +0 -59
  430. package/dist/generated/reflect_main/types/OrderTriggerCondition.d.ts +0 -22
  431. package/dist/generated/reflect_main/types/OrderTriggerCondition.js +0 -59
  432. package/dist/generated/reflect_main/types/OrderType.d.ts +0 -23
  433. package/dist/generated/reflect_main/types/OrderType.js +0 -60
  434. package/dist/generated/reflect_main/types/PermissionLevel.d.ts +0 -45
  435. package/dist/generated/reflect_main/types/PermissionLevel.js +0 -58
  436. package/dist/generated/reflect_main/types/PerpHedge.d.ts +0 -17
  437. package/dist/generated/reflect_main/types/PerpHedge.js +0 -52
  438. package/dist/generated/reflect_main/types/PerpPosition.d.ts +0 -29
  439. package/dist/generated/reflect_main/types/PerpPosition.js +0 -64
  440. package/dist/generated/reflect_main/types/PoolBalance.d.ts +0 -17
  441. package/dist/generated/reflect_main/types/PoolBalance.js +0 -52
  442. package/dist/generated/reflect_main/types/Position.d.ts +0 -20
  443. package/dist/generated/reflect_main/types/Position.js +0 -55
  444. package/dist/generated/reflect_main/types/PositionDirection.d.ts +0 -20
  445. package/dist/generated/reflect_main/types/PositionDirection.js +0 -57
  446. package/dist/generated/reflect_main/types/PositionDrift.d.ts +0 -18
  447. package/dist/generated/reflect_main/types/PositionDrift.js +0 -53
  448. package/dist/generated/reflect_main/types/PostOnlyParam.d.ts +0 -22
  449. package/dist/generated/reflect_main/types/PostOnlyParam.js +0 -59
  450. package/dist/generated/reflect_main/types/Price.d.ts +0 -41
  451. package/dist/generated/reflect_main/types/Price.js +0 -76
  452. package/dist/generated/reflect_main/types/PriceComp.d.ts +0 -19
  453. package/dist/generated/reflect_main/types/PriceComp.js +0 -54
  454. package/dist/generated/reflect_main/types/PriceDivergenceGuardRails.d.ts +0 -16
  455. package/dist/generated/reflect_main/types/PriceDivergenceGuardRails.js +0 -51
  456. package/dist/generated/reflect_main/types/PriceInfo.d.ts +0 -21
  457. package/dist/generated/reflect_main/types/PriceInfo.js +0 -56
  458. package/dist/generated/reflect_main/types/PriceStatus.d.ts +0 -22
  459. package/dist/generated/reflect_main/types/PriceStatus.js +0 -59
  460. package/dist/generated/reflect_main/types/PriceType.d.ts +0 -20
  461. package/dist/generated/reflect_main/types/PriceType.js +0 -57
  462. package/dist/generated/reflect_main/types/Program.d.ts +0 -19
  463. package/dist/generated/reflect_main/types/Program.js +0 -54
  464. package/dist/generated/reflect_main/types/ProgramStatus.d.ts +0 -20
  465. package/dist/generated/reflect_main/types/ProgramStatus.js +0 -57
  466. package/dist/generated/reflect_main/types/Recipient.d.ts +0 -17
  467. package/dist/generated/reflect_main/types/Recipient.js +0 -52
  468. package/dist/generated/reflect_main/types/Recipients.d.ts +0 -17
  469. package/dist/generated/reflect_main/types/Recipients.js +0 -52
  470. package/dist/generated/reflect_main/types/Role.d.ts +0 -25
  471. package/dist/generated/reflect_main/types/Role.js +0 -62
  472. package/dist/generated/reflect_main/types/ShiftCollateral.d.ts +0 -19
  473. package/dist/generated/reflect_main/types/ShiftCollateral.js +0 -54
  474. package/dist/generated/reflect_main/types/ShiftPosition.d.ts +0 -17
  475. package/dist/generated/reflect_main/types/ShiftPosition.js +0 -52
  476. package/dist/generated/reflect_main/types/ShortHolding.d.ts +0 -17
  477. package/dist/generated/reflect_main/types/ShortHolding.js +0 -52
  478. package/dist/generated/reflect_main/types/SplBase.d.ts +0 -17
  479. package/dist/generated/reflect_main/types/SplBase.js +0 -52
  480. package/dist/generated/reflect_main/types/SplMain.d.ts +0 -22
  481. package/dist/generated/reflect_main/types/SplMain.js +0 -57
  482. package/dist/generated/reflect_main/types/Spls.d.ts +0 -17
  483. package/dist/generated/reflect_main/types/Spls.js +0 -52
  484. package/dist/generated/reflect_main/types/SpotBalanceType.d.ts +0 -20
  485. package/dist/generated/reflect_main/types/SpotBalanceType.js +0 -57
  486. package/dist/generated/reflect_main/types/SpotPosition.d.ts +0 -23
  487. package/dist/generated/reflect_main/types/SpotPosition.js +0 -58
  488. package/dist/generated/reflect_main/types/Status.d.ts +0 -21
  489. package/dist/generated/reflect_main/types/Status.js +0 -58
  490. package/dist/generated/reflect_main/types/Strategy.d.ts +0 -33
  491. package/dist/generated/reflect_main/types/Strategy.js +0 -68
  492. package/dist/generated/reflect_main/types/StrategyPadding.d.ts +0 -15
  493. package/dist/generated/reflect_main/types/StrategyPadding.js +0 -48
  494. package/dist/generated/reflect_main/types/StrategyRoleEntry.d.ts +0 -17
  495. package/dist/generated/reflect_main/types/StrategyRoleEntry.js +0 -52
  496. package/dist/generated/reflect_main/types/SubAccount.d.ts +0 -17
  497. package/dist/generated/reflect_main/types/SubAccount.js +0 -52
  498. package/dist/generated/reflect_main/types/Update.d.ts +0 -20
  499. package/dist/generated/reflect_main/types/Update.js +0 -57
  500. package/dist/generated/reflect_main/types/UserFees.d.ts +0 -20
  501. package/dist/generated/reflect_main/types/UserFees.js +0 -55
  502. package/dist/generated/reflect_main/types/ValidityGuardRails.d.ts +0 -18
  503. package/dist/generated/reflect_main/types/ValidityGuardRails.js +0 -53
  504. package/dist/generated/reflect_main/types/YieldDistribution.d.ts +0 -20
  505. package/dist/generated/reflect_main/types/YieldDistribution.js +0 -57
  506. package/dist/helpers/getOrcaQuote.d.ts +0 -3
  507. package/dist/helpers/getOrcaQuote.js +0 -27
  508. package/dist/stablecoins/LstStablecoin.d.ts +0 -108
  509. package/dist/stablecoins/LstStablecoin.js +0 -354
  510. package/dist/stablecoins/UsdjStablecoin.d.ts +0 -1
  511. package/dist/stablecoins/UsdjStablecoin.js +0 -44
  512. package/dist/types/api.d.ts +0 -1384
  513. package/dist/types/api.js +0 -6
@@ -14,242 +14,374 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.UsdcPlusStablecoin = void 0;
16
16
  const Stablecoin_1 = require("../classes/Stablecoin");
17
- const web3_js_1 = require("@solana/web3.js");
17
+ const kit_1 = require("@solana/kit");
18
18
  const classes_1 = require("../classes");
19
19
  const constants_1 = require("../constants");
20
20
  const reflect_main_1 = require("../generated/reflect_main");
21
+ const accounts_1 = require("../generated/reflect_main/accounts");
22
+ const types_1 = require("../generated/reflect_main/types");
21
23
  const drift_1 = require("../helpers/drift");
22
24
  const sdk_1 = require("@drift-labs/sdk");
23
25
  const bn_js_1 = __importDefault(require("bn.js"));
24
26
  const constants_2 = require("../constants");
25
- const spl_token_1 = require("@solana/spl-token");
26
- const constants_3 = require("../constants");
27
- const kit_1 = require("@solana/kit");
27
+ const web3_js_1 = require("@solana/web3.js");
28
+ const token_1 = require("@solana-program/token");
29
+ // Constants from rack.rs for component data access
30
+ const DISCRIMINATOR_SIZE = 8;
31
+ const STRATEGY_SIZE = 1018;
32
+ const MAX_COMPONENTS = 8;
33
+ const COMPONENT_META_SIZE = 6; // 1 + 2 + 2 + 1
34
+ const RACK_REGISTRY_SIZE = MAX_COMPONENTS * COMPONENT_META_SIZE; // 48
35
+ const RACK_OFFSET = DISCRIMINATOR_SIZE + STRATEGY_SIZE; // 1026
36
+ const RACK_DATA_OFFSET = RACK_OFFSET + RACK_REGISTRY_SIZE; // 1074
37
+ // ComponentType enum values
38
+ const COMPONENT_TYPE_AUTO_COMPOUND = 1;
28
39
  /**
29
40
  * USDC+ Stablecoin implementation for the Reflect protocol.
30
41
  * Extends the base Stablecoin class to provide USDC-specific functionality
31
42
  * including initialization, minting, redemption, and rebalancing operations.
43
+ *
44
+ * Strategy ID: 0
45
+ * Collateral: USDC
46
+ *
47
+ * This class uses the post-migration StrategyController account type which
48
+ * stores data in a rack component system.
49
+ *
50
+ * Environment handling:
51
+ * - devnet=true → Uses devnet program
52
+ * - devnet=false, mock=true → Uses mock program on mainnet
53
+ * - devnet=false, mock=false → Uses production mainnet program
32
54
  */
33
55
  class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
34
56
  /**
35
57
  * Creates a new USDC+ Stablecoin instance.
36
58
  *
37
- * @param connection - Solana connection instance for RPC communication
59
+ * @param rpc - Solana RPC instance
38
60
  * @param stablecoinMintOverride - Optional override for the stablecoin mint address
61
+ * @param devnet - Whether to use devnet program
62
+ * @param mock - Whether to use mock program on mainnet (only applies when devnet=false)
39
63
  */
40
- constructor(connection, stablecoinMintOverride, devnet) {
41
- super(0, "USD Coin Plus", connection, devnet ? constants_3.USDC_PLUS_LOOKUP_TABLE_DEVNET : constants_2.USDC_PLUS_LOOKUP_TABLE, devnet);
42
- this.rpc = (0, kit_1.createSolanaRpc)(connection.rpcEndpoint);
64
+ constructor(rpc, stablecoinMintOverride, devnet = false, mock = false) {
65
+ super(0, "USD Coin Plus", rpc, devnet ? constants_2.USDC_PLUS_LOOKUP_TABLE_DEVNET : constants_2.USDC_PLUS_LOOKUP_TABLE, devnet, mock);
43
66
  this.collaterals = [
44
67
  {
45
- mint: devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT,
68
+ mint: devnet ? constants_1.USDC_MINT_DEVNET : constants_1.USDC_MINT,
46
69
  oracle: "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
47
70
  decimals: 6,
48
71
  },
49
72
  ];
50
73
  this.isPermissioned = true;
51
- this.devnet = devnet;
52
- // Otherwise has to be loaded first.
53
- if (stablecoinMintOverride)
74
+ if (stablecoinMintOverride) {
54
75
  this.stablecoinMint = stablecoinMintOverride;
76
+ }
55
77
  }
78
+ // programAddress getter is inherited from Stablecoin base class
56
79
  /**
57
80
  * Loads the USDC+ controller data from the blockchain.
58
81
  * Updates the stablecoin mint and strategy information.
82
+ *
83
+ * This method fetches the StrategyController account and extracts:
84
+ * - Base strategy data (mint, bump, cap, etc.)
85
+ * - AutoCompound component from the rack system
59
86
  */
60
87
  load() {
61
88
  return __awaiter(this, void 0, void 0, function* () {
62
- const controller = yield reflect_main_1.DriftUsdcController.fromAccountAddress(this.connection, this.controllerKey);
63
- const { baseStrategy } = controller;
64
- this.stablecoinMint = baseStrategy.mint;
65
- this.strategy = baseStrategy;
66
- this.controller = controller;
67
- yield this.loadMint();
89
+ if (!this.controllerKey)
90
+ yield this.initializeKeys();
91
+ // Fetch the encoded account to get raw bytes
92
+ const encodedAccount = yield (0, kit_1.fetchEncodedAccount)(this.rpc, this.controllerKey);
93
+ if (!encodedAccount.exists) {
94
+ throw new Error(`Controller account not found at ${this.controllerKey}`);
95
+ }
96
+ const data = encodedAccount.data;
97
+ // Decode the StrategyController (discriminator + base + rack registry)
98
+ const strategyControllerAccount = yield (0, accounts_1.fetchStrategyController)(this.rpc, this.controllerKey);
99
+ this.controller = strategyControllerAccount.data;
100
+ // Extract AutoCompound component from rack if present
101
+ let autoCompound;
102
+ const rack = this.controller.rack;
103
+ // Find AutoCompound component in the rack registry
104
+ for (const component of rack.registry) {
105
+ // ComponentType.AutoCompound = 1
106
+ if (component.componentType === COMPONENT_TYPE_AUTO_COMPOUND) {
107
+ // Read the component data from the account buffer
108
+ const absoluteOffset = RACK_DATA_OFFSET + component.offset;
109
+ const componentData = data.slice(absoluteOffset, absoluteOffset + component.size);
110
+ // Decode the AutoCompound component
111
+ let slice = componentData;
112
+ autoCompound = (0, types_1.getAutoCompoundDecoder)().decode(slice);
113
+ break;
114
+ }
115
+ }
116
+ this.autoCompound = autoCompound;
117
+ this.stablecoinMint = this.controller.base.mint;
118
+ });
119
+ }
120
+ /**
121
+ * Helper to get associated token address
122
+ */
123
+ getAta(mint, owner) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ const [ata] = yield (0, token_1.findAssociatedTokenPda)({
126
+ mint,
127
+ owner,
128
+ tokenProgram: token_1.TOKEN_PROGRAM_ADDRESS,
129
+ });
130
+ return ata;
68
131
  });
69
132
  }
70
133
  /**
71
134
  * Initializes the USDC stablecoin with the specified parameters.
72
- * Creates receipt tokens, initializes vault, and initializes the stablecoin.
73
135
  *
74
- * @param signer - Public key of the signer/initializer
75
- * @param mint - Public key of the mint to be used for the stablecoin
76
- * @param cap - Maximum supply cap as a BN (Big Number)
77
- * @param recipientAddresses - Array of recipient public keys for fee distribution
78
- * @param recipientCuts - Array of fee cuts (percentages) corresponding to each recipient
79
- * @returns Promise resolving to an array of TransactionInstruction objects
136
+ * @param admin - TransactionSigner of the initializer
137
+ * @param mint - Address of the mint to be used for the stablecoin
138
+ * @param cap - Maximum supply cap
139
+ * @param recipientAddresses - Array of recipient addresses for fee distribution
140
+ * @param recipientCuts - Array of recipient cuts (u16 values, total must equal 10000)
141
+ * @returns Promise resolving to an array of Instructions
80
142
  */
81
- initialize(signer, mint, cap, recipientAddresses, recipientCuts) {
143
+ initialize(admin, mint, cap, recipientAddresses, recipientCuts) {
82
144
  return __awaiter(this, void 0, void 0, function* () {
83
- const ix = (0, reflect_main_1.createInitDriftControllerS1Instruction)({
84
- admin: signer,
85
- adminPermissions: classes_1.PdaClient.derivePermissions(signer, this.devnet),
86
- main: classes_1.PdaClient.deriveMain(this.devnet),
145
+ if (!this.controllerKey)
146
+ yield this.initializeKeys();
147
+ const main = yield classes_1.PdaClient.deriveMain(this.devnet, this.mock);
148
+ const adminPermissions = yield classes_1.PdaClient.derivePermissions(admin.address, this.devnet, this.mock);
149
+ const ix = (0, reflect_main_1.getInitDriftControllerS1Instruction)({
150
+ admin,
151
+ adminPermissions,
152
+ main,
87
153
  driftUsdcController: this.controllerKey,
88
- systemProgram: web3_js_1.SystemProgram.programId,
89
- anchorRemainingAccounts: [
90
- {
91
- isSigner: false,
92
- isWritable: false,
93
- pubkey: this.devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT,
94
- },
95
- ],
96
- }, {
97
154
  mint,
98
155
  cap,
99
156
  recipientAddresses,
100
157
  recipientCuts,
101
- }, this.programId);
158
+ }, { programAddress: this.programAddress });
102
159
  return [ix];
103
160
  });
104
161
  }
105
162
  /**
106
- * Initializes the stablecoin drift account for the USDC+ controller.
163
+ * Creates a mint instruction for the USDC+ stablecoin.
107
164
  *
108
- * @param signer - Public key of the signer/initializer
109
- * @returns Promise resolving to a TransactionInstruction
165
+ * @param user - TransactionSigner of the user
166
+ * @param amount - Amount of USDC to deposit
167
+ * @param minimumReceived - Minimum amount of USDC+ stablecoins to receive
168
+ * @returns Promise resolving to an array of Instructions
110
169
  */
111
- initializeStablecoinDriftAccount(signer) {
170
+ mint(user, amount, minimumReceived) {
112
171
  return __awaiter(this, void 0, void 0, function* () {
113
- const anchorRemainingAccounts = [constants_1.REFERRAL_USER, constants_1.REFERRAL_USER_STATS].map((account) => ({
114
- isSigner: false,
115
- isWritable: true,
116
- pubkey: account,
117
- }));
118
- const ix = (0, reflect_main_1.createInitDriftAccountsS1Instruction)({
119
- admin: signer,
120
- adminPermissions: classes_1.PdaClient.derivePermissions(signer, this.devnet),
121
- main: classes_1.PdaClient.deriveMain(this.devnet),
122
- usdcController: this.controllerKey,
123
- systemProgram: web3_js_1.SystemProgram.programId,
124
- drift: constants_1.DRIFT_PROGRAM_ID,
125
- state: yield (0, sdk_1.getDriftStateAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID),
126
- userAccount: (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey),
127
- userStats: (0, sdk_1.getUserStatsAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey),
128
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
129
- anchorRemainingAccounts,
130
- }, this.programId);
131
- return ix;
132
- });
133
- }
134
- /**
135
- * Constructs the required accounts for the InitDriftControllerS1 instruction.
136
- *
137
- * @param signer - Public key of the signer
138
- * @returns Promise resolving to the constructed accounts object of type T
139
- */
140
- constructAccounts(signer_1) {
141
- return __awaiter(this, arguments, void 0, function* (signer, permissions = this.isPermissioned) {
142
- const userAccount = (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey);
143
- const userStats = (0, sdk_1.getUserStatsAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey);
144
- const anchorRemainingAccounts = yield this.constructRemainingAccounts();
145
- const { data: userStatsData } = yield (0, drift_1.fetchUserStats)(this.rpc, (0, kit_1.address)(this.controllerKey.toString()));
146
- const referrerUser = (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, new web3_js_1.PublicKey(userStatsData.referrer.toString()));
147
- const referrerUserStats = (0, sdk_1.getUserStatsAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID, new web3_js_1.PublicKey(userStatsData.referrer.toString()));
148
- const userUsdcAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT, signer, true);
149
- const userReceiptAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.stablecoinMint, signer, true);
150
- const controllerUsdcAta = (0, spl_token_1.getAssociatedTokenAddressSync)(this.devnet ? constants_3.USDC_MINT_DEVNET : constants_1.USDC_MINT, this.controllerKey, true);
151
- const spotMarketVault = yield (0, sdk_1.getSpotMarketVaultPublicKey)(constants_1.DRIFT_PROGRAM_ID, 0);
152
- const driftState = yield (0, sdk_1.getDriftStateAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID);
153
- const accounts = {
154
- clock: web3_js_1.SYSVAR_CLOCK_PUBKEY,
155
- controllerUsdcAta,
156
- drift: constants_1.DRIFT_PROGRAM_ID,
157
- driftVault: constants_1.DRIFT_VAULT,
158
- main: classes_1.PdaClient.deriveMain(this.devnet),
172
+ if (!this.controllerKey)
173
+ yield this.initializeKeys();
174
+ if (!this.stablecoinMint)
175
+ throw new Error("Stablecoin mint not loaded. Call load() first.");
176
+ const main = yield classes_1.PdaClient.deriveMain(this.devnet, this.mock);
177
+ const adminPermissions = yield classes_1.PdaClient.derivePermissions(user.address, this.devnet, this.mock);
178
+ const usdcMint = this.devnet ? constants_1.USDC_MINT_DEVNET : constants_1.USDC_MINT;
179
+ const userEarnAta = yield this.getAta(usdcMint, user.address);
180
+ const userReceiptAta = yield this.getAta(this.stablecoinMint, user.address);
181
+ const strategyControllerEarnTokenAccount = yield this.getAta(usdcMint, this.controllerKey);
182
+ // Derive Kamino accounts for remaining accounts
183
+ const kaminoObligation = yield this.deriveKaminoObligation(constants_1.KAMINO_LENDING_MARKET);
184
+ const lendingMarketAuthority = yield this.deriveKaminoLendingMarketAuthority(constants_1.KAMINO_LENDING_MARKET);
185
+ const userMetadata = yield this.deriveKaminoUserMetadata();
186
+ // Get Kamino constants based on mock mode
187
+ const reserveCollateralMint = this.mock
188
+ ? constants_1.KAMINO_USDC_RESERVE_COLLATERAL_MINT_MOCK
189
+ : constants_1.KAMINO_USDC_RESERVE_COLLATERAL_MINT;
190
+ const reserveCollateralSupplyVault = this.mock
191
+ ? constants_1.KAMINO_USDC_RESERVE_COLLATERAL_MOCK
192
+ : constants_1.KAMINO_USDC_RESERVE_COLLATERAL;
193
+ const reserveFarmState = this.mock
194
+ ? constants_1.KAMINO_USDC_RESERVE_FARM_STATE_MOCK
195
+ : constants_1.KAMINO_USDC_RESERVE_FARM_STATE;
196
+ // Derive obligation farm state
197
+ const obligationFarmState = yield this.deriveKaminoObligationFarmState(reserveFarmState, kaminoObligation);
198
+ // Derive Drift user account and user stats account for the controller
199
+ const controllerPubkey = new web3_js_1.PublicKey(this.controllerKey);
200
+ const driftProgramPubkey = new web3_js_1.PublicKey(constants_1.DRIFT_PROGRAM_ID);
201
+ const driftUserAccount = (0, sdk_1.getUserAccountPublicKeySync)(driftProgramPubkey, controllerPubkey, 0);
202
+ const driftUserStatsAccount = (0, sdk_1.getUserStatsAccountPublicKey)(driftProgramPubkey, controllerPubkey);
203
+ const ix = (0, reflect_main_1.getMintStrategy1Instruction)({
204
+ user,
205
+ adminPermissions,
206
+ main,
207
+ strategyController: this.controllerKey,
159
208
  receiptMint: this.stablecoinMint,
160
- referrerUser,
161
- referrerUserStats,
162
- spotMarketVault,
163
- state: driftState,
164
- usdcController: this.controllerKey,
165
- user: signer,
166
- userAccount,
167
209
  userReceiptAta,
168
- userStats,
169
- userUsdcAta,
170
- adminPermissions: permissions
171
- ? classes_1.PdaClient.derivePermissions(signer, this.devnet)
172
- : null,
173
- anchorRemainingAccounts,
174
- systemProgram: web3_js_1.SystemProgram.programId,
175
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
176
- };
177
- return accounts;
178
- });
179
- }
180
- /**
181
- * Constructs remaining accounts for transactions.
182
- * Currently returns an empty array as no additional accounts are needed.
183
- *
184
- * @returns Promise resolving to an empty array of AccountMeta objects
185
- */
186
- constructRemainingAccounts() {
187
- return __awaiter(this, void 0, void 0, function* () {
188
- const { oracle, marketIndex } = sdk_1.SpotMarkets["mainnet-beta"][0];
189
- const spotMarket = (0, sdk_1.getSpotMarketPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, marketIndex);
190
- return [
191
- {
192
- pubkey: oracle,
193
- isSigner: false,
194
- isWritable: true,
195
- },
196
- {
197
- pubkey: spotMarket,
198
- isSigner: false,
199
- isWritable: true,
200
- },
210
+ userEarnAta,
211
+ strategyControllerEarnTokenAccount,
212
+ associatedTokenProgram: token_1.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
213
+ usdcDepositAmount: BigInt(amount),
214
+ minReceiptReceive: BigInt(minimumReceived),
215
+ }, { programAddress: this.programAddress });
216
+ // Get controller's Jupiter fToken ATA
217
+ const controllerJupiterFTokenAccount = yield this.getAta(constants_1.JUPITER_USDC_F_TOKEN_MINT, this.controllerKey);
218
+ // Add Drift, Kamino, and Jupiter remaining accounts
219
+ // Role: 0 = READONLY, 1 = WRITABLE
220
+ // The program searches for accounts by pubkey, so order doesn't matter
221
+ const remainingAccounts = [
222
+ // Drift supply accounts (all 10 required by DriftUsdcSupplyAccounts::from_remaining)
223
+ { address: constants_1.DRIFT_STATE, role: 1 }, // drift_state (writable for CPI)
224
+ { address: (0, kit_1.address)(driftUserAccount.toBase58()), role: 1 }, // reflect_user_account
225
+ { address: (0, kit_1.address)(driftUserStatsAccount.toBase58()), role: 1 }, // reflect_user_stats_account
226
+ { address: constants_1.USDC_SPOT_MARKET, role: 1 }, // usdc_spot_market
227
+ { address: constants_1.USDC_SPOT_MARKET_VAULT, role: 1 }, // usdc_spot_market_vault
228
+ { address: constants_1.USDC_LAZER_ORACLE, role: 1 }, // usdc_oracle (writable for CPI)
229
+ { address: constants_1.REFERRAL_USER_STATS, role: 1 }, // referrer_user_stats
230
+ { address: constants_1.REFERRAL_USER, role: 1 }, // referrer_user
231
+ { address: constants_1.DRIFT_VAULT, role: 1 }, // drift_vault
232
+ { address: constants_1.DRIFT_PROGRAM_ID, role: 0 }, // drift_program
233
+ // Jupiter supply accounts (all 15 required by JupiterSupplyAccounts::from_remaining)
234
+ { address: constants_1.JUPITER_LENDING_ADMIN, role: 1 }, // lending_admin
235
+ { address: constants_1.JUPITER_USDC_LENDING, role: 1 }, // lending
236
+ { address: constants_1.JUPITER_USDC_SUPPLY_TOKEN_RESERVES_LIQUIDITY, role: 1 }, // supply_token_reserves_liquidity
237
+ { address: constants_1.JUPITER_USDC_LENDING_SUPPLY_POSITION, role: 1 }, // lending_supply_position_on_liquidity
238
+ { address: constants_1.JUPITER_USDC_RATE_MODEL, role: 0 }, // rate_model
239
+ { address: constants_1.JUPITER_USDC_VAULT, role: 1 }, // vault
240
+ { address: constants_1.JUPITER_USDC_CLAIM_ACCOUNT, role: 1 }, // claim_account
241
+ { address: constants_1.JUPITER_LIQUIDITY_OWNER, role: 1 }, // liquidity_owner (writable for CPI)
242
+ { address: constants_1.JUPITER_USDC_REWARDS_RATE_MODEL, role: 0 }, // rewards_rate_model
243
+ { address: usdcMint, role: 0 }, // earn_mint (shared with Kamino)
244
+ { address: constants_1.JUPITER_USDC_F_TOKEN_MINT, role: 1 }, // f_token_mint
245
+ { address: strategyControllerEarnTokenAccount, role: 1 }, // controller_earn_account (shared)
246
+ { address: controllerJupiterFTokenAccount, role: 1 }, // controller_f_token_account
247
+ { address: constants_1.JUPITER_LENDING_PROGRAM_ID, role: 0 }, // lending_program
248
+ { address: constants_1.JUPITER_LIQUIDITY_PROGRAM_ID, role: 1 }, // liquidity_program (writable for CPI)
249
+ // Kamino supply accounts (all 15 required by KaminoSupplyAccounts::from_remaining)
250
+ { address: constants_1.KAMINO_USDC_RESERVE, role: 1 }, // reserve
251
+ { address: constants_1.KAMINO_LENDING_MARKET, role: 0 }, // lending_market
252
+ { address: lendingMarketAuthority, role: 0 }, // lending_market_authority
253
+ { address: constants_1.KAMINO_USDC_RESERVE_LIQUIDITY_SUPPLY, role: 1 }, // reserve_liquidity_supply
254
+ { address: reserveCollateralMint, role: 1 }, // reserve_collateral_mint
255
+ { address: reserveCollateralSupplyVault, role: 1 }, // collateral_supply_vault
256
+ { address: userMetadata, role: 1 }, // user_metadata
257
+ { address: kaminoObligation, role: 1 }, // obligation
258
+ { address: constants_1.KAMINO_SCOPE_ORACLE, role: 0 }, // scope_oracle
259
+ { address: obligationFarmState, role: 1 }, // obligation_farm_state
260
+ { address: reserveFarmState, role: 1 }, // reserve_farm_state
261
+ { address: constants_1.KLEND_PROGRAM_ID, role: 0 }, // klend_program
262
+ { address: constants_1.FARMS_PROGRAM_ID, role: 0 }, // farms_program
201
263
  ];
202
- });
203
- }
204
- /**
205
- * Creates a mint instruction for the USDC+ stablecoin.
206
- *
207
- * @param signer - Public key of the signer
208
- * @param amount - Amount of USDC to deposit
209
- * @param minimumReceived - Minimum amount of USDC+ stablecoins to receive (slippage protection)
210
- * @returns Promise resolving to an array containing a single TransactionInstruction
211
- */
212
- mint(signer, amount, minimumReceived) {
213
- return __awaiter(this, void 0, void 0, function* () {
214
- const accounts = yield this.constructAccounts(signer, true);
215
- const ix = (0, reflect_main_1.createMintDriftS1Instruction)(accounts, {
216
- minUsdcAmount: minimumReceived,
217
- usdcAmount: amount,
218
- }, this.programId);
219
- return [ix];
264
+ // Create new instruction with remaining accounts
265
+ const ixWithRemainingAccounts = Object.assign(Object.assign({}, ix), { accounts: [...ix.accounts, ...remainingAccounts] });
266
+ return [ixWithRemainingAccounts];
220
267
  });
221
268
  }
222
269
  /**
223
270
  * Creates a redeem instruction for the USDC stablecoin.
224
- * Currently returns a placeholder instruction - implementation needed.
225
271
  *
226
- * @returns Promise resolving to an array containing a single TransactionInstruction
272
+ * @param user - TransactionSigner of the user
273
+ * @param amount - Amount of USDC+ to redeem
274
+ * @param minimumReceived - Minimum amount of USDC to receive
275
+ * @returns Promise resolving to an array of Instructions
227
276
  */
228
- redeem(signer, amount, minimumReceived) {
277
+ redeem(user, amount, minimumReceived) {
229
278
  return __awaiter(this, void 0, void 0, function* () {
230
- const accounts = yield this.constructAccounts(signer, true);
231
- const ix = (0, reflect_main_1.createRedeemDriftS1Instruction)(accounts, {
232
- canChill: false,
233
- minLstRedeem: minimumReceived,
234
- rusdBurnAmount: amount,
235
- }, this.programId);
236
- return [ix];
279
+ if (!this.controllerKey)
280
+ yield this.initializeKeys();
281
+ if (!this.stablecoinMint)
282
+ throw new Error("Stablecoin mint not loaded. Call load() first.");
283
+ const main = yield classes_1.PdaClient.deriveMain(this.devnet, this.mock);
284
+ const adminPermissions = yield classes_1.PdaClient.derivePermissions(user.address, this.devnet, this.mock);
285
+ const usdcMint = this.devnet ? constants_1.USDC_MINT_DEVNET : constants_1.USDC_MINT;
286
+ const userEarnAta = yield this.getAta(usdcMint, user.address);
287
+ const userReceiptAta = yield this.getAta(this.stablecoinMint, user.address);
288
+ const strategyControllerEarnTokenAccount = yield this.getAta(usdcMint, this.controllerKey);
289
+ // Derive Kamino accounts for remaining accounts
290
+ const kaminoObligation = yield this.deriveKaminoObligation(constants_1.KAMINO_LENDING_MARKET);
291
+ const lendingMarketAuthority = yield this.deriveKaminoLendingMarketAuthority(constants_1.KAMINO_LENDING_MARKET);
292
+ const userMetadata = yield this.deriveKaminoUserMetadata();
293
+ // Get Kamino constants based on mock mode
294
+ const reserveCollateralMint = this.mock
295
+ ? constants_1.KAMINO_USDC_RESERVE_COLLATERAL_MINT_MOCK
296
+ : constants_1.KAMINO_USDC_RESERVE_COLLATERAL_MINT;
297
+ const reserveCollateralSupplyVault = this.mock
298
+ ? constants_1.KAMINO_USDC_RESERVE_COLLATERAL_MOCK
299
+ : constants_1.KAMINO_USDC_RESERVE_COLLATERAL;
300
+ const reserveFarmState = this.mock
301
+ ? constants_1.KAMINO_USDC_RESERVE_FARM_STATE_MOCK
302
+ : constants_1.KAMINO_USDC_RESERVE_FARM_STATE;
303
+ // Derive obligation farm state
304
+ const obligationFarmState = yield this.deriveKaminoObligationFarmState(reserveFarmState, kaminoObligation);
305
+ // Derive Drift user account and user stats account for the controller
306
+ const controllerPubkey = new web3_js_1.PublicKey(this.controllerKey);
307
+ const driftProgramPubkey = new web3_js_1.PublicKey(constants_1.DRIFT_PROGRAM_ID);
308
+ const driftUserAccount = (0, sdk_1.getUserAccountPublicKeySync)(driftProgramPubkey, controllerPubkey, 0);
309
+ const driftUserStatsAccount = (0, sdk_1.getUserStatsAccountPublicKey)(driftProgramPubkey, controllerPubkey);
310
+ const ix = (0, reflect_main_1.getRedeemStrategy1Instruction)({
311
+ user,
312
+ adminPermissions,
313
+ main,
314
+ strategyController: this.controllerKey,
315
+ receiptMint: this.stablecoinMint,
316
+ userReceiptAta,
317
+ userEarnAta,
318
+ strategyControllerEarnTokenAccount,
319
+ associatedTokenProgram: token_1.ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
320
+ receiptBurnAmount: BigInt(amount),
321
+ minLstRedeem: BigInt(minimumReceived),
322
+ }, { programAddress: this.programAddress });
323
+ // Get controller's Jupiter fToken ATA
324
+ const controllerJupiterFTokenAccount = yield this.getAta(constants_1.JUPITER_USDC_F_TOKEN_MINT, this.controllerKey);
325
+ // Add Drift, Kamino, and Jupiter remaining accounts
326
+ // Role: 0 = READONLY, 1 = WRITABLE
327
+ // The program searches for accounts by pubkey, so order doesn't matter
328
+ const remainingAccounts = [
329
+ // Drift supply accounts (all 10 required by DriftUsdcSupplyAccounts::from_remaining)
330
+ { address: constants_1.DRIFT_STATE, role: 1 }, // drift_state (writable for CPI)
331
+ { address: (0, kit_1.address)(driftUserAccount.toBase58()), role: 1 }, // reflect_user_account
332
+ { address: (0, kit_1.address)(driftUserStatsAccount.toBase58()), role: 1 }, // reflect_user_stats_account
333
+ { address: constants_1.USDC_SPOT_MARKET, role: 1 }, // usdc_spot_market
334
+ { address: constants_1.USDC_SPOT_MARKET_VAULT, role: 1 }, // usdc_spot_market_vault
335
+ { address: constants_1.USDC_LAZER_ORACLE, role: 1 }, // usdc_oracle (writable for CPI)
336
+ { address: constants_1.REFERRAL_USER_STATS, role: 1 }, // referrer_user_stats
337
+ { address: constants_1.REFERRAL_USER, role: 1 }, // referrer_user
338
+ { address: constants_1.DRIFT_VAULT, role: 1 }, // drift_vault
339
+ { address: constants_1.DRIFT_PROGRAM_ID, role: 0 }, // drift_program
340
+ // Jupiter supply accounts (all 15 required by JupiterSupplyAccounts::from_remaining)
341
+ { address: constants_1.JUPITER_LENDING_ADMIN, role: 1 }, // lending_admin
342
+ { address: constants_1.JUPITER_USDC_LENDING, role: 1 }, // lending
343
+ { address: constants_1.JUPITER_USDC_SUPPLY_TOKEN_RESERVES_LIQUIDITY, role: 1 }, // supply_token_reserves_liquidity
344
+ { address: constants_1.JUPITER_USDC_LENDING_SUPPLY_POSITION, role: 1 }, // lending_supply_position_on_liquidity
345
+ { address: constants_1.JUPITER_USDC_RATE_MODEL, role: 0 }, // rate_model
346
+ { address: constants_1.JUPITER_USDC_VAULT, role: 1 }, // vault
347
+ { address: constants_1.JUPITER_USDC_CLAIM_ACCOUNT, role: 1 }, // claim_account
348
+ { address: constants_1.JUPITER_LIQUIDITY_OWNER, role: 1 }, // liquidity_owner (writable for CPI)
349
+ { address: constants_1.JUPITER_USDC_REWARDS_RATE_MODEL, role: 0 }, // rewards_rate_model
350
+ { address: usdcMint, role: 0 }, // earn_mint (shared with Kamino)
351
+ { address: constants_1.JUPITER_USDC_F_TOKEN_MINT, role: 1 }, // f_token_mint
352
+ { address: strategyControllerEarnTokenAccount, role: 1 }, // controller_earn_account (shared)
353
+ { address: controllerJupiterFTokenAccount, role: 1 }, // controller_f_token_account
354
+ { address: constants_1.JUPITER_LENDING_PROGRAM_ID, role: 0 }, // lending_program
355
+ { address: constants_1.JUPITER_LIQUIDITY_PROGRAM_ID, role: 1 }, // liquidity_program (writable for CPI)
356
+ // Kamino supply accounts (all 15 required by KaminoSupplyAccounts::from_remaining)
357
+ { address: constants_1.KAMINO_USDC_RESERVE, role: 1 }, // reserve
358
+ { address: constants_1.KAMINO_LENDING_MARKET, role: 0 }, // lending_market
359
+ { address: lendingMarketAuthority, role: 0 }, // lending_market_authority
360
+ { address: constants_1.KAMINO_USDC_RESERVE_LIQUIDITY_SUPPLY, role: 1 }, // reserve_liquidity_supply
361
+ { address: reserveCollateralMint, role: 1 }, // reserve_collateral_mint
362
+ { address: reserveCollateralSupplyVault, role: 1 }, // collateral_supply_vault
363
+ { address: userMetadata, role: 1 }, // user_metadata
364
+ { address: kaminoObligation, role: 1 }, // obligation
365
+ { address: constants_1.KAMINO_SCOPE_ORACLE, role: 0 }, // scope_oracle
366
+ { address: obligationFarmState, role: 1 }, // obligation_farm_state
367
+ { address: reserveFarmState, role: 1 }, // reserve_farm_state
368
+ { address: constants_1.KLEND_PROGRAM_ID, role: 0 }, // klend_program
369
+ { address: constants_1.FARMS_PROGRAM_ID, role: 0 }, // farms_program
370
+ ];
371
+ // Create new instruction with remaining accounts
372
+ const ixWithRemainingAccounts = Object.assign(Object.assign({}, ix), { accounts: [...ix.accounts, ...remainingAccounts] });
373
+ return [ixWithRemainingAccounts];
237
374
  });
238
375
  }
239
376
  /**
240
377
  * Creates a rebalance instruction for the USDC+ stablecoin.
241
- * Currently returns an empty instruction, as the rebalance is unnecessary.
378
+ * Currently returns an empty array as the rebalance is unnecessary.
242
379
  *
243
- * @returns Promise resolving to an array containing a single, empty TransactionInstruction.
380
+ * @returns Promise resolving to an empty array
244
381
  */
245
382
  rebalance() {
246
383
  return __awaiter(this, void 0, void 0, function* () {
247
- const ix = new web3_js_1.TransactionInstruction({
248
- programId: web3_js_1.Keypair.generate().publicKey,
249
- data: Buffer.from(""),
250
- keys: [],
251
- });
252
- return [ix];
384
+ return [];
253
385
  });
254
386
  }
255
387
  /**
@@ -259,21 +391,24 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
259
391
  */
260
392
  getBaseUsdExchangeRate() {
261
393
  return __awaiter(this, void 0, void 0, function* () {
262
- const userAccount = (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey);
263
- const { data: userAccountData } = yield (0, drift_1.fetchUser)(this.rpc, (0, kit_1.address)(userAccount.toString()));
394
+ if (!this.controllerKey)
395
+ yield this.initializeKeys();
396
+ const controllerPubkey = new web3_js_1.PublicKey(this.controllerKey);
397
+ const driftProgramPubkey = new web3_js_1.PublicKey(constants_1.DRIFT_PROGRAM_ID);
398
+ const userAccount = (0, sdk_1.getUserAccountPublicKeySync)(driftProgramPubkey, controllerPubkey);
399
+ const { data: userAccountData } = yield (0, drift_1.fetchUser)(this.rpc, (0, kit_1.address)(userAccount.toBase58()));
264
400
  const spotPosition = userAccountData.spotPositions[0];
265
401
  const { scaledBalance, balanceType } = spotPosition;
266
- const spotMarketAccount = (0, sdk_1.getSpotMarketPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, 0);
267
- const { data: spotMarketAccountData } = yield (0, drift_1.fetchSpotMarket)(this.rpc, (0, kit_1.address)(spotMarketAccount.toString()));
402
+ const spotMarketAccount = (0, sdk_1.getSpotMarketPublicKeySync)(driftProgramPubkey, 0);
403
+ const { data: spotMarketAccountData } = yield (0, drift_1.fetchSpotMarket)(this.rpc, (0, kit_1.address)(spotMarketAccount.toBase58()));
268
404
  const usdcAmount = (0, sdk_1.getTokenAmount)(new bn_js_1.default(scaledBalance.toString()), (0, drift_1.mapSpotMarket)(spotMarketAccountData), (0, drift_1.mapSpotBalanceType)(balanceType));
269
- const { supply, decimals } = yield (0, spl_token_1.getMint)(this.connection, this.stablecoinMint, "confirmed");
270
405
  const [{ mint: usdcMint }] = this.collaterals;
271
- const { data: [{ price: { expo, price }, },], } = yield this.getCollateralPrice(usdcMint);
406
+ const { data: [{ price: { expo, price } }], } = yield this.getCollateralPrice(usdcMint);
272
407
  const exchangeRate = usdcAmount
273
408
  .mul(new bn_js_1.default(price))
274
- .mul(new bn_js_1.default(constants_1.EXCHANGE_RATE_PRECISION)) // gives us exhcnage rate precision
275
- .div(new bn_js_1.default(supply.toString())) // price per stablecoin
276
- .div(new bn_js_1.default(10).pow(new bn_js_1.default(expo).abs())); // cancels out the price decimals
409
+ .mul(new bn_js_1.default(constants_1.EXCHANGE_RATE_PRECISION))
410
+ .div(new bn_js_1.default(this.stablecoinMintSupply.toString()))
411
+ .div(new bn_js_1.default(10).pow(new bn_js_1.default(expo).abs()));
277
412
  return exchangeRate.toNumber();
278
413
  });
279
414
  }
@@ -288,23 +423,25 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
288
423
  */
289
424
  getBaseToCollateralExchangeRate() {
290
425
  return __awaiter(this, void 0, void 0, function* () {
291
- const userAccount = (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey);
292
- const { data: userAccountData } = yield (0, drift_1.fetchUser)(this.rpc, (0, kit_1.address)(userAccount.toString()));
426
+ if (!this.controllerKey)
427
+ yield this.initializeKeys();
428
+ const controllerPubkey = new web3_js_1.PublicKey(this.controllerKey);
429
+ const driftProgramPubkey = new web3_js_1.PublicKey(constants_1.DRIFT_PROGRAM_ID);
430
+ const userAccount = (0, sdk_1.getUserAccountPublicKeySync)(driftProgramPubkey, controllerPubkey);
431
+ const { data: userAccountData } = yield (0, drift_1.fetchUser)(this.rpc, (0, kit_1.address)(userAccount.toBase58()));
293
432
  const spotPosition = userAccountData.spotPositions[0];
294
433
  const { scaledBalance, balanceType } = spotPosition;
295
- const spotMarketAccount = (0, sdk_1.getSpotMarketPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, 0);
296
- const { data: spotMarketAccountData } = yield (0, drift_1.fetchSpotMarket)(this.rpc, (0, kit_1.address)(spotMarketAccount.toString()));
434
+ const spotMarketAccount = (0, sdk_1.getSpotMarketPublicKeySync)(driftProgramPubkey, 0);
435
+ const { data: spotMarketAccountData } = yield (0, drift_1.fetchSpotMarket)(this.rpc, (0, kit_1.address)(spotMarketAccount.toBase58()));
297
436
  const usdcAmount = (0, sdk_1.getTokenAmount)(new bn_js_1.default(scaledBalance.toString()), (0, drift_1.mapSpotMarket)(spotMarketAccountData), (0, drift_1.mapSpotBalanceType)(balanceType));
298
- const { supply, decimals } = yield (0, spl_token_1.getMint)(this.connection, this.stablecoinMint, "confirmed");
299
437
  const exchangeRate = usdcAmount
300
- .mul(new bn_js_1.default(constants_1.EXCHANGE_RATE_PRECISION)) // gives us exhcnage rate precision
301
- .div(new bn_js_1.default(supply.toString())); // price per stablecoin
438
+ .mul(new bn_js_1.default(constants_1.EXCHANGE_RATE_PRECISION))
439
+ .div(new bn_js_1.default(this.stablecoinMintSupply.toString()));
302
440
  return exchangeRate.toNumber();
303
441
  });
304
442
  }
305
443
  /**
306
444
  * Receipt (USDC+) to Collateral (USDC) exchange rate.
307
- * rate = deposited_vault_value / receipt_supply, scaled by EXCHANGE_RATE_PRECISION
308
445
  */
309
446
  getReceiptToCollateralExchangeRate() {
310
447
  return __awaiter(this, void 0, void 0, function* () {
@@ -313,72 +450,45 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
313
450
  }
314
451
  /**
315
452
  * Math helper function that calculates receipt tokens to issue for a given deposit amount.
316
- * Mirrors the compute_receipt_token function from Rust.
317
- *
318
- * @param deposit - Amount of USDC being deposited
319
- * @param depositedVault - Current deposited vault value
320
- * @param receiptTokenSupply - Current effective supply of receipt tokens
321
- * @returns Amount of receipt tokens to issue
322
453
  */
323
454
  computeReceiptToken(deposit, depositedVault, receiptTokenSupply) {
324
- // If supply is 0, return deposit amount (1:1 ratio for first deposit)
325
455
  if (receiptTokenSupply.isZero()) {
326
456
  return deposit;
327
457
  }
328
- // receipt_tokens = (deposit * receipt_token_supply) / deposited_vault
329
458
  return deposit.mul(receiptTokenSupply).div(depositedVault);
330
459
  }
331
460
  /**
332
461
  * Math helper function that calculates base token amount to return for a given receipt token burn.
333
- * Mirrors the compute_base_token function from Rust.
334
- *
335
- * @param receipt - Amount of receipt tokens being burned
336
- * @param depositedVault - Current deposited vault value
337
- * @param receiptTokenSupply - Current effective supply of receipt tokens
338
- * @returns Amount of base tokens (USDC) to return
339
462
  */
340
463
  computeBaseToken(receipt, depositedVault, receiptTokenSupply) {
341
- // usdc_amount = (receipt * deposited_vault) / receipt_token_supply
342
464
  return receipt.mul(depositedVault).div(receiptTokenSupply);
343
465
  }
344
466
  /**
345
- * Processes a user deposit: calculates receipt tokens to issue and updates internal accounting.
346
- * Mirrors the process_deposit function from Rust AutoCompound.
347
- *
348
- * @param usdcDeposited - Amount of USDC being deposited
349
- * @returns Amount of receipt tokens to issue
350
- * @throws Error if USDC input is zero
467
+ * Processes a user deposit: calculates receipt tokens to issue.
351
468
  */
352
469
  processDeposit(usdcDeposited) {
353
470
  if (usdcDeposited.isZero()) {
354
471
  throw new Error("USDC input can not be zero");
355
472
  }
356
- if (!this.controller || !this.controller.compounder) {
357
- throw new Error("Controller not loaded. Call load() first.");
473
+ if (!this.controller || !this.autoCompound) {
474
+ throw new Error("Controller not loaded or AutoCompound component not found. Call load() first.");
358
475
  }
359
- const autocompound = this.controller.compounder;
360
- // Calculate receipt tokens to issue
361
- const receiptTokens = this.computeReceiptToken(usdcDeposited, new bn_js_1.default(autocompound.depositedVaultValue), new bn_js_1.default(this.stablecoinMintData.supply.toString()));
476
+ const autocompound = this.autoCompound;
477
+ const receiptTokens = this.computeReceiptToken(usdcDeposited, new bn_js_1.default(autocompound.depositedVaultValue.toString()), new bn_js_1.default(this.stablecoinMintSupply.toString()));
362
478
  return receiptTokens;
363
479
  }
364
480
  /**
365
- * Processes a user redemption: calculates USDC to return and updates internal accounting.
366
- * Mirrors the process_redemption function from Rust AutoCompound.
367
- *
368
- * @param receiptTokensBurned - Amount of receipt tokens being burned
369
- * @returns Amount of USDC to return to user
370
- * @throws Error if receipt token input is zero
481
+ * Processes a user redemption: calculates USDC to return.
371
482
  */
372
483
  processRedemption(receiptTokensBurned) {
373
484
  if (receiptTokensBurned.isZero()) {
374
485
  throw new Error("LP input can not be zero");
375
486
  }
376
- if (!this.controller || !this.controller.compounder) {
377
- throw new Error("Controller not loaded. Call load() first.");
487
+ if (!this.controller || !this.autoCompound) {
488
+ throw new Error("Controller not loaded or AutoCompound component not found. Call load() first.");
378
489
  }
379
- const autocompound = this.controller.compounder;
380
- // Calculate USDC to return
381
- const usdcAmount = this.computeBaseToken(receiptTokensBurned, new bn_js_1.default(autocompound.depositedVaultValue), new bn_js_1.default(this.stablecoinMintData.supply.toString()));
490
+ const autocompound = this.autoCompound;
491
+ const usdcAmount = this.computeBaseToken(receiptTokensBurned, new bn_js_1.default(autocompound.depositedVaultValue.toString()), new bn_js_1.default(this.stablecoinMintSupply.toString()));
382
492
  return usdcAmount;
383
493
  }
384
494
  simulateMintMath(usdcAmount) {
@@ -397,39 +507,266 @@ class UsdcPlusStablecoin extends Stablecoin_1.Stablecoin {
397
507
  return this.processRedemption(receiptTokens);
398
508
  });
399
509
  }
400
- depositDrift(signer, amount) {
510
+ /**
511
+ * Deposit to Drift
512
+ */
513
+ depositDrift(depositor, amount) {
401
514
  return __awaiter(this, void 0, void 0, function* () {
515
+ if (!this.controllerKey)
516
+ yield this.initializeKeys();
517
+ if (!this.controller)
518
+ throw new Error("Controller not loaded. Call load() first.");
402
519
  const { oracle, marketIndex } = sdk_1.SpotMarkets["mainnet-beta"][0];
403
- const spotMarket = (0, sdk_1.getSpotMarketPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, marketIndex);
520
+ const driftProgramPubkey = new web3_js_1.PublicKey(constants_1.DRIFT_PROGRAM_ID);
521
+ const controllerPubkey = new web3_js_1.PublicKey(this.controllerKey);
522
+ const spotMarket = (0, sdk_1.getSpotMarketPublicKeySync)(driftProgramPubkey, marketIndex);
404
523
  const [{ mint }] = this.collaterals;
405
- const controllerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, this.controllerKey, true);
406
- const depositorTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, signer, true);
407
- const bump = this.controller.baseStrategy.bump;
408
- const ix = (0, reflect_main_1.createDepositDriftInstruction)({
524
+ const controllerTokenAccount = yield this.getAta(mint, this.controllerKey);
525
+ const depositorTokenAccount = yield this.getAta(mint, depositor.address);
526
+ const bump = this.controller.base.bump;
527
+ const driftState = yield (0, sdk_1.getDriftStateAccountPublicKey)(driftProgramPubkey);
528
+ const spotMarketVault = yield (0, sdk_1.getSpotMarketVaultPublicKey)(driftProgramPubkey, 0);
529
+ const userAccount = (0, sdk_1.getUserAccountPublicKeySync)(driftProgramPubkey, controllerPubkey);
530
+ const userStats = (0, sdk_1.getUserStatsAccountPublicKey)(driftProgramPubkey, controllerPubkey);
531
+ const ix = (0, reflect_main_1.getDepositDriftInstruction)({
409
532
  controller: this.controllerKey,
410
- depositor: signer,
411
- spotMarket,
533
+ depositor,
534
+ spotMarket: (0, kit_1.address)(spotMarket.toBase58()),
412
535
  controllerTokenAccount,
413
- main: classes_1.PdaClient.deriveMain(this.devnet),
414
- userAccount: (0, sdk_1.getUserAccountPublicKeySync)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey),
415
- userStats: (0, sdk_1.getUserStatsAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID, this.controllerKey),
416
- spotMarketVault: yield (0, sdk_1.getSpotMarketVaultPublicKey)(constants_1.DRIFT_PROGRAM_ID, 0),
417
- oracle,
418
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
419
- state: yield (0, sdk_1.getDriftStateAccountPublicKey)(constants_1.DRIFT_PROGRAM_ID),
536
+ main: yield classes_1.PdaClient.deriveMain(this.devnet, this.mock),
537
+ userAccount: (0, kit_1.address)(userAccount.toBase58()),
538
+ userStats: (0, kit_1.address)(userStats.toBase58()),
539
+ spotMarketVault: (0, kit_1.address)(spotMarketVault.toBase58()),
540
+ oracle: (0, kit_1.address)(oracle.toBase58()),
541
+ tokenProgram: token_1.TOKEN_PROGRAM_ADDRESS,
542
+ state: (0, kit_1.address)(driftState.toBase58()),
420
543
  depositorTokenAccount,
421
544
  drift: constants_1.DRIFT_PROGRAM_ID,
422
- }, {
423
545
  amount,
424
546
  controllerBump: bump,
425
547
  controllerIndex: this.index,
426
- }, this.programId);
548
+ }, { programAddress: this.programAddress });
549
+ return ix;
550
+ });
551
+ }
552
+ /**
553
+ * Derives the Kamino obligation PDA for this controller.
554
+ * The obligation account stores the user's lending/borrowing positions.
555
+ *
556
+ * @param lendingMarket - Address of the lending market
557
+ * @returns Promise resolving to the obligation address
558
+ */
559
+ deriveKaminoObligation(lendingMarket) {
560
+ return __awaiter(this, void 0, void 0, function* () {
561
+ if (!this.controllerKey)
562
+ yield this.initializeKeys();
563
+ const encoder = (0, kit_1.getAddressEncoder)();
564
+ const [obligation] = yield (0, kit_1.getProgramDerivedAddress)({
565
+ programAddress: constants_1.KLEND_PROGRAM_ID,
566
+ seeds: [
567
+ new Uint8Array([0]), // tag
568
+ new Uint8Array([0]), // id
569
+ encoder.encode(this.controllerKey),
570
+ encoder.encode(lendingMarket),
571
+ encoder.encode((0, kit_1.address)("11111111111111111111111111111111")), // elevationGroup (default)
572
+ encoder.encode((0, kit_1.address)("11111111111111111111111111111111")), // referrer (default)
573
+ ],
574
+ });
575
+ return obligation;
576
+ });
577
+ }
578
+ /**
579
+ * Derives the Kamino user metadata PDA for this controller.
580
+ *
581
+ * @returns Promise resolving to the user metadata address
582
+ */
583
+ deriveKaminoUserMetadata() {
584
+ return __awaiter(this, void 0, void 0, function* () {
585
+ if (!this.controllerKey)
586
+ yield this.initializeKeys();
587
+ const encoder = (0, kit_1.getAddressEncoder)();
588
+ const [userMetadata] = yield (0, kit_1.getProgramDerivedAddress)({
589
+ programAddress: constants_1.KLEND_PROGRAM_ID,
590
+ seeds: [
591
+ Buffer.from("user_meta"),
592
+ encoder.encode(this.controllerKey),
593
+ ],
594
+ });
595
+ return userMetadata;
596
+ });
597
+ }
598
+ /**
599
+ * Derives the Kamino lending market authority PDA.
600
+ *
601
+ * @param lendingMarket - Address of the lending market
602
+ * @returns Promise resolving to the lending market authority address
603
+ */
604
+ deriveKaminoLendingMarketAuthority(lendingMarket) {
605
+ return __awaiter(this, void 0, void 0, function* () {
606
+ const encoder = (0, kit_1.getAddressEncoder)();
607
+ const [authority] = yield (0, kit_1.getProgramDerivedAddress)({
608
+ programAddress: constants_1.KLEND_PROGRAM_ID,
609
+ seeds: [
610
+ Buffer.from("lma"),
611
+ encoder.encode(lendingMarket),
612
+ ],
613
+ });
614
+ return authority;
615
+ });
616
+ }
617
+ /**
618
+ * Derives the Kamino obligation farm state PDA.
619
+ *
620
+ * @param reserveFarmState - Address of the reserve farm state
621
+ * @param obligation - Address of the obligation
622
+ * @returns Promise resolving to the obligation farm state address
623
+ */
624
+ deriveKaminoObligationFarmState(reserveFarmState, obligation) {
625
+ return __awaiter(this, void 0, void 0, function* () {
626
+ const encoder = (0, kit_1.getAddressEncoder)();
627
+ const [obligationFarmState] = yield (0, kit_1.getProgramDerivedAddress)({
628
+ programAddress: constants_1.FARMS_PROGRAM_ID,
629
+ seeds: [
630
+ Buffer.from("user"),
631
+ encoder.encode(reserveFarmState),
632
+ encoder.encode(obligation),
633
+ ],
634
+ });
635
+ return obligationFarmState;
636
+ });
637
+ }
638
+ /**
639
+ * Creates the controller's token account (ATA) for the earn token (USDC).
640
+ * This must be called before initializeKaminoAccounts if the ATA doesn't exist.
641
+ *
642
+ * @param payer - TransactionSigner who pays for the account creation
643
+ * @returns Promise resolving to the instruction
644
+ */
645
+ initializeControllerTokenAccount(payer) {
646
+ return __awaiter(this, void 0, void 0, function* () {
647
+ if (!this.controllerKey)
648
+ yield this.initializeKeys();
649
+ const usdcMint = this.devnet ? constants_1.USDC_MINT_DEVNET : constants_1.USDC_MINT;
650
+ const controllerTokenAccount = yield this.getAta(usdcMint, this.controllerKey);
651
+ const ix = (0, token_1.getCreateAssociatedTokenIdempotentInstruction)({
652
+ payer,
653
+ ata: controllerTokenAccount,
654
+ owner: this.controllerKey,
655
+ mint: usdcMint,
656
+ tokenProgram: token_1.TOKEN_PROGRAM_ADDRESS,
657
+ });
658
+ return ix;
659
+ });
660
+ }
661
+ /**
662
+ * Creates the controller's Jupiter fToken account (ATA).
663
+ * This must be called before mint/redeem if the ATA doesn't exist.
664
+ *
665
+ * @param payer - TransactionSigner who pays for the account creation
666
+ * @returns Promise resolving to the instruction
667
+ */
668
+ initializeControllerJupiterFTokenAccount(payer) {
669
+ return __awaiter(this, void 0, void 0, function* () {
670
+ if (!this.controllerKey)
671
+ yield this.initializeKeys();
672
+ const controllerJupiterFTokenAccount = yield this.getAta(constants_1.JUPITER_USDC_F_TOKEN_MINT, this.controllerKey);
673
+ const ix = (0, token_1.getCreateAssociatedTokenIdempotentInstruction)({
674
+ payer,
675
+ ata: controllerJupiterFTokenAccount,
676
+ owner: this.controllerKey,
677
+ mint: constants_1.JUPITER_USDC_F_TOKEN_MINT,
678
+ tokenProgram: token_1.TOKEN_PROGRAM_ADDRESS,
679
+ });
680
+ return ix;
681
+ });
682
+ }
683
+ /**
684
+ * Creates the controller's Kamino collateral token account (cToken ATA).
685
+ * This must be called before mint/redeem if the ATA doesn't exist.
686
+ *
687
+ * @param payer - TransactionSigner who pays for the account creation
688
+ * @returns Promise resolving to the instruction
689
+ */
690
+ initializeControllerKaminoCollateralAccount(payer) {
691
+ return __awaiter(this, void 0, void 0, function* () {
692
+ if (!this.controllerKey)
693
+ yield this.initializeKeys();
694
+ const reserveCollateralMint = this.mock
695
+ ? constants_1.KAMINO_USDC_RESERVE_COLLATERAL_MINT_MOCK
696
+ : constants_1.KAMINO_USDC_RESERVE_COLLATERAL_MINT;
697
+ const controllerCollateralAccount = yield this.getAta(reserveCollateralMint, this.controllerKey);
698
+ const ix = (0, token_1.getCreateAssociatedTokenIdempotentInstruction)({
699
+ payer,
700
+ ata: controllerCollateralAccount,
701
+ owner: this.controllerKey,
702
+ mint: reserveCollateralMint,
703
+ tokenProgram: token_1.TOKEN_PROGRAM_ADDRESS,
704
+ });
705
+ return ix;
706
+ });
707
+ }
708
+ /**
709
+ * Initializes Kamino user accounts for this stablecoin controller.
710
+ * This creates the necessary accounts to interact with Kamino lending protocol:
711
+ * - User metadata
712
+ * - Obligation account
713
+ * - Obligation farm state (for rewards)
714
+ *
715
+ * @param admin - TransactionSigner of the admin
716
+ * @returns Promise resolving to the instruction
717
+ */
718
+ initializeKaminoAccounts(admin) {
719
+ return __awaiter(this, void 0, void 0, function* () {
720
+ if (!this.controllerKey)
721
+ yield this.initializeKeys();
722
+ const main = yield classes_1.PdaClient.deriveMain(this.devnet, this.mock);
723
+ const adminPermissions = yield classes_1.PdaClient.derivePermissions(admin.address, this.devnet, this.mock);
724
+ const usdcMint = this.devnet ? constants_1.USDC_MINT_DEVNET : constants_1.USDC_MINT;
725
+ // Select Kamino constants based on mock mode
726
+ // Mock mode uses different fixture accounts than mainnet
727
+ const reserveFarmState = this.mock
728
+ ? constants_1.KAMINO_USDC_RESERVE_FARM_STATE_MOCK
729
+ : constants_1.KAMINO_USDC_RESERVE_FARM_STATE;
730
+ const reserveCollateralMint = this.mock
731
+ ? constants_1.KAMINO_USDC_RESERVE_COLLATERAL_MINT_MOCK
732
+ : constants_1.KAMINO_USDC_RESERVE_COLLATERAL_MINT;
733
+ // Note: reserveCollateral in this instruction is actually the reserve account (used for refresh_reserve)
734
+ const reserveCollateral = constants_1.KAMINO_USDC_RESERVE;
735
+ const reserveDestinationDepositCollateral = this.mock
736
+ ? constants_1.KAMINO_USDC_RESERVE_DESTINATION_DEPOSIT_COLLATERAL_MOCK
737
+ : constants_1.KAMINO_USDC_RESERVE_DESTINATION_DEPOSIT_COLLATERAL;
738
+ // Derive Kamino PDAs
739
+ const obligation = yield this.deriveKaminoObligation(constants_1.KAMINO_LENDING_MARKET);
740
+ const userMetadata = yield this.deriveKaminoUserMetadata();
741
+ const lendingMarketAuthority = yield this.deriveKaminoLendingMarketAuthority(constants_1.KAMINO_LENDING_MARKET);
742
+ // Explicitly derive obligationFarmState with FARMS_PROGRAM_ID (generated code has a bug using wrong program)
743
+ const obligationFarmState = yield this.deriveKaminoObligationFarmState(reserveFarmState, obligation);
744
+ // Get controller token account (ATA for USDC)
745
+ const controllerTokenAccount = yield this.getAta(usdcMint, this.controllerKey);
746
+ const userUsdcAccount = yield this.getAta(usdcMint, admin.address);
747
+ const ix = yield (0, reflect_main_1.getCreateKaminoUserAccountsInstructionAsync)({
748
+ admin,
749
+ controller: this.controllerKey,
750
+ adminPermissions,
751
+ obligation,
752
+ lendingMarket: constants_1.KAMINO_LENDING_MARKET,
753
+ reserve: constants_1.KAMINO_USDC_RESERVE,
754
+ reserveFarmState,
755
+ // Explicitly pass obligationFarmState to override buggy derivation in generated code
756
+ obligationFarmState,
757
+ earnMint: usdcMint,
758
+ reserveCollateral,
759
+ scopeOracle: constants_1.KAMINO_SCOPE_ORACLE,
760
+ reserveLiquiditySupply: constants_1.KAMINO_USDC_RESERVE_LIQUIDITY_SUPPLY,
761
+ reserveCollateralMint,
762
+ reserveDestinationDepositCollateral,
763
+ }, { programAddress: this.programAddress });
427
764
  return ix;
428
765
  });
429
766
  }
430
767
  cleanup() {
431
768
  return __awaiter(this, void 0, void 0, function* () {
432
- return;
769
+ // No cleanup needed
433
770
  });
434
771
  }
435
772
  }