@whetstone-research/doppler-sdk 0.0.24 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (445) hide show
  1. package/README.md +69 -0
  2. package/dist/chunk-3LTCKCJC.js +319 -0
  3. package/dist/chunk-3LTCKCJC.js.map +1 -0
  4. package/dist/chunk-PZ5AY32C.js +9 -0
  5. package/dist/{chunk-4XN6DQBW.js.map → chunk-PZ5AY32C.js.map} +1 -1
  6. package/dist/chunk-RO6R66OM.js +974 -0
  7. package/dist/chunk-RO6R66OM.js.map +1 -0
  8. package/dist/evm/index.d.ts +8533 -0
  9. package/dist/evm/index.js +15055 -0
  10. package/dist/evm/index.js.map +1 -0
  11. package/dist/oracle-BSvZ6pxp.d.ts +820 -0
  12. package/dist/pda-RVIHNLRP.js +4 -0
  13. package/dist/pda-RVIHNLRP.js.map +1 -0
  14. package/dist/solana/index.d.ts +2495 -0
  15. package/dist/solana/index.js +2209 -0
  16. package/dist/solana/index.js.map +1 -0
  17. package/dist/solana/react/index.d.ts +1046 -0
  18. package/dist/solana/react/index.js +1436 -0
  19. package/dist/solana/react/index.js.map +1 -0
  20. package/package.json +36 -20
  21. package/dist/DopplerSDK.d.mts +0 -106
  22. package/dist/DopplerSDK.d.ts +0 -106
  23. package/dist/DopplerSDK.js +0 -53
  24. package/dist/DopplerSDK.js.map +0 -1
  25. package/dist/DopplerSDK.mjs +0 -44
  26. package/dist/DopplerSDK.mjs.map +0 -1
  27. package/dist/abis/bytecodes/derc20.d.mts +0 -3
  28. package/dist/abis/bytecodes/derc20.d.ts +0 -3
  29. package/dist/abis/bytecodes/derc20.js +0 -9
  30. package/dist/abis/bytecodes/derc20.js.map +0 -1
  31. package/dist/abis/bytecodes/derc20.mjs +0 -3
  32. package/dist/abis/bytecodes/derc20.mjs.map +0 -1
  33. package/dist/abis/bytecodes/derc2080.d.mts +0 -3
  34. package/dist/abis/bytecodes/derc2080.d.ts +0 -3
  35. package/dist/abis/bytecodes/derc2080.js +0 -9
  36. package/dist/abis/bytecodes/derc2080.js.map +0 -1
  37. package/dist/abis/bytecodes/derc2080.mjs +0 -3
  38. package/dist/abis/bytecodes/derc2080.mjs.map +0 -1
  39. package/dist/abis/bytecodes/doppler.d.mts +0 -3
  40. package/dist/abis/bytecodes/doppler.d.ts +0 -3
  41. package/dist/abis/bytecodes/doppler.js +0 -9
  42. package/dist/abis/bytecodes/doppler.js.map +0 -1
  43. package/dist/abis/bytecodes/doppler.mjs +0 -3
  44. package/dist/abis/bytecodes/doppler.mjs.map +0 -1
  45. package/dist/abis/bytecodes/dopplerDN404.d.mts +0 -3
  46. package/dist/abis/bytecodes/dopplerDN404.d.ts +0 -3
  47. package/dist/abis/bytecodes/dopplerDN404.js +0 -9
  48. package/dist/abis/bytecodes/dopplerDN404.js.map +0 -1
  49. package/dist/abis/bytecodes/dopplerDN404.mjs +0 -3
  50. package/dist/abis/bytecodes/dopplerDN404.mjs.map +0 -1
  51. package/dist/abis/bytecodes/stateView.d.mts +0 -3
  52. package/dist/abis/bytecodes/stateView.d.ts +0 -3
  53. package/dist/abis/bytecodes/stateView.js +0 -9
  54. package/dist/abis/bytecodes/stateView.js.map +0 -1
  55. package/dist/abis/bytecodes/stateView.mjs +0 -3
  56. package/dist/abis/bytecodes/stateView.mjs.map +0 -1
  57. package/dist/abis/bytecodes.d.mts +0 -5
  58. package/dist/abis/bytecodes.d.ts +0 -5
  59. package/dist/abis/bytecodes.js +0 -33
  60. package/dist/abis/bytecodes.js.map +0 -1
  61. package/dist/abis/bytecodes.mjs +0 -8
  62. package/dist/abis/bytecodes.mjs.map +0 -1
  63. package/dist/abis/index.d.mts +0 -3871
  64. package/dist/abis/index.d.ts +0 -3871
  65. package/dist/abis/index.js +0 -130
  66. package/dist/abis/index.js.map +0 -1
  67. package/dist/abis/index.mjs +0 -9
  68. package/dist/abis/index.mjs.map +0 -1
  69. package/dist/addresses.d.mts +0 -69
  70. package/dist/addresses.d.ts +0 -69
  71. package/dist/addresses.js +0 -29
  72. package/dist/addresses.js.map +0 -1
  73. package/dist/addresses.mjs +0 -4
  74. package/dist/addresses.mjs.map +0 -1
  75. package/dist/builders/DynamicAuctionBuilder.d.mts +0 -138
  76. package/dist/builders/DynamicAuctionBuilder.d.ts +0 -138
  77. package/dist/builders/DynamicAuctionBuilder.js +0 -35
  78. package/dist/builders/DynamicAuctionBuilder.js.map +0 -1
  79. package/dist/builders/DynamicAuctionBuilder.mjs +0 -26
  80. package/dist/builders/DynamicAuctionBuilder.mjs.map +0 -1
  81. package/dist/builders/MulticurveBuilder.d.mts +0 -196
  82. package/dist/builders/MulticurveBuilder.d.ts +0 -196
  83. package/dist/builders/MulticurveBuilder.js +0 -35
  84. package/dist/builders/MulticurveBuilder.js.map +0 -1
  85. package/dist/builders/MulticurveBuilder.mjs +0 -26
  86. package/dist/builders/MulticurveBuilder.mjs.map +0 -1
  87. package/dist/builders/StaticAuctionBuilder.d.mts +0 -131
  88. package/dist/builders/StaticAuctionBuilder.d.ts +0 -131
  89. package/dist/builders/StaticAuctionBuilder.js +0 -35
  90. package/dist/builders/StaticAuctionBuilder.js.map +0 -1
  91. package/dist/builders/StaticAuctionBuilder.mjs +0 -26
  92. package/dist/builders/StaticAuctionBuilder.mjs.map +0 -1
  93. package/dist/builders/index.d.mts +0 -8
  94. package/dist/builders/index.d.ts +0 -8
  95. package/dist/builders/index.js +0 -62
  96. package/dist/builders/index.js.map +0 -1
  97. package/dist/builders/index.mjs +0 -29
  98. package/dist/builders/index.mjs.map +0 -1
  99. package/dist/builders/shared.d.mts +0 -115
  100. package/dist/builders/shared.d.ts +0 -115
  101. package/dist/builders/shared.js +0 -46
  102. package/dist/builders/shared.js.map +0 -1
  103. package/dist/builders/shared.mjs +0 -25
  104. package/dist/builders/shared.mjs.map +0 -1
  105. package/dist/chunk-25GEBO3B.mjs +0 -219
  106. package/dist/chunk-25GEBO3B.mjs.map +0 -1
  107. package/dist/chunk-2A3B3NVB.js +0 -737
  108. package/dist/chunk-2A3B3NVB.js.map +0 -1
  109. package/dist/chunk-3NMGCQJ4.mjs +0 -6
  110. package/dist/chunk-3NMGCQJ4.mjs.map +0 -1
  111. package/dist/chunk-44CYUEPG.js +0 -377
  112. package/dist/chunk-44CYUEPG.js.map +0 -1
  113. package/dist/chunk-4VWQNNNW.js +0 -233
  114. package/dist/chunk-4VWQNNNW.js.map +0 -1
  115. package/dist/chunk-4XN6DQBW.js +0 -4
  116. package/dist/chunk-5GQJRNFL.mjs +0 -40
  117. package/dist/chunk-5GQJRNFL.mjs.map +0 -1
  118. package/dist/chunk-5JHXBDZD.js +0 -265
  119. package/dist/chunk-5JHXBDZD.js.map +0 -1
  120. package/dist/chunk-5TQOT6CW.js +0 -8
  121. package/dist/chunk-5TQOT6CW.js.map +0 -1
  122. package/dist/chunk-65CESA3J.js +0 -46
  123. package/dist/chunk-65CESA3J.js.map +0 -1
  124. package/dist/chunk-6BQY5EPB.js +0 -144
  125. package/dist/chunk-6BQY5EPB.js.map +0 -1
  126. package/dist/chunk-6H6X3VTZ.js +0 -18
  127. package/dist/chunk-6H6X3VTZ.js.map +0 -1
  128. package/dist/chunk-7A4DBBXA.js +0 -311
  129. package/dist/chunk-7A4DBBXA.js.map +0 -1
  130. package/dist/chunk-7M57PU6V.js +0 -28
  131. package/dist/chunk-7M57PU6V.js.map +0 -1
  132. package/dist/chunk-7ZUV6WPX.mjs +0 -3
  133. package/dist/chunk-7ZUV6WPX.mjs.map +0 -1
  134. package/dist/chunk-A2CJYRRQ.js +0 -330
  135. package/dist/chunk-A2CJYRRQ.js.map +0 -1
  136. package/dist/chunk-ABT6AT7C.mjs +0 -16
  137. package/dist/chunk-ABT6AT7C.mjs.map +0 -1
  138. package/dist/chunk-BK3S6SVR.js +0 -2707
  139. package/dist/chunk-BK3S6SVR.js.map +0 -1
  140. package/dist/chunk-BQZTELUX.js +0 -45
  141. package/dist/chunk-BQZTELUX.js.map +0 -1
  142. package/dist/chunk-CFAAYL5M.mjs +0 -26
  143. package/dist/chunk-CFAAYL5M.mjs.map +0 -1
  144. package/dist/chunk-CFXXUZJY.js +0 -275
  145. package/dist/chunk-CFXXUZJY.js.map +0 -1
  146. package/dist/chunk-CWTGQAOG.mjs +0 -72
  147. package/dist/chunk-CWTGQAOG.mjs.map +0 -1
  148. package/dist/chunk-DCWF3EMP.js +0 -171
  149. package/dist/chunk-DCWF3EMP.js.map +0 -1
  150. package/dist/chunk-DOUF6NON.mjs +0 -3
  151. package/dist/chunk-DOUF6NON.mjs.map +0 -1
  152. package/dist/chunk-DQJXCZU2.mjs +0 -318
  153. package/dist/chunk-DQJXCZU2.mjs.map +0 -1
  154. package/dist/chunk-DSYPZETD.js +0 -4
  155. package/dist/chunk-DSYPZETD.js.map +0 -1
  156. package/dist/chunk-F2BYG63D.mjs +0 -145
  157. package/dist/chunk-F2BYG63D.mjs.map +0 -1
  158. package/dist/chunk-FNUBKONK.js +0 -291
  159. package/dist/chunk-FNUBKONK.js.map +0 -1
  160. package/dist/chunk-FOESYJP3.mjs +0 -3
  161. package/dist/chunk-FOESYJP3.mjs.map +0 -1
  162. package/dist/chunk-FXTGIKQG.mjs +0 -3
  163. package/dist/chunk-FXTGIKQG.mjs.map +0 -1
  164. package/dist/chunk-GSBQIVME.mjs +0 -278
  165. package/dist/chunk-GSBQIVME.mjs.map +0 -1
  166. package/dist/chunk-H3B54PFV.mjs +0 -17
  167. package/dist/chunk-H3B54PFV.mjs.map +0 -1
  168. package/dist/chunk-HJFVRV47.js +0 -120
  169. package/dist/chunk-HJFVRV47.js.map +0 -1
  170. package/dist/chunk-IIM2CSDQ.js +0 -147
  171. package/dist/chunk-IIM2CSDQ.js.map +0 -1
  172. package/dist/chunk-IUTIHSLH.mjs +0 -295
  173. package/dist/chunk-IUTIHSLH.mjs.map +0 -1
  174. package/dist/chunk-IUZ3BBQP.mjs +0 -117
  175. package/dist/chunk-IUZ3BBQP.mjs.map +0 -1
  176. package/dist/chunk-IWJOPXYN.mjs +0 -96
  177. package/dist/chunk-IWJOPXYN.mjs.map +0 -1
  178. package/dist/chunk-IX4V4UGW.mjs +0 -141
  179. package/dist/chunk-IX4V4UGW.mjs.map +0 -1
  180. package/dist/chunk-J62YDWIK.js +0 -8
  181. package/dist/chunk-J62YDWIK.js.map +0 -1
  182. package/dist/chunk-JIKAD4YL.js +0 -4
  183. package/dist/chunk-JIKAD4YL.js.map +0 -1
  184. package/dist/chunk-JLUOFAE4.mjs +0 -2531
  185. package/dist/chunk-JLUOFAE4.mjs.map +0 -1
  186. package/dist/chunk-KAZQJ24E.mjs +0 -59
  187. package/dist/chunk-KAZQJ24E.mjs.map +0 -1
  188. package/dist/chunk-KHUE77HC.js +0 -81
  189. package/dist/chunk-KHUE77HC.js.map +0 -1
  190. package/dist/chunk-KOAC3BBP.mjs +0 -11
  191. package/dist/chunk-KOAC3BBP.mjs.map +0 -1
  192. package/dist/chunk-LW3CYA27.mjs +0 -2705
  193. package/dist/chunk-LW3CYA27.mjs.map +0 -1
  194. package/dist/chunk-MEA2C5YX.js +0 -143
  195. package/dist/chunk-MEA2C5YX.js.map +0 -1
  196. package/dist/chunk-MU56HCUI.js +0 -2556
  197. package/dist/chunk-MU56HCUI.js.map +0 -1
  198. package/dist/chunk-OCIY7QEJ.mjs +0 -169
  199. package/dist/chunk-OCIY7QEJ.mjs.map +0 -1
  200. package/dist/chunk-OHA5KJ2M.mjs +0 -6
  201. package/dist/chunk-OHA5KJ2M.mjs.map +0 -1
  202. package/dist/chunk-P25HBGP5.mjs +0 -3
  203. package/dist/chunk-P25HBGP5.mjs.map +0 -1
  204. package/dist/chunk-P563HTVU.js +0 -164
  205. package/dist/chunk-P563HTVU.js.map +0 -1
  206. package/dist/chunk-P7CHGWY7.js +0 -4
  207. package/dist/chunk-P7CHGWY7.js.map +0 -1
  208. package/dist/chunk-PGYTMRP3.js +0 -277
  209. package/dist/chunk-PGYTMRP3.js.map +0 -1
  210. package/dist/chunk-QAPQGDWK.js +0 -8
  211. package/dist/chunk-QAPQGDWK.js.map +0 -1
  212. package/dist/chunk-QHBKRUBY.mjs +0 -328
  213. package/dist/chunk-QHBKRUBY.mjs.map +0 -1
  214. package/dist/chunk-QOYI7WCH.js +0 -120
  215. package/dist/chunk-QOYI7WCH.js.map +0 -1
  216. package/dist/chunk-QRTABC4Z.js +0 -8
  217. package/dist/chunk-QRTABC4Z.js.map +0 -1
  218. package/dist/chunk-QSQGLWNY.mjs +0 -3
  219. package/dist/chunk-QSQGLWNY.mjs.map +0 -1
  220. package/dist/chunk-QUBD6HUZ.mjs +0 -735
  221. package/dist/chunk-QUBD6HUZ.mjs.map +0 -1
  222. package/dist/chunk-RDTIXP6S.mjs +0 -263
  223. package/dist/chunk-RDTIXP6S.mjs.map +0 -1
  224. package/dist/chunk-RLOZWHRR.js +0 -320
  225. package/dist/chunk-RLOZWHRR.js.map +0 -1
  226. package/dist/chunk-RV64M4Q6.mjs +0 -3
  227. package/dist/chunk-RV64M4Q6.mjs.map +0 -1
  228. package/dist/chunk-SWWLOD7Q.mjs +0 -6
  229. package/dist/chunk-SWWLOD7Q.mjs.map +0 -1
  230. package/dist/chunk-T3UA4MJL.js +0 -4
  231. package/dist/chunk-T3UA4MJL.js.map +0 -1
  232. package/dist/chunk-TEWAXP5C.mjs +0 -162
  233. package/dist/chunk-TEWAXP5C.mjs.map +0 -1
  234. package/dist/chunk-THEIRDGE.mjs +0 -273
  235. package/dist/chunk-THEIRDGE.mjs.map +0 -1
  236. package/dist/chunk-U3GOWK6J.mjs +0 -6
  237. package/dist/chunk-U3GOWK6J.mjs.map +0 -1
  238. package/dist/chunk-UPVKABAV.js +0 -19
  239. package/dist/chunk-UPVKABAV.js.map +0 -1
  240. package/dist/chunk-VEIVYUYF.js +0 -4
  241. package/dist/chunk-VEIVYUYF.js.map +0 -1
  242. package/dist/chunk-VKSD3KXF.mjs +0 -275
  243. package/dist/chunk-VKSD3KXF.mjs.map +0 -1
  244. package/dist/chunk-VYSOAGRU.mjs +0 -6
  245. package/dist/chunk-VYSOAGRU.mjs.map +0 -1
  246. package/dist/chunk-WDC53TM7.mjs +0 -305
  247. package/dist/chunk-WDC53TM7.mjs.map +0 -1
  248. package/dist/chunk-WKWP42TD.mjs +0 -39
  249. package/dist/chunk-WKWP42TD.mjs.map +0 -1
  250. package/dist/chunk-WNUB3UTT.js +0 -241
  251. package/dist/chunk-WNUB3UTT.js.map +0 -1
  252. package/dist/chunk-WNWK2QMU.mjs +0 -375
  253. package/dist/chunk-WNWK2QMU.mjs.map +0 -1
  254. package/dist/chunk-WQHTNL5L.js +0 -4
  255. package/dist/chunk-WQHTNL5L.js.map +0 -1
  256. package/dist/chunk-WZF5XNBC.js +0 -297
  257. package/dist/chunk-WZF5XNBC.js.map +0 -1
  258. package/dist/chunk-X3UMAHOJ.js +0 -4
  259. package/dist/chunk-X3UMAHOJ.js.map +0 -1
  260. package/dist/chunk-XMFOZYNI.js +0 -8
  261. package/dist/chunk-XMFOZYNI.js.map +0 -1
  262. package/dist/chunk-XNMXN5SZ.mjs +0 -3
  263. package/dist/chunk-XNMXN5SZ.mjs.map +0 -1
  264. package/dist/chunk-XSJTASPK.js +0 -13
  265. package/dist/chunk-XSJTASPK.js.map +0 -1
  266. package/dist/chunk-YBK6EBA5.mjs +0 -239
  267. package/dist/chunk-YBK6EBA5.mjs.map +0 -1
  268. package/dist/chunk-YYLD3AJ7.js +0 -61
  269. package/dist/chunk-YYLD3AJ7.js.map +0 -1
  270. package/dist/chunk-ZEDJUNC6.mjs +0 -115
  271. package/dist/chunk-ZEDJUNC6.mjs.map +0 -1
  272. package/dist/constants.d.mts +0 -91
  273. package/dist/constants.d.ts +0 -91
  274. package/dist/constants.js +0 -196
  275. package/dist/constants.js.map +0 -1
  276. package/dist/constants.mjs +0 -3
  277. package/dist/constants.mjs.map +0 -1
  278. package/dist/deployments.generated.d.mts +0 -275
  279. package/dist/deployments.generated.d.ts +0 -275
  280. package/dist/deployments.generated.js +0 -12
  281. package/dist/deployments.generated.js.map +0 -1
  282. package/dist/deployments.generated.mjs +0 -3
  283. package/dist/deployments.generated.mjs.map +0 -1
  284. package/dist/entities/DopplerFactory.d.mts +0 -272
  285. package/dist/entities/DopplerFactory.d.ts +0 -272
  286. package/dist/entities/DopplerFactory.js +0 -34
  287. package/dist/entities/DopplerFactory.js.map +0 -1
  288. package/dist/entities/DopplerFactory.mjs +0 -25
  289. package/dist/entities/DopplerFactory.mjs.map +0 -1
  290. package/dist/entities/auction/DynamicAuction.d.mts +0 -72
  291. package/dist/entities/auction/DynamicAuction.d.ts +0 -72
  292. package/dist/entities/auction/DynamicAuction.js +0 -21
  293. package/dist/entities/auction/DynamicAuction.js.map +0 -1
  294. package/dist/entities/auction/DynamicAuction.mjs +0 -12
  295. package/dist/entities/auction/DynamicAuction.mjs.map +0 -1
  296. package/dist/entities/auction/MulticurvePool.d.mts +0 -78
  297. package/dist/entities/auction/MulticurvePool.d.ts +0 -78
  298. package/dist/entities/auction/MulticurvePool.js +0 -24
  299. package/dist/entities/auction/MulticurvePool.js.map +0 -1
  300. package/dist/entities/auction/MulticurvePool.mjs +0 -15
  301. package/dist/entities/auction/MulticurvePool.mjs.map +0 -1
  302. package/dist/entities/auction/RehypeDopplerHook.d.mts +0 -57
  303. package/dist/entities/auction/RehypeDopplerHook.d.ts +0 -57
  304. package/dist/entities/auction/RehypeDopplerHook.js +0 -34
  305. package/dist/entities/auction/RehypeDopplerHook.js.map +0 -1
  306. package/dist/entities/auction/RehypeDopplerHook.mjs +0 -25
  307. package/dist/entities/auction/RehypeDopplerHook.mjs.map +0 -1
  308. package/dist/entities/auction/RehypeDopplerHookMigrator.d.mts +0 -48
  309. package/dist/entities/auction/RehypeDopplerHookMigrator.d.ts +0 -48
  310. package/dist/entities/auction/RehypeDopplerHookMigrator.js +0 -34
  311. package/dist/entities/auction/RehypeDopplerHookMigrator.js.map +0 -1
  312. package/dist/entities/auction/RehypeDopplerHookMigrator.mjs +0 -25
  313. package/dist/entities/auction/RehypeDopplerHookMigrator.mjs.map +0 -1
  314. package/dist/entities/auction/StaticAuction.d.mts +0 -44
  315. package/dist/entities/auction/StaticAuction.d.ts +0 -44
  316. package/dist/entities/auction/StaticAuction.js +0 -21
  317. package/dist/entities/auction/StaticAuction.js.map +0 -1
  318. package/dist/entities/auction/StaticAuction.mjs +0 -12
  319. package/dist/entities/auction/StaticAuction.mjs.map +0 -1
  320. package/dist/entities/auction/index.d.mts +0 -9
  321. package/dist/entities/auction/index.d.ts +0 -9
  322. package/dist/entities/auction/index.js +0 -55
  323. package/dist/entities/auction/index.js.map +0 -1
  324. package/dist/entities/auction/index.mjs +0 -30
  325. package/dist/entities/auction/index.mjs.map +0 -1
  326. package/dist/entities/quoter/Quoter.d.mts +0 -150
  327. package/dist/entities/quoter/Quoter.d.ts +0 -150
  328. package/dist/entities/quoter/Quoter.js +0 -21
  329. package/dist/entities/quoter/Quoter.js.map +0 -1
  330. package/dist/entities/quoter/Quoter.mjs +0 -12
  331. package/dist/entities/quoter/Quoter.mjs.map +0 -1
  332. package/dist/entities/quoter/index.d.mts +0 -5
  333. package/dist/entities/quoter/index.d.ts +0 -5
  334. package/dist/entities/quoter/index.js +0 -22
  335. package/dist/entities/quoter/index.js.map +0 -1
  336. package/dist/entities/quoter/index.mjs +0 -13
  337. package/dist/entities/quoter/index.mjs.map +0 -1
  338. package/dist/entities/token/derc20/Derc20.d.mts +0 -102
  339. package/dist/entities/token/derc20/Derc20.d.ts +0 -102
  340. package/dist/entities/token/derc20/Derc20.js +0 -19
  341. package/dist/entities/token/derc20/Derc20.js.map +0 -1
  342. package/dist/entities/token/derc20/Derc20.mjs +0 -10
  343. package/dist/entities/token/derc20/Derc20.mjs.map +0 -1
  344. package/dist/entities/token/derc20/index.d.mts +0 -5
  345. package/dist/entities/token/derc20/index.d.ts +0 -5
  346. package/dist/entities/token/derc20/index.js +0 -20
  347. package/dist/entities/token/derc20/index.js.map +0 -1
  348. package/dist/entities/token/derc20/index.mjs +0 -11
  349. package/dist/entities/token/derc20/index.mjs.map +0 -1
  350. package/dist/entities/token/eth/Eth.d.mts +0 -54
  351. package/dist/entities/token/eth/Eth.d.ts +0 -54
  352. package/dist/entities/token/eth/Eth.js +0 -12
  353. package/dist/entities/token/eth/Eth.js.map +0 -1
  354. package/dist/entities/token/eth/Eth.mjs +0 -3
  355. package/dist/entities/token/eth/Eth.mjs.map +0 -1
  356. package/dist/entities/token/eth/index.d.mts +0 -5
  357. package/dist/entities/token/eth/index.d.ts +0 -5
  358. package/dist/entities/token/eth/index.js +0 -13
  359. package/dist/entities/token/eth/index.js.map +0 -1
  360. package/dist/entities/token/eth/index.mjs +0 -4
  361. package/dist/entities/token/eth/index.mjs.map +0 -1
  362. package/dist/entities/token/index.d.mts +0 -6
  363. package/dist/entities/token/index.d.ts +0 -6
  364. package/dist/entities/token/index.js +0 -27
  365. package/dist/entities/token/index.js.map +0 -1
  366. package/dist/entities/token/index.mjs +0 -14
  367. package/dist/entities/token/index.mjs.map +0 -1
  368. package/dist/index.d.mts +0 -39
  369. package/dist/index.d.ts +0 -39
  370. package/dist/index.js +0 -587
  371. package/dist/index.js.map +0 -1
  372. package/dist/index.mjs +0 -49
  373. package/dist/index.mjs.map +0 -1
  374. package/dist/types.d.mts +0 -662
  375. package/dist/types.d.ts +0 -662
  376. package/dist/types.js +0 -34
  377. package/dist/types.js.map +0 -1
  378. package/dist/types.mjs +0 -5
  379. package/dist/types.mjs.map +0 -1
  380. package/dist/utils/airlock.d.mts +0 -11
  381. package/dist/utils/airlock.d.ts +0 -11
  382. package/dist/utils/airlock.js +0 -26
  383. package/dist/utils/airlock.js.map +0 -1
  384. package/dist/utils/airlock.mjs +0 -5
  385. package/dist/utils/airlock.mjs.map +0 -1
  386. package/dist/utils/balanceDelta.d.mts +0 -10
  387. package/dist/utils/balanceDelta.d.ts +0 -10
  388. package/dist/utils/balanceDelta.js +0 -12
  389. package/dist/utils/balanceDelta.js.map +0 -1
  390. package/dist/utils/balanceDelta.mjs +0 -3
  391. package/dist/utils/balanceDelta.mjs.map +0 -1
  392. package/dist/utils/computeOptimalGamma.d.mts +0 -7
  393. package/dist/utils/computeOptimalGamma.d.ts +0 -7
  394. package/dist/utils/computeOptimalGamma.js +0 -12
  395. package/dist/utils/computeOptimalGamma.js.map +0 -1
  396. package/dist/utils/computeOptimalGamma.mjs +0 -3
  397. package/dist/utils/computeOptimalGamma.mjs.map +0 -1
  398. package/dist/utils/dopplerHookMigrator.d.mts +0 -18
  399. package/dist/utils/dopplerHookMigrator.d.ts +0 -18
  400. package/dist/utils/dopplerHookMigrator.js +0 -20
  401. package/dist/utils/dopplerHookMigrator.js.map +0 -1
  402. package/dist/utils/dopplerHookMigrator.mjs +0 -7
  403. package/dist/utils/dopplerHookMigrator.mjs.map +0 -1
  404. package/dist/utils/index.d.mts +0 -14
  405. package/dist/utils/index.d.ts +0 -14
  406. package/dist/utils/index.js +0 -197
  407. package/dist/utils/index.js.map +0 -1
  408. package/dist/utils/index.mjs +0 -24
  409. package/dist/utils/index.mjs.map +0 -1
  410. package/dist/utils/isToken0Expected.d.mts +0 -13
  411. package/dist/utils/isToken0Expected.d.ts +0 -13
  412. package/dist/utils/isToken0Expected.js +0 -12
  413. package/dist/utils/isToken0Expected.js.map +0 -1
  414. package/dist/utils/isToken0Expected.mjs +0 -3
  415. package/dist/utils/isToken0Expected.mjs.map +0 -1
  416. package/dist/utils/marketCapHelpers.d.mts +0 -259
  417. package/dist/utils/marketCapHelpers.d.ts +0 -259
  418. package/dist/utils/marketCapHelpers.js +0 -58
  419. package/dist/utils/marketCapHelpers.js.map +0 -1
  420. package/dist/utils/marketCapHelpers.mjs +0 -5
  421. package/dist/utils/marketCapHelpers.mjs.map +0 -1
  422. package/dist/utils/poolKey.d.mts +0 -17
  423. package/dist/utils/poolKey.d.ts +0 -17
  424. package/dist/utils/poolKey.js +0 -12
  425. package/dist/utils/poolKey.js.map +0 -1
  426. package/dist/utils/poolKey.mjs +0 -3
  427. package/dist/utils/poolKey.mjs.map +0 -1
  428. package/dist/utils/priceHelpers.d.mts +0 -86
  429. package/dist/utils/priceHelpers.d.ts +0 -86
  430. package/dist/utils/priceHelpers.js +0 -41
  431. package/dist/utils/priceHelpers.js.map +0 -1
  432. package/dist/utils/priceHelpers.mjs +0 -4
  433. package/dist/utils/priceHelpers.mjs.map +0 -1
  434. package/dist/utils/tickMath.d.mts +0 -72
  435. package/dist/utils/tickMath.d.ts +0 -72
  436. package/dist/utils/tickMath.js +0 -60
  437. package/dist/utils/tickMath.js.map +0 -1
  438. package/dist/utils/tickMath.mjs +0 -3
  439. package/dist/utils/tickMath.mjs.map +0 -1
  440. package/dist/utils/tokenAddressMiner.d.mts +0 -37
  441. package/dist/utils/tokenAddressMiner.d.ts +0 -37
  442. package/dist/utils/tokenAddressMiner.js +0 -19
  443. package/dist/utils/tokenAddressMiner.js.map +0 -1
  444. package/dist/utils/tokenAddressMiner.mjs +0 -10
  445. package/dist/utils/tokenAddressMiner.mjs.map +0 -1
