@drift-labs/sdk-browser 2.162.0-beta.2 → 2.163.0-beta.10

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 (500) hide show
  1. package/.prettierignore +1 -0
  2. package/.yarn/install-state.gz +0 -0
  3. package/README.md +2 -2
  4. package/VERSION +1 -1
  5. package/bun.lock +47 -79
  6. package/lib/browser/accounts/fetch.d.ts +6 -6
  7. package/lib/browser/accounts/fetch.js +4 -4
  8. package/lib/browser/accounts/grpcAccountSubscriber.d.ts +2 -2
  9. package/lib/browser/accounts/grpcDriftClientAccountSubscriber.d.ts +2 -2
  10. package/lib/browser/accounts/grpcDriftClientAccountSubscriberV2.d.ts +3 -3
  11. package/lib/browser/accounts/grpcDriftClientAccountSubscriberV2.js +2 -2
  12. package/lib/browser/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +2 -2
  13. package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +2 -2
  14. package/lib/browser/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -2
  15. package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +2 -2
  16. package/lib/browser/accounts/grpcUserAccountSubscriber.d.ts +2 -2
  17. package/lib/browser/accounts/grpcUserStatsAccountSubscriber.d.ts +2 -2
  18. package/lib/browser/accounts/laserProgramAccountSubscriber.d.ts +2 -2
  19. package/lib/browser/accounts/oneShotUserAccountSubscriber.d.ts +3 -3
  20. package/lib/browser/accounts/oneShotUserStatsAccountSubscriber.d.ts +3 -3
  21. package/lib/browser/accounts/pollingDriftClientAccountSubscriber.d.ts +3 -3
  22. package/lib/browser/accounts/pollingDriftClientAccountSubscriber.js +2 -2
  23. package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +3 -3
  24. package/lib/browser/accounts/pollingInsuranceFundStakeAccountSubscriber.js +1 -1
  25. package/lib/browser/accounts/pollingOracleAccountSubscriber.d.ts +2 -2
  26. package/lib/browser/accounts/pollingTokenAccountSubscriber.d.ts +2 -2
  27. package/lib/browser/accounts/pollingUserAccountSubscriber.js +2 -2
  28. package/lib/browser/accounts/pollingUserStatsAccountSubscriber.d.ts +3 -3
  29. package/lib/browser/accounts/pollingUserStatsAccountSubscriber.js +1 -1
  30. package/lib/browser/accounts/testBulkAccountLoader.js +3 -5
  31. package/lib/browser/accounts/types.d.ts +11 -14
  32. package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +3 -3
  33. package/lib/browser/accounts/webSocketAccountSubscriber.js +1 -2
  34. package/lib/browser/accounts/webSocketAccountSubscriberV2.d.ts +3 -3
  35. package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.d.ts +5 -5
  36. package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.js +2 -2
  37. package/lib/browser/accounts/webSocketDriftClientAccountSubscriberV2.d.ts +3 -3
  38. package/lib/browser/accounts/webSocketDriftClientAccountSubscriberV2.js +2 -2
  39. package/lib/browser/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +3 -3
  40. package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +3 -3
  41. package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -3
  42. package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -3
  43. package/lib/browser/accounts/webSocketUserAccountSubscriber.d.ts +3 -3
  44. package/lib/browser/accounts/webSocketUserStatsAccountSubsriber.d.ts +3 -3
  45. package/lib/browser/accounts/websocketProgramUserAccountSubscriber.d.ts +2 -2
  46. package/lib/browser/addresses/pda.d.ts +6 -2
  47. package/lib/browser/addresses/pda.js +7 -12
  48. package/lib/browser/adminClient.d.ts +11 -9
  49. package/lib/browser/adminClient.js +30 -72
  50. package/lib/browser/auctionSubscriber/auctionSubscriber.js +1 -1
  51. package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +1 -1
  52. package/lib/browser/config.d.ts +7 -3
  53. package/lib/browser/config.js +9 -7
  54. package/lib/browser/constants/index.d.ts +5 -0
  55. package/lib/browser/constants/index.js +5 -0
  56. package/lib/browser/constants/numericConstants.d.ts +1 -1
  57. package/lib/browser/constants/numericConstants.js +3 -3
  58. package/lib/browser/constants/perpMarkets.js +3 -412
  59. package/lib/browser/constants/spotMarkets.js +7 -91
  60. package/lib/browser/constituentMap/constituentMap.js +2 -2
  61. package/lib/browser/constituentMap/pollingConstituentAccountSubscriber.d.ts +3 -3
  62. package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.d.ts +3 -3
  63. package/lib/browser/constituentMap/webSocketConstituentAccountSubscriber.js +1 -1
  64. package/lib/browser/decode/customCoder.d.ts +7 -9
  65. package/lib/browser/decode/customCoder.js +17 -28
  66. package/lib/browser/decode/user.js +7 -25
  67. package/lib/browser/dlob/DLOB.d.ts +12 -0
  68. package/lib/browser/dlob/DLOB.js +12 -0
  69. package/lib/browser/dlob/orderBookLevels.js +1 -1
  70. package/lib/browser/driftClient.d.ts +32 -59
  71. package/lib/browser/driftClient.js +85 -562
  72. package/lib/browser/driftClientConfig.d.ts +7 -0
  73. package/lib/browser/events/eventSubscriber.d.ts +8 -0
  74. package/lib/browser/events/eventSubscriber.js +5 -2
  75. package/lib/browser/events/parse.d.ts +1 -1
  76. package/lib/browser/factory/oracleClient.d.ts +2 -2
  77. package/lib/browser/factory/oracleClient.js +9 -21
  78. package/lib/browser/idl/drift.d.ts +21406 -0
  79. package/lib/browser/idl/drift.js +2 -0
  80. package/lib/browser/idl/drift.json +20850 -15287
  81. package/lib/browser/idl/pyth.d.ts +97 -0
  82. package/lib/browser/idl/pyth.js +2 -0
  83. package/lib/browser/idl/token_faucet.d.ts +197 -0
  84. package/lib/browser/idl/token_faucet.js +2 -0
  85. package/lib/browser/idl/token_faucet.json +148 -61
  86. package/lib/browser/index.d.ts +13 -6
  87. package/lib/browser/index.js +12 -5
  88. package/lib/browser/marinade/index.d.ts +1 -1
  89. package/lib/browser/marinade/index.js +2 -2
  90. package/lib/browser/math/amm.d.ts +4 -5
  91. package/lib/browser/math/amm.js +8 -35
  92. package/lib/browser/math/funding.js +6 -1
  93. package/lib/browser/math/margin.d.ts +3 -4
  94. package/lib/browser/math/margin.js +16 -47
  95. package/lib/browser/math/market.d.ts +2 -2
  96. package/lib/browser/math/market.js +10 -42
  97. package/lib/browser/math/oracles.js +14 -19
  98. package/lib/browser/math/position.js +1 -1
  99. package/lib/browser/math/trade.js +4 -4
  100. package/lib/browser/memcmp.js +8 -8
  101. package/lib/browser/openbook/openbookV2Subscriber.d.ts +1 -1
  102. package/lib/browser/openbook/openbookV2Subscriber.js +3 -3
  103. package/lib/browser/oracles/oracleClientCache.d.ts +2 -2
  104. package/lib/browser/oracles/prelaunchOracleClient.d.ts +2 -2
  105. package/lib/browser/oracles/prelaunchOracleClient.js +1 -1
  106. package/lib/browser/oracles/pythLazerClient.js +3 -5
  107. package/lib/browser/oracles/types.d.ts +6 -0
  108. package/lib/browser/orderParams.d.ts +0 -1
  109. package/lib/browser/orderParams.js +1 -5
  110. package/lib/browser/orderSubscriber/OrderSubscriber.js +3 -4
  111. package/lib/browser/orderSubscriber/WebsocketSubscription.js +1 -1
  112. package/lib/browser/orderSubscriber/grpcSubscription.js +2 -2
  113. package/lib/browser/orderSubscriber/index.d.ts +5 -0
  114. package/lib/browser/orderSubscriber/index.js +5 -0
  115. package/lib/browser/priorityFee/index.d.ts +5 -0
  116. package/lib/browser/priorityFee/index.js +5 -0
  117. package/lib/browser/pyth/index.d.ts +2 -2
  118. package/lib/browser/pyth/types.d.ts +1 -1
  119. package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +1 -1
  120. package/lib/browser/swift/index.d.ts +7 -0
  121. package/lib/browser/swift/index.js +7 -0
  122. package/lib/browser/swift/signedMsgUserAccountSubscriber.js +4 -3
  123. package/lib/browser/tokenFaucet.d.ts +2 -2
  124. package/lib/browser/tokenFaucet.js +4 -4
  125. package/lib/browser/tx/txHandler.d.ts +12 -0
  126. package/lib/browser/tx/txHandler.js +12 -0
  127. package/lib/browser/types.d.ts +19 -31
  128. package/lib/browser/types.js +6 -11
  129. package/lib/browser/user.d.ts +27 -18
  130. package/lib/browser/user.js +64 -100
  131. package/lib/browser/userMap/WebsocketSubscription.js +1 -1
  132. package/lib/browser/userMap/grpcSubscription.js +1 -1
  133. package/lib/browser/userMap/revenueShareEscrowMap.js +4 -4
  134. package/lib/browser/userMap/userMap.js +4 -5
  135. package/lib/browser/userMap/userStatsMap.js +2 -3
  136. package/lib/browser/userStats.d.ts +5 -0
  137. package/lib/node/accounts/fetch.d.ts +6 -6
  138. package/lib/node/accounts/fetch.d.ts.map +1 -1
  139. package/lib/node/accounts/fetch.js +4 -4
  140. package/lib/node/accounts/grpcAccountSubscriber.d.ts +2 -2
  141. package/lib/node/accounts/grpcAccountSubscriber.d.ts.map +1 -1
  142. package/lib/node/accounts/grpcDriftClientAccountSubscriber.d.ts +2 -2
  143. package/lib/node/accounts/grpcDriftClientAccountSubscriber.d.ts.map +1 -1
  144. package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts +3 -3
  145. package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts.map +1 -1
  146. package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.js +2 -2
  147. package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +2 -2
  148. package/lib/node/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
  149. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +2 -2
  150. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
  151. package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts +2 -2
  152. package/lib/node/accounts/grpcMultiUserAccountSubscriber.d.ts.map +1 -1
  153. package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +2 -2
  154. package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts.map +1 -1
  155. package/lib/node/accounts/grpcUserAccountSubscriber.d.ts +2 -2
  156. package/lib/node/accounts/grpcUserAccountSubscriber.d.ts.map +1 -1
  157. package/lib/node/accounts/grpcUserStatsAccountSubscriber.d.ts +2 -2
  158. package/lib/node/accounts/grpcUserStatsAccountSubscriber.d.ts.map +1 -1
  159. package/lib/node/accounts/laserProgramAccountSubscriber.d.ts +2 -2
  160. package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
  161. package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts +3 -3
  162. package/lib/node/accounts/oneShotUserAccountSubscriber.d.ts.map +1 -1
  163. package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts +3 -3
  164. package/lib/node/accounts/oneShotUserStatsAccountSubscriber.d.ts.map +1 -1
  165. package/lib/node/accounts/pollingDriftClientAccountSubscriber.d.ts +3 -3
  166. package/lib/node/accounts/pollingDriftClientAccountSubscriber.d.ts.map +1 -1
  167. package/lib/node/accounts/pollingDriftClientAccountSubscriber.js +2 -2
  168. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +3 -3
  169. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
  170. package/lib/node/accounts/pollingInsuranceFundStakeAccountSubscriber.js +1 -1
  171. package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts +2 -2
  172. package/lib/node/accounts/pollingOracleAccountSubscriber.d.ts.map +1 -1
  173. package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts +2 -2
  174. package/lib/node/accounts/pollingTokenAccountSubscriber.d.ts.map +1 -1
  175. package/lib/node/accounts/pollingUserAccountSubscriber.js +2 -2
  176. package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts +3 -3
  177. package/lib/node/accounts/pollingUserStatsAccountSubscriber.d.ts.map +1 -1
  178. package/lib/node/accounts/pollingUserStatsAccountSubscriber.js +1 -1
  179. package/lib/node/accounts/testBulkAccountLoader.d.ts.map +1 -1
  180. package/lib/node/accounts/testBulkAccountLoader.js +3 -5
  181. package/lib/node/accounts/types.d.ts +11 -14
  182. package/lib/node/accounts/types.d.ts.map +1 -1
  183. package/lib/node/accounts/webSocketAccountSubscriber.d.ts +3 -3
  184. package/lib/node/accounts/webSocketAccountSubscriber.d.ts.map +1 -1
  185. package/lib/node/accounts/webSocketAccountSubscriber.js +1 -2
  186. package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts +3 -3
  187. package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts.map +1 -1
  188. package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts +5 -5
  189. package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts.map +1 -1
  190. package/lib/node/accounts/webSocketDriftClientAccountSubscriber.js +2 -2
  191. package/lib/node/accounts/webSocketDriftClientAccountSubscriberV2.d.ts +3 -3
  192. package/lib/node/accounts/webSocketDriftClientAccountSubscriberV2.d.ts.map +1 -1
  193. package/lib/node/accounts/webSocketDriftClientAccountSubscriberV2.js +2 -2
  194. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +3 -3
  195. package/lib/node/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts.map +1 -1
  196. package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +3 -3
  197. package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts.map +1 -1
  198. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +3 -3
  199. package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -1
  200. package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts +3 -3
  201. package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts.map +1 -1
  202. package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts +3 -3
  203. package/lib/node/accounts/webSocketUserAccountSubscriber.d.ts.map +1 -1
  204. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts +3 -3
  205. package/lib/node/accounts/webSocketUserStatsAccountSubsriber.d.ts.map +1 -1
  206. package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts +2 -2
  207. package/lib/node/accounts/websocketProgramUserAccountSubscriber.d.ts.map +1 -1
  208. package/lib/node/addresses/pda.d.ts +6 -2
  209. package/lib/node/addresses/pda.d.ts.map +1 -1
  210. package/lib/node/addresses/pda.js +7 -12
  211. package/lib/node/adminClient.d.ts +11 -9
  212. package/lib/node/adminClient.d.ts.map +1 -1
  213. package/lib/node/adminClient.js +30 -72
  214. package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
  215. package/lib/node/auctionSubscriber/auctionSubscriber.js +1 -1
  216. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
  217. package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +1 -1
  218. package/lib/node/config.d.ts +7 -3
  219. package/lib/node/config.d.ts.map +1 -1
  220. package/lib/node/config.js +9 -7
  221. package/lib/node/constants/index.d.ts +5 -0
  222. package/lib/node/constants/index.d.ts.map +1 -1
  223. package/lib/node/constants/index.js +5 -0
  224. package/lib/node/constants/numericConstants.d.ts +1 -1
  225. package/lib/node/constants/numericConstants.d.ts.map +1 -1
  226. package/lib/node/constants/numericConstants.js +3 -3
  227. package/lib/node/constants/perpMarkets.d.ts.map +1 -1
  228. package/lib/node/constants/perpMarkets.js +3 -412
  229. package/lib/node/constants/spotMarkets.d.ts.map +1 -1
  230. package/lib/node/constants/spotMarkets.js +7 -91
  231. package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
  232. package/lib/node/constituentMap/constituentMap.js +2 -2
  233. package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts +3 -3
  234. package/lib/node/constituentMap/pollingConstituentAccountSubscriber.d.ts.map +1 -1
  235. package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts +3 -3
  236. package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.d.ts.map +1 -1
  237. package/lib/node/constituentMap/webSocketConstituentAccountSubscriber.js +1 -1
  238. package/lib/node/decode/customCoder.d.ts +7 -9
  239. package/lib/node/decode/customCoder.d.ts.map +1 -1
  240. package/lib/node/decode/customCoder.js +17 -28
  241. package/lib/node/decode/user.d.ts.map +1 -1
  242. package/lib/node/decode/user.js +7 -25
  243. package/lib/node/dlob/DLOB.d.ts +12 -0
  244. package/lib/node/dlob/DLOB.d.ts.map +1 -1
  245. package/lib/node/dlob/DLOB.js +12 -0
  246. package/lib/node/dlob/orderBookLevels.d.ts.map +1 -1
  247. package/lib/node/dlob/orderBookLevels.js +1 -1
  248. package/lib/node/driftClient.d.ts +32 -59
  249. package/lib/node/driftClient.d.ts.map +1 -1
  250. package/lib/node/driftClient.js +85 -562
  251. package/lib/node/driftClientConfig.d.ts +7 -0
  252. package/lib/node/driftClientConfig.d.ts.map +1 -1
  253. package/lib/node/events/eventSubscriber.d.ts +8 -0
  254. package/lib/node/events/eventSubscriber.d.ts.map +1 -1
  255. package/lib/node/events/eventSubscriber.js +5 -2
  256. package/lib/node/events/parse.d.ts +1 -1
  257. package/lib/node/events/parse.d.ts.map +1 -1
  258. package/lib/node/factory/oracleClient.d.ts +2 -2
  259. package/lib/node/factory/oracleClient.d.ts.map +1 -1
  260. package/lib/node/factory/oracleClient.js +9 -21
  261. package/lib/node/idl/drift.d.ts +21407 -0
  262. package/lib/node/idl/drift.d.ts.map +1 -0
  263. package/lib/node/idl/drift.js +2 -0
  264. package/lib/node/idl/drift.json +20850 -15287
  265. package/lib/node/idl/pyth.d.ts +98 -0
  266. package/lib/node/idl/pyth.d.ts.map +1 -0
  267. package/lib/node/idl/pyth.js +2 -0
  268. package/lib/node/idl/token_faucet.d.ts +198 -0
  269. package/lib/node/idl/token_faucet.d.ts.map +1 -0
  270. package/lib/node/idl/token_faucet.js +2 -0
  271. package/lib/node/idl/token_faucet.json +148 -61
  272. package/lib/node/index.d.ts +13 -6
  273. package/lib/node/index.d.ts.map +1 -1
  274. package/lib/node/index.js +12 -5
  275. package/lib/node/marinade/index.d.ts +1 -1
  276. package/lib/node/marinade/index.d.ts.map +1 -1
  277. package/lib/node/marinade/index.js +2 -2
  278. package/lib/node/math/amm.d.ts +4 -5
  279. package/lib/node/math/amm.d.ts.map +1 -1
  280. package/lib/node/math/amm.js +8 -35
  281. package/lib/node/math/funding.d.ts.map +1 -1
  282. package/lib/node/math/funding.js +6 -1
  283. package/lib/node/math/margin.d.ts +3 -4
  284. package/lib/node/math/margin.d.ts.map +1 -1
  285. package/lib/node/math/margin.js +16 -47
  286. package/lib/node/math/market.d.ts +2 -2
  287. package/lib/node/math/market.d.ts.map +1 -1
  288. package/lib/node/math/market.js +10 -42
  289. package/lib/node/math/oracles.d.ts.map +1 -1
  290. package/lib/node/math/oracles.js +14 -19
  291. package/lib/node/math/position.d.ts.map +1 -1
  292. package/lib/node/math/position.js +1 -1
  293. package/lib/node/math/trade.d.ts.map +1 -1
  294. package/lib/node/math/trade.js +4 -4
  295. package/lib/node/memcmp.js +8 -8
  296. package/lib/node/openbook/openbookV2Subscriber.d.ts +1 -1
  297. package/lib/node/openbook/openbookV2Subscriber.d.ts.map +1 -1
  298. package/lib/node/openbook/openbookV2Subscriber.js +3 -3
  299. package/lib/node/oracles/oracleClientCache.d.ts +2 -2
  300. package/lib/node/oracles/oracleClientCache.d.ts.map +1 -1
  301. package/lib/node/oracles/prelaunchOracleClient.d.ts +2 -2
  302. package/lib/node/oracles/prelaunchOracleClient.d.ts.map +1 -1
  303. package/lib/node/oracles/prelaunchOracleClient.js +1 -1
  304. package/lib/node/oracles/pythLazerClient.d.ts.map +1 -1
  305. package/lib/node/oracles/pythLazerClient.js +3 -5
  306. package/lib/node/oracles/types.d.ts +6 -0
  307. package/lib/node/oracles/types.d.ts.map +1 -1
  308. package/lib/node/orderParams.d.ts +0 -1
  309. package/lib/node/orderParams.d.ts.map +1 -1
  310. package/lib/node/orderParams.js +1 -5
  311. package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
  312. package/lib/node/orderSubscriber/OrderSubscriber.js +3 -4
  313. package/lib/node/orderSubscriber/WebsocketSubscription.js +1 -1
  314. package/lib/node/orderSubscriber/grpcSubscription.js +2 -2
  315. package/lib/node/orderSubscriber/index.d.ts +5 -0
  316. package/lib/node/orderSubscriber/index.d.ts.map +1 -1
  317. package/lib/node/orderSubscriber/index.js +5 -0
  318. package/lib/node/priorityFee/index.d.ts +5 -0
  319. package/lib/node/priorityFee/index.d.ts.map +1 -1
  320. package/lib/node/priorityFee/index.js +5 -0
  321. package/lib/node/pyth/index.d.ts +2 -2
  322. package/lib/node/pyth/index.d.ts.map +1 -1
  323. package/lib/node/pyth/types.d.ts +1 -1
  324. package/lib/node/pyth/types.d.ts.map +1 -1
  325. package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.js +1 -1
  326. package/lib/node/swift/index.d.ts +7 -0
  327. package/lib/node/swift/index.d.ts.map +1 -1
  328. package/lib/node/swift/index.js +7 -0
  329. package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
  330. package/lib/node/swift/signedMsgUserAccountSubscriber.js +4 -3
  331. package/lib/node/tokenFaucet.d.ts +2 -2
  332. package/lib/node/tokenFaucet.d.ts.map +1 -1
  333. package/lib/node/tokenFaucet.js +4 -4
  334. package/lib/node/tx/txHandler.d.ts +12 -0
  335. package/lib/node/tx/txHandler.d.ts.map +1 -1
  336. package/lib/node/tx/txHandler.js +12 -0
  337. package/lib/node/types.d.ts +19 -31
  338. package/lib/node/types.d.ts.map +1 -1
  339. package/lib/node/types.js +6 -11
  340. package/lib/node/user.d.ts +27 -18
  341. package/lib/node/user.d.ts.map +1 -1
  342. package/lib/node/user.js +64 -100
  343. package/lib/node/userMap/WebsocketSubscription.js +1 -1
  344. package/lib/node/userMap/grpcSubscription.js +1 -1
  345. package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
  346. package/lib/node/userMap/revenueShareEscrowMap.js +4 -4
  347. package/lib/node/userMap/userMap.d.ts.map +1 -1
  348. package/lib/node/userMap/userMap.js +4 -5
  349. package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
  350. package/lib/node/userMap/userStatsMap.js +2 -3
  351. package/lib/node/userStats.d.ts +5 -0
  352. package/lib/node/userStats.d.ts.map +1 -1
  353. package/package.json +5 -7
  354. package/src/accounts/fetch.ts +18 -17
  355. package/src/accounts/grpcAccountSubscriber.ts +3 -3
  356. package/src/accounts/grpcDriftClientAccountSubscriber.ts +2 -3
  357. package/src/accounts/grpcDriftClientAccountSubscriberV2.ts +5 -6
  358. package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +2 -2
  359. package/src/accounts/grpcMultiAccountSubscriber.ts +4 -4
  360. package/src/accounts/grpcMultiUserAccountSubscriber.ts +4 -4
  361. package/src/accounts/grpcProgramAccountSubscriber.ts +3 -3
  362. package/src/accounts/grpcUserAccountSubscriber.ts +2 -2
  363. package/src/accounts/grpcUserStatsAccountSubscriber.ts +2 -2
  364. package/src/accounts/laserProgramAccountSubscriber.ts +3 -3
  365. package/src/accounts/oneShotUserAccountSubscriber.ts +6 -7
  366. package/src/accounts/oneShotUserStatsAccountSubscriber.ts +10 -9
  367. package/src/accounts/pollingDriftClientAccountSubscriber.ts +12 -11
  368. package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +11 -10
  369. package/src/accounts/pollingOracleAccountSubscriber.ts +2 -2
  370. package/src/accounts/pollingTokenAccountSubscriber.ts +2 -2
  371. package/src/accounts/pollingUserAccountSubscriber.ts +2 -2
  372. package/src/accounts/pollingUserStatsAccountSubscriber.ts +14 -14
  373. package/src/accounts/testBulkAccountLoader.ts +3 -5
  374. package/src/accounts/types.ts +10 -25
  375. package/src/accounts/webSocketAccountSubscriber.ts +5 -5
  376. package/src/accounts/webSocketAccountSubscriberV2.ts +4 -3
  377. package/src/accounts/webSocketDriftClientAccountSubscriber.ts +9 -10
  378. package/src/accounts/webSocketDriftClientAccountSubscriberV2.ts +13 -10
  379. package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +3 -3
  380. package/src/accounts/webSocketProgramAccountSubscriber.ts +4 -3
  381. package/src/accounts/webSocketProgramAccountSubscriberV2.ts +4 -3
  382. package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +4 -3
  383. package/src/accounts/webSocketUserAccountSubscriber.ts +3 -3
  384. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +3 -3
  385. package/src/accounts/websocketProgramUserAccountSubscriber.ts +4 -4
  386. package/src/addresses/pda.ts +6 -22
  387. package/src/adminClient.ts +154 -239
  388. package/src/auctionSubscriber/auctionSubscriber.ts +5 -3
  389. package/src/auctionSubscriber/auctionSubscriberGrpc.ts +5 -3
  390. package/src/config.ts +24 -16
  391. package/src/constants/index.ts +5 -0
  392. package/src/constants/numericConstants.ts +2 -3
  393. package/src/constants/perpMarkets.ts +3 -445
  394. package/src/constants/spotMarkets.ts +7 -102
  395. package/src/constituentMap/constituentMap.ts +5 -6
  396. package/src/constituentMap/pollingConstituentAccountSubscriber.ts +3 -3
  397. package/src/constituentMap/webSocketConstituentAccountSubscriber.ts +6 -6
  398. package/src/decode/customCoder.ts +26 -35
  399. package/src/decode/user.ts +7 -25
  400. package/src/dlob/DLOB.ts +12 -0
  401. package/src/dlob/orderBookLevels.ts +0 -1
  402. package/src/driftClient.ts +245 -1091
  403. package/src/driftClientConfig.ts +7 -0
  404. package/src/events/eventSubscriber.ts +14 -2
  405. package/src/events/parse.ts +2 -2
  406. package/src/factory/oracleClient.ts +17 -28
  407. package/src/idl/drift.json +20850 -15287
  408. package/src/idl/drift.ts +21406 -0
  409. package/src/idl/pyth.ts +97 -0
  410. package/src/idl/token_faucet.json +148 -61
  411. package/src/idl/token_faucet.ts +197 -0
  412. package/src/index.ts +13 -12
  413. package/src/margin/README.md +0 -1
  414. package/src/marinade/index.ts +2 -2
  415. package/src/math/amm.ts +2 -48
  416. package/src/math/funding.ts +8 -3
  417. package/src/math/margin.ts +12 -67
  418. package/src/math/market.ts +15 -69
  419. package/src/math/oracles.ts +14 -30
  420. package/src/math/position.ts +0 -1
  421. package/src/math/trade.ts +0 -4
  422. package/src/memcmp.ts +1 -1
  423. package/src/openbook/openbookV2Subscriber.ts +1 -1
  424. package/src/oracles/oracleClientCache.ts +2 -2
  425. package/src/oracles/prelaunchOracleClient.ts +9 -8
  426. package/src/oracles/pythLazerClient.ts +10 -12
  427. package/src/oracles/types.ts +6 -0
  428. package/src/orderParams.ts +0 -5
  429. package/src/orderSubscriber/OrderSubscriber.ts +7 -6
  430. package/src/orderSubscriber/WebsocketSubscription.ts +1 -1
  431. package/src/orderSubscriber/grpcSubscription.ts +2 -2
  432. package/src/orderSubscriber/index.ts +5 -0
  433. package/src/priorityFee/index.ts +5 -0
  434. package/src/pyth/index.ts +4 -4
  435. package/src/pyth/types.ts +1 -1
  436. package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +1 -1
  437. package/src/swift/index.ts +7 -0
  438. package/src/swift/signedMsgUserAccountSubscriber.ts +7 -4
  439. package/src/tokenFaucet.ts +8 -4
  440. package/src/tx/txHandler.ts +12 -0
  441. package/src/types.ts +16 -20
  442. package/src/user.ts +66 -144
  443. package/src/userMap/WebsocketSubscription.ts +1 -1
  444. package/src/userMap/grpcSubscription.ts +1 -1
  445. package/src/userMap/revenueShareEscrowMap.ts +24 -20
  446. package/src/userMap/userMap.ts +8 -7
  447. package/src/userMap/userStatsMap.ts +6 -5
  448. package/src/userStats.ts +5 -0
  449. package/tests/accounts/customizedCadenceBulkAccountLoader.test.ts +5 -4
  450. package/tests/amm/test.ts +45 -64
  451. package/tests/ci/verifyConstants.ts +23 -26
  452. package/tests/decode/test.ts +2 -4
  453. package/tests/dlob/helpers.ts +8 -15
  454. package/tests/user/helpers.ts +0 -2
  455. package/tests/user/marginCalculations.test.ts +2 -3
  456. package/tests/user/test.ts +18 -15
  457. package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +0 -29
  458. package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +0 -111
  459. package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +0 -23
  460. package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +0 -69
  461. package/lib/browser/idl/pyth_solana_receiver.json +0 -628
  462. package/lib/browser/idl/switchboard.json +0 -8354
  463. package/lib/browser/idl/switchboard_on_demand_30.json +0 -5849
  464. package/lib/browser/oracles/pythPullClient.d.ts +0 -19
  465. package/lib/browser/oracles/pythPullClient.js +0 -65
  466. package/lib/browser/oracles/switchboardClient.d.ts +0 -12
  467. package/lib/browser/oracles/switchboardClient.js +0 -40
  468. package/lib/browser/oracles/switchboardOnDemandClient.d.ts +0 -12
  469. package/lib/browser/oracles/switchboardOnDemandClient.js +0 -33
  470. package/lib/browser/util/pythOracleUtils.d.ts +0 -2
  471. package/lib/browser/util/pythOracleUtils.js +0 -15
  472. package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +0 -30
  473. package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts.map +0 -1
  474. package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +0 -111
  475. package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +0 -24
  476. package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts.map +0 -1
  477. package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +0 -69
  478. package/lib/node/idl/pyth_solana_receiver.json +0 -628
  479. package/lib/node/idl/switchboard.json +0 -8354
  480. package/lib/node/idl/switchboard_on_demand_30.json +0 -5849
  481. package/lib/node/oracles/pythPullClient.d.ts +0 -20
  482. package/lib/node/oracles/pythPullClient.d.ts.map +0 -1
  483. package/lib/node/oracles/pythPullClient.js +0 -65
  484. package/lib/node/oracles/switchboardClient.d.ts +0 -13
  485. package/lib/node/oracles/switchboardClient.d.ts.map +0 -1
  486. package/lib/node/oracles/switchboardClient.js +0 -40
  487. package/lib/node/oracles/switchboardOnDemandClient.d.ts +0 -13
  488. package/lib/node/oracles/switchboardOnDemandClient.d.ts.map +0 -1
  489. package/lib/node/oracles/switchboardOnDemandClient.js +0 -33
  490. package/lib/node/util/pythOracleUtils.d.ts +0 -3
  491. package/lib/node/util/pythOracleUtils.d.ts.map +0 -1
  492. package/lib/node/util/pythOracleUtils.js +0 -15
  493. package/src/accounts/pollingHighLeverageModeConfigAccountSubscriber.ts +0 -189
  494. package/src/accounts/webSocketHighLeverageModeConfigAccountSubscriber.ts +0 -131
  495. package/src/idl/switchboard.json +0 -8354
  496. package/src/idl/switchboard_on_demand_30.json +0 -5849
  497. package/src/oracles/pythPullClient.ts +0 -112
  498. package/src/oracles/switchboardClient.ts +0 -77
  499. package/src/oracles/switchboardOnDemandClient.ts +0 -64
  500. package/src/util/pythOracleUtils.ts +0 -11
