@haven-fi/solauto-sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (519) hide show
  1. package/dist/clients/index.d.ts +2 -0
  2. package/dist/clients/index.d.ts.map +1 -0
  3. package/dist/clients/index.js +17 -0
  4. package/dist/clients/solautoClient.d.ts +73 -0
  5. package/dist/clients/solautoClient.d.ts.map +1 -0
  6. package/dist/clients/solautoClient.js +416 -0
  7. package/dist/clients/solautoMarginfiClient.d.ts +40 -0
  8. package/dist/clients/solautoMarginfiClient.d.ts.map +1 -0
  9. package/dist/clients/solautoMarginfiClient.js +313 -0
  10. package/dist/constants/generalAccounts.d.ts +5 -0
  11. package/dist/constants/generalAccounts.d.ts.map +1 -0
  12. package/dist/constants/generalAccounts.js +8 -0
  13. package/dist/constants/index.d.ts +6 -0
  14. package/dist/constants/index.d.ts.map +1 -0
  15. package/dist/constants/index.js +21 -0
  16. package/dist/constants/marginfiAccounts.d.ts +7 -0
  17. package/dist/constants/marginfiAccounts.d.ts.map +1 -0
  18. package/dist/constants/marginfiAccounts.js +23 -0
  19. package/dist/constants/pythConstants.d.ts +5 -0
  20. package/dist/constants/pythConstants.d.ts.map +1 -0
  21. package/dist/constants/pythConstants.js +10 -0
  22. package/dist/constants/solautoConstants.d.ts +19 -0
  23. package/dist/constants/solautoConstants.d.ts.map +1 -0
  24. package/dist/constants/solautoConstants.js +35 -0
  25. package/dist/constants/tokenConstants.d.ts +3 -0
  26. package/dist/constants/tokenConstants.d.ts.map +1 -0
  27. package/dist/constants/tokenConstants.js +10 -0
  28. package/dist/generated/accounts/index.d.ts +10 -0
  29. package/dist/generated/accounts/index.d.ts.map +1 -0
  30. package/dist/generated/accounts/index.js +25 -0
  31. package/dist/generated/accounts/referralState.d.ts +37 -0
  32. package/dist/generated/accounts/referralState.d.ts.map +1 -0
  33. package/dist/generated/accounts/referralState.js +73 -0
  34. package/dist/generated/accounts/solautoPosition.d.ts +58 -0
  35. package/dist/generated/accounts/solautoPosition.d.ts.map +1 -0
  36. package/dist/generated/accounts/solautoPosition.js +82 -0
  37. package/dist/generated/errors/index.d.ts +9 -0
  38. package/dist/generated/errors/index.d.ts.map +1 -0
  39. package/dist/generated/errors/index.js +24 -0
  40. package/dist/generated/errors/solauto.d.ts +91 -0
  41. package/dist/generated/errors/solauto.d.ts.map +1 -0
  42. package/dist/generated/errors/solauto.js +163 -0
  43. package/dist/generated/index.d.ts +14 -0
  44. package/dist/generated/index.d.ts.map +1 -0
  45. package/dist/generated/index.js +29 -0
  46. package/dist/generated/instructions/cancelDCA.d.ts +26 -0
  47. package/dist/generated/instructions/cancelDCA.d.ts.map +1 -0
  48. package/dist/generated/instructions/cancelDCA.js +92 -0
  49. package/dist/generated/instructions/claimReferralFees.d.ts +26 -0
  50. package/dist/generated/instructions/claimReferralFees.d.ts.map +1 -0
  51. package/dist/generated/instructions/claimReferralFees.js +87 -0
  52. package/dist/generated/instructions/closePosition.d.ts +28 -0
  53. package/dist/generated/instructions/closePosition.d.ts.map +1 -0
  54. package/dist/generated/instructions/closePosition.js +102 -0
  55. package/dist/generated/instructions/convertReferralFees.d.ts +27 -0
  56. package/dist/generated/instructions/convertReferralFees.d.ts.map +1 -0
  57. package/dist/generated/instructions/convertReferralFees.js +96 -0
  58. package/dist/generated/instructions/index.d.ts +18 -0
  59. package/dist/generated/instructions/index.d.ts.map +1 -0
  60. package/dist/generated/instructions/index.js +33 -0
  61. package/dist/generated/instructions/marginfiOpenPosition.d.ts +46 -0
  62. package/dist/generated/instructions/marginfiOpenPosition.d.ts.map +1 -0
  63. package/dist/generated/instructions/marginfiOpenPosition.js +161 -0
  64. package/dist/generated/instructions/marginfiProtocolInteraction.d.ts +42 -0
  65. package/dist/generated/instructions/marginfiProtocolInteraction.d.ts.map +1 -0
  66. package/dist/generated/instructions/marginfiProtocolInteraction.js +150 -0
  67. package/dist/generated/instructions/marginfiRebalance.d.ts +49 -0
  68. package/dist/generated/instructions/marginfiRebalance.d.ts.map +1 -0
  69. package/dist/generated/instructions/marginfiRebalance.js +164 -0
  70. package/dist/generated/instructions/marginfiRefreshData.d.ts +27 -0
  71. package/dist/generated/instructions/marginfiRefreshData.d.ts.map +1 -0
  72. package/dist/generated/instructions/marginfiRefreshData.js +84 -0
  73. package/dist/generated/instructions/updatePosition.d.ts +30 -0
  74. package/dist/generated/instructions/updatePosition.d.ts.map +1 -0
  75. package/dist/generated/instructions/updatePosition.js +87 -0
  76. package/dist/generated/instructions/updateReferralStates.d.ts +30 -0
  77. package/dist/generated/instructions/updateReferralStates.d.ts.map +1 -0
  78. package/dist/generated/instructions/updateReferralStates.js +77 -0
  79. package/dist/generated/programs/index.d.ts +9 -0
  80. package/dist/generated/programs/index.d.ts.map +1 -0
  81. package/dist/generated/programs/index.js +24 -0
  82. package/dist/generated/programs/solauto.d.ts +13 -0
  83. package/dist/generated/programs/solauto.d.ts.map +1 -0
  84. package/dist/generated/programs/solauto.js +36 -0
  85. package/dist/generated/shared/index.d.ts +54 -0
  86. package/dist/generated/shared/index.d.ts.map +1 -0
  87. package/dist/generated/shared/index.js +70 -0
  88. package/dist/generated/types/automationSettings.d.ts +26 -0
  89. package/dist/generated/types/automationSettings.d.ts.map +1 -0
  90. package/dist/generated/types/automationSettings.js +22 -0
  91. package/dist/generated/types/automationSettingsInp.d.ts +22 -0
  92. package/dist/generated/types/automationSettingsInp.d.ts.map +1 -0
  93. package/dist/generated/types/automationSettingsInp.js +20 -0
  94. package/dist/generated/types/dCASettings.d.ts +21 -0
  95. package/dist/generated/types/dCASettings.d.ts.map +1 -0
  96. package/dist/generated/types/dCASettings.js +20 -0
  97. package/dist/generated/types/dCASettingsInp.d.ts +19 -0
  98. package/dist/generated/types/dCASettingsInp.d.ts.map +1 -0
  99. package/dist/generated/types/dCASettingsInp.js +19 -0
  100. package/dist/generated/types/feeType.d.ts +15 -0
  101. package/dist/generated/types/feeType.d.ts.map +1 -0
  102. package/dist/generated/types/feeType.js +20 -0
  103. package/dist/generated/types/index.d.ts +26 -0
  104. package/dist/generated/types/index.d.ts.map +1 -0
  105. package/dist/generated/types/index.js +41 -0
  106. package/dist/generated/types/lendingPlatform.d.ts +16 -0
  107. package/dist/generated/types/lendingPlatform.d.ts.map +1 -0
  108. package/dist/generated/types/lendingPlatform.js +23 -0
  109. package/dist/generated/types/podBool.d.ts +14 -0
  110. package/dist/generated/types/podBool.d.ts.map +1 -0
  111. package/dist/generated/types/podBool.js +17 -0
  112. package/dist/generated/types/positionData.d.ts +32 -0
  113. package/dist/generated/types/positionData.d.ts.map +1 -0
  114. package/dist/generated/types/positionData.js +25 -0
  115. package/dist/generated/types/positionState.d.ts +35 -0
  116. package/dist/generated/types/positionState.d.ts.map +1 -0
  117. package/dist/generated/types/positionState.js +27 -0
  118. package/dist/generated/types/positionTokenUsage.d.ts +36 -0
  119. package/dist/generated/types/positionTokenUsage.d.ts.map +1 -0
  120. package/dist/generated/types/positionTokenUsage.js +27 -0
  121. package/dist/generated/types/rebalanceData.d.ts +29 -0
  122. package/dist/generated/types/rebalanceData.d.ts.map +1 -0
  123. package/dist/generated/types/rebalanceData.js +24 -0
  124. package/dist/generated/types/solautoAction.d.ts +44 -0
  125. package/dist/generated/types/solautoAction.d.ts.map +1 -0
  126. package/dist/generated/types/solautoAction.js +51 -0
  127. package/dist/generated/types/solautoRebalanceType.d.ts +17 -0
  128. package/dist/generated/types/solautoRebalanceType.d.ts.map +1 -0
  129. package/dist/generated/types/solautoRebalanceType.js +24 -0
  130. package/dist/generated/types/solautoSettingsParameters.d.ts +31 -0
  131. package/dist/generated/types/solautoSettingsParameters.d.ts.map +1 -0
  132. package/dist/generated/types/solautoSettingsParameters.js +25 -0
  133. package/dist/generated/types/solautoSettingsParametersInp.d.ts +28 -0
  134. package/dist/generated/types/solautoSettingsParametersInp.d.ts.map +1 -0
  135. package/dist/generated/types/solautoSettingsParametersInp.js +23 -0
  136. package/dist/generated/types/tokenAmount.d.ts +18 -0
  137. package/dist/generated/types/tokenAmount.d.ts.map +1 -0
  138. package/dist/generated/types/tokenAmount.js +18 -0
  139. package/dist/generated/types/tokenBalanceAmount.d.ts +27 -0
  140. package/dist/generated/types/tokenBalanceAmount.d.ts.map +1 -0
  141. package/dist/generated/types/tokenBalanceAmount.js +33 -0
  142. package/dist/generated/types/updatePositionData.d.ts +22 -0
  143. package/dist/generated/types/updatePositionData.d.ts.map +1 -0
  144. package/dist/generated/types/updatePositionData.js +20 -0
  145. package/dist/index.d.ts +7 -0
  146. package/dist/index.d.ts.map +1 -0
  147. package/dist/index.js +22 -0
  148. package/dist/marginfi-sdk/accounts/bank.d.ts +136 -0
  149. package/dist/marginfi-sdk/accounts/bank.d.ts.map +1 -0
  150. package/dist/marginfi-sdk/accounts/bank.js +124 -0
  151. package/dist/marginfi-sdk/accounts/index.d.ts +11 -0
  152. package/dist/marginfi-sdk/accounts/index.d.ts.map +1 -0
  153. package/dist/marginfi-sdk/accounts/index.js +26 -0
  154. package/dist/marginfi-sdk/accounts/marginfiAccount.d.ts +58 -0
  155. package/dist/marginfi-sdk/accounts/marginfiAccount.d.ts.map +1 -0
  156. package/dist/marginfi-sdk/accounts/marginfiAccount.js +76 -0
  157. package/dist/marginfi-sdk/accounts/marginfiGroup.d.ts +35 -0
  158. package/dist/marginfi-sdk/accounts/marginfiGroup.d.ts.map +1 -0
  159. package/dist/marginfi-sdk/accounts/marginfiGroup.js +71 -0
  160. package/dist/marginfi-sdk/errors/index.d.ts +9 -0
  161. package/dist/marginfi-sdk/errors/index.d.ts.map +1 -0
  162. package/dist/marginfi-sdk/errors/index.js +24 -0
  163. package/dist/marginfi-sdk/errors/marginfi.d.ts +283 -0
  164. package/dist/marginfi-sdk/errors/marginfi.d.ts.map +1 -0
  165. package/dist/marginfi-sdk/errors/marginfi.js +515 -0
  166. package/dist/marginfi-sdk/index.d.ts +14 -0
  167. package/dist/marginfi-sdk/index.d.ts.map +1 -0
  168. package/dist/marginfi-sdk/index.js +29 -0
  169. package/dist/marginfi-sdk/instructions/index.d.ts +32 -0
  170. package/dist/marginfi-sdk/instructions/index.d.ts.map +1 -0
  171. package/dist/marginfi-sdk/instructions/index.js +47 -0
  172. package/dist/marginfi-sdk/instructions/lendingAccountBorrow.d.ts +30 -0
  173. package/dist/marginfi-sdk/instructions/lendingAccountBorrow.d.ts.map +1 -0
  174. package/dist/marginfi-sdk/instructions/lendingAccountBorrow.js +83 -0
  175. package/dist/marginfi-sdk/instructions/lendingAccountCloseBalance.d.ts +22 -0
  176. package/dist/marginfi-sdk/instructions/lendingAccountCloseBalance.d.ts.map +1 -0
  177. package/dist/marginfi-sdk/instructions/lendingAccountCloseBalance.js +53 -0
  178. package/dist/marginfi-sdk/instructions/lendingAccountDeposit.d.ts +29 -0
  179. package/dist/marginfi-sdk/instructions/lendingAccountDeposit.d.ts.map +1 -0
  180. package/dist/marginfi-sdk/instructions/lendingAccountDeposit.js +81 -0
  181. package/dist/marginfi-sdk/instructions/lendingAccountEndFlashloan.d.ts +20 -0
  182. package/dist/marginfi-sdk/instructions/lendingAccountEndFlashloan.d.ts.map +1 -0
  183. package/dist/marginfi-sdk/instructions/lendingAccountEndFlashloan.js +50 -0
  184. package/dist/marginfi-sdk/instructions/lendingAccountLiquidate.d.ts +32 -0
  185. package/dist/marginfi-sdk/instructions/lendingAccountLiquidate.d.ts.map +1 -0
  186. package/dist/marginfi-sdk/instructions/lendingAccountLiquidate.js +100 -0
  187. package/dist/marginfi-sdk/instructions/lendingAccountRepay.d.ts +31 -0
  188. package/dist/marginfi-sdk/instructions/lendingAccountRepay.d.ts.map +1 -0
  189. package/dist/marginfi-sdk/instructions/lendingAccountRepay.js +82 -0
  190. package/dist/marginfi-sdk/instructions/lendingAccountSettleEmissions.d.ts +20 -0
  191. package/dist/marginfi-sdk/instructions/lendingAccountSettleEmissions.d.ts.map +1 -0
  192. package/dist/marginfi-sdk/instructions/lendingAccountSettleEmissions.js +46 -0
  193. package/dist/marginfi-sdk/instructions/lendingAccountStartFlashloan.d.ts +25 -0
  194. package/dist/marginfi-sdk/instructions/lendingAccountStartFlashloan.d.ts.map +1 -0
  195. package/dist/marginfi-sdk/instructions/lendingAccountStartFlashloan.js +62 -0
  196. package/dist/marginfi-sdk/instructions/lendingAccountWithdraw.d.ts +32 -0
  197. package/dist/marginfi-sdk/instructions/lendingAccountWithdraw.d.ts.map +1 -0
  198. package/dist/marginfi-sdk/instructions/lendingAccountWithdraw.js +87 -0
  199. package/dist/marginfi-sdk/instructions/lendingAccountWithdrawEmissions.d.ts +27 -0
  200. package/dist/marginfi-sdk/instructions/lendingAccountWithdrawEmissions.d.ts.map +1 -0
  201. package/dist/marginfi-sdk/instructions/lendingAccountWithdrawEmissions.js +86 -0
  202. package/dist/marginfi-sdk/instructions/lendingPoolAccrueBankInterest.d.ts +20 -0
  203. package/dist/marginfi-sdk/instructions/lendingPoolAccrueBankInterest.d.ts.map +1 -0
  204. package/dist/marginfi-sdk/instructions/lendingPoolAccrueBankInterest.js +46 -0
  205. package/dist/marginfi-sdk/instructions/lendingPoolAddBank.d.ts +37 -0
  206. package/dist/marginfi-sdk/instructions/lendingPoolAddBank.d.ts.map +1 -0
  207. package/dist/marginfi-sdk/instructions/lendingPoolAddBank.js +127 -0
  208. package/dist/marginfi-sdk/instructions/lendingPoolAddBankWithSeed.d.ts +39 -0
  209. package/dist/marginfi-sdk/instructions/lendingPoolAddBankWithSeed.d.ts.map +1 -0
  210. package/dist/marginfi-sdk/instructions/lendingPoolAddBankWithSeed.js +128 -0
  211. package/dist/marginfi-sdk/instructions/lendingPoolCollectBankFees.d.ts +25 -0
  212. package/dist/marginfi-sdk/instructions/lendingPoolCollectBankFees.d.ts.map +1 -0
  213. package/dist/marginfi-sdk/instructions/lendingPoolCollectBankFees.js +76 -0
  214. package/dist/marginfi-sdk/instructions/lendingPoolConfigureBank.d.ts +46 -0
  215. package/dist/marginfi-sdk/instructions/lendingPoolConfigureBank.d.ts.map +1 -0
  216. package/dist/marginfi-sdk/instructions/lendingPoolConfigureBank.js +67 -0
  217. package/dist/marginfi-sdk/instructions/lendingPoolHandleBankruptcy.d.ts +26 -0
  218. package/dist/marginfi-sdk/instructions/lendingPoolHandleBankruptcy.d.ts.map +1 -0
  219. package/dist/marginfi-sdk/instructions/lendingPoolHandleBankruptcy.js +81 -0
  220. package/dist/marginfi-sdk/instructions/lendingPoolSetupEmissions.d.ts +35 -0
  221. package/dist/marginfi-sdk/instructions/lendingPoolSetupEmissions.d.ts.map +1 -0
  222. package/dist/marginfi-sdk/instructions/lendingPoolSetupEmissions.js +97 -0
  223. package/dist/marginfi-sdk/instructions/lendingPoolUpdateEmissionsParameters.d.ts +33 -0
  224. package/dist/marginfi-sdk/instructions/lendingPoolUpdateEmissionsParameters.d.ts.map +1 -0
  225. package/dist/marginfi-sdk/instructions/lendingPoolUpdateEmissionsParameters.js +85 -0
  226. package/dist/marginfi-sdk/instructions/marginfiAccountInitialize.d.ts +23 -0
  227. package/dist/marginfi-sdk/instructions/marginfiAccountInitialize.d.ts.map +1 -0
  228. package/dist/marginfi-sdk/instructions/marginfiAccountInitialize.js +76 -0
  229. package/dist/marginfi-sdk/instructions/marginfiGroupConfigure.d.ts +24 -0
  230. package/dist/marginfi-sdk/instructions/marginfiGroupConfigure.d.ts.map +1 -0
  231. package/dist/marginfi-sdk/instructions/marginfiGroupConfigure.js +52 -0
  232. package/dist/marginfi-sdk/instructions/marginfiGroupInitialize.d.ts +21 -0
  233. package/dist/marginfi-sdk/instructions/marginfiGroupInitialize.d.ts.map +1 -0
  234. package/dist/marginfi-sdk/instructions/marginfiGroupInitialize.js +57 -0
  235. package/dist/marginfi-sdk/instructions/setAccountFlag.d.ts +26 -0
  236. package/dist/marginfi-sdk/instructions/setAccountFlag.d.ts.map +1 -0
  237. package/dist/marginfi-sdk/instructions/setAccountFlag.js +60 -0
  238. package/dist/marginfi-sdk/instructions/setNewAccountAuthority.d.ts +23 -0
  239. package/dist/marginfi-sdk/instructions/setNewAccountAuthority.d.ts.map +1 -0
  240. package/dist/marginfi-sdk/instructions/setNewAccountAuthority.js +69 -0
  241. package/dist/marginfi-sdk/instructions/unsetAccountFlag.d.ts +26 -0
  242. package/dist/marginfi-sdk/instructions/unsetAccountFlag.d.ts.map +1 -0
  243. package/dist/marginfi-sdk/instructions/unsetAccountFlag.js +57 -0
  244. package/dist/marginfi-sdk/programs/index.d.ts +9 -0
  245. package/dist/marginfi-sdk/programs/index.d.ts.map +1 -0
  246. package/dist/marginfi-sdk/programs/index.js +24 -0
  247. package/dist/marginfi-sdk/programs/marginfi.d.ts +13 -0
  248. package/dist/marginfi-sdk/programs/marginfi.d.ts.map +1 -0
  249. package/dist/marginfi-sdk/programs/marginfi.js +36 -0
  250. package/dist/marginfi-sdk/shared/index.d.ts +54 -0
  251. package/dist/marginfi-sdk/shared/index.d.ts.map +1 -0
  252. package/dist/marginfi-sdk/shared/index.js +70 -0
  253. package/dist/marginfi-sdk/types/accountEventHeader.d.ts +23 -0
  254. package/dist/marginfi-sdk/types/accountEventHeader.d.ts.map +1 -0
  255. package/dist/marginfi-sdk/types/accountEventHeader.js +20 -0
  256. package/dist/marginfi-sdk/types/balance.d.ts +32 -0
  257. package/dist/marginfi-sdk/types/balance.d.ts.map +1 -0
  258. package/dist/marginfi-sdk/types/balance.js +25 -0
  259. package/dist/marginfi-sdk/types/balanceDecreaseType.d.ts +17 -0
  260. package/dist/marginfi-sdk/types/balanceDecreaseType.d.ts.map +1 -0
  261. package/dist/marginfi-sdk/types/balanceDecreaseType.js +24 -0
  262. package/dist/marginfi-sdk/types/balanceIncreaseType.d.ts +17 -0
  263. package/dist/marginfi-sdk/types/balanceIncreaseType.d.ts.map +1 -0
  264. package/dist/marginfi-sdk/types/balanceIncreaseType.js +24 -0
  265. package/dist/marginfi-sdk/types/balanceSide.d.ts +15 -0
  266. package/dist/marginfi-sdk/types/balanceSide.d.ts.map +1 -0
  267. package/dist/marginfi-sdk/types/balanceSide.js +22 -0
  268. package/dist/marginfi-sdk/types/bankConfig.d.ts +67 -0
  269. package/dist/marginfi-sdk/types/bankConfig.d.ts.map +1 -0
  270. package/dist/marginfi-sdk/types/bankConfig.js +32 -0
  271. package/dist/marginfi-sdk/types/bankConfigCompact.d.ts +65 -0
  272. package/dist/marginfi-sdk/types/bankConfigCompact.d.ts.map +1 -0
  273. package/dist/marginfi-sdk/types/bankConfigCompact.js +31 -0
  274. package/dist/marginfi-sdk/types/bankOperationalState.d.ts +16 -0
  275. package/dist/marginfi-sdk/types/bankOperationalState.d.ts.map +1 -0
  276. package/dist/marginfi-sdk/types/bankOperationalState.js +23 -0
  277. package/dist/marginfi-sdk/types/bankVaultType.d.ts +16 -0
  278. package/dist/marginfi-sdk/types/bankVaultType.d.ts.map +1 -0
  279. package/dist/marginfi-sdk/types/bankVaultType.js +23 -0
  280. package/dist/marginfi-sdk/types/groupEventHeader.d.ts +19 -0
  281. package/dist/marginfi-sdk/types/groupEventHeader.d.ts.map +1 -0
  282. package/dist/marginfi-sdk/types/groupEventHeader.js +18 -0
  283. package/dist/marginfi-sdk/types/index.d.ts +31 -0
  284. package/dist/marginfi-sdk/types/index.d.ts.map +1 -0
  285. package/dist/marginfi-sdk/types/index.js +46 -0
  286. package/dist/marginfi-sdk/types/interestRateConfig.d.ts +31 -0
  287. package/dist/marginfi-sdk/types/interestRateConfig.d.ts.map +1 -0
  288. package/dist/marginfi-sdk/types/interestRateConfig.js +25 -0
  289. package/dist/marginfi-sdk/types/interestRateConfigCompact.d.ts +29 -0
  290. package/dist/marginfi-sdk/types/interestRateConfigCompact.d.ts.map +1 -0
  291. package/dist/marginfi-sdk/types/interestRateConfigCompact.js +24 -0
  292. package/dist/marginfi-sdk/types/interestRateConfigOpt.d.ts +30 -0
  293. package/dist/marginfi-sdk/types/interestRateConfigOpt.d.ts.map +1 -0
  294. package/dist/marginfi-sdk/types/interestRateConfigOpt.js +24 -0
  295. package/dist/marginfi-sdk/types/lendingAccount.d.ts +19 -0
  296. package/dist/marginfi-sdk/types/lendingAccount.d.ts.map +1 -0
  297. package/dist/marginfi-sdk/types/lendingAccount.js +19 -0
  298. package/dist/marginfi-sdk/types/liquidationBalances.d.ts +17 -0
  299. package/dist/marginfi-sdk/types/liquidationBalances.d.ts.map +1 -0
  300. package/dist/marginfi-sdk/types/liquidationBalances.js +20 -0
  301. package/dist/marginfi-sdk/types/oracleConfig.d.ts +20 -0
  302. package/dist/marginfi-sdk/types/oracleConfig.d.ts.map +1 -0
  303. package/dist/marginfi-sdk/types/oracleConfig.js +19 -0
  304. package/dist/marginfi-sdk/types/oraclePriceType.d.ts +15 -0
  305. package/dist/marginfi-sdk/types/oraclePriceType.d.ts.map +1 -0
  306. package/dist/marginfi-sdk/types/oraclePriceType.js +22 -0
  307. package/dist/marginfi-sdk/types/oracleSetup.d.ts +17 -0
  308. package/dist/marginfi-sdk/types/oracleSetup.d.ts.map +1 -0
  309. package/dist/marginfi-sdk/types/oracleSetup.js +24 -0
  310. package/dist/marginfi-sdk/types/priceBias.d.ts +15 -0
  311. package/dist/marginfi-sdk/types/priceBias.d.ts.map +1 -0
  312. package/dist/marginfi-sdk/types/priceBias.js +22 -0
  313. package/dist/marginfi-sdk/types/requirementType.d.ts +16 -0
  314. package/dist/marginfi-sdk/types/requirementType.d.ts.map +1 -0
  315. package/dist/marginfi-sdk/types/requirementType.js +23 -0
  316. package/dist/marginfi-sdk/types/riskRequirementType.d.ts +16 -0
  317. package/dist/marginfi-sdk/types/riskRequirementType.d.ts.map +1 -0
  318. package/dist/marginfi-sdk/types/riskRequirementType.js +23 -0
  319. package/dist/marginfi-sdk/types/riskTier.d.ts +15 -0
  320. package/dist/marginfi-sdk/types/riskTier.d.ts.map +1 -0
  321. package/dist/marginfi-sdk/types/riskTier.js +22 -0
  322. package/dist/marginfi-sdk/types/wrappedI80F48.d.ts +16 -0
  323. package/dist/marginfi-sdk/types/wrappedI80F48.d.ts.map +1 -0
  324. package/dist/marginfi-sdk/types/wrappedI80F48.js +17 -0
  325. package/dist/transactions/index.d.ts +3 -0
  326. package/dist/transactions/index.d.ts.map +1 -0
  327. package/dist/transactions/index.js +18 -0
  328. package/dist/transactions/transactionUtils.d.ts +12 -0
  329. package/dist/transactions/transactionUtils.d.ts.map +1 -0
  330. package/dist/transactions/transactionUtils.js +262 -0
  331. package/dist/transactions/transactionsManager.d.ts +42 -0
  332. package/dist/transactions/transactionsManager.d.ts.map +1 -0
  333. package/dist/transactions/transactionsManager.js +246 -0
  334. package/dist/types/accounts.d.ts +8 -0
  335. package/dist/types/accounts.d.ts.map +1 -0
  336. package/dist/types/accounts.js +2 -0
  337. package/dist/types/index.d.ts +2 -0
  338. package/dist/types/index.d.ts.map +1 -0
  339. package/dist/types/index.js +17 -0
  340. package/dist/utils/accountUtils.d.ts +11 -0
  341. package/dist/utils/accountUtils.d.ts.map +1 -0
  342. package/dist/utils/accountUtils.js +60 -0
  343. package/dist/utils/deleteme.d.ts +2 -0
  344. package/dist/utils/deleteme.d.ts.map +1 -0
  345. package/dist/utils/deleteme.js +21 -0
  346. package/dist/utils/generalUtils.d.ts +11 -0
  347. package/dist/utils/generalUtils.d.ts.map +1 -0
  348. package/dist/utils/generalUtils.js +107 -0
  349. package/dist/utils/index.d.ts +9 -0
  350. package/dist/utils/index.d.ts.map +1 -0
  351. package/dist/utils/index.js +24 -0
  352. package/dist/utils/jitoUtils.d.ts +15 -0
  353. package/dist/utils/jitoUtils.d.ts.map +1 -0
  354. package/dist/utils/jitoUtils.js +108 -0
  355. package/dist/utils/jupiterUtils.d.ts +21 -0
  356. package/dist/utils/jupiterUtils.d.ts.map +1 -0
  357. package/dist/utils/jupiterUtils.js +61 -0
  358. package/dist/utils/local/shared.d.ts +3 -0
  359. package/dist/utils/local/shared.d.ts.map +1 -0
  360. package/dist/utils/local/shared.js +63 -0
  361. package/dist/utils/local/updateMarginfiLUT.d.ts +2 -0
  362. package/dist/utils/local/updateMarginfiLUT.d.ts.map +1 -0
  363. package/dist/utils/local/updateMarginfiLUT.js +22 -0
  364. package/dist/utils/local/updateSolautoLUT.d.ts +2 -0
  365. package/dist/utils/local/updateSolautoLUT.d.ts.map +1 -0
  366. package/dist/utils/local/updateSolautoLUT.js +13 -0
  367. package/dist/utils/marginfiUtils.d.ts +14 -0
  368. package/dist/utils/marginfiUtils.d.ts.map +1 -0
  369. package/dist/utils/marginfiUtils.js +201 -0
  370. package/dist/utils/numberUtils.d.ts +9 -0
  371. package/dist/utils/numberUtils.d.ts.map +1 -0
  372. package/dist/utils/numberUtils.js +62 -0
  373. package/dist/utils/solanaUtils.d.ts +18 -0
  374. package/dist/utils/solanaUtils.d.ts.map +1 -0
  375. package/dist/utils/solanaUtils.js +183 -0
  376. package/dist/utils/solauto/generalUtils.d.ts +51 -0
  377. package/dist/utils/solauto/generalUtils.d.ts.map +1 -0
  378. package/dist/utils/solauto/generalUtils.js +271 -0
  379. package/dist/utils/solauto/index.d.ts +3 -0
  380. package/dist/utils/solauto/index.d.ts.map +1 -0
  381. package/dist/utils/solauto/index.js +18 -0
  382. package/dist/utils/solauto/rebalanceUtils.d.ts +17 -0
  383. package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -0
  384. package/dist/utils/solauto/rebalanceUtils.js +199 -0
  385. package/package.json +37 -0
  386. package/src/clients/index.ts +1 -0
  387. package/src/clients/solautoClient.ts +684 -0
  388. package/src/clients/solautoMarginfiClient.ts +496 -0
  389. package/src/constants/README.md +9 -0
  390. package/src/constants/generalAccounts.ts +8 -0
  391. package/src/constants/index.ts +5 -0
  392. package/src/constants/marginfiAccounts.ts +24 -0
  393. package/src/constants/pythConstants.ts +10 -0
  394. package/src/constants/solautoConstants.ts +54 -0
  395. package/src/constants/tokenConstants.ts +9 -0
  396. package/src/generated/accounts/index.ts +10 -0
  397. package/src/generated/accounts/referralState.ts +159 -0
  398. package/src/generated/accounts/solautoPosition.ts +205 -0
  399. package/src/generated/errors/index.ts +9 -0
  400. package/src/generated/errors/solauto.ts +228 -0
  401. package/src/generated/index.ts +14 -0
  402. package/src/generated/instructions/cancelDCA.ts +161 -0
  403. package/src/generated/instructions/claimReferralFees.ts +159 -0
  404. package/src/generated/instructions/closePosition.ts +176 -0
  405. package/src/generated/instructions/convertReferralFees.ts +172 -0
  406. package/src/generated/instructions/index.ts +18 -0
  407. package/src/generated/instructions/marginfiOpenPosition.ts +275 -0
  408. package/src/generated/instructions/marginfiProtocolInteraction.ts +257 -0
  409. package/src/generated/instructions/marginfiRebalance.ts +274 -0
  410. package/src/generated/instructions/marginfiRefreshData.ts +147 -0
  411. package/src/generated/instructions/updatePosition.ts +173 -0
  412. package/src/generated/instructions/updateReferralStates.ts +166 -0
  413. package/src/generated/programs/index.ts +9 -0
  414. package/src/generated/programs/solauto.ts +52 -0
  415. package/src/generated/shared/index.ts +117 -0
  416. package/src/generated/types/automationSettings.ts +52 -0
  417. package/src/generated/types/automationSettingsInp.ts +43 -0
  418. package/src/generated/types/dCASettings.ts +45 -0
  419. package/src/generated/types/dCASettingsInp.ts +37 -0
  420. package/src/generated/types/feeType.ts +23 -0
  421. package/src/generated/types/index.ts +26 -0
  422. package/src/generated/types/lendingPlatform.ts +26 -0
  423. package/src/generated/types/podBool.ts +19 -0
  424. package/src/generated/types/positionData.ts +69 -0
  425. package/src/generated/types/positionState.ts +72 -0
  426. package/src/generated/types/positionTokenUsage.ts +67 -0
  427. package/src/generated/types/rebalanceData.ts +60 -0
  428. package/src/generated/types/solautoAction.ts +101 -0
  429. package/src/generated/types/solautoRebalanceType.ts +27 -0
  430. package/src/generated/types/solautoSettingsParameters.ts +62 -0
  431. package/src/generated/types/solautoSettingsParametersInp.ts +58 -0
  432. package/src/generated/types/tokenAmount.ts +29 -0
  433. package/src/generated/types/tokenBalanceAmount.ts +67 -0
  434. package/src/generated/types/updatePositionData.ts +49 -0
  435. package/src/index.ts +6 -0
  436. package/src/marginfi-sdk/accounts/bank.ts +311 -0
  437. package/src/marginfi-sdk/accounts/index.ts +11 -0
  438. package/src/marginfi-sdk/accounts/marginfiAccount.ts +195 -0
  439. package/src/marginfi-sdk/accounts/marginfiGroup.ts +164 -0
  440. package/src/marginfi-sdk/errors/index.ts +9 -0
  441. package/src/marginfi-sdk/errors/marginfi.ts +650 -0
  442. package/src/marginfi-sdk/index.ts +14 -0
  443. package/src/marginfi-sdk/instructions/index.ts +32 -0
  444. package/src/marginfi-sdk/instructions/lendingAccountBorrow.ts +167 -0
  445. package/src/marginfi-sdk/instructions/lendingAccountCloseBalance.ts +118 -0
  446. package/src/marginfi-sdk/instructions/lendingAccountDeposit.ts +164 -0
  447. package/src/marginfi-sdk/instructions/lendingAccountEndFlashloan.ts +113 -0
  448. package/src/marginfi-sdk/instructions/lendingAccountLiquidate.ts +186 -0
  449. package/src/marginfi-sdk/instructions/lendingAccountRepay.ts +171 -0
  450. package/src/marginfi-sdk/instructions/lendingAccountSettleEmissions.ts +108 -0
  451. package/src/marginfi-sdk/instructions/lendingAccountStartFlashloan.ts +138 -0
  452. package/src/marginfi-sdk/instructions/lendingAccountWithdraw.ts +177 -0
  453. package/src/marginfi-sdk/instructions/lendingAccountWithdrawEmissions.ts +160 -0
  454. package/src/marginfi-sdk/instructions/lendingPoolAccrueBankInterest.ts +108 -0
  455. package/src/marginfi-sdk/instructions/lendingPoolAddBank.ts +226 -0
  456. package/src/marginfi-sdk/instructions/lendingPoolAddBankWithSeed.ts +231 -0
  457. package/src/marginfi-sdk/instructions/lendingPoolCollectBankFees.ts +147 -0
  458. package/src/marginfi-sdk/instructions/lendingPoolConfigureBank.ts +181 -0
  459. package/src/marginfi-sdk/instructions/lendingPoolHandleBankruptcy.ts +154 -0
  460. package/src/marginfi-sdk/instructions/lendingPoolSetupEmissions.ts +190 -0
  461. package/src/marginfi-sdk/instructions/lendingPoolUpdateEmissionsParameters.ts +176 -0
  462. package/src/marginfi-sdk/instructions/marginfiAccountInitialize.ts +146 -0
  463. package/src/marginfi-sdk/instructions/marginfiGroupConfigure.ts +129 -0
  464. package/src/marginfi-sdk/instructions/marginfiGroupInitialize.ts +126 -0
  465. package/src/marginfi-sdk/instructions/setAccountFlag.ts +132 -0
  466. package/src/marginfi-sdk/instructions/setNewAccountAuthority.ts +137 -0
  467. package/src/marginfi-sdk/instructions/unsetAccountFlag.ts +130 -0
  468. package/src/marginfi-sdk/programs/index.ts +9 -0
  469. package/src/marginfi-sdk/programs/marginfi.ts +52 -0
  470. package/src/marginfi-sdk/shared/index.ts +117 -0
  471. package/src/marginfi-sdk/types/accountEventHeader.ts +44 -0
  472. package/src/marginfi-sdk/types/balance.ts +61 -0
  473. package/src/marginfi-sdk/types/balanceDecreaseType.ts +27 -0
  474. package/src/marginfi-sdk/types/balanceIncreaseType.ts +27 -0
  475. package/src/marginfi-sdk/types/balanceSide.ts +25 -0
  476. package/src/marginfi-sdk/types/bankConfig.ts +117 -0
  477. package/src/marginfi-sdk/types/bankConfigCompact.ts +114 -0
  478. package/src/marginfi-sdk/types/bankOperationalState.ts +26 -0
  479. package/src/marginfi-sdk/types/bankVaultType.ts +26 -0
  480. package/src/marginfi-sdk/types/groupEventHeader.ts +38 -0
  481. package/src/marginfi-sdk/types/index.ts +31 -0
  482. package/src/marginfi-sdk/types/interestRateConfig.ts +60 -0
  483. package/src/marginfi-sdk/types/interestRateConfigCompact.ts +52 -0
  484. package/src/marginfi-sdk/types/interestRateConfigOpt.ts +57 -0
  485. package/src/marginfi-sdk/types/lendingAccount.ts +38 -0
  486. package/src/marginfi-sdk/types/liquidationBalances.ts +33 -0
  487. package/src/marginfi-sdk/types/oracleConfig.ts +36 -0
  488. package/src/marginfi-sdk/types/oraclePriceType.ts +25 -0
  489. package/src/marginfi-sdk/types/oracleSetup.ts +27 -0
  490. package/src/marginfi-sdk/types/priceBias.ts +22 -0
  491. package/src/marginfi-sdk/types/requirementType.ts +26 -0
  492. package/src/marginfi-sdk/types/riskRequirementType.ts +26 -0
  493. package/src/marginfi-sdk/types/riskTier.ts +22 -0
  494. package/src/marginfi-sdk/types/wrappedI80F48.ts +22 -0
  495. package/src/transactions/index.ts +2 -0
  496. package/src/transactions/transactionUtils.ts +518 -0
  497. package/src/transactions/transactionsManager.ts +344 -0
  498. package/src/types/accounts.ts +7 -0
  499. package/src/types/index.ts +1 -0
  500. package/src/utils/accountUtils.ts +92 -0
  501. package/src/utils/deleteme.ts +40 -0
  502. package/src/utils/generalUtils.ts +123 -0
  503. package/src/utils/index.ts +8 -0
  504. package/src/utils/jitoUtils.ts +192 -0
  505. package/src/utils/jupiterUtils.ts +114 -0
  506. package/src/utils/local/shared.ts +85 -0
  507. package/src/utils/local/updateMarginfiLUT.ts +33 -0
  508. package/src/utils/local/updateSolautoLUT.ts +15 -0
  509. package/src/utils/marginfiUtils.ts +383 -0
  510. package/src/utils/numberUtils.ts +77 -0
  511. package/src/utils/solanaUtils.ts +333 -0
  512. package/src/utils/solauto/generalUtils.ts +371 -0
  513. package/src/utils/solauto/index.ts +2 -0
  514. package/src/utils/solauto/rebalanceUtils.ts +359 -0
  515. package/tests/shared.ts +15 -0
  516. package/tests/transactions/solautoMarginfi.ts +144 -0
  517. package/tests/unit/lookupTables.ts +40 -0
  518. package/tests/unit/rebalanceCalculations.ts +432 -0
  519. package/tsconfig.json +22 -0