@@ -0,0 +1,1436 @@
1
+ import { fetchPool, getSwapQuote, getSwapQuoteExactOut, ratioToNumber, getAddLiquidityQuote, getRemoveLiquidityQuote, fetchPosition, getPendingFees, getPositionValue, fetchUserPositions, MAX_FEE_AMOUNT, createCollectFeesInstruction, fetchOracle, consultTwap, getOracleSpotPrices, getOracleDeviation, getOracleAge, isOracleStale, getOracleBufferStats, comparePoolAndOraclePrices, getOracleForPool } from '../../chunk-RO6R66OM.js';
2
+ import { PROGRAM_ID, BPS_DENOM, getOracleAddress } from '../../chunk-3LTCKCJC.js';
3
+ import '../../chunk-PZ5AY32C.js';
4
+ import { createContext, useMemo, useContext, useState, useEffect, useCallback, useRef } from 'react';
5
+ import { jsx } from 'react/jsx-runtime';
6
+ import { createSolanaRpc, createTransactionMessage, setTransactionMessageFeePayerSigner, setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstruction, signTransactionMessageWithSigners, getBase64EncodedWireTransaction } from '@solana/kit';
7
+
8
+ var AmmContext = createContext(null);
9
+ function AmmProvider({
10
+ rpc,
11
+ programId = PROGRAM_ID,
12
+ commitment = "confirmed",
13
+ refreshInterval = 3e4,
14
+ defaultSlippageBps = 50,
15
+ children
16
+ }) {
17
+ const value = useMemo(
18
+ () => ({
19
+ rpc,
20
+ programId,
21
+ commitment,
22
+ refreshInterval,
23
+ defaultSlippageBps
24
+ }),
25
+ [rpc, programId, commitment, refreshInterval, defaultSlippageBps]
26
+ );
27
+ return /* @__PURE__ */ jsx(AmmContext.Provider, { value, children });
28
+ }
29
+ function useAmm() {
30
+ const context = useContext(AmmContext);
31
+ if (!context) {
32
+ throw new Error("useAmm must be used within an AmmProvider");
33
+ }
34
+ return context;
35
+ }
36
+ function useAmmOptional() {
37
+ return useContext(AmmContext);
38
+ }
39
+ var WalletContext = createContext(null);
40
+ function WalletProvider({
41
+ wallet,
42
+ signAndSendTransaction,
43
+ children
44
+ }) {
45
+ const value = useMemo(
46
+ () => ({
47
+ ...wallet,
48
+ signAndSendTransaction
49
+ }),
50
+ [wallet, signAndSendTransaction]
51
+ );
52
+ return /* @__PURE__ */ jsx(WalletContext.Provider, { value, children });
53
+ }
54
+ function useWallet() {
55
+ const context = useContext(WalletContext);
56
+ if (!context) {
57
+ throw new Error("useWallet must be used within a WalletProvider");
58
+ }
59
+ return context;
60
+ }
61
+ function useWalletOptional() {
62
+ return useContext(WalletContext);
63
+ }
64
+ function useWalletAddress() {
65
+ const { connected, address } = useWallet();
66
+ if (!connected || !address) {
67
+ throw new Error("Wallet is not connected");
68
+ }
69
+ return address;
70
+ }
71
+ var AmmContext2 = createContext(null);
72
+ AmmContext2.displayName = "AmmContext";
73
+ function useAmm2() {
74
+ const ctx = useContext(AmmContext2);
75
+ if (!ctx) {
76
+ throw new Error("useAmm must be used within AmmProvider");
77
+ }
78
+ return ctx;
79
+ }
80
+ function createAmmContextValue(config) {
81
+ const {
82
+ endpoint,
83
+ programId,
84
+ commitment = "confirmed",
85
+ refreshInterval = 3e4,
86
+ defaultSlippageBps = 50
87
+ } = config;
88
+ const rpc = createSolanaRpc(endpoint);
89
+ return {
90
+ rpc,
91
+ endpoint,
92
+ programId: programId ?? PROGRAM_ID,
93
+ commitment,
94
+ refreshInterval,
95
+ defaultSlippageBps
96
+ };
97
+ }
98
+ function AmmProvider2({
99
+ children,
100
+ endpoint,
101
+ programId,
102
+ commitment = "confirmed",
103
+ refreshInterval = 3e4,
104
+ defaultSlippageBps = 50
105
+ }) {
106
+ const value = useMemo(
107
+ () => createAmmContextValue({
108
+ endpoint,
109
+ programId,
110
+ commitment,
111
+ refreshInterval,
112
+ defaultSlippageBps
113
+ }),
114
+ [endpoint, programId, commitment, refreshInterval, defaultSlippageBps]
115
+ );
116
+ return /* @__PURE__ */ jsx(AmmContext2.Provider, { value, children });
117
+ }
118
+ function isConnectableWallet(wallet) {
119
+ return "standard:connect" in wallet.features;
120
+ }
121
+ function getWallets() {
122
+ if (typeof window === "undefined") {
123
+ return [];
124
+ }
125
+ const registry = window.navigator?.wallets;
126
+ if (!registry) {
127
+ return [];
128
+ }
129
+ const wallets = [];
130
+ try {
131
+ const registered = registry.get?.() ?? [];
132
+ for (const wallet of registered) {
133
+ const supportsSolana = wallet.chains?.some(
134
+ (chain) => chain.startsWith("solana:")
135
+ );
136
+ if (supportsSolana && isConnectableWallet(wallet)) {
137
+ wallets.push(wallet);
138
+ }
139
+ }
140
+ } catch {
141
+ }
142
+ return wallets;
143
+ }
144
+ var WalletContext2 = createContext(null);
145
+ WalletContext2.displayName = "WalletContext";
146
+ function useWallet2() {
147
+ const ctx = useContext(WalletContext2);
148
+ if (!ctx) {
149
+ throw new Error("useWallet must be used within WalletProvider");
150
+ }
151
+ return ctx;
152
+ }
153
+ function createWalletContextValue() {
154
+ return {
155
+ wallet: null,
156
+ account: null,
157
+ connected: false,
158
+ connecting: false,
159
+ wallets: [],
160
+ select: () => {
161
+ },
162
+ connect: async () => {
163
+ },
164
+ disconnect: async () => {
165
+ },
166
+ error: null
167
+ };
168
+ }
169
+ function WalletProvider2({
170
+ children,
171
+ autoConnect = false,
172
+ onConnect,
173
+ onDisconnect,
174
+ onError
175
+ }) {
176
+ const [wallets, setWallets] = useState([]);
177
+ const [wallet, setWallet] = useState(null);
178
+ const [account, setAccount] = useState(null);
179
+ const [connecting, setConnecting] = useState(false);
180
+ const [error, setError] = useState(null);
181
+ const connected = account !== null;
182
+ useEffect(() => {
183
+ const discovered = getWallets();
184
+ setWallets(discovered);
185
+ if (typeof window !== "undefined") {
186
+ const registry = window.navigator?.wallets;
187
+ if (registry?.on) {
188
+ const unsubscribe = registry.on("register", () => {
189
+ setWallets(getWallets());
190
+ });
191
+ return () => {
192
+ unsubscribe?.();
193
+ };
194
+ }
195
+ }
196
+ return void 0;
197
+ }, []);
198
+ const select = useCallback((newWallet) => {
199
+ setWallet(newWallet);
200
+ setError(null);
201
+ }, []);
202
+ const connect = useCallback(async () => {
203
+ if (!wallet) {
204
+ const err = new Error("No wallet selected");
205
+ setError(err);
206
+ onError?.(err);
207
+ return;
208
+ }
209
+ setConnecting(true);
210
+ setError(null);
211
+ try {
212
+ const connectFeature = wallet.features["standard:connect"];
213
+ const result = await connectFeature.connect();
214
+ if (result.accounts.length > 0) {
215
+ const connectedAccount = result.accounts[0];
216
+ setAccount(connectedAccount);
217
+ onConnect?.(connectedAccount);
218
+ } else {
219
+ throw new Error("No accounts returned from wallet");
220
+ }
221
+ } catch (err) {
222
+ const error2 = err instanceof Error ? err : new Error(String(err));
223
+ setError(error2);
224
+ onError?.(error2);
225
+ } finally {
226
+ setConnecting(false);
227
+ }
228
+ }, [wallet, onConnect, onError]);
229
+ const disconnect = useCallback(async () => {
230
+ if (!wallet) {
231
+ return;
232
+ }
233
+ try {
234
+ const disconnectFeature = wallet.features["standard:disconnect"];
235
+ if (disconnectFeature) {
236
+ await disconnectFeature.disconnect();
237
+ }
238
+ } catch (err) {
239
+ console.warn("Disconnect error:", err);
240
+ } finally {
241
+ setAccount(null);
242
+ onDisconnect?.();
243
+ }
244
+ }, [wallet, onDisconnect]);
245
+ useEffect(() => {
246
+ if (autoConnect && wallet && !connected && !connecting) {
247
+ const connectFeature = wallet.features["standard:connect"];
248
+ connectFeature.connect({ silent: true }).then(
249
+ (result) => {
250
+ if (result.accounts.length > 0) {
251
+ setAccount(result.accounts[0]);
252
+ onConnect?.(result.accounts[0]);
253
+ }
254
+ }
255
+ ).catch(() => {
256
+ });
257
+ }
258
+ }, [autoConnect, wallet, connected, connecting, onConnect]);
259
+ useEffect(() => {
260
+ if (!wallet) return void 0;
261
+ const eventsFeature = wallet.features["standard:events"];
262
+ if (eventsFeature?.on) {
263
+ const unsubscribe = eventsFeature.on("change", () => {
264
+ if (wallet.accounts.length > 0) {
265
+ setAccount(wallet.accounts[0]);
266
+ } else {
267
+ setAccount(null);
268
+ onDisconnect?.();
269
+ }
270
+ });
271
+ return () => {
272
+ unsubscribe?.();
273
+ };
274
+ }
275
+ return void 0;
276
+ }, [wallet, onDisconnect]);
277
+ const value = useMemo(
278
+ () => ({
279
+ wallet,
280
+ account,
281
+ connected,
282
+ connecting,
283
+ wallets,
284
+ select,
285
+ connect,
286
+ disconnect,
287
+ error
288
+ }),
289
+ [
290
+ wallet,
291
+ account,
292
+ connected,
293
+ connecting,
294
+ wallets,
295
+ select,
296
+ connect,
297
+ disconnect,
298
+ error
299
+ ]
300
+ );
301
+ return /* @__PURE__ */ jsx(WalletContext2.Provider, { value, children });
302
+ }
303
+ function usePool(poolAddress, options = {}) {
304
+ const {
305
+ rpc,
306
+ programId,
307
+ commitment: defaultCommitment,
308
+ refreshInterval: defaultRefreshInterval
309
+ } = useAmm();
310
+ const {
311
+ refreshInterval = defaultRefreshInterval,
312
+ fetchOnMount = true,
313
+ commitment = defaultCommitment
314
+ } = options;
315
+ const [pool, setPool] = useState(null);
316
+ const [loading, setLoading] = useState(true);
317
+ const [error, setError] = useState(null);
318
+ const [refetching, setRefetching] = useState(false);
319
+ const mountedRef = useRef(true);
320
+ const fetchPoolData = useCallback(
321
+ async (isRefetch = false) => {
322
+ if (!poolAddress) {
323
+ setPool(null);
324
+ setLoading(false);
325
+ return;
326
+ }
327
+ if (isRefetch) {
328
+ setRefetching(true);
329
+ } else {
330
+ setLoading(true);
331
+ }
332
+ setError(null);
333
+ try {
334
+ const poolData = await fetchPool(rpc, poolAddress, {
335
+ programId,
336
+ commitment
337
+ });
338
+ if (mountedRef.current) {
339
+ setPool(poolData);
340
+ }
341
+ } catch (err) {
342
+ if (mountedRef.current) {
343
+ setError(err instanceof Error ? err : new Error(String(err)));
344
+ }
345
+ } finally {
346
+ if (mountedRef.current) {
347
+ setLoading(false);
348
+ setRefetching(false);
349
+ }
350
+ }
351
+ },
352
+ [poolAddress, rpc, programId, commitment]
353
+ );
354
+ const refetch = useCallback(async () => {
355
+ await fetchPoolData(true);
356
+ }, [fetchPoolData]);
357
+ useEffect(() => {
358
+ mountedRef.current = true;
359
+ if (fetchOnMount) {
360
+ fetchPoolData(false);
361
+ }
362
+ return () => {
363
+ mountedRef.current = false;
364
+ };
365
+ }, [fetchPoolData, fetchOnMount]);
366
+ useEffect(() => {
367
+ if (refreshInterval <= 0 || !poolAddress) {
368
+ return;
369
+ }
370
+ const intervalId = setInterval(() => {
371
+ fetchPoolData(true);
372
+ }, refreshInterval);
373
+ return () => {
374
+ clearInterval(intervalId);
375
+ };
376
+ }, [fetchPoolData, refreshInterval, poolAddress]);
377
+ return {
378
+ pool,
379
+ loading,
380
+ error,
381
+ refetch,
382
+ refetching
383
+ };
384
+ }
385
+ function usePools(poolAddresses, options = {}) {
386
+ const {
387
+ rpc,
388
+ programId,
389
+ commitment: defaultCommitment,
390
+ refreshInterval: defaultRefreshInterval
391
+ } = useAmm();
392
+ const {
393
+ refreshInterval = defaultRefreshInterval,
394
+ fetchOnMount = true,
395
+ commitment = defaultCommitment
396
+ } = options;
397
+ const [pools, setPools] = useState(/* @__PURE__ */ new Map());
398
+ const [loading, setLoading] = useState(true);
399
+ const [error, setError] = useState(null);
400
+ const mountedRef = useRef(true);
401
+ const fetchPools = useCallback(async () => {
402
+ if (poolAddresses.length === 0) {
403
+ setPools(/* @__PURE__ */ new Map());
404
+ setLoading(false);
405
+ return;
406
+ }
407
+ setLoading(true);
408
+ setError(null);
409
+ try {
410
+ const results = await Promise.all(
411
+ poolAddresses.map(
412
+ (addr) => fetchPool(rpc, addr, { programId, commitment }).then((pool) => [addr, pool]).catch(() => [addr, null])
413
+ )
414
+ );
415
+ if (mountedRef.current) {
416
+ const poolMap = /* @__PURE__ */ new Map();
417
+ for (const [addr, pool] of results) {
418
+ if (pool) {
419
+ poolMap.set(addr, pool);
420
+ }
421
+ }
422
+ setPools(poolMap);
423
+ }
424
+ } catch (err) {
425
+ if (mountedRef.current) {
426
+ setError(err instanceof Error ? err : new Error(String(err)));
427
+ }
428
+ } finally {
429
+ if (mountedRef.current) {
430
+ setLoading(false);
431
+ }
432
+ }
433
+ }, [poolAddresses, rpc, programId, commitment]);
434
+ useEffect(() => {
435
+ mountedRef.current = true;
436
+ if (fetchOnMount) {
437
+ fetchPools();
438
+ }
439
+ return () => {
440
+ mountedRef.current = false;
441
+ };
442
+ }, [fetchPools, fetchOnMount]);
443
+ useEffect(() => {
444
+ if (refreshInterval <= 0 || poolAddresses.length === 0) {
445
+ return;
446
+ }
447
+ const intervalId = setInterval(fetchPools, refreshInterval);
448
+ return () => clearInterval(intervalId);
449
+ }, [fetchPools, refreshInterval, poolAddresses.length]);
450
+ return {
451
+ pools,
452
+ loading,
453
+ error,
454
+ refetch: fetchPools
455
+ };
456
+ }
457
+ function useSwap(options) {
458
+ const { defaultSlippageBps: contextSlippage } = useAmm();
459
+ const {
460
+ defaultSlippageBps = contextSlippage ?? 50,
461
+ pool,
462
+ token0Mint,
463
+ token1Mint
464
+ } = options;
465
+ const [state, setState] = useState({
466
+ inputToken: token0Mint,
467
+ outputToken: token1Mint,
468
+ inputAmount: 0n,
469
+ outputAmount: 0n,
470
+ exactInput: true,
471
+ slippageBps: defaultSlippageBps
472
+ });
473
+ const [quoting] = useState(false);
474
+ const direction = useMemo(() => {
475
+ if (!token0Mint || !token1Mint || !state.inputToken) return null;
476
+ if (state.inputToken === token0Mint) return 0;
477
+ if (state.inputToken === token1Mint) return 1;
478
+ return null;
479
+ }, [token0Mint, token1Mint, state.inputToken]);
480
+ const quote = useMemo(() => {
481
+ if (!pool || direction === null) {
482
+ return null;
483
+ }
484
+ if (state.exactInput) {
485
+ if (state.inputAmount === 0n) {
486
+ return {
487
+ amountOut: 0n,
488
+ feeTotal: 0n,
489
+ feeDist: 0n,
490
+ feeComp: 0n,
491
+ priceImpact: 0,
492
+ executionPrice: 0,
493
+ minAmountOut: 0n,
494
+ maxAmountIn: 0n,
495
+ direction,
496
+ isValid: false,
497
+ error: null
498
+ };
499
+ }
500
+ try {
501
+ const swapQuote = getSwapQuote(pool, state.inputAmount, direction);
502
+ const slippageFactor = BPS_DENOM - BigInt(state.slippageBps);
503
+ const minAmountOut = swapQuote.amountOut * slippageFactor / BPS_DENOM;
504
+ return {
505
+ ...swapQuote,
506
+ minAmountOut,
507
+ maxAmountIn: state.inputAmount,
508
+ direction,
509
+ isValid: swapQuote.amountOut > 0n,
510
+ error: null
511
+ };
512
+ } catch (err) {
513
+ return {
514
+ amountOut: 0n,
515
+ feeTotal: 0n,
516
+ feeDist: 0n,
517
+ feeComp: 0n,
518
+ priceImpact: 0,
519
+ executionPrice: 0,
520
+ minAmountOut: 0n,
521
+ maxAmountIn: 0n,
522
+ direction,
523
+ isValid: false,
524
+ error: err instanceof Error ? err.message : "Failed to calculate quote"
525
+ };
526
+ }
527
+ } else {
528
+ if (state.outputAmount === 0n) {
529
+ return {
530
+ amountOut: 0n,
531
+ feeTotal: 0n,
532
+ feeDist: 0n,
533
+ feeComp: 0n,
534
+ priceImpact: 0,
535
+ executionPrice: 0,
536
+ minAmountOut: 0n,
537
+ maxAmountIn: 0n,
538
+ direction,
539
+ isValid: false,
540
+ error: null
541
+ };
542
+ }
543
+ try {
544
+ const { amountIn, feeTotal } = getSwapQuoteExactOut(
545
+ pool,
546
+ state.outputAmount,
547
+ direction
548
+ );
549
+ const slippageFactor = BPS_DENOM + BigInt(state.slippageBps);
550
+ const maxAmountIn = amountIn * slippageFactor / BPS_DENOM;
551
+ const forwardQuote = getSwapQuote(pool, amountIn, direction);
552
+ return {
553
+ amountOut: state.outputAmount,
554
+ feeTotal,
555
+ feeDist: 0n,
556
+ // Not calculated for exact out
557
+ feeComp: 0n,
558
+ priceImpact: forwardQuote.priceImpact,
559
+ executionPrice: ratioToNumber(state.outputAmount, amountIn),
560
+ minAmountOut: state.outputAmount,
561
+ maxAmountIn,
562
+ direction,
563
+ isValid: amountIn > 0n,
564
+ error: null
565
+ };
566
+ } catch (err) {
567
+ return {
568
+ amountOut: 0n,
569
+ feeTotal: 0n,
570
+ feeDist: 0n,
571
+ feeComp: 0n,
572
+ priceImpact: 0,
573
+ executionPrice: 0,
574
+ minAmountOut: 0n,
575
+ maxAmountIn: 0n,
576
+ direction,
577
+ isValid: false,
578
+ error: err instanceof Error ? err.message : "Failed to calculate quote"
579
+ };
580
+ }
581
+ }
582
+ }, [
583
+ pool,
584
+ direction,
585
+ state.inputAmount,
586
+ state.outputAmount,
587
+ state.exactInput,
588
+ state.slippageBps
589
+ ]);
590
+ const setInputToken = useCallback((token) => {
591
+ setState((s) => ({ ...s, inputToken: token }));
592
+ }, []);
593
+ const setOutputToken = useCallback((token) => {
594
+ setState((s) => ({ ...s, outputToken: token }));
595
+ }, []);
596
+ const setInputAmount = useCallback((amount) => {
597
+ setState((s) => ({
598
+ ...s,
599
+ inputAmount: amount,
600
+ exactInput: true
601
+ }));
602
+ }, []);
603
+ const setOutputAmount = useCallback((amount) => {
604
+ setState((s) => ({
605
+ ...s,
606
+ outputAmount: amount,
607
+ exactInput: false
608
+ }));
609
+ }, []);
610
+ const setSlippage = useCallback((bps) => {
611
+ setState((s) => ({ ...s, slippageBps: bps }));
612
+ }, []);
613
+ const flipTokens = useCallback(() => {
614
+ setState((s) => ({
615
+ ...s,
616
+ inputToken: s.outputToken,
617
+ outputToken: s.inputToken,
618
+ inputAmount: s.outputAmount,
619
+ outputAmount: s.inputAmount
620
+ }));
621
+ }, []);
622
+ const reset = useCallback(() => {
623
+ setState({
624
+ inputToken: token0Mint,
625
+ outputToken: token1Mint,
626
+ inputAmount: 0n,
627
+ outputAmount: 0n,
628
+ exactInput: true,
629
+ slippageBps: defaultSlippageBps
630
+ });
631
+ }, [token0Mint, token1Mint, defaultSlippageBps]);
632
+ const canSwap = useMemo(() => {
633
+ return !!(quote?.isValid && state.inputToken && state.outputToken && (state.exactInput ? state.inputAmount > 0n : state.outputAmount > 0n));
634
+ }, [quote, state]);
635
+ return {
636
+ state,
637
+ quote,
638
+ quoting,
639
+ setInputToken,
640
+ setOutputToken,
641
+ setInputAmount,
642
+ setOutputAmount,
643
+ setSlippage,
644
+ flipTokens,
645
+ reset,
646
+ canSwap
647
+ };
648
+ }
649
+ function useLiquidity(options) {
650
+ const { defaultSlippageBps: contextSlippage } = useAmm();
651
+ const {
652
+ pool,
653
+ userShares = 0n,
654
+ defaultSlippageBps = contextSlippage ?? 50,
655
+ defaultMode = "add"
656
+ } = options;
657
+ const [mode, setMode] = useState(defaultMode);
658
+ const [addState, setAddState] = useState({
659
+ amount0: 0n,
660
+ amount1: 0n,
661
+ slippageBps: defaultSlippageBps
662
+ });
663
+ const [removeState, setRemoveState] = useState({
664
+ shares: 0n,
665
+ percentage: 0,
666
+ slippageBps: defaultSlippageBps
667
+ });
668
+ const addQuote = useMemo(() => {
669
+ if (!pool) {
670
+ return null;
671
+ }
672
+ if (addState.amount0 === 0n && addState.amount1 === 0n) {
673
+ return {
674
+ sharesOut: 0n,
675
+ amount0: 0n,
676
+ amount1: 0n,
677
+ poolShare: 0,
678
+ minSharesOut: 0n,
679
+ isValid: false,
680
+ error: null
681
+ };
682
+ }
683
+ try {
684
+ const quote = getAddLiquidityQuote(
685
+ pool,
686
+ addState.amount0,
687
+ addState.amount1
688
+ );
689
+ const slippageFactor = BPS_DENOM - BigInt(addState.slippageBps);
690
+ const minSharesOut = quote.sharesOut * slippageFactor / BPS_DENOM;
691
+ return {
692
+ ...quote,
693
+ minSharesOut,
694
+ isValid: quote.sharesOut > 0n,
695
+ error: null
696
+ };
697
+ } catch (err) {
698
+ return {
699
+ sharesOut: 0n,
700
+ amount0: 0n,
701
+ amount1: 0n,
702
+ poolShare: 0,
703
+ minSharesOut: 0n,
704
+ isValid: false,
705
+ error: err instanceof Error ? err.message : "Failed to calculate quote"
706
+ };
707
+ }
708
+ }, [pool, addState.amount0, addState.amount1, addState.slippageBps]);
709
+ const removeQuote = useMemo(() => {
710
+ if (!pool) {
711
+ return null;
712
+ }
713
+ if (removeState.shares === 0n) {
714
+ return {
715
+ amount0: 0n,
716
+ amount1: 0n,
717
+ minAmount0Out: 0n,
718
+ minAmount1Out: 0n,
719
+ isValid: false,
720
+ error: null
721
+ };
722
+ }
723
+ try {
724
+ const quote = getRemoveLiquidityQuote(pool, removeState.shares);
725
+ const slippageFactor = BPS_DENOM - BigInt(removeState.slippageBps);
726
+ const minAmount0Out = quote.amount0 * slippageFactor / BPS_DENOM;
727
+ const minAmount1Out = quote.amount1 * slippageFactor / BPS_DENOM;
728
+ return {
729
+ ...quote,
730
+ minAmount0Out,
731
+ minAmount1Out,
732
+ isValid: quote.amount0 > 0n || quote.amount1 > 0n,
733
+ error: null
734
+ };
735
+ } catch (err) {
736
+ return {
737
+ amount0: 0n,
738
+ amount1: 0n,
739
+ minAmount0Out: 0n,
740
+ minAmount1Out: 0n,
741
+ isValid: false,
742
+ error: err instanceof Error ? err.message : "Failed to calculate quote"
743
+ };
744
+ }
745
+ }, [pool, removeState.shares, removeState.slippageBps]);
746
+ const setAmount0 = useCallback((amount) => {
747
+ setAddState((s) => ({ ...s, amount0: amount }));
748
+ }, []);
749
+ const setAmount1 = useCallback((amount) => {
750
+ setAddState((s) => ({ ...s, amount1: amount }));
751
+ }, []);
752
+ const setShares = useCallback(
753
+ (shares) => {
754
+ setRemoveState((s) => ({
755
+ ...s,
756
+ shares,
757
+ percentage: userShares > 0n ? Number(shares * 100n / userShares) : 0
758
+ }));
759
+ },
760
+ [userShares]
761
+ );
762
+ const setPercentage = useCallback(
763
+ (percentage) => {
764
+ const clampedPercentage = Math.min(100, Math.max(0, percentage));
765
+ const shares = userShares * BigInt(Math.round(clampedPercentage)) / 100n;
766
+ setRemoveState((s) => ({
767
+ ...s,
768
+ shares,
769
+ percentage: clampedPercentage
770
+ }));
771
+ },
772
+ [userShares]
773
+ );
774
+ const setSlippage = useCallback((bps) => {
775
+ setAddState((s) => ({ ...s, slippageBps: bps }));
776
+ setRemoveState((s) => ({ ...s, slippageBps: bps }));
777
+ }, []);
778
+ const reset = useCallback(() => {
779
+ setAddState({
780
+ amount0: 0n,
781
+ amount1: 0n,
782
+ slippageBps: defaultSlippageBps
783
+ });
784
+ setRemoveState({
785
+ shares: 0n,
786
+ percentage: 0,
787
+ slippageBps: defaultSlippageBps
788
+ });
789
+ }, [defaultSlippageBps]);
790
+ const canAdd = useMemo(() => {
791
+ return !!(addQuote?.isValid && (addState.amount0 > 0n || addState.amount1 > 0n));
792
+ }, [addQuote, addState]);
793
+ const canRemove = useMemo(() => {
794
+ return !!(removeQuote?.isValid && removeState.shares > 0n && removeState.shares <= userShares);
795
+ }, [removeQuote, removeState.shares, userShares]);
796
+ return {
797
+ mode,
798
+ setMode,
799
+ addState,
800
+ addQuote,
801
+ setAmount0,
802
+ setAmount1,
803
+ canAdd,
804
+ removeState,
805
+ removeQuote,
806
+ setShares,
807
+ setPercentage,
808
+ canRemove,
809
+ setSlippage,
810
+ reset
811
+ };
812
+ }
813
+ function usePosition(poolAddress, positionId = 0n, options = {}) {
814
+ const {
815
+ rpc,
816
+ programId,
817
+ commitment: defaultCommitment,
818
+ refreshInterval: defaultRefreshInterval
819
+ } = useAmm();
820
+ const wallet = useWalletOptional();
821
+ const {
822
+ refreshInterval = defaultRefreshInterval,
823
+ fetchOnMount = true,
824
+ commitment = defaultCommitment,
825
+ pool: providedPool
826
+ } = options;
827
+ const [position, setPosition] = useState(null);
828
+ const [positionAddress, setPositionAddress] = useState();
829
+ const [pool, setPool] = useState(providedPool ?? null);
830
+ const [loading, setLoading] = useState(true);
831
+ const [error, setError] = useState(null);
832
+ const mountedRef = useRef(true);
833
+ const ownerAddress = wallet?.address;
834
+ const fetchPositionData = useCallback(async () => {
835
+ if (!poolAddress || !ownerAddress) {
836
+ setPosition(null);
837
+ setPositionAddress(void 0);
838
+ setLoading(false);
839
+ return;
840
+ }
841
+ setLoading(true);
842
+ setError(null);
843
+ try {
844
+ const { getPositionAddress } = await import('../../pda-RVIHNLRP.js');
845
+ const [posAddr] = await getPositionAddress(
846
+ poolAddress,
847
+ ownerAddress,
848
+ positionId,
849
+ programId
850
+ );
851
+ setPositionAddress(posAddr);
852
+ const [positionData, poolData] = await Promise.all([
853
+ fetchPosition(rpc, posAddr, { programId, commitment }),
854
+ providedPool ? Promise.resolve(providedPool) : fetchPool(rpc, poolAddress, { programId, commitment })
855
+ ]);
856
+ if (mountedRef.current) {
857
+ setPosition(positionData);
858
+ setPool(poolData);
859
+ }
860
+ } catch (err) {
861
+ if (mountedRef.current) {
862
+ setError(err instanceof Error ? err : new Error(String(err)));
863
+ }
864
+ } finally {
865
+ if (mountedRef.current) {
866
+ setLoading(false);
867
+ }
868
+ }
869
+ }, [
870
+ poolAddress,
871
+ ownerAddress,
872
+ positionId,
873
+ rpc,
874
+ programId,
875
+ commitment,
876
+ providedPool
877
+ ]);
878
+ const refetch = useCallback(async () => {
879
+ await fetchPositionData();
880
+ }, [fetchPositionData]);
881
+ const pendingFees = useMemo(() => {
882
+ if (!pool || !position) return null;
883
+ return getPendingFees(pool, position);
884
+ }, [pool, position]);
885
+ const value = useMemo(() => {
886
+ if (!pool || !position) return null;
887
+ return getPositionValue(pool, position);
888
+ }, [pool, position]);
889
+ useEffect(() => {
890
+ mountedRef.current = true;
891
+ if (fetchOnMount) {
892
+ fetchPositionData();
893
+ }
894
+ return () => {
895
+ mountedRef.current = false;
896
+ };
897
+ }, [fetchPositionData, fetchOnMount]);
898
+ useEffect(() => {
899
+ if (refreshInterval <= 0 || !poolAddress || !ownerAddress) {
900
+ return;
901
+ }
902
+ const intervalId = setInterval(fetchPositionData, refreshInterval);
903
+ return () => clearInterval(intervalId);
904
+ }, [fetchPositionData, refreshInterval, poolAddress, ownerAddress]);
905
+ return {
906
+ position,
907
+ positionAddress,
908
+ loading,
909
+ error,
910
+ refetch,
911
+ pendingFees,
912
+ value
913
+ };
914
+ }
915
+ function useUserPositions(poolFilter, options = {}) {
916
+ const {
917
+ rpc,
918
+ programId,
919
+ commitment: defaultCommitment,
920
+ refreshInterval: defaultRefreshInterval
921
+ } = useAmm();
922
+ const wallet = useWalletOptional();
923
+ const {
924
+ refreshInterval = defaultRefreshInterval,
925
+ fetchOnMount = true,
926
+ commitment = defaultCommitment
927
+ } = options;
928
+ const [positions, setPositions] = useState([]);
929
+ const [loading, setLoading] = useState(true);
930
+ const [error, setError] = useState(null);
931
+ const mountedRef = useRef(true);
932
+ const ownerAddress = wallet?.address;
933
+ const fetchPositions = useCallback(async () => {
934
+ if (!ownerAddress) {
935
+ setPositions([]);
936
+ setLoading(false);
937
+ return;
938
+ }
939
+ setLoading(true);
940
+ setError(null);
941
+ try {
942
+ const positionsData = await fetchUserPositions(
943
+ rpc,
944
+ ownerAddress,
945
+ poolFilter,
946
+ {
947
+ programId,
948
+ commitment
949
+ }
950
+ );
951
+ if (mountedRef.current) {
952
+ setPositions(positionsData.filter((p) => p.account.shares > 0n));
953
+ }
954
+ } catch (err) {
955
+ if (mountedRef.current) {
956
+ setError(err instanceof Error ? err : new Error(String(err)));
957
+ }
958
+ } finally {
959
+ if (mountedRef.current) {
960
+ setLoading(false);
961
+ }
962
+ }
963
+ }, [ownerAddress, poolFilter, rpc, programId, commitment]);
964
+ useEffect(() => {
965
+ mountedRef.current = true;
966
+ if (fetchOnMount) {
967
+ fetchPositions();
968
+ }
969
+ return () => {
970
+ mountedRef.current = false;
971
+ };
972
+ }, [fetchPositions, fetchOnMount]);
973
+ useEffect(() => {
974
+ if (refreshInterval <= 0 || !ownerAddress) {
975
+ return;
976
+ }
977
+ const intervalId = setInterval(fetchPositions, refreshInterval);
978
+ return () => clearInterval(intervalId);
979
+ }, [fetchPositions, refreshInterval, ownerAddress]);
980
+ return {
981
+ positions,
982
+ loading,
983
+ error,
984
+ refetch: fetchPositions
985
+ };
986
+ }
987
+ function useFees(positionAddress, poolAddress, options = {}) {
988
+ const {
989
+ rpc,
990
+ programId,
991
+ commitment: defaultCommitment,
992
+ refreshInterval: defaultRefreshInterval
993
+ } = useAmm();
994
+ const wallet = useWalletOptional();
995
+ const {
996
+ refreshInterval = defaultRefreshInterval,
997
+ fetchOnMount = true,
998
+ commitment = defaultCommitment,
999
+ pool: providedPool,
1000
+ position: providedPosition
1001
+ } = options;
1002
+ const [pool, setPool] = useState(providedPool ?? null);
1003
+ const [position, setPosition] = useState(
1004
+ providedPosition ?? null
1005
+ );
1006
+ const [loading, setLoading] = useState(true);
1007
+ const [refetching, setRefetching] = useState(false);
1008
+ const [error, setError] = useState(null);
1009
+ const [status, setStatus] = useState("idle");
1010
+ const [txError, setTxError] = useState(null);
1011
+ const [txSignature, setTxSignature] = useState(null);
1012
+ const mountedRef = useRef(true);
1013
+ useEffect(() => {
1014
+ if (providedPool) setPool(providedPool);
1015
+ if (providedPosition) setPosition(providedPosition);
1016
+ }, [providedPool, providedPosition]);
1017
+ const fees = useMemo(() => {
1018
+ if (!pool || !position) return null;
1019
+ const { pending0, pending1 } = getPendingFees(pool, position);
1020
+ return {
1021
+ pending0,
1022
+ pending1,
1023
+ hasFees: pending0 > 0n || pending1 > 0n
1024
+ };
1025
+ }, [pool, position]);
1026
+ const fetchFeesData = useCallback(
1027
+ async (isRefetch = false) => {
1028
+ if (providedPool && providedPosition) {
1029
+ setLoading(false);
1030
+ return;
1031
+ }
1032
+ if (!positionAddress && !providedPosition) {
1033
+ setLoading(false);
1034
+ return;
1035
+ }
1036
+ if (isRefetch) {
1037
+ setRefetching(true);
1038
+ } else {
1039
+ setLoading(true);
1040
+ }
1041
+ setError(null);
1042
+ try {
1043
+ const promises = [];
1044
+ if (!providedPosition && positionAddress) {
1045
+ promises.push(
1046
+ fetchPosition(rpc, positionAddress, { programId, commitment })
1047
+ );
1048
+ } else {
1049
+ promises.push(Promise.resolve(providedPosition));
1050
+ }
1051
+ if (!providedPool && poolAddress) {
1052
+ promises.push(fetchPool(rpc, poolAddress, { programId, commitment }));
1053
+ } else {
1054
+ promises.push(Promise.resolve(providedPool));
1055
+ }
1056
+ const [posData, poolData] = await Promise.all(promises);
1057
+ if (mountedRef.current) {
1058
+ if (posData && !providedPosition) setPosition(posData);
1059
+ if (poolData && !providedPool) setPool(poolData);
1060
+ }
1061
+ } catch (err) {
1062
+ if (mountedRef.current) {
1063
+ setError(err instanceof Error ? err : new Error(String(err)));
1064
+ }
1065
+ } finally {
1066
+ if (mountedRef.current) {
1067
+ setLoading(false);
1068
+ setRefetching(false);
1069
+ }
1070
+ }
1071
+ },
1072
+ [
1073
+ positionAddress,
1074
+ poolAddress,
1075
+ providedPool,
1076
+ providedPosition,
1077
+ rpc,
1078
+ programId,
1079
+ commitment
1080
+ ]
1081
+ );
1082
+ const refetch = useCallback(async () => {
1083
+ await fetchFeesData(true);
1084
+ }, [fetchFeesData]);
1085
+ const collect = useCallback(
1086
+ async (collectOptions) => {
1087
+ if (!pool || !poolAddress || !position || !positionAddress || !wallet?.address) {
1088
+ throw new Error("Pool, position, or wallet not available");
1089
+ }
1090
+ if (!wallet.signer) {
1091
+ throw new Error("Wallet signer is not available");
1092
+ }
1093
+ setStatus("signing");
1094
+ setTxError(null);
1095
+ setTxSignature(null);
1096
+ try {
1097
+ const {
1098
+ max0 = MAX_FEE_AMOUNT,
1099
+ max1 = MAX_FEE_AMOUNT,
1100
+ userToken0,
1101
+ userToken1
1102
+ } = collectOptions;
1103
+ const ix = createCollectFeesInstruction(
1104
+ {
1105
+ pool: poolAddress,
1106
+ position: positionAddress,
1107
+ owner: wallet.address,
1108
+ authority: pool.authority,
1109
+ vault0: pool.vault0,
1110
+ vault1: pool.vault1,
1111
+ token0Mint: pool.token0Mint,
1112
+ token1Mint: pool.token1Mint,
1113
+ user0: userToken0,
1114
+ user1: userToken1
1115
+ },
1116
+ { max0, max1 },
1117
+ programId
1118
+ );
1119
+ const { value: latestBlockhash } = await rpc.getLatestBlockhash({ commitment }).send();
1120
+ const baseMessage = createTransactionMessage({ version: "legacy" });
1121
+ const messageWithPayer = setTransactionMessageFeePayerSigner(
1122
+ wallet.signer,
1123
+ baseMessage
1124
+ );
1125
+ const messageWithLifetime = setTransactionMessageLifetimeUsingBlockhash(
1126
+ latestBlockhash,
1127
+ messageWithPayer
1128
+ );
1129
+ const messageWithIx = appendTransactionMessageInstruction(
1130
+ ix,
1131
+ messageWithLifetime
1132
+ );
1133
+ setStatus("sending");
1134
+ const signedTransaction = await signTransactionMessageWithSigners(messageWithIx);
1135
+ const wireTransaction = getBase64EncodedWireTransaction(signedTransaction);
1136
+ const signature = await rpc.sendTransaction(wireTransaction, { encoding: "base64" }).send();
1137
+ setStatus("success");
1138
+ setTxSignature(signature);
1139
+ await fetchFeesData(true);
1140
+ return signature;
1141
+ } catch (err) {
1142
+ setStatus("error");
1143
+ const error2 = err instanceof Error ? err : new Error(String(err));
1144
+ setTxError(error2);
1145
+ throw error2;
1146
+ }
1147
+ },
1148
+ [
1149
+ pool,
1150
+ poolAddress,
1151
+ position,
1152
+ positionAddress,
1153
+ wallet,
1154
+ programId,
1155
+ rpc,
1156
+ commitment,
1157
+ fetchFeesData
1158
+ ]
1159
+ );
1160
+ const reset = useCallback(() => {
1161
+ setStatus("idle");
1162
+ setTxError(null);
1163
+ setTxSignature(null);
1164
+ }, []);
1165
+ const canCollect = useMemo(() => {
1166
+ return !!(fees?.hasFees && wallet?.connected && wallet?.signer && pool && position);
1167
+ }, [fees, wallet, pool, position]);
1168
+ useEffect(() => {
1169
+ mountedRef.current = true;
1170
+ if (fetchOnMount) {
1171
+ fetchFeesData(false);
1172
+ }
1173
+ return () => {
1174
+ mountedRef.current = false;
1175
+ };
1176
+ }, [fetchFeesData, fetchOnMount]);
1177
+ useEffect(() => {
1178
+ if (refreshInterval <= 0) {
1179
+ return;
1180
+ }
1181
+ const intervalId = setInterval(() => {
1182
+ fetchFeesData(true);
1183
+ }, refreshInterval);
1184
+ return () => {
1185
+ clearInterval(intervalId);
1186
+ };
1187
+ }, [fetchFeesData, refreshInterval]);
1188
+ return {
1189
+ fees,
1190
+ loading,
1191
+ error,
1192
+ refetch,
1193
+ refetching,
1194
+ collect,
1195
+ status,
1196
+ txError,
1197
+ txSignature,
1198
+ reset,
1199
+ canCollect
1200
+ };
1201
+ }
1202
+ function useFeesFromData(pool, position) {
1203
+ return useMemo(() => {
1204
+ if (!pool || !position) return null;
1205
+ const { pending0, pending1 } = getPendingFees(pool, position);
1206
+ return {
1207
+ pending0,
1208
+ pending1,
1209
+ hasFees: pending0 > 0n || pending1 > 0n
1210
+ };
1211
+ }, [pool, position]);
1212
+ }
1213
+ function useOracle(poolAddress, options = {}) {
1214
+ const {
1215
+ rpc,
1216
+ programId,
1217
+ commitment: defaultCommitment,
1218
+ refreshInterval: defaultRefreshInterval
1219
+ } = useAmm();
1220
+ const {
1221
+ refreshInterval = defaultRefreshInterval,
1222
+ fetchOnMount = true,
1223
+ commitment = defaultCommitment
1224
+ } = options;
1225
+ const [oracle, setOracle] = useState(null);
1226
+ const [oracleAddress, setOracleAddress] = useState(null);
1227
+ const [loading, setLoading] = useState(true);
1228
+ const [error, setError] = useState(null);
1229
+ const mountedRef = useRef(true);
1230
+ const fetchOracleData = useCallback(async () => {
1231
+ if (!poolAddress) {
1232
+ setOracle(null);
1233
+ setOracleAddress(null);
1234
+ setLoading(false);
1235
+ return;
1236
+ }
1237
+ setLoading(true);
1238
+ setError(null);
1239
+ try {
1240
+ const [oracleAddr] = await getOracleAddress(poolAddress, programId);
1241
+ setOracleAddress(oracleAddr);
1242
+ const oracleData = await fetchOracle(rpc, oracleAddr, {
1243
+ programId,
1244
+ commitment
1245
+ });
1246
+ if (mountedRef.current) {
1247
+ setOracle(oracleData);
1248
+ }
1249
+ } catch (err) {
1250
+ if (mountedRef.current) {
1251
+ setError(err instanceof Error ? err : new Error(String(err)));
1252
+ }
1253
+ } finally {
1254
+ if (mountedRef.current) {
1255
+ setLoading(false);
1256
+ }
1257
+ }
1258
+ }, [poolAddress, rpc, programId, commitment]);
1259
+ const refetch = useCallback(async () => {
1260
+ await fetchOracleData();
1261
+ }, [fetchOracleData]);
1262
+ const twap = useCallback(
1263
+ (windowSeconds) => {
1264
+ if (!oracle || !oracle.initialized) return null;
1265
+ return consultTwap(oracle, windowSeconds);
1266
+ },
1267
+ [oracle]
1268
+ );
1269
+ const spotPrice = useMemo(() => {
1270
+ if (!oracle || !oracle.initialized) return null;
1271
+ const prices = getOracleSpotPrices(oracle);
1272
+ return { price0: prices.price0, price1: prices.price1 };
1273
+ }, [oracle]);
1274
+ const deviation = useMemo(() => {
1275
+ if (!oracle || !oracle.initialized) return null;
1276
+ const dev = getOracleDeviation(oracle);
1277
+ return { deviation0: dev.deviation0, deviation1: dev.deviation1 };
1278
+ }, [oracle]);
1279
+ const age = useMemo(() => {
1280
+ if (!oracle || !oracle.initialized) return null;
1281
+ return getOracleAge(oracle);
1282
+ }, [oracle]);
1283
+ const isStaleCheck = useCallback(
1284
+ (maxAgeSeconds) => {
1285
+ if (!oracle || !oracle.initialized) return true;
1286
+ return isOracleStale(oracle, maxAgeSeconds);
1287
+ },
1288
+ [oracle]
1289
+ );
1290
+ const bufferStats = useMemo(() => {
1291
+ if (!oracle || !oracle.initialized) return null;
1292
+ const stats = getOracleBufferStats(oracle);
1293
+ return {
1294
+ capacity: stats.capacity,
1295
+ filledCount: stats.filledCount,
1296
+ currentIndex: stats.currentIndex,
1297
+ timeSpanSeconds: stats.timeSpanSeconds
1298
+ };
1299
+ }, [oracle]);
1300
+ const compareWithPool = useCallback(
1301
+ (pool) => {
1302
+ if (!oracle || !oracle.initialized) return null;
1303
+ return comparePoolAndOraclePrices(pool, oracle);
1304
+ },
1305
+ [oracle]
1306
+ );
1307
+ useEffect(() => {
1308
+ mountedRef.current = true;
1309
+ if (fetchOnMount) {
1310
+ fetchOracleData();
1311
+ }
1312
+ return () => {
1313
+ mountedRef.current = false;
1314
+ };
1315
+ }, [fetchOracleData, fetchOnMount]);
1316
+ useEffect(() => {
1317
+ if (refreshInterval <= 0 || !poolAddress) {
1318
+ return;
1319
+ }
1320
+ const intervalId = setInterval(fetchOracleData, refreshInterval);
1321
+ return () => clearInterval(intervalId);
1322
+ }, [fetchOracleData, refreshInterval, poolAddress]);
1323
+ return {
1324
+ oracle,
1325
+ oracleAddress,
1326
+ loading,
1327
+ error,
1328
+ refetch,
1329
+ twap,
1330
+ spotPrice,
1331
+ deviation,
1332
+ age,
1333
+ isStale: isStaleCheck,
1334
+ bufferStats,
1335
+ compareWithPool
1336
+ };
1337
+ }
1338
+ function useTwap(poolAddress, windowSeconds, options = {}) {
1339
+ const { oracle, loading, error, refetch } = useOracle(poolAddress, options);
1340
+ const twap = useMemo(() => {
1341
+ if (!oracle || !oracle.initialized) return null;
1342
+ return consultTwap(oracle, windowSeconds);
1343
+ }, [oracle, windowSeconds]);
1344
+ return {
1345
+ twap,
1346
+ loading,
1347
+ error,
1348
+ refetch
1349
+ };
1350
+ }
1351
+ function useOracles(poolAddresses, options = {}) {
1352
+ const {
1353
+ rpc,
1354
+ programId,
1355
+ commitment: defaultCommitment,
1356
+ refreshInterval: defaultRefreshInterval
1357
+ } = useAmm();
1358
+ const {
1359
+ refreshInterval = defaultRefreshInterval,
1360
+ fetchOnMount = true,
1361
+ commitment = defaultCommitment
1362
+ } = options;
1363
+ const [oracles, setOracles] = useState(
1364
+ /* @__PURE__ */ new Map()
1365
+ );
1366
+ const [loading, setLoading] = useState(true);
1367
+ const [error, setError] = useState(null);
1368
+ const mountedRef = useRef(true);
1369
+ const fetchOracles = useCallback(async () => {
1370
+ if (poolAddresses.length === 0) {
1371
+ setOracles(/* @__PURE__ */ new Map());
1372
+ setLoading(false);
1373
+ return;
1374
+ }
1375
+ setLoading(true);
1376
+ setError(null);
1377
+ try {
1378
+ const results = await Promise.all(
1379
+ poolAddresses.map(async (poolAddr) => {
1380
+ try {
1381
+ const result = await getOracleForPool(rpc, poolAddr, {
1382
+ programId,
1383
+ commitment
1384
+ });
1385
+ return [poolAddr, result];
1386
+ } catch {
1387
+ return [poolAddr, null];
1388
+ }
1389
+ })
1390
+ );
1391
+ if (mountedRef.current) {
1392
+ const oracleMap = /* @__PURE__ */ new Map();
1393
+ for (const [poolAddr, oracleData] of results) {
1394
+ if (oracleData) {
1395
+ oracleMap.set(poolAddr, oracleData);
1396
+ }
1397
+ }
1398
+ setOracles(oracleMap);
1399
+ }
1400
+ } catch (err) {
1401
+ if (mountedRef.current) {
1402
+ setError(err instanceof Error ? err : new Error(String(err)));
1403
+ }
1404
+ } finally {
1405
+ if (mountedRef.current) {
1406
+ setLoading(false);
1407
+ }
1408
+ }
1409
+ }, [poolAddresses, rpc, programId, commitment]);
1410
+ useEffect(() => {
1411
+ mountedRef.current = true;
1412
+ if (fetchOnMount) {
1413
+ fetchOracles();
1414
+ }
1415
+ return () => {
1416
+ mountedRef.current = false;
1417
+ };
1418
+ }, [fetchOracles, fetchOnMount]);
1419
+ useEffect(() => {
1420
+ if (refreshInterval <= 0 || poolAddresses.length === 0) {
1421
+ return;
1422
+ }
1423
+ const intervalId = setInterval(fetchOracles, refreshInterval);
1424
+ return () => clearInterval(intervalId);
1425
+ }, [fetchOracles, refreshInterval, poolAddresses.length]);
1426
+ return {
1427
+ oracles,
1428
+ loading,
1429
+ error,
1430
+ refetch: fetchOracles
1431
+ };
1432
+ }
1433
+
1434
+ export { AmmContext, AmmProvider, AmmContext2 as EndpointAmmContext, AmmProvider2 as EndpointAmmProvider, WalletContext, WalletProvider, WalletContext2 as WalletStandardContext, WalletProvider2 as WalletStandardProvider, createAmmContextValue, createWalletContextValue, useAmm, useAmmOptional, useAmm2 as useEndpointAmm, useFees, useFeesFromData, useLiquidity, useOracle, useOracles, usePool, usePools, usePosition, useWallet2 as useStandardWallet, useSwap, useTwap, useUserPositions, useWallet, useWalletAddress, useWalletOptional };
1435
+ //# sourceMappingURL=index.js.map
1436
+ //# sourceMappingURL=index.js.map