@drift-labs/sdk 2.97.0-beta.3 → 2.97.0-beta.30

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 (754) hide show
  1. package/README.md +11 -4
  2. package/VERSION +1 -1
  3. package/bun.lockb +0 -0
  4. package/lib/{accounts → browser/accounts}/bulkAccountLoader.d.ts +1 -0
  5. package/lib/browser/accounts/grpcAccountSubscriber.d.ts +16 -0
  6. package/lib/browser/accounts/grpcAccountSubscriber.js +154 -0
  7. package/lib/browser/accounts/grpcDriftClientAccountSubscriber.d.ts +12 -0
  8. package/lib/browser/accounts/grpcDriftClientAccountSubscriber.js +97 -0
  9. package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +10 -0
  10. package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.js +30 -0
  11. package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +18 -0
  12. package/lib/browser/accounts/grpcProgramAccountSubscriber.js +171 -0
  13. package/lib/browser/accounts/grpcUserAccountSubscriber.d.ts +10 -0
  14. package/lib/browser/accounts/grpcUserAccountSubscriber.js +28 -0
  15. package/lib/browser/accounts/grpcUserStatsAccountSubscriber.d.ts +10 -0
  16. package/lib/browser/accounts/grpcUserStatsAccountSubscriber.js +28 -0
  17. package/lib/{accounts → browser/accounts}/types.d.ts +8 -0
  18. package/lib/{accounts → browser/accounts}/webSocketAccountSubscriber.d.ts +2 -1
  19. package/lib/{accounts → browser/accounts}/webSocketDriftClientAccountSubscriber.d.ts +3 -3
  20. package/lib/{accounts → browser/accounts}/webSocketProgramAccountSubscriber.d.ts +2 -1
  21. package/lib/{addresses → browser/addresses}/pda.d.ts +2 -0
  22. package/lib/{addresses → browser/addresses}/pda.js +12 -1
  23. package/lib/{adminClient.d.ts → browser/adminClient.d.ts} +6 -0
  24. package/lib/{adminClient.js → browser/adminClient.js} +53 -0
  25. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +15 -0
  26. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +32 -0
  27. package/lib/{auctionSubscriber → browser/auctionSubscriber}/index.d.ts +1 -0
  28. package/lib/browser/auctionSubscriber/index.js +19 -0
  29. package/lib/{auctionSubscriber → browser/auctionSubscriber}/types.d.ts +2 -0
  30. package/lib/{bankrun → browser/bankrun}/bankrunConnection.d.ts +1 -0
  31. package/lib/{config.d.ts → browser/config.d.ts} +1 -1
  32. package/lib/{config.js → browser/config.js} +5 -3
  33. package/lib/{constants → browser/constants}/perpMarkets.js +43 -2
  34. package/lib/{constants → browser/constants}/spotMarkets.js +2 -2
  35. package/lib/{decode → browser/decode}/phoenix.d.ts +1 -0
  36. package/lib/{decode → browser/decode}/user.d.ts +1 -0
  37. package/lib/{decode → browser/decode}/user.js +10 -0
  38. package/lib/{dlob → browser/dlob}/DLOBOrders.d.ts +1 -0
  39. package/lib/{driftClient.d.ts → browser/driftClient.d.ts} +27 -5
  40. package/lib/{driftClient.js → browser/driftClient.js} +204 -37
  41. package/lib/{driftClientConfig.d.ts → browser/driftClientConfig.d.ts} +6 -1
  42. package/lib/{idl → browser/idl}/drift.json +502 -6
  43. package/lib/{idl → browser/idl}/switchboard_on_demand_30.json +195 -37
  44. package/lib/{index.d.ts → browser/index.d.ts} +8 -0
  45. package/lib/{index.js → browser/index.js} +8 -0
  46. package/lib/browser/isomorphic/grpc.browser.d.ts +1 -0
  47. package/lib/browser/isomorphic/grpc.browser.js +8 -0
  48. package/lib/browser/isomorphic/grpc.d.ts +1 -0
  49. package/lib/browser/isomorphic/grpc.js +8 -0
  50. package/lib/browser/isomorphic/grpc.node.d.ts +5 -0
  51. package/lib/{math → browser/math}/margin.d.ts +3 -3
  52. package/lib/{math → browser/math}/margin.js +10 -10
  53. package/lib/{math → browser/math}/market.d.ts +1 -1
  54. package/lib/{math → browser/math}/market.js +15 -3
  55. package/lib/{math → browser/math}/oracles.d.ts +1 -0
  56. package/lib/{oracles → browser/oracles}/prelaunchOracleClient.d.ts +1 -0
  57. package/lib/{oracles → browser/oracles}/pythClient.d.ts +1 -1
  58. package/lib/{oracles → browser/oracles}/pythClient.js +1 -2
  59. package/lib/{oracles → browser/oracles}/pythPullClient.d.ts +1 -0
  60. package/lib/{oracles → browser/oracles}/quoteAssetOracleClient.d.ts +1 -0
  61. package/lib/{oracles → browser/oracles}/switchboardClient.d.ts +1 -0
  62. package/lib/{oracles → browser/oracles}/switchboardOnDemandClient.d.ts +1 -0
  63. package/lib/{oracles → browser/oracles}/types.d.ts +1 -0
  64. package/lib/{orderSubscriber → browser/orderSubscriber}/OrderSubscriber.d.ts +3 -1
  65. package/lib/{orderSubscriber → browser/orderSubscriber}/OrderSubscriber.js +18 -13
  66. package/lib/browser/orderSubscriber/grpcSubscription.d.ts +22 -0
  67. package/lib/browser/orderSubscriber/grpcSubscription.js +66 -0
  68. package/lib/{orderSubscriber → browser/orderSubscriber}/types.d.ts +9 -0
  69. package/lib/{token → browser/token}/index.d.ts +1 -0
  70. package/lib/{tx → browser/tx}/baseTxSender.d.ts +4 -1
  71. package/lib/{tx → browser/tx}/baseTxSender.js +9 -4
  72. package/lib/{tx → browser/tx}/fastSingleTxSender.d.ts +3 -1
  73. package/lib/{tx → browser/tx}/fastSingleTxSender.js +4 -3
  74. package/lib/{tx → browser/tx}/forwardOnlyTxSender.d.ts +3 -1
  75. package/lib/{tx → browser/tx}/forwardOnlyTxSender.js +2 -1
  76. package/lib/{tx → browser/tx}/retryTxSender.d.ts +3 -1
  77. package/lib/{tx → browser/tx}/retryTxSender.js +3 -2
  78. package/lib/{tx → browser/tx}/types.d.ts +1 -0
  79. package/lib/{tx → browser/tx}/whileValidTxSender.d.ts +3 -1
  80. package/lib/{tx → browser/tx}/whileValidTxSender.js +3 -2
  81. package/lib/{types.d.ts → browser/types.d.ts} +41 -1
  82. package/lib/{types.js → browser/types.js} +11 -1
  83. package/lib/{user.d.ts → browser/user.d.ts} +2 -1
  84. package/lib/{user.js → browser/user.js} +25 -14
  85. package/lib/{userConfig.d.ts → browser/userConfig.d.ts} +6 -1
  86. package/lib/{userMap → browser/userMap}/WebsocketSubscription.d.ts +1 -0
  87. package/lib/browser/userMap/grpcSubscription.d.ts +24 -0
  88. package/lib/browser/userMap/grpcSubscription.js +40 -0
  89. package/lib/{userMap → browser/userMap}/userMap.js +17 -1
  90. package/lib/{userMap → browser/userMap}/userMapConfig.d.ts +6 -0
  91. package/lib/{userStats.js → browser/userStats.js} +11 -4
  92. package/lib/{userStatsConfig.d.ts → browser/userStatsConfig.d.ts} +6 -0
  93. package/lib/node/accounts/basicUserAccountSubscriber.d.ts +27 -0
  94. package/lib/node/accounts/basicUserAccountSubscriber.js +38 -0
  95. package/lib/node/accounts/bulkAccountLoader.d.ts +37 -0
  96. package/lib/node/accounts/bulkAccountLoader.js +222 -0
  97. package/lib/node/accounts/bulkUserStatsSubscription.d.ts +7 -0
  98. package/lib/node/accounts/bulkUserStatsSubscription.js +21 -0
  99. package/lib/node/accounts/bulkUserSubscription.d.ts +7 -0
  100. package/lib/node/accounts/bulkUserSubscription.js +21 -0
  101. package/lib/node/accounts/fetch.d.ts +6 -0
  102. package/lib/node/accounts/fetch.js +30 -0
  103. package/lib/node/accounts/grpcAccountSubscriber.d.ts +16 -0
  104. package/lib/node/accounts/grpcAccountSubscriber.js +154 -0
  105. package/lib/node/accounts/grpcDriftClientAccountSubscriber.d.ts +12 -0
  106. package/lib/node/accounts/grpcDriftClientAccountSubscriber.js +97 -0
  107. package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +10 -0
  108. package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.js +30 -0
  109. package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +18 -0
  110. package/lib/node/accounts/grpcProgramAccountSubscriber.js +171 -0
  111. package/lib/node/accounts/grpcUserAccountSubscriber.d.ts +10 -0
  112. package/lib/node/accounts/grpcUserAccountSubscriber.js +28 -0
  113. package/lib/node/accounts/grpcUserStatsAccountSubscriber.d.ts +10 -0
  114. package/lib/node/accounts/grpcUserStatsAccountSubscriber.js +28 -0
  115. package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts +18 -0
  116. package/lib/node/accounts/oneShotUserAccountSubscriber.js +48 -0
  117. package/lib/node/accounts/pollingDriftClientAccountSubscriber.d.ts +69 -0
  118. package/lib/node/accounts/pollingDriftClientAccountSubscriber.js +415 -0
  119. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +29 -0
  120. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +110 -0
  121. package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +27 -0
  122. package/lib/node/accounts/pollingOracleAccountSubscriber.js +78 -0
  123. package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +26 -0
  124. package/lib/node/accounts/pollingTokenAccountSubscriber.js +78 -0
  125. package/lib/node/accounts/pollingUserAccountSubscriber.d.ts +29 -0
  126. package/lib/node/accounts/pollingUserAccountSubscriber.js +102 -0
  127. package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
  128. package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +94 -0
  129. package/lib/node/accounts/testBulkAccountLoader.d.ts +4 -0
  130. package/lib/node/accounts/testBulkAccountLoader.js +45 -0
  131. package/lib/node/accounts/types.d.ts +155 -0
  132. package/lib/node/accounts/types.js +16 -0
  133. package/lib/node/accounts/utils.d.ts +8 -0
  134. package/lib/node/accounts/utils.js +39 -0
  135. package/lib/node/accounts/webSocketAccountSubscriber.d.ts +29 -0
  136. package/lib/node/accounts/webSocketAccountSubscriber.js +149 -0
  137. package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts +66 -0
  138. package/lib/node/accounts/webSocketDriftClientAccountSubscriber.js +352 -0
  139. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +23 -0
  140. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +67 -0
  141. package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +34 -0
  142. package/lib/node/accounts/webSocketProgramAccountSubscriber.js +127 -0
  143. package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +23 -0
  144. package/lib/node/accounts/webSocketUserAccountSubscriber.js +61 -0
  145. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +22 -0
  146. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.js +52 -0
  147. package/lib/node/addresses/marketAddresses.d.ts +2 -0
  148. package/lib/node/addresses/marketAddresses.js +15 -0
  149. package/lib/node/addresses/pda.d.ts +30 -0
  150. package/lib/node/addresses/pda.js +193 -0
  151. package/lib/node/adminClient.d.ts +202 -0
  152. package/lib/node/adminClient.js +1826 -0
  153. package/lib/node/assert/assert.d.ts +1 -0
  154. package/lib/node/assert/assert.js +9 -0
  155. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +14 -0
  156. package/lib/node/auctionSubscriber/auctionSubscriber.js +32 -0
  157. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +15 -0
  158. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +32 -0
  159. package/lib/node/auctionSubscriber/index.d.ts +3 -0
  160. package/lib/node/auctionSubscriber/index.js +19 -0
  161. package/lib/node/auctionSubscriber/types.d.ts +14 -0
  162. package/lib/node/auctionSubscriber/types.js +2 -0
  163. package/lib/node/bankrun/bankrunConnection.d.ts +74 -0
  164. package/lib/node/bankrun/bankrunConnection.js +318 -0
  165. package/lib/node/blockhashSubscriber/BlockhashSubscriber.d.ts +27 -0
  166. package/lib/node/blockhashSubscriber/BlockhashSubscriber.js +89 -0
  167. package/lib/node/blockhashSubscriber/index.d.ts +1 -0
  168. package/lib/node/blockhashSubscriber/index.js +17 -0
  169. package/lib/node/blockhashSubscriber/types.d.ts +7 -0
  170. package/lib/node/blockhashSubscriber/types.js +2 -0
  171. package/lib/node/clock/clockSubscriber.d.ts +31 -0
  172. package/lib/node/clock/clockSubscriber.js +80 -0
  173. package/lib/node/config.d.ts +58 -0
  174. package/lib/node/config.js +126 -0
  175. package/lib/node/constants/numericConstants.d.ts +71 -0
  176. package/lib/node/constants/numericConstants.js +75 -0
  177. package/lib/node/constants/perpMarkets.d.ts +19 -0
  178. package/lib/node/constants/perpMarkets.js +868 -0
  179. package/lib/node/constants/spotMarkets.d.ts +23 -0
  180. package/lib/node/constants/spotMarkets.js +361 -0
  181. package/lib/node/constants/txConstants.d.ts +1 -0
  182. package/lib/node/constants/txConstants.js +4 -0
  183. package/lib/node/decode/phoenix.d.ts +7 -0
  184. package/lib/node/decode/phoenix.js +159 -0
  185. package/lib/node/decode/user.d.ts +4 -0
  186. package/lib/node/decode/user.js +339 -0
  187. package/lib/node/dlob/DLOB.d.ts +166 -0
  188. package/lib/node/dlob/DLOB.js +1142 -0
  189. package/lib/node/dlob/DLOBApiClient.d.ts +14 -0
  190. package/lib/node/dlob/DLOBApiClient.js +34 -0
  191. package/lib/node/dlob/DLOBNode.d.ts +57 -0
  192. package/lib/node/dlob/DLOBNode.js +86 -0
  193. package/lib/node/dlob/DLOBOrders.d.ts +17 -0
  194. package/lib/node/dlob/DLOBOrders.js +40 -0
  195. package/lib/node/dlob/DLOBSubscriber.d.ts +54 -0
  196. package/lib/node/dlob/DLOBSubscriber.js +139 -0
  197. package/lib/node/dlob/NodeList.d.ts +27 -0
  198. package/lib/node/dlob/NodeList.js +141 -0
  199. package/lib/node/dlob/dlobIdl.json +248 -0
  200. package/lib/node/dlob/orderBookLevels.d.ts +72 -0
  201. package/lib/node/dlob/orderBookLevels.js +438 -0
  202. package/lib/node/dlob/types.d.ts +18 -0
  203. package/lib/node/dlob/types.js +2 -0
  204. package/lib/node/driftClient.d.ts +829 -0
  205. package/lib/node/driftClient.js +4496 -0
  206. package/lib/node/driftClientConfig.d.ts +49 -0
  207. package/lib/node/driftClientConfig.js +2 -0
  208. package/lib/node/events/eventList.d.ts +22 -0
  209. package/lib/node/events/eventList.js +80 -0
  210. package/lib/node/events/eventSubscriber.d.ts +46 -0
  211. package/lib/node/events/eventSubscriber.js +223 -0
  212. package/lib/node/events/eventsServerLogProvider.d.ts +21 -0
  213. package/lib/node/events/eventsServerLogProvider.js +121 -0
  214. package/lib/node/events/fetchLogs.d.ts +25 -0
  215. package/lib/node/events/fetchLogs.js +99 -0
  216. package/lib/node/events/parse.d.ts +6 -0
  217. package/lib/node/events/parse.js +106 -0
  218. package/lib/node/events/pollingLogProvider.d.ts +17 -0
  219. package/lib/node/events/pollingLogProvider.js +58 -0
  220. package/lib/node/events/sort.d.ts +2 -0
  221. package/lib/node/events/sort.js +24 -0
  222. package/lib/node/events/txEventCache.d.ts +24 -0
  223. package/lib/node/events/txEventCache.js +71 -0
  224. package/lib/node/events/types.d.ts +77 -0
  225. package/lib/node/events/types.js +30 -0
  226. package/lib/node/events/webSocketLogProvider.d.ts +24 -0
  227. package/lib/node/events/webSocketLogProvider.js +96 -0
  228. package/lib/node/factory/bigNum.d.ts +122 -0
  229. package/lib/node/factory/bigNum.js +457 -0
  230. package/lib/node/factory/oracleClient.d.ts +5 -0
  231. package/lib/node/factory/oracleClient.js +52 -0
  232. package/lib/node/idl/drift.json +13656 -0
  233. package/lib/node/idl/openbook.json +3854 -0
  234. package/lib/node/idl/pyth_solana_receiver.json +628 -0
  235. package/lib/node/idl/switchboard.json +8354 -0
  236. package/lib/node/idl/switchboard_on_demand_30.json +4541 -0
  237. package/lib/node/idl/token_faucet.json +142 -0
  238. package/lib/node/index.d.ts +120 -0
  239. package/lib/node/index.js +142 -0
  240. package/lib/node/isomorphic/grpc.browser.d.ts +1 -0
  241. package/lib/node/isomorphic/grpc.d.ts +1 -0
  242. package/lib/node/isomorphic/grpc.js +17 -0
  243. package/lib/node/isomorphic/grpc.node.d.ts +5 -0
  244. package/lib/node/isomorphic/grpc.node.js +17 -0
  245. package/lib/node/jupiter/jupiterClient.d.ts +296 -0
  246. package/lib/node/jupiter/jupiterClient.js +178 -0
  247. package/lib/node/keypair.d.ts +2 -0
  248. package/lib/node/keypair.js +28 -0
  249. package/lib/node/marinade/index.d.ts +12 -0
  250. package/lib/node/marinade/index.js +36 -0
  251. package/lib/node/marinade/types.d.ts +1963 -0
  252. package/lib/node/marinade/types.js +1965 -0
  253. package/lib/node/math/amm.d.ts +98 -0
  254. package/lib/node/math/amm.js +626 -0
  255. package/lib/node/math/auction.d.ts +23 -0
  256. package/lib/node/math/auction.js +127 -0
  257. package/lib/node/math/bankruptcy.d.ts +2 -0
  258. package/lib/node/math/bankruptcy.js +31 -0
  259. package/lib/node/math/conversion.d.ts +2 -0
  260. package/lib/node/math/conversion.js +11 -0
  261. package/lib/node/math/exchangeStatus.d.ts +6 -0
  262. package/lib/node/math/exchangeStatus.js +77 -0
  263. package/lib/node/math/fuel.d.ts +6 -0
  264. package/lib/node/math/fuel.js +55 -0
  265. package/lib/node/math/funding.d.ts +34 -0
  266. package/lib/node/math/funding.js +209 -0
  267. package/lib/node/math/insurance.d.ts +7 -0
  268. package/lib/node/math/insurance.js +73 -0
  269. package/lib/node/math/margin.d.ts +39 -0
  270. package/lib/node/math/margin.js +184 -0
  271. package/lib/node/math/market.d.ts +39 -0
  272. package/lib/node/math/market.js +163 -0
  273. package/lib/node/math/oracles.d.ts +14 -0
  274. package/lib/node/math/oracles.js +134 -0
  275. package/lib/node/math/orders.d.ts +23 -0
  276. package/lib/node/math/orders.js +216 -0
  277. package/lib/node/math/position.d.ts +54 -0
  278. package/lib/node/math/position.js +198 -0
  279. package/lib/node/math/repeg.d.ts +22 -0
  280. package/lib/node/math/repeg.js +164 -0
  281. package/lib/node/math/spotBalance.d.ts +83 -0
  282. package/lib/node/math/spotBalance.js +373 -0
  283. package/lib/node/math/spotMarket.d.ts +11 -0
  284. package/lib/node/math/spotMarket.js +49 -0
  285. package/lib/node/math/spotPosition.d.ts +19 -0
  286. package/lib/node/math/spotPosition.js +78 -0
  287. package/lib/node/math/state.d.ts +5 -0
  288. package/lib/node/math/state.js +30 -0
  289. package/lib/node/math/superStake.d.ts +167 -0
  290. package/lib/node/math/superStake.js +306 -0
  291. package/lib/node/math/tiers.d.ts +4 -0
  292. package/lib/node/math/tiers.js +52 -0
  293. package/lib/node/math/trade.d.ts +117 -0
  294. package/lib/node/math/trade.js +637 -0
  295. package/lib/node/math/utils.d.ts +23 -0
  296. package/lib/node/math/utils.js +112 -0
  297. package/lib/node/memcmp.d.ts +7 -0
  298. package/lib/node/memcmp.js +63 -0
  299. package/lib/node/openbook/openbookV2FulfillmentConfigMap.d.ts +10 -0
  300. package/lib/node/openbook/openbookV2FulfillmentConfigMap.js +17 -0
  301. package/lib/node/openbook/openbookV2Subscriber.d.ts +36 -0
  302. package/lib/node/openbook/openbookV2Subscriber.js +104 -0
  303. package/lib/node/oracles/oracleClientCache.d.ts +9 -0
  304. package/lib/node/oracles/oracleClientCache.js +19 -0
  305. package/lib/node/oracles/prelaunchOracleClient.d.ts +12 -0
  306. package/lib/node/oracles/prelaunchOracleClient.js +24 -0
  307. package/lib/node/oracles/pythClient.d.ts +14 -0
  308. package/lib/node/oracles/pythClient.js +51 -0
  309. package/lib/node/oracles/pythPullClient.d.ts +19 -0
  310. package/lib/node/oracles/pythPullClient.js +60 -0
  311. package/lib/node/oracles/quoteAssetOracleClient.d.ts +10 -0
  312. package/lib/node/oracles/quoteAssetOracleClient.js +21 -0
  313. package/lib/node/oracles/strictOraclePrice.d.ts +9 -0
  314. package/lib/node/oracles/strictOraclePrice.js +17 -0
  315. package/lib/node/oracles/switchboardClient.d.ts +12 -0
  316. package/lib/node/oracles/switchboardClient.js +40 -0
  317. package/lib/node/oracles/switchboardOnDemandClient.d.ts +12 -0
  318. package/lib/node/oracles/switchboardOnDemandClient.js +32 -0
  319. package/lib/node/oracles/types.d.ts +23 -0
  320. package/lib/node/oracles/types.js +2 -0
  321. package/lib/node/orderParams.d.ts +29 -0
  322. package/lib/node/orderParams.js +44 -0
  323. package/lib/node/orderSubscriber/OrderSubscriber.d.ts +42 -0
  324. package/lib/node/orderSubscriber/OrderSubscriber.js +170 -0
  325. package/lib/node/orderSubscriber/PollingSubscription.d.ts +12 -0
  326. package/lib/node/orderSubscriber/PollingSubscription.js +23 -0
  327. package/lib/node/orderSubscriber/WebsocketSubscription.d.ts +23 -0
  328. package/lib/node/orderSubscriber/WebsocketSubscription.js +67 -0
  329. package/lib/node/orderSubscriber/grpcSubscription.d.ts +22 -0
  330. package/lib/node/orderSubscriber/grpcSubscription.js +66 -0
  331. package/lib/node/orderSubscriber/index.d.ts +2 -0
  332. package/lib/{auctionSubscriber → node/orderSubscriber}/index.js +1 -1
  333. package/lib/node/orderSubscriber/types.d.ts +34 -0
  334. package/lib/node/orderSubscriber/types.js +2 -0
  335. package/lib/node/phoenix/phoenixFulfillmentConfigMap.d.ts +10 -0
  336. package/lib/node/phoenix/phoenixFulfillmentConfigMap.js +17 -0
  337. package/lib/node/phoenix/phoenixSubscriber.d.ts +41 -0
  338. package/lib/node/phoenix/phoenixSubscriber.js +152 -0
  339. package/lib/node/priorityFee/averageOverSlotsStrategy.d.ts +5 -0
  340. package/lib/node/priorityFee/averageOverSlotsStrategy.js +16 -0
  341. package/lib/node/priorityFee/averageStrategy.d.ts +5 -0
  342. package/lib/node/priorityFee/averageStrategy.js +11 -0
  343. package/lib/node/priorityFee/driftPriorityFeeMethod.d.ts +13 -0
  344. package/lib/node/priorityFee/driftPriorityFeeMethod.js +26 -0
  345. package/lib/node/priorityFee/ewmaStrategy.d.ts +11 -0
  346. package/lib/node/priorityFee/ewmaStrategy.js +33 -0
  347. package/lib/node/priorityFee/heliusPriorityFeeMethod.d.ts +20 -0
  348. package/lib/node/priorityFee/heliusPriorityFeeMethod.js +46 -0
  349. package/lib/node/priorityFee/index.d.ts +11 -0
  350. package/lib/node/priorityFee/index.js +27 -0
  351. package/lib/node/priorityFee/maxOverSlotsStrategy.d.ts +5 -0
  352. package/lib/node/priorityFee/maxOverSlotsStrategy.js +17 -0
  353. package/lib/node/priorityFee/maxStrategy.d.ts +7 -0
  354. package/lib/node/priorityFee/maxStrategy.js +9 -0
  355. package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +46 -0
  356. package/lib/node/priorityFee/priorityFeeSubscriber.js +188 -0
  357. package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +48 -0
  358. package/lib/node/priorityFee/priorityFeeSubscriberMap.js +88 -0
  359. package/lib/node/priorityFee/solanaPriorityFeeMethod.d.ts +6 -0
  360. package/lib/node/priorityFee/solanaPriorityFeeMethod.js +21 -0
  361. package/lib/node/priorityFee/types.d.ts +31 -0
  362. package/lib/node/priorityFee/types.js +10 -0
  363. package/lib/node/serum/serumFulfillmentConfigMap.d.ts +10 -0
  364. package/lib/node/serum/serumFulfillmentConfigMap.js +17 -0
  365. package/lib/node/serum/serumSubscriber.d.ts +32 -0
  366. package/lib/node/serum/serumSubscriber.js +107 -0
  367. package/lib/node/serum/types.d.ts +13 -0
  368. package/lib/node/serum/types.js +2 -0
  369. package/lib/node/slot/SlotSubscriber.d.ts +27 -0
  370. package/lib/node/slot/SlotSubscriber.js +71 -0
  371. package/lib/node/testClient.d.ts +8 -0
  372. package/lib/node/testClient.js +23 -0
  373. package/lib/node/token/index.d.ts +5 -0
  374. package/lib/node/token/index.js +15 -0
  375. package/lib/node/tokenFaucet.d.ts +41 -0
  376. package/lib/node/tokenFaucet.js +188 -0
  377. package/lib/node/tx/baseTxSender.d.ts +57 -0
  378. package/lib/node/tx/baseTxSender.js +293 -0
  379. package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.d.ts +8 -0
  380. package/lib/node/tx/blockhashFetcher/baseBlockhashFetcher.js +13 -0
  381. package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.d.ts +28 -0
  382. package/lib/node/tx/blockhashFetcher/cachedBlockhashFetcher.js +73 -0
  383. package/lib/node/tx/blockhashFetcher/types.d.ts +4 -0
  384. package/lib/node/tx/blockhashFetcher/types.js +2 -0
  385. package/lib/node/tx/fastSingleTxSender.d.ts +41 -0
  386. package/lib/node/tx/fastSingleTxSender.js +86 -0
  387. package/lib/node/tx/forwardOnlyTxSender.d.ts +37 -0
  388. package/lib/node/tx/forwardOnlyTxSender.js +92 -0
  389. package/lib/node/tx/priorityFeeCalculator.d.ts +44 -0
  390. package/lib/node/tx/priorityFeeCalculator.js +85 -0
  391. package/lib/node/tx/reportTransactionError.d.ts +20 -0
  392. package/lib/node/tx/reportTransactionError.js +103 -0
  393. package/lib/node/tx/retryTxSender.d.ts +37 -0
  394. package/lib/node/tx/retryTxSender.js +86 -0
  395. package/lib/node/tx/txHandler.d.ts +154 -0
  396. package/lib/node/tx/txHandler.js +453 -0
  397. package/lib/node/tx/txParamProcessor.d.ts +25 -0
  398. package/lib/node/tx/txParamProcessor.js +88 -0
  399. package/lib/node/tx/types.d.ts +29 -0
  400. package/lib/node/tx/types.js +20 -0
  401. package/lib/node/tx/utils.d.ts +2 -0
  402. package/lib/node/tx/utils.js +10 -0
  403. package/lib/node/tx/whileValidTxSender.d.ts +44 -0
  404. package/lib/node/tx/whileValidTxSender.js +166 -0
  405. package/lib/node/types.d.ts +1351 -0
  406. package/lib/node/types.js +347 -0
  407. package/lib/node/user.d.ts +411 -0
  408. package/lib/node/user.js +2161 -0
  409. package/lib/node/userConfig.d.ts +26 -0
  410. package/lib/node/userConfig.js +2 -0
  411. package/lib/node/userMap/PollingSubscription.d.ts +16 -0
  412. package/lib/node/userMap/PollingSubscription.js +30 -0
  413. package/lib/node/userMap/WebsocketSubscription.d.ts +25 -0
  414. package/lib/node/userMap/WebsocketSubscription.js +41 -0
  415. package/lib/node/userMap/grpcSubscription.d.ts +24 -0
  416. package/lib/node/userMap/grpcSubscription.js +40 -0
  417. package/lib/node/userMap/userMap.d.ts +88 -0
  418. package/lib/node/userMap/userMap.js +455 -0
  419. package/lib/node/userMap/userMapConfig.d.ts +37 -0
  420. package/lib/node/userMap/userMapConfig.js +2 -0
  421. package/lib/node/userMap/userStatsMap.d.ts +46 -0
  422. package/lib/node/userMap/userStatsMap.js +165 -0
  423. package/lib/node/userName.d.ts +5 -0
  424. package/lib/node/userName.js +21 -0
  425. package/lib/node/userStats.d.ts +19 -0
  426. package/lib/node/userStats.js +65 -0
  427. package/lib/node/userStatsConfig.d.ts +25 -0
  428. package/lib/node/userStatsConfig.js +2 -0
  429. package/lib/node/util/TransactionConfirmationManager.d.ts +16 -0
  430. package/lib/node/util/TransactionConfirmationManager.js +174 -0
  431. package/lib/node/util/chainClock.d.ts +17 -0
  432. package/lib/node/util/chainClock.js +29 -0
  433. package/lib/node/util/computeUnits.d.ts +8 -0
  434. package/lib/node/util/computeUnits.js +46 -0
  435. package/lib/node/util/promiseTimeout.d.ts +1 -0
  436. package/lib/node/util/promiseTimeout.js +14 -0
  437. package/lib/node/util/pythPullOracleUtils.d.ts +2 -0
  438. package/lib/node/util/pythPullOracleUtils.js +15 -0
  439. package/lib/node/util/tps.d.ts +2 -0
  440. package/lib/node/util/tps.js +16 -0
  441. package/lib/node/wallet.d.ts +11 -0
  442. package/lib/node/wallet.js +32 -0
  443. package/package.json +8 -4
  444. package/scripts/postbuild.js +61 -0
  445. package/src/accounts/grpcAccountSubscriber.ts +160 -0
  446. package/src/accounts/grpcDriftClientAccountSubscriber.ts +197 -0
  447. package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +56 -0
  448. package/src/accounts/grpcProgramAccountSubscriber.ts +190 -0
  449. package/src/accounts/grpcUserAccountSubscriber.ts +48 -0
  450. package/src/accounts/grpcUserStatsAccountSubscriber.ts +50 -0
  451. package/src/accounts/types.ts +8 -0
  452. package/src/accounts/webSocketAccountSubscriber.ts +1 -1
  453. package/src/accounts/webSocketDriftClientAccountSubscriber.ts +3 -3
  454. package/src/accounts/webSocketProgramAccountSubscriber.ts +1 -1
  455. package/src/addresses/pda.ts +22 -0
  456. package/src/adminClient.ts +114 -0
  457. package/src/auctionSubscriber/auctionSubscriberGrpc.ts +70 -0
  458. package/src/auctionSubscriber/index.ts +1 -0
  459. package/src/auctionSubscriber/types.ts +2 -0
  460. package/src/config.ts +12 -3
  461. package/src/constants/perpMarkets.ts +44 -2
  462. package/src/constants/spotMarkets.ts +2 -2
  463. package/src/decode/user.ts +11 -1
  464. package/src/driftClient.ts +309 -27
  465. package/src/driftClientConfig.ts +7 -1
  466. package/src/idl/drift.json +502 -6
  467. package/src/idl/switchboard_on_demand_30.json +195 -37
  468. package/src/index.ts +8 -0
  469. package/src/isomorphic/README.md +19 -0
  470. package/src/isomorphic/grpc.browser.ts +4 -0
  471. package/src/isomorphic/grpc.node.ts +23 -0
  472. package/src/isomorphic/grpc.ts +1 -0
  473. package/src/math/margin.ts +20 -12
  474. package/src/math/market.ts +19 -3
  475. package/src/oracles/pythClient.ts +1 -5
  476. package/src/orderSubscriber/OrderSubscriber.ts +14 -11
  477. package/src/orderSubscriber/grpcSubscription.ts +121 -0
  478. package/src/orderSubscriber/types.ts +10 -0
  479. package/src/tx/baseTxSender.ts +21 -13
  480. package/src/tx/fastSingleTxSender.ts +5 -2
  481. package/src/tx/forwardOnlyTxSender.ts +3 -0
  482. package/src/tx/retryTxSender.ts +4 -1
  483. package/src/tx/whileValidTxSender.ts +4 -1
  484. package/src/types.ts +44 -1
  485. package/src/user.ts +37 -10
  486. package/src/userConfig.ts +7 -1
  487. package/src/userMap/grpcSubscription.ts +78 -0
  488. package/src/userMap/userMap.ts +21 -2
  489. package/src/userMap/userMapConfig.ts +7 -0
  490. package/src/userStats.ts +11 -0
  491. package/src/userStatsConfig.ts +7 -0
  492. package/tsconfig.browser.json +13 -0
  493. package/tsconfig.json +1 -1
  494. /package/lib/{accounts → browser/accounts}/basicUserAccountSubscriber.d.ts +0 -0
  495. /package/lib/{accounts → browser/accounts}/basicUserAccountSubscriber.js +0 -0
  496. /package/lib/{accounts → browser/accounts}/bulkAccountLoader.js +0 -0
  497. /package/lib/{accounts → browser/accounts}/bulkUserStatsSubscription.d.ts +0 -0
  498. /package/lib/{accounts → browser/accounts}/bulkUserStatsSubscription.js +0 -0
  499. /package/lib/{accounts → browser/accounts}/bulkUserSubscription.d.ts +0 -0
  500. /package/lib/{accounts → browser/accounts}/bulkUserSubscription.js +0 -0
  501. /package/lib/{accounts → browser/accounts}/fetch.d.ts +0 -0
  502. /package/lib/{accounts → browser/accounts}/fetch.js +0 -0
  503. /package/lib/{accounts → browser/accounts}/oneShotUserAccountSubscriber.d.ts +0 -0
  504. /package/lib/{accounts → browser/accounts}/oneShotUserAccountSubscriber.js +0 -0
  505. /package/lib/{accounts → browser/accounts}/pollingDriftClientAccountSubscriber.d.ts +0 -0
  506. /package/lib/{accounts → browser/accounts}/pollingDriftClientAccountSubscriber.js +0 -0
  507. /package/lib/{accounts → browser/accounts}/pollingInsuranceFundStakeAccountSubscriber.d.ts +0 -0
  508. /package/lib/{accounts → browser/accounts}/pollingInsuranceFundStakeAccountSubscriber.js +0 -0
  509. /package/lib/{accounts → browser/accounts}/pollingOracleAccountSubscriber.d.ts +0 -0
  510. /package/lib/{accounts → browser/accounts}/pollingOracleAccountSubscriber.js +0 -0
  511. /package/lib/{accounts → browser/accounts}/pollingTokenAccountSubscriber.d.ts +0 -0
  512. /package/lib/{accounts → browser/accounts}/pollingTokenAccountSubscriber.js +0 -0
  513. /package/lib/{accounts → browser/accounts}/pollingUserAccountSubscriber.d.ts +0 -0
  514. /package/lib/{accounts → browser/accounts}/pollingUserAccountSubscriber.js +0 -0
  515. /package/lib/{accounts → browser/accounts}/pollingUserStatsAccountSubscriber.d.ts +0 -0
  516. /package/lib/{accounts → browser/accounts}/pollingUserStatsAccountSubscriber.js +0 -0
  517. /package/lib/{accounts → browser/accounts}/testBulkAccountLoader.d.ts +0 -0
  518. /package/lib/{accounts → browser/accounts}/testBulkAccountLoader.js +0 -0
  519. /package/lib/{accounts → browser/accounts}/types.js +0 -0
  520. /package/lib/{accounts → browser/accounts}/utils.d.ts +0 -0
  521. /package/lib/{accounts → browser/accounts}/utils.js +0 -0
  522. /package/lib/{accounts → browser/accounts}/webSocketAccountSubscriber.js +0 -0
  523. /package/lib/{accounts → browser/accounts}/webSocketDriftClientAccountSubscriber.js +0 -0
  524. /package/lib/{accounts → browser/accounts}/webSocketInsuranceFundStakeAccountSubscriber.d.ts +0 -0
  525. /package/lib/{accounts → browser/accounts}/webSocketInsuranceFundStakeAccountSubscriber.js +0 -0
  526. /package/lib/{accounts → browser/accounts}/webSocketProgramAccountSubscriber.js +0 -0
  527. /package/lib/{accounts → browser/accounts}/webSocketUserAccountSubscriber.d.ts +0 -0
  528. /package/lib/{accounts → browser/accounts}/webSocketUserAccountSubscriber.js +0 -0
  529. /package/lib/{accounts → browser/accounts}/webSocketUserStatsAccountSubsriber.d.ts +0 -0
  530. /package/lib/{accounts → browser/accounts}/webSocketUserStatsAccountSubsriber.js +0 -0
  531. /package/lib/{addresses → browser/addresses}/marketAddresses.d.ts +0 -0
  532. /package/lib/{addresses → browser/addresses}/marketAddresses.js +0 -0
  533. /package/lib/{assert → browser/assert}/assert.d.ts +0 -0
  534. /package/lib/{assert → browser/assert}/assert.js +0 -0
  535. /package/lib/{auctionSubscriber → browser/auctionSubscriber}/auctionSubscriber.d.ts +0 -0
  536. /package/lib/{auctionSubscriber → browser/auctionSubscriber}/auctionSubscriber.js +0 -0
  537. /package/lib/{auctionSubscriber → browser/auctionSubscriber}/types.js +0 -0
  538. /package/lib/{bankrun → browser/bankrun}/bankrunConnection.js +0 -0
  539. /package/lib/{blockhashSubscriber → browser/blockhashSubscriber}/BlockhashSubscriber.d.ts +0 -0
  540. /package/lib/{blockhashSubscriber → browser/blockhashSubscriber}/BlockhashSubscriber.js +0 -0
  541. /package/lib/{blockhashSubscriber → browser/blockhashSubscriber}/index.d.ts +0 -0
  542. /package/lib/{blockhashSubscriber → browser/blockhashSubscriber}/index.js +0 -0
  543. /package/lib/{blockhashSubscriber → browser/blockhashSubscriber}/types.d.ts +0 -0
  544. /package/lib/{blockhashSubscriber → browser/blockhashSubscriber}/types.js +0 -0
  545. /package/lib/{clock → browser/clock}/clockSubscriber.d.ts +0 -0
  546. /package/lib/{clock → browser/clock}/clockSubscriber.js +0 -0
  547. /package/lib/{constants → browser/constants}/numericConstants.d.ts +0 -0
  548. /package/lib/{constants → browser/constants}/numericConstants.js +0 -0
  549. /package/lib/{constants → browser/constants}/perpMarkets.d.ts +0 -0
  550. /package/lib/{constants → browser/constants}/spotMarkets.d.ts +0 -0
  551. /package/lib/{constants → browser/constants}/txConstants.d.ts +0 -0
  552. /package/lib/{constants → browser/constants}/txConstants.js +0 -0
  553. /package/lib/{decode → browser/decode}/phoenix.js +0 -0
  554. /package/lib/{dlob → browser/dlob}/DLOB.d.ts +0 -0
  555. /package/lib/{dlob → browser/dlob}/DLOB.js +0 -0
  556. /package/lib/{dlob → browser/dlob}/DLOBApiClient.d.ts +0 -0
  557. /package/lib/{dlob → browser/dlob}/DLOBApiClient.js +0 -0
  558. /package/lib/{dlob → browser/dlob}/DLOBNode.d.ts +0 -0
  559. /package/lib/{dlob → browser/dlob}/DLOBNode.js +0 -0
  560. /package/lib/{dlob → browser/dlob}/DLOBOrders.js +0 -0
  561. /package/lib/{dlob → browser/dlob}/DLOBSubscriber.d.ts +0 -0
  562. /package/lib/{dlob → browser/dlob}/DLOBSubscriber.js +0 -0
  563. /package/lib/{dlob → browser/dlob}/NodeList.d.ts +0 -0
  564. /package/lib/{dlob → browser/dlob}/NodeList.js +0 -0
  565. /package/lib/{dlob → browser/dlob}/dlobIdl.json +0 -0
  566. /package/lib/{dlob → browser/dlob}/orderBookLevels.d.ts +0 -0
  567. /package/lib/{dlob → browser/dlob}/orderBookLevels.js +0 -0
  568. /package/lib/{dlob → browser/dlob}/types.d.ts +0 -0
  569. /package/lib/{dlob → browser/dlob}/types.js +0 -0
  570. /package/lib/{driftClientConfig.js → browser/driftClientConfig.js} +0 -0
  571. /package/lib/{events → browser/events}/eventList.d.ts +0 -0
  572. /package/lib/{events → browser/events}/eventList.js +0 -0
  573. /package/lib/{events → browser/events}/eventSubscriber.d.ts +0 -0
  574. /package/lib/{events → browser/events}/eventSubscriber.js +0 -0
  575. /package/lib/{events → browser/events}/eventsServerLogProvider.d.ts +0 -0
  576. /package/lib/{events → browser/events}/eventsServerLogProvider.js +0 -0
  577. /package/lib/{events → browser/events}/fetchLogs.d.ts +0 -0
  578. /package/lib/{events → browser/events}/fetchLogs.js +0 -0
  579. /package/lib/{events → browser/events}/parse.d.ts +0 -0
  580. /package/lib/{events → browser/events}/parse.js +0 -0
  581. /package/lib/{events → browser/events}/pollingLogProvider.d.ts +0 -0
  582. /package/lib/{events → browser/events}/pollingLogProvider.js +0 -0
  583. /package/lib/{events → browser/events}/sort.d.ts +0 -0
  584. /package/lib/{events → browser/events}/sort.js +0 -0
  585. /package/lib/{events → browser/events}/txEventCache.d.ts +0 -0
  586. /package/lib/{events → browser/events}/txEventCache.js +0 -0
  587. /package/lib/{events → browser/events}/types.d.ts +0 -0
  588. /package/lib/{events → browser/events}/types.js +0 -0
  589. /package/lib/{events → browser/events}/webSocketLogProvider.d.ts +0 -0
  590. /package/lib/{events → browser/events}/webSocketLogProvider.js +0 -0
  591. /package/lib/{factory → browser/factory}/bigNum.d.ts +0 -0
  592. /package/lib/{factory → browser/factory}/bigNum.js +0 -0
  593. /package/lib/{factory → browser/factory}/oracleClient.d.ts +0 -0
  594. /package/lib/{factory → browser/factory}/oracleClient.js +0 -0
  595. /package/lib/{idl → browser/idl}/openbook.json +0 -0
  596. /package/lib/{idl → browser/idl}/pyth_solana_receiver.json +0 -0
  597. /package/lib/{idl → browser/idl}/switchboard.json +0 -0
  598. /package/lib/{idl → browser/idl}/token_faucet.json +0 -0
  599. /package/lib/{jupiter → browser/jupiter}/jupiterClient.d.ts +0 -0
  600. /package/lib/{jupiter → browser/jupiter}/jupiterClient.js +0 -0
  601. /package/lib/{keypair.d.ts → browser/keypair.d.ts} +0 -0
  602. /package/lib/{keypair.js → browser/keypair.js} +0 -0
  603. /package/lib/{marinade → browser/marinade}/index.d.ts +0 -0
  604. /package/lib/{marinade → browser/marinade}/index.js +0 -0
  605. /package/lib/{marinade → browser/marinade}/types.d.ts +0 -0
  606. /package/lib/{marinade → browser/marinade}/types.js +0 -0
  607. /package/lib/{math → browser/math}/amm.d.ts +0 -0
  608. /package/lib/{math → browser/math}/amm.js +0 -0
  609. /package/lib/{math → browser/math}/auction.d.ts +0 -0
  610. /package/lib/{math → browser/math}/auction.js +0 -0
  611. /package/lib/{math → browser/math}/bankruptcy.d.ts +0 -0
  612. /package/lib/{math → browser/math}/bankruptcy.js +0 -0
  613. /package/lib/{math → browser/math}/conversion.d.ts +0 -0
  614. /package/lib/{math → browser/math}/conversion.js +0 -0
  615. /package/lib/{math → browser/math}/exchangeStatus.d.ts +0 -0
  616. /package/lib/{math → browser/math}/exchangeStatus.js +0 -0
  617. /package/lib/{math → browser/math}/fuel.d.ts +0 -0
  618. /package/lib/{math → browser/math}/fuel.js +0 -0
  619. /package/lib/{math → browser/math}/funding.d.ts +0 -0
  620. /package/lib/{math → browser/math}/funding.js +0 -0
  621. /package/lib/{math → browser/math}/insurance.d.ts +0 -0
  622. /package/lib/{math → browser/math}/insurance.js +0 -0
  623. /package/lib/{math → browser/math}/oracles.js +0 -0
  624. /package/lib/{math → browser/math}/orders.d.ts +0 -0
  625. /package/lib/{math → browser/math}/orders.js +0 -0
  626. /package/lib/{math → browser/math}/position.d.ts +0 -0
  627. /package/lib/{math → browser/math}/position.js +0 -0
  628. /package/lib/{math → browser/math}/repeg.d.ts +0 -0
  629. /package/lib/{math → browser/math}/repeg.js +0 -0
  630. /package/lib/{math → browser/math}/spotBalance.d.ts +0 -0
  631. /package/lib/{math → browser/math}/spotBalance.js +0 -0
  632. /package/lib/{math → browser/math}/spotMarket.d.ts +0 -0
  633. /package/lib/{math → browser/math}/spotMarket.js +0 -0
  634. /package/lib/{math → browser/math}/spotPosition.d.ts +0 -0
  635. /package/lib/{math → browser/math}/spotPosition.js +0 -0
  636. /package/lib/{math → browser/math}/state.d.ts +0 -0
  637. /package/lib/{math → browser/math}/state.js +0 -0
  638. /package/lib/{math → browser/math}/superStake.d.ts +0 -0
  639. /package/lib/{math → browser/math}/superStake.js +0 -0
  640. /package/lib/{math → browser/math}/tiers.d.ts +0 -0
  641. /package/lib/{math → browser/math}/tiers.js +0 -0
  642. /package/lib/{math → browser/math}/trade.d.ts +0 -0
  643. /package/lib/{math → browser/math}/trade.js +0 -0
  644. /package/lib/{math → browser/math}/utils.d.ts +0 -0
  645. /package/lib/{math → browser/math}/utils.js +0 -0
  646. /package/lib/{memcmp.d.ts → browser/memcmp.d.ts} +0 -0
  647. /package/lib/{memcmp.js → browser/memcmp.js} +0 -0
  648. /package/lib/{openbook → browser/openbook}/openbookV2FulfillmentConfigMap.d.ts +0 -0
  649. /package/lib/{openbook → browser/openbook}/openbookV2FulfillmentConfigMap.js +0 -0
  650. /package/lib/{openbook → browser/openbook}/openbookV2Subscriber.d.ts +0 -0
  651. /package/lib/{openbook → browser/openbook}/openbookV2Subscriber.js +0 -0
  652. /package/lib/{oracles → browser/oracles}/oracleClientCache.d.ts +0 -0
  653. /package/lib/{oracles → browser/oracles}/oracleClientCache.js +0 -0
  654. /package/lib/{oracles → browser/oracles}/prelaunchOracleClient.js +0 -0
  655. /package/lib/{oracles → browser/oracles}/pythPullClient.js +0 -0
  656. /package/lib/{oracles → browser/oracles}/quoteAssetOracleClient.js +0 -0
  657. /package/lib/{oracles → browser/oracles}/strictOraclePrice.d.ts +0 -0
  658. /package/lib/{oracles → browser/oracles}/strictOraclePrice.js +0 -0
  659. /package/lib/{oracles → browser/oracles}/switchboardClient.js +0 -0
  660. /package/lib/{oracles → browser/oracles}/switchboardOnDemandClient.js +0 -0
  661. /package/lib/{oracles → browser/oracles}/types.js +0 -0
  662. /package/lib/{orderParams.d.ts → browser/orderParams.d.ts} +0 -0
  663. /package/lib/{orderParams.js → browser/orderParams.js} +0 -0
  664. /package/lib/{orderSubscriber → browser/orderSubscriber}/PollingSubscription.d.ts +0 -0
  665. /package/lib/{orderSubscriber → browser/orderSubscriber}/PollingSubscription.js +0 -0
  666. /package/lib/{orderSubscriber → browser/orderSubscriber}/WebsocketSubscription.d.ts +0 -0
  667. /package/lib/{orderSubscriber → browser/orderSubscriber}/WebsocketSubscription.js +0 -0
  668. /package/lib/{orderSubscriber → browser/orderSubscriber}/index.d.ts +0 -0
  669. /package/lib/{orderSubscriber → browser/orderSubscriber}/index.js +0 -0
  670. /package/lib/{orderSubscriber → browser/orderSubscriber}/types.js +0 -0
  671. /package/lib/{phoenix → browser/phoenix}/phoenixFulfillmentConfigMap.d.ts +0 -0
  672. /package/lib/{phoenix → browser/phoenix}/phoenixFulfillmentConfigMap.js +0 -0
  673. /package/lib/{phoenix → browser/phoenix}/phoenixSubscriber.d.ts +0 -0
  674. /package/lib/{phoenix → browser/phoenix}/phoenixSubscriber.js +0 -0
  675. /package/lib/{priorityFee → browser/priorityFee}/averageOverSlotsStrategy.d.ts +0 -0
  676. /package/lib/{priorityFee → browser/priorityFee}/averageOverSlotsStrategy.js +0 -0
  677. /package/lib/{priorityFee → browser/priorityFee}/averageStrategy.d.ts +0 -0
  678. /package/lib/{priorityFee → browser/priorityFee}/averageStrategy.js +0 -0
  679. /package/lib/{priorityFee → browser/priorityFee}/driftPriorityFeeMethod.d.ts +0 -0
  680. /package/lib/{priorityFee → browser/priorityFee}/driftPriorityFeeMethod.js +0 -0
  681. /package/lib/{priorityFee → browser/priorityFee}/ewmaStrategy.d.ts +0 -0
  682. /package/lib/{priorityFee → browser/priorityFee}/ewmaStrategy.js +0 -0
  683. /package/lib/{priorityFee → browser/priorityFee}/heliusPriorityFeeMethod.d.ts +0 -0
  684. /package/lib/{priorityFee → browser/priorityFee}/heliusPriorityFeeMethod.js +0 -0
  685. /package/lib/{priorityFee → browser/priorityFee}/index.d.ts +0 -0
  686. /package/lib/{priorityFee → browser/priorityFee}/index.js +0 -0
  687. /package/lib/{priorityFee → browser/priorityFee}/maxOverSlotsStrategy.d.ts +0 -0
  688. /package/lib/{priorityFee → browser/priorityFee}/maxOverSlotsStrategy.js +0 -0
  689. /package/lib/{priorityFee → browser/priorityFee}/maxStrategy.d.ts +0 -0
  690. /package/lib/{priorityFee → browser/priorityFee}/maxStrategy.js +0 -0
  691. /package/lib/{priorityFee → browser/priorityFee}/priorityFeeSubscriber.d.ts +0 -0
  692. /package/lib/{priorityFee → browser/priorityFee}/priorityFeeSubscriber.js +0 -0
  693. /package/lib/{priorityFee → browser/priorityFee}/priorityFeeSubscriberMap.d.ts +0 -0
  694. /package/lib/{priorityFee → browser/priorityFee}/priorityFeeSubscriberMap.js +0 -0
  695. /package/lib/{priorityFee → browser/priorityFee}/solanaPriorityFeeMethod.d.ts +0 -0
  696. /package/lib/{priorityFee → browser/priorityFee}/solanaPriorityFeeMethod.js +0 -0
  697. /package/lib/{priorityFee → browser/priorityFee}/types.d.ts +0 -0
  698. /package/lib/{priorityFee → browser/priorityFee}/types.js +0 -0
  699. /package/lib/{serum → browser/serum}/serumFulfillmentConfigMap.d.ts +0 -0
  700. /package/lib/{serum → browser/serum}/serumFulfillmentConfigMap.js +0 -0
  701. /package/lib/{serum → browser/serum}/serumSubscriber.d.ts +0 -0
  702. /package/lib/{serum → browser/serum}/serumSubscriber.js +0 -0
  703. /package/lib/{serum → browser/serum}/types.d.ts +0 -0
  704. /package/lib/{serum → browser/serum}/types.js +0 -0
  705. /package/lib/{slot → browser/slot}/SlotSubscriber.d.ts +0 -0
  706. /package/lib/{slot → browser/slot}/SlotSubscriber.js +0 -0
  707. /package/lib/{testClient.d.ts → browser/testClient.d.ts} +0 -0
  708. /package/lib/{testClient.js → browser/testClient.js} +0 -0
  709. /package/lib/{token → browser/token}/index.js +0 -0
  710. /package/lib/{tokenFaucet.d.ts → browser/tokenFaucet.d.ts} +0 -0
  711. /package/lib/{tokenFaucet.js → browser/tokenFaucet.js} +0 -0
  712. /package/lib/{tx → browser/tx}/blockhashFetcher/baseBlockhashFetcher.d.ts +0 -0
  713. /package/lib/{tx → browser/tx}/blockhashFetcher/baseBlockhashFetcher.js +0 -0
  714. /package/lib/{tx → browser/tx}/blockhashFetcher/cachedBlockhashFetcher.d.ts +0 -0
  715. /package/lib/{tx → browser/tx}/blockhashFetcher/cachedBlockhashFetcher.js +0 -0
  716. /package/lib/{tx → browser/tx}/blockhashFetcher/types.d.ts +0 -0
  717. /package/lib/{tx → browser/tx}/blockhashFetcher/types.js +0 -0
  718. /package/lib/{tx → browser/tx}/priorityFeeCalculator.d.ts +0 -0
  719. /package/lib/{tx → browser/tx}/priorityFeeCalculator.js +0 -0
  720. /package/lib/{tx → browser/tx}/reportTransactionError.d.ts +0 -0
  721. /package/lib/{tx → browser/tx}/reportTransactionError.js +0 -0
  722. /package/lib/{tx → browser/tx}/txHandler.d.ts +0 -0
  723. /package/lib/{tx → browser/tx}/txHandler.js +0 -0
  724. /package/lib/{tx → browser/tx}/txParamProcessor.d.ts +0 -0
  725. /package/lib/{tx → browser/tx}/txParamProcessor.js +0 -0
  726. /package/lib/{tx → browser/tx}/types.js +0 -0
  727. /package/lib/{tx → browser/tx}/utils.d.ts +0 -0
  728. /package/lib/{tx → browser/tx}/utils.js +0 -0
  729. /package/lib/{userConfig.js → browser/userConfig.js} +0 -0
  730. /package/lib/{userMap → browser/userMap}/PollingSubscription.d.ts +0 -0
  731. /package/lib/{userMap → browser/userMap}/PollingSubscription.js +0 -0
  732. /package/lib/{userMap → browser/userMap}/WebsocketSubscription.js +0 -0
  733. /package/lib/{userMap → browser/userMap}/userMap.d.ts +0 -0
  734. /package/lib/{userMap → browser/userMap}/userMapConfig.js +0 -0
  735. /package/lib/{userMap → browser/userMap}/userStatsMap.d.ts +0 -0
  736. /package/lib/{userMap → browser/userMap}/userStatsMap.js +0 -0
  737. /package/lib/{userName.d.ts → browser/userName.d.ts} +0 -0
  738. /package/lib/{userName.js → browser/userName.js} +0 -0
  739. /package/lib/{userStats.d.ts → browser/userStats.d.ts} +0 -0
  740. /package/lib/{userStatsConfig.js → browser/userStatsConfig.js} +0 -0
  741. /package/lib/{util → browser/util}/TransactionConfirmationManager.d.ts +0 -0
  742. /package/lib/{util → browser/util}/TransactionConfirmationManager.js +0 -0
  743. /package/lib/{util → browser/util}/chainClock.d.ts +0 -0
  744. /package/lib/{util → browser/util}/chainClock.js +0 -0
  745. /package/lib/{util → browser/util}/computeUnits.d.ts +0 -0
  746. /package/lib/{util → browser/util}/computeUnits.js +0 -0
  747. /package/lib/{util → browser/util}/promiseTimeout.d.ts +0 -0
  748. /package/lib/{util → browser/util}/promiseTimeout.js +0 -0
  749. /package/lib/{util → browser/util}/pythPullOracleUtils.d.ts +0 -0
  750. /package/lib/{util → browser/util}/pythPullOracleUtils.js +0 -0
  751. /package/lib/{util → browser/util}/tps.d.ts +0 -0
  752. /package/lib/{util → browser/util}/tps.js +0 -0
  753. /package/lib/{wallet.d.ts → browser/wallet.d.ts} +0 -0
  754. /package/lib/{wallet.js → browser/wallet.js} +0 -0