@@ -0,0 +1,518 @@
1
+ import {
2
+ Signer,
3
+ TransactionBuilder,
4
+ publicKey,
5
+ transactionBuilder,
6
+ } from "@metaplex-foundation/umi";
7
+ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
8
+ import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY } from "@solana/web3.js";
9
+ import {
10
+ ACCOUNT_SIZE as TOKEN_ACCOUNT_SIZE,
11
+ NATIVE_MINT,
12
+ Account as SplTokenAccount,
13
+ } from "@solana/spl-token";
14
+ import {
15
+ LendingPlatform,
16
+ ReferralState,
17
+ SOLAUTO_PROGRAM_ID,
18
+ SolautoAction,
19
+ SolautoRebalanceType,
20
+ convertReferralFees,
21
+ getMarginfiProtocolInteractionInstructionDataSerializer,
22
+ isSolautoAction,
23
+ solautoAction,
24
+ } from "../generated";
25
+ import { SolautoClient } from "../clients/solautoClient";
26
+ import {
27
+ closeTokenAccountUmiIx,
28
+ createAssociatedTokenAccountUmiIx,
29
+ systemTransferUmiIx,
30
+ } from "../utils/solanaUtils";
31
+ import { getJupSwapTransaction } from "../utils/jupiterUtils";
32
+ import {
33
+ getFlashLoanDetails,
34
+ getJupSwapRebalanceDetails,
35
+ getRebalanceValues,
36
+ } from "../utils/solauto/rebalanceUtils";
37
+ import {
38
+ getSolanaAccountCreated,
39
+ rpcAccountCreated,
40
+ } from "../utils/generalUtils";
41
+ import { SolautoMarginfiClient } from "../clients/solautoMarginfiClient";
42
+ import { UMI } from "../constants/solautoConstants";
43
+ import { uint8ArrayToBigInt } from "../utils/numberUtils";
44
+ import {
45
+ eligibileForRebalance,
46
+ getMaxLiqUtilizationRate,
47
+ } from "../utils/solauto/generalUtils";
48
+ import { getTokenAccount } from "../utils/accountUtils";
49
+
50
+ interface wSolTokenUsage {
51
+ wSolTokenAccount: PublicKey;
52
+ solautoAction: SolautoAction;
53
+ }
54
+
55
+ function getWSolUsage(
56
+ client: SolautoClient,
57
+ solautoActions?: SolautoAction[],
58
+ initiatingDcaIn?: bigint,
59
+ cancellingDcaIn?: boolean
60
+ ): wSolTokenUsage | undefined {
61
+ const supplyIsWsol = client.supplyLiquidityMint.equals(NATIVE_MINT);
62
+ const debtIsWsol = client.debtLiquidityMint.equals(NATIVE_MINT);
63
+ if (!supplyIsWsol && !debtIsWsol) {
64
+ return undefined;
65
+ }
66
+
67
+ const usingSupplyTaAction = solautoActions?.find(
68
+ (args) =>
69
+ isSolautoAction("Deposit", args) || isSolautoAction("Withdraw", args)
70
+ );
71
+ const usingDebtTaAction = solautoActions?.find(
72
+ (args) =>
73
+ isSolautoAction("Borrow", args) ||
74
+ isSolautoAction("Repay", args) ||
75
+ initiatingDcaIn ||
76
+ cancellingDcaIn
77
+ );
78
+ if (supplyIsWsol && usingSupplyTaAction) {
79
+ return {
80
+ wSolTokenAccount: client.signerSupplyLiquidityTa,
81
+ solautoAction: usingSupplyTaAction,
82
+ };
83
+ } else if (debtIsWsol && usingDebtTaAction) {
84
+ return {
85
+ wSolTokenAccount: client.signerDebtLiquidityTa,
86
+ solautoAction: usingDebtTaAction,
87
+ };
88
+ } else {
89
+ return undefined;
90
+ }
91
+ }
92
+
93
+ async function transactionChoresBefore(
94
+ client: SolautoClient,
95
+ solautoActions?: SolautoAction[],
96
+ initiatingDcaIn?: bigint
97
+ ): Promise<TransactionBuilder> {
98
+ const accountsGettingCreated: string[] = [];
99
+ let chores = transactionBuilder();
100
+
101
+ if (
102
+ client.authorityReferralStateData === null ||
103
+ (client.referredByState !== undefined &&
104
+ client.authorityReferralStateData.referredByState ===
105
+ publicKey(PublicKey.default)) ||
106
+ (client.authorityLutAddress !== undefined &&
107
+ client.authorityReferralStateData.lookupTable ==
108
+ publicKey(PublicKey.default))
109
+ ) {
110
+ chores = chores.add(client.updateReferralStatesIx());
111
+ }
112
+
113
+ if (client.selfManaged && client.solautoPositionData === undefined) {
114
+ chores = chores.add(client.openPosition());
115
+ }
116
+
117
+ const wSolUsage = getWSolUsage(
118
+ client,
119
+ solautoActions,
120
+ initiatingDcaIn,
121
+ undefined
122
+ );
123
+ if (wSolUsage !== undefined) {
124
+ if (!getSolanaAccountCreated(wSolUsage.wSolTokenAccount)) {
125
+ client.log(`Closing signer wSol TA`);
126
+ chores = chores.add(
127
+ closeTokenAccountUmiIx(
128
+ client.signer,
129
+ wSolUsage.wSolTokenAccount,
130
+ toWeb3JsPublicKey(client.signer.publicKey)
131
+ )
132
+ );
133
+ }
134
+
135
+ let amountToTransfer = BigInt(0);
136
+ if (isSolautoAction("Deposit", wSolUsage.solautoAction)) {
137
+ amountToTransfer += BigInt(wSolUsage.solautoAction.fields[0]);
138
+ } else if (
139
+ isSolautoAction("Repay", wSolUsage.solautoAction) &&
140
+ wSolUsage.solautoAction.fields[0].__kind === "Some"
141
+ ) {
142
+ amountToTransfer += BigInt(wSolUsage.solautoAction.fields[0].fields[0]);
143
+ } else if (
144
+ initiatingDcaIn &&
145
+ client.debtLiquidityMint.toString() === NATIVE_MINT.toString()
146
+ ) {
147
+ amountToTransfer += initiatingDcaIn;
148
+ }
149
+
150
+ if (amountToTransfer > 0) {
151
+ const amount =
152
+ amountToTransfer +
153
+ (await UMI.rpc.getRent(TOKEN_ACCOUNT_SIZE)).basisPoints;
154
+ client.log(`Transferring ${amount} lamports to signer wSol TA`);
155
+ chores = chores.add(
156
+ systemTransferUmiIx(client.signer, wSolUsage.wSolTokenAccount, amount)
157
+ );
158
+ }
159
+
160
+ client.log("Creating signer wSol TA");
161
+ chores = chores.add(
162
+ createAssociatedTokenAccountUmiIx(
163
+ client.signer,
164
+ toWeb3JsPublicKey(client.signer.publicKey),
165
+ NATIVE_MINT
166
+ )
167
+ );
168
+ accountsGettingCreated.push(wSolUsage.wSolTokenAccount.toString());
169
+ }
170
+
171
+ for (const solautoAction of solautoActions ?? []) {
172
+ if (
173
+ !isSolautoAction("Withdraw", solautoAction) &&
174
+ !isSolautoAction("Borrow", solautoAction)
175
+ ) {
176
+ continue;
177
+ }
178
+
179
+ const tokenAccount = isSolautoAction("Withdraw", solautoAction)
180
+ ? client.signerSupplyLiquidityTa
181
+ : client.signerDebtLiquidityTa;
182
+ if (accountsGettingCreated.includes(tokenAccount.toString())) {
183
+ continue;
184
+ }
185
+
186
+ if (!getSolanaAccountCreated(tokenAccount)) {
187
+ chores = chores.add(
188
+ createAssociatedTokenAccountUmiIx(
189
+ client.signer,
190
+ toWeb3JsPublicKey(client.signer.publicKey),
191
+ isSolautoAction("Withdraw", solautoAction)
192
+ ? client.supplyLiquidityMint
193
+ : client.debtLiquidityMint
194
+ )
195
+ );
196
+ accountsGettingCreated.push(tokenAccount.toString());
197
+ }
198
+ }
199
+
200
+ return chores;
201
+ }
202
+
203
+ export async function rebalanceChoresBefore(
204
+ client: SolautoClient,
205
+ tx: TransactionBuilder
206
+ ): Promise<TransactionBuilder> {
207
+ const usesAccount = (key: PublicKey) =>
208
+ tx
209
+ .getInstructions()
210
+ .some((t) => t.keys.some((k) => toWeb3JsPublicKey(k.pubkey).equals(key)));
211
+
212
+ const checkReferralSupplyTa =
213
+ client.referredBySupplyTa && usesAccount(client.referredBySupplyTa);
214
+ const checkSolautoFeesTa = usesAccount(client.solautoFeesSupplyTa);
215
+ const checkIntermediaryMfiAccount =
216
+ client.lendingPlatform === LendingPlatform.Marginfi &&
217
+ usesAccount(
218
+ (client as SolautoMarginfiClient).intermediaryMarginfiAccountPk
219
+ );
220
+
221
+ const accountsNeeded = [
222
+ ...[checkReferralSupplyTa ? client.referredBySupplyTa : PublicKey.default],
223
+ ...[checkSolautoFeesTa ? client.solautoFeesSupplyTa : PublicKey.default],
224
+ ...[
225
+ checkIntermediaryMfiAccount
226
+ ? (client as SolautoMarginfiClient).intermediaryMarginfiAccountPk
227
+ : PublicKey.default,
228
+ ],
229
+ ];
230
+
231
+ const [referredBySupplyTa, solautoFeesSupplyTa, intermediaryMarginfiAccount] =
232
+ await UMI.rpc.getAccounts(
233
+ accountsNeeded.map((x) => publicKey(x ?? PublicKey.default))
234
+ );
235
+
236
+ let chores = transactionBuilder();
237
+
238
+ if (checkReferralSupplyTa && !rpcAccountCreated(referredBySupplyTa)) {
239
+ client.log(
240
+ "Creating referred-by TA for ",
241
+ client.supplyLiquidityMint.toString()
242
+ );
243
+ chores = chores.add(
244
+ createAssociatedTokenAccountUmiIx(
245
+ client.signer,
246
+ client.referredByState!,
247
+ client.supplyLiquidityMint
248
+ )
249
+ );
250
+ }
251
+
252
+ if (checkSolautoFeesTa && !rpcAccountCreated(solautoFeesSupplyTa)) {
253
+ client.log(
254
+ "Creating Solauto fees TA for ",
255
+ client.supplyLiquidityMint.toString()
256
+ );
257
+ chores = chores.add(
258
+ createAssociatedTokenAccountUmiIx(
259
+ client.signer,
260
+ client.solautoFeesWallet,
261
+ client.supplyLiquidityMint
262
+ )
263
+ );
264
+ }
265
+
266
+ if (
267
+ checkIntermediaryMfiAccount &&
268
+ !rpcAccountCreated(intermediaryMarginfiAccount)
269
+ ) {
270
+ chores = chores.add(
271
+ (client as SolautoMarginfiClient).createIntermediaryMarginfiAccount()
272
+ );
273
+ }
274
+
275
+ return chores;
276
+ }
277
+
278
+ function transactionChoresAfter(
279
+ client: SolautoClient,
280
+ solautoActions?: SolautoAction[],
281
+ cancellingDcaIn?: boolean
282
+ ): TransactionBuilder {
283
+ let chores = transactionBuilder();
284
+
285
+ const wSolUsage = getWSolUsage(
286
+ client,
287
+ solautoActions,
288
+ undefined,
289
+ cancellingDcaIn
290
+ );
291
+ if (wSolUsage) {
292
+ chores = chores.add(
293
+ closeTokenAccountUmiIx(
294
+ client.signer,
295
+ wSolUsage.wSolTokenAccount,
296
+ toWeb3JsPublicKey(client.signer.publicKey)
297
+ )
298
+ );
299
+ }
300
+
301
+ return chores;
302
+ }
303
+
304
+ function getSolautoActions(tx: TransactionBuilder): SolautoAction[] {
305
+ let solautoActions: SolautoAction[] = [];
306
+
307
+ tx.getInstructions().forEach((x) => {
308
+ if (x.programId !== SOLAUTO_PROGRAM_ID) {
309
+ return;
310
+ }
311
+
312
+ try {
313
+ const serializer =
314
+ getMarginfiProtocolInteractionInstructionDataSerializer();
315
+ const discriminator = uint8ArrayToBigInt(
316
+ serializer
317
+ .serialize({
318
+ solautoAction: solautoAction("Deposit", [BigInt(0)]),
319
+ })
320
+ .slice(0, 8)
321
+ );
322
+ const [data, _] = serializer.deserialize(x.data);
323
+ if (BigInt(data.discriminator) === discriminator) {
324
+ solautoActions?.push(data.solautoAction);
325
+ }
326
+ } catch {}
327
+
328
+ // TODO support other platforms
329
+ });
330
+
331
+ return solautoActions;
332
+ }
333
+
334
+ export async function getTransactionChores(
335
+ client: SolautoClient,
336
+ tx: TransactionBuilder
337
+ ): Promise<[TransactionBuilder, TransactionBuilder]> {
338
+ let choresBefore = transactionBuilder();
339
+ let choresAfter = transactionBuilder();
340
+
341
+ const solautoActions = getSolautoActions(tx);
342
+
343
+ choresBefore = choresBefore.add([
344
+ await transactionChoresBefore(
345
+ client,
346
+ solautoActions,
347
+ client.livePositionUpdates.debtTaBalanceAdjustment > 0
348
+ ? client.livePositionUpdates.debtTaBalanceAdjustment
349
+ : undefined
350
+ ),
351
+ await rebalanceChoresBefore(client, tx),
352
+ ]);
353
+
354
+ choresAfter = choresAfter.add(
355
+ transactionChoresAfter(
356
+ client,
357
+ solautoActions,
358
+ client.livePositionUpdates.debtTaBalanceAdjustment < 0
359
+ )
360
+ );
361
+
362
+ return [choresBefore, choresAfter];
363
+ }
364
+
365
+ export async function buildSolautoRebalanceTransaction(
366
+ client: SolautoClient,
367
+ targetLiqUtilizationRateBps?: number,
368
+ attemptNum?: number
369
+ ): Promise<
370
+ | {
371
+ tx: TransactionBuilder;
372
+ lookupTableAddresses: string[];
373
+ }
374
+ | undefined
375
+ > {
376
+ client.solautoPositionState = await client.getFreshPositionState();
377
+ if (
378
+ targetLiqUtilizationRateBps === undefined &&
379
+ !eligibileForRebalance(
380
+ client.solautoPositionState!,
381
+ client.livePositionUpdates.settings ??
382
+ client.solautoPositionData?.position.settingParams!,
383
+ client.livePositionUpdates.activeDca ??
384
+ client.solautoPositionData?.position.dca!
385
+ )
386
+ ) {
387
+ client.log("Not eligible for a rebalance");
388
+ return undefined;
389
+ }
390
+
391
+ const values = getRebalanceValues(client, targetLiqUtilizationRateBps);
392
+ client.log("Rebalance values: ", values);
393
+
394
+ const swapDetails = getJupSwapRebalanceDetails(
395
+ client,
396
+ values,
397
+ targetLiqUtilizationRateBps,
398
+ attemptNum
399
+ );
400
+ const {
401
+ jupQuote,
402
+ lookupTableAddresses,
403
+ setupInstructions,
404
+ tokenLedgerIx,
405
+ swapIx,
406
+ } = await getJupSwapTransaction(client.signer, swapDetails);
407
+ const flashLoan = getFlashLoanDetails(client, values, jupQuote);
408
+
409
+ let tx = transactionBuilder();
410
+
411
+ if (flashLoan) {
412
+ client.log("Flash loan details: ", flashLoan);
413
+ const addFirstRebalance = values.amountUsdToDcaIn > 0;
414
+ const rebalanceType = addFirstRebalance
415
+ ? SolautoRebalanceType.DoubleRebalanceWithFL
416
+ : SolautoRebalanceType.SingleRebalanceWithFL;
417
+
418
+ tx = tx.add([
419
+ setupInstructions,
420
+ tokenLedgerIx,
421
+ client.flashBorrow(
422
+ flashLoan,
423
+ getTokenAccount(
424
+ toWeb3JsPublicKey(client.signer.publicKey),
425
+ swapDetails.inputMint
426
+ )
427
+ ),
428
+ ...(addFirstRebalance
429
+ ? [
430
+ client.rebalance(
431
+ "A",
432
+ swapDetails,
433
+ rebalanceType,
434
+ targetLiqUtilizationRateBps
435
+ ),
436
+ ]
437
+ : []),
438
+ swapIx,
439
+ client.rebalance(
440
+ "B",
441
+ swapDetails,
442
+ rebalanceType,
443
+ targetLiqUtilizationRateBps
444
+ ),
445
+ client.flashRepay(flashLoan),
446
+ ]);
447
+ } else {
448
+ const rebalanceType = SolautoRebalanceType.Regular;
449
+ tx = tx.add([
450
+ setupInstructions,
451
+ tokenLedgerIx,
452
+ client.rebalance(
453
+ "A",
454
+ swapDetails,
455
+ rebalanceType,
456
+ targetLiqUtilizationRateBps
457
+ ),
458
+ swapIx,
459
+ client.rebalance(
460
+ "B",
461
+ swapDetails,
462
+ rebalanceType,
463
+ targetLiqUtilizationRateBps
464
+ ),
465
+ ]);
466
+ }
467
+
468
+ if (
469
+ client.solautoPositionState!.liqUtilizationRateBps >
470
+ getMaxLiqUtilizationRate(
471
+ client.solautoPositionState!.maxLtvBps,
472
+ client.solautoPositionState!.liqThresholdBps
473
+ )
474
+ ) {
475
+ tx = tx.prepend(client.refresh());
476
+ }
477
+
478
+ return {
479
+ tx,
480
+ lookupTableAddresses,
481
+ };
482
+ }
483
+
484
+ export async function convertReferralFeesToDestination(
485
+ referralState: ReferralState,
486
+ tokenAccount: SplTokenAccount,
487
+ signer: Signer
488
+ ): Promise<[TransactionBuilder, string[]]> {
489
+ const { lookupTableAddresses, setupInstructions, swapIx } =
490
+ await getJupSwapTransaction(signer, {
491
+ amount: tokenAccount.amount,
492
+ destinationWallet: toWeb3JsPublicKey(referralState.publicKey),
493
+ inputMint: tokenAccount.mint,
494
+ outputMint: toWeb3JsPublicKey(referralState.destFeesMint),
495
+ exactIn: true,
496
+ slippageBpsIncFactor: 0.15,
497
+ });
498
+
499
+ let tx = transactionBuilder()
500
+ .add(setupInstructions)
501
+ .add(
502
+ convertReferralFees(UMI, {
503
+ signer,
504
+ intermediaryTa: publicKey(
505
+ getTokenAccount(
506
+ toWeb3JsPublicKey(signer.publicKey),
507
+ toWeb3JsPublicKey(referralState.destFeesMint)
508
+ )
509
+ ),
510
+ ixsSysvar: publicKey(SYSVAR_INSTRUCTIONS_PUBKEY),
511
+ referralState: referralState.publicKey,
512
+ referralFeesTa: publicKey(tokenAccount.address),
513
+ })
514
+ )
515
+ .add(swapIx);
516
+
517
+ return [tx, lookupTableAddresses];
518
+ }