@drift-labs/sdk-browser 2.104.0-beta.21

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 (935) hide show
  1. package/README.md +276 -0
  2. package/VERSION +1 -0
  3. package/bun.lockb +0 -0
  4. package/get_events.ts +47 -0
  5. package/lib/browser/accounts/basicUserAccountSubscriber.d.ts +27 -0
  6. package/lib/browser/accounts/basicUserAccountSubscriber.js +38 -0
  7. package/lib/browser/accounts/bulkAccountLoader.d.ts +37 -0
  8. package/lib/browser/accounts/bulkAccountLoader.js +222 -0
  9. package/lib/browser/accounts/bulkUserStatsSubscription.d.ts +7 -0
  10. package/lib/browser/accounts/bulkUserStatsSubscription.js +21 -0
  11. package/lib/browser/accounts/bulkUserSubscription.d.ts +7 -0
  12. package/lib/browser/accounts/bulkUserSubscription.js +21 -0
  13. package/lib/browser/accounts/fetch.d.ts +6 -0
  14. package/lib/browser/accounts/fetch.js +30 -0
  15. package/lib/browser/accounts/grpcAccountSubscriber.d.ts +16 -0
  16. package/lib/browser/accounts/grpcAccountSubscriber.js +154 -0
  17. package/lib/browser/accounts/grpcDriftClientAccountSubscriber.d.ts +12 -0
  18. package/lib/browser/accounts/grpcDriftClientAccountSubscriber.js +98 -0
  19. package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +10 -0
  20. package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.js +30 -0
  21. package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +18 -0
  22. package/lib/browser/accounts/grpcProgramAccountSubscriber.js +171 -0
  23. package/lib/browser/accounts/grpcUserAccountSubscriber.d.ts +10 -0
  24. package/lib/browser/accounts/grpcUserAccountSubscriber.js +28 -0
  25. package/lib/browser/accounts/grpcUserStatsAccountSubscriber.d.ts +10 -0
  26. package/lib/browser/accounts/grpcUserStatsAccountSubscriber.js +28 -0
  27. package/lib/browser/accounts/oneShotUserAccountSubscriber.d.ts +18 -0
  28. package/lib/browser/accounts/oneShotUserAccountSubscriber.js +48 -0
  29. package/lib/browser/accounts/pollingDriftClientAccountSubscriber.d.ts +69 -0
  30. package/lib/browser/accounts/pollingDriftClientAccountSubscriber.js +418 -0
  31. package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +29 -0
  32. package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +111 -0
  33. package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +29 -0
  34. package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.js +110 -0
  35. package/lib/browser/accounts/pollingOracleAccountSubscriber.d.ts +27 -0
  36. package/lib/browser/accounts/pollingOracleAccountSubscriber.js +78 -0
  37. package/lib/browser/accounts/pollingTokenAccountSubscriber.d.ts +26 -0
  38. package/lib/browser/accounts/pollingTokenAccountSubscriber.js +78 -0
  39. package/lib/browser/accounts/pollingUserAccountSubscriber.d.ts +29 -0
  40. package/lib/browser/accounts/pollingUserAccountSubscriber.js +102 -0
  41. package/lib/browser/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
  42. package/lib/browser/accounts/pollingUserStatsAccountSubscriber.js +94 -0
  43. package/lib/browser/accounts/testBulkAccountLoader.d.ts +4 -0
  44. package/lib/browser/accounts/testBulkAccountLoader.js +45 -0
  45. package/lib/browser/accounts/types.d.ts +168 -0
  46. package/lib/browser/accounts/types.js +16 -0
  47. package/lib/browser/accounts/utils.d.ts +8 -0
  48. package/lib/browser/accounts/utils.js +49 -0
  49. package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +29 -0
  50. package/lib/browser/accounts/webSocketAccountSubscriber.js +149 -0
  51. package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.d.ts +66 -0
  52. package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.js +358 -0
  53. package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +23 -0
  54. package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +69 -0
  55. package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +23 -0
  56. package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +67 -0
  57. package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +32 -0
  58. package/lib/browser/accounts/webSocketProgramAccountSubscriber.js +120 -0
  59. package/lib/browser/accounts/webSocketUserAccountSubscriber.d.ts +23 -0
  60. package/lib/browser/accounts/webSocketUserAccountSubscriber.js +61 -0
  61. package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.d.ts +22 -0
  62. package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.js +52 -0
  63. package/lib/browser/addresses/marketAddresses.d.ts +2 -0
  64. package/lib/browser/addresses/marketAddresses.js +15 -0
  65. package/lib/browser/addresses/pda.d.ts +32 -0
  66. package/lib/browser/addresses/pda.js +211 -0
  67. package/lib/browser/adminClient.d.ts +206 -0
  68. package/lib/browser/adminClient.js +1858 -0
  69. package/lib/browser/assert/assert.d.ts +1 -0
  70. package/lib/browser/assert/assert.js +9 -0
  71. package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +14 -0
  72. package/lib/browser/auctionSubscriber/auctionSubscriber.js +32 -0
  73. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +15 -0
  74. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +32 -0
  75. package/lib/browser/auctionSubscriber/index.d.ts +3 -0
  76. package/lib/browser/auctionSubscriber/index.js +19 -0
  77. package/lib/browser/auctionSubscriber/types.d.ts +14 -0
  78. package/lib/browser/auctionSubscriber/types.js +2 -0
  79. package/lib/browser/bankrun/bankrunConnection.d.ts +75 -0
  80. package/lib/browser/bankrun/bankrunConnection.js +332 -0
  81. package/lib/browser/blockhashSubscriber/BlockhashSubscriber.d.ts +27 -0
  82. package/lib/browser/blockhashSubscriber/BlockhashSubscriber.js +89 -0
  83. package/lib/browser/blockhashSubscriber/index.d.ts +1 -0
  84. package/lib/browser/blockhashSubscriber/index.js +17 -0
  85. package/lib/browser/blockhashSubscriber/types.d.ts +7 -0
  86. package/lib/browser/blockhashSubscriber/types.js +2 -0
  87. package/lib/browser/clock/clockSubscriber.d.ts +31 -0
  88. package/lib/browser/clock/clockSubscriber.js +80 -0
  89. package/lib/browser/config.d.ts +60 -0
  90. package/lib/browser/config.js +130 -0
  91. package/lib/browser/constants/numericConstants.d.ts +71 -0
  92. package/lib/browser/constants/numericConstants.js +75 -0
  93. package/lib/browser/constants/perpMarkets.d.ts +19 -0
  94. package/lib/browser/constants/perpMarkets.js +997 -0
  95. package/lib/browser/constants/spotMarkets.d.ts +24 -0
  96. package/lib/browser/constants/spotMarkets.js +470 -0
  97. package/lib/browser/constants/txConstants.d.ts +1 -0
  98. package/lib/browser/constants/txConstants.js +4 -0
  99. package/lib/browser/decode/phoenix.d.ts +7 -0
  100. package/lib/browser/decode/phoenix.js +159 -0
  101. package/lib/browser/decode/user.d.ts +4 -0
  102. package/lib/browser/decode/user.js +339 -0
  103. package/lib/browser/dlob/DLOB.d.ts +186 -0
  104. package/lib/browser/dlob/DLOB.js +1039 -0
  105. package/lib/browser/dlob/DLOBNode.d.ts +68 -0
  106. package/lib/browser/dlob/DLOBNode.js +100 -0
  107. package/lib/browser/dlob/DLOBSubscriber.d.ts +54 -0
  108. package/lib/browser/dlob/DLOBSubscriber.js +139 -0
  109. package/lib/browser/dlob/NodeList.d.ts +25 -0
  110. package/lib/browser/dlob/NodeList.js +126 -0
  111. package/lib/browser/dlob/orderBookLevels.d.ts +72 -0
  112. package/lib/browser/dlob/orderBookLevels.js +438 -0
  113. package/lib/browser/dlob/types.d.ts +18 -0
  114. package/lib/browser/dlob/types.js +2 -0
  115. package/lib/browser/driftClient.d.ts +861 -0
  116. package/lib/browser/driftClient.js +4768 -0
  117. package/lib/browser/driftClientConfig.d.ts +49 -0
  118. package/lib/browser/driftClientConfig.js +2 -0
  119. package/lib/browser/events/eventList.d.ts +22 -0
  120. package/lib/browser/events/eventList.js +80 -0
  121. package/lib/browser/events/eventSubscriber.d.ts +46 -0
  122. package/lib/browser/events/eventSubscriber.js +223 -0
  123. package/lib/browser/events/eventsServerLogProvider.d.ts +21 -0
  124. package/lib/browser/events/eventsServerLogProvider.js +121 -0
  125. package/lib/browser/events/fetchLogs.d.ts +25 -0
  126. package/lib/browser/events/fetchLogs.js +99 -0
  127. package/lib/browser/events/parse.d.ts +6 -0
  128. package/lib/browser/events/parse.js +106 -0
  129. package/lib/browser/events/pollingLogProvider.d.ts +17 -0
  130. package/lib/browser/events/pollingLogProvider.js +58 -0
  131. package/lib/browser/events/sort.d.ts +2 -0
  132. package/lib/browser/events/sort.js +24 -0
  133. package/lib/browser/events/txEventCache.d.ts +24 -0
  134. package/lib/browser/events/txEventCache.js +71 -0
  135. package/lib/browser/events/types.d.ts +79 -0
  136. package/lib/browser/events/types.js +32 -0
  137. package/lib/browser/events/webSocketLogProvider.d.ts +24 -0
  138. package/lib/browser/events/webSocketLogProvider.js +96 -0
  139. package/lib/browser/factory/bigNum.d.ts +122 -0
  140. package/lib/browser/factory/bigNum.js +457 -0
  141. package/lib/browser/factory/oracleClient.d.ts +5 -0
  142. package/lib/browser/factory/oracleClient.js +56 -0
  143. package/lib/browser/idl/drift.json +14440 -0
  144. package/lib/browser/idl/openbook.json +3854 -0
  145. package/lib/browser/idl/pyth_solana_receiver.json +628 -0
  146. package/lib/browser/idl/switchboard.json +8354 -0
  147. package/lib/browser/idl/switchboard_on_demand_30.json +4546 -0
  148. package/lib/browser/idl/token_faucet.json +142 -0
  149. package/lib/browser/index.d.ts +125 -0
  150. package/lib/browser/index.js +147 -0
  151. package/lib/browser/isomorphic/grpc.browser.d.ts +1 -0
  152. package/lib/browser/isomorphic/grpc.browser.js +8 -0
  153. package/lib/browser/isomorphic/grpc.d.ts +1 -0
  154. package/lib/browser/isomorphic/grpc.js +8 -0
  155. package/lib/browser/jupiter/jupiterClient.d.ts +302 -0
  156. package/lib/browser/jupiter/jupiterClient.js +178 -0
  157. package/lib/browser/keypair.d.ts +2 -0
  158. package/lib/browser/keypair.js +28 -0
  159. package/lib/browser/marinade/index.d.ts +12 -0
  160. package/lib/browser/marinade/index.js +36 -0
  161. package/lib/browser/marinade/types.d.ts +1963 -0
  162. package/lib/browser/marinade/types.js +1965 -0
  163. package/lib/browser/math/amm.d.ts +98 -0
  164. package/lib/browser/math/amm.js +626 -0
  165. package/lib/browser/math/auction.d.ts +23 -0
  166. package/lib/browser/math/auction.js +130 -0
  167. package/lib/browser/math/bankruptcy.d.ts +2 -0
  168. package/lib/browser/math/bankruptcy.js +31 -0
  169. package/lib/browser/math/conversion.d.ts +2 -0
  170. package/lib/browser/math/conversion.js +11 -0
  171. package/lib/browser/math/exchangeStatus.d.ts +6 -0
  172. package/lib/browser/math/exchangeStatus.js +77 -0
  173. package/lib/browser/math/fuel.d.ts +6 -0
  174. package/lib/browser/math/fuel.js +55 -0
  175. package/lib/browser/math/funding.d.ts +34 -0
  176. package/lib/browser/math/funding.js +209 -0
  177. package/lib/browser/math/insurance.d.ts +7 -0
  178. package/lib/browser/math/insurance.js +73 -0
  179. package/lib/browser/math/margin.d.ts +39 -0
  180. package/lib/browser/math/margin.js +184 -0
  181. package/lib/browser/math/market.d.ts +39 -0
  182. package/lib/browser/math/market.js +163 -0
  183. package/lib/browser/math/oracles.d.ts +14 -0
  184. package/lib/browser/math/oracles.js +134 -0
  185. package/lib/browser/math/orders.d.ts +23 -0
  186. package/lib/browser/math/orders.js +216 -0
  187. package/lib/browser/math/position.d.ts +70 -0
  188. package/lib/browser/math/position.js +225 -0
  189. package/lib/browser/math/repeg.d.ts +22 -0
  190. package/lib/browser/math/repeg.js +164 -0
  191. package/lib/browser/math/spotBalance.d.ts +83 -0
  192. package/lib/browser/math/spotBalance.js +373 -0
  193. package/lib/browser/math/spotMarket.d.ts +11 -0
  194. package/lib/browser/math/spotMarket.js +49 -0
  195. package/lib/browser/math/spotPosition.d.ts +19 -0
  196. package/lib/browser/math/spotPosition.js +78 -0
  197. package/lib/browser/math/state.d.ts +5 -0
  198. package/lib/browser/math/state.js +30 -0
  199. package/lib/browser/math/superStake.d.ts +167 -0
  200. package/lib/browser/math/superStake.js +306 -0
  201. package/lib/browser/math/tiers.d.ts +4 -0
  202. package/lib/browser/math/tiers.js +52 -0
  203. package/lib/browser/math/trade.d.ts +117 -0
  204. package/lib/browser/math/trade.js +637 -0
  205. package/lib/browser/math/userStatus.d.ts +2 -0
  206. package/lib/browser/math/userStatus.js +8 -0
  207. package/lib/browser/math/utils.d.ts +23 -0
  208. package/lib/browser/math/utils.js +112 -0
  209. package/lib/browser/memcmp.d.ts +11 -0
  210. package/lib/browser/memcmp.js +99 -0
  211. package/lib/browser/openbook/openbookV2FulfillmentConfigMap.d.ts +10 -0
  212. package/lib/browser/openbook/openbookV2FulfillmentConfigMap.js +17 -0
  213. package/lib/browser/openbook/openbookV2Subscriber.d.ts +36 -0
  214. package/lib/browser/openbook/openbookV2Subscriber.js +104 -0
  215. package/lib/browser/oracles/oracleClientCache.d.ts +9 -0
  216. package/lib/browser/oracles/oracleClientCache.js +19 -0
  217. package/lib/browser/oracles/oracleId.d.ts +4 -0
  218. package/lib/browser/oracles/oracleId.js +38 -0
  219. package/lib/browser/oracles/prelaunchOracleClient.d.ts +12 -0
  220. package/lib/browser/oracles/prelaunchOracleClient.js +24 -0
  221. package/lib/browser/oracles/pythClient.d.ts +14 -0
  222. package/lib/browser/oracles/pythClient.js +51 -0
  223. package/lib/browser/oracles/pythLazerClient.d.ts +16 -0
  224. package/lib/browser/oracles/pythLazerClient.js +61 -0
  225. package/lib/browser/oracles/pythPullClient.d.ts +19 -0
  226. package/lib/browser/oracles/pythPullClient.js +60 -0
  227. package/lib/browser/oracles/quoteAssetOracleClient.d.ts +10 -0
  228. package/lib/browser/oracles/quoteAssetOracleClient.js +21 -0
  229. package/lib/browser/oracles/strictOraclePrice.d.ts +9 -0
  230. package/lib/browser/oracles/strictOraclePrice.js +17 -0
  231. package/lib/browser/oracles/switchboardClient.d.ts +12 -0
  232. package/lib/browser/oracles/switchboardClient.js +40 -0
  233. package/lib/browser/oracles/switchboardOnDemandClient.d.ts +12 -0
  234. package/lib/browser/oracles/switchboardOnDemandClient.js +32 -0
  235. package/lib/browser/oracles/types.d.ts +23 -0
  236. package/lib/browser/oracles/types.js +2 -0
  237. package/lib/browser/orderParams.d.ts +29 -0
  238. package/lib/browser/orderParams.js +44 -0
  239. package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +42 -0
  240. package/lib/browser/orderSubscriber/OrderSubscriber.js +172 -0
  241. package/lib/browser/orderSubscriber/PollingSubscription.d.ts +12 -0
  242. package/lib/browser/orderSubscriber/PollingSubscription.js +23 -0
  243. package/lib/browser/orderSubscriber/WebsocketSubscription.d.ts +23 -0
  244. package/lib/browser/orderSubscriber/WebsocketSubscription.js +67 -0
  245. package/lib/browser/orderSubscriber/grpcSubscription.d.ts +22 -0
  246. package/lib/browser/orderSubscriber/grpcSubscription.js +66 -0
  247. package/lib/browser/orderSubscriber/index.d.ts +2 -0
  248. package/lib/browser/orderSubscriber/index.js +18 -0
  249. package/lib/browser/orderSubscriber/types.d.ts +34 -0
  250. package/lib/browser/orderSubscriber/types.js +2 -0
  251. package/lib/browser/phoenix/phoenixFulfillmentConfigMap.d.ts +10 -0
  252. package/lib/browser/phoenix/phoenixFulfillmentConfigMap.js +17 -0
  253. package/lib/browser/phoenix/phoenixSubscriber.d.ts +41 -0
  254. package/lib/browser/phoenix/phoenixSubscriber.js +152 -0
  255. package/lib/browser/priorityFee/averageOverSlotsStrategy.d.ts +5 -0
  256. package/lib/browser/priorityFee/averageOverSlotsStrategy.js +16 -0
  257. package/lib/browser/priorityFee/averageStrategy.d.ts +5 -0
  258. package/lib/browser/priorityFee/averageStrategy.js +11 -0
  259. package/lib/browser/priorityFee/driftPriorityFeeMethod.d.ts +13 -0
  260. package/lib/browser/priorityFee/driftPriorityFeeMethod.js +26 -0
  261. package/lib/browser/priorityFee/ewmaStrategy.d.ts +11 -0
  262. package/lib/browser/priorityFee/ewmaStrategy.js +33 -0
  263. package/lib/browser/priorityFee/heliusPriorityFeeMethod.d.ts +20 -0
  264. package/lib/browser/priorityFee/heliusPriorityFeeMethod.js +46 -0
  265. package/lib/browser/priorityFee/index.d.ts +11 -0
  266. package/lib/browser/priorityFee/index.js +27 -0
  267. package/lib/browser/priorityFee/maxOverSlotsStrategy.d.ts +5 -0
  268. package/lib/browser/priorityFee/maxOverSlotsStrategy.js +17 -0
  269. package/lib/browser/priorityFee/maxStrategy.d.ts +7 -0
  270. package/lib/browser/priorityFee/maxStrategy.js +9 -0
  271. package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +46 -0
  272. package/lib/browser/priorityFee/priorityFeeSubscriber.js +188 -0
  273. package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +48 -0
  274. package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +88 -0
  275. package/lib/browser/priorityFee/solanaPriorityFeeMethod.d.ts +6 -0
  276. package/lib/browser/priorityFee/solanaPriorityFeeMethod.js +21 -0
  277. package/lib/browser/priorityFee/types.d.ts +31 -0
  278. package/lib/browser/priorityFee/types.js +10 -0
  279. package/lib/browser/serum/serumFulfillmentConfigMap.d.ts +10 -0
  280. package/lib/browser/serum/serumFulfillmentConfigMap.js +17 -0
  281. package/lib/browser/serum/serumSubscriber.d.ts +32 -0
  282. package/lib/browser/serum/serumSubscriber.js +107 -0
  283. package/lib/browser/serum/types.d.ts +13 -0
  284. package/lib/browser/serum/types.js +2 -0
  285. package/lib/browser/slot/SlotSubscriber.d.ts +27 -0
  286. package/lib/browser/slot/SlotSubscriber.js +71 -0
  287. package/lib/browser/slot/SlothashSubscriber.d.ts +26 -0
  288. package/lib/browser/slot/SlothashSubscriber.js +85 -0
  289. package/lib/browser/testClient.d.ts +8 -0
  290. package/lib/browser/testClient.js +23 -0
  291. package/lib/browser/token/index.d.ts +5 -0
  292. package/lib/browser/token/index.js +15 -0
  293. package/lib/browser/tokenFaucet.d.ts +41 -0
  294. package/lib/browser/tokenFaucet.js +188 -0
  295. package/lib/browser/tx/baseTxSender.d.ts +59 -0
  296. package/lib/browser/tx/baseTxSender.js +294 -0
  297. package/lib/browser/tx/blockhashFetcher/baseBlockhashFetcher.d.ts +8 -0
  298. package/lib/browser/tx/blockhashFetcher/baseBlockhashFetcher.js +13 -0
  299. package/lib/browser/tx/blockhashFetcher/cachedBlockhashFetcher.d.ts +28 -0
  300. package/lib/browser/tx/blockhashFetcher/cachedBlockhashFetcher.js +73 -0
  301. package/lib/browser/tx/blockhashFetcher/types.d.ts +4 -0
  302. package/lib/browser/tx/blockhashFetcher/types.js +2 -0
  303. package/lib/browser/tx/fastSingleTxSender.d.ts +41 -0
  304. package/lib/browser/tx/fastSingleTxSender.js +86 -0
  305. package/lib/browser/tx/forwardOnlyTxSender.d.ts +37 -0
  306. package/lib/browser/tx/forwardOnlyTxSender.js +92 -0
  307. package/lib/browser/tx/priorityFeeCalculator.d.ts +44 -0
  308. package/lib/browser/tx/priorityFeeCalculator.js +85 -0
  309. package/lib/browser/tx/reportTransactionError.d.ts +20 -0
  310. package/lib/browser/tx/reportTransactionError.js +103 -0
  311. package/lib/browser/tx/retryTxSender.d.ts +37 -0
  312. package/lib/browser/tx/retryTxSender.js +86 -0
  313. package/lib/browser/tx/txHandler.d.ts +154 -0
  314. package/lib/browser/tx/txHandler.js +453 -0
  315. package/lib/browser/tx/txParamProcessor.d.ts +25 -0
  316. package/lib/browser/tx/txParamProcessor.js +88 -0
  317. package/lib/browser/tx/types.d.ts +29 -0
  318. package/lib/browser/tx/types.js +20 -0
  319. package/lib/browser/tx/utils.d.ts +2 -0
  320. package/lib/browser/tx/utils.js +10 -0
  321. package/lib/browser/tx/whileValidTxSender.d.ts +45 -0
  322. package/lib/browser/tx/whileValidTxSender.js +167 -0
  323. package/lib/browser/types.d.ts +1385 -0
  324. package/lib/browser/types.js +366 -0
  325. package/lib/browser/user.d.ts +411 -0
  326. package/lib/browser/user.js +2151 -0
  327. package/lib/browser/userConfig.d.ts +26 -0
  328. package/lib/browser/userConfig.js +2 -0
  329. package/lib/browser/userMap/PollingSubscription.d.ts +16 -0
  330. package/lib/browser/userMap/PollingSubscription.js +30 -0
  331. package/lib/browser/userMap/WebsocketSubscription.d.ts +27 -0
  332. package/lib/browser/userMap/WebsocketSubscription.js +45 -0
  333. package/lib/browser/userMap/grpcSubscription.d.ts +27 -0
  334. package/lib/browser/userMap/grpcSubscription.js +44 -0
  335. package/lib/browser/userMap/referrerMap.d.ts +45 -0
  336. package/lib/browser/userMap/referrerMap.js +181 -0
  337. package/lib/browser/userMap/userMap.d.ts +90 -0
  338. package/lib/browser/userMap/userMap.js +467 -0
  339. package/lib/browser/userMap/userMapConfig.d.ts +39 -0
  340. package/lib/browser/userMap/userMapConfig.js +2 -0
  341. package/lib/browser/userMap/userStatsMap.d.ts +46 -0
  342. package/lib/browser/userMap/userStatsMap.js +165 -0
  343. package/lib/browser/userName.d.ts +5 -0
  344. package/lib/browser/userName.js +21 -0
  345. package/lib/browser/userStats.d.ts +22 -0
  346. package/lib/browser/userStats.js +91 -0
  347. package/lib/browser/userStatsConfig.d.ts +25 -0
  348. package/lib/browser/userStatsConfig.js +2 -0
  349. package/lib/browser/util/TransactionConfirmationManager.d.ts +16 -0
  350. package/lib/browser/util/TransactionConfirmationManager.js +174 -0
  351. package/lib/browser/util/chainClock.d.ts +17 -0
  352. package/lib/browser/util/chainClock.js +29 -0
  353. package/lib/browser/util/computeUnits.d.ts +8 -0
  354. package/lib/browser/util/computeUnits.js +48 -0
  355. package/lib/browser/util/digest.d.ts +4 -0
  356. package/lib/browser/util/digest.js +14 -0
  357. package/lib/browser/util/promiseTimeout.d.ts +1 -0
  358. package/lib/browser/util/promiseTimeout.js +14 -0
  359. package/lib/browser/util/pythOracleUtils.d.ts +17 -0
  360. package/lib/browser/util/pythOracleUtils.js +107 -0
  361. package/lib/browser/util/tps.d.ts +2 -0
  362. package/lib/browser/util/tps.js +16 -0
  363. package/lib/browser/wallet.d.ts +11 -0
  364. package/lib/browser/wallet.js +32 -0
  365. package/lib/node/accounts/basicUserAccountSubscriber.d.ts +27 -0
  366. package/lib/node/accounts/basicUserAccountSubscriber.js +38 -0
  367. package/lib/node/accounts/bulkAccountLoader.d.ts +37 -0
  368. package/lib/node/accounts/bulkAccountLoader.js +222 -0
  369. package/lib/node/accounts/bulkUserStatsSubscription.d.ts +7 -0
  370. package/lib/node/accounts/bulkUserStatsSubscription.js +21 -0
  371. package/lib/node/accounts/bulkUserSubscription.d.ts +7 -0
  372. package/lib/node/accounts/bulkUserSubscription.js +21 -0
  373. package/lib/node/accounts/fetch.d.ts +6 -0
  374. package/lib/node/accounts/fetch.js +30 -0
  375. package/lib/node/accounts/grpcAccountSubscriber.d.ts +16 -0
  376. package/lib/node/accounts/grpcAccountSubscriber.js +154 -0
  377. package/lib/node/accounts/grpcDriftClientAccountSubscriber.d.ts +12 -0
  378. package/lib/node/accounts/grpcDriftClientAccountSubscriber.js +98 -0
  379. package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +10 -0
  380. package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.js +30 -0
  381. package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +18 -0
  382. package/lib/node/accounts/grpcProgramAccountSubscriber.js +171 -0
  383. package/lib/node/accounts/grpcUserAccountSubscriber.d.ts +10 -0
  384. package/lib/node/accounts/grpcUserAccountSubscriber.js +28 -0
  385. package/lib/node/accounts/grpcUserStatsAccountSubscriber.d.ts +10 -0
  386. package/lib/node/accounts/grpcUserStatsAccountSubscriber.js +28 -0
  387. package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts +18 -0
  388. package/lib/node/accounts/oneShotUserAccountSubscriber.js +48 -0
  389. package/lib/node/accounts/pollingDriftClientAccountSubscriber.d.ts +69 -0
  390. package/lib/node/accounts/pollingDriftClientAccountSubscriber.js +418 -0
  391. package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +29 -0
  392. package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +111 -0
  393. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +29 -0
  394. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +110 -0
  395. package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +27 -0
  396. package/lib/node/accounts/pollingOracleAccountSubscriber.js +78 -0
  397. package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +26 -0
  398. package/lib/node/accounts/pollingTokenAccountSubscriber.js +78 -0
  399. package/lib/node/accounts/pollingUserAccountSubscriber.d.ts +29 -0
  400. package/lib/node/accounts/pollingUserAccountSubscriber.js +102 -0
  401. package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
  402. package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +94 -0
  403. package/lib/node/accounts/testBulkAccountLoader.d.ts +4 -0
  404. package/lib/node/accounts/testBulkAccountLoader.js +45 -0
  405. package/lib/node/accounts/types.d.ts +168 -0
  406. package/lib/node/accounts/types.js +16 -0
  407. package/lib/node/accounts/utils.d.ts +8 -0
  408. package/lib/node/accounts/utils.js +49 -0
  409. package/lib/node/accounts/webSocketAccountSubscriber.d.ts +29 -0
  410. package/lib/node/accounts/webSocketAccountSubscriber.js +149 -0
  411. package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts +66 -0
  412. package/lib/node/accounts/webSocketDriftClientAccountSubscriber.js +358 -0
  413. package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +23 -0
  414. package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +69 -0
  415. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +23 -0
  416. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +67 -0
  417. package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +32 -0
  418. package/lib/node/accounts/webSocketProgramAccountSubscriber.js +120 -0
  419. package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +23 -0
  420. package/lib/node/accounts/webSocketUserAccountSubscriber.js +61 -0
  421. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +22 -0
  422. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.js +52 -0
  423. package/lib/node/addresses/marketAddresses.d.ts +2 -0
  424. package/lib/node/addresses/marketAddresses.js +15 -0
  425. package/lib/node/addresses/pda.d.ts +32 -0
  426. package/lib/node/addresses/pda.js +211 -0
  427. package/lib/node/adminClient.d.ts +206 -0
  428. package/lib/node/adminClient.js +1858 -0
  429. package/lib/node/assert/assert.d.ts +1 -0
  430. package/lib/node/assert/assert.js +9 -0
  431. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +14 -0
  432. package/lib/node/auctionSubscriber/auctionSubscriber.js +32 -0
  433. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +15 -0
  434. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +32 -0
  435. package/lib/node/auctionSubscriber/index.d.ts +3 -0
  436. package/lib/node/auctionSubscriber/index.js +19 -0
  437. package/lib/node/auctionSubscriber/types.d.ts +14 -0
  438. package/lib/node/auctionSubscriber/types.js +2 -0
  439. package/lib/node/bankrun/bankrunConnection.d.ts +75 -0
  440. package/lib/node/bankrun/bankrunConnection.js +332 -0
  441. package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts +27 -0
  442. package/lib/node/blockhashSubscriber/BlockhashSubscriber.js +89 -0
  443. package/lib/node/blockhashSubscriber/index.d.ts +1 -0
  444. package/lib/node/blockhashSubscriber/index.js +17 -0
  445. package/lib/node/blockhashSubscriber/types.d.ts +7 -0
  446. package/lib/node/blockhashSubscriber/types.js +2 -0
  447. package/lib/node/clock/clockSubscriber.d.ts +31 -0
  448. package/lib/node/clock/clockSubscriber.js +80 -0
  449. package/lib/node/config.d.ts +60 -0
  450. package/lib/node/config.js +130 -0
  451. package/lib/node/constants/numericConstants.d.ts +71 -0
  452. package/lib/node/constants/numericConstants.js +75 -0
  453. package/lib/node/constants/perpMarkets.d.ts +19 -0
  454. package/lib/node/constants/perpMarkets.js +997 -0
  455. package/lib/node/constants/spotMarkets.d.ts +24 -0
  456. package/lib/node/constants/spotMarkets.js +470 -0
  457. package/lib/node/constants/txConstants.d.ts +1 -0
  458. package/lib/node/constants/txConstants.js +4 -0
  459. package/lib/node/decode/phoenix.d.ts +7 -0
  460. package/lib/node/decode/phoenix.js +159 -0
  461. package/lib/node/decode/user.d.ts +4 -0
  462. package/lib/node/decode/user.js +339 -0
  463. package/lib/node/dlob/DLOB.d.ts +186 -0
  464. package/lib/node/dlob/DLOB.js +1039 -0
  465. package/lib/node/dlob/DLOBNode.d.ts +68 -0
  466. package/lib/node/dlob/DLOBNode.js +100 -0
  467. package/lib/node/dlob/DLOBSubscriber.d.ts +54 -0
  468. package/lib/node/dlob/DLOBSubscriber.js +139 -0
  469. package/lib/node/dlob/NodeList.d.ts +25 -0
  470. package/lib/node/dlob/NodeList.js +126 -0
  471. package/lib/node/dlob/orderBookLevels.d.ts +72 -0
  472. package/lib/node/dlob/orderBookLevels.js +438 -0
  473. package/lib/node/dlob/types.d.ts +18 -0
  474. package/lib/node/dlob/types.js +2 -0
  475. package/lib/node/driftClient.d.ts +861 -0
  476. package/lib/node/driftClient.js +4768 -0
  477. package/lib/node/driftClientConfig.d.ts +49 -0
  478. package/lib/node/driftClientConfig.js +2 -0
  479. package/lib/node/events/eventList.d.ts +22 -0
  480. package/lib/node/events/eventList.js +80 -0
  481. package/lib/node/events/eventSubscriber.d.ts +46 -0
  482. package/lib/node/events/eventSubscriber.js +223 -0
  483. package/lib/node/events/eventsServerLogProvider.d.ts +21 -0
  484. package/lib/node/events/eventsServerLogProvider.js +121 -0
  485. package/lib/node/events/fetchLogs.d.ts +25 -0
  486. package/lib/node/events/fetchLogs.js +99 -0
  487. package/lib/node/events/parse.d.ts +6 -0
  488. package/lib/node/events/parse.js +106 -0
  489. package/lib/node/events/pollingLogProvider.d.ts +17 -0
  490. package/lib/node/events/pollingLogProvider.js +58 -0
  491. package/lib/node/events/sort.d.ts +2 -0
  492. package/lib/node/events/sort.js +24 -0
  493. package/lib/node/events/txEventCache.d.ts +24 -0
  494. package/lib/node/events/txEventCache.js +71 -0
  495. package/lib/node/events/types.d.ts +79 -0
  496. package/lib/node/events/types.js +32 -0
  497. package/lib/node/events/webSocketLogProvider.d.ts +24 -0
  498. package/lib/node/events/webSocketLogProvider.js +96 -0
  499. package/lib/node/factory/bigNum.d.ts +122 -0
  500. package/lib/node/factory/bigNum.js +457 -0
  501. package/lib/node/factory/oracleClient.d.ts +5 -0
  502. package/lib/node/factory/oracleClient.js +56 -0
  503. package/lib/node/idl/drift.json +14440 -0
  504. package/lib/node/idl/openbook.json +3854 -0
  505. package/lib/node/idl/pyth_solana_receiver.json +628 -0
  506. package/lib/node/idl/switchboard.json +8354 -0
  507. package/lib/node/idl/switchboard_on_demand_30.json +4546 -0
  508. package/lib/node/idl/token_faucet.json +142 -0
  509. package/lib/node/index.d.ts +125 -0
  510. package/lib/node/index.js +147 -0
  511. package/lib/node/isomorphic/grpc.browser.d.ts +1 -0
  512. package/lib/node/isomorphic/grpc.browser.js +8 -0
  513. package/lib/node/isomorphic/grpc.d.ts +1 -0
  514. package/lib/node/isomorphic/grpc.js +8 -0
  515. package/lib/node/jupiter/jupiterClient.d.ts +302 -0
  516. package/lib/node/jupiter/jupiterClient.js +178 -0
  517. package/lib/node/keypair.d.ts +2 -0
  518. package/lib/node/keypair.js +28 -0
  519. package/lib/node/marinade/index.d.ts +12 -0
  520. package/lib/node/marinade/index.js +36 -0
  521. package/lib/node/marinade/types.d.ts +1963 -0
  522. package/lib/node/marinade/types.js +1965 -0
  523. package/lib/node/math/amm.d.ts +98 -0
  524. package/lib/node/math/amm.js +626 -0
  525. package/lib/node/math/auction.d.ts +23 -0
  526. package/lib/node/math/auction.js +130 -0
  527. package/lib/node/math/bankruptcy.d.ts +2 -0
  528. package/lib/node/math/bankruptcy.js +31 -0
  529. package/lib/node/math/conversion.d.ts +2 -0
  530. package/lib/node/math/conversion.js +11 -0
  531. package/lib/node/math/exchangeStatus.d.ts +6 -0
  532. package/lib/node/math/exchangeStatus.js +77 -0
  533. package/lib/node/math/fuel.d.ts +6 -0
  534. package/lib/node/math/fuel.js +55 -0
  535. package/lib/node/math/funding.d.ts +34 -0
  536. package/lib/node/math/funding.js +209 -0
  537. package/lib/node/math/insurance.d.ts +7 -0
  538. package/lib/node/math/insurance.js +73 -0
  539. package/lib/node/math/margin.d.ts +39 -0
  540. package/lib/node/math/margin.js +184 -0
  541. package/lib/node/math/market.d.ts +39 -0
  542. package/lib/node/math/market.js +163 -0
  543. package/lib/node/math/oracles.d.ts +14 -0
  544. package/lib/node/math/oracles.js +134 -0
  545. package/lib/node/math/orders.d.ts +23 -0
  546. package/lib/node/math/orders.js +216 -0
  547. package/lib/node/math/position.d.ts +70 -0
  548. package/lib/node/math/position.js +225 -0
  549. package/lib/node/math/repeg.d.ts +22 -0
  550. package/lib/node/math/repeg.js +164 -0
  551. package/lib/node/math/spotBalance.d.ts +83 -0
  552. package/lib/node/math/spotBalance.js +373 -0
  553. package/lib/node/math/spotMarket.d.ts +11 -0
  554. package/lib/node/math/spotMarket.js +49 -0
  555. package/lib/node/math/spotPosition.d.ts +19 -0
  556. package/lib/node/math/spotPosition.js +78 -0
  557. package/lib/node/math/state.d.ts +5 -0
  558. package/lib/node/math/state.js +30 -0
  559. package/lib/node/math/superStake.d.ts +167 -0
  560. package/lib/node/math/superStake.js +306 -0
  561. package/lib/node/math/tiers.d.ts +4 -0
  562. package/lib/node/math/tiers.js +52 -0
  563. package/lib/node/math/trade.d.ts +117 -0
  564. package/lib/node/math/trade.js +637 -0
  565. package/lib/node/math/userStatus.d.ts +2 -0
  566. package/lib/node/math/userStatus.js +8 -0
  567. package/lib/node/math/utils.d.ts +23 -0
  568. package/lib/node/math/utils.js +112 -0
  569. package/lib/node/memcmp.d.ts +11 -0
  570. package/lib/node/memcmp.js +99 -0
  571. package/lib/node/openbook/openbookV2FulfillmentConfigMap.d.ts +10 -0
  572. package/lib/node/openbook/openbookV2FulfillmentConfigMap.js +17 -0
  573. package/lib/node/openbook/openbookV2Subscriber.d.ts +36 -0
  574. package/lib/node/openbook/openbookV2Subscriber.js +104 -0
  575. package/lib/node/oracles/oracleClientCache.d.ts +9 -0
  576. package/lib/node/oracles/oracleClientCache.js +19 -0
  577. package/lib/node/oracles/oracleId.d.ts +4 -0
  578. package/lib/node/oracles/oracleId.js +38 -0
  579. package/lib/node/oracles/prelaunchOracleClient.d.ts +12 -0
  580. package/lib/node/oracles/prelaunchOracleClient.js +24 -0
  581. package/lib/node/oracles/pythClient.d.ts +14 -0
  582. package/lib/node/oracles/pythClient.js +51 -0
  583. package/lib/node/oracles/pythLazerClient.d.ts +16 -0
  584. package/lib/node/oracles/pythLazerClient.js +61 -0
  585. package/lib/node/oracles/pythPullClient.d.ts +19 -0
  586. package/lib/node/oracles/pythPullClient.js +60 -0
  587. package/lib/node/oracles/quoteAssetOracleClient.d.ts +10 -0
  588. package/lib/node/oracles/quoteAssetOracleClient.js +21 -0
  589. package/lib/node/oracles/strictOraclePrice.d.ts +9 -0
  590. package/lib/node/oracles/strictOraclePrice.js +17 -0
  591. package/lib/node/oracles/switchboardClient.d.ts +12 -0
  592. package/lib/node/oracles/switchboardClient.js +40 -0
  593. package/lib/node/oracles/switchboardOnDemandClient.d.ts +12 -0
  594. package/lib/node/oracles/switchboardOnDemandClient.js +32 -0
  595. package/lib/node/oracles/types.d.ts +23 -0
  596. package/lib/node/oracles/types.js +2 -0
  597. package/lib/node/orderParams.d.ts +29 -0
  598. package/lib/node/orderParams.js +44 -0
  599. package/lib/node/orderSubscriber/OrderSubscriber.d.ts +42 -0
  600. package/lib/node/orderSubscriber/OrderSubscriber.js +172 -0
  601. package/lib/node/orderSubscriber/PollingSubscription.d.ts +12 -0
  602. package/lib/node/orderSubscriber/PollingSubscription.js +23 -0
  603. package/lib/node/orderSubscriber/WebsocketSubscription.d.ts +23 -0
  604. package/lib/node/orderSubscriber/WebsocketSubscription.js +67 -0
  605. package/lib/node/orderSubscriber/grpcSubscription.d.ts +22 -0
  606. package/lib/node/orderSubscriber/grpcSubscription.js +66 -0
  607. package/lib/node/orderSubscriber/index.d.ts +2 -0
  608. package/lib/node/orderSubscriber/index.js +18 -0
  609. package/lib/node/orderSubscriber/types.d.ts +34 -0
  610. package/lib/node/orderSubscriber/types.js +2 -0
  611. package/lib/node/phoenix/phoenixFulfillmentConfigMap.d.ts +10 -0
  612. package/lib/node/phoenix/phoenixFulfillmentConfigMap.js +17 -0
  613. package/lib/node/phoenix/phoenixSubscriber.d.ts +41 -0
  614. package/lib/node/phoenix/phoenixSubscriber.js +152 -0
  615. package/lib/node/priorityFee/averageOverSlotsStrategy.d.ts +5 -0
  616. package/lib/node/priorityFee/averageOverSlotsStrategy.js +16 -0
  617. package/lib/node/priorityFee/averageStrategy.d.ts +5 -0
  618. package/lib/node/priorityFee/averageStrategy.js +11 -0
  619. package/lib/node/priorityFee/driftPriorityFeeMethod.d.ts +13 -0
  620. package/lib/node/priorityFee/driftPriorityFeeMethod.js +26 -0
  621. package/lib/node/priorityFee/ewmaStrategy.d.ts +11 -0
  622. package/lib/node/priorityFee/ewmaStrategy.js +33 -0
  623. package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts +20 -0
  624. package/lib/node/priorityFee/heliusPriorityFeeMethod.js +46 -0
  625. package/lib/node/priorityFee/index.d.ts +11 -0
  626. package/lib/node/priorityFee/index.js +27 -0
  627. package/lib/node/priorityFee/maxOverSlotsStrategy.d.ts +5 -0
  628. package/lib/node/priorityFee/maxOverSlotsStrategy.js +17 -0
  629. package/lib/node/priorityFee/maxStrategy.d.ts +7 -0
  630. package/lib/node/priorityFee/maxStrategy.js +9 -0
  631. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +46 -0
  632. package/lib/node/priorityFee/priorityFeeSubscriber.js +188 -0
  633. package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +48 -0
  634. package/lib/node/priorityFee/priorityFeeSubscriberMap.js +88 -0
  635. package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +6 -0
  636. package/lib/node/priorityFee/solanaPriorityFeeMethod.js +21 -0
  637. package/lib/node/priorityFee/types.d.ts +31 -0
  638. package/lib/node/priorityFee/types.js +10 -0
  639. package/lib/node/serum/serumFulfillmentConfigMap.d.ts +10 -0
  640. package/lib/node/serum/serumFulfillmentConfigMap.js +17 -0
  641. package/lib/node/serum/serumSubscriber.d.ts +32 -0
  642. package/lib/node/serum/serumSubscriber.js +107 -0
  643. package/lib/node/serum/types.d.ts +13 -0
  644. package/lib/node/serum/types.js +2 -0
  645. package/lib/node/slot/SlotSubscriber.d.ts +27 -0
  646. package/lib/node/slot/SlotSubscriber.js +71 -0
  647. package/lib/node/slot/SlothashSubscriber.d.ts +26 -0
  648. package/lib/node/slot/SlothashSubscriber.js +85 -0
  649. package/lib/node/testClient.d.ts +8 -0
  650. package/lib/node/testClient.js +23 -0
  651. package/lib/node/token/index.d.ts +5 -0
  652. package/lib/node/token/index.js +15 -0
  653. package/lib/node/tokenFaucet.d.ts +41 -0
  654. package/lib/node/tokenFaucet.js +188 -0
  655. package/lib/node/tx/baseTxSender.d.ts +59 -0
  656. package/lib/node/tx/baseTxSender.js +294 -0
  657. package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.d.ts +8 -0
  658. package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.js +13 -0
  659. package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.d.ts +28 -0
  660. package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.js +73 -0
  661. package/lib/node/tx/blockhashFetcher/types.d.ts +4 -0
  662. package/lib/node/tx/blockhashFetcher/types.js +2 -0
  663. package/lib/node/tx/fastSingleTxSender.d.ts +41 -0
  664. package/lib/node/tx/fastSingleTxSender.js +86 -0
  665. package/lib/node/tx/forwardOnlyTxSender.d.ts +37 -0
  666. package/lib/node/tx/forwardOnlyTxSender.js +92 -0
  667. package/lib/node/tx/priorityFeeCalculator.d.ts +44 -0
  668. package/lib/node/tx/priorityFeeCalculator.js +85 -0
  669. package/lib/node/tx/reportTransactionError.d.ts +20 -0
  670. package/lib/node/tx/reportTransactionError.js +103 -0
  671. package/lib/node/tx/retryTxSender.d.ts +37 -0
  672. package/lib/node/tx/retryTxSender.js +86 -0
  673. package/lib/node/tx/txHandler.d.ts +154 -0
  674. package/lib/node/tx/txHandler.js +453 -0
  675. package/lib/node/tx/txParamProcessor.d.ts +25 -0
  676. package/lib/node/tx/txParamProcessor.js +88 -0
  677. package/lib/node/tx/types.d.ts +29 -0
  678. package/lib/node/tx/types.js +20 -0
  679. package/lib/node/tx/utils.d.ts +2 -0
  680. package/lib/node/tx/utils.js +10 -0
  681. package/lib/node/tx/whileValidTxSender.d.ts +45 -0
  682. package/lib/node/tx/whileValidTxSender.js +167 -0
  683. package/lib/node/types.d.ts +1385 -0
  684. package/lib/node/types.js +366 -0
  685. package/lib/node/user.d.ts +411 -0
  686. package/lib/node/user.js +2151 -0
  687. package/lib/node/userConfig.d.ts +26 -0
  688. package/lib/node/userConfig.js +2 -0
  689. package/lib/node/userMap/PollingSubscription.d.ts +16 -0
  690. package/lib/node/userMap/PollingSubscription.js +30 -0
  691. package/lib/node/userMap/WebsocketSubscription.d.ts +27 -0
  692. package/lib/node/userMap/WebsocketSubscription.js +45 -0
  693. package/lib/node/userMap/grpcSubscription.d.ts +27 -0
  694. package/lib/node/userMap/grpcSubscription.js +44 -0
  695. package/lib/node/userMap/referrerMap.d.ts +45 -0
  696. package/lib/node/userMap/referrerMap.js +181 -0
  697. package/lib/node/userMap/userMap.d.ts +90 -0
  698. package/lib/node/userMap/userMap.js +467 -0
  699. package/lib/node/userMap/userMapConfig.d.ts +39 -0
  700. package/lib/node/userMap/userMapConfig.js +2 -0
  701. package/lib/node/userMap/userStatsMap.d.ts +46 -0
  702. package/lib/node/userMap/userStatsMap.js +165 -0
  703. package/lib/node/userName.d.ts +5 -0
  704. package/lib/node/userName.js +21 -0
  705. package/lib/node/userStats.d.ts +22 -0
  706. package/lib/node/userStats.js +91 -0
  707. package/lib/node/userStatsConfig.d.ts +25 -0
  708. package/lib/node/userStatsConfig.js +2 -0
  709. package/lib/node/util/TransactionConfirmationManager.d.ts +16 -0
  710. package/lib/node/util/TransactionConfirmationManager.js +174 -0
  711. package/lib/node/util/chainClock.d.ts +17 -0
  712. package/lib/node/util/chainClock.js +29 -0
  713. package/lib/node/util/computeUnits.d.ts +8 -0
  714. package/lib/node/util/computeUnits.js +48 -0
  715. package/lib/node/util/digest.d.ts +4 -0
  716. package/lib/node/util/digest.js +14 -0
  717. package/lib/node/util/promiseTimeout.d.ts +1 -0
  718. package/lib/node/util/promiseTimeout.js +14 -0
  719. package/lib/node/util/pythOracleUtils.d.ts +17 -0
  720. package/lib/node/util/pythOracleUtils.js +107 -0
  721. package/lib/node/util/tps.d.ts +2 -0
  722. package/lib/node/util/tps.js +16 -0
  723. package/lib/node/wallet.d.ts +11 -0
  724. package/lib/node/wallet.js +32 -0
  725. package/package.json +92 -0
  726. package/scripts/postbuild.js +95 -0
  727. package/scripts/updateVersion.js +28 -0
  728. package/src/accounts/basicUserAccountSubscriber.ts +59 -0
  729. package/src/accounts/bulkAccountLoader.ts +294 -0
  730. package/src/accounts/bulkUserStatsSubscription.ts +33 -0
  731. package/src/accounts/bulkUserSubscription.ts +33 -0
  732. package/src/accounts/fetch.ts +66 -0
  733. package/src/accounts/grpcAccountSubscriber.ts +160 -0
  734. package/src/accounts/grpcDriftClientAccountSubscriber.ts +203 -0
  735. package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +56 -0
  736. package/src/accounts/grpcProgramAccountSubscriber.ts +190 -0
  737. package/src/accounts/grpcUserAccountSubscriber.ts +48 -0
  738. package/src/accounts/grpcUserStatsAccountSubscriber.ts +50 -0
  739. package/src/accounts/oneShotUserAccountSubscriber.ts +68 -0
  740. package/src/accounts/pollingDriftClientAccountSubscriber.ts +644 -0
  741. package/src/accounts/pollingHighLeverageModeConfigAccountSubscriber.ts +189 -0
  742. package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +185 -0
  743. package/src/accounts/pollingOracleAccountSubscriber.ts +125 -0
  744. package/src/accounts/pollingTokenAccountSubscriber.ts +118 -0
  745. package/src/accounts/pollingUserAccountSubscriber.ts +160 -0
  746. package/src/accounts/pollingUserStatsAccountSubscriber.ts +156 -0
  747. package/src/accounts/testBulkAccountLoader.ts +53 -0
  748. package/src/accounts/types.ts +245 -0
  749. package/src/accounts/utils.ts +62 -0
  750. package/src/accounts/webSocketAccountSubscriber.ts +205 -0
  751. package/src/accounts/webSocketDriftClientAccountSubscriber.ts +621 -0
  752. package/src/accounts/webSocketHighLeverageModeConfigAccountSubscriber.ts +131 -0
  753. package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +129 -0
  754. package/src/accounts/webSocketProgramAccountSubscriber.ts +182 -0
  755. package/src/accounts/webSocketUserAccountSubscriber.ts +104 -0
  756. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +98 -0
  757. package/src/addresses/marketAddresses.ts +17 -0
  758. package/src/addresses/pda.ts +355 -0
  759. package/src/adminClient.ts +4030 -0
  760. package/src/assert/assert.ts +5 -0
  761. package/src/auctionSubscriber/auctionSubscriber.ts +66 -0
  762. package/src/auctionSubscriber/auctionSubscriberGrpc.ts +70 -0
  763. package/src/auctionSubscriber/index.ts +3 -0
  764. package/src/auctionSubscriber/types.ts +20 -0
  765. package/src/bankrun/bankrunConnection.ts +534 -0
  766. package/src/blockhashSubscriber/BlockhashSubscriber.ts +126 -0
  767. package/src/blockhashSubscriber/index.ts +1 -0
  768. package/src/blockhashSubscriber/types.ts +12 -0
  769. package/src/clock/clockSubscriber.ts +121 -0
  770. package/src/config.ts +212 -0
  771. package/src/constants/numericConstants.ts +113 -0
  772. package/src/constants/perpMarkets.ts +1084 -0
  773. package/src/constants/spotMarkets.ts +565 -0
  774. package/src/constants/txConstants.ts +1 -0
  775. package/src/decode/phoenix.ts +207 -0
  776. package/src/decode/user.ts +368 -0
  777. package/src/dlob/DLOB.ts +1897 -0
  778. package/src/dlob/DLOBNode.ts +197 -0
  779. package/src/dlob/DLOBSubscriber.ts +201 -0
  780. package/src/dlob/NodeList.ts +173 -0
  781. package/src/dlob/orderBookLevels.ts +643 -0
  782. package/src/dlob/types.ts +22 -0
  783. package/src/driftClient.ts +9032 -0
  784. package/src/driftClientConfig.ts +60 -0
  785. package/src/events/eventList.ts +97 -0
  786. package/src/events/eventSubscriber.ts +364 -0
  787. package/src/events/eventsServerLogProvider.ts +152 -0
  788. package/src/events/fetchLogs.ts +169 -0
  789. package/src/events/parse.ts +133 -0
  790. package/src/events/pollingLogProvider.ts +89 -0
  791. package/src/events/sort.ts +39 -0
  792. package/src/events/txEventCache.ts +74 -0
  793. package/src/events/types.ts +185 -0
  794. package/src/events/webSocketLogProvider.ts +121 -0
  795. package/src/factory/bigNum.ts +660 -0
  796. package/src/factory/oracleClient.ts +72 -0
  797. package/src/idl/drift.json +14440 -0
  798. package/src/idl/openbook.json +3854 -0
  799. package/src/idl/pyth.json +142 -0
  800. package/src/idl/pyth_solana_receiver.json +628 -0
  801. package/src/idl/switchboard.json +8354 -0
  802. package/src/idl/switchboard_on_demand_30.json +4546 -0
  803. package/src/idl/token_faucet.json +142 -0
  804. package/src/index.ts +127 -0
  805. package/src/isomorphic/README.md +19 -0
  806. package/src/isomorphic/grpc.browser.ts +4 -0
  807. package/src/isomorphic/grpc.node.ts +23 -0
  808. package/src/isomorphic/grpc.ts +1 -0
  809. package/src/jupiter/jupiterClient.ts +510 -0
  810. package/src/keypair.ts +24 -0
  811. package/src/marinade/idl/idl.json +1962 -0
  812. package/src/marinade/index.ts +64 -0
  813. package/src/marinade/types.ts +3925 -0
  814. package/src/math/amm.ts +1162 -0
  815. package/src/math/auction.ts +173 -0
  816. package/src/math/bankruptcy.ts +34 -0
  817. package/src/math/conversion.ts +13 -0
  818. package/src/math/exchangeStatus.ts +121 -0
  819. package/src/math/fuel.ts +70 -0
  820. package/src/math/funding.ts +342 -0
  821. package/src/math/insurance.ts +110 -0
  822. package/src/math/margin.ts +340 -0
  823. package/src/math/market.ts +336 -0
  824. package/src/math/oracles.ts +228 -0
  825. package/src/math/orders.ts +343 -0
  826. package/src/math/position.ts +324 -0
  827. package/src/math/repeg.ts +214 -0
  828. package/src/math/spotBalance.ts +630 -0
  829. package/src/math/spotMarket.ts +82 -0
  830. package/src/math/spotPosition.ts +184 -0
  831. package/src/math/state.ts +29 -0
  832. package/src/math/superStake.ts +525 -0
  833. package/src/math/tiers.ts +44 -0
  834. package/src/math/trade.ts +993 -0
  835. package/src/math/userStatus.ts +5 -0
  836. package/src/math/utils.ts +120 -0
  837. package/src/memcmp.ts +94 -0
  838. package/src/openbook/openbookV2FulfillmentConfigMap.ts +29 -0
  839. package/src/openbook/openbookV2Subscriber.ts +165 -0
  840. package/src/oracles/oracleClientCache.ts +25 -0
  841. package/src/oracles/oracleId.ts +28 -0
  842. package/src/oracles/prelaunchOracleClient.ts +37 -0
  843. package/src/oracles/pythClient.ts +85 -0
  844. package/src/oracles/pythLazerClient.ts +102 -0
  845. package/src/oracles/pythPullClient.ts +111 -0
  846. package/src/oracles/quoteAssetOracleClient.ts +25 -0
  847. package/src/oracles/strictOraclePrice.ts +19 -0
  848. package/src/oracles/switchboardClient.ts +77 -0
  849. package/src/oracles/switchboardOnDemandClient.ts +56 -0
  850. package/src/oracles/types.ts +23 -0
  851. package/src/orderParams.ts +79 -0
  852. package/src/orderSubscriber/OrderSubscriber.ts +249 -0
  853. package/src/orderSubscriber/PollingSubscription.ts +39 -0
  854. package/src/orderSubscriber/WebsocketSubscription.ts +119 -0
  855. package/src/orderSubscriber/grpcSubscription.ts +121 -0
  856. package/src/orderSubscriber/index.ts +2 -0
  857. package/src/orderSubscriber/types.ts +54 -0
  858. package/src/phoenix/phoenixFulfillmentConfigMap.ts +26 -0
  859. package/src/phoenix/phoenixSubscriber.ts +235 -0
  860. package/src/priorityFee/averageOverSlotsStrategy.ts +16 -0
  861. package/src/priorityFee/averageStrategy.ts +12 -0
  862. package/src/priorityFee/driftPriorityFeeMethod.ts +42 -0
  863. package/src/priorityFee/ewmaStrategy.ts +41 -0
  864. package/src/priorityFee/heliusPriorityFeeMethod.ts +57 -0
  865. package/src/priorityFee/index.ts +11 -0
  866. package/src/priorityFee/maxOverSlotsStrategy.ts +17 -0
  867. package/src/priorityFee/maxStrategy.ts +7 -0
  868. package/src/priorityFee/priorityFeeSubscriber.ts +251 -0
  869. package/src/priorityFee/priorityFeeSubscriberMap.ts +112 -0
  870. package/src/priorityFee/solanaPriorityFeeMethod.ts +34 -0
  871. package/src/priorityFee/types.ts +60 -0
  872. package/src/serum/serumFulfillmentConfigMap.ts +26 -0
  873. package/src/serum/serumSubscriber.ts +169 -0
  874. package/src/serum/types.ts +17 -0
  875. package/src/slot/SlotSubscriber.ts +101 -0
  876. package/src/slot/SlothashSubscriber.ts +126 -0
  877. package/src/testClient.ts +41 -0
  878. package/src/token/index.ts +13 -0
  879. package/src/tokenFaucet.ts +269 -0
  880. package/src/tx/baseTxSender.ts +477 -0
  881. package/src/tx/blockhashFetcher/baseBlockhashFetcher.ts +19 -0
  882. package/src/tx/blockhashFetcher/cachedBlockhashFetcher.ts +90 -0
  883. package/src/tx/blockhashFetcher/types.ts +5 -0
  884. package/src/tx/fastSingleTxSender.ts +142 -0
  885. package/src/tx/forwardOnlyTxSender.ts +145 -0
  886. package/src/tx/priorityFeeCalculator.ts +117 -0
  887. package/src/tx/reportTransactionError.ts +159 -0
  888. package/src/tx/retryTxSender.ts +135 -0
  889. package/src/tx/txHandler.ts +737 -0
  890. package/src/tx/txParamProcessor.ts +155 -0
  891. package/src/tx/types.ts +71 -0
  892. package/src/tx/utils.ts +11 -0
  893. package/src/tx/whileValidTxSender.ts +265 -0
  894. package/src/types.ts +1386 -0
  895. package/src/user.ts +4054 -0
  896. package/src/userConfig.ts +32 -0
  897. package/src/userMap/PollingSubscription.ts +47 -0
  898. package/src/userMap/WebsocketSubscription.ts +84 -0
  899. package/src/userMap/grpcSubscription.ts +85 -0
  900. package/src/userMap/referrerMap.ts +267 -0
  901. package/src/userMap/userMap.ts +654 -0
  902. package/src/userMap/userMapConfig.ts +63 -0
  903. package/src/userMap/userStatsMap.ts +218 -0
  904. package/src/userName.ts +21 -0
  905. package/src/userStats.ts +174 -0
  906. package/src/userStatsConfig.ts +31 -0
  907. package/src/util/TransactionConfirmationManager.ts +292 -0
  908. package/src/util/chainClock.ts +41 -0
  909. package/src/util/computeUnits.ts +65 -0
  910. package/src/util/digest.ts +11 -0
  911. package/src/util/promiseTimeout.ts +14 -0
  912. package/src/util/pythOracleUtils.ts +136 -0
  913. package/src/util/tps.ts +27 -0
  914. package/src/wallet.ts +43 -0
  915. package/tests/amm/test.ts +2092 -0
  916. package/tests/auctions/test.ts +81 -0
  917. package/tests/bn/test.ts +341 -0
  918. package/tests/ci/idl.ts +101 -0
  919. package/tests/ci/verifyConstants.ts +278 -0
  920. package/tests/decode/phoenix.ts +71 -0
  921. package/tests/decode/test.ts +266 -0
  922. package/tests/decode/userAccountBufferStrings.ts +102 -0
  923. package/tests/dlob/helpers.ts +749 -0
  924. package/tests/dlob/test.ts +6623 -0
  925. package/tests/insurance/test.ts +40 -0
  926. package/tests/spot/test.ts +226 -0
  927. package/tests/subscriber/openbook.ts +62 -0
  928. package/tests/tx/TransactionConfirmationManager.test.ts +305 -0
  929. package/tests/tx/cachedBlockhashFetcher.test.ts +96 -0
  930. package/tests/tx/priorityFeeCalculator.ts +77 -0
  931. package/tests/tx/priorityFeeStrategy.ts +95 -0
  932. package/tests/user/helpers.ts +92 -0
  933. package/tests/user/test.ts +517 -0
  934. package/tsconfig.browser.json +13 -0
  935. package/tsconfig.json +13 -0