package/lib/node/user.js CHANGED
@@ -185,7 +185,6 @@ class User {
185
185
  settledPnl: numericConstants_1.ZERO,
186
186
  lpShares: numericConstants_1.ZERO,
187
187
  lastQuoteAssetAmountPerLp: numericConstants_1.ZERO,
188
- perLpBase: 0,
189
188
  maxMarginRatio: 0,
190
189
  isolatedPositionScaledBalance: numericConstants_1.ZERO,
191
190
  positionFlag: 0,
@@ -303,7 +302,7 @@ class User {
303
302
  * calculates Buying Power = free collateral / initial margin ratio
304
303
  * @returns : Precision QUOTE_PRECISION
305
304
  */
306
- getPerpBuyingPower(marketIndex, collateralBuffer = numericConstants_1.ZERO, enterHighLeverageMode = undefined, maxMarginRatio = undefined, positionType = 'cross') {
305
+ getPerpBuyingPower(marketIndex, collateralBuffer = numericConstants_1.ZERO, maxMarginRatio = undefined, positionType = 'cross') {
307
306
  const perpPosition = this.getPerpPositionOrEmpty(marketIndex);
308
307
  const perpMarket = this.driftClient.getPerpMarketAccount(marketIndex);
309
308
  const oraclePriceData = this.getOracleDataForPerpMarket(marketIndex);
@@ -315,27 +314,26 @@ class User {
315
314
  if (positionType === 'isolated') {
316
315
  const { totalAssetValue: quoteSpotMarketAssetValue, totalLiabilityValue: quoteSpotMarketLiabilityValue, } = this.getSpotMarketAssetAndLiabilityValue(perpMarket.quoteSpotMarketIndex, 'Initial', undefined, undefined, true);
317
316
  const usdcAvailableForIsolatedMargin = quoteSpotMarketAssetValue.sub(quoteSpotMarketLiabilityValue);
318
- const generalFreeCollateral = this.getFreeCollateral('Initial', enterHighLeverageMode, undefined);
317
+ const generalFreeCollateral = this.getFreeCollateral('Initial', undefined);
319
318
  freeCollateral = anchor_1.BN.min(usdcAvailableForIsolatedMargin, generalFreeCollateral).sub(collateralBuffer);
320
319
  }
321
320
  else {
322
321
  // free collateral from the cross account only
323
- freeCollateral = this.getFreeCollateral('Initial', enterHighLeverageMode, undefined).sub(collateralBuffer);
322
+ freeCollateral = this.getFreeCollateral('Initial', undefined).sub(collateralBuffer);
324
323
  }
325
- return this.getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, worstCaseBaseAssetAmount, enterHighLeverageMode, maxMarginRatio || perpPosition.maxMarginRatio);
324
+ return this.getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, worstCaseBaseAssetAmount, maxMarginRatio || perpPosition.maxMarginRatio);
326
325
  }
327
- getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, baseAssetAmount, enterHighLeverageMode = undefined, perpMarketMaxMarginRatio = undefined) {
326
+ getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, baseAssetAmount, perpMarketMaxMarginRatio = undefined) {
328
327
  const maxMarginRatio = Math.max(perpMarketMaxMarginRatio, this.getUserAccount().maxMarginRatio);
329
- const marginRatio = (0, market_1.calculateMarketMarginRatio)(this.driftClient.getPerpMarketAccount(marketIndex), baseAssetAmount, 'Initial', maxMarginRatio, enterHighLeverageMode || this.isHighLeverageMode('Initial'));
328
+ const marginRatio = (0, market_1.calculateMarketMarginRatio)(this.driftClient.getPerpMarketAccount(marketIndex), baseAssetAmount, 'Initial', maxMarginRatio);
330
329
  return freeCollateral.mul(numericConstants_1.MARGIN_PRECISION).div(new anchor_1.BN(marginRatio));
331
330
  }
332
331
  /**
333
332
  * calculates Free Collateral = Total collateral - margin requirement
334
333
  * @returns : Precision QUOTE_PRECISION
335
334
  */
336
- getFreeCollateral(marginCategory = 'Initial', enterHighLeverageMode = false, perpMarketIndex) {
335
+ getFreeCollateral(marginCategory = 'Initial', perpMarketIndex) {
337
336
  const calc = this.getMarginCalculation(marginCategory, {
338
- enteringHighLeverage: enterHighLeverageMode,
339
337
  strict: marginCategory === 'Initial',
340
338
  });
341
339
  if (perpMarketIndex !== undefined) {
@@ -351,7 +349,7 @@ class User {
351
349
  return calc.getCrossFreeCollateral();
352
350
  }
353
351
  }
354
- getMarginRequirement(marginCategory, liquidationBuffer, strict, includeOpenOrders, enteringHighLeverage, perpMarketIndex) {
352
+ getMarginRequirement(marginCategory, liquidationBuffer, strict, includeOpenOrders, perpMarketIndex) {
355
353
  const liquidationBufferMap = new Map();
356
354
  if (liquidationBuffer && perpMarketIndex !== undefined) {
357
355
  liquidationBufferMap.set(perpMarketIndex, liquidationBuffer);
@@ -362,7 +360,6 @@ class User {
362
360
  const marginCalc = this.getMarginCalculation(marginCategory, {
363
361
  strict,
364
362
  includeOpenOrders,
365
- enteringHighLeverage,
366
363
  liquidationBufferMap,
367
364
  });
368
365
  // If perpMarketIndex is provided, compute only for that market index
@@ -385,8 +382,8 @@ class User {
385
382
  /**
386
383
  * @returns The initial margin requirement in USDC. : QUOTE_PRECISION
387
384
  */
388
- getInitialMarginRequirement(enterHighLeverageMode = false, perpMarketIndex) {
389
- return this.getMarginRequirement('Initial', undefined, true, undefined, enterHighLeverageMode, perpMarketIndex);
385
+ getInitialMarginRequirement(perpMarketIndex) {
386
+ return this.getMarginRequirement('Initial', undefined, true, undefined, perpMarketIndex);
390
387
  }
391
388
  /**
392
389
  * @returns The maintenance margin requirement in USDC. : QUOTE_PRECISION
@@ -394,7 +391,6 @@ class User {
394
391
  getMaintenanceMarginRequirement(liquidationBuffer, perpMarketIndex) {
395
392
  return this.getMarginRequirement('Maintenance', liquidationBuffer, false, // strict default
396
393
  true, // includeOpenOrders default
397
- false, // enteringHighLeverage default
398
394
  perpMarketIndex);
399
395
  }
400
396
  getActivePerpPositionsForUserAccount(userAccount) {
@@ -721,7 +717,7 @@ class User {
721
717
  }
722
718
  return health;
723
719
  }
724
- calculateWeightedPerpPositionLiability(perpPosition, marginCategory, liquidationBuffer, includeOpenOrders, strict = false, enteringHighLeverage = undefined) {
720
+ calculateWeightedPerpPositionLiability(perpPosition, marginCategory, liquidationBuffer, includeOpenOrders, strict = false) {
725
721
  const market = this.driftClient.getPerpMarketAccount(perpPosition.marketIndex);
726
722
  let valuationPrice = this.getOracleDataForPerpMarket(market.marketIndex).price;
727
723
  if ((0, types_1.isVariant)(market.status, 'settlement')) {
@@ -736,14 +732,11 @@ class User {
736
732
  }
737
733
  else {
738
734
  baseAssetAmount = perpPosition.baseAssetAmount;
739
- liabilityValue = (0, margin_1.calculatePerpLiabilityValue)(baseAssetAmount, valuationPrice, (0, types_1.isVariant)(market.contractType, 'prediction'));
735
+ liabilityValue = (0, margin_1.calculatePerpLiabilityValue)(baseAssetAmount, valuationPrice);
740
736
  }
741
737
  if (marginCategory) {
742
738
  const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
743
- let marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(market, baseAssetAmount.abs(), marginCategory, enteringHighLeverage === false
744
- ? Math.max(market.marginRatioInitial, userCustomMargin)
745
- : userCustomMargin, this.isHighLeverageMode(marginCategory) ||
746
- enteringHighLeverage === true));
739
+ let marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(market, baseAssetAmount.abs(), marginCategory, userCustomMargin));
747
740
  if (liquidationBuffer !== undefined) {
748
741
  marginRatio = marginRatio.add(liquidationBuffer);
749
742
  }
@@ -782,9 +775,9 @@ class User {
782
775
  * calculates sum of position value across all positions in margin system
783
776
  * @returns : Precision QUOTE_PRECISION
784
777
  */
785
- getTotalPerpPositionLiability(marginCategory, liquidationBuffer, includeOpenOrders, strict = false, enteringHighLeverage = undefined) {
778
+ getTotalPerpPositionLiability(marginCategory, liquidationBuffer, includeOpenOrders, strict = false) {
786
779
  return this.getActivePerpPositions().reduce((totalPerpValue, perpPosition) => {
787
- const baseAssetValue = this.calculateWeightedPerpPositionLiability(perpPosition, marginCategory, liquidationBuffer, includeOpenOrders, strict, enteringHighLeverage);
780
+ const baseAssetValue = this.calculateWeightedPerpPositionLiability(perpPosition, marginCategory, liquidationBuffer, includeOpenOrders, strict);
788
781
  return totalPerpValue.add(baseAssetValue);
789
782
  }, numericConstants_1.ZERO);
790
783
  }
@@ -808,7 +801,7 @@ class User {
808
801
  return (0, margin_1.calculateWorstCasePerpLiabilityValue)(userPosition, market, oraclePriceData.price).worstCaseLiabilityValue;
809
802
  }
810
803
  else {
811
- return (0, margin_1.calculatePerpLiabilityValue)(userPosition.baseAssetAmount, oraclePriceData.price, (0, types_1.isVariant)(market.contractType, 'prediction'));
804
+ return (0, margin_1.calculatePerpLiabilityValue)(userPosition.baseAssetAmount, oraclePriceData.price);
812
805
  }
813
806
  }
814
807
  getPositionSide(currentPosition) {
@@ -973,10 +966,9 @@ class User {
973
966
  * for large sizes where imf factor activates, result is a lower bound
974
967
  * @param marginCategory {Initial, Maintenance}
975
968
  * @param isLp if calculating max leveraging for adding lp, need to add buffer
976
- * @param enterHighLeverageMode can pass this as true to calculate max leverage if the user was to enter high leverage mode
977
969
  * @returns : Precision TEN_THOUSAND
978
970
  */
979
- getMaxLeverageForPerp(perpMarketIndex, _marginCategory = 'Initial', isLp = false, enterHighLeverageMode = undefined) {
971
+ getMaxLeverageForPerp(perpMarketIndex, _marginCategory = 'Initial', isLp = false) {
980
972
  const market = this.driftClient.getPerpMarketAccount(perpMarketIndex);
981
973
  const marketPrice = this.driftClient.getOracleDataForPerpMarket(perpMarketIndex).price;
982
974
  const { perpLiabilityValue, perpPnl, spotAssetValue, spotLiabilityValue } = this.getLeverageComponents();
@@ -990,7 +982,7 @@ class User {
990
982
  ? marketPrice.mul(market.amm.orderStepSize).div(numericConstants_1.AMM_RESERVE_PRECISION)
991
983
  : numericConstants_1.ZERO;
992
984
  // absolute max fesible size (upper bound)
993
- const maxSizeQuote = anchor_1.BN.max(anchor_1.BN.min(this.getMaxTradeSizeUSDCForPerp(perpMarketIndex, types_2.PositionDirection.LONG, false, enterHighLeverageMode || this.isHighLeverageMode('Initial')).tradeSize, this.getMaxTradeSizeUSDCForPerp(perpMarketIndex, types_2.PositionDirection.SHORT, false, enterHighLeverageMode || this.isHighLeverageMode('Initial')).tradeSize).sub(lpBuffer), numericConstants_1.ZERO);
985
+ const maxSizeQuote = anchor_1.BN.max(anchor_1.BN.min(this.getMaxTradeSizeUSDCForPerp(perpMarketIndex, types_2.PositionDirection.LONG, false).tradeSize, this.getMaxTradeSizeUSDCForPerp(perpMarketIndex, types_2.PositionDirection.SHORT, false).tradeSize).sub(lpBuffer), numericConstants_1.ZERO);
994
986
  return totalLiabilityValue
995
987
  .add(maxSizeQuote)
996
988
  .mul(numericConstants_1.TEN_THOUSAND)
@@ -1150,11 +1142,6 @@ class User {
1150
1142
  isBankrupt() {
1151
1143
  return (this.getUserAccount().status & types_1.UserStatus.BANKRUPT) > 0;
1152
1144
  }
1153
- isHighLeverageMode(marginCategory) {
1154
- return ((0, types_1.isVariant)(this.getUserAccount().marginMode, 'highLeverage') ||
1155
- (marginCategory === 'Maintenance' &&
1156
- (0, types_1.isVariant)(this.getUserAccount().marginMode, 'highLeverageMaintenance')));
1157
- }
1158
1145
  /**
1159
1146
  * Checks if any user position cumulative funding differs from respective market cumulative funding
1160
1147
  * @returns
@@ -1233,7 +1220,7 @@ class User {
1233
1220
  * @param offsetCollateral // allows calculating the liquidation price after this offset collateral is added to the user's account (e.g. : what will the liquidation price be for this position AFTER I deposit $x worth of collateral)
1234
1221
  * @returns Precision : PRICE_PRECISION
1235
1222
  */
1236
- liquidationPrice(marketIndex, positionBaseSizeChange = numericConstants_1.ZERO, estimatedEntryPrice = numericConstants_1.ZERO, marginCategory = 'Maintenance', includeOpenOrders = false, offsetCollateral = numericConstants_1.ZERO, enteringHighLeverage = false, marginType) {
1223
+ liquidationPrice(marketIndex, positionBaseSizeChange = numericConstants_1.ZERO, estimatedEntryPrice = numericConstants_1.ZERO, marginCategory = 'Maintenance', includeOpenOrders = false, offsetCollateral = numericConstants_1.ZERO, marginType) {
1237
1224
  const market = this.driftClient.getPerpMarketAccount(marketIndex);
1238
1225
  const oracle = this.driftClient.getPerpMarketAccount(marketIndex).amm.oracle;
1239
1226
  const oraclePrice = this.driftClient.getOracleDataForPerpMarket(marketIndex).price;
@@ -1242,14 +1229,13 @@ class User {
1242
1229
  const marginCalculation = this.getMarginCalculation(marginCategory, {
1243
1230
  strict: false,
1244
1231
  includeOpenOrders,
1245
- enteringHighLeverage,
1246
1232
  });
1247
1233
  const isolatedMarginCalculation = marginCalculation.isolatedMarginCalculations.get(marketIndex);
1248
1234
  if (!isolatedMarginCalculation)
1249
1235
  return new anchor_1.BN(-1);
1250
1236
  const { totalCollateral, marginRequirement } = isolatedMarginCalculation;
1251
1237
  const freeCollateral = anchor_1.BN.max(numericConstants_1.ZERO, totalCollateral.sub(marginRequirement)).add(offsetCollateral);
1252
- const freeCollateralDelta = this.calculateFreeCollateralDeltaForPerp(market, currentPerpPosition, positionBaseSizeChange, oraclePrice, marginCategory, includeOpenOrders, enteringHighLeverage);
1238
+ const freeCollateralDelta = this.calculateFreeCollateralDeltaForPerp(market, currentPerpPosition, positionBaseSizeChange, oraclePrice, marginCategory, includeOpenOrders);
1253
1239
  if (!freeCollateralDelta || freeCollateralDelta.eq(numericConstants_1.ZERO)) {
1254
1240
  return new anchor_1.BN(-1);
1255
1241
  }
@@ -1263,12 +1249,12 @@ class User {
1263
1249
  return liqPrice;
1264
1250
  }
1265
1251
  const totalCollateral = this.getTotalCollateral(marginCategory, false, includeOpenOrders);
1266
- const marginRequirement = this.getMarginRequirement(marginCategory, undefined, false, includeOpenOrders, enteringHighLeverage);
1252
+ const marginRequirement = this.getMarginRequirement(marginCategory, undefined, false, includeOpenOrders);
1267
1253
  let freeCollateral = anchor_1.BN.max(numericConstants_1.ZERO, totalCollateral.sub(marginRequirement)).add(offsetCollateral);
1268
1254
  positionBaseSizeChange = (0, orders_1.standardizeBaseAssetAmount)(positionBaseSizeChange, market.amm.orderStepSize);
1269
- const freeCollateralChangeFromNewPosition = this.calculateEntriesEffectOnFreeCollateral(market, oraclePrice, currentPerpPosition, positionBaseSizeChange, estimatedEntryPrice, includeOpenOrders, enteringHighLeverage);
1255
+ const freeCollateralChangeFromNewPosition = this.calculateEntriesEffectOnFreeCollateral(market, oraclePrice, currentPerpPosition, positionBaseSizeChange, estimatedEntryPrice, includeOpenOrders);
1270
1256
  freeCollateral = freeCollateral.add(freeCollateralChangeFromNewPosition);
1271
- let freeCollateralDelta = this.calculateFreeCollateralDeltaForPerp(market, currentPerpPosition, positionBaseSizeChange, oraclePrice, marginCategory, includeOpenOrders, enteringHighLeverage);
1257
+ let freeCollateralDelta = this.calculateFreeCollateralDeltaForPerp(market, currentPerpPosition, positionBaseSizeChange, oraclePrice, marginCategory, includeOpenOrders);
1272
1258
  if (!freeCollateralDelta) {
1273
1259
  return new anchor_1.BN(-1);
1274
1260
  }
@@ -1301,7 +1287,7 @@ class User {
1301
1287
  }
1302
1288
  return liqPrice;
1303
1289
  }
1304
- calculateEntriesEffectOnFreeCollateral(market, oraclePrice, perpPosition, positionBaseSizeChange, estimatedEntryPrice, includeOpenOrders, enteringHighLeverage = undefined, marginCategory = 'Maintenance') {
1290
+ calculateEntriesEffectOnFreeCollateral(market, oraclePrice, perpPosition, positionBaseSizeChange, estimatedEntryPrice, includeOpenOrders, marginCategory = 'Maintenance') {
1305
1291
  let freeCollateralChange = numericConstants_1.ZERO;
1306
1292
  // update free collateral to account for change in pnl from new position
1307
1293
  if (!estimatedEntryPrice.eq(numericConstants_1.ZERO) &&
@@ -1336,12 +1322,10 @@ class User {
1336
1322
  }
1337
1323
  else {
1338
1324
  baseAssetAmount = perpPosition.baseAssetAmount;
1339
- liabilityValue = (0, margin_1.calculatePerpLiabilityValue)(baseAssetAmount, oraclePrice, (0, types_1.isVariant)(market.contractType, 'prediction'));
1325
+ liabilityValue = (0, margin_1.calculatePerpLiabilityValue)(baseAssetAmount, oraclePrice);
1340
1326
  }
1341
1327
  const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
1342
- const marginRatio = (0, market_1.calculateMarketMarginRatio)(market, baseAssetAmount.abs(), marginCategory, enteringHighLeverage === false
1343
- ? Math.max(market.marginRatioInitial, userCustomMargin)
1344
- : userCustomMargin, this.isHighLeverageMode(marginCategory) || enteringHighLeverage === true);
1328
+ const marginRatio = (0, market_1.calculateMarketMarginRatio)(market, baseAssetAmount.abs(), marginCategory, userCustomMargin);
1345
1329
  return liabilityValue.mul(new anchor_1.BN(marginRatio)).div(numericConstants_1.MARGIN_PRECISION);
1346
1330
  };
1347
1331
  const freeCollateralConsumptionBefore = calculateMarginRequirement(perpPosition);
@@ -1350,7 +1334,7 @@ class User {
1350
1334
  const freeCollateralConsumptionAfter = calculateMarginRequirement(perpPositionAfter);
1351
1335
  return freeCollateralChange.sub(freeCollateralConsumptionAfter.sub(freeCollateralConsumptionBefore));
1352
1336
  }
1353
- calculateFreeCollateralDeltaForPerp(market, perpPosition, positionBaseSizeChange, oraclePrice, marginCategory = 'Maintenance', includeOpenOrders = false, enteringHighLeverage = undefined) {
1337
+ calculateFreeCollateralDeltaForPerp(market, perpPosition, positionBaseSizeChange, oraclePrice, marginCategory = 'Maintenance', includeOpenOrders = false) {
1354
1338
  const baseAssetAmount = includeOpenOrders
1355
1339
  ? (0, margin_2.calculateWorstCaseBaseAssetAmount)(perpPosition, market, oraclePrice)
1356
1340
  : perpPosition.baseAssetAmount;
@@ -1358,9 +1342,7 @@ class User {
1358
1342
  const orderBaseAssetAmount = baseAssetAmount.sub(perpPosition.baseAssetAmount);
1359
1343
  const proposedBaseAssetAmount = baseAssetAmount.add(positionBaseSizeChange);
1360
1344
  const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
1361
- const marginRatio = (0, market_1.calculateMarketMarginRatio)(market, proposedBaseAssetAmount.abs(), marginCategory, enteringHighLeverage === false
1362
- ? Math.max(market.marginRatioInitial, userCustomMargin)
1363
- : userCustomMargin, this.isHighLeverageMode(marginCategory) || enteringHighLeverage === true);
1345
+ const marginRatio = (0, market_1.calculateMarketMarginRatio)(market, proposedBaseAssetAmount.abs(), marginCategory, userCustomMargin);
1364
1346
  const marginRatioQuotePrecision = new anchor_1.BN(marginRatio)
1365
1347
  .mul(numericConstants_1.QUOTE_PRECISION)
1366
1348
  .div(numericConstants_1.MARGIN_PRECISION);
@@ -1368,33 +1350,21 @@ class User {
1368
1350
  return undefined;
1369
1351
  }
1370
1352
  let freeCollateralDelta = numericConstants_1.ZERO;
1371
- if ((0, types_1.isVariant)(market.contractType, 'prediction')) {
1372
- // for prediction market, increase in pnl and margin requirement will net out for position
1373
- // open order margin requirement will change with price though
1374
- if (orderBaseAssetAmount.gt(numericConstants_1.ZERO)) {
1375
- freeCollateralDelta = marginRatioQuotePrecision.neg();
1376
- }
1377
- else if (orderBaseAssetAmount.lt(numericConstants_1.ZERO)) {
1378
- freeCollateralDelta = marginRatioQuotePrecision;
1379
- }
1353
+ if (proposedBaseAssetAmount.gt(numericConstants_1.ZERO)) {
1354
+ freeCollateralDelta = numericConstants_1.QUOTE_PRECISION.sub(marginRatioQuotePrecision)
1355
+ .mul(proposedBaseAssetAmount)
1356
+ .div(numericConstants_1.BASE_PRECISION);
1380
1357
  }
1381
1358
  else {
1382
- if (proposedBaseAssetAmount.gt(numericConstants_1.ZERO)) {
1383
- freeCollateralDelta = numericConstants_1.QUOTE_PRECISION.sub(marginRatioQuotePrecision)
1384
- .mul(proposedBaseAssetAmount)
1385
- .div(numericConstants_1.BASE_PRECISION);
1386
- }
1387
- else {
1388
- freeCollateralDelta = numericConstants_1.QUOTE_PRECISION.neg()
1389
- .sub(marginRatioQuotePrecision)
1390
- .mul(proposedBaseAssetAmount.abs())
1391
- .div(numericConstants_1.BASE_PRECISION);
1392
- }
1393
- if (!orderBaseAssetAmount.eq(numericConstants_1.ZERO)) {
1394
- freeCollateralDelta = freeCollateralDelta.sub(marginRatioQuotePrecision
1395
- .mul(orderBaseAssetAmount.abs())
1396
- .div(numericConstants_1.BASE_PRECISION));
1397
- }
1359
+ freeCollateralDelta = numericConstants_1.QUOTE_PRECISION.neg()
1360
+ .sub(marginRatioQuotePrecision)
1361
+ .mul(proposedBaseAssetAmount.abs())
1362
+ .div(numericConstants_1.BASE_PRECISION);
1363
+ }
1364
+ if (!orderBaseAssetAmount.eq(numericConstants_1.ZERO)) {
1365
+ freeCollateralDelta = freeCollateralDelta.sub(marginRatioQuotePrecision
1366
+ .mul(orderBaseAssetAmount.abs())
1367
+ .div(numericConstants_1.BASE_PRECISION));
1398
1368
  }
1399
1369
  return freeCollateralDelta;
1400
1370
  }
@@ -1435,12 +1405,11 @@ class User {
1435
1405
  }
1436
1406
  getMarginUSDCRequiredForTrade(targetMarketIndex, baseSize, estEntryPrice, perpMarketMaxMarginRatio) {
1437
1407
  const maxMarginRatio = Math.max(perpMarketMaxMarginRatio, this.getUserAccount().maxMarginRatio);
1438
- return (0, margin_2.calculateMarginUSDCRequiredForTrade)(this.driftClient, targetMarketIndex, baseSize, maxMarginRatio, undefined, estEntryPrice);
1408
+ return (0, margin_2.calculateMarginUSDCRequiredForTrade)(this.driftClient, targetMarketIndex, baseSize, maxMarginRatio, estEntryPrice);
1439
1409
  }
1440
1410
  getCollateralDepositRequiredForTrade(targetMarketIndex, baseSize, collateralIndex, perpMarketMaxMarginRatio) {
1441
1411
  const maxMarginRatio = Math.max(perpMarketMaxMarginRatio, this.getUserAccount().maxMarginRatio);
1442
- return (0, margin_2.calculateCollateralDepositRequiredForTrade)(this.driftClient, targetMarketIndex, baseSize, collateralIndex, maxMarginRatio, false // assume user cant be high leverage if they havent created user account ?
1443
- );
1412
+ return (0, margin_2.calculateCollateralDepositRequiredForTrade)(this.driftClient, targetMarketIndex, baseSize, collateralIndex, maxMarginRatio);
1444
1413
  }
1445
1414
  /**
1446
1415
  * Separates the max trade size into two parts:
@@ -1451,7 +1420,7 @@ class User {
1451
1420
  * @param isLp
1452
1421
  * @returns { tradeSize: BN, oppositeSideTradeSize: BN} : Precision QUOTE_PRECISION
1453
1422
  */
1454
- getMaxTradeSizeUSDCForPerp(targetMarketIndex, tradeSide, isLp = false, enterHighLeverageMode = undefined, maxMarginRatio = undefined, positionType = 'cross') {
1423
+ getMaxTradeSizeUSDCForPerp(targetMarketIndex, tradeSide, isLp = false, maxMarginRatio = undefined, positionType = 'cross') {
1455
1424
  let tradeSize = numericConstants_1.ZERO;
1456
1425
  let oppositeSideTradeSize = numericConstants_1.ZERO;
1457
1426
  const currentPosition = this.getPerpPositionOrEmpty(targetMarketIndex);
@@ -1472,8 +1441,8 @@ class User {
1472
1441
  // add any position we have on the opposite side of the current trade, because we can "flip" the size of this position without taking any extra leverage.
1473
1442
  const oppositeSizeLiabilityValue = targetingSameSide
1474
1443
  ? numericConstants_1.ZERO
1475
- : (0, margin_1.calculatePerpLiabilityValue)(currentPosition.baseAssetAmount, oracleData.price, (0, types_1.isVariant)(marketAccount.contractType, 'prediction'));
1476
- const maxPositionSize = this.getPerpBuyingPower(targetMarketIndex, lpBuffer, enterHighLeverageMode, maxMarginRatio, positionType);
1444
+ : (0, margin_1.calculatePerpLiabilityValue)(currentPosition.baseAssetAmount, oracleData.price);
1445
+ const maxPositionSize = this.getPerpBuyingPower(targetMarketIndex, lpBuffer, maxMarginRatio, positionType);
1477
1446
  if (maxPositionSize.gte(numericConstants_1.ZERO)) {
1478
1447
  if (oppositeSizeLiabilityValue.eq(numericConstants_1.ZERO)) {
1479
1448
  // case 1 : Regular trade where current total position less than max, and no opposite position to account for
@@ -1489,10 +1458,9 @@ class User {
1489
1458
  else {
1490
1459
  // current leverage is greater than max leverage - can only reduce position size
1491
1460
  if (!targetingSameSide) {
1492
- const market = this.driftClient.getPerpMarketAccount(targetMarketIndex);
1493
- const perpLiabilityValue = (0, margin_1.calculatePerpLiabilityValue)(currentPosition.baseAssetAmount, oracleData.price, (0, types_1.isVariant)(market.contractType, 'prediction'));
1461
+ const perpLiabilityValue = (0, margin_1.calculatePerpLiabilityValue)(currentPosition.baseAssetAmount, oracleData.price);
1494
1462
  const totalCollateral = this.getTotalCollateral();
1495
- const marginRequirement = this.getInitialMarginRequirement(enterHighLeverageMode);
1463
+ const marginRequirement = this.getInitialMarginRequirement();
1496
1464
  const marginRatio = Math.max(currentPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
1497
1465
  const marginFreedByClosing = perpLiabilityValue
1498
1466
  .mul(new anchor_1.BN(marginRatio))
@@ -1513,11 +1481,11 @@ class User {
1513
1481
  tradeSize = maxPositionSize;
1514
1482
  }
1515
1483
  }
1516
- const freeCollateral = this.getFreeCollateral('Initial', enterHighLeverageMode);
1484
+ const freeCollateral = this.getFreeCollateral('Initial');
1517
1485
  let baseTradeSize = targetSide === 'long'
1518
1486
  ? tradeSize.mul(numericConstants_1.BASE_PRECISION).div(oracleData.price)
1519
1487
  : tradeSize.mul(numericConstants_1.BASE_PRECISION).div(oracleData.price).neg();
1520
- let freeCollateralChangeFromNewPosition = this.calculateEntriesEffectOnFreeCollateral(marketAccount, oracleData.price, currentPosition, baseTradeSize, oracleData.price, false, enterHighLeverageMode, 'Initial');
1488
+ let freeCollateralChangeFromNewPosition = this.calculateEntriesEffectOnFreeCollateral(marketAccount, oracleData.price, currentPosition, baseTradeSize, oracleData.price, false, 'Initial');
1521
1489
  while (freeCollateralChangeFromNewPosition.isNeg() &&
1522
1490
  freeCollateralChangeFromNewPosition.abs().gt(freeCollateral)) {
1523
1491
  tradeSize = tradeSize.mul(new anchor_1.BN(99)).div(new anchor_1.BN(100));
@@ -1526,7 +1494,7 @@ class User {
1526
1494
  ? tradeSize.mul(numericConstants_1.BASE_PRECISION).div(oracleData.price)
1527
1495
  : tradeSize.mul(numericConstants_1.BASE_PRECISION).div(oracleData.price).neg();
1528
1496
  freeCollateralChangeFromNewPosition =
1529
- this.calculateEntriesEffectOnFreeCollateral(marketAccount, oracleData.price, currentPosition, baseTradeSize, oracleData.price, false, enterHighLeverageMode, 'Initial');
1497
+ this.calculateEntriesEffectOnFreeCollateral(marketAccount, oracleData.price, currentPosition, baseTradeSize, oracleData.price, false, 'Initial');
1530
1498
  }
1531
1499
  return { tradeSize, oppositeSideTradeSize };
1532
1500
  }
@@ -1871,9 +1839,6 @@ class User {
1871
1839
  const state = this.driftClient.getStateAccount();
1872
1840
  const feeTierIndex = 0;
1873
1841
  if ((0, types_1.isVariant)(marketType, 'perp')) {
1874
- if (this.isHighLeverageMode('Initial')) {
1875
- return state.perpFeeStructure.feeTiers[0];
1876
- }
1877
1842
  const userStatsAccount = this.driftClient
1878
1843
  .getUserStats()
1879
1844
  .getAccount();
@@ -1924,9 +1889,9 @@ class User {
1924
1889
  * @param quoteAmount
1925
1890
  * @returns feeForQuote : Precision QUOTE_PRECISION
1926
1891
  */
1927
- calculateFeeForQuoteAmount(quoteAmount, marketIndex, enteringHighLeverageMode) {
1892
+ calculateFeeForQuoteAmount(quoteAmount, marketIndex) {
1928
1893
  if (marketIndex !== undefined) {
1929
- const takerFeeMultiplier = this.driftClient.getMarketFees(types_2.MarketType.PERP, marketIndex, this, enteringHighLeverageMode).takerFee;
1894
+ const takerFeeMultiplier = this.driftClient.getMarketFees(types_2.MarketType.PERP, marketIndex, this).takerFee;
1930
1895
  const feeAmountNum = bigNum_1.BigNum.from(quoteAmount, numericConstants_1.QUOTE_PRECISION_EXP).toNum() *
1931
1896
  takerFeeMultiplier;
1932
1897
  return bigNum_1.BigNum.fromPrint(feeAmountNum.toString(), numericConstants_1.QUOTE_PRECISION_EXP).val;
@@ -2158,10 +2123,10 @@ class User {
2158
2123
  }
2159
2124
  else {
2160
2125
  worstCaseBaseAmount = perpPosition.baseAssetAmount;
2161
- worstCaseLiabilityValue = (0, margin_1.calculatePerpLiabilityValue)(perpPosition.baseAssetAmount, oraclePrice, (0, types_1.isVariant)(perpMarket.contractType, 'prediction'));
2126
+ worstCaseLiabilityValue = (0, margin_1.calculatePerpLiabilityValue)(perpPosition.baseAssetAmount, oraclePrice);
2162
2127
  }
2163
2128
  const userCustomMargin = Math.max(perpPosition.maxMarginRatio, this.getUserAccount().maxMarginRatio);
2164
- const marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(perpMarket, worstCaseBaseAmount.abs(), marginCategory, userCustomMargin, this.isHighLeverageMode(marginCategory)));
2129
+ const marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(perpMarket, worstCaseBaseAmount.abs(), marginCategory, userCustomMargin));
2165
2130
  const _quoteOraclePriceData = quoteOraclePriceData ||
2166
2131
  this.driftClient.getOracleDataForSpotMarket(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
2167
2132
  let marginRequirement = worstCaseLiabilityValue
@@ -2317,23 +2282,22 @@ class User {
2317
2282
  * Consumers can use this to avoid duplicating work across separate calls.
2318
2283
  */
2319
2284
  getMarginCalculation(marginCategory = 'Initial', opts) {
2320
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2285
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2321
2286
  const strict = (_a = opts === null || opts === void 0 ? void 0 : opts.strict) !== null && _a !== void 0 ? _a : false;
2322
- const enteringHighLeverage = (_b = opts === null || opts === void 0 ? void 0 : opts.enteringHighLeverage) !== null && _b !== void 0 ? _b : false;
2323
- const liquidationBufferMap = (_c = opts === null || opts === void 0 ? void 0 : opts.liquidationBufferMap) !== null && _c !== void 0 ? _c : new Map();
2324
- const includeOpenOrders = (_d = opts === null || opts === void 0 ? void 0 : opts.includeOpenOrders) !== null && _d !== void 0 ? _d : true;
2287
+ const liquidationBufferMap = (_b = opts === null || opts === void 0 ? void 0 : opts.liquidationBufferMap) !== null && _b !== void 0 ? _b : new Map();
2288
+ const includeOpenOrders = (_c = opts === null || opts === void 0 ? void 0 : opts.includeOpenOrders) !== null && _c !== void 0 ? _c : true;
2325
2289
  // Equivalent to on-chain user_custom_margin_ratio
2326
2290
  const userCustomMarginRatio = marginCategory === 'Initial' ? this.getUserAccount().maxMarginRatio : 0;
2327
2291
  // Initialize calc via JS mirror of Rust/on-chain MarginCalculation
2328
2292
  const isolatedMarginBuffers = new Map();
2329
- for (const [marketIndex, isolatedMarginBuffer,] of (_e = opts === null || opts === void 0 ? void 0 : opts.liquidationBufferMap) !== null && _e !== void 0 ? _e : new Map()) {
2293
+ for (const [marketIndex, isolatedMarginBuffer,] of (_d = opts === null || opts === void 0 ? void 0 : opts.liquidationBufferMap) !== null && _d !== void 0 ? _d : new Map()) {
2330
2294
  if (marketIndex !== 'cross') {
2331
2295
  isolatedMarginBuffers.set(marketIndex, isolatedMarginBuffer);
2332
2296
  }
2333
2297
  }
2334
2298
  const ctx = marginCalculation_1.MarginContext.standard(marginCategory)
2335
2299
  .strictMode(strict)
2336
- .setCrossMarginBuffer((_g = (_f = opts === null || opts === void 0 ? void 0 : opts.liquidationBufferMap) === null || _f === void 0 ? void 0 : _f.get('cross')) !== null && _g !== void 0 ? _g : numericConstants_1.ZERO)
2300
+ .setCrossMarginBuffer((_f = (_e = opts === null || opts === void 0 ? void 0 : opts.liquidationBufferMap) === null || _e === void 0 ? void 0 : _e.get('cross')) !== null && _f !== void 0 ? _f : numericConstants_1.ZERO)
2337
2301
  .setIsolatedMarginBuffers(isolatedMarginBuffers);
2338
2302
  const calc = new marginCalculation_1.MarginCalculation(ctx);
2339
2303
  // SPOT POSITIONS
@@ -2356,7 +2320,7 @@ class User {
2356
2320
  }
2357
2321
  else {
2358
2322
  // borrow on quote contributes to margin requirement
2359
- const tokenValueAbs = this.getSpotLiabilityValue(tokenAmount, strictOracle, spotMarket, marginCategory, (_h = liquidationBufferMap.get('cross')) !== null && _h !== void 0 ? _h : new anchor_1.BN(0)).abs();
2323
+ const tokenValueAbs = this.getSpotLiabilityValue(tokenAmount, strictOracle, spotMarket, marginCategory, (_g = liquidationBufferMap.get('cross')) !== null && _g !== void 0 ? _g : new anchor_1.BN(0)).abs();
2360
2324
  calc.addCrossMarginRequirement(tokenValueAbs, tokenValueAbs);
2361
2325
  }
2362
2326
  continue;
@@ -2399,7 +2363,7 @@ class User {
2399
2363
  const { worstCaseBaseAssetAmount, worstCaseLiabilityValue } = (0, margin_1.calculateWorstCasePerpLiabilityValue)(marketPosition, market, nonMmmOraclePriceData.price, includeOpenOrders);
2400
2364
  // margin ratio for this perp
2401
2365
  const customMarginRatio = Math.max(userCustomMarginRatio, marketPosition.maxMarginRatio);
2402
- let marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(market, worstCaseBaseAssetAmount.abs(), marginCategory, customMarginRatio, this.isHighLeverageMode(marginCategory) || enteringHighLeverage));
2366
+ let marginRatio = new anchor_1.BN((0, market_1.calculateMarketMarginRatio)(market, worstCaseBaseAssetAmount.abs(), marginCategory, customMarginRatio));
2403
2367
  if ((0, types_1.isVariant)(market.status, 'settlement')) {
2404
2368
  marginRatio = numericConstants_1.ZERO;
2405
2369
  }
@@ -2443,13 +2407,13 @@ class User {
2443
2407
  if (isIsolated) {
2444
2408
  // derive isolated quote deposit value, mirroring on-chain logic
2445
2409
  let depositValue = numericConstants_1.ZERO;
2446
- if ((_j = marketPosition.isolatedPositionScaledBalance) === null || _j === void 0 ? void 0 : _j.gt(numericConstants_1.ZERO)) {
2410
+ if ((_h = marketPosition.isolatedPositionScaledBalance) === null || _h === void 0 ? void 0 : _h.gt(numericConstants_1.ZERO)) {
2447
2411
  const quoteSpotMarket = this.driftClient.getSpotMarketAccount(market.quoteSpotMarketIndex);
2448
2412
  const quoteOraclePriceData = this.getOracleDataForSpotMarket(market.quoteSpotMarketIndex);
2449
2413
  const strictQuote = new strictOraclePrice_1.StrictOraclePrice(quoteOraclePriceData.price, strict
2450
2414
  ? quoteSpotMarket.historicalOracleData.lastOraclePriceTwap5Min
2451
2415
  : undefined);
2452
- const quoteTokenAmount = (0, spotBalance_2.getTokenAmount)((_k = marketPosition.isolatedPositionScaledBalance) !== null && _k !== void 0 ? _k : numericConstants_1.ZERO, quoteSpotMarket, types_2.SpotBalanceType.DEPOSIT);
2416
+ const quoteTokenAmount = (0, spotBalance_2.getTokenAmount)((_j = marketPosition.isolatedPositionScaledBalance) !== null && _j !== void 0 ? _j : numericConstants_1.ZERO, quoteSpotMarket, types_2.SpotBalanceType.DEPOSIT);
2453
2417
  depositValue = (0, spotBalance_1.getStrictTokenValue)(quoteTokenAmount, quoteSpotMarket.decimals, strictQuote);
2454
2418
  }
2455
2419
  calc.addIsolatedMarginCalculation(market.marketIndex, depositValue, positionUnrealizedPnl, worstCaseLiabilityValue, perpMarginRequirement);
@@ -22,7 +22,7 @@ class WebsocketSubscription {
22
22
  if (this.additionalFilters) {
23
23
  filters.push(...this.additionalFilters);
24
24
  }
25
- this.subscriber = new webSocketProgramAccountSubscriber_1.WebSocketProgramAccountSubscriber('UserMap', 'User', this.userMap.driftClient.program, this.decodeFn, {
25
+ this.subscriber = new webSocketProgramAccountSubscriber_1.WebSocketProgramAccountSubscriber('UserMap', 'user', this.userMap.driftClient.program, this.decodeFn, {
26
26
  filters,
27
27
  commitment: this.commitment,
28
28
  }, this.resubOpts);
@@ -22,7 +22,7 @@ class grpcSubscription {
22
22
  if (this.additionalFilters) {
23
23
  filters.push(...this.additionalFilters);
24
24
  }
25
- this.subscriber = await grpcProgramAccountSubscriber_1.grpcProgramAccountSubscriber.create(this.grpcConfigs, 'UserMap', 'User', this.userMap.driftClient.program, this.decodeFn, {
25
+ this.subscriber = await grpcProgramAccountSubscriber_1.grpcProgramAccountSubscriber.create(this.grpcConfigs, 'UserMap', 'user', this.userMap.driftClient.program, this.decodeFn, {
26
26
  filters,
27
27
  }, this.resubOpts);
28
28
  }
@@ -1 +1 @@
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D;;OAEG;IACI,oBAAoB,IAAI,GAAG,CAAC,MAAM,EAAE,yBAAyB,CAAC;IAUrE;;OAEG;IACI,aAAa,CACnB,iBAAiB,EAAE,MAAM,GACvB,yBAAyB,GAAG,SAAS;IASxC;;OAEG;IACI,gBAAgB,CACtB,iBAAiB,EAAE,MAAM,GACvB,yBAAyB,EAAE;IAUjB,WAAW;CAGxB"}
@@ -52,7 +52,7 @@ class RevenueShareEscrowMap {
52
52
  try {
53
53
  const accountInfo = await this.driftClient.connection.getAccountInfo(escrowAccountPublicKey, 'processed');
54
54
  if (accountInfo && accountInfo.data) {
55
- const escrow = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('RevenueShareEscrow', accountInfo.data);
55
+ const escrow = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('revenueShareEscrow', accountInfo.data);
56
56
  this.authorityEscrowMap.set(authority, escrow);
57
57
  }
58
58
  }
@@ -89,7 +89,7 @@ class RevenueShareEscrowMap {
89
89
  }
90
90
  for (const authority of this.authorityEscrowMap.keys()) {
91
91
  const accountInfo = await this.driftClient.connection.getAccountInfo((0, pda_1.getRevenueShareEscrowAccountPublicKey)(this.driftClient.program.programId, new web3_js_1.PublicKey(authority)), 'confirmed');
92
- const escrowNew = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('RevenueShareEscrow', accountInfo.data);
92
+ const escrowNew = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('revenueShareEscrow', accountInfo.data);
93
93
  this.authorityEscrowMap.set(authority, escrowNew);
94
94
  }
95
95
  }
@@ -115,7 +115,7 @@ class RevenueShareEscrowMap {
115
115
  try {
116
116
  // @ts-ignore
117
117
  const buffer = Buffer.from(programAccount.account.data[0], programAccount.account.data[1]);
118
- const escrow = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('RevenueShareEscrow', buffer);
118
+ const escrow = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('revenueShareEscrow', buffer);
119
119
  // Extract authority from the account data
120
120
  const authorityKey = escrow.authority.toBase58();
121
121
  this.authorityEscrowMap.set(authorityKey, escrow);
@@ -130,7 +130,7 @@ class RevenueShareEscrowMap {
130
130
  try {
131
131
  // @ts-ignore
132
132
  const buffer = Buffer.from(programAccount.account.data[0], programAccount.account.data[1]);
133
- const escrow = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('RevenueShareEscrow', buffer);
133
+ const escrow = this.driftClient.program.account.revenueShareEscrow.coder.accounts.decode('revenueShareEscrow', buffer);
134
134
  // Extract authority from the account data
135
135
  const authorityKey = escrow.authority.toBase58();
136
136
  this.authorityEscrowMap.set(authorityKey, escrow);
@@ -1 +1 @@
1
- {"version":3,"file":"userMap.d.ts","sourceRoot":"","sources":["../../../src/userMap/userMap.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACN,WAAW,EACX,WAAW,EASX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAIN,SAAS,EAET,MAAM,iBAAiB,CAAC;AAQzB,OAAO,EAEN,yBAAyB,IAAI,kBAAkB,EAC/C,aAAa,EACb,MAAM,iBAAiB,CAAC;AAKzB,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC,MAAM,WAAW,gBAAgB;IAChC,YAAY,EAAE,kBAAkB,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IAC3D,SAAS,IA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jC,SAAS,EAAE;IAmBD,IAAI;IAQjB,OAAO,CAAC,UAAU;IAclB;;;;OAIG;YACW,WAAW;IA4FzB;;;;OAIG;YACW,aAAa;IAqHd,WAAW;IAoBX,iBAAiB,CAC7B,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,MAAM;IAkBb,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI7B,OAAO,IAAI,MAAM;CAGxB"}
@@ -50,8 +50,7 @@ class UserMap {
50
50
  decodeFn = (name, buffer) => (0, user_2.decodeUser)(buffer);
51
51
  }
52
52
  else {
53
- decodeFn =
54
- this.driftClient.program.account.user.coder.accounts.decodeUnchecked.bind(this.driftClient.program.account.user.coder.accounts);
53
+ decodeFn = this.driftClient.program.account.user.coder.accounts.decodeUnchecked.bind(this.driftClient.program.account.user.coder.accounts);
55
54
  }
56
55
  this.decode = decodeFn;
57
56
  if (config.subscriptionConfig.type === 'polling') {
@@ -323,12 +322,12 @@ class UserMap {
323
322
  const currAccountWithSlot = this.getWithSlot(key);
324
323
  if (currAccountWithSlot) {
325
324
  if (slot >= currAccountWithSlot.slot) {
326
- const userAccount = this.decode('User', buffer);
325
+ const userAccount = this.decode('user', buffer);
327
326
  this.updateUserAccount(key, userAccount, slot);
328
327
  }
329
328
  }
330
329
  else {
331
- const userAccount = this.decode('User', buffer);
330
+ const userAccount = this.decode('user', buffer);
332
331
  await this.addPubkey(new web3_js_1.PublicKey(key), userAccount, slot);
333
332
  }
334
333
  })());
@@ -413,7 +412,7 @@ class UserMap {
413
412
  const publicKeyString = chunk[j].toString();
414
413
  const buffer = buffer_1.Buffer.from(accountInfo.data);
415
414
  programAccountBufferMap.set(publicKeyString, buffer);
416
- const decodedUser = this.decode('User', buffer);
415
+ const decodedUser = this.decode('user', buffer);
417
416
  const currAccountWithSlot = this.getWithSlot(publicKeyString);
418
417
  if (currAccountWithSlot &&
419
418
  currAccountWithSlot.slot <= accountInfosSlot) {
@@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CAAC,WAAW,EAAE,SAAS,EAAE;IAS/C;;;;;OAKG;IACU,WAAW,CACvB,SAAS,EAAE,SAAS,EACpB,gBAAgB,CAAC,EAAE,gBAAgB,EACnC,SAAS,CAAC,EAAE,OAAO;IAwBP,qBAAqB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO;IAO3D,qBAAqB,CACjC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,EACzB,OAAO,CAAC,EAAE,OAAO;IAiEX,GAAG,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO;IAIxC,GAAG,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS;IAIjD;;;;;OAKG;IACU,OAAO,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAW7D,MAAM,IAAI,gBAAgB,CAAC,SAAS,CAAC;IAIrC,IAAI,IAAI,MAAM;IAIrB;;;;OAIG;IACU,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE;IAQ1C;;;;OAIG;YACW,WAAW;IASzB;;;OAGG;YACW,aAAa;IA8Gd,WAAW;CAMxB"}
@@ -26,8 +26,7 @@ class UserStatsMap {
26
26
  this.syncConfig = syncConfig !== null && syncConfig !== void 0 ? syncConfig : {
27
27
  type: 'default',
28
28
  };
29
- this.decode =
30
- this.driftClient.program.account.userStats.coder.accounts.decodeUnchecked.bind(this.driftClient.program.account.userStats.coder.accounts);
29
+ this.decode = this.driftClient.program.account.userStats.coder.accounts.decodeUnchecked.bind(this.driftClient.program.account.userStats.coder.accounts);
31
30
  }
32
31
  async subscribe(authorities) {
33
32
  if (this.size() > 0) {
@@ -235,7 +234,7 @@ class UserStatsMap {
235
234
  const publicKeyString = chunk[j].toString();
236
235
  if (!this.has(publicKeyString)) {
237
236
  const buffer = Buffer.from(accountInfo.data);
238
- const decodedUserStats = this.decode('UserStats', buffer);
237
+ const decodedUserStats = this.decode('userStats', buffer);
239
238
  programAccountBufferMap.add(decodedUserStats.authority.toBase58());
240
239
  this.addUserStat(decodedUserStats.authority, decodedUserStats, false);
241
240
  }