@@ -0,0 +1,637 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUser30dRollingVolumeEstimate = exports.calculateEstimatedEntryPriceWithL2 = exports.calculateEstimatedSpotEntryPrice = exports.calculateEstimatedPerpEntryPrice = exports.calculateTargetPriceTrade = exports.calculateTradeAcquiredAmounts = exports.calculateTradeSlippage = void 0;
4
+ const types_1 = require("../types");
5
+ const anchor_1 = require("@coral-xyz/anchor");
6
+ const assert_1 = require("../assert/assert");
7
+ const numericConstants_1 = require("../constants/numericConstants");
8
+ const market_1 = require("./market");
9
+ const amm_1 = require("./amm");
10
+ const utils_1 = require("./utils");
11
+ const types_2 = require("../types");
12
+ const MAXPCT = new anchor_1.BN(1000); //percentage units are [0,1000] => [0,1]
13
+ /**
14
+ * Calculates avg/max slippage (price impact) for candidate trade
15
+ *
16
+ * @deprecated use calculateEstimatedPerpEntryPrice instead
17
+ *
18
+ * @param direction
19
+ * @param amount
20
+ * @param market
21
+ * @param inputAssetType which asset is being traded
22
+ * @param useSpread whether to consider spread with calculating slippage
23
+ * @return [pctAvgSlippage, pctMaxSlippage, entryPrice, newPrice]
24
+ *
25
+ * 'pctAvgSlippage' => the percentage change to entryPrice (average est slippage in execution) : Precision PRICE_PRECISION
26
+ *
27
+ * 'pctMaxSlippage' => the percentage change to maxPrice (highest est slippage in execution) : Precision PRICE_PRECISION
28
+ *
29
+ * 'entryPrice' => the average price of the trade : Precision PRICE_PRECISION
30
+ *
31
+ * 'newPrice' => the price of the asset after the trade : Precision PRICE_PRECISION
32
+ */
33
+ function calculateTradeSlippage(direction, amount, market, inputAssetType = 'quote', oraclePriceData, useSpread = true) {
34
+ let oldPrice;
35
+ if (useSpread && market.amm.baseSpread > 0) {
36
+ if ((0, types_2.isVariant)(direction, 'long')) {
37
+ oldPrice = (0, market_1.calculateAskPrice)(market, oraclePriceData);
38
+ }
39
+ else {
40
+ oldPrice = (0, market_1.calculateBidPrice)(market, oraclePriceData);
41
+ }
42
+ }
43
+ else {
44
+ oldPrice = (0, market_1.calculateReservePrice)(market, oraclePriceData);
45
+ }
46
+ if (amount.eq(numericConstants_1.ZERO)) {
47
+ return [numericConstants_1.ZERO, numericConstants_1.ZERO, oldPrice, oldPrice];
48
+ }
49
+ const [acquiredBaseReserve, acquiredQuoteReserve, acquiredQuoteAssetAmount] = calculateTradeAcquiredAmounts(direction, amount, market, inputAssetType, oraclePriceData, useSpread);
50
+ const entryPrice = acquiredQuoteAssetAmount
51
+ .mul(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
52
+ .mul(numericConstants_1.PRICE_PRECISION)
53
+ .div(acquiredBaseReserve.abs());
54
+ let amm;
55
+ if (useSpread && market.amm.baseSpread > 0) {
56
+ const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, direction, oraclePriceData);
57
+ amm = {
58
+ baseAssetReserve,
59
+ quoteAssetReserve,
60
+ sqrtK: sqrtK,
61
+ pegMultiplier: newPeg,
62
+ };
63
+ }
64
+ else {
65
+ amm = market.amm;
66
+ }
67
+ const newPrice = (0, amm_1.calculatePrice)(amm.baseAssetReserve.sub(acquiredBaseReserve), amm.quoteAssetReserve.sub(acquiredQuoteReserve), amm.pegMultiplier);
68
+ if (direction == types_1.PositionDirection.SHORT) {
69
+ (0, assert_1.assert)(newPrice.lte(oldPrice));
70
+ }
71
+ else {
72
+ (0, assert_1.assert)(oldPrice.lte(newPrice));
73
+ }
74
+ const pctMaxSlippage = newPrice
75
+ .sub(oldPrice)
76
+ .mul(numericConstants_1.PRICE_PRECISION)
77
+ .div(oldPrice)
78
+ .abs();
79
+ const pctAvgSlippage = entryPrice
80
+ .sub(oldPrice)
81
+ .mul(numericConstants_1.PRICE_PRECISION)
82
+ .div(oldPrice)
83
+ .abs();
84
+ return [pctAvgSlippage, pctMaxSlippage, entryPrice, newPrice];
85
+ }
86
+ exports.calculateTradeSlippage = calculateTradeSlippage;
87
+ /**
88
+ * Calculates acquired amounts for trade executed
89
+ * @param direction
90
+ * @param amount
91
+ * @param market
92
+ * @param inputAssetType
93
+ * @param useSpread
94
+ * @return
95
+ * | 'acquiredBase' => positive/negative change in user's base : BN AMM_RESERVE_PRECISION
96
+ * | 'acquiredQuote' => positive/negative change in user's quote : BN TODO-PRECISION
97
+ */
98
+ function calculateTradeAcquiredAmounts(direction, amount, market, inputAssetType = 'quote', oraclePriceData, useSpread = true) {
99
+ if (amount.eq(numericConstants_1.ZERO)) {
100
+ return [numericConstants_1.ZERO, numericConstants_1.ZERO, numericConstants_1.ZERO];
101
+ }
102
+ const swapDirection = (0, amm_1.getSwapDirection)(inputAssetType, direction);
103
+ let amm;
104
+ if (useSpread && market.amm.baseSpread > 0) {
105
+ const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, direction, oraclePriceData);
106
+ amm = {
107
+ baseAssetReserve,
108
+ quoteAssetReserve,
109
+ sqrtK: sqrtK,
110
+ pegMultiplier: newPeg,
111
+ };
112
+ }
113
+ else {
114
+ amm = market.amm;
115
+ }
116
+ const [newQuoteAssetReserve, newBaseAssetReserve] = (0, amm_1.calculateAmmReservesAfterSwap)(amm, inputAssetType, amount, swapDirection);
117
+ const acquiredBase = amm.baseAssetReserve.sub(newBaseAssetReserve);
118
+ const acquiredQuote = amm.quoteAssetReserve.sub(newQuoteAssetReserve);
119
+ const acquiredQuoteAssetAmount = (0, amm_1.calculateQuoteAssetAmountSwapped)(acquiredQuote.abs(), amm.pegMultiplier, swapDirection);
120
+ return [acquiredBase, acquiredQuote, acquiredQuoteAssetAmount];
121
+ }
122
+ exports.calculateTradeAcquiredAmounts = calculateTradeAcquiredAmounts;
123
+ /**
124
+ * calculateTargetPriceTrade
125
+ * simple function for finding arbitraging trades
126
+ *
127
+ * @deprecated
128
+ *
129
+ * @param market
130
+ * @param targetPrice
131
+ * @param pct optional default is 100% gap filling, can set smaller.
132
+ * @param outputAssetType which asset to trade.
133
+ * @param useSpread whether or not to consider the spread when calculating the trade size
134
+ * @returns trade direction/size in order to push price to a targetPrice,
135
+ *
136
+ * [
137
+ * direction => direction of trade required, PositionDirection
138
+ * tradeSize => size of trade required, TODO-PRECISION
139
+ * entryPrice => the entry price for the trade, PRICE_PRECISION
140
+ * targetPrice => the target price PRICE_PRECISION
141
+ * ]
142
+ */
143
+ function calculateTargetPriceTrade(market, targetPrice, pct = MAXPCT, outputAssetType = 'quote', oraclePriceData, useSpread = true) {
144
+ (0, assert_1.assert)(market.amm.baseAssetReserve.gt(numericConstants_1.ZERO));
145
+ (0, assert_1.assert)(targetPrice.gt(numericConstants_1.ZERO));
146
+ (0, assert_1.assert)(pct.lte(MAXPCT) && pct.gt(numericConstants_1.ZERO));
147
+ const reservePriceBefore = (0, market_1.calculateReservePrice)(market, oraclePriceData);
148
+ const bidPriceBefore = (0, market_1.calculateBidPrice)(market, oraclePriceData);
149
+ const askPriceBefore = (0, market_1.calculateAskPrice)(market, oraclePriceData);
150
+ let direction;
151
+ if (targetPrice.gt(reservePriceBefore)) {
152
+ const priceGap = targetPrice.sub(reservePriceBefore);
153
+ const priceGapScaled = priceGap.mul(pct).div(MAXPCT);
154
+ targetPrice = reservePriceBefore.add(priceGapScaled);
155
+ direction = types_1.PositionDirection.LONG;
156
+ }
157
+ else {
158
+ const priceGap = reservePriceBefore.sub(targetPrice);
159
+ const priceGapScaled = priceGap.mul(pct).div(MAXPCT);
160
+ targetPrice = reservePriceBefore.sub(priceGapScaled);
161
+ direction = types_1.PositionDirection.SHORT;
162
+ }
163
+ let tradeSize;
164
+ let baseSize;
165
+ let baseAssetReserveBefore;
166
+ let quoteAssetReserveBefore;
167
+ let peg = market.amm.pegMultiplier;
168
+ if (useSpread && market.amm.baseSpread > 0) {
169
+ const { baseAssetReserve, quoteAssetReserve, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, direction, oraclePriceData);
170
+ baseAssetReserveBefore = baseAssetReserve;
171
+ quoteAssetReserveBefore = quoteAssetReserve;
172
+ peg = newPeg;
173
+ }
174
+ else {
175
+ baseAssetReserveBefore = market.amm.baseAssetReserve;
176
+ quoteAssetReserveBefore = market.amm.quoteAssetReserve;
177
+ }
178
+ const invariant = market.amm.sqrtK.mul(market.amm.sqrtK);
179
+ const k = invariant.mul(numericConstants_1.PRICE_PRECISION);
180
+ let baseAssetReserveAfter;
181
+ let quoteAssetReserveAfter;
182
+ const biasModifier = new anchor_1.BN(1);
183
+ let markPriceAfter;
184
+ if (useSpread &&
185
+ targetPrice.lt(askPriceBefore) &&
186
+ targetPrice.gt(bidPriceBefore)) {
187
+ // no trade, market is at target
188
+ if (reservePriceBefore.gt(targetPrice)) {
189
+ direction = types_1.PositionDirection.SHORT;
190
+ }
191
+ else {
192
+ direction = types_1.PositionDirection.LONG;
193
+ }
194
+ tradeSize = numericConstants_1.ZERO;
195
+ return [direction, tradeSize, targetPrice, targetPrice];
196
+ }
197
+ else if (reservePriceBefore.gt(targetPrice)) {
198
+ // overestimate y2
199
+ baseAssetReserveAfter = (0, utils_1.squareRootBN)(k.div(targetPrice).mul(peg).div(numericConstants_1.PEG_PRECISION).sub(biasModifier)).sub(new anchor_1.BN(1));
200
+ quoteAssetReserveAfter = k.div(numericConstants_1.PRICE_PRECISION).div(baseAssetReserveAfter);
201
+ markPriceAfter = (0, amm_1.calculatePrice)(baseAssetReserveAfter, quoteAssetReserveAfter, peg);
202
+ direction = types_1.PositionDirection.SHORT;
203
+ tradeSize = quoteAssetReserveBefore
204
+ .sub(quoteAssetReserveAfter)
205
+ .mul(peg)
206
+ .div(numericConstants_1.PEG_PRECISION)
207
+ .div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO);
208
+ baseSize = baseAssetReserveAfter.sub(baseAssetReserveBefore);
209
+ }
210
+ else if (reservePriceBefore.lt(targetPrice)) {
211
+ // underestimate y2
212
+ baseAssetReserveAfter = (0, utils_1.squareRootBN)(k.div(targetPrice).mul(peg).div(numericConstants_1.PEG_PRECISION).add(biasModifier)).add(new anchor_1.BN(1));
213
+ quoteAssetReserveAfter = k.div(numericConstants_1.PRICE_PRECISION).div(baseAssetReserveAfter);
214
+ markPriceAfter = (0, amm_1.calculatePrice)(baseAssetReserveAfter, quoteAssetReserveAfter, peg);
215
+ direction = types_1.PositionDirection.LONG;
216
+ tradeSize = quoteAssetReserveAfter
217
+ .sub(quoteAssetReserveBefore)
218
+ .mul(peg)
219
+ .div(numericConstants_1.PEG_PRECISION)
220
+ .div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO);
221
+ baseSize = baseAssetReserveBefore.sub(baseAssetReserveAfter);
222
+ }
223
+ else {
224
+ // no trade, market is at target
225
+ direction = types_1.PositionDirection.LONG;
226
+ tradeSize = numericConstants_1.ZERO;
227
+ return [direction, tradeSize, targetPrice, targetPrice];
228
+ }
229
+ let tp1 = targetPrice;
230
+ let tp2 = markPriceAfter;
231
+ let originalDiff = targetPrice.sub(reservePriceBefore);
232
+ if (direction == types_1.PositionDirection.SHORT) {
233
+ tp1 = markPriceAfter;
234
+ tp2 = targetPrice;
235
+ originalDiff = reservePriceBefore.sub(targetPrice);
236
+ }
237
+ const entryPrice = tradeSize
238
+ .mul(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
239
+ .mul(numericConstants_1.PRICE_PRECISION)
240
+ .div(baseSize.abs());
241
+ (0, assert_1.assert)(tp1.sub(tp2).lte(originalDiff), 'Target Price Calculation incorrect');
242
+ (0, assert_1.assert)(tp2.lte(tp1) || tp2.sub(tp1).abs() < 100000, 'Target Price Calculation incorrect' +
243
+ tp2.toString() +
244
+ '>=' +
245
+ tp1.toString() +
246
+ 'err: ' +
247
+ tp2.sub(tp1).abs().toString());
248
+ if (outputAssetType == 'quote') {
249
+ return [direction, tradeSize, entryPrice, targetPrice];
250
+ }
251
+ else {
252
+ return [direction, baseSize, entryPrice, targetPrice];
253
+ }
254
+ }
255
+ exports.calculateTargetPriceTrade = calculateTargetPriceTrade;
256
+ /**
257
+ * Calculates the estimated entry price and price impact of order, in base or quote
258
+ * Price impact is based on the difference between the entry price and the best bid/ask price (whether it's dlob or vamm)
259
+ *
260
+ * @param assetType
261
+ * @param amount
262
+ * @param direction
263
+ * @param market
264
+ * @param oraclePriceData
265
+ * @param dlob
266
+ * @param slot
267
+ * @param usersToSkip
268
+ */
269
+ function calculateEstimatedPerpEntryPrice(assetType, amount, direction, market, oraclePriceData, dlob, slot, usersToSkip = new Map()) {
270
+ if (amount.eq(numericConstants_1.ZERO)) {
271
+ return {
272
+ entryPrice: numericConstants_1.ZERO,
273
+ priceImpact: numericConstants_1.ZERO,
274
+ bestPrice: numericConstants_1.ZERO,
275
+ worstPrice: numericConstants_1.ZERO,
276
+ baseFilled: numericConstants_1.ZERO,
277
+ quoteFilled: numericConstants_1.ZERO,
278
+ };
279
+ }
280
+ const takerIsLong = (0, types_2.isVariant)(direction, 'long');
281
+ const limitOrders = dlob[takerIsLong ? 'getRestingLimitAsks' : 'getRestingLimitBids'](market.marketIndex, slot, types_1.MarketType.PERP, oraclePriceData);
282
+ const swapDirection = (0, amm_1.getSwapDirection)(assetType, direction);
283
+ const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, direction, oraclePriceData);
284
+ const amm = {
285
+ baseAssetReserve,
286
+ quoteAssetReserve,
287
+ sqrtK: sqrtK,
288
+ pegMultiplier: newPeg,
289
+ };
290
+ const [ammBids, ammAsks] = (0, amm_1.calculateMarketOpenBidAsk)(market.amm.baseAssetReserve, market.amm.minBaseAssetReserve, market.amm.maxBaseAssetReserve, market.amm.orderStepSize);
291
+ let ammLiquidity;
292
+ if (assetType === 'base') {
293
+ ammLiquidity = takerIsLong ? ammAsks.abs() : ammBids;
294
+ }
295
+ else {
296
+ const [afterSwapQuoteReserves, _] = (0, amm_1.calculateAmmReservesAfterSwap)(amm, 'base', takerIsLong ? ammAsks.abs() : ammBids, (0, amm_1.getSwapDirection)('base', direction));
297
+ ammLiquidity = (0, amm_1.calculateQuoteAssetAmountSwapped)(amm.quoteAssetReserve.sub(afterSwapQuoteReserves).abs(), amm.pegMultiplier, swapDirection);
298
+ }
299
+ const invariant = amm.sqrtK.mul(amm.sqrtK);
300
+ let bestPrice = (0, amm_1.calculatePrice)(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
301
+ let cumulativeBaseFilled = numericConstants_1.ZERO;
302
+ let cumulativeQuoteFilled = numericConstants_1.ZERO;
303
+ let limitOrder = limitOrders.next().value;
304
+ if (limitOrder) {
305
+ const limitOrderPrice = limitOrder.getPrice(oraclePriceData, slot);
306
+ bestPrice = takerIsLong
307
+ ? anchor_1.BN.min(limitOrderPrice, bestPrice)
308
+ : anchor_1.BN.max(limitOrderPrice, bestPrice);
309
+ }
310
+ let worstPrice = bestPrice;
311
+ if (assetType === 'base') {
312
+ while (!cumulativeBaseFilled.eq(amount) &&
313
+ (ammLiquidity.gt(numericConstants_1.ZERO) || limitOrder)) {
314
+ const limitOrderPrice = limitOrder === null || limitOrder === void 0 ? void 0 : limitOrder.getPrice(oraclePriceData, slot);
315
+ let maxAmmFill;
316
+ if (limitOrderPrice) {
317
+ const newBaseReserves = (0, utils_1.squareRootBN)(invariant
318
+ .mul(numericConstants_1.PRICE_PRECISION)
319
+ .mul(amm.pegMultiplier)
320
+ .div(limitOrderPrice)
321
+ .div(numericConstants_1.PEG_PRECISION));
322
+ // will be zero if the limit order price is better than the amm price
323
+ maxAmmFill = takerIsLong
324
+ ? amm.baseAssetReserve.sub(newBaseReserves)
325
+ : newBaseReserves.sub(amm.baseAssetReserve);
326
+ }
327
+ else {
328
+ maxAmmFill = amount.sub(cumulativeBaseFilled);
329
+ }
330
+ maxAmmFill = anchor_1.BN.min(maxAmmFill, ammLiquidity);
331
+ if (maxAmmFill.gt(numericConstants_1.ZERO)) {
332
+ const baseFilled = anchor_1.BN.min(amount.sub(cumulativeBaseFilled), maxAmmFill);
333
+ const [afterSwapQuoteReserves, afterSwapBaseReserves] = (0, amm_1.calculateAmmReservesAfterSwap)(amm, 'base', baseFilled, swapDirection);
334
+ ammLiquidity = ammLiquidity.sub(baseFilled);
335
+ const quoteFilled = (0, amm_1.calculateQuoteAssetAmountSwapped)(amm.quoteAssetReserve.sub(afterSwapQuoteReserves).abs(), amm.pegMultiplier, swapDirection);
336
+ cumulativeBaseFilled = cumulativeBaseFilled.add(baseFilled);
337
+ cumulativeQuoteFilled = cumulativeQuoteFilled.add(quoteFilled);
338
+ amm.baseAssetReserve = afterSwapBaseReserves;
339
+ amm.quoteAssetReserve = afterSwapQuoteReserves;
340
+ worstPrice = (0, amm_1.calculatePrice)(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
341
+ if (cumulativeBaseFilled.eq(amount)) {
342
+ break;
343
+ }
344
+ }
345
+ if (!limitOrder) {
346
+ continue;
347
+ }
348
+ if (usersToSkip.has(limitOrder.userAccount)) {
349
+ continue;
350
+ }
351
+ const baseFilled = anchor_1.BN.min(limitOrder.order.baseAssetAmount.sub(limitOrder.order.baseAssetAmountFilled), amount.sub(cumulativeBaseFilled));
352
+ const quoteFilled = baseFilled.mul(limitOrderPrice).div(numericConstants_1.BASE_PRECISION);
353
+ cumulativeBaseFilled = cumulativeBaseFilled.add(baseFilled);
354
+ cumulativeQuoteFilled = cumulativeQuoteFilled.add(quoteFilled);
355
+ worstPrice = limitOrderPrice;
356
+ if (cumulativeBaseFilled.eq(amount)) {
357
+ break;
358
+ }
359
+ limitOrder = limitOrders.next().value;
360
+ }
361
+ }
362
+ else {
363
+ while (!cumulativeQuoteFilled.eq(amount) &&
364
+ (ammLiquidity.gt(numericConstants_1.ZERO) || limitOrder)) {
365
+ const limitOrderPrice = limitOrder === null || limitOrder === void 0 ? void 0 : limitOrder.getPrice(oraclePriceData, slot);
366
+ let maxAmmFill;
367
+ if (limitOrderPrice) {
368
+ const newQuoteReserves = (0, utils_1.squareRootBN)(invariant
369
+ .mul(numericConstants_1.PEG_PRECISION)
370
+ .mul(limitOrderPrice)
371
+ .div(amm.pegMultiplier)
372
+ .div(numericConstants_1.PRICE_PRECISION));
373
+ // will be zero if the limit order price is better than the amm price
374
+ maxAmmFill = takerIsLong
375
+ ? newQuoteReserves.sub(amm.quoteAssetReserve)
376
+ : amm.quoteAssetReserve.sub(newQuoteReserves);
377
+ }
378
+ else {
379
+ maxAmmFill = amount.sub(cumulativeQuoteFilled);
380
+ }
381
+ maxAmmFill = anchor_1.BN.min(maxAmmFill, ammLiquidity);
382
+ if (maxAmmFill.gt(numericConstants_1.ZERO)) {
383
+ const quoteFilled = anchor_1.BN.min(amount.sub(cumulativeQuoteFilled), maxAmmFill);
384
+ const [afterSwapQuoteReserves, afterSwapBaseReserves] = (0, amm_1.calculateAmmReservesAfterSwap)(amm, 'quote', quoteFilled, swapDirection);
385
+ ammLiquidity = ammLiquidity.sub(quoteFilled);
386
+ const baseFilled = afterSwapBaseReserves
387
+ .sub(amm.baseAssetReserve)
388
+ .abs();
389
+ cumulativeBaseFilled = cumulativeBaseFilled.add(baseFilled);
390
+ cumulativeQuoteFilled = cumulativeQuoteFilled.add(quoteFilled);
391
+ amm.baseAssetReserve = afterSwapBaseReserves;
392
+ amm.quoteAssetReserve = afterSwapQuoteReserves;
393
+ worstPrice = (0, amm_1.calculatePrice)(amm.baseAssetReserve, amm.quoteAssetReserve, amm.pegMultiplier);
394
+ if (cumulativeQuoteFilled.eq(amount)) {
395
+ break;
396
+ }
397
+ }
398
+ if (!limitOrder) {
399
+ continue;
400
+ }
401
+ if (usersToSkip.has(limitOrder.userAccount)) {
402
+ continue;
403
+ }
404
+ const quoteFilled = anchor_1.BN.min(limitOrder.order.baseAssetAmount
405
+ .sub(limitOrder.order.baseAssetAmountFilled)
406
+ .mul(limitOrderPrice)
407
+ .div(numericConstants_1.BASE_PRECISION), amount.sub(cumulativeQuoteFilled));
408
+ const baseFilled = quoteFilled.mul(numericConstants_1.BASE_PRECISION).div(limitOrderPrice);
409
+ cumulativeBaseFilled = cumulativeBaseFilled.add(baseFilled);
410
+ cumulativeQuoteFilled = cumulativeQuoteFilled.add(quoteFilled);
411
+ worstPrice = limitOrderPrice;
412
+ if (cumulativeQuoteFilled.eq(amount)) {
413
+ break;
414
+ }
415
+ limitOrder = limitOrders.next().value;
416
+ }
417
+ }
418
+ const entryPrice = cumulativeBaseFilled && cumulativeBaseFilled.gt(numericConstants_1.ZERO)
419
+ ? cumulativeQuoteFilled.mul(numericConstants_1.BASE_PRECISION).div(cumulativeBaseFilled)
420
+ : numericConstants_1.ZERO;
421
+ const priceImpact = bestPrice && bestPrice.gt(numericConstants_1.ZERO)
422
+ ? entryPrice.sub(bestPrice).mul(numericConstants_1.PRICE_PRECISION).div(bestPrice).abs()
423
+ : numericConstants_1.ZERO;
424
+ return {
425
+ entryPrice,
426
+ priceImpact,
427
+ bestPrice,
428
+ worstPrice,
429
+ baseFilled: cumulativeBaseFilled,
430
+ quoteFilled: cumulativeQuoteFilled,
431
+ };
432
+ }
433
+ exports.calculateEstimatedPerpEntryPrice = calculateEstimatedPerpEntryPrice;
434
+ /**
435
+ * Calculates the estimated entry price and price impact of order, in base or quote
436
+ * Price impact is based on the difference between the entry price and the best bid/ask price (whether it's dlob or serum)
437
+ *
438
+ * @param assetType
439
+ * @param amount
440
+ * @param direction
441
+ * @param market
442
+ * @param oraclePriceData
443
+ * @param dlob
444
+ * @param serumBids
445
+ * @param serumAsks
446
+ * @param slot
447
+ * @param usersToSkip
448
+ */
449
+ function calculateEstimatedSpotEntryPrice(assetType, amount, direction, market, oraclePriceData, dlob, serumBids, serumAsks, slot, usersToSkip = new Map()) {
450
+ if (amount.eq(numericConstants_1.ZERO)) {
451
+ return {
452
+ entryPrice: numericConstants_1.ZERO,
453
+ priceImpact: numericConstants_1.ZERO,
454
+ bestPrice: numericConstants_1.ZERO,
455
+ worstPrice: numericConstants_1.ZERO,
456
+ baseFilled: numericConstants_1.ZERO,
457
+ quoteFilled: numericConstants_1.ZERO,
458
+ };
459
+ }
460
+ const basePrecision = new anchor_1.BN(Math.pow(10, market.decimals));
461
+ const takerIsLong = (0, types_2.isVariant)(direction, 'long');
462
+ const dlobLimitOrders = dlob[takerIsLong ? 'getRestingLimitAsks' : 'getRestingLimitBids'](market.marketIndex, slot, types_1.MarketType.SPOT, oraclePriceData);
463
+ const serumLimitOrders = takerIsLong
464
+ ? serumAsks.getL2(100)
465
+ : serumBids.getL2(100);
466
+ let cumulativeBaseFilled = numericConstants_1.ZERO;
467
+ let cumulativeQuoteFilled = numericConstants_1.ZERO;
468
+ let dlobLimitOrder = dlobLimitOrders.next().value;
469
+ let serumLimitOrder = serumLimitOrders.shift();
470
+ const dlobLimitOrderPrice = dlobLimitOrder === null || dlobLimitOrder === void 0 ? void 0 : dlobLimitOrder.getPrice(oraclePriceData, slot);
471
+ const serumLimitOrderPrice = serumLimitOrder
472
+ ? new anchor_1.BN(serumLimitOrder[0] * numericConstants_1.PRICE_PRECISION.toNumber())
473
+ : undefined;
474
+ const bestPrice = takerIsLong
475
+ ? anchor_1.BN.min(serumLimitOrderPrice || numericConstants_1.BN_MAX, dlobLimitOrderPrice || numericConstants_1.BN_MAX)
476
+ : anchor_1.BN.max(serumLimitOrderPrice || numericConstants_1.ZERO, dlobLimitOrderPrice || numericConstants_1.ZERO);
477
+ let worstPrice = bestPrice;
478
+ if (assetType === 'base') {
479
+ while (!cumulativeBaseFilled.eq(amount) &&
480
+ (dlobLimitOrder || serumLimitOrder)) {
481
+ const dlobLimitOrderPrice = dlobLimitOrder === null || dlobLimitOrder === void 0 ? void 0 : dlobLimitOrder.getPrice(oraclePriceData, slot);
482
+ const serumLimitOrderPrice = serumLimitOrder
483
+ ? new anchor_1.BN(serumLimitOrder[0] * numericConstants_1.PRICE_PRECISION.toNumber())
484
+ : undefined;
485
+ const useSerum = takerIsLong
486
+ ? (serumLimitOrderPrice || numericConstants_1.BN_MAX).lt(dlobLimitOrderPrice || numericConstants_1.BN_MAX)
487
+ : (serumLimitOrderPrice || numericConstants_1.ZERO).gt(dlobLimitOrderPrice || numericConstants_1.ZERO);
488
+ if (!useSerum) {
489
+ if (dlobLimitOrder && usersToSkip.has(dlobLimitOrder.userAccount)) {
490
+ continue;
491
+ }
492
+ const baseFilled = anchor_1.BN.min(dlobLimitOrder.order.baseAssetAmount.sub(dlobLimitOrder.order.baseAssetAmountFilled), amount.sub(cumulativeBaseFilled));
493
+ const quoteFilled = baseFilled
494
+ .mul(dlobLimitOrderPrice)
495
+ .div(basePrecision);
496
+ cumulativeBaseFilled = cumulativeBaseFilled.add(baseFilled);
497
+ cumulativeQuoteFilled = cumulativeQuoteFilled.add(quoteFilled);
498
+ worstPrice = dlobLimitOrderPrice;
499
+ dlobLimitOrder = dlobLimitOrders.next().value;
500
+ }
501
+ else {
502
+ const baseFilled = anchor_1.BN.min(new anchor_1.BN(serumLimitOrder[1] * basePrecision.toNumber()), amount.sub(cumulativeBaseFilled));
503
+ const quoteFilled = baseFilled
504
+ .mul(serumLimitOrderPrice)
505
+ .div(basePrecision);
506
+ cumulativeBaseFilled = cumulativeBaseFilled.add(baseFilled);
507
+ cumulativeQuoteFilled = cumulativeQuoteFilled.add(quoteFilled);
508
+ worstPrice = serumLimitOrderPrice;
509
+ serumLimitOrder = serumLimitOrders.shift();
510
+ }
511
+ }
512
+ }
513
+ else {
514
+ while (!cumulativeQuoteFilled.eq(amount) &&
515
+ (dlobLimitOrder || serumLimitOrder)) {
516
+ const dlobLimitOrderPrice = dlobLimitOrder === null || dlobLimitOrder === void 0 ? void 0 : dlobLimitOrder.getPrice(oraclePriceData, slot);
517
+ const serumLimitOrderPrice = serumLimitOrder
518
+ ? new anchor_1.BN(serumLimitOrder[0] * numericConstants_1.PRICE_PRECISION.toNumber())
519
+ : undefined;
520
+ const useSerum = takerIsLong
521
+ ? (serumLimitOrderPrice || numericConstants_1.BN_MAX).lt(dlobLimitOrderPrice || numericConstants_1.BN_MAX)
522
+ : (serumLimitOrderPrice || numericConstants_1.ZERO).gt(dlobLimitOrderPrice || numericConstants_1.ZERO);
523
+ if (!useSerum) {
524
+ if (dlobLimitOrder && usersToSkip.has(dlobLimitOrder.userAccount)) {
525
+ continue;
526
+ }
527
+ const quoteFilled = anchor_1.BN.min(dlobLimitOrder.order.baseAssetAmount
528
+ .sub(dlobLimitOrder.order.baseAssetAmountFilled)
529
+ .mul(dlobLimitOrderPrice)
530
+ .div(basePrecision), amount.sub(cumulativeQuoteFilled));
531
+ const baseFilled = quoteFilled
532
+ .mul(basePrecision)
533
+ .div(dlobLimitOrderPrice);
534
+ cumulativeBaseFilled = cumulativeBaseFilled.add(baseFilled);
535
+ cumulativeQuoteFilled = cumulativeQuoteFilled.add(quoteFilled);
536
+ worstPrice = dlobLimitOrderPrice;
537
+ dlobLimitOrder = dlobLimitOrders.next().value;
538
+ }
539
+ else {
540
+ const serumOrderBaseAmount = new anchor_1.BN(serumLimitOrder[1] * basePrecision.toNumber());
541
+ const quoteFilled = anchor_1.BN.min(serumOrderBaseAmount.mul(serumLimitOrderPrice).div(basePrecision), amount.sub(cumulativeQuoteFilled));
542
+ const baseFilled = quoteFilled
543
+ .mul(basePrecision)
544
+ .div(serumLimitOrderPrice);
545
+ cumulativeBaseFilled = cumulativeBaseFilled.add(baseFilled);
546
+ cumulativeQuoteFilled = cumulativeQuoteFilled.add(quoteFilled);
547
+ worstPrice = serumLimitOrderPrice;
548
+ serumLimitOrder = serumLimitOrders.shift();
549
+ }
550
+ }
551
+ }
552
+ const entryPrice = cumulativeBaseFilled && cumulativeBaseFilled.gt(numericConstants_1.ZERO)
553
+ ? cumulativeQuoteFilled.mul(basePrecision).div(cumulativeBaseFilled)
554
+ : numericConstants_1.ZERO;
555
+ const priceImpact = bestPrice && bestPrice.gt(numericConstants_1.ZERO)
556
+ ? entryPrice.sub(bestPrice).mul(numericConstants_1.PRICE_PRECISION).div(bestPrice).abs()
557
+ : numericConstants_1.ZERO;
558
+ return {
559
+ entryPrice,
560
+ priceImpact,
561
+ bestPrice,
562
+ worstPrice,
563
+ baseFilled: cumulativeBaseFilled,
564
+ quoteFilled: cumulativeQuoteFilled,
565
+ };
566
+ }
567
+ exports.calculateEstimatedSpotEntryPrice = calculateEstimatedSpotEntryPrice;
568
+ function calculateEstimatedEntryPriceWithL2(assetType, amount, direction, basePrecision, l2) {
569
+ const takerIsLong = (0, types_2.isVariant)(direction, 'long');
570
+ let cumulativeBaseFilled = numericConstants_1.ZERO;
571
+ let cumulativeQuoteFilled = numericConstants_1.ZERO;
572
+ const levels = [...(takerIsLong ? l2.asks : l2.bids)];
573
+ let nextLevel = levels.shift();
574
+ let bestPrice;
575
+ let worstPrice;
576
+ if (nextLevel) {
577
+ bestPrice = nextLevel.price;
578
+ worstPrice = nextLevel.price;
579
+ }
580
+ else {
581
+ bestPrice = takerIsLong ? numericConstants_1.BN_MAX : numericConstants_1.ZERO;
582
+ worstPrice = bestPrice;
583
+ }
584
+ if (assetType === 'base') {
585
+ while (!cumulativeBaseFilled.eq(amount) && nextLevel) {
586
+ const price = nextLevel.price;
587
+ const size = nextLevel.size;
588
+ worstPrice = price;
589
+ const baseFilled = anchor_1.BN.min(size, amount.sub(cumulativeBaseFilled));
590
+ const quoteFilled = baseFilled.mul(price).div(basePrecision);
591
+ cumulativeBaseFilled = cumulativeBaseFilled.add(baseFilled);
592
+ cumulativeQuoteFilled = cumulativeQuoteFilled.add(quoteFilled);
593
+ nextLevel = levels.shift();
594
+ }
595
+ }
596
+ else {
597
+ while (!cumulativeQuoteFilled.eq(amount) && nextLevel) {
598
+ const price = nextLevel.price;
599
+ const size = nextLevel.size;
600
+ worstPrice = price;
601
+ const quoteFilled = anchor_1.BN.min(size.mul(price).div(basePrecision), amount.sub(cumulativeQuoteFilled));
602
+ const baseFilled = quoteFilled.mul(basePrecision).div(price);
603
+ cumulativeBaseFilled = cumulativeBaseFilled.add(baseFilled);
604
+ cumulativeQuoteFilled = cumulativeQuoteFilled.add(quoteFilled);
605
+ nextLevel = levels.shift();
606
+ }
607
+ }
608
+ const entryPrice = cumulativeBaseFilled && cumulativeBaseFilled.gt(numericConstants_1.ZERO)
609
+ ? cumulativeQuoteFilled.mul(basePrecision).div(cumulativeBaseFilled)
610
+ : numericConstants_1.ZERO;
611
+ const priceImpact = bestPrice && bestPrice.gt(numericConstants_1.ZERO)
612
+ ? entryPrice.sub(bestPrice).mul(numericConstants_1.PRICE_PRECISION).div(bestPrice).abs()
613
+ : numericConstants_1.ZERO;
614
+ return {
615
+ entryPrice,
616
+ priceImpact,
617
+ bestPrice,
618
+ worstPrice,
619
+ baseFilled: cumulativeBaseFilled,
620
+ quoteFilled: cumulativeQuoteFilled,
621
+ };
622
+ }
623
+ exports.calculateEstimatedEntryPriceWithL2 = calculateEstimatedEntryPriceWithL2;
624
+ function getUser30dRollingVolumeEstimate(userStatsAccount, now) {
625
+ now = now || new anchor_1.BN(new Date().getTime() / 1000);
626
+ const sinceLastTaker = anchor_1.BN.max(now.sub(userStatsAccount.lastTakerVolume30DTs), numericConstants_1.ZERO);
627
+ const sinceLastMaker = anchor_1.BN.max(now.sub(userStatsAccount.lastMakerVolume30DTs), numericConstants_1.ZERO);
628
+ const thirtyDaysInSeconds = new anchor_1.BN(60 * 60 * 24 * 30);
629
+ const last30dVolume = userStatsAccount.takerVolume30D
630
+ .mul(anchor_1.BN.max(thirtyDaysInSeconds.sub(sinceLastTaker), numericConstants_1.ZERO))
631
+ .div(thirtyDaysInSeconds)
632
+ .add(userStatsAccount.makerVolume30D
633
+ .mul(anchor_1.BN.max(thirtyDaysInSeconds.sub(sinceLastMaker), numericConstants_1.ZERO))
634
+ .div(thirtyDaysInSeconds));
635
+ return last30dVolume;
636
+ }
637
+ exports.getUser30dRollingVolumeEstimate = getUser30dRollingVolumeEstimate;
@@ -0,0 +1,23 @@
1
+ /// <reference types="bn.js" />
2
+ import { BN } from '../';
3
+ export declare function clampBN(x: BN, min: BN, max: BN): BN;
4
+ export declare const squareRootBN: (n: BN) => BN;
5
+ export declare const divCeil: (a: BN, b: BN) => BN;
6
+ export declare const sigNum: (x: BN) => BN;
7
+ /**
8
+ * calculates the time remaining until the next update based on a rounded, "on-the-hour" update schedule
9
+ * this schedule is used for Perpetual Funding Rate and Revenue -> Insurance Updates
10
+ * @param now: current blockchain unix timestamp
11
+ * @param lastUpdateTs: the unix timestamp of the last update
12
+ * @param updatePeriod: desired interval between updates (in seconds)
13
+ * @returns: timeRemainingUntilUpdate (in seconds)
14
+ */
15
+ export declare function timeRemainingUntilUpdate(now: BN, lastUpdateTs: BN, updatePeriod: BN): BN;
16
+ export declare const checkSameDate: (dateString1: string, dateString2: string) => boolean;
17
+ export declare function isBNSafe(number: number): boolean;
18
+ /**
19
+ * Converts a number to BN makes sure the number is safe to convert to BN (that it does not overflow number after multiplying by precision)
20
+ * @param number the number to convert to BN
21
+ * @param precision the BN precision to use (i.e. QUOTE_PRECISION and BASE_PRECISION from drift sdk)
22
+ */
23
+ export declare function numberToSafeBN(number: number, precision: BN): BN;