@@ -0,0 +1,4030 @@
1
+ import {
2
+ PublicKey,
3
+ SystemProgram,
4
+ SYSVAR_RENT_PUBKEY,
5
+ TransactionInstruction,
6
+ TransactionSignature,
7
+ } from '@solana/web3.js';
8
+ import {
9
+ FeeStructure,
10
+ OracleGuardRails,
11
+ OracleSource,
12
+ ExchangeStatus,
13
+ MarketStatus,
14
+ ContractTier,
15
+ AssetTier,
16
+ SpotFulfillmentConfigStatus,
17
+ } from './types';
18
+ import { DEFAULT_MARKET_NAME, encodeName } from './userName';
19
+ import { BN } from '@coral-xyz/anchor';
20
+ import * as anchor from '@coral-xyz/anchor';
21
+ import {
22
+ getDriftStateAccountPublicKeyAndNonce,
23
+ getSpotMarketPublicKey,
24
+ getSpotMarketVaultPublicKey,
25
+ getPerpMarketPublicKey,
26
+ getInsuranceFundVaultPublicKey,
27
+ getSerumOpenOrdersPublicKey,
28
+ getSerumFulfillmentConfigPublicKey,
29
+ getPhoenixFulfillmentConfigPublicKey,
30
+ getProtocolIfSharesTransferConfigPublicKey,
31
+ getPrelaunchOraclePublicKey,
32
+ getOpenbookV2FulfillmentConfigPublicKey,
33
+ getPythPullOraclePublicKey,
34
+ getUserStatsAccountPublicKey,
35
+ getHighLeverageModeConfigPublicKey,
36
+ getPythLazerOraclePublicKey,
37
+ } from './addresses/pda';
38
+ import { squareRootBN } from './math/utils';
39
+ import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
40
+ import { DriftClient } from './driftClient';
41
+ import {
42
+ PEG_PRECISION,
43
+ QUOTE_SPOT_MARKET_INDEX,
44
+ ZERO,
45
+ ONE,
46
+ BASE_PRECISION,
47
+ PRICE_PRECISION,
48
+ } from './constants/numericConstants';
49
+ import { calculateTargetPriceTrade } from './math/trade';
50
+ import { calculateAmmReservesAfterSwap, getSwapDirection } from './math/amm';
51
+ import { PROGRAM_ID as PHOENIX_PROGRAM_ID } from '@ellipsis-labs/phoenix-sdk';
52
+ import { DRIFT_ORACLE_RECEIVER_ID } from './config';
53
+ import { getFeedIdUint8Array } from './util/pythOracleUtils';
54
+
55
+ const OPENBOOK_PROGRAM_ID = new PublicKey(
56
+ 'opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb'
57
+ );
58
+
59
+ export class AdminClient extends DriftClient {
60
+ public async initialize(
61
+ usdcMint: PublicKey,
62
+ _adminControlsPrices: boolean
63
+ ): Promise<[TransactionSignature]> {
64
+ const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(
65
+ await this.getStatePublicKey()
66
+ );
67
+ if (stateAccountRPCResponse.value !== null) {
68
+ throw new Error('Clearing house already initialized');
69
+ }
70
+
71
+ const [driftStatePublicKey] = await getDriftStateAccountPublicKeyAndNonce(
72
+ this.program.programId
73
+ );
74
+
75
+ const initializeIx = await this.program.instruction.initialize({
76
+ accounts: {
77
+ admin: this.isSubscribed
78
+ ? this.getStateAccount().admin
79
+ : this.wallet.publicKey,
80
+ state: driftStatePublicKey,
81
+ quoteAssetMint: usdcMint,
82
+ rent: SYSVAR_RENT_PUBKEY,
83
+ driftSigner: this.getSignerPublicKey(),
84
+ systemProgram: anchor.web3.SystemProgram.programId,
85
+ tokenProgram: TOKEN_PROGRAM_ID,
86
+ },
87
+ });
88
+
89
+ const tx = await this.buildTransaction(initializeIx);
90
+
91
+ const { txSig } = await super.sendTransaction(tx, [], this.opts);
92
+
93
+ return [txSig];
94
+ }
95
+
96
+ public async initializeSpotMarket(
97
+ mint: PublicKey,
98
+ optimalUtilization: number,
99
+ optimalRate: number,
100
+ maxRate: number,
101
+ oracle: PublicKey,
102
+ oracleSource: OracleSource,
103
+ initialAssetWeight: number,
104
+ maintenanceAssetWeight: number,
105
+ initialLiabilityWeight: number,
106
+ maintenanceLiabilityWeight: number,
107
+ imfFactor = 0,
108
+ liquidatorFee = 0,
109
+ ifLiquidationFee = 0,
110
+ activeStatus = true,
111
+ assetTier = AssetTier.COLLATERAL,
112
+ scaleInitialAssetWeightStart = ZERO,
113
+ withdrawGuardThreshold = ZERO,
114
+ orderTickSize = ONE,
115
+ orderStepSize = ONE,
116
+ ifTotalFactor = 0,
117
+ name = DEFAULT_MARKET_NAME,
118
+ marketIndex?: number
119
+ ): Promise<TransactionSignature> {
120
+ const spotMarketIndex =
121
+ marketIndex ?? this.getStateAccount().numberOfSpotMarkets;
122
+
123
+ const initializeIx = await this.getInitializeSpotMarketIx(
124
+ mint,
125
+ optimalUtilization,
126
+ optimalRate,
127
+ maxRate,
128
+ oracle,
129
+ oracleSource,
130
+ initialAssetWeight,
131
+ maintenanceAssetWeight,
132
+ initialLiabilityWeight,
133
+ maintenanceLiabilityWeight,
134
+ imfFactor,
135
+ liquidatorFee,
136
+ ifLiquidationFee,
137
+ activeStatus,
138
+ assetTier,
139
+ scaleInitialAssetWeightStart,
140
+ withdrawGuardThreshold,
141
+ orderTickSize,
142
+ orderStepSize,
143
+ ifTotalFactor,
144
+ name,
145
+ marketIndex
146
+ );
147
+
148
+ const tx = await this.buildTransaction(initializeIx);
149
+
150
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
151
+
152
+ await this.accountSubscriber.addSpotMarket(spotMarketIndex);
153
+ await this.accountSubscriber.addOracle({
154
+ source: oracleSource,
155
+ publicKey: oracle,
156
+ });
157
+ await this.accountSubscriber.setSpotOracleMap();
158
+
159
+ return txSig;
160
+ }
161
+
162
+ public async getInitializeSpotMarketIx(
163
+ mint: PublicKey,
164
+ optimalUtilization: number,
165
+ optimalRate: number,
166
+ maxRate: number,
167
+ oracle: PublicKey,
168
+ oracleSource: OracleSource,
169
+ initialAssetWeight: number,
170
+ maintenanceAssetWeight: number,
171
+ initialLiabilityWeight: number,
172
+ maintenanceLiabilityWeight: number,
173
+ imfFactor = 0,
174
+ liquidatorFee = 0,
175
+ ifLiquidationFee = 0,
176
+ activeStatus = true,
177
+ assetTier = AssetTier.COLLATERAL,
178
+ scaleInitialAssetWeightStart = ZERO,
179
+ withdrawGuardThreshold = ZERO,
180
+ orderTickSize = ONE,
181
+ orderStepSize = ONE,
182
+ ifTotalFactor = 0,
183
+ name = DEFAULT_MARKET_NAME,
184
+ marketIndex?: number
185
+ ): Promise<TransactionInstruction> {
186
+ const spotMarketIndex =
187
+ marketIndex ?? this.getStateAccount().numberOfSpotMarkets;
188
+ const spotMarket = await getSpotMarketPublicKey(
189
+ this.program.programId,
190
+ spotMarketIndex
191
+ );
192
+
193
+ const spotMarketVault = await getSpotMarketVaultPublicKey(
194
+ this.program.programId,
195
+ spotMarketIndex
196
+ );
197
+
198
+ const insuranceFundVault = await getInsuranceFundVaultPublicKey(
199
+ this.program.programId,
200
+ spotMarketIndex
201
+ );
202
+
203
+ const tokenProgram = (await this.connection.getAccountInfo(mint)).owner;
204
+
205
+ const nameBuffer = encodeName(name);
206
+ const initializeIx = await this.program.instruction.initializeSpotMarket(
207
+ optimalUtilization,
208
+ optimalRate,
209
+ maxRate,
210
+ oracleSource,
211
+ initialAssetWeight,
212
+ maintenanceAssetWeight,
213
+ initialLiabilityWeight,
214
+ maintenanceLiabilityWeight,
215
+ imfFactor,
216
+ liquidatorFee,
217
+ ifLiquidationFee,
218
+ activeStatus,
219
+ assetTier,
220
+ scaleInitialAssetWeightStart,
221
+ withdrawGuardThreshold,
222
+ orderTickSize,
223
+ orderStepSize,
224
+ ifTotalFactor,
225
+ nameBuffer,
226
+ {
227
+ accounts: {
228
+ admin: this.isSubscribed
229
+ ? this.getStateAccount().admin
230
+ : this.wallet.publicKey,
231
+ state: await this.getStatePublicKey(),
232
+ spotMarket,
233
+ spotMarketVault,
234
+ insuranceFundVault,
235
+ driftSigner: this.getSignerPublicKey(),
236
+ spotMarketMint: mint,
237
+ oracle,
238
+ rent: SYSVAR_RENT_PUBKEY,
239
+ systemProgram: anchor.web3.SystemProgram.programId,
240
+ tokenProgram,
241
+ },
242
+ }
243
+ );
244
+
245
+ return initializeIx;
246
+ }
247
+
248
+ public async deleteInitializedSpotMarket(
249
+ marketIndex: number
250
+ ): Promise<TransactionSignature> {
251
+ const deleteInitializeMarketIx =
252
+ await this.getDeleteInitializedSpotMarketIx(marketIndex);
253
+
254
+ const tx = await this.buildTransaction(deleteInitializeMarketIx);
255
+
256
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
257
+
258
+ return txSig;
259
+ }
260
+
261
+ public async getDeleteInitializedSpotMarketIx(
262
+ marketIndex: number
263
+ ): Promise<TransactionInstruction> {
264
+ const spotMarketPublicKey = await getSpotMarketPublicKey(
265
+ this.program.programId,
266
+ marketIndex
267
+ );
268
+
269
+ const spotMarketVaultPublicKey = await getSpotMarketVaultPublicKey(
270
+ this.program.programId,
271
+ marketIndex
272
+ );
273
+
274
+ const insuranceFundVaultPublicKey = await getInsuranceFundVaultPublicKey(
275
+ this.program.programId,
276
+ marketIndex
277
+ );
278
+
279
+ return await this.program.instruction.deleteInitializedSpotMarket(
280
+ marketIndex,
281
+ {
282
+ accounts: {
283
+ state: await this.getStatePublicKey(),
284
+ admin: this.isSubscribed
285
+ ? this.getStateAccount().admin
286
+ : this.wallet.publicKey,
287
+ spotMarket: spotMarketPublicKey,
288
+ spotMarketVault: spotMarketVaultPublicKey,
289
+ insuranceFundVault: insuranceFundVaultPublicKey,
290
+ driftSigner: this.getSignerPublicKey(),
291
+ tokenProgram: TOKEN_PROGRAM_ID,
292
+ },
293
+ }
294
+ );
295
+ }
296
+
297
+ public async initializeSerumFulfillmentConfig(
298
+ marketIndex: number,
299
+ serumMarket: PublicKey,
300
+ serumProgram: PublicKey
301
+ ): Promise<TransactionSignature> {
302
+ const initializeIx = await this.getInitializeSerumFulfillmentConfigIx(
303
+ marketIndex,
304
+ serumMarket,
305
+ serumProgram
306
+ );
307
+
308
+ const tx = await this.buildTransaction(initializeIx);
309
+
310
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
311
+
312
+ return txSig;
313
+ }
314
+
315
+ public async getInitializeSerumFulfillmentConfigIx(
316
+ marketIndex: number,
317
+ serumMarket: PublicKey,
318
+ serumProgram: PublicKey
319
+ ): Promise<TransactionInstruction> {
320
+ const serumOpenOrders = getSerumOpenOrdersPublicKey(
321
+ this.program.programId,
322
+ serumMarket
323
+ );
324
+
325
+ const serumFulfillmentConfig = getSerumFulfillmentConfigPublicKey(
326
+ this.program.programId,
327
+ serumMarket
328
+ );
329
+
330
+ return await this.program.instruction.initializeSerumFulfillmentConfig(
331
+ marketIndex,
332
+ {
333
+ accounts: {
334
+ admin: this.isSubscribed
335
+ ? this.getStateAccount().admin
336
+ : this.wallet.publicKey,
337
+ state: await this.getStatePublicKey(),
338
+ baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
339
+ quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
340
+ driftSigner: this.getSignerPublicKey(),
341
+ serumProgram,
342
+ serumMarket,
343
+ serumOpenOrders,
344
+ rent: SYSVAR_RENT_PUBKEY,
345
+ systemProgram: anchor.web3.SystemProgram.programId,
346
+ serumFulfillmentConfig,
347
+ },
348
+ }
349
+ );
350
+ }
351
+
352
+ public async initializePhoenixFulfillmentConfig(
353
+ marketIndex: number,
354
+ phoenixMarket: PublicKey
355
+ ): Promise<TransactionSignature> {
356
+ const initializeIx = await this.getInitializePhoenixFulfillmentConfigIx(
357
+ marketIndex,
358
+ phoenixMarket
359
+ );
360
+
361
+ const tx = await this.buildTransaction(initializeIx);
362
+
363
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
364
+
365
+ return txSig;
366
+ }
367
+
368
+ public async getInitializePhoenixFulfillmentConfigIx(
369
+ marketIndex: number,
370
+ phoenixMarket: PublicKey
371
+ ): Promise<TransactionInstruction> {
372
+ const phoenixFulfillmentConfig = getPhoenixFulfillmentConfigPublicKey(
373
+ this.program.programId,
374
+ phoenixMarket
375
+ );
376
+
377
+ return await this.program.instruction.initializePhoenixFulfillmentConfig(
378
+ marketIndex,
379
+ {
380
+ accounts: {
381
+ admin: this.isSubscribed
382
+ ? this.getStateAccount().admin
383
+ : this.wallet.publicKey,
384
+ state: await this.getStatePublicKey(),
385
+ baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
386
+ quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
387
+ driftSigner: this.getSignerPublicKey(),
388
+ phoenixMarket: phoenixMarket,
389
+ phoenixProgram: PHOENIX_PROGRAM_ID,
390
+ rent: SYSVAR_RENT_PUBKEY,
391
+ systemProgram: anchor.web3.SystemProgram.programId,
392
+ phoenixFulfillmentConfig,
393
+ },
394
+ }
395
+ );
396
+ }
397
+
398
+ public async initializeOpenbookV2FulfillmentConfig(
399
+ marketIndex: number,
400
+ openbookMarket: PublicKey
401
+ ): Promise<TransactionSignature> {
402
+ const initializeIx = await this.getInitializeOpenbookV2FulfillmentConfigIx(
403
+ marketIndex,
404
+ openbookMarket
405
+ );
406
+
407
+ const tx = await this.buildTransaction(initializeIx);
408
+
409
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
410
+
411
+ return txSig;
412
+ }
413
+
414
+ public async getInitializeOpenbookV2FulfillmentConfigIx(
415
+ marketIndex: number,
416
+ openbookMarket: PublicKey
417
+ ): Promise<TransactionInstruction> {
418
+ const openbookFulfillmentConfig = getOpenbookV2FulfillmentConfigPublicKey(
419
+ this.program.programId,
420
+ openbookMarket
421
+ );
422
+
423
+ return this.program.instruction.initializeOpenbookV2FulfillmentConfig(
424
+ marketIndex,
425
+ {
426
+ accounts: {
427
+ baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
428
+ quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
429
+ state: await this.getStatePublicKey(),
430
+ openbookV2Program: OPENBOOK_PROGRAM_ID,
431
+ openbookV2Market: openbookMarket,
432
+ driftSigner: this.getSignerPublicKey(),
433
+ openbookV2FulfillmentConfig: openbookFulfillmentConfig,
434
+ admin: this.isSubscribed
435
+ ? this.getStateAccount().admin
436
+ : this.wallet.publicKey,
437
+ rent: SYSVAR_RENT_PUBKEY,
438
+ systemProgram: anchor.web3.SystemProgram.programId,
439
+ },
440
+ }
441
+ );
442
+ }
443
+
444
+ public async initializePerpMarket(
445
+ marketIndex: number,
446
+ priceOracle: PublicKey,
447
+ baseAssetReserve: BN,
448
+ quoteAssetReserve: BN,
449
+ periodicity: BN,
450
+ pegMultiplier: BN = PEG_PRECISION,
451
+ oracleSource: OracleSource = OracleSource.PYTH,
452
+ contractTier: ContractTier = ContractTier.SPECULATIVE,
453
+ marginRatioInitial = 2000,
454
+ marginRatioMaintenance = 500,
455
+ liquidatorFee = 0,
456
+ ifLiquidatorFee = 10000,
457
+ imfFactor = 0,
458
+ activeStatus = true,
459
+ baseSpread = 0,
460
+ maxSpread = 142500,
461
+ maxOpenInterest = ZERO,
462
+ maxRevenueWithdrawPerPeriod = ZERO,
463
+ quoteMaxInsurance = ZERO,
464
+ orderStepSize = BASE_PRECISION.divn(10000),
465
+ orderTickSize = PRICE_PRECISION.divn(100000),
466
+ minOrderSize = BASE_PRECISION.divn(10000),
467
+ concentrationCoefScale = ONE,
468
+ curveUpdateIntensity = 0,
469
+ ammJitIntensity = 0,
470
+ name = DEFAULT_MARKET_NAME
471
+ ): Promise<TransactionSignature> {
472
+ const currentPerpMarketIndex = this.getStateAccount().numberOfMarkets;
473
+
474
+ const initializeMarketIx = await this.getInitializePerpMarketIx(
475
+ marketIndex,
476
+ priceOracle,
477
+ baseAssetReserve,
478
+ quoteAssetReserve,
479
+ periodicity,
480
+ pegMultiplier,
481
+ oracleSource,
482
+ contractTier,
483
+ marginRatioInitial,
484
+ marginRatioMaintenance,
485
+ liquidatorFee,
486
+ ifLiquidatorFee,
487
+ imfFactor,
488
+ activeStatus,
489
+ baseSpread,
490
+ maxSpread,
491
+ maxOpenInterest,
492
+ maxRevenueWithdrawPerPeriod,
493
+ quoteMaxInsurance,
494
+ orderStepSize,
495
+ orderTickSize,
496
+ minOrderSize,
497
+ concentrationCoefScale,
498
+ curveUpdateIntensity,
499
+ ammJitIntensity,
500
+ name
501
+ );
502
+ const tx = await this.buildTransaction(initializeMarketIx);
503
+
504
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
505
+
506
+ while (this.getStateAccount().numberOfMarkets <= currentPerpMarketIndex) {
507
+ await this.fetchAccounts();
508
+ }
509
+
510
+ await this.accountSubscriber.addPerpMarket(marketIndex);
511
+ await this.accountSubscriber.addOracle({
512
+ source: oracleSource,
513
+ publicKey: priceOracle,
514
+ });
515
+ await this.accountSubscriber.setPerpOracleMap();
516
+
517
+ return txSig;
518
+ }
519
+
520
+ public async getInitializePerpMarketIx(
521
+ marketIndex: number,
522
+ priceOracle: PublicKey,
523
+ baseAssetReserve: BN,
524
+ quoteAssetReserve: BN,
525
+ periodicity: BN,
526
+ pegMultiplier: BN = PEG_PRECISION,
527
+ oracleSource: OracleSource = OracleSource.PYTH,
528
+ contractTier: ContractTier = ContractTier.SPECULATIVE,
529
+ marginRatioInitial = 2000,
530
+ marginRatioMaintenance = 500,
531
+ liquidatorFee = 0,
532
+ ifLiquidatorFee = 10000,
533
+ imfFactor = 0,
534
+ activeStatus = true,
535
+ baseSpread = 0,
536
+ maxSpread = 142500,
537
+ maxOpenInterest = ZERO,
538
+ maxRevenueWithdrawPerPeriod = ZERO,
539
+ quoteMaxInsurance = ZERO,
540
+ orderStepSize = BASE_PRECISION.divn(10000),
541
+ orderTickSize = PRICE_PRECISION.divn(100000),
542
+ minOrderSize = BASE_PRECISION.divn(10000),
543
+ concentrationCoefScale = ONE,
544
+ curveUpdateIntensity = 0,
545
+ ammJitIntensity = 0,
546
+ name = DEFAULT_MARKET_NAME
547
+ ): Promise<TransactionInstruction> {
548
+ const perpMarketPublicKey = await getPerpMarketPublicKey(
549
+ this.program.programId,
550
+ marketIndex
551
+ );
552
+
553
+ const nameBuffer = encodeName(name);
554
+ return await this.program.instruction.initializePerpMarket(
555
+ marketIndex,
556
+ baseAssetReserve,
557
+ quoteAssetReserve,
558
+ periodicity,
559
+ pegMultiplier,
560
+ oracleSource,
561
+ contractTier,
562
+ marginRatioInitial,
563
+ marginRatioMaintenance,
564
+ liquidatorFee,
565
+ ifLiquidatorFee,
566
+ imfFactor,
567
+ activeStatus,
568
+ baseSpread,
569
+ maxSpread,
570
+ maxOpenInterest,
571
+ maxRevenueWithdrawPerPeriod,
572
+ quoteMaxInsurance,
573
+ orderStepSize,
574
+ orderTickSize,
575
+ minOrderSize,
576
+ concentrationCoefScale,
577
+ curveUpdateIntensity,
578
+ ammJitIntensity,
579
+ nameBuffer,
580
+ {
581
+ accounts: {
582
+ state: await this.getStatePublicKey(),
583
+ admin: this.isSubscribed
584
+ ? this.getStateAccount().admin
585
+ : this.wallet.publicKey,
586
+ oracle: priceOracle,
587
+ perpMarket: perpMarketPublicKey,
588
+ rent: SYSVAR_RENT_PUBKEY,
589
+ systemProgram: anchor.web3.SystemProgram.programId,
590
+ },
591
+ }
592
+ );
593
+ }
594
+
595
+ public async initializePredictionMarket(
596
+ perpMarketIndex: number
597
+ ): Promise<TransactionSignature> {
598
+ const updatePerpMarketConcentrationCoefIx =
599
+ await this.getInitializePredictionMarketIx(perpMarketIndex);
600
+
601
+ const tx = await this.buildTransaction(updatePerpMarketConcentrationCoefIx);
602
+
603
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
604
+
605
+ return txSig;
606
+ }
607
+
608
+ public async getInitializePredictionMarketIx(
609
+ perpMarketIndex: number
610
+ ): Promise<TransactionInstruction> {
611
+ return await this.program.instruction.initializePredictionMarket({
612
+ accounts: {
613
+ state: await this.getStatePublicKey(),
614
+ admin: this.isSubscribed
615
+ ? this.getStateAccount().admin
616
+ : this.wallet.publicKey,
617
+ perpMarket: await getPerpMarketPublicKey(
618
+ this.program.programId,
619
+ perpMarketIndex
620
+ ),
621
+ },
622
+ });
623
+ }
624
+
625
+ public async deleteInitializedPerpMarket(
626
+ marketIndex: number
627
+ ): Promise<TransactionSignature> {
628
+ const deleteInitializeMarketIx =
629
+ await this.getDeleteInitializedPerpMarketIx(marketIndex);
630
+
631
+ const tx = await this.buildTransaction(deleteInitializeMarketIx);
632
+
633
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
634
+
635
+ return txSig;
636
+ }
637
+
638
+ public async getDeleteInitializedPerpMarketIx(
639
+ marketIndex: number
640
+ ): Promise<TransactionInstruction> {
641
+ const perpMarketPublicKey = await getPerpMarketPublicKey(
642
+ this.program.programId,
643
+ marketIndex
644
+ );
645
+
646
+ return await this.program.instruction.deleteInitializedPerpMarket(
647
+ marketIndex,
648
+ {
649
+ accounts: {
650
+ state: await this.getStatePublicKey(),
651
+ admin: this.isSubscribed
652
+ ? this.getStateAccount().admin
653
+ : this.wallet.publicKey,
654
+ perpMarket: perpMarketPublicKey,
655
+ },
656
+ }
657
+ );
658
+ }
659
+
660
+ public async moveAmmPrice(
661
+ perpMarketIndex: number,
662
+ baseAssetReserve: BN,
663
+ quoteAssetReserve: BN,
664
+ sqrtK?: BN
665
+ ): Promise<TransactionSignature> {
666
+ const moveAmmPriceIx = await this.getMoveAmmPriceIx(
667
+ perpMarketIndex,
668
+ baseAssetReserve,
669
+ quoteAssetReserve,
670
+ sqrtK
671
+ );
672
+
673
+ const tx = await this.buildTransaction(moveAmmPriceIx);
674
+
675
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
676
+
677
+ return txSig;
678
+ }
679
+
680
+ public async getMoveAmmPriceIx(
681
+ perpMarketIndex: number,
682
+ baseAssetReserve: BN,
683
+ quoteAssetReserve: BN,
684
+ sqrtK?: BN
685
+ ): Promise<TransactionInstruction> {
686
+ const marketPublicKey = await getPerpMarketPublicKey(
687
+ this.program.programId,
688
+ perpMarketIndex
689
+ );
690
+
691
+ if (sqrtK == undefined) {
692
+ sqrtK = squareRootBN(baseAssetReserve.mul(quoteAssetReserve));
693
+ }
694
+
695
+ return await this.program.instruction.moveAmmPrice(
696
+ baseAssetReserve,
697
+ quoteAssetReserve,
698
+ sqrtK,
699
+ {
700
+ accounts: {
701
+ state: await this.getStatePublicKey(),
702
+ admin: this.isSubscribed
703
+ ? this.getStateAccount().admin
704
+ : this.wallet.publicKey,
705
+ perpMarket: marketPublicKey,
706
+ },
707
+ }
708
+ );
709
+ }
710
+
711
+ public async updateK(
712
+ perpMarketIndex: number,
713
+ sqrtK: BN
714
+ ): Promise<TransactionSignature> {
715
+ const updateKIx = await this.getUpdateKIx(perpMarketIndex, sqrtK);
716
+
717
+ const tx = await this.buildTransaction(updateKIx);
718
+
719
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
720
+
721
+ return txSig;
722
+ }
723
+
724
+ public async getUpdateKIx(
725
+ perpMarketIndex: number,
726
+ sqrtK: BN
727
+ ): Promise<TransactionInstruction> {
728
+ return await this.program.instruction.updateK(sqrtK, {
729
+ accounts: {
730
+ state: await this.getStatePublicKey(),
731
+ admin: this.isSubscribed
732
+ ? this.getStateAccount().admin
733
+ : this.wallet.publicKey,
734
+ perpMarket: await getPerpMarketPublicKey(
735
+ this.program.programId,
736
+ perpMarketIndex
737
+ ),
738
+ oracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
739
+ },
740
+ });
741
+ }
742
+
743
+ public async recenterPerpMarketAmm(
744
+ perpMarketIndex: number,
745
+ pegMultiplier: BN,
746
+ sqrtK: BN
747
+ ): Promise<TransactionSignature> {
748
+ const recenterPerpMarketAmmIx = await this.getRecenterPerpMarketAmmIx(
749
+ perpMarketIndex,
750
+ pegMultiplier,
751
+ sqrtK
752
+ );
753
+
754
+ const tx = await this.buildTransaction(recenterPerpMarketAmmIx);
755
+
756
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
757
+
758
+ return txSig;
759
+ }
760
+
761
+ public async getRecenterPerpMarketAmmIx(
762
+ perpMarketIndex: number,
763
+ pegMultiplier: BN,
764
+ sqrtK: BN
765
+ ): Promise<TransactionInstruction> {
766
+ const marketPublicKey = await getPerpMarketPublicKey(
767
+ this.program.programId,
768
+ perpMarketIndex
769
+ );
770
+
771
+ return await this.program.instruction.recenterPerpMarketAmm(
772
+ pegMultiplier,
773
+ sqrtK,
774
+ {
775
+ accounts: {
776
+ state: await this.getStatePublicKey(),
777
+ admin: this.isSubscribed
778
+ ? this.getStateAccount().admin
779
+ : this.wallet.publicKey,
780
+ perpMarket: marketPublicKey,
781
+ },
782
+ }
783
+ );
784
+ }
785
+
786
+ public async updatePerpMarketConcentrationScale(
787
+ perpMarketIndex: number,
788
+ concentrationScale: BN
789
+ ): Promise<TransactionSignature> {
790
+ const updatePerpMarketConcentrationCoefIx =
791
+ await this.getUpdatePerpMarketConcentrationScaleIx(
792
+ perpMarketIndex,
793
+ concentrationScale
794
+ );
795
+
796
+ const tx = await this.buildTransaction(updatePerpMarketConcentrationCoefIx);
797
+
798
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
799
+
800
+ return txSig;
801
+ }
802
+
803
+ public async getUpdatePerpMarketConcentrationScaleIx(
804
+ perpMarketIndex: number,
805
+ concentrationScale: BN
806
+ ): Promise<TransactionInstruction> {
807
+ return await this.program.instruction.updatePerpMarketConcentrationCoef(
808
+ concentrationScale,
809
+ {
810
+ accounts: {
811
+ state: await this.getStatePublicKey(),
812
+ admin: this.isSubscribed
813
+ ? this.getStateAccount().admin
814
+ : this.wallet.publicKey,
815
+ perpMarket: await getPerpMarketPublicKey(
816
+ this.program.programId,
817
+ perpMarketIndex
818
+ ),
819
+ },
820
+ }
821
+ );
822
+ }
823
+
824
+ public async moveAmmToPrice(
825
+ perpMarketIndex: number,
826
+ targetPrice: BN
827
+ ): Promise<TransactionSignature> {
828
+ const moveAmmPriceIx = await this.getMoveAmmToPriceIx(
829
+ perpMarketIndex,
830
+ targetPrice
831
+ );
832
+
833
+ const tx = await this.buildTransaction(moveAmmPriceIx);
834
+
835
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
836
+
837
+ return txSig;
838
+ }
839
+
840
+ public async getMoveAmmToPriceIx(
841
+ perpMarketIndex: number,
842
+ targetPrice: BN
843
+ ): Promise<TransactionInstruction> {
844
+ const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
845
+
846
+ const [direction, tradeSize, _] = calculateTargetPriceTrade(
847
+ perpMarket,
848
+ targetPrice,
849
+ new BN(1000),
850
+ 'quote',
851
+ undefined //todo
852
+ );
853
+
854
+ const [newQuoteAssetAmount, newBaseAssetAmount] =
855
+ calculateAmmReservesAfterSwap(
856
+ perpMarket.amm,
857
+ 'quote',
858
+ tradeSize,
859
+ getSwapDirection('quote', direction)
860
+ );
861
+
862
+ const perpMarketPublicKey = await getPerpMarketPublicKey(
863
+ this.program.programId,
864
+ perpMarketIndex
865
+ );
866
+
867
+ return await this.program.instruction.moveAmmPrice(
868
+ newBaseAssetAmount,
869
+ newQuoteAssetAmount,
870
+ perpMarket.amm.sqrtK,
871
+ {
872
+ accounts: {
873
+ state: await this.getStatePublicKey(),
874
+ admin: this.isSubscribed
875
+ ? this.getStateAccount().admin
876
+ : this.wallet.publicKey,
877
+ perpMarket: perpMarketPublicKey,
878
+ },
879
+ }
880
+ );
881
+ }
882
+
883
+ public async repegAmmCurve(
884
+ newPeg: BN,
885
+ perpMarketIndex: number
886
+ ): Promise<TransactionSignature> {
887
+ const repegAmmCurveIx = await this.getRepegAmmCurveIx(
888
+ newPeg,
889
+ perpMarketIndex
890
+ );
891
+
892
+ const tx = await this.buildTransaction(repegAmmCurveIx);
893
+
894
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
895
+
896
+ return txSig;
897
+ }
898
+
899
+ public async getRepegAmmCurveIx(
900
+ newPeg: BN,
901
+ perpMarketIndex: number
902
+ ): Promise<TransactionInstruction> {
903
+ const perpMarketPublicKey = await getPerpMarketPublicKey(
904
+ this.program.programId,
905
+ perpMarketIndex
906
+ );
907
+ const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
908
+
909
+ return await this.program.instruction.repegAmmCurve(newPeg, {
910
+ accounts: {
911
+ state: await this.getStatePublicKey(),
912
+ admin: this.isSubscribed
913
+ ? this.getStateAccount().admin
914
+ : this.wallet.publicKey,
915
+ oracle: ammData.oracle,
916
+ perpMarket: perpMarketPublicKey,
917
+ },
918
+ });
919
+ }
920
+
921
+ public async updatePerpMarketAmmOracleTwap(
922
+ perpMarketIndex: number
923
+ ): Promise<TransactionSignature> {
924
+ const updatePerpMarketAmmOracleTwapIx =
925
+ await this.getUpdatePerpMarketAmmOracleTwapIx(perpMarketIndex);
926
+
927
+ const tx = await this.buildTransaction(updatePerpMarketAmmOracleTwapIx);
928
+
929
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
930
+
931
+ return txSig;
932
+ }
933
+
934
+ public async getUpdatePerpMarketAmmOracleTwapIx(
935
+ perpMarketIndex: number
936
+ ): Promise<TransactionInstruction> {
937
+ const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
938
+ const perpMarketPublicKey = await getPerpMarketPublicKey(
939
+ this.program.programId,
940
+ perpMarketIndex
941
+ );
942
+
943
+ return await this.program.instruction.updatePerpMarketAmmOracleTwap({
944
+ accounts: {
945
+ state: await this.getStatePublicKey(),
946
+ admin: this.isSubscribed
947
+ ? this.getStateAccount().admin
948
+ : this.wallet.publicKey,
949
+ oracle: ammData.oracle,
950
+ perpMarket: perpMarketPublicKey,
951
+ },
952
+ });
953
+ }
954
+
955
+ public async resetPerpMarketAmmOracleTwap(
956
+ perpMarketIndex: number
957
+ ): Promise<TransactionSignature> {
958
+ const resetPerpMarketAmmOracleTwapIx =
959
+ await this.getResetPerpMarketAmmOracleTwapIx(perpMarketIndex);
960
+
961
+ const tx = await this.buildTransaction(resetPerpMarketAmmOracleTwapIx);
962
+
963
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
964
+
965
+ return txSig;
966
+ }
967
+
968
+ public async getResetPerpMarketAmmOracleTwapIx(
969
+ perpMarketIndex: number
970
+ ): Promise<TransactionInstruction> {
971
+ const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
972
+ const perpMarketPublicKey = await getPerpMarketPublicKey(
973
+ this.program.programId,
974
+ perpMarketIndex
975
+ );
976
+
977
+ return await this.program.instruction.resetPerpMarketAmmOracleTwap({
978
+ accounts: {
979
+ state: await this.getStatePublicKey(),
980
+ admin: this.isSubscribed
981
+ ? this.getStateAccount().admin
982
+ : this.wallet.publicKey,
983
+ oracle: ammData.oracle,
984
+ perpMarket: perpMarketPublicKey,
985
+ },
986
+ });
987
+ }
988
+
989
+ public async depositIntoPerpMarketFeePool(
990
+ perpMarketIndex: number,
991
+ amount: BN,
992
+ sourceVault: PublicKey
993
+ ): Promise<TransactionSignature> {
994
+ const depositIntoPerpMarketFeePoolIx =
995
+ await this.getDepositIntoPerpMarketFeePoolIx(
996
+ perpMarketIndex,
997
+ amount,
998
+ sourceVault
999
+ );
1000
+
1001
+ const tx = await this.buildTransaction(depositIntoPerpMarketFeePoolIx);
1002
+
1003
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1004
+
1005
+ return txSig;
1006
+ }
1007
+
1008
+ public async getDepositIntoPerpMarketFeePoolIx(
1009
+ perpMarketIndex: number,
1010
+ amount: BN,
1011
+ sourceVault: PublicKey
1012
+ ): Promise<TransactionInstruction> {
1013
+ const spotMarket = this.getQuoteSpotMarketAccount();
1014
+
1015
+ return await this.program.instruction.depositIntoPerpMarketFeePool(amount, {
1016
+ accounts: {
1017
+ admin: this.isSubscribed
1018
+ ? this.getStateAccount().admin
1019
+ : this.wallet.publicKey,
1020
+ state: await this.getStatePublicKey(),
1021
+ perpMarket: await getPerpMarketPublicKey(
1022
+ this.program.programId,
1023
+ perpMarketIndex
1024
+ ),
1025
+ sourceVault,
1026
+ driftSigner: this.getSignerPublicKey(),
1027
+ quoteSpotMarket: spotMarket.pubkey,
1028
+ spotMarketVault: spotMarket.vault,
1029
+ tokenProgram: TOKEN_PROGRAM_ID,
1030
+ },
1031
+ });
1032
+ }
1033
+
1034
+ public async depositIntoSpotMarketVault(
1035
+ spotMarketIndex: number,
1036
+ amount: BN,
1037
+ sourceVault: PublicKey
1038
+ ): Promise<TransactionSignature> {
1039
+ const depositIntoPerpMarketFeePoolIx =
1040
+ await this.getDepositIntoSpotMarketVaultIx(
1041
+ spotMarketIndex,
1042
+ amount,
1043
+ sourceVault
1044
+ );
1045
+
1046
+ const tx = await this.buildTransaction(depositIntoPerpMarketFeePoolIx);
1047
+
1048
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1049
+
1050
+ return txSig;
1051
+ }
1052
+
1053
+ public async getDepositIntoSpotMarketVaultIx(
1054
+ spotMarketIndex: number,
1055
+ amount: BN,
1056
+ sourceVault: PublicKey
1057
+ ): Promise<TransactionInstruction> {
1058
+ const spotMarket = this.getSpotMarketAccount(spotMarketIndex);
1059
+
1060
+ const remainingAccounts = [];
1061
+ this.addTokenMintToRemainingAccounts(spotMarket, remainingAccounts);
1062
+ const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
1063
+ return await this.program.instruction.depositIntoSpotMarketVault(amount, {
1064
+ accounts: {
1065
+ admin: this.wallet.publicKey,
1066
+ state: await this.getStatePublicKey(),
1067
+ sourceVault,
1068
+ spotMarket: spotMarket.pubkey,
1069
+ spotMarketVault: spotMarket.vault,
1070
+ tokenProgram,
1071
+ },
1072
+ remainingAccounts,
1073
+ });
1074
+ }
1075
+
1076
+ public async updateAdmin(admin: PublicKey): Promise<TransactionSignature> {
1077
+ const updateAdminIx = await this.getUpdateAdminIx(admin);
1078
+
1079
+ const tx = await this.buildTransaction(updateAdminIx);
1080
+
1081
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1082
+
1083
+ return txSig;
1084
+ }
1085
+
1086
+ public async getUpdateAdminIx(
1087
+ admin: PublicKey
1088
+ ): Promise<TransactionInstruction> {
1089
+ return await this.program.instruction.updateAdmin(admin, {
1090
+ accounts: {
1091
+ admin: this.isSubscribed
1092
+ ? this.getStateAccount().admin
1093
+ : this.wallet.publicKey,
1094
+ state: await this.getStatePublicKey(),
1095
+ },
1096
+ });
1097
+ }
1098
+
1099
+ public async updatePerpMarketCurveUpdateIntensity(
1100
+ perpMarketIndex: number,
1101
+ curveUpdateIntensity: number
1102
+ ): Promise<TransactionSignature> {
1103
+ const updatePerpMarketCurveUpdateIntensityIx =
1104
+ await this.getUpdatePerpMarketCurveUpdateIntensityIx(
1105
+ perpMarketIndex,
1106
+ curveUpdateIntensity
1107
+ );
1108
+
1109
+ const tx = await this.buildTransaction(
1110
+ updatePerpMarketCurveUpdateIntensityIx
1111
+ );
1112
+
1113
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1114
+
1115
+ return txSig;
1116
+ }
1117
+
1118
+ public async getUpdatePerpMarketCurveUpdateIntensityIx(
1119
+ perpMarketIndex: number,
1120
+ curveUpdateIntensity: number
1121
+ ): Promise<TransactionInstruction> {
1122
+ return await this.program.instruction.updatePerpMarketCurveUpdateIntensity(
1123
+ curveUpdateIntensity,
1124
+ {
1125
+ accounts: {
1126
+ admin: this.isSubscribed
1127
+ ? this.getStateAccount().admin
1128
+ : this.wallet.publicKey,
1129
+ state: await this.getStatePublicKey(),
1130
+ perpMarket: await getPerpMarketPublicKey(
1131
+ this.program.programId,
1132
+ perpMarketIndex
1133
+ ),
1134
+ },
1135
+ }
1136
+ );
1137
+ }
1138
+
1139
+ public async updatePerpMarketTargetBaseAssetAmountPerLp(
1140
+ perpMarketIndex: number,
1141
+ targetBaseAssetAmountPerLP: number
1142
+ ): Promise<TransactionSignature> {
1143
+ const updatePerpMarketTargetBaseAssetAmountPerLpIx =
1144
+ await this.getUpdatePerpMarketTargetBaseAssetAmountPerLpIx(
1145
+ perpMarketIndex,
1146
+ targetBaseAssetAmountPerLP
1147
+ );
1148
+
1149
+ const tx = await this.buildTransaction(
1150
+ updatePerpMarketTargetBaseAssetAmountPerLpIx
1151
+ );
1152
+
1153
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1154
+
1155
+ return txSig;
1156
+ }
1157
+
1158
+ public async updatePerpMarketAmmSummaryStats(
1159
+ perpMarketIndex: number,
1160
+ updateAmmSummaryStats?: boolean,
1161
+ quoteAssetAmountWithUnsettledLp?: BN,
1162
+ netUnsettledFundingPnl?: BN
1163
+ ): Promise<TransactionSignature> {
1164
+ const updatePerpMarketMarginRatioIx =
1165
+ await this.getUpdatePerpMarketAmmSummaryStatsIx(
1166
+ perpMarketIndex,
1167
+ updateAmmSummaryStats,
1168
+ quoteAssetAmountWithUnsettledLp,
1169
+ netUnsettledFundingPnl
1170
+ );
1171
+
1172
+ const tx = await this.buildTransaction(updatePerpMarketMarginRatioIx);
1173
+
1174
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1175
+
1176
+ return txSig;
1177
+ }
1178
+
1179
+ public async getUpdatePerpMarketAmmSummaryStatsIx(
1180
+ perpMarketIndex: number,
1181
+ updateAmmSummaryStats?: boolean,
1182
+ quoteAssetAmountWithUnsettledLp?: BN,
1183
+ netUnsettledFundingPnl?: BN
1184
+ ): Promise<TransactionInstruction> {
1185
+ return await this.program.instruction.updatePerpMarketAmmSummaryStats(
1186
+ {
1187
+ updateAmmSummaryStats: updateAmmSummaryStats ?? null,
1188
+ quoteAssetAmountWithUnsettledLp:
1189
+ quoteAssetAmountWithUnsettledLp ?? null,
1190
+ netUnsettledFundingPnl: netUnsettledFundingPnl ?? null,
1191
+ },
1192
+ {
1193
+ accounts: {
1194
+ admin: this.wallet.publicKey,
1195
+ state: await this.getStatePublicKey(),
1196
+ perpMarket: await getPerpMarketPublicKey(
1197
+ this.program.programId,
1198
+ perpMarketIndex
1199
+ ),
1200
+ spotMarket: await getSpotMarketPublicKey(
1201
+ this.program.programId,
1202
+ QUOTE_SPOT_MARKET_INDEX
1203
+ ),
1204
+ oracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
1205
+ },
1206
+ }
1207
+ );
1208
+ }
1209
+
1210
+ public async getUpdatePerpMarketTargetBaseAssetAmountPerLpIx(
1211
+ perpMarketIndex: number,
1212
+ targetBaseAssetAmountPerLP: number
1213
+ ): Promise<TransactionInstruction> {
1214
+ return await this.program.instruction.updatePerpMarketTargetBaseAssetAmountPerLp(
1215
+ targetBaseAssetAmountPerLP,
1216
+ {
1217
+ accounts: {
1218
+ admin: this.isSubscribed
1219
+ ? this.getStateAccount().admin
1220
+ : this.wallet.publicKey,
1221
+ state: await this.getStatePublicKey(),
1222
+ perpMarket: await getPerpMarketPublicKey(
1223
+ this.program.programId,
1224
+ perpMarketIndex
1225
+ ),
1226
+ },
1227
+ }
1228
+ );
1229
+ }
1230
+
1231
+ public async updatePerpMarketMarginRatio(
1232
+ perpMarketIndex: number,
1233
+ marginRatioInitial: number,
1234
+ marginRatioMaintenance: number
1235
+ ): Promise<TransactionSignature> {
1236
+ const updatePerpMarketMarginRatioIx =
1237
+ await this.getUpdatePerpMarketMarginRatioIx(
1238
+ perpMarketIndex,
1239
+ marginRatioInitial,
1240
+ marginRatioMaintenance
1241
+ );
1242
+
1243
+ const tx = await this.buildTransaction(updatePerpMarketMarginRatioIx);
1244
+
1245
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1246
+
1247
+ return txSig;
1248
+ }
1249
+
1250
+ public async getUpdatePerpMarketMarginRatioIx(
1251
+ perpMarketIndex: number,
1252
+ marginRatioInitial: number,
1253
+ marginRatioMaintenance: number
1254
+ ): Promise<TransactionInstruction> {
1255
+ return await this.program.instruction.updatePerpMarketMarginRatio(
1256
+ marginRatioInitial,
1257
+ marginRatioMaintenance,
1258
+ {
1259
+ accounts: {
1260
+ admin: this.isSubscribed
1261
+ ? this.getStateAccount().admin
1262
+ : this.wallet.publicKey,
1263
+ state: await this.getStatePublicKey(),
1264
+ perpMarket: await getPerpMarketPublicKey(
1265
+ this.program.programId,
1266
+ perpMarketIndex
1267
+ ),
1268
+ },
1269
+ }
1270
+ );
1271
+ }
1272
+
1273
+ public async updatePerpMarketHighLeverageMarginRatio(
1274
+ perpMarketIndex: number,
1275
+ marginRatioInitial: number,
1276
+ marginRatioMaintenance: number
1277
+ ): Promise<TransactionSignature> {
1278
+ const updatePerpMarketHighLeverageMarginRatioIx =
1279
+ await this.getUpdatePerpMarketHighLeverageMarginRatioIx(
1280
+ perpMarketIndex,
1281
+ marginRatioInitial,
1282
+ marginRatioMaintenance
1283
+ );
1284
+
1285
+ const tx = await this.buildTransaction(
1286
+ updatePerpMarketHighLeverageMarginRatioIx
1287
+ );
1288
+
1289
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1290
+
1291
+ return txSig;
1292
+ }
1293
+
1294
+ public async getUpdatePerpMarketHighLeverageMarginRatioIx(
1295
+ perpMarketIndex: number,
1296
+ marginRatioInitial: number,
1297
+ marginRatioMaintenance: number
1298
+ ): Promise<TransactionInstruction> {
1299
+ return await this.program.instruction.updatePerpMarketHighLeverageMarginRatio(
1300
+ marginRatioInitial,
1301
+ marginRatioMaintenance,
1302
+ {
1303
+ accounts: {
1304
+ admin: this.isSubscribed
1305
+ ? this.getStateAccount().admin
1306
+ : this.wallet.publicKey,
1307
+ state: await this.getStatePublicKey(),
1308
+ perpMarket: await getPerpMarketPublicKey(
1309
+ this.program.programId,
1310
+ perpMarketIndex
1311
+ ),
1312
+ },
1313
+ }
1314
+ );
1315
+ }
1316
+
1317
+ public async updatePerpMarketImfFactor(
1318
+ perpMarketIndex: number,
1319
+ imfFactor: number,
1320
+ unrealizedPnlImfFactor: number
1321
+ ): Promise<TransactionSignature> {
1322
+ const updatePerpMarketImfFactorIx =
1323
+ await this.getUpdatePerpMarketImfFactorIx(
1324
+ perpMarketIndex,
1325
+ imfFactor,
1326
+ unrealizedPnlImfFactor
1327
+ );
1328
+
1329
+ const tx = await this.buildTransaction(updatePerpMarketImfFactorIx);
1330
+
1331
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1332
+
1333
+ return txSig;
1334
+ }
1335
+
1336
+ public async getUpdatePerpMarketImfFactorIx(
1337
+ perpMarketIndex: number,
1338
+ imfFactor: number,
1339
+ unrealizedPnlImfFactor: number
1340
+ ): Promise<TransactionInstruction> {
1341
+ return await this.program.instruction.updatePerpMarketImfFactor(
1342
+ imfFactor,
1343
+ unrealizedPnlImfFactor,
1344
+ {
1345
+ accounts: {
1346
+ admin: this.isSubscribed
1347
+ ? this.getStateAccount().admin
1348
+ : this.wallet.publicKey,
1349
+ state: await this.getStatePublicKey(),
1350
+ perpMarket: await getPerpMarketPublicKey(
1351
+ this.program.programId,
1352
+ perpMarketIndex
1353
+ ),
1354
+ },
1355
+ }
1356
+ );
1357
+ }
1358
+
1359
+ public async updatePerpMarketBaseSpread(
1360
+ perpMarketIndex: number,
1361
+ baseSpread: number
1362
+ ): Promise<TransactionSignature> {
1363
+ const updatePerpMarketBaseSpreadIx =
1364
+ await this.getUpdatePerpMarketBaseSpreadIx(perpMarketIndex, baseSpread);
1365
+
1366
+ const tx = await this.buildTransaction(updatePerpMarketBaseSpreadIx);
1367
+
1368
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1369
+
1370
+ return txSig;
1371
+ }
1372
+
1373
+ public async getUpdatePerpMarketBaseSpreadIx(
1374
+ perpMarketIndex: number,
1375
+ baseSpread: number
1376
+ ): Promise<TransactionInstruction> {
1377
+ return await this.program.instruction.updatePerpMarketBaseSpread(
1378
+ baseSpread,
1379
+ {
1380
+ accounts: {
1381
+ admin: this.isSubscribed
1382
+ ? this.getStateAccount().admin
1383
+ : this.wallet.publicKey,
1384
+ state: await this.getStatePublicKey(),
1385
+ perpMarket: await getPerpMarketPublicKey(
1386
+ this.program.programId,
1387
+ perpMarketIndex
1388
+ ),
1389
+ },
1390
+ }
1391
+ );
1392
+ }
1393
+
1394
+ public async updateAmmJitIntensity(
1395
+ perpMarketIndex: number,
1396
+ ammJitIntensity: number
1397
+ ): Promise<TransactionSignature> {
1398
+ const updateAmmJitIntensityIx = await this.getUpdateAmmJitIntensityIx(
1399
+ perpMarketIndex,
1400
+ ammJitIntensity
1401
+ );
1402
+
1403
+ const tx = await this.buildTransaction(updateAmmJitIntensityIx);
1404
+
1405
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1406
+
1407
+ return txSig;
1408
+ }
1409
+
1410
+ public async getUpdateAmmJitIntensityIx(
1411
+ perpMarketIndex: number,
1412
+ ammJitIntensity: number
1413
+ ): Promise<TransactionInstruction> {
1414
+ return await this.program.instruction.updateAmmJitIntensity(
1415
+ ammJitIntensity,
1416
+ {
1417
+ accounts: {
1418
+ admin: this.isSubscribed
1419
+ ? this.getStateAccount().admin
1420
+ : this.wallet.publicKey,
1421
+ state: await this.getStatePublicKey(),
1422
+ perpMarket: await getPerpMarketPublicKey(
1423
+ this.program.programId,
1424
+ perpMarketIndex
1425
+ ),
1426
+ },
1427
+ }
1428
+ );
1429
+ }
1430
+
1431
+ public async updatePerpMarketName(
1432
+ perpMarketIndex: number,
1433
+ name: string
1434
+ ): Promise<TransactionSignature> {
1435
+ const updatePerpMarketNameIx = await this.getUpdatePerpMarketNameIx(
1436
+ perpMarketIndex,
1437
+ name
1438
+ );
1439
+
1440
+ const tx = await this.buildTransaction(updatePerpMarketNameIx);
1441
+
1442
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1443
+
1444
+ return txSig;
1445
+ }
1446
+
1447
+ public async getUpdatePerpMarketNameIx(
1448
+ perpMarketIndex: number,
1449
+ name: string
1450
+ ): Promise<TransactionInstruction> {
1451
+ const nameBuffer = encodeName(name);
1452
+ return await this.program.instruction.updatePerpMarketName(nameBuffer, {
1453
+ accounts: {
1454
+ admin: this.isSubscribed
1455
+ ? this.getStateAccount().admin
1456
+ : this.wallet.publicKey,
1457
+ state: await this.getStatePublicKey(),
1458
+ perpMarket: await getPerpMarketPublicKey(
1459
+ this.program.programId,
1460
+ perpMarketIndex
1461
+ ),
1462
+ },
1463
+ });
1464
+ }
1465
+
1466
+ public async updateSpotMarketName(
1467
+ spotMarketIndex: number,
1468
+ name: string
1469
+ ): Promise<TransactionSignature> {
1470
+ const updateSpotMarketNameIx = await this.getUpdateSpotMarketNameIx(
1471
+ spotMarketIndex,
1472
+ name
1473
+ );
1474
+
1475
+ const tx = await this.buildTransaction(updateSpotMarketNameIx);
1476
+
1477
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1478
+
1479
+ return txSig;
1480
+ }
1481
+
1482
+ public async getUpdateSpotMarketNameIx(
1483
+ spotMarketIndex: number,
1484
+ name: string
1485
+ ): Promise<TransactionInstruction> {
1486
+ const nameBuffer = encodeName(name);
1487
+ return await this.program.instruction.updateSpotMarketName(nameBuffer, {
1488
+ accounts: {
1489
+ admin: this.isSubscribed
1490
+ ? this.getStateAccount().admin
1491
+ : this.wallet.publicKey,
1492
+ state: await this.getStatePublicKey(),
1493
+ spotMarket: await getSpotMarketPublicKey(
1494
+ this.program.programId,
1495
+ spotMarketIndex
1496
+ ),
1497
+ },
1498
+ });
1499
+ }
1500
+
1501
+ public async updateSpotMarketPoolId(
1502
+ spotMarketIndex: number,
1503
+ poolId: number
1504
+ ): Promise<TransactionSignature> {
1505
+ const updateSpotMarketPoolIdIx = await this.getUpdateSpotMarketPoolIdIx(
1506
+ spotMarketIndex,
1507
+ poolId
1508
+ );
1509
+
1510
+ const tx = await this.buildTransaction(updateSpotMarketPoolIdIx);
1511
+
1512
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1513
+
1514
+ return txSig;
1515
+ }
1516
+
1517
+ public async getUpdateSpotMarketPoolIdIx(
1518
+ spotMarketIndex: number,
1519
+ poolId: number
1520
+ ): Promise<TransactionInstruction> {
1521
+ return await this.program.instruction.updateSpotMarketPoolId(poolId, {
1522
+ accounts: {
1523
+ admin: this.isSubscribed
1524
+ ? this.getStateAccount().admin
1525
+ : this.wallet.publicKey,
1526
+ state: await this.getStatePublicKey(),
1527
+ spotMarket: await getSpotMarketPublicKey(
1528
+ this.program.programId,
1529
+ spotMarketIndex
1530
+ ),
1531
+ },
1532
+ });
1533
+ }
1534
+
1535
+ public async updatePerpMarketPerLpBase(
1536
+ perpMarketIndex: number,
1537
+ perLpBase: number
1538
+ ): Promise<TransactionSignature> {
1539
+ const updatePerpMarketPerLpBaseIx =
1540
+ await this.getUpdatePerpMarketPerLpBaseIx(perpMarketIndex, perLpBase);
1541
+
1542
+ const tx = await this.buildTransaction(updatePerpMarketPerLpBaseIx);
1543
+
1544
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1545
+
1546
+ return txSig;
1547
+ }
1548
+
1549
+ public async getUpdatePerpMarketPerLpBaseIx(
1550
+ perpMarketIndex: number,
1551
+ perLpBase: number
1552
+ ): Promise<TransactionInstruction> {
1553
+ const perpMarketPublicKey = await getPerpMarketPublicKey(
1554
+ this.program.programId,
1555
+ perpMarketIndex
1556
+ );
1557
+
1558
+ return await this.program.instruction.updatePerpMarketPerLpBase(perLpBase, {
1559
+ accounts: {
1560
+ admin: this.isSubscribed
1561
+ ? this.getStateAccount().admin
1562
+ : this.wallet.publicKey,
1563
+ state: await this.getStatePublicKey(),
1564
+ perpMarket: perpMarketPublicKey,
1565
+ },
1566
+ });
1567
+ }
1568
+
1569
+ public async updatePerpMarketMaxSpread(
1570
+ perpMarketIndex: number,
1571
+ maxSpread: number
1572
+ ): Promise<TransactionSignature> {
1573
+ const updatePerpMarketMaxSpreadIx =
1574
+ await this.getUpdatePerpMarketMaxSpreadIx(perpMarketIndex, maxSpread);
1575
+
1576
+ const tx = await this.buildTransaction(updatePerpMarketMaxSpreadIx);
1577
+
1578
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1579
+
1580
+ return txSig;
1581
+ }
1582
+
1583
+ public async getUpdatePerpMarketMaxSpreadIx(
1584
+ perpMarketIndex: number,
1585
+ maxSpread: number
1586
+ ): Promise<TransactionInstruction> {
1587
+ const perpMarketPublicKey = await getPerpMarketPublicKey(
1588
+ this.program.programId,
1589
+ perpMarketIndex
1590
+ );
1591
+
1592
+ return await this.program.instruction.updatePerpMarketMaxSpread(maxSpread, {
1593
+ accounts: {
1594
+ admin: this.isSubscribed
1595
+ ? this.getStateAccount().admin
1596
+ : this.wallet.publicKey,
1597
+ state: await this.getStatePublicKey(),
1598
+ perpMarket: perpMarketPublicKey,
1599
+ },
1600
+ });
1601
+ }
1602
+
1603
+ public async updatePerpFeeStructure(
1604
+ feeStructure: FeeStructure
1605
+ ): Promise<TransactionSignature> {
1606
+ const updatePerpFeeStructureIx = await this.getUpdatePerpFeeStructureIx(
1607
+ feeStructure
1608
+ );
1609
+
1610
+ const tx = await this.buildTransaction(updatePerpFeeStructureIx);
1611
+
1612
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1613
+
1614
+ return txSig;
1615
+ }
1616
+
1617
+ public async getUpdatePerpFeeStructureIx(
1618
+ feeStructure: FeeStructure
1619
+ ): Promise<TransactionInstruction> {
1620
+ return this.program.instruction.updatePerpFeeStructure(feeStructure, {
1621
+ accounts: {
1622
+ admin: this.isSubscribed
1623
+ ? this.getStateAccount().admin
1624
+ : this.wallet.publicKey,
1625
+ state: await this.getStatePublicKey(),
1626
+ },
1627
+ });
1628
+ }
1629
+
1630
+ public async updateSpotFeeStructure(
1631
+ feeStructure: FeeStructure
1632
+ ): Promise<TransactionSignature> {
1633
+ const updateSpotFeeStructureIx = await this.getUpdateSpotFeeStructureIx(
1634
+ feeStructure
1635
+ );
1636
+
1637
+ const tx = await this.buildTransaction(updateSpotFeeStructureIx);
1638
+
1639
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1640
+
1641
+ return txSig;
1642
+ }
1643
+
1644
+ public async getUpdateSpotFeeStructureIx(
1645
+ feeStructure: FeeStructure
1646
+ ): Promise<TransactionInstruction> {
1647
+ return await this.program.instruction.updateSpotFeeStructure(feeStructure, {
1648
+ accounts: {
1649
+ admin: this.isSubscribed
1650
+ ? this.getStateAccount().admin
1651
+ : this.wallet.publicKey,
1652
+ state: await this.getStatePublicKey(),
1653
+ },
1654
+ });
1655
+ }
1656
+
1657
+ public async updateInitialPctToLiquidate(
1658
+ initialPctToLiquidate: number
1659
+ ): Promise<TransactionSignature> {
1660
+ const updateInitialPctToLiquidateIx =
1661
+ await this.getUpdateInitialPctToLiquidateIx(initialPctToLiquidate);
1662
+
1663
+ const tx = await this.buildTransaction(updateInitialPctToLiquidateIx);
1664
+
1665
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1666
+
1667
+ return txSig;
1668
+ }
1669
+
1670
+ public async getUpdateInitialPctToLiquidateIx(
1671
+ initialPctToLiquidate: number
1672
+ ): Promise<TransactionInstruction> {
1673
+ return await this.program.instruction.updateInitialPctToLiquidate(
1674
+ initialPctToLiquidate,
1675
+ {
1676
+ accounts: {
1677
+ admin: this.isSubscribed
1678
+ ? this.getStateAccount().admin
1679
+ : this.wallet.publicKey,
1680
+ state: await this.getStatePublicKey(),
1681
+ },
1682
+ }
1683
+ );
1684
+ }
1685
+
1686
+ public async updateLiquidationDuration(
1687
+ liquidationDuration: number
1688
+ ): Promise<TransactionSignature> {
1689
+ const updateLiquidationDurationIx =
1690
+ await this.getUpdateLiquidationDurationIx(liquidationDuration);
1691
+
1692
+ const tx = await this.buildTransaction(updateLiquidationDurationIx);
1693
+
1694
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1695
+
1696
+ return txSig;
1697
+ }
1698
+
1699
+ public async getUpdateLiquidationDurationIx(
1700
+ liquidationDuration: number
1701
+ ): Promise<TransactionInstruction> {
1702
+ return await this.program.instruction.updateLiquidationDuration(
1703
+ liquidationDuration,
1704
+ {
1705
+ accounts: {
1706
+ admin: this.isSubscribed
1707
+ ? this.getStateAccount().admin
1708
+ : this.wallet.publicKey,
1709
+ state: await this.getStatePublicKey(),
1710
+ },
1711
+ }
1712
+ );
1713
+ }
1714
+
1715
+ public async updateLiquidationMarginBufferRatio(
1716
+ updateLiquidationMarginBufferRatio: number
1717
+ ): Promise<TransactionSignature> {
1718
+ const updateLiquidationMarginBufferRatioIx =
1719
+ await this.getUpdateLiquidationMarginBufferRatioIx(
1720
+ updateLiquidationMarginBufferRatio
1721
+ );
1722
+
1723
+ const tx = await this.buildTransaction(
1724
+ updateLiquidationMarginBufferRatioIx
1725
+ );
1726
+
1727
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1728
+
1729
+ return txSig;
1730
+ }
1731
+
1732
+ public async getUpdateLiquidationMarginBufferRatioIx(
1733
+ updateLiquidationMarginBufferRatio: number
1734
+ ): Promise<TransactionInstruction> {
1735
+ return await this.program.instruction.updateLiquidationMarginBufferRatio(
1736
+ updateLiquidationMarginBufferRatio,
1737
+ {
1738
+ accounts: {
1739
+ admin: this.isSubscribed
1740
+ ? this.getStateAccount().admin
1741
+ : this.wallet.publicKey,
1742
+ state: await this.getStatePublicKey(),
1743
+ },
1744
+ }
1745
+ );
1746
+ }
1747
+
1748
+ public async updateOracleGuardRails(
1749
+ oracleGuardRails: OracleGuardRails
1750
+ ): Promise<TransactionSignature> {
1751
+ const updateOracleGuardRailsIx = await this.getUpdateOracleGuardRailsIx(
1752
+ oracleGuardRails
1753
+ );
1754
+
1755
+ const tx = await this.buildTransaction(updateOracleGuardRailsIx);
1756
+
1757
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1758
+
1759
+ return txSig;
1760
+ }
1761
+
1762
+ public async getUpdateOracleGuardRailsIx(
1763
+ oracleGuardRails: OracleGuardRails
1764
+ ): Promise<TransactionInstruction> {
1765
+ return await this.program.instruction.updateOracleGuardRails(
1766
+ oracleGuardRails,
1767
+ {
1768
+ accounts: {
1769
+ admin: this.isSubscribed
1770
+ ? this.getStateAccount().admin
1771
+ : this.wallet.publicKey,
1772
+ state: await this.getStatePublicKey(),
1773
+ },
1774
+ }
1775
+ );
1776
+ }
1777
+
1778
+ public async updateStateSettlementDuration(
1779
+ settlementDuration: number
1780
+ ): Promise<TransactionSignature> {
1781
+ const updateStateSettlementDurationIx =
1782
+ await this.getUpdateStateSettlementDurationIx(settlementDuration);
1783
+
1784
+ const tx = await this.buildTransaction(updateStateSettlementDurationIx);
1785
+
1786
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1787
+
1788
+ return txSig;
1789
+ }
1790
+
1791
+ public async getUpdateStateSettlementDurationIx(
1792
+ settlementDuration: number
1793
+ ): Promise<TransactionInstruction> {
1794
+ return await this.program.instruction.updateStateSettlementDuration(
1795
+ settlementDuration,
1796
+ {
1797
+ accounts: {
1798
+ admin: this.isSubscribed
1799
+ ? this.getStateAccount().admin
1800
+ : this.wallet.publicKey,
1801
+ state: await this.getStatePublicKey(),
1802
+ },
1803
+ }
1804
+ );
1805
+ }
1806
+
1807
+ public async updateStateMaxNumberOfSubAccounts(
1808
+ maxNumberOfSubAccounts: number
1809
+ ): Promise<TransactionSignature> {
1810
+ const updateStateMaxNumberOfSubAccountsIx =
1811
+ await this.getUpdateStateMaxNumberOfSubAccountsIx(maxNumberOfSubAccounts);
1812
+
1813
+ const tx = await this.buildTransaction(updateStateMaxNumberOfSubAccountsIx);
1814
+
1815
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1816
+
1817
+ return txSig;
1818
+ }
1819
+
1820
+ public async getUpdateStateMaxNumberOfSubAccountsIx(
1821
+ maxNumberOfSubAccounts: number
1822
+ ): Promise<TransactionInstruction> {
1823
+ return await this.program.instruction.updateStateMaxNumberOfSubAccounts(
1824
+ maxNumberOfSubAccounts,
1825
+ {
1826
+ accounts: {
1827
+ admin: this.isSubscribed
1828
+ ? this.getStateAccount().admin
1829
+ : this.wallet.publicKey,
1830
+ state: await this.getStatePublicKey(),
1831
+ },
1832
+ }
1833
+ );
1834
+ }
1835
+
1836
+ public async updateStateMaxInitializeUserFee(
1837
+ maxInitializeUserFee: number
1838
+ ): Promise<TransactionSignature> {
1839
+ const updateStateMaxInitializeUserFeeIx =
1840
+ await this.getUpdateStateMaxInitializeUserFeeIx(maxInitializeUserFee);
1841
+
1842
+ const tx = await this.buildTransaction(updateStateMaxInitializeUserFeeIx);
1843
+
1844
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1845
+
1846
+ return txSig;
1847
+ }
1848
+
1849
+ public async getUpdateStateMaxInitializeUserFeeIx(
1850
+ maxInitializeUserFee: number
1851
+ ): Promise<TransactionInstruction> {
1852
+ return await this.program.instruction.updateStateMaxInitializeUserFee(
1853
+ maxInitializeUserFee,
1854
+ {
1855
+ accounts: {
1856
+ admin: this.isSubscribed
1857
+ ? this.getStateAccount().admin
1858
+ : this.wallet.publicKey,
1859
+ state: await this.getStatePublicKey(),
1860
+ },
1861
+ }
1862
+ );
1863
+ }
1864
+
1865
+ public async updateWithdrawGuardThreshold(
1866
+ spotMarketIndex: number,
1867
+ withdrawGuardThreshold: BN
1868
+ ): Promise<TransactionSignature> {
1869
+ const updateWithdrawGuardThresholdIx =
1870
+ await this.getUpdateWithdrawGuardThresholdIx(
1871
+ spotMarketIndex,
1872
+ withdrawGuardThreshold
1873
+ );
1874
+
1875
+ const tx = await this.buildTransaction(updateWithdrawGuardThresholdIx);
1876
+
1877
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1878
+
1879
+ return txSig;
1880
+ }
1881
+
1882
+ public async getUpdateWithdrawGuardThresholdIx(
1883
+ spotMarketIndex: number,
1884
+ withdrawGuardThreshold: BN
1885
+ ): Promise<TransactionInstruction> {
1886
+ return await this.program.instruction.updateWithdrawGuardThreshold(
1887
+ withdrawGuardThreshold,
1888
+ {
1889
+ accounts: {
1890
+ admin: this.isSubscribed
1891
+ ? this.getStateAccount().admin
1892
+ : this.wallet.publicKey,
1893
+ state: await this.getStatePublicKey(),
1894
+ spotMarket: await getSpotMarketPublicKey(
1895
+ this.program.programId,
1896
+ spotMarketIndex
1897
+ ),
1898
+ },
1899
+ }
1900
+ );
1901
+ }
1902
+
1903
+ public async updateSpotMarketIfFactor(
1904
+ spotMarketIndex: number,
1905
+ userIfFactor: BN,
1906
+ totalIfFactor: BN
1907
+ ): Promise<TransactionSignature> {
1908
+ const updateSpotMarketIfFactorIx = await this.getUpdateSpotMarketIfFactorIx(
1909
+ spotMarketIndex,
1910
+ userIfFactor,
1911
+ totalIfFactor
1912
+ );
1913
+
1914
+ const tx = await this.buildTransaction(updateSpotMarketIfFactorIx);
1915
+
1916
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1917
+
1918
+ return txSig;
1919
+ }
1920
+
1921
+ public async getUpdateSpotMarketIfFactorIx(
1922
+ spotMarketIndex: number,
1923
+ userIfFactor: BN,
1924
+ totalIfFactor: BN
1925
+ ): Promise<TransactionInstruction> {
1926
+ return await this.program.instruction.updateSpotMarketIfFactor(
1927
+ spotMarketIndex,
1928
+ userIfFactor,
1929
+ totalIfFactor,
1930
+ {
1931
+ accounts: {
1932
+ admin: this.isSubscribed
1933
+ ? this.getStateAccount().admin
1934
+ : this.wallet.publicKey,
1935
+ state: await this.getStatePublicKey(),
1936
+ spotMarket: await getSpotMarketPublicKey(
1937
+ this.program.programId,
1938
+ spotMarketIndex
1939
+ ),
1940
+ },
1941
+ }
1942
+ );
1943
+ }
1944
+
1945
+ public async updateSpotMarketRevenueSettlePeriod(
1946
+ spotMarketIndex: number,
1947
+ revenueSettlePeriod: BN
1948
+ ): Promise<TransactionSignature> {
1949
+ const updateSpotMarketRevenueSettlePeriodIx =
1950
+ await this.getUpdateSpotMarketRevenueSettlePeriodIx(
1951
+ spotMarketIndex,
1952
+ revenueSettlePeriod
1953
+ );
1954
+
1955
+ const tx = await this.buildTransaction(
1956
+ updateSpotMarketRevenueSettlePeriodIx
1957
+ );
1958
+
1959
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1960
+
1961
+ return txSig;
1962
+ }
1963
+
1964
+ public async getUpdateSpotMarketRevenueSettlePeriodIx(
1965
+ spotMarketIndex: number,
1966
+ revenueSettlePeriod: BN
1967
+ ): Promise<TransactionInstruction> {
1968
+ return await this.program.instruction.updateSpotMarketRevenueSettlePeriod(
1969
+ revenueSettlePeriod,
1970
+ {
1971
+ accounts: {
1972
+ admin: this.isSubscribed
1973
+ ? this.getStateAccount().admin
1974
+ : this.wallet.publicKey,
1975
+ state: await this.getStatePublicKey(),
1976
+ spotMarket: await getSpotMarketPublicKey(
1977
+ this.program.programId,
1978
+ spotMarketIndex
1979
+ ),
1980
+ },
1981
+ }
1982
+ );
1983
+ }
1984
+
1985
+ public async updateSpotMarketMaxTokenDeposits(
1986
+ spotMarketIndex: number,
1987
+ maxTokenDeposits: BN
1988
+ ): Promise<TransactionSignature> {
1989
+ const updateSpotMarketMaxTokenDepositsIx =
1990
+ await this.getUpdateSpotMarketMaxTokenDepositsIx(
1991
+ spotMarketIndex,
1992
+ maxTokenDeposits
1993
+ );
1994
+
1995
+ const tx = await this.buildTransaction(updateSpotMarketMaxTokenDepositsIx);
1996
+
1997
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1998
+
1999
+ return txSig;
2000
+ }
2001
+
2002
+ public async getUpdateSpotMarketMaxTokenDepositsIx(
2003
+ spotMarketIndex: number,
2004
+ maxTokenDeposits: BN
2005
+ ): Promise<TransactionInstruction> {
2006
+ return this.program.instruction.updateSpotMarketMaxTokenDeposits(
2007
+ maxTokenDeposits,
2008
+ {
2009
+ accounts: {
2010
+ admin: this.isSubscribed
2011
+ ? this.getStateAccount().admin
2012
+ : this.wallet.publicKey,
2013
+ state: await this.getStatePublicKey(),
2014
+ spotMarket: await getSpotMarketPublicKey(
2015
+ this.program.programId,
2016
+ spotMarketIndex
2017
+ ),
2018
+ },
2019
+ }
2020
+ );
2021
+ }
2022
+
2023
+ public async updateSpotMarketMaxTokenBorrows(
2024
+ spotMarketIndex: number,
2025
+ maxTokenBorrowsFraction: number
2026
+ ): Promise<TransactionSignature> {
2027
+ const updateSpotMarketMaxTokenBorrowsIx =
2028
+ await this.getUpdateSpotMarketMaxTokenBorrowsIx(
2029
+ spotMarketIndex,
2030
+ maxTokenBorrowsFraction
2031
+ );
2032
+
2033
+ const tx = await this.buildTransaction(updateSpotMarketMaxTokenBorrowsIx);
2034
+
2035
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2036
+
2037
+ return txSig;
2038
+ }
2039
+
2040
+ public async getUpdateSpotMarketMaxTokenBorrowsIx(
2041
+ spotMarketIndex: number,
2042
+ maxTokenBorrowsFraction: number
2043
+ ): Promise<TransactionInstruction> {
2044
+ return this.program.instruction.updateSpotMarketMaxTokenBorrows(
2045
+ maxTokenBorrowsFraction,
2046
+ {
2047
+ accounts: {
2048
+ admin: this.isSubscribed
2049
+ ? this.getStateAccount().admin
2050
+ : this.wallet.publicKey,
2051
+ state: await this.getStatePublicKey(),
2052
+ spotMarket: await getSpotMarketPublicKey(
2053
+ this.program.programId,
2054
+ spotMarketIndex
2055
+ ),
2056
+ },
2057
+ }
2058
+ );
2059
+ }
2060
+
2061
+ public async updateSpotMarketScaleInitialAssetWeightStart(
2062
+ spotMarketIndex: number,
2063
+ scaleInitialAssetWeightStart: BN
2064
+ ): Promise<TransactionSignature> {
2065
+ const updateSpotMarketScaleInitialAssetWeightStartIx =
2066
+ await this.getUpdateSpotMarketScaleInitialAssetWeightStartIx(
2067
+ spotMarketIndex,
2068
+ scaleInitialAssetWeightStart
2069
+ );
2070
+
2071
+ const tx = await this.buildTransaction(
2072
+ updateSpotMarketScaleInitialAssetWeightStartIx
2073
+ );
2074
+
2075
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2076
+
2077
+ return txSig;
2078
+ }
2079
+
2080
+ public async getUpdateSpotMarketScaleInitialAssetWeightStartIx(
2081
+ spotMarketIndex: number,
2082
+ scaleInitialAssetWeightStart: BN
2083
+ ): Promise<TransactionInstruction> {
2084
+ return this.program.instruction.updateSpotMarketScaleInitialAssetWeightStart(
2085
+ scaleInitialAssetWeightStart,
2086
+ {
2087
+ accounts: {
2088
+ admin: this.isSubscribed
2089
+ ? this.getStateAccount().admin
2090
+ : this.wallet.publicKey,
2091
+ state: await this.getStatePublicKey(),
2092
+ spotMarket: await getSpotMarketPublicKey(
2093
+ this.program.programId,
2094
+ spotMarketIndex
2095
+ ),
2096
+ },
2097
+ }
2098
+ );
2099
+ }
2100
+
2101
+ public async updateInsuranceFundUnstakingPeriod(
2102
+ spotMarketIndex: number,
2103
+ insuranceWithdrawEscrowPeriod: BN
2104
+ ): Promise<TransactionSignature> {
2105
+ const updateInsuranceFundUnstakingPeriodIx =
2106
+ await this.getUpdateInsuranceFundUnstakingPeriodIx(
2107
+ spotMarketIndex,
2108
+ insuranceWithdrawEscrowPeriod
2109
+ );
2110
+
2111
+ const tx = await this.buildTransaction(
2112
+ updateInsuranceFundUnstakingPeriodIx
2113
+ );
2114
+
2115
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2116
+
2117
+ return txSig;
2118
+ }
2119
+
2120
+ public async getUpdateInsuranceFundUnstakingPeriodIx(
2121
+ spotMarketIndex: number,
2122
+ insuranceWithdrawEscrowPeriod: BN
2123
+ ): Promise<TransactionInstruction> {
2124
+ return await this.program.instruction.updateInsuranceFundUnstakingPeriod(
2125
+ insuranceWithdrawEscrowPeriod,
2126
+ {
2127
+ accounts: {
2128
+ admin: this.isSubscribed
2129
+ ? this.getStateAccount().admin
2130
+ : this.wallet.publicKey,
2131
+ state: await this.getStatePublicKey(),
2132
+ spotMarket: await getSpotMarketPublicKey(
2133
+ this.program.programId,
2134
+ spotMarketIndex
2135
+ ),
2136
+ },
2137
+ }
2138
+ );
2139
+ }
2140
+
2141
+ public async updateLpCooldownTime(
2142
+ cooldownTime: BN
2143
+ ): Promise<TransactionSignature> {
2144
+ const updateLpCooldownTimeIx = await this.getUpdateLpCooldownTimeIx(
2145
+ cooldownTime
2146
+ );
2147
+
2148
+ const tx = await this.buildTransaction(updateLpCooldownTimeIx);
2149
+
2150
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2151
+
2152
+ return txSig;
2153
+ }
2154
+
2155
+ public async getUpdateLpCooldownTimeIx(
2156
+ cooldownTime: BN
2157
+ ): Promise<TransactionInstruction> {
2158
+ return await this.program.instruction.updateLpCooldownTime(cooldownTime, {
2159
+ accounts: {
2160
+ admin: this.isSubscribed
2161
+ ? this.getStateAccount().admin
2162
+ : this.wallet.publicKey,
2163
+ state: await this.getStatePublicKey(),
2164
+ },
2165
+ });
2166
+ }
2167
+
2168
+ public async updatePerpMarketOracle(
2169
+ perpMarketIndex: number,
2170
+ oracle: PublicKey,
2171
+ oracleSource: OracleSource
2172
+ ): Promise<TransactionSignature> {
2173
+ const updatePerpMarketOracleIx = await this.getUpdatePerpMarketOracleIx(
2174
+ perpMarketIndex,
2175
+ oracle,
2176
+ oracleSource
2177
+ );
2178
+
2179
+ const tx = await this.buildTransaction(updatePerpMarketOracleIx);
2180
+
2181
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2182
+
2183
+ return txSig;
2184
+ }
2185
+
2186
+ public async getUpdatePerpMarketOracleIx(
2187
+ perpMarketIndex: number,
2188
+ oracle: PublicKey,
2189
+ oracleSource: OracleSource
2190
+ ): Promise<TransactionInstruction> {
2191
+ return await this.program.instruction.updatePerpMarketOracle(
2192
+ oracle,
2193
+ oracleSource,
2194
+ {
2195
+ accounts: {
2196
+ admin: this.isSubscribed
2197
+ ? this.getStateAccount().admin
2198
+ : this.wallet.publicKey,
2199
+ state: await this.getStatePublicKey(),
2200
+ perpMarket: await getPerpMarketPublicKey(
2201
+ this.program.programId,
2202
+ perpMarketIndex
2203
+ ),
2204
+ oracle: oracle,
2205
+ },
2206
+ }
2207
+ );
2208
+ }
2209
+
2210
+ public async updatePerpMarketStepSizeAndTickSize(
2211
+ perpMarketIndex: number,
2212
+ stepSize: BN,
2213
+ tickSize: BN
2214
+ ): Promise<TransactionSignature> {
2215
+ const updatePerpMarketStepSizeAndTickSizeIx =
2216
+ await this.getUpdatePerpMarketStepSizeAndTickSizeIx(
2217
+ perpMarketIndex,
2218
+ stepSize,
2219
+ tickSize
2220
+ );
2221
+
2222
+ const tx = await this.buildTransaction(
2223
+ updatePerpMarketStepSizeAndTickSizeIx
2224
+ );
2225
+
2226
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2227
+
2228
+ return txSig;
2229
+ }
2230
+
2231
+ public async getUpdatePerpMarketStepSizeAndTickSizeIx(
2232
+ perpMarketIndex: number,
2233
+ stepSize: BN,
2234
+ tickSize: BN
2235
+ ): Promise<TransactionInstruction> {
2236
+ return await this.program.instruction.updatePerpMarketStepSizeAndTickSize(
2237
+ stepSize,
2238
+ tickSize,
2239
+ {
2240
+ accounts: {
2241
+ admin: this.isSubscribed
2242
+ ? this.getStateAccount().admin
2243
+ : this.wallet.publicKey,
2244
+ state: await this.getStatePublicKey(),
2245
+ perpMarket: await getPerpMarketPublicKey(
2246
+ this.program.programId,
2247
+ perpMarketIndex
2248
+ ),
2249
+ },
2250
+ }
2251
+ );
2252
+ }
2253
+
2254
+ public async updatePerpMarketMinOrderSize(
2255
+ perpMarketIndex: number,
2256
+ orderSize: BN
2257
+ ): Promise<TransactionSignature> {
2258
+ const updatePerpMarketMinOrderSizeIx =
2259
+ await this.getUpdatePerpMarketMinOrderSizeIx(perpMarketIndex, orderSize);
2260
+
2261
+ const tx = await this.buildTransaction(updatePerpMarketMinOrderSizeIx);
2262
+
2263
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2264
+
2265
+ return txSig;
2266
+ }
2267
+
2268
+ public async getUpdatePerpMarketMinOrderSizeIx(
2269
+ perpMarketIndex: number,
2270
+ orderSize: BN
2271
+ ): Promise<TransactionInstruction> {
2272
+ return await this.program.instruction.updatePerpMarketMinOrderSize(
2273
+ orderSize,
2274
+ {
2275
+ accounts: {
2276
+ admin: this.isSubscribed
2277
+ ? this.getStateAccount().admin
2278
+ : this.wallet.publicKey,
2279
+ state: await this.getStatePublicKey(),
2280
+ perpMarket: await getPerpMarketPublicKey(
2281
+ this.program.programId,
2282
+ perpMarketIndex
2283
+ ),
2284
+ },
2285
+ }
2286
+ );
2287
+ }
2288
+
2289
+ public async updateSpotMarketStepSizeAndTickSize(
2290
+ spotMarketIndex: number,
2291
+ stepSize: BN,
2292
+ tickSize: BN
2293
+ ): Promise<TransactionSignature> {
2294
+ const updateSpotMarketStepSizeAndTickSizeIx =
2295
+ await this.getUpdateSpotMarketStepSizeAndTickSizeIx(
2296
+ spotMarketIndex,
2297
+ stepSize,
2298
+ tickSize
2299
+ );
2300
+
2301
+ const tx = await this.buildTransaction(
2302
+ updateSpotMarketStepSizeAndTickSizeIx
2303
+ );
2304
+
2305
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2306
+
2307
+ return txSig;
2308
+ }
2309
+
2310
+ public async getUpdateSpotMarketStepSizeAndTickSizeIx(
2311
+ spotMarketIndex: number,
2312
+ stepSize: BN,
2313
+ tickSize: BN
2314
+ ): Promise<TransactionInstruction> {
2315
+ return await this.program.instruction.updateSpotMarketStepSizeAndTickSize(
2316
+ stepSize,
2317
+ tickSize,
2318
+ {
2319
+ accounts: {
2320
+ admin: this.isSubscribed
2321
+ ? this.getStateAccount().admin
2322
+ : this.wallet.publicKey,
2323
+ state: await this.getStatePublicKey(),
2324
+ spotMarket: await getSpotMarketPublicKey(
2325
+ this.program.programId,
2326
+ spotMarketIndex
2327
+ ),
2328
+ },
2329
+ }
2330
+ );
2331
+ }
2332
+
2333
+ public async updateSpotMarketMinOrderSize(
2334
+ spotMarketIndex: number,
2335
+ orderSize: BN
2336
+ ): Promise<TransactionSignature> {
2337
+ const updateSpotMarketMinOrderSizeIx =
2338
+ await this.program.instruction.updateSpotMarketMinOrderSize(orderSize, {
2339
+ accounts: {
2340
+ admin: this.isSubscribed
2341
+ ? this.getStateAccount().admin
2342
+ : this.wallet.publicKey,
2343
+ state: await this.getStatePublicKey(),
2344
+ spotMarket: await getSpotMarketPublicKey(
2345
+ this.program.programId,
2346
+ spotMarketIndex
2347
+ ),
2348
+ },
2349
+ });
2350
+
2351
+ const tx = await this.buildTransaction(updateSpotMarketMinOrderSizeIx);
2352
+
2353
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2354
+
2355
+ return txSig;
2356
+ }
2357
+
2358
+ public async getUpdateSpotMarketMinOrderSizeIx(
2359
+ spotMarketIndex: number,
2360
+ orderSize: BN
2361
+ ): Promise<TransactionInstruction> {
2362
+ return await this.program.instruction.updateSpotMarketMinOrderSize(
2363
+ orderSize,
2364
+ {
2365
+ accounts: {
2366
+ admin: this.isSubscribed
2367
+ ? this.getStateAccount().admin
2368
+ : this.wallet.publicKey,
2369
+ state: await this.getStatePublicKey(),
2370
+ spotMarket: await getSpotMarketPublicKey(
2371
+ this.program.programId,
2372
+ spotMarketIndex
2373
+ ),
2374
+ },
2375
+ }
2376
+ );
2377
+ }
2378
+
2379
+ public async updatePerpMarketExpiry(
2380
+ perpMarketIndex: number,
2381
+ expiryTs: BN
2382
+ ): Promise<TransactionSignature> {
2383
+ const updatePerpMarketExpiryIx = await this.getUpdatePerpMarketExpiryIx(
2384
+ perpMarketIndex,
2385
+ expiryTs
2386
+ );
2387
+ const tx = await this.buildTransaction(updatePerpMarketExpiryIx);
2388
+
2389
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2390
+
2391
+ return txSig;
2392
+ }
2393
+
2394
+ public async getUpdatePerpMarketExpiryIx(
2395
+ perpMarketIndex: number,
2396
+ expiryTs: BN
2397
+ ): Promise<TransactionInstruction> {
2398
+ return await this.program.instruction.updatePerpMarketExpiry(expiryTs, {
2399
+ accounts: {
2400
+ admin: this.isSubscribed
2401
+ ? this.getStateAccount().admin
2402
+ : this.wallet.publicKey,
2403
+ state: await this.getStatePublicKey(),
2404
+ perpMarket: await getPerpMarketPublicKey(
2405
+ this.program.programId,
2406
+ perpMarketIndex
2407
+ ),
2408
+ },
2409
+ });
2410
+ }
2411
+
2412
+ public async updateSpotMarketOracle(
2413
+ spotMarketIndex: number,
2414
+ oracle: PublicKey,
2415
+ oracleSource: OracleSource
2416
+ ): Promise<TransactionSignature> {
2417
+ const updateSpotMarketOracleIx = await this.getUpdateSpotMarketOracleIx(
2418
+ spotMarketIndex,
2419
+ oracle,
2420
+ oracleSource
2421
+ );
2422
+
2423
+ const tx = await this.buildTransaction(updateSpotMarketOracleIx);
2424
+
2425
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2426
+
2427
+ return txSig;
2428
+ }
2429
+
2430
+ public async getUpdateSpotMarketOracleIx(
2431
+ spotMarketIndex: number,
2432
+ oracle: PublicKey,
2433
+ oracleSource: OracleSource
2434
+ ): Promise<TransactionInstruction> {
2435
+ return await this.program.instruction.updateSpotMarketOracle(
2436
+ oracle,
2437
+ oracleSource,
2438
+ {
2439
+ accounts: {
2440
+ admin: this.isSubscribed
2441
+ ? this.getStateAccount().admin
2442
+ : this.wallet.publicKey,
2443
+ state: await this.getStatePublicKey(),
2444
+ spotMarket: await getSpotMarketPublicKey(
2445
+ this.program.programId,
2446
+ spotMarketIndex
2447
+ ),
2448
+ oracle: oracle,
2449
+ },
2450
+ }
2451
+ );
2452
+ }
2453
+
2454
+ public async updateSpotMarketOrdersEnabled(
2455
+ spotMarketIndex: number,
2456
+ ordersEnabled: boolean
2457
+ ): Promise<TransactionSignature> {
2458
+ const updateSpotMarketOrdersEnabledIx =
2459
+ await this.getUpdateSpotMarketOrdersEnabledIx(
2460
+ spotMarketIndex,
2461
+ ordersEnabled
2462
+ );
2463
+
2464
+ const tx = await this.buildTransaction(updateSpotMarketOrdersEnabledIx);
2465
+
2466
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2467
+
2468
+ return txSig;
2469
+ }
2470
+
2471
+ public async getUpdateSpotMarketOrdersEnabledIx(
2472
+ spotMarketIndex: number,
2473
+ ordersEnabled: boolean
2474
+ ): Promise<TransactionInstruction> {
2475
+ return await this.program.instruction.updateSpotMarketOrdersEnabled(
2476
+ ordersEnabled,
2477
+ {
2478
+ accounts: {
2479
+ admin: this.isSubscribed
2480
+ ? this.getStateAccount().admin
2481
+ : this.wallet.publicKey,
2482
+ state: await this.getStatePublicKey(),
2483
+ spotMarket: await getSpotMarketPublicKey(
2484
+ this.program.programId,
2485
+ spotMarketIndex
2486
+ ),
2487
+ },
2488
+ }
2489
+ );
2490
+ }
2491
+
2492
+ public async updateSpotMarketIfPausedOperations(
2493
+ spotMarketIndex: number,
2494
+ pausedOperations: number
2495
+ ): Promise<TransactionSignature> {
2496
+ const updateSpotMarketIfStakingDisabledIx =
2497
+ await this.getUpdateSpotMarketIfPausedOperationsIx(
2498
+ spotMarketIndex,
2499
+ pausedOperations
2500
+ );
2501
+
2502
+ const tx = await this.buildTransaction(updateSpotMarketIfStakingDisabledIx);
2503
+
2504
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2505
+
2506
+ return txSig;
2507
+ }
2508
+
2509
+ public async getUpdateSpotMarketIfPausedOperationsIx(
2510
+ spotMarketIndex: number,
2511
+ pausedOperations: number
2512
+ ): Promise<TransactionInstruction> {
2513
+ return await this.program.instruction.updateSpotMarketIfPausedOperations(
2514
+ pausedOperations,
2515
+ {
2516
+ accounts: {
2517
+ admin: this.isSubscribed
2518
+ ? this.getStateAccount().admin
2519
+ : this.wallet.publicKey,
2520
+ state: await this.getStatePublicKey(),
2521
+ spotMarket: await getSpotMarketPublicKey(
2522
+ this.program.programId,
2523
+ spotMarketIndex
2524
+ ),
2525
+ },
2526
+ }
2527
+ );
2528
+ }
2529
+
2530
+ public async updateSerumFulfillmentConfigStatus(
2531
+ serumFulfillmentConfig: PublicKey,
2532
+ status: SpotFulfillmentConfigStatus
2533
+ ): Promise<TransactionSignature> {
2534
+ const updateSerumFulfillmentConfigStatusIx =
2535
+ await this.getUpdateSerumFulfillmentConfigStatusIx(
2536
+ serumFulfillmentConfig,
2537
+ status
2538
+ );
2539
+
2540
+ const tx = await this.buildTransaction(
2541
+ updateSerumFulfillmentConfigStatusIx
2542
+ );
2543
+
2544
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2545
+
2546
+ return txSig;
2547
+ }
2548
+
2549
+ public async getUpdateSerumFulfillmentConfigStatusIx(
2550
+ serumFulfillmentConfig: PublicKey,
2551
+ status: SpotFulfillmentConfigStatus
2552
+ ): Promise<TransactionInstruction> {
2553
+ return await this.program.instruction.updateSerumFulfillmentConfigStatus(
2554
+ status,
2555
+ {
2556
+ accounts: {
2557
+ admin: this.isSubscribed
2558
+ ? this.getStateAccount().admin
2559
+ : this.wallet.publicKey,
2560
+ state: await this.getStatePublicKey(),
2561
+ serumFulfillmentConfig,
2562
+ },
2563
+ }
2564
+ );
2565
+ }
2566
+
2567
+ public async updatePhoenixFulfillmentConfigStatus(
2568
+ phoenixFulfillmentConfig: PublicKey,
2569
+ status: SpotFulfillmentConfigStatus
2570
+ ): Promise<TransactionSignature> {
2571
+ const updatePhoenixFulfillmentConfigStatusIx =
2572
+ await this.program.instruction.phoenixFulfillmentConfigStatus(status, {
2573
+ accounts: {
2574
+ admin: this.isSubscribed
2575
+ ? this.getStateAccount().admin
2576
+ : this.wallet.publicKey,
2577
+ state: await this.getStatePublicKey(),
2578
+ phoenixFulfillmentConfig,
2579
+ },
2580
+ });
2581
+
2582
+ const tx = await this.buildTransaction(
2583
+ updatePhoenixFulfillmentConfigStatusIx
2584
+ );
2585
+
2586
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2587
+
2588
+ return txSig;
2589
+ }
2590
+
2591
+ public async getUpdatePhoenixFulfillmentConfigStatusIx(
2592
+ phoenixFulfillmentConfig: PublicKey,
2593
+ status: SpotFulfillmentConfigStatus
2594
+ ): Promise<TransactionInstruction> {
2595
+ return await this.program.instruction.phoenixFulfillmentConfigStatus(
2596
+ status,
2597
+ {
2598
+ accounts: {
2599
+ admin: this.isSubscribed
2600
+ ? this.getStateAccount().admin
2601
+ : this.wallet.publicKey,
2602
+ state: await this.getStatePublicKey(),
2603
+ phoenixFulfillmentConfig,
2604
+ },
2605
+ }
2606
+ );
2607
+ }
2608
+
2609
+ public async updateSpotMarketExpiry(
2610
+ spotMarketIndex: number,
2611
+ expiryTs: BN
2612
+ ): Promise<TransactionSignature> {
2613
+ const updateSpotMarketExpiryIx = await this.getUpdateSpotMarketExpiryIx(
2614
+ spotMarketIndex,
2615
+ expiryTs
2616
+ );
2617
+
2618
+ const tx = await this.buildTransaction(updateSpotMarketExpiryIx);
2619
+
2620
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2621
+
2622
+ return txSig;
2623
+ }
2624
+
2625
+ public async getUpdateSpotMarketExpiryIx(
2626
+ spotMarketIndex: number,
2627
+ expiryTs: BN
2628
+ ): Promise<TransactionInstruction> {
2629
+ return await this.program.instruction.updateSpotMarketExpiry(expiryTs, {
2630
+ accounts: {
2631
+ admin: this.isSubscribed
2632
+ ? this.getStateAccount().admin
2633
+ : this.wallet.publicKey,
2634
+ state: await this.getStatePublicKey(),
2635
+ spotMarket: await getSpotMarketPublicKey(
2636
+ this.program.programId,
2637
+ spotMarketIndex
2638
+ ),
2639
+ },
2640
+ });
2641
+ }
2642
+
2643
+ public async updateWhitelistMint(
2644
+ whitelistMint?: PublicKey
2645
+ ): Promise<TransactionSignature> {
2646
+ const updateWhitelistMintIx = await this.getUpdateWhitelistMintIx(
2647
+ whitelistMint
2648
+ );
2649
+
2650
+ const tx = await this.buildTransaction(updateWhitelistMintIx);
2651
+
2652
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2653
+
2654
+ return txSig;
2655
+ }
2656
+
2657
+ public async getUpdateWhitelistMintIx(
2658
+ whitelistMint?: PublicKey
2659
+ ): Promise<TransactionInstruction> {
2660
+ return await this.program.instruction.updateWhitelistMint(whitelistMint, {
2661
+ accounts: {
2662
+ admin: this.isSubscribed
2663
+ ? this.getStateAccount().admin
2664
+ : this.wallet.publicKey,
2665
+ state: await this.getStatePublicKey(),
2666
+ },
2667
+ });
2668
+ }
2669
+
2670
+ public async updateDiscountMint(
2671
+ discountMint: PublicKey
2672
+ ): Promise<TransactionSignature> {
2673
+ const updateDiscountMintIx = await this.getUpdateDiscountMintIx(
2674
+ discountMint
2675
+ );
2676
+
2677
+ const tx = await this.buildTransaction(updateDiscountMintIx);
2678
+
2679
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2680
+
2681
+ return txSig;
2682
+ }
2683
+
2684
+ public async getUpdateDiscountMintIx(
2685
+ discountMint: PublicKey
2686
+ ): Promise<TransactionInstruction> {
2687
+ return await this.program.instruction.updateDiscountMint(discountMint, {
2688
+ accounts: {
2689
+ admin: this.isSubscribed
2690
+ ? this.getStateAccount().admin
2691
+ : this.wallet.publicKey,
2692
+ state: await this.getStatePublicKey(),
2693
+ },
2694
+ });
2695
+ }
2696
+
2697
+ public async updateSpotMarketMarginWeights(
2698
+ spotMarketIndex: number,
2699
+ initialAssetWeight: number,
2700
+ maintenanceAssetWeight: number,
2701
+ initialLiabilityWeight: number,
2702
+ maintenanceLiabilityWeight: number,
2703
+ imfFactor = 0
2704
+ ): Promise<TransactionSignature> {
2705
+ const updateSpotMarketMarginWeightsIx =
2706
+ await this.getUpdateSpotMarketMarginWeightsIx(
2707
+ spotMarketIndex,
2708
+ initialAssetWeight,
2709
+ maintenanceAssetWeight,
2710
+ initialLiabilityWeight,
2711
+ maintenanceLiabilityWeight,
2712
+ imfFactor
2713
+ );
2714
+
2715
+ const tx = await this.buildTransaction(updateSpotMarketMarginWeightsIx);
2716
+
2717
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2718
+
2719
+ return txSig;
2720
+ }
2721
+
2722
+ public async getUpdateSpotMarketMarginWeightsIx(
2723
+ spotMarketIndex: number,
2724
+ initialAssetWeight: number,
2725
+ maintenanceAssetWeight: number,
2726
+ initialLiabilityWeight: number,
2727
+ maintenanceLiabilityWeight: number,
2728
+ imfFactor = 0
2729
+ ): Promise<TransactionInstruction> {
2730
+ return await this.program.instruction.updateSpotMarketMarginWeights(
2731
+ initialAssetWeight,
2732
+ maintenanceAssetWeight,
2733
+ initialLiabilityWeight,
2734
+ maintenanceLiabilityWeight,
2735
+ imfFactor,
2736
+ {
2737
+ accounts: {
2738
+ admin: this.isSubscribed
2739
+ ? this.getStateAccount().admin
2740
+ : this.wallet.publicKey,
2741
+ state: await this.getStatePublicKey(),
2742
+ spotMarket: await getSpotMarketPublicKey(
2743
+ this.program.programId,
2744
+ spotMarketIndex
2745
+ ),
2746
+ },
2747
+ }
2748
+ );
2749
+ }
2750
+
2751
+ public async updateSpotMarketBorrowRate(
2752
+ spotMarketIndex: number,
2753
+ optimalUtilization: number,
2754
+ optimalBorrowRate: number,
2755
+ optimalMaxRate: number,
2756
+ minBorrowRate?: number | undefined
2757
+ ): Promise<TransactionSignature> {
2758
+ const updateSpotMarketBorrowRateIx =
2759
+ await this.getUpdateSpotMarketBorrowRateIx(
2760
+ spotMarketIndex,
2761
+ optimalUtilization,
2762
+ optimalBorrowRate,
2763
+ optimalMaxRate,
2764
+ minBorrowRate
2765
+ );
2766
+
2767
+ const tx = await this.buildTransaction(updateSpotMarketBorrowRateIx);
2768
+
2769
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2770
+
2771
+ return txSig;
2772
+ }
2773
+
2774
+ public async getUpdateSpotMarketBorrowRateIx(
2775
+ spotMarketIndex: number,
2776
+ optimalUtilization: number,
2777
+ optimalBorrowRate: number,
2778
+ optimalMaxRate: number,
2779
+ minBorrowRate?: number | undefined
2780
+ ): Promise<TransactionInstruction> {
2781
+ return await this.program.instruction.updateSpotMarketBorrowRate(
2782
+ optimalUtilization,
2783
+ optimalBorrowRate,
2784
+ optimalMaxRate,
2785
+ minBorrowRate,
2786
+ {
2787
+ accounts: {
2788
+ admin: this.isSubscribed
2789
+ ? this.getStateAccount().admin
2790
+ : this.wallet.publicKey,
2791
+ state: await this.getStatePublicKey(),
2792
+ spotMarket: await getSpotMarketPublicKey(
2793
+ this.program.programId,
2794
+ spotMarketIndex
2795
+ ),
2796
+ },
2797
+ }
2798
+ );
2799
+ }
2800
+
2801
+ public async updateSpotMarketAssetTier(
2802
+ spotMarketIndex: number,
2803
+ assetTier: AssetTier
2804
+ ): Promise<TransactionSignature> {
2805
+ const updateSpotMarketAssetTierIx =
2806
+ await this.getUpdateSpotMarketAssetTierIx(spotMarketIndex, assetTier);
2807
+
2808
+ const tx = await this.buildTransaction(updateSpotMarketAssetTierIx);
2809
+
2810
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2811
+
2812
+ return txSig;
2813
+ }
2814
+
2815
+ public async getUpdateSpotMarketAssetTierIx(
2816
+ spotMarketIndex: number,
2817
+ assetTier: AssetTier
2818
+ ): Promise<TransactionInstruction> {
2819
+ return await this.program.instruction.updateSpotMarketAssetTier(assetTier, {
2820
+ accounts: {
2821
+ admin: this.isSubscribed
2822
+ ? this.getStateAccount().admin
2823
+ : this.wallet.publicKey,
2824
+ state: await this.getStatePublicKey(),
2825
+ spotMarket: await getSpotMarketPublicKey(
2826
+ this.program.programId,
2827
+ spotMarketIndex
2828
+ ),
2829
+ },
2830
+ });
2831
+ }
2832
+
2833
+ public async updateSpotMarketStatus(
2834
+ spotMarketIndex: number,
2835
+ marketStatus: MarketStatus
2836
+ ): Promise<TransactionSignature> {
2837
+ const updateSpotMarketStatusIx = await this.getUpdateSpotMarketStatusIx(
2838
+ spotMarketIndex,
2839
+ marketStatus
2840
+ );
2841
+
2842
+ const tx = await this.buildTransaction(updateSpotMarketStatusIx);
2843
+
2844
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2845
+
2846
+ return txSig;
2847
+ }
2848
+
2849
+ public async getUpdateSpotMarketStatusIx(
2850
+ spotMarketIndex: number,
2851
+ marketStatus: MarketStatus
2852
+ ): Promise<TransactionInstruction> {
2853
+ return await this.program.instruction.updateSpotMarketStatus(marketStatus, {
2854
+ accounts: {
2855
+ admin: this.isSubscribed
2856
+ ? this.getStateAccount().admin
2857
+ : this.wallet.publicKey,
2858
+ state: await this.getStatePublicKey(),
2859
+ spotMarket: await getSpotMarketPublicKey(
2860
+ this.program.programId,
2861
+ spotMarketIndex
2862
+ ),
2863
+ },
2864
+ });
2865
+ }
2866
+
2867
+ public async updateSpotMarketPausedOperations(
2868
+ spotMarketIndex: number,
2869
+ pausedOperations: number
2870
+ ): Promise<TransactionSignature> {
2871
+ const updateSpotMarketPausedOperationsIx =
2872
+ await this.getUpdateSpotMarketPausedOperationsIx(
2873
+ spotMarketIndex,
2874
+ pausedOperations
2875
+ );
2876
+
2877
+ const tx = await this.buildTransaction(updateSpotMarketPausedOperationsIx);
2878
+
2879
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2880
+
2881
+ return txSig;
2882
+ }
2883
+
2884
+ public async getUpdateSpotMarketPausedOperationsIx(
2885
+ spotMarketIndex: number,
2886
+ pausedOperations: number
2887
+ ): Promise<TransactionInstruction> {
2888
+ return await this.program.instruction.updateSpotMarketPausedOperations(
2889
+ pausedOperations,
2890
+ {
2891
+ accounts: {
2892
+ admin: this.isSubscribed
2893
+ ? this.getStateAccount().admin
2894
+ : this.wallet.publicKey,
2895
+ state: await this.getStatePublicKey(),
2896
+ spotMarket: await getSpotMarketPublicKey(
2897
+ this.program.programId,
2898
+ spotMarketIndex
2899
+ ),
2900
+ },
2901
+ }
2902
+ );
2903
+ }
2904
+
2905
+ public async updatePerpMarketStatus(
2906
+ perpMarketIndex: number,
2907
+ marketStatus: MarketStatus
2908
+ ): Promise<TransactionSignature> {
2909
+ const updatePerpMarketStatusIx = await this.getUpdatePerpMarketStatusIx(
2910
+ perpMarketIndex,
2911
+ marketStatus
2912
+ );
2913
+
2914
+ const tx = await this.buildTransaction(updatePerpMarketStatusIx);
2915
+
2916
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2917
+
2918
+ return txSig;
2919
+ }
2920
+
2921
+ public async getUpdatePerpMarketStatusIx(
2922
+ perpMarketIndex: number,
2923
+ marketStatus: MarketStatus
2924
+ ): Promise<TransactionInstruction> {
2925
+ return await this.program.instruction.updatePerpMarketStatus(marketStatus, {
2926
+ accounts: {
2927
+ admin: this.isSubscribed
2928
+ ? this.getStateAccount().admin
2929
+ : this.wallet.publicKey,
2930
+ state: await this.getStatePublicKey(),
2931
+ perpMarket: await getPerpMarketPublicKey(
2932
+ this.program.programId,
2933
+ perpMarketIndex
2934
+ ),
2935
+ },
2936
+ });
2937
+ }
2938
+
2939
+ public async updatePerpMarketPausedOperations(
2940
+ perpMarketIndex: number,
2941
+ pausedOperations: number
2942
+ ): Promise<TransactionSignature> {
2943
+ const updatePerpMarketPausedOperationsIx =
2944
+ await this.getUpdatePerpMarketPausedOperationsIx(
2945
+ perpMarketIndex,
2946
+ pausedOperations
2947
+ );
2948
+
2949
+ const tx = await this.buildTransaction(updatePerpMarketPausedOperationsIx);
2950
+
2951
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2952
+
2953
+ return txSig;
2954
+ }
2955
+
2956
+ public async getUpdatePerpMarketPausedOperationsIx(
2957
+ perpMarketIndex: number,
2958
+ pausedOperations: number
2959
+ ): Promise<TransactionInstruction> {
2960
+ return await this.program.instruction.updatePerpMarketPausedOperations(
2961
+ pausedOperations,
2962
+ {
2963
+ accounts: {
2964
+ admin: this.isSubscribed
2965
+ ? this.getStateAccount().admin
2966
+ : this.wallet.publicKey,
2967
+ state: await this.getStatePublicKey(),
2968
+ perpMarket: await getPerpMarketPublicKey(
2969
+ this.program.programId,
2970
+ perpMarketIndex
2971
+ ),
2972
+ },
2973
+ }
2974
+ );
2975
+ }
2976
+
2977
+ public async updatePerpMarketContractTier(
2978
+ perpMarketIndex: number,
2979
+ contractTier: ContractTier
2980
+ ): Promise<TransactionSignature> {
2981
+ const updatePerpMarketContractTierIx =
2982
+ await this.getUpdatePerpMarketContractTierIx(
2983
+ perpMarketIndex,
2984
+ contractTier
2985
+ );
2986
+
2987
+ const tx = await this.buildTransaction(updatePerpMarketContractTierIx);
2988
+
2989
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2990
+
2991
+ return txSig;
2992
+ }
2993
+
2994
+ public async getUpdatePerpMarketContractTierIx(
2995
+ perpMarketIndex: number,
2996
+ contractTier: ContractTier
2997
+ ): Promise<TransactionInstruction> {
2998
+ return await this.program.instruction.updatePerpMarketContractTier(
2999
+ contractTier,
3000
+ {
3001
+ accounts: {
3002
+ admin: this.isSubscribed
3003
+ ? this.getStateAccount().admin
3004
+ : this.wallet.publicKey,
3005
+ state: await this.getStatePublicKey(),
3006
+ perpMarket: await getPerpMarketPublicKey(
3007
+ this.program.programId,
3008
+ perpMarketIndex
3009
+ ),
3010
+ },
3011
+ }
3012
+ );
3013
+ }
3014
+
3015
+ public async updateExchangeStatus(
3016
+ exchangeStatus: ExchangeStatus
3017
+ ): Promise<TransactionSignature> {
3018
+ const updateExchangeStatusIx = await this.getUpdateExchangeStatusIx(
3019
+ exchangeStatus
3020
+ );
3021
+
3022
+ const tx = await this.buildTransaction(updateExchangeStatusIx);
3023
+
3024
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3025
+
3026
+ return txSig;
3027
+ }
3028
+
3029
+ public async getUpdateExchangeStatusIx(
3030
+ exchangeStatus: ExchangeStatus
3031
+ ): Promise<TransactionInstruction> {
3032
+ return await this.program.instruction.updateExchangeStatus(exchangeStatus, {
3033
+ accounts: {
3034
+ admin: this.isSubscribed
3035
+ ? this.getStateAccount().admin
3036
+ : this.wallet.publicKey,
3037
+ state: await this.getStatePublicKey(),
3038
+ },
3039
+ });
3040
+ }
3041
+
3042
+ public async updatePerpAuctionDuration(
3043
+ minDuration: BN | number
3044
+ ): Promise<TransactionSignature> {
3045
+ const updatePerpAuctionDurationIx =
3046
+ await this.getUpdatePerpAuctionDurationIx(minDuration);
3047
+
3048
+ const tx = await this.buildTransaction(updatePerpAuctionDurationIx);
3049
+
3050
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3051
+
3052
+ return txSig;
3053
+ }
3054
+
3055
+ public async getUpdatePerpAuctionDurationIx(
3056
+ minDuration: BN | number
3057
+ ): Promise<TransactionInstruction> {
3058
+ return await this.program.instruction.updatePerpAuctionDuration(
3059
+ typeof minDuration === 'number' ? minDuration : minDuration.toNumber(),
3060
+ {
3061
+ accounts: {
3062
+ admin: this.isSubscribed
3063
+ ? this.getStateAccount().admin
3064
+ : this.wallet.publicKey,
3065
+ state: await this.getStatePublicKey(),
3066
+ },
3067
+ }
3068
+ );
3069
+ }
3070
+
3071
+ public async updateSpotAuctionDuration(
3072
+ defaultAuctionDuration: number
3073
+ ): Promise<TransactionSignature> {
3074
+ const updateSpotAuctionDurationIx =
3075
+ await this.getUpdateSpotAuctionDurationIx(defaultAuctionDuration);
3076
+
3077
+ const tx = await this.buildTransaction(updateSpotAuctionDurationIx);
3078
+
3079
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3080
+
3081
+ return txSig;
3082
+ }
3083
+
3084
+ public async getUpdateSpotAuctionDurationIx(
3085
+ defaultAuctionDuration: number
3086
+ ): Promise<TransactionInstruction> {
3087
+ return await this.program.instruction.updateSpotAuctionDuration(
3088
+ defaultAuctionDuration,
3089
+ {
3090
+ accounts: {
3091
+ admin: this.isSubscribed
3092
+ ? this.getStateAccount().admin
3093
+ : this.wallet.publicKey,
3094
+ state: await this.getStatePublicKey(),
3095
+ },
3096
+ }
3097
+ );
3098
+ }
3099
+
3100
+ public async updatePerpMarketMaxFillReserveFraction(
3101
+ perpMarketIndex: number,
3102
+ maxBaseAssetAmountRatio: number
3103
+ ): Promise<TransactionSignature> {
3104
+ const updatePerpMarketMaxFillReserveFractionIx =
3105
+ await this.getUpdatePerpMarketMaxFillReserveFractionIx(
3106
+ perpMarketIndex,
3107
+ maxBaseAssetAmountRatio
3108
+ );
3109
+
3110
+ const tx = await this.buildTransaction(
3111
+ updatePerpMarketMaxFillReserveFractionIx
3112
+ );
3113
+
3114
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3115
+
3116
+ return txSig;
3117
+ }
3118
+
3119
+ public async getUpdatePerpMarketMaxFillReserveFractionIx(
3120
+ perpMarketIndex: number,
3121
+ maxBaseAssetAmountRatio: number
3122
+ ): Promise<TransactionInstruction> {
3123
+ return await this.program.instruction.updatePerpMarketMaxFillReserveFraction(
3124
+ maxBaseAssetAmountRatio,
3125
+ {
3126
+ accounts: {
3127
+ admin: this.isSubscribed
3128
+ ? this.getStateAccount().admin
3129
+ : this.wallet.publicKey,
3130
+ state: await this.getStatePublicKey(),
3131
+ perpMarket: await getPerpMarketPublicKey(
3132
+ this.program.programId,
3133
+ perpMarketIndex
3134
+ ),
3135
+ },
3136
+ }
3137
+ );
3138
+ }
3139
+
3140
+ public async updateMaxSlippageRatio(
3141
+ perpMarketIndex: number,
3142
+ maxSlippageRatio: number
3143
+ ): Promise<TransactionSignature> {
3144
+ const updateMaxSlippageRatioIx = await this.getUpdateMaxSlippageRatioIx(
3145
+ perpMarketIndex,
3146
+ maxSlippageRatio
3147
+ );
3148
+
3149
+ const tx = await this.buildTransaction(updateMaxSlippageRatioIx);
3150
+
3151
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3152
+
3153
+ return txSig;
3154
+ }
3155
+
3156
+ public async getUpdateMaxSlippageRatioIx(
3157
+ perpMarketIndex: number,
3158
+ maxSlippageRatio: number
3159
+ ): Promise<TransactionInstruction> {
3160
+ return await this.program.instruction.updateMaxSlippageRatio(
3161
+ maxSlippageRatio,
3162
+ {
3163
+ accounts: {
3164
+ admin: this.isSubscribed
3165
+ ? this.getStateAccount().admin
3166
+ : this.wallet.publicKey,
3167
+ state: await this.getStatePublicKey(),
3168
+ perpMarket: this.getPerpMarketAccount(perpMarketIndex).pubkey,
3169
+ },
3170
+ }
3171
+ );
3172
+ }
3173
+
3174
+ public async updatePerpMarketUnrealizedAssetWeight(
3175
+ perpMarketIndex: number,
3176
+ unrealizedInitialAssetWeight: number,
3177
+ unrealizedMaintenanceAssetWeight: number
3178
+ ): Promise<TransactionSignature> {
3179
+ const updatePerpMarketUnrealizedAssetWeightIx =
3180
+ await this.getUpdatePerpMarketUnrealizedAssetWeightIx(
3181
+ perpMarketIndex,
3182
+ unrealizedInitialAssetWeight,
3183
+ unrealizedMaintenanceAssetWeight
3184
+ );
3185
+
3186
+ const tx = await this.buildTransaction(
3187
+ updatePerpMarketUnrealizedAssetWeightIx
3188
+ );
3189
+
3190
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3191
+
3192
+ return txSig;
3193
+ }
3194
+
3195
+ public async getUpdatePerpMarketUnrealizedAssetWeightIx(
3196
+ perpMarketIndex: number,
3197
+ unrealizedInitialAssetWeight: number,
3198
+ unrealizedMaintenanceAssetWeight: number
3199
+ ): Promise<TransactionInstruction> {
3200
+ return await this.program.instruction.updatePerpMarketUnrealizedAssetWeight(
3201
+ unrealizedInitialAssetWeight,
3202
+ unrealizedMaintenanceAssetWeight,
3203
+ {
3204
+ accounts: {
3205
+ admin: this.isSubscribed
3206
+ ? this.getStateAccount().admin
3207
+ : this.wallet.publicKey,
3208
+ state: await this.getStatePublicKey(),
3209
+ perpMarket: await getPerpMarketPublicKey(
3210
+ this.program.programId,
3211
+ perpMarketIndex
3212
+ ),
3213
+ },
3214
+ }
3215
+ );
3216
+ }
3217
+
3218
+ public async updatePerpMarketMaxImbalances(
3219
+ perpMarketIndex: number,
3220
+ unrealizedMaxImbalance: BN,
3221
+ maxRevenueWithdrawPerPeriod: BN,
3222
+ quoteMaxInsurance: BN
3223
+ ): Promise<TransactionSignature> {
3224
+ const updatePerpMarketMaxImabalancesIx =
3225
+ await this.getUpdatePerpMarketMaxImbalancesIx(
3226
+ perpMarketIndex,
3227
+ unrealizedMaxImbalance,
3228
+ maxRevenueWithdrawPerPeriod,
3229
+ quoteMaxInsurance
3230
+ );
3231
+
3232
+ const tx = await this.buildTransaction(updatePerpMarketMaxImabalancesIx);
3233
+
3234
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3235
+
3236
+ return txSig;
3237
+ }
3238
+
3239
+ public async getUpdatePerpMarketMaxImbalancesIx(
3240
+ perpMarketIndex: number,
3241
+ unrealizedMaxImbalance: BN,
3242
+ maxRevenueWithdrawPerPeriod: BN,
3243
+ quoteMaxInsurance: BN
3244
+ ): Promise<TransactionInstruction> {
3245
+ return await this.program.instruction.updatePerpMarketMaxImbalances(
3246
+ unrealizedMaxImbalance,
3247
+ maxRevenueWithdrawPerPeriod,
3248
+ quoteMaxInsurance,
3249
+ {
3250
+ accounts: {
3251
+ admin: this.isSubscribed
3252
+ ? this.getStateAccount().admin
3253
+ : this.wallet.publicKey,
3254
+ state: await this.getStatePublicKey(),
3255
+ perpMarket: await getPerpMarketPublicKey(
3256
+ this.program.programId,
3257
+ perpMarketIndex
3258
+ ),
3259
+ },
3260
+ }
3261
+ );
3262
+ }
3263
+
3264
+ public async updatePerpMarketMaxOpenInterest(
3265
+ perpMarketIndex: number,
3266
+ maxOpenInterest: BN
3267
+ ): Promise<TransactionSignature> {
3268
+ const updatePerpMarketMaxOpenInterestIx =
3269
+ await this.getUpdatePerpMarketMaxOpenInterestIx(
3270
+ perpMarketIndex,
3271
+ maxOpenInterest
3272
+ );
3273
+
3274
+ const tx = await this.buildTransaction(updatePerpMarketMaxOpenInterestIx);
3275
+
3276
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3277
+
3278
+ return txSig;
3279
+ }
3280
+
3281
+ public async getUpdatePerpMarketMaxOpenInterestIx(
3282
+ perpMarketIndex: number,
3283
+ maxOpenInterest: BN
3284
+ ): Promise<TransactionInstruction> {
3285
+ return await this.program.instruction.updatePerpMarketMaxOpenInterest(
3286
+ maxOpenInterest,
3287
+ {
3288
+ accounts: {
3289
+ admin: this.isSubscribed
3290
+ ? this.getStateAccount().admin
3291
+ : this.wallet.publicKey,
3292
+ state: await this.getStatePublicKey(),
3293
+ perpMarket: await getPerpMarketPublicKey(
3294
+ this.program.programId,
3295
+ perpMarketIndex
3296
+ ),
3297
+ },
3298
+ }
3299
+ );
3300
+ }
3301
+
3302
+ public async updatePerpMarketNumberOfUser(
3303
+ perpMarketIndex: number,
3304
+ numberOfUsers?: number,
3305
+ numberOfUsersWithBase?: number
3306
+ ): Promise<TransactionSignature> {
3307
+ const updatepPerpMarketFeeAdjustmentIx =
3308
+ await this.getUpdatePerpMarketNumberOfUsersIx(
3309
+ perpMarketIndex,
3310
+ numberOfUsers,
3311
+ numberOfUsersWithBase
3312
+ );
3313
+
3314
+ const tx = await this.buildTransaction(updatepPerpMarketFeeAdjustmentIx);
3315
+
3316
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3317
+
3318
+ return txSig;
3319
+ }
3320
+
3321
+ public async getUpdatePerpMarketNumberOfUsersIx(
3322
+ perpMarketIndex: number,
3323
+ numberOfUsers?: number,
3324
+ numberOfUsersWithBase?: number
3325
+ ): Promise<TransactionInstruction> {
3326
+ return await this.program.instruction.updatePerpMarketNumberOfUsers(
3327
+ numberOfUsers,
3328
+ numberOfUsersWithBase,
3329
+ {
3330
+ accounts: {
3331
+ admin: this.isSubscribed
3332
+ ? this.getStateAccount().admin
3333
+ : this.wallet.publicKey,
3334
+ state: await this.getStatePublicKey(),
3335
+ perpMarket: await getPerpMarketPublicKey(
3336
+ this.program.programId,
3337
+ perpMarketIndex
3338
+ ),
3339
+ },
3340
+ }
3341
+ );
3342
+ }
3343
+
3344
+ public async updatePerpMarketFeeAdjustment(
3345
+ perpMarketIndex: number,
3346
+ feeAdjustment: number
3347
+ ): Promise<TransactionSignature> {
3348
+ const updatepPerpMarketFeeAdjustmentIx =
3349
+ await this.getUpdatePerpMarketFeeAdjustmentIx(
3350
+ perpMarketIndex,
3351
+ feeAdjustment
3352
+ );
3353
+
3354
+ const tx = await this.buildTransaction(updatepPerpMarketFeeAdjustmentIx);
3355
+
3356
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3357
+
3358
+ return txSig;
3359
+ }
3360
+
3361
+ public async getUpdatePerpMarketFeeAdjustmentIx(
3362
+ perpMarketIndex: number,
3363
+ feeAdjustment: number
3364
+ ): Promise<TransactionInstruction> {
3365
+ return await this.program.instruction.updatePerpMarketFeeAdjustment(
3366
+ feeAdjustment,
3367
+ {
3368
+ accounts: {
3369
+ admin: this.isSubscribed
3370
+ ? this.getStateAccount().admin
3371
+ : this.wallet.publicKey,
3372
+ state: await this.getStatePublicKey(),
3373
+ perpMarket: await getPerpMarketPublicKey(
3374
+ this.program.programId,
3375
+ perpMarketIndex
3376
+ ),
3377
+ },
3378
+ }
3379
+ );
3380
+ }
3381
+
3382
+ public async updateSpotMarketFeeAdjustment(
3383
+ perpMarketIndex: number,
3384
+ feeAdjustment: number
3385
+ ): Promise<TransactionSignature> {
3386
+ const updateSpotMarketFeeAdjustmentIx =
3387
+ await this.getUpdateSpotMarketFeeAdjustmentIx(
3388
+ perpMarketIndex,
3389
+ feeAdjustment
3390
+ );
3391
+
3392
+ const tx = await this.buildTransaction(updateSpotMarketFeeAdjustmentIx);
3393
+
3394
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3395
+
3396
+ return txSig;
3397
+ }
3398
+
3399
+ public async getUpdateSpotMarketFeeAdjustmentIx(
3400
+ spotMarketIndex: number,
3401
+ feeAdjustment: number
3402
+ ): Promise<TransactionInstruction> {
3403
+ return await this.program.instruction.updateSpotMarketFeeAdjustment(
3404
+ feeAdjustment,
3405
+ {
3406
+ accounts: {
3407
+ admin: this.isSubscribed
3408
+ ? this.getStateAccount().admin
3409
+ : this.wallet.publicKey,
3410
+ state: await this.getStatePublicKey(),
3411
+ spotMarket: await getSpotMarketPublicKey(
3412
+ this.program.programId,
3413
+ spotMarketIndex
3414
+ ),
3415
+ },
3416
+ }
3417
+ );
3418
+ }
3419
+
3420
+ public async updateSerumVault(
3421
+ srmVault: PublicKey
3422
+ ): Promise<TransactionSignature> {
3423
+ const updateSerumVaultIx = await this.getUpdateSerumVaultIx(srmVault);
3424
+
3425
+ const tx = await this.buildTransaction(updateSerumVaultIx);
3426
+
3427
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3428
+
3429
+ return txSig;
3430
+ }
3431
+
3432
+ public async getUpdateSerumVaultIx(
3433
+ srmVault: PublicKey
3434
+ ): Promise<TransactionInstruction> {
3435
+ return await this.program.instruction.updateSerumVault(srmVault, {
3436
+ accounts: {
3437
+ admin: this.isSubscribed
3438
+ ? this.getStateAccount().admin
3439
+ : this.wallet.publicKey,
3440
+ state: await this.getStatePublicKey(),
3441
+ srmVault: srmVault,
3442
+ },
3443
+ });
3444
+ }
3445
+
3446
+ public async updatePerpMarketLiquidationFee(
3447
+ perpMarketIndex: number,
3448
+ liquidatorFee: number,
3449
+ ifLiquidationFee: number
3450
+ ): Promise<TransactionSignature> {
3451
+ const updatePerpMarketLiquidationFeeIx =
3452
+ await this.getUpdatePerpMarketLiquidationFeeIx(
3453
+ perpMarketIndex,
3454
+ liquidatorFee,
3455
+ ifLiquidationFee
3456
+ );
3457
+
3458
+ const tx = await this.buildTransaction(updatePerpMarketLiquidationFeeIx);
3459
+
3460
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3461
+
3462
+ return txSig;
3463
+ }
3464
+
3465
+ public async getUpdatePerpMarketLiquidationFeeIx(
3466
+ perpMarketIndex: number,
3467
+ liquidatorFee: number,
3468
+ ifLiquidationFee: number
3469
+ ): Promise<TransactionInstruction> {
3470
+ return await this.program.instruction.updatePerpMarketLiquidationFee(
3471
+ liquidatorFee,
3472
+ ifLiquidationFee,
3473
+ {
3474
+ accounts: {
3475
+ admin: this.isSubscribed
3476
+ ? this.getStateAccount().admin
3477
+ : this.wallet.publicKey,
3478
+ state: await this.getStatePublicKey(),
3479
+ perpMarket: await getPerpMarketPublicKey(
3480
+ this.program.programId,
3481
+ perpMarketIndex
3482
+ ),
3483
+ },
3484
+ }
3485
+ );
3486
+ }
3487
+
3488
+ public async updateSpotMarketLiquidationFee(
3489
+ spotMarketIndex: number,
3490
+ liquidatorFee: number,
3491
+ ifLiquidationFee: number
3492
+ ): Promise<TransactionSignature> {
3493
+ const updateSpotMarketLiquidationFeeIx =
3494
+ await this.getUpdateSpotMarketLiquidationFeeIx(
3495
+ spotMarketIndex,
3496
+ liquidatorFee,
3497
+ ifLiquidationFee
3498
+ );
3499
+
3500
+ const tx = await this.buildTransaction(updateSpotMarketLiquidationFeeIx);
3501
+
3502
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3503
+
3504
+ return txSig;
3505
+ }
3506
+
3507
+ public async getUpdateSpotMarketLiquidationFeeIx(
3508
+ spotMarketIndex: number,
3509
+ liquidatorFee: number,
3510
+ ifLiquidationFee: number
3511
+ ): Promise<TransactionInstruction> {
3512
+ return await this.program.instruction.updateSpotMarketLiquidationFee(
3513
+ liquidatorFee,
3514
+ ifLiquidationFee,
3515
+ {
3516
+ accounts: {
3517
+ admin: this.isSubscribed
3518
+ ? this.getStateAccount().admin
3519
+ : this.wallet.publicKey,
3520
+ state: await this.getStatePublicKey(),
3521
+ spotMarket: await getSpotMarketPublicKey(
3522
+ this.program.programId,
3523
+ spotMarketIndex
3524
+ ),
3525
+ },
3526
+ }
3527
+ );
3528
+ }
3529
+
3530
+ public async initializeProtocolIfSharesTransferConfig(): Promise<TransactionSignature> {
3531
+ const initializeProtocolIfSharesTransferConfigIx =
3532
+ await this.getInitializeProtocolIfSharesTransferConfigIx();
3533
+
3534
+ const tx = await this.buildTransaction(
3535
+ initializeProtocolIfSharesTransferConfigIx
3536
+ );
3537
+
3538
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3539
+
3540
+ return txSig;
3541
+ }
3542
+
3543
+ public async getInitializeProtocolIfSharesTransferConfigIx(): Promise<TransactionInstruction> {
3544
+ return await this.program.instruction.initializeProtocolIfSharesTransferConfig(
3545
+ {
3546
+ accounts: {
3547
+ admin: this.isSubscribed
3548
+ ? this.getStateAccount().admin
3549
+ : this.wallet.publicKey,
3550
+ state: await this.getStatePublicKey(),
3551
+ rent: SYSVAR_RENT_PUBKEY,
3552
+ systemProgram: anchor.web3.SystemProgram.programId,
3553
+ protocolIfSharesTransferConfig:
3554
+ getProtocolIfSharesTransferConfigPublicKey(this.program.programId),
3555
+ },
3556
+ }
3557
+ );
3558
+ }
3559
+
3560
+ public async updateProtocolIfSharesTransferConfig(
3561
+ whitelistedSigners?: PublicKey[],
3562
+ maxTransferPerEpoch?: BN
3563
+ ): Promise<TransactionSignature> {
3564
+ const updateProtocolIfSharesTransferConfigIx =
3565
+ await this.getUpdateProtocolIfSharesTransferConfigIx(
3566
+ whitelistedSigners,
3567
+ maxTransferPerEpoch
3568
+ );
3569
+
3570
+ const tx = await this.buildTransaction(
3571
+ updateProtocolIfSharesTransferConfigIx
3572
+ );
3573
+
3574
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3575
+
3576
+ return txSig;
3577
+ }
3578
+
3579
+ public async getUpdateProtocolIfSharesTransferConfigIx(
3580
+ whitelistedSigners?: PublicKey[],
3581
+ maxTransferPerEpoch?: BN
3582
+ ): Promise<TransactionInstruction> {
3583
+ return await this.program.instruction.updateProtocolIfSharesTransferConfig(
3584
+ whitelistedSigners || null,
3585
+ maxTransferPerEpoch,
3586
+ {
3587
+ accounts: {
3588
+ admin: this.isSubscribed
3589
+ ? this.getStateAccount().admin
3590
+ : this.wallet.publicKey,
3591
+ state: await this.getStatePublicKey(),
3592
+ protocolIfSharesTransferConfig:
3593
+ getProtocolIfSharesTransferConfigPublicKey(this.program.programId),
3594
+ },
3595
+ }
3596
+ );
3597
+ }
3598
+
3599
+ public async initializePrelaunchOracle(
3600
+ perpMarketIndex: number,
3601
+ price?: BN,
3602
+ maxPrice?: BN
3603
+ ): Promise<TransactionSignature> {
3604
+ const initializePrelaunchOracleIx =
3605
+ await this.getInitializePrelaunchOracleIx(
3606
+ perpMarketIndex,
3607
+ price,
3608
+ maxPrice
3609
+ );
3610
+
3611
+ const tx = await this.buildTransaction(initializePrelaunchOracleIx);
3612
+
3613
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3614
+
3615
+ return txSig;
3616
+ }
3617
+
3618
+ public async getInitializePrelaunchOracleIx(
3619
+ perpMarketIndex: number,
3620
+ price?: BN,
3621
+ maxPrice?: BN
3622
+ ): Promise<TransactionInstruction> {
3623
+ const params = {
3624
+ perpMarketIndex,
3625
+ price: price || null,
3626
+ maxPrice: maxPrice || null,
3627
+ };
3628
+
3629
+ return await this.program.instruction.initializePrelaunchOracle(params, {
3630
+ accounts: {
3631
+ admin: this.isSubscribed
3632
+ ? this.getStateAccount().admin
3633
+ : this.wallet.publicKey,
3634
+ state: await this.getStatePublicKey(),
3635
+ prelaunchOracle: await getPrelaunchOraclePublicKey(
3636
+ this.program.programId,
3637
+ perpMarketIndex
3638
+ ),
3639
+ rent: SYSVAR_RENT_PUBKEY,
3640
+ systemProgram: anchor.web3.SystemProgram.programId,
3641
+ },
3642
+ });
3643
+ }
3644
+
3645
+ public async updatePrelaunchOracleParams(
3646
+ perpMarketIndex: number,
3647
+ price?: BN,
3648
+ maxPrice?: BN
3649
+ ): Promise<TransactionSignature> {
3650
+ const updatePrelaunchOracleParamsIx =
3651
+ await this.getUpdatePrelaunchOracleParamsIx(
3652
+ perpMarketIndex,
3653
+ price,
3654
+ maxPrice
3655
+ );
3656
+
3657
+ const tx = await this.buildTransaction(updatePrelaunchOracleParamsIx);
3658
+
3659
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3660
+
3661
+ return txSig;
3662
+ }
3663
+
3664
+ public async getUpdatePrelaunchOracleParamsIx(
3665
+ perpMarketIndex: number,
3666
+ price?: BN,
3667
+ maxPrice?: BN
3668
+ ): Promise<TransactionInstruction> {
3669
+ const params = {
3670
+ perpMarketIndex,
3671
+ price: price || null,
3672
+ maxPrice: maxPrice || null,
3673
+ };
3674
+
3675
+ const perpMarketPublicKey = await getPerpMarketPublicKey(
3676
+ this.program.programId,
3677
+ perpMarketIndex
3678
+ );
3679
+
3680
+ return await this.program.instruction.updatePrelaunchOracleParams(params, {
3681
+ accounts: {
3682
+ admin: this.isSubscribed
3683
+ ? this.getStateAccount().admin
3684
+ : this.wallet.publicKey,
3685
+ state: await this.getStatePublicKey(),
3686
+ perpMarket: perpMarketPublicKey,
3687
+ prelaunchOracle: await getPrelaunchOraclePublicKey(
3688
+ this.program.programId,
3689
+ perpMarketIndex
3690
+ ),
3691
+ },
3692
+ });
3693
+ }
3694
+
3695
+ public async deletePrelaunchOracle(
3696
+ perpMarketIndex: number
3697
+ ): Promise<TransactionSignature> {
3698
+ const deletePrelaunchOracleIx = await this.getDeletePrelaunchOracleIx(
3699
+ perpMarketIndex
3700
+ );
3701
+
3702
+ const tx = await this.buildTransaction(deletePrelaunchOracleIx);
3703
+
3704
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3705
+
3706
+ return txSig;
3707
+ }
3708
+
3709
+ public async getDeletePrelaunchOracleIx(
3710
+ perpMarketIndex: number,
3711
+ price?: BN,
3712
+ maxPrice?: BN
3713
+ ): Promise<TransactionInstruction> {
3714
+ const params = {
3715
+ perpMarketIndex,
3716
+ price: price || null,
3717
+ maxPrice: maxPrice || null,
3718
+ };
3719
+
3720
+ const perpMarketPublicKey = await getPerpMarketPublicKey(
3721
+ this.program.programId,
3722
+ perpMarketIndex
3723
+ );
3724
+
3725
+ return await this.program.instruction.deletePrelaunchOracle(params, {
3726
+ accounts: {
3727
+ admin: this.isSubscribed
3728
+ ? this.getStateAccount().admin
3729
+ : this.wallet.publicKey,
3730
+ state: await this.getStatePublicKey(),
3731
+ perpMarket: perpMarketPublicKey,
3732
+ prelaunchOracle: await getPrelaunchOraclePublicKey(
3733
+ this.program.programId,
3734
+ perpMarketIndex
3735
+ ),
3736
+ },
3737
+ });
3738
+ }
3739
+
3740
+ public async updateSpotMarketFuel(
3741
+ spotMarketIndex: number,
3742
+ fuelBoostDeposits?: number,
3743
+ fuelBoostBorrows?: number,
3744
+ fuelBoostTaker?: number,
3745
+ fuelBoostMaker?: number,
3746
+ fuelBoostInsurance?: number
3747
+ ): Promise<TransactionSignature> {
3748
+ const updateSpotMarketFuelIx = await this.getUpdateSpotMarketFuelIx(
3749
+ spotMarketIndex,
3750
+ fuelBoostDeposits || null,
3751
+ fuelBoostBorrows || null,
3752
+ fuelBoostTaker || null,
3753
+ fuelBoostMaker || null,
3754
+ fuelBoostInsurance || null
3755
+ );
3756
+
3757
+ const tx = await this.buildTransaction(updateSpotMarketFuelIx);
3758
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3759
+
3760
+ return txSig;
3761
+ }
3762
+
3763
+ public async getUpdateSpotMarketFuelIx(
3764
+ spotMarketIndex: number,
3765
+ fuelBoostDeposits?: number,
3766
+ fuelBoostBorrows?: number,
3767
+ fuelBoostTaker?: number,
3768
+ fuelBoostMaker?: number,
3769
+ fuelBoostInsurance?: number
3770
+ ): Promise<TransactionInstruction> {
3771
+ const spotMarketPublicKey = await getSpotMarketPublicKey(
3772
+ this.program.programId,
3773
+ spotMarketIndex
3774
+ );
3775
+
3776
+ return await this.program.instruction.updateSpotMarketFuel(
3777
+ fuelBoostDeposits || null,
3778
+ fuelBoostBorrows || null,
3779
+ fuelBoostTaker || null,
3780
+ fuelBoostMaker || null,
3781
+ fuelBoostInsurance || null,
3782
+ {
3783
+ accounts: {
3784
+ admin: this.isSubscribed
3785
+ ? this.getStateAccount().admin
3786
+ : this.wallet.publicKey,
3787
+ state: await this.getStatePublicKey(),
3788
+ spotMarket: spotMarketPublicKey,
3789
+ },
3790
+ }
3791
+ );
3792
+ }
3793
+
3794
+ public async updatePerpMarketFuel(
3795
+ perpMarketIndex: number,
3796
+ fuelBoostTaker?: number,
3797
+ fuelBoostMaker?: number,
3798
+ fuelBoostPosition?: number
3799
+ ): Promise<TransactionSignature> {
3800
+ const updatePerpMarketFuelIx = await this.getUpdatePerpMarketFuelIx(
3801
+ perpMarketIndex,
3802
+ fuelBoostTaker || null,
3803
+ fuelBoostMaker || null,
3804
+ fuelBoostPosition || null
3805
+ );
3806
+
3807
+ const tx = await this.buildTransaction(updatePerpMarketFuelIx);
3808
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3809
+
3810
+ return txSig;
3811
+ }
3812
+
3813
+ public async getUpdatePerpMarketFuelIx(
3814
+ perpMarketIndex: number,
3815
+ fuelBoostTaker?: number,
3816
+ fuelBoostMaker?: number,
3817
+ fuelBoostPosition?: number
3818
+ ): Promise<TransactionInstruction> {
3819
+ const perpMarketPublicKey = await getPerpMarketPublicKey(
3820
+ this.program.programId,
3821
+ perpMarketIndex
3822
+ );
3823
+
3824
+ return await this.program.instruction.updatePerpMarketFuel(
3825
+ fuelBoostTaker || null,
3826
+ fuelBoostMaker || null,
3827
+ fuelBoostPosition || null,
3828
+ {
3829
+ accounts: {
3830
+ admin: this.isSubscribed
3831
+ ? this.getStateAccount().admin
3832
+ : this.wallet.publicKey,
3833
+ state: await this.getStatePublicKey(),
3834
+ perpMarket: perpMarketPublicKey,
3835
+ },
3836
+ }
3837
+ );
3838
+ }
3839
+
3840
+ public async initUserFuel(
3841
+ user: PublicKey,
3842
+ authority: PublicKey,
3843
+ fuelBonusDeposits?: number,
3844
+ fuelBonusBorrows?: number,
3845
+ fuelBonusTaker?: number,
3846
+ fuelBonusMaker?: number,
3847
+ fuelBonusInsurance?: number
3848
+ ): Promise<TransactionSignature> {
3849
+ const updatePerpMarketFuelIx = await this.getInitUserFuelIx(
3850
+ user,
3851
+ authority,
3852
+ fuelBonusDeposits,
3853
+ fuelBonusBorrows,
3854
+ fuelBonusTaker,
3855
+ fuelBonusMaker,
3856
+ fuelBonusInsurance
3857
+ );
3858
+
3859
+ const tx = await this.buildTransaction(updatePerpMarketFuelIx);
3860
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3861
+
3862
+ return txSig;
3863
+ }
3864
+
3865
+ public async getInitUserFuelIx(
3866
+ user: PublicKey,
3867
+ authority: PublicKey,
3868
+ fuelBonusDeposits?: number,
3869
+ fuelBonusBorrows?: number,
3870
+ fuelBonusTaker?: number,
3871
+ fuelBonusMaker?: number,
3872
+ fuelBonusInsurance?: number
3873
+ ): Promise<TransactionInstruction> {
3874
+ const userStats = await getUserStatsAccountPublicKey(
3875
+ this.program.programId,
3876
+ authority
3877
+ );
3878
+
3879
+ return await this.program.instruction.initUserFuel(
3880
+ fuelBonusDeposits || null,
3881
+ fuelBonusBorrows || null,
3882
+ fuelBonusTaker || null,
3883
+ fuelBonusMaker || null,
3884
+ fuelBonusInsurance || null,
3885
+ {
3886
+ accounts: {
3887
+ admin: this.wallet.publicKey,
3888
+ state: await this.getStatePublicKey(),
3889
+ user,
3890
+ userStats,
3891
+ },
3892
+ }
3893
+ );
3894
+ }
3895
+
3896
+ public async initializePythPullOracle(
3897
+ feedId: string,
3898
+ isAdmin = false
3899
+ ): Promise<TransactionSignature> {
3900
+ const initializePythPullOracleIx = await this.getInitializePythPullOracleIx(
3901
+ feedId,
3902
+ isAdmin
3903
+ );
3904
+ const tx = await this.buildTransaction(initializePythPullOracleIx);
3905
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3906
+
3907
+ return txSig;
3908
+ }
3909
+
3910
+ public async getInitializePythPullOracleIx(
3911
+ feedId: string,
3912
+ isAdmin = false
3913
+ ): Promise<TransactionInstruction> {
3914
+ const feedIdBuffer = getFeedIdUint8Array(feedId);
3915
+ return await this.program.instruction.initializePythPullOracle(
3916
+ feedIdBuffer,
3917
+ {
3918
+ accounts: {
3919
+ admin: isAdmin ? this.getStateAccount().admin : this.wallet.publicKey,
3920
+ state: await this.getStatePublicKey(),
3921
+ systemProgram: SystemProgram.programId,
3922
+ priceFeed: getPythPullOraclePublicKey(
3923
+ this.program.programId,
3924
+ feedIdBuffer
3925
+ ),
3926
+ pythSolanaReceiver: DRIFT_ORACLE_RECEIVER_ID,
3927
+ },
3928
+ }
3929
+ );
3930
+ }
3931
+
3932
+ public async initializePythLazerOracle(
3933
+ feedId: number,
3934
+ isAdmin = false
3935
+ ): Promise<TransactionSignature> {
3936
+ const initializePythPullOracleIx =
3937
+ await this.getInitializePythLazerOracleIx(feedId, isAdmin);
3938
+ const tx = await this.buildTransaction(initializePythPullOracleIx);
3939
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3940
+
3941
+ return txSig;
3942
+ }
3943
+
3944
+ public async getInitializePythLazerOracleIx(
3945
+ feedId: number,
3946
+ isAdmin = false
3947
+ ): Promise<TransactionInstruction> {
3948
+ return await this.program.instruction.initializePythLazerOracle(feedId, {
3949
+ accounts: {
3950
+ admin: isAdmin ? this.getStateAccount().admin : this.wallet.publicKey,
3951
+ state: await this.getStatePublicKey(),
3952
+ systemProgram: SystemProgram.programId,
3953
+ lazerOracle: getPythLazerOraclePublicKey(
3954
+ this.program.programId,
3955
+ feedId
3956
+ ),
3957
+ rent: SYSVAR_RENT_PUBKEY,
3958
+ },
3959
+ });
3960
+ }
3961
+
3962
+ public async initializeHighLeverageModeConfig(
3963
+ maxUsers: number
3964
+ ): Promise<TransactionSignature> {
3965
+ const initializeHighLeverageModeConfigIx =
3966
+ await this.getInitializeHighLeverageModeConfigIx(maxUsers);
3967
+
3968
+ const tx = await this.buildTransaction(initializeHighLeverageModeConfigIx);
3969
+
3970
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
3971
+
3972
+ return txSig;
3973
+ }
3974
+
3975
+ public async getInitializeHighLeverageModeConfigIx(
3976
+ maxUsers: number
3977
+ ): Promise<TransactionInstruction> {
3978
+ return await this.program.instruction.initializeHighLeverageModeConfig(
3979
+ maxUsers,
3980
+ {
3981
+ accounts: {
3982
+ admin: this.isSubscribed
3983
+ ? this.getStateAccount().admin
3984
+ : this.wallet.publicKey,
3985
+ state: await this.getStatePublicKey(),
3986
+ rent: SYSVAR_RENT_PUBKEY,
3987
+ systemProgram: anchor.web3.SystemProgram.programId,
3988
+ highLeverageModeConfig: getHighLeverageModeConfigPublicKey(
3989
+ this.program.programId
3990
+ ),
3991
+ },
3992
+ }
3993
+ );
3994
+ }
3995
+
3996
+ public async updateUpdateHighLeverageModeConfig(
3997
+ maxUsers: number,
3998
+ reduceOnly: boolean
3999
+ ): Promise<TransactionSignature> {
4000
+ const updateHighLeverageModeConfigIx =
4001
+ await this.getUpdateHighLeverageModeConfigIx(maxUsers, reduceOnly);
4002
+
4003
+ const tx = await this.buildTransaction(updateHighLeverageModeConfigIx);
4004
+
4005
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
4006
+
4007
+ return txSig;
4008
+ }
4009
+
4010
+ public async getUpdateHighLeverageModeConfigIx(
4011
+ maxUsers: number,
4012
+ reduceOnly: boolean
4013
+ ): Promise<TransactionInstruction> {
4014
+ return await this.program.instruction.updateHighLeverageModeConfig(
4015
+ maxUsers,
4016
+ reduceOnly,
4017
+ {
4018
+ accounts: {
4019
+ admin: this.isSubscribed
4020
+ ? this.getStateAccount().admin
4021
+ : this.wallet.publicKey,
4022
+ state: await this.getStatePublicKey(),
4023
+ highLeverageModeConfig: getHighLeverageModeConfigPublicKey(
4024
+ this.program.programId
4025
+ ),
4026
+ },
4027
+ }
4028
+ );
4029
+ }
4030
+ }