@clober/v2-sdk 0.0.10 → 0.0.11-1.dev

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 (391) hide show
  1. package/README.md +12 -4
  2. package/dist/cjs/abis/core/book-manager-abi.js +112 -0
  3. package/dist/cjs/abis/core/book-manager-abi.js.map +1 -0
  4. package/dist/cjs/abis/core/book-viewer-abi.js +137 -5
  5. package/dist/cjs/abis/core/book-viewer-abi.js.map +1 -1
  6. package/dist/cjs/abis/core/controller-abi.js +1 -6
  7. package/dist/cjs/abis/core/controller-abi.js.map +1 -1
  8. package/dist/cjs/abis/governance/election-governor-abi.js +838 -0
  9. package/dist/cjs/abis/governance/election-governor-abi.js.map +1 -0
  10. package/dist/cjs/abis/governance/keepers-registry-abi.js +546 -0
  11. package/dist/cjs/abis/governance/keepers-registry-abi.js.map +1 -0
  12. package/dist/cjs/abis/governance/vclob-abi.js +743 -0
  13. package/dist/cjs/abis/governance/vclob-abi.js.map +1 -0
  14. package/dist/cjs/abis/rebalancer/minter-abi.js +262 -0
  15. package/dist/cjs/abis/rebalancer/minter-abi.js.map +1 -0
  16. package/dist/cjs/abis/rebalancer/mock-swap-abi.js +95 -0
  17. package/dist/cjs/abis/rebalancer/mock-swap-abi.js.map +1 -0
  18. package/dist/cjs/abis/rebalancer/operator-abi.js +401 -0
  19. package/dist/cjs/abis/rebalancer/operator-abi.js.map +1 -0
  20. package/dist/cjs/abis/rebalancer/rebalancer-abi.js +1326 -0
  21. package/dist/cjs/abis/rebalancer/rebalancer-abi.js.map +1 -0
  22. package/dist/cjs/abis/rebalancer/strategy-abi.js +895 -0
  23. package/dist/cjs/abis/rebalancer/strategy-abi.js.map +1 -0
  24. package/dist/cjs/apis/chart-logs.js +30 -13
  25. package/dist/cjs/apis/chart-logs.js.map +1 -1
  26. package/dist/cjs/apis/market.js +45 -22
  27. package/dist/cjs/apis/market.js.map +1 -1
  28. package/dist/cjs/apis/odos.js +100 -0
  29. package/dist/cjs/apis/odos.js.map +1 -0
  30. package/dist/cjs/apis/open-order.js +76 -39
  31. package/dist/cjs/apis/open-order.js.map +1 -1
  32. package/dist/cjs/apis/pool.js +96 -0
  33. package/dist/cjs/apis/pool.js.map +1 -0
  34. package/dist/cjs/apis/strategy.js +53 -0
  35. package/dist/cjs/apis/strategy.js.map +1 -0
  36. package/dist/cjs/apis/vclob.js +47 -0
  37. package/dist/cjs/apis/vclob.js.map +1 -0
  38. package/dist/cjs/approval.js +83 -26
  39. package/dist/cjs/approval.js.map +1 -1
  40. package/dist/cjs/call.js +787 -125
  41. package/dist/cjs/call.js.map +1 -1
  42. package/dist/cjs/constants/addresses.js +104 -1
  43. package/dist/cjs/constants/addresses.js.map +1 -1
  44. package/dist/cjs/constants/bera-bartio-chain.js +30 -0
  45. package/dist/cjs/constants/bera-bartio-chain.js.map +1 -0
  46. package/dist/cjs/constants/chain.js +29 -2
  47. package/dist/cjs/constants/chain.js.map +1 -1
  48. package/dist/cjs/constants/currency.js +99 -3
  49. package/dist/cjs/constants/currency.js.map +1 -1
  50. package/dist/cjs/constants/fee.js +23 -2
  51. package/dist/cjs/constants/fee.js.map +1 -1
  52. package/dist/cjs/constants/mitosis-testnet-chain.js +30 -0
  53. package/dist/cjs/constants/mitosis-testnet-chain.js.map +1 -0
  54. package/dist/cjs/constants/monad-testnet-chain.js +40 -0
  55. package/dist/cjs/constants/monad-testnet-chain.js.map +1 -0
  56. package/dist/cjs/constants/permit.js +14 -0
  57. package/dist/cjs/constants/permit.js.map +1 -0
  58. package/dist/cjs/constants/price.js +2 -1
  59. package/dist/cjs/constants/price.js.map +1 -1
  60. package/dist/cjs/constants/sonic-mainnet-chain.js +30 -0
  61. package/dist/cjs/constants/sonic-mainnet-chain.js.map +1 -0
  62. package/dist/cjs/constants/subgraph.js +38 -0
  63. package/dist/cjs/constants/subgraph.js.map +1 -0
  64. package/dist/cjs/constants/test-chain.js +50 -0
  65. package/dist/cjs/constants/test-chain.js.map +1 -0
  66. package/dist/cjs/constants/tick.js +6 -0
  67. package/dist/cjs/constants/tick.js.map +1 -0
  68. package/dist/cjs/index.js +1 -1
  69. package/dist/cjs/index.js.map +1 -1
  70. package/dist/cjs/model/book.js +62 -35
  71. package/dist/cjs/model/book.js.map +1 -1
  72. package/dist/cjs/model/market.js +61 -26
  73. package/dist/cjs/model/market.js.map +1 -1
  74. package/dist/cjs/model/pool.js +240 -0
  75. package/dist/cjs/model/pool.js.map +1 -0
  76. package/dist/cjs/model/vclob.js +3 -0
  77. package/dist/cjs/model/vclob.js.map +1 -0
  78. package/dist/cjs/type.js +8 -1
  79. package/dist/cjs/type.js.map +1 -1
  80. package/dist/cjs/utils/allowance.js +39 -0
  81. package/dist/cjs/utils/allowance.js.map +1 -0
  82. package/dist/cjs/utils/approval.js +2 -3
  83. package/dist/cjs/utils/approval.js.map +1 -1
  84. package/dist/cjs/utils/bigint.js +5 -1
  85. package/dist/cjs/utils/bigint.js.map +1 -1
  86. package/dist/cjs/utils/book-id.js +7 -7
  87. package/dist/cjs/utils/book-id.js.map +1 -1
  88. package/dist/cjs/utils/build-transaction.js +3 -4
  89. package/dist/cjs/utils/build-transaction.js.map +1 -1
  90. package/dist/cjs/utils/currency.js +61 -27
  91. package/dist/cjs/utils/currency.js.map +1 -1
  92. package/dist/cjs/utils/market.js +1 -1
  93. package/dist/cjs/utils/market.js.map +1 -1
  94. package/dist/cjs/utils/math.js +3 -1
  95. package/dist/cjs/utils/math.js.map +1 -1
  96. package/dist/cjs/utils/open.js +35 -25
  97. package/dist/cjs/utils/open.js.map +1 -1
  98. package/dist/cjs/utils/order.js +68 -126
  99. package/dist/cjs/utils/order.js.map +1 -1
  100. package/dist/cjs/utils/pool-key.js +17 -0
  101. package/dist/cjs/utils/pool-key.js.map +1 -0
  102. package/dist/cjs/utils/pool.js +88 -0
  103. package/dist/cjs/utils/pool.js.map +1 -0
  104. package/dist/cjs/utils/prices.js +40 -5
  105. package/dist/cjs/utils/prices.js.map +1 -1
  106. package/dist/cjs/utils/tick.js +12 -1
  107. package/dist/cjs/utils/tick.js.map +1 -1
  108. package/dist/cjs/utils/time-series.js +31 -0
  109. package/dist/cjs/utils/time-series.js.map +1 -0
  110. package/dist/cjs/utils/unit-size.js +48 -0
  111. package/dist/cjs/utils/unit-size.js.map +1 -0
  112. package/dist/cjs/utils.js +18 -0
  113. package/dist/cjs/utils.js.map +1 -0
  114. package/dist/cjs/view.js +459 -44
  115. package/dist/cjs/view.js.map +1 -1
  116. package/dist/esm/abis/core/book-manager-abi.js +109 -0
  117. package/dist/esm/abis/core/book-manager-abi.js.map +1 -0
  118. package/dist/esm/abis/core/book-viewer-abi.js +137 -5
  119. package/dist/esm/abis/core/book-viewer-abi.js.map +1 -1
  120. package/dist/esm/abis/core/controller-abi.js +1 -6
  121. package/dist/esm/abis/core/controller-abi.js.map +1 -1
  122. package/dist/esm/abis/governance/election-governor-abi.js +835 -0
  123. package/dist/esm/abis/governance/election-governor-abi.js.map +1 -0
  124. package/dist/esm/abis/governance/keepers-registry-abi.js +543 -0
  125. package/dist/esm/abis/governance/keepers-registry-abi.js.map +1 -0
  126. package/dist/esm/abis/governance/vclob-abi.js +740 -0
  127. package/dist/esm/abis/governance/vclob-abi.js.map +1 -0
  128. package/dist/esm/abis/rebalancer/minter-abi.js +259 -0
  129. package/dist/esm/abis/rebalancer/minter-abi.js.map +1 -0
  130. package/dist/esm/abis/rebalancer/mock-swap-abi.js +92 -0
  131. package/dist/esm/abis/rebalancer/mock-swap-abi.js.map +1 -0
  132. package/dist/esm/abis/rebalancer/operator-abi.js +398 -0
  133. package/dist/esm/abis/rebalancer/operator-abi.js.map +1 -0
  134. package/dist/esm/abis/rebalancer/rebalancer-abi.js +1323 -0
  135. package/dist/esm/abis/rebalancer/rebalancer-abi.js.map +1 -0
  136. package/dist/esm/abis/rebalancer/strategy-abi.js +892 -0
  137. package/dist/esm/abis/rebalancer/strategy-abi.js.map +1 -0
  138. package/dist/esm/apis/chart-logs.js +29 -12
  139. package/dist/esm/apis/chart-logs.js.map +1 -1
  140. package/dist/esm/apis/market.js +47 -24
  141. package/dist/esm/apis/market.js.map +1 -1
  142. package/dist/esm/apis/odos.js +94 -0
  143. package/dist/esm/apis/odos.js.map +1 -0
  144. package/dist/esm/apis/open-order.js +78 -40
  145. package/dist/esm/apis/open-order.js.map +1 -1
  146. package/dist/esm/apis/pool.js +91 -0
  147. package/dist/esm/apis/pool.js.map +1 -0
  148. package/dist/esm/apis/strategy.js +48 -0
  149. package/dist/esm/apis/strategy.js.map +1 -0
  150. package/dist/esm/apis/vclob.js +43 -0
  151. package/dist/esm/apis/vclob.js.map +1 -0
  152. package/dist/esm/approval.js +107 -25
  153. package/dist/esm/approval.js.map +1 -1
  154. package/dist/esm/call.js +818 -166
  155. package/dist/esm/call.js.map +1 -1
  156. package/dist/esm/constants/addresses.js +105 -2
  157. package/dist/esm/constants/addresses.js.map +1 -1
  158. package/dist/esm/constants/bera-bartio-chain.js +27 -0
  159. package/dist/esm/constants/bera-bartio-chain.js.map +1 -0
  160. package/dist/esm/constants/chain.js +28 -2
  161. package/dist/esm/constants/chain.js.map +1 -1
  162. package/dist/esm/constants/currency.js +100 -2
  163. package/dist/esm/constants/currency.js.map +1 -1
  164. package/dist/esm/constants/fee.js +23 -2
  165. package/dist/esm/constants/fee.js.map +1 -1
  166. package/dist/esm/constants/mitosis-testnet-chain.js +27 -0
  167. package/dist/esm/constants/mitosis-testnet-chain.js.map +1 -0
  168. package/dist/esm/constants/monad-testnet-chain.js +37 -0
  169. package/dist/esm/constants/monad-testnet-chain.js.map +1 -0
  170. package/dist/esm/constants/permit.js +11 -0
  171. package/dist/esm/constants/permit.js.map +1 -0
  172. package/dist/esm/constants/price.js +1 -0
  173. package/dist/esm/constants/price.js.map +1 -1
  174. package/dist/esm/constants/sonic-mainnet-chain.js +27 -0
  175. package/dist/esm/constants/sonic-mainnet-chain.js.map +1 -0
  176. package/dist/esm/constants/subgraph.js +34 -0
  177. package/dist/esm/constants/subgraph.js.map +1 -0
  178. package/dist/esm/constants/test-chain.js +47 -0
  179. package/dist/esm/constants/test-chain.js.map +1 -0
  180. package/dist/esm/constants/tick.js +3 -0
  181. package/dist/esm/constants/tick.js.map +1 -0
  182. package/dist/esm/index.js +1 -1
  183. package/dist/esm/index.js.map +1 -1
  184. package/dist/esm/model/book.js +62 -35
  185. package/dist/esm/model/book.js.map +1 -1
  186. package/dist/esm/model/market.js +63 -28
  187. package/dist/esm/model/market.js.map +1 -1
  188. package/dist/esm/model/pool.js +237 -0
  189. package/dist/esm/model/pool.js.map +1 -0
  190. package/dist/esm/model/vclob.js +2 -0
  191. package/dist/esm/model/vclob.js.map +1 -0
  192. package/dist/esm/type.js +7 -0
  193. package/dist/esm/type.js.map +1 -1
  194. package/dist/esm/utils/allowance.js +35 -0
  195. package/dist/esm/utils/allowance.js.map +1 -0
  196. package/dist/esm/utils/approval.js +2 -3
  197. package/dist/esm/utils/approval.js.map +1 -1
  198. package/dist/esm/utils/bigint.js +2 -0
  199. package/dist/esm/utils/bigint.js.map +1 -1
  200. package/dist/esm/utils/book-id.js +7 -7
  201. package/dist/esm/utils/book-id.js.map +1 -1
  202. package/dist/esm/utils/build-transaction.js +3 -4
  203. package/dist/esm/utils/build-transaction.js.map +1 -1
  204. package/dist/esm/utils/currency.js +59 -25
  205. package/dist/esm/utils/currency.js.map +1 -1
  206. package/dist/esm/utils/market.js +1 -1
  207. package/dist/esm/utils/market.js.map +1 -1
  208. package/dist/esm/utils/math.js +1 -0
  209. package/dist/esm/utils/math.js.map +1 -1
  210. package/dist/esm/utils/open.js +33 -23
  211. package/dist/esm/utils/open.js.map +1 -1
  212. package/dist/esm/utils/order.js +67 -125
  213. package/dist/esm/utils/order.js.map +1 -1
  214. package/dist/esm/utils/pool-key.js +12 -0
  215. package/dist/esm/utils/pool-key.js.map +1 -0
  216. package/dist/esm/utils/pool.js +84 -0
  217. package/dist/esm/utils/pool.js.map +1 -0
  218. package/dist/esm/utils/prices.js +39 -5
  219. package/dist/esm/utils/prices.js.map +1 -1
  220. package/dist/esm/utils/tick.js +11 -1
  221. package/dist/esm/utils/tick.js.map +1 -1
  222. package/dist/esm/utils/time-series.js +27 -0
  223. package/dist/esm/utils/time-series.js.map +1 -0
  224. package/dist/esm/utils/unit-size.js +44 -0
  225. package/dist/esm/utils/unit-size.js.map +1 -0
  226. package/dist/esm/utils.js +5 -0
  227. package/dist/esm/utils.js.map +1 -0
  228. package/dist/esm/view.js +516 -61
  229. package/dist/esm/view.js.map +1 -1
  230. package/dist/tsconfig.build.tsbuildinfo +1 -1
  231. package/dist/types/abis/core/book-manager-abi.d.ts +82 -0
  232. package/dist/types/abis/core/book-manager-abi.d.ts.map +1 -0
  233. package/dist/types/abis/core/book-viewer-abi.d.ts +107 -5
  234. package/dist/types/abis/core/book-viewer-abi.d.ts.map +1 -1
  235. package/dist/types/abis/core/controller-abi.d.ts +1 -5
  236. package/dist/types/abis/core/controller-abi.d.ts.map +1 -1
  237. package/dist/types/abis/governance/election-governor-abi.d.ts +648 -0
  238. package/dist/types/abis/governance/election-governor-abi.d.ts.map +1 -0
  239. package/dist/types/abis/governance/keepers-registry-abi.d.ts +417 -0
  240. package/dist/types/abis/governance/keepers-registry-abi.d.ts.map +1 -0
  241. package/dist/types/abis/governance/vclob-abi.d.ts +568 -0
  242. package/dist/types/abis/governance/vclob-abi.d.ts.map +1 -0
  243. package/dist/types/abis/rebalancer/minter-abi.d.ts +198 -0
  244. package/dist/types/abis/rebalancer/minter-abi.d.ts.map +1 -0
  245. package/dist/types/abis/rebalancer/mock-swap-abi.d.ts +70 -0
  246. package/dist/types/abis/rebalancer/mock-swap-abi.d.ts.map +1 -0
  247. package/dist/types/abis/rebalancer/operator-abi.d.ts +308 -0
  248. package/dist/types/abis/rebalancer/operator-abi.d.ts.map +1 -0
  249. package/dist/types/abis/rebalancer/rebalancer-abi.d.ts +1023 -0
  250. package/dist/types/abis/rebalancer/rebalancer-abi.d.ts.map +1 -0
  251. package/dist/types/abis/rebalancer/strategy-abi.d.ts +690 -0
  252. package/dist/types/abis/rebalancer/strategy-abi.d.ts.map +1 -0
  253. package/dist/types/apis/chart-logs.d.ts +3 -0
  254. package/dist/types/apis/chart-logs.d.ts.map +1 -1
  255. package/dist/types/apis/market.d.ts +2 -1
  256. package/dist/types/apis/market.d.ts.map +1 -1
  257. package/dist/types/apis/odos.d.ts +28 -0
  258. package/dist/types/apis/odos.d.ts.map +1 -0
  259. package/dist/types/apis/open-order.d.ts +4 -2
  260. package/dist/types/apis/open-order.d.ts.map +1 -1
  261. package/dist/types/apis/pool.d.ts +11 -0
  262. package/dist/types/apis/pool.d.ts.map +1 -0
  263. package/dist/types/apis/strategy.d.ts +6 -0
  264. package/dist/types/apis/strategy.d.ts.map +1 -0
  265. package/dist/types/apis/vclob.d.ts +5 -0
  266. package/dist/types/apis/vclob.d.ts.map +1 -0
  267. package/dist/types/approval.d.ts +37 -3
  268. package/dist/types/approval.d.ts.map +1 -1
  269. package/dist/types/call.d.ts +275 -59
  270. package/dist/types/call.d.ts.map +1 -1
  271. package/dist/types/constants/addresses.d.ts +7 -0
  272. package/dist/types/constants/addresses.d.ts.map +1 -1
  273. package/dist/types/constants/bera-bartio-chain.d.ts +33 -0
  274. package/dist/types/constants/bera-bartio-chain.d.ts.map +1 -0
  275. package/dist/types/constants/chain.d.ts +10 -2
  276. package/dist/types/constants/chain.d.ts.map +1 -1
  277. package/dist/types/constants/currency.d.ts +9 -0
  278. package/dist/types/constants/currency.d.ts.map +1 -1
  279. package/dist/types/constants/fee.d.ts +7 -2
  280. package/dist/types/constants/fee.d.ts.map +1 -1
  281. package/dist/types/constants/mitosis-testnet-chain.d.ts +33 -0
  282. package/dist/types/constants/mitosis-testnet-chain.d.ts.map +1 -0
  283. package/dist/types/constants/monad-testnet-chain.d.ts +37 -0
  284. package/dist/types/constants/monad-testnet-chain.d.ts.map +1 -0
  285. package/dist/types/constants/permit.d.ts +10 -0
  286. package/dist/types/constants/permit.d.ts.map +1 -0
  287. package/dist/types/constants/price.d.ts +1 -0
  288. package/dist/types/constants/price.d.ts.map +1 -1
  289. package/dist/types/constants/sonic-mainnet-chain.d.ts +33 -0
  290. package/dist/types/constants/sonic-mainnet-chain.d.ts.map +1 -0
  291. package/dist/types/constants/subgraph.d.ts +5 -0
  292. package/dist/types/constants/subgraph.d.ts.map +1 -0
  293. package/dist/types/constants/test-chain.d.ts +4 -0
  294. package/dist/types/constants/test-chain.d.ts.map +1 -0
  295. package/dist/types/constants/tick.d.ts +3 -0
  296. package/dist/types/constants/tick.d.ts.map +1 -0
  297. package/dist/types/index.d.ts +1 -1
  298. package/dist/types/index.d.ts.map +1 -1
  299. package/dist/types/model/book.d.ts +25 -33
  300. package/dist/types/model/book.d.ts.map +1 -1
  301. package/dist/types/model/currency.d.ts +7 -0
  302. package/dist/types/model/currency.d.ts.map +1 -1
  303. package/dist/types/model/depth.d.ts +4 -3
  304. package/dist/types/model/depth.d.ts.map +1 -1
  305. package/dist/types/model/market.d.ts +24 -13
  306. package/dist/types/model/market.d.ts.map +1 -1
  307. package/dist/types/model/open-order.d.ts +20 -27
  308. package/dist/types/model/open-order.d.ts.map +1 -1
  309. package/dist/types/model/pool.d.ts +77 -0
  310. package/dist/types/model/pool.d.ts.map +1 -0
  311. package/dist/types/model/vclob.d.ts +7 -0
  312. package/dist/types/model/vclob.d.ts.map +1 -0
  313. package/dist/types/type.d.ts +141 -6
  314. package/dist/types/type.d.ts.map +1 -1
  315. package/dist/types/utils/allowance.d.ts +3 -0
  316. package/dist/types/utils/allowance.d.ts.map +1 -0
  317. package/dist/types/utils/approval.d.ts +2 -1
  318. package/dist/types/utils/approval.d.ts.map +1 -1
  319. package/dist/types/utils/bigint.d.ts +2 -0
  320. package/dist/types/utils/bigint.d.ts.map +1 -1
  321. package/dist/types/utils/book-id.d.ts +2 -1
  322. package/dist/types/utils/book-id.d.ts.map +1 -1
  323. package/dist/types/utils/build-transaction.d.ts +3 -3
  324. package/dist/types/utils/build-transaction.d.ts.map +1 -1
  325. package/dist/types/utils/currency.d.ts +3 -2
  326. package/dist/types/utils/currency.d.ts.map +1 -1
  327. package/dist/types/utils/math.d.ts +1 -0
  328. package/dist/types/utils/math.d.ts.map +1 -1
  329. package/dist/types/utils/open.d.ts +2 -1
  330. package/dist/types/utils/open.d.ts.map +1 -1
  331. package/dist/types/utils/order.d.ts +4 -11
  332. package/dist/types/utils/order.d.ts.map +1 -1
  333. package/dist/types/utils/pool-key.d.ts +3 -0
  334. package/dist/types/utils/pool-key.d.ts.map +1 -0
  335. package/dist/types/utils/pool.d.ts +11 -0
  336. package/dist/types/utils/pool.d.ts.map +1 -0
  337. package/dist/types/utils/prices.d.ts +13 -2
  338. package/dist/types/utils/prices.d.ts.map +1 -1
  339. package/dist/types/utils/tick.d.ts +1 -0
  340. package/dist/types/utils/tick.d.ts.map +1 -1
  341. package/dist/types/utils/time-series.d.ts +4 -0
  342. package/dist/types/utils/time-series.d.ts.map +1 -0
  343. package/dist/types/utils/unit-size.d.ts +5 -0
  344. package/dist/types/utils/unit-size.d.ts.map +1 -0
  345. package/dist/types/utils.d.ts +5 -0
  346. package/dist/types/utils.d.ts.map +1 -0
  347. package/dist/types/view.d.ts +247 -30
  348. package/dist/types/view.d.ts.map +1 -1
  349. package/package.json +3 -2
  350. package/dist/cjs/abis/core/params-abi.js +0 -62
  351. package/dist/cjs/abis/core/params-abi.js.map +0 -1
  352. package/dist/cjs/apis/subgraph.js +0 -26
  353. package/dist/cjs/apis/subgraph.js.map +0 -1
  354. package/dist/cjs/constants/client.js +0 -14
  355. package/dist/cjs/constants/client.js.map +0 -1
  356. package/dist/cjs/constants/subgraph-url.js +0 -8
  357. package/dist/cjs/constants/subgraph-url.js.map +0 -1
  358. package/dist/cjs/signature.js +0 -146
  359. package/dist/cjs/signature.js.map +0 -1
  360. package/dist/cjs/utils/decorator.js +0 -13
  361. package/dist/cjs/utils/decorator.js.map +0 -1
  362. package/dist/cjs/utils/unit.js +0 -34
  363. package/dist/cjs/utils/unit.js.map +0 -1
  364. package/dist/esm/abis/core/params-abi.js +0 -59
  365. package/dist/esm/abis/core/params-abi.js.map +0 -1
  366. package/dist/esm/apis/subgraph.js +0 -22
  367. package/dist/esm/apis/subgraph.js.map +0 -1
  368. package/dist/esm/constants/client.js +0 -10
  369. package/dist/esm/constants/client.js.map +0 -1
  370. package/dist/esm/constants/subgraph-url.js +0 -5
  371. package/dist/esm/constants/subgraph-url.js.map +0 -1
  372. package/dist/esm/signature.js +0 -170
  373. package/dist/esm/signature.js.map +0 -1
  374. package/dist/esm/utils/decorator.js +0 -9
  375. package/dist/esm/utils/decorator.js.map +0 -1
  376. package/dist/esm/utils/unit.js +0 -30
  377. package/dist/esm/utils/unit.js.map +0 -1
  378. package/dist/types/abis/core/params-abi.d.ts +0 -21
  379. package/dist/types/abis/core/params-abi.d.ts.map +0 -1
  380. package/dist/types/apis/subgraph.d.ts +0 -3
  381. package/dist/types/apis/subgraph.d.ts.map +0 -1
  382. package/dist/types/constants/client.d.ts +0 -5
  383. package/dist/types/constants/client.d.ts.map +0 -1
  384. package/dist/types/constants/subgraph-url.d.ts +0 -5
  385. package/dist/types/constants/subgraph-url.d.ts.map +0 -1
  386. package/dist/types/signature.d.ts +0 -38
  387. package/dist/types/signature.d.ts.map +0 -1
  388. package/dist/types/utils/decorator.d.ts +0 -6
  389. package/dist/types/utils/decorator.d.ts.map +0 -1
  390. package/dist/types/utils/unit.d.ts +0 -4
  391. package/dist/types/utils/unit.d.ts.map +0 -1
package/dist/esm/view.js CHANGED
@@ -1,19 +1,59 @@
1
- import { formatUnits, getAddress, isAddressEqual, parseUnits } from 'viem';
1
+ import { createPublicClient, formatUnits, getAddress, http, isAddressEqual, parseUnits, } from 'viem';
2
2
  import { fetchMarket } from './apis/market';
3
- import { parsePrice } from './utils/prices';
4
- import { MAX_PRICE } from './constants/price';
5
- import { fetchOpenOrder, fetchOpenOrders } from './apis/open-order';
6
- import { decorator } from './utils/decorator';
7
- import { fetchChartLogs, fetchLatestChartLog } from './apis/chart-logs';
3
+ import { CHAIN_MAP } from './constants/chain';
4
+ import { formatPrice, parsePrice } from './utils/prices';
5
+ import { fetchOpenOrder, fetchOpenOrdersByUserAddress } from './apis/open-order';
6
+ import { CHART_LOG_INTERVAL_TIMESTAMP, fetchChartLogs, fetchLatestChartLog, } from './apis/chart-logs';
8
7
  import { getMarketId } from './utils/market';
8
+ import { CONTRACT_ADDRESSES } from './constants/addresses';
9
+ import { invertTick, toPrice } from './utils/tick';
10
+ import { MAX_TICK, MIN_TICK } from './constants/tick';
11
+ import { fetchPool, fetchPoolPerformance } from './apis/pool';
12
+ import { fetchLastAmounts, fetchStrategyPosition } from './apis/strategy';
13
+ import { Subgraph } from './constants/subgraph';
14
+ import { fillAndSortByTimestamp } from './utils/time-series';
15
+ import { fetchVCLOBList } from './apis/vclob';
16
+ import { ELECTION_GOVERNOR_ABI } from './abis/governance/election-governor-abi';
17
+ import { VCLOB_ABI } from './abis/governance/vclob-abi';
18
+ import { KEEPERS_REGISTRY_ABI } from './abis/governance/keepers-registry-abi';
19
+ /**
20
+ * Get contract addresses by chain id
21
+ * @param chainId - chain id from {@link CHAIN_IDS}
22
+ * @returns Contract addresses
23
+ *
24
+ * @example
25
+ * import { getContractAddresses } from '@clober/v2-sdk'
26
+ *
27
+ * const addresses = await getContractAddresses({
28
+ * chainId: 421614,
29
+ * })
30
+ */
31
+ export const getContractAddresses = ({ chainId }) => {
32
+ return CONTRACT_ADDRESSES[chainId];
33
+ };
34
+ /**
35
+ * Get subgraph block number by chain id
36
+ * @param chainId - chain id from {@link CHAIN_IDS}
37
+ * @returns Contract addresses
38
+ *
39
+ * @example
40
+ * import { getContractAddresses } from '@clober/v2-sdk'
41
+ *
42
+ * const blockNumber = await getSubgraphBlockNumber({
43
+ * chainId: 421614,
44
+ * })
45
+ */
46
+ export const getSubgraphBlockNumber = async ({ chainId, }) => {
47
+ const { data: { latestBlock: { blockNumber }, }, } = await Subgraph.get(chainId, 'getLatestBlockNumber', 'query getLatestBlockNumber { latestBlock(id: "latest") { blockNumber } }', {});
48
+ return Number(blockNumber);
49
+ };
9
50
  /**
10
51
  * Get market information by chain id and token addresses
11
52
  * @param chainId - chain id from {@link CHAIN_IDS}
12
53
  * @param token0 - token0 address
13
54
  * @param token1 - token1 address
14
- * @param options
55
+ * @param options {@link DefaultReadContractOptions} options.
15
56
  * @param options.n - number of depth levels to fetch
16
- * @param options.rpcUrl - RPC URL of the blockchain
17
57
  * @returns A market {@link Market}
18
58
  *
19
59
  * @example
@@ -25,23 +65,387 @@ import { getMarketId } from './utils/market';
25
65
  * token1: '0x0000000000000000000000000000000000000000',
26
66
  * })
27
67
  */
28
- export const getMarket = decorator(async ({ chainId, token0, token1, options, }) => {
68
+ export const getMarket = async ({ chainId, token0, token1, options, }) => {
69
+ if (isAddressEqual(token0, token1)) {
70
+ throw new Error('Token0 and token1 must be different');
71
+ }
72
+ const publicClient = createPublicClient({
73
+ chain: CHAIN_MAP[chainId],
74
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
75
+ });
76
+ const market = await fetchMarket(publicClient, chainId, [token0, token1], !!(options && options.useSubgraph), options?.n);
77
+ return market.toJson();
78
+ };
79
+ /**
80
+ * Get pool information by chain id and token addresses
81
+ * @param chainId - chain id from {@link CHAIN_IDS}
82
+ * @param token0 - token0 address
83
+ * @param token1 - token1 address
84
+ * @param salt - salt for the pool
85
+ * @param options {@link DefaultReadContractOptions} options.
86
+ * @param options.n - number of depth levels to fetch
87
+ * @returns A pool {@link Pool}
88
+ *
89
+ * @example
90
+ * import { getPool } from '@clober/v2-sdk'
91
+ *
92
+ * const market = await getPool({
93
+ * chainId: 421614,
94
+ * token0: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
95
+ * token1: '0x0000000000000000000000000000000000000000',
96
+ * salt: '0x0000000000000000000000000000000000000000000000000000000000000000',
97
+ * })
98
+ */
99
+ export const getPool = async ({ chainId, token0, token1, salt, options, }) => {
100
+ if (isAddressEqual(token0, token1)) {
101
+ throw new Error('Token0 and token1 must be different');
102
+ }
103
+ const publicClient = createPublicClient({
104
+ chain: CHAIN_MAP[chainId],
105
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
106
+ });
107
+ const pool = await fetchPool(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph), options?.market);
108
+ return pool.toJson();
109
+ };
110
+ export const getPoolPerformance = async ({ chainId, token0, token1, salt, volumeFromTimestamp, volumeToTimestamp, snapshotFromTimestamp, snapshotToTimestamp, snapshotIntervalType, spreadProfitFromTimestamp, spreadProfitToTimestamp, options, }) => {
111
+ if (isAddressEqual(token0, token1)) {
112
+ throw new Error('Token0 and token1 must be different');
113
+ }
114
+ if (!options?.useSubgraph) {
115
+ throw new Error('useSubgraph must be true');
116
+ }
117
+ let pool;
118
+ if (options?.pool) {
119
+ pool = options.pool;
120
+ }
121
+ else {
122
+ const publicClient = createPublicClient({
123
+ chain: CHAIN_MAP[chainId],
124
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
125
+ });
126
+ pool = (await fetchPool(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph), undefined)).toJson();
127
+ }
128
+ const poolPerformance = await fetchPoolPerformance(chainId, pool.key, volumeFromTimestamp, snapshotFromTimestamp, snapshotIntervalType, spreadProfitFromTimestamp);
129
+ const poolVolumes = fillAndSortByTimestamp(poolPerformance.poolVolumes, 300, volumeFromTimestamp, volumeToTimestamp, (timestamp) => {
130
+ const emptyPoolVolume = {
131
+ id: '',
132
+ poolKey: pool.key,
133
+ intervalType: '5m',
134
+ timestamp: BigInt(timestamp),
135
+ currencyAVolume: 0n,
136
+ currencyBVolume: 0n,
137
+ bookACurrencyAVolume: 0n,
138
+ bookACurrencyBVolume: 0n,
139
+ bookBCurrencyAVolume: 0n,
140
+ bookBCurrencyBVolume: 0n,
141
+ };
142
+ return emptyPoolVolume;
143
+ });
144
+ const poolSnapshots = fillAndSortByTimestamp(poolPerformance.poolSnapshots, CHART_LOG_INTERVAL_TIMESTAMP[snapshotIntervalType], snapshotFromTimestamp, snapshotToTimestamp, (timestamp, prev) => {
145
+ const emptyPoolSnapshot = {
146
+ id: '',
147
+ poolKey: pool.key,
148
+ intervalType: snapshotIntervalType,
149
+ timestamp: BigInt(timestamp),
150
+ price: prev ? prev.price : 0n,
151
+ liquidityA: prev ? prev.liquidityA : 0n,
152
+ liquidityB: prev ? prev.liquidityB : 0n,
153
+ totalSupply: prev ? prev.totalSupply : 0n,
154
+ };
155
+ return emptyPoolSnapshot;
156
+ });
157
+ const poolSpreadProfits = fillAndSortByTimestamp(poolPerformance.poolSpreadProfits, 300, spreadProfitFromTimestamp, spreadProfitToTimestamp, (timestamp) => {
158
+ const emptyPoolSpreadProfit = {
159
+ id: '',
160
+ intervalType: '5m',
161
+ timestamp: BigInt(timestamp),
162
+ accumulatedProfitInUsd: '0',
163
+ };
164
+ return emptyPoolSpreadProfit;
165
+ });
166
+ return {
167
+ poolVolumes: poolVolumes.map((poolVolume) => ({
168
+ poolKey: poolVolume.poolKey,
169
+ intervalType: poolVolume.intervalType,
170
+ timestamp: Number(poolVolume.timestamp),
171
+ currencyAVolume: {
172
+ currency: pool.currencyA,
173
+ value: formatUnits(poolVolume.currencyAVolume, pool.currencyA.decimals),
174
+ },
175
+ currencyBVolume: {
176
+ currency: pool.currencyB,
177
+ value: formatUnits(poolVolume.currencyBVolume, pool.currencyB.decimals),
178
+ },
179
+ })),
180
+ poolSnapshots: poolSnapshots.map((poolSnapshot) => ({
181
+ poolKey: poolSnapshot.poolKey,
182
+ intervalType: poolSnapshot.intervalType,
183
+ timestamp: Number(poolSnapshot.timestamp),
184
+ price: formatUnits(poolSnapshot.price, 18),
185
+ liquidityA: {
186
+ currency: pool.currencyA,
187
+ value: formatUnits(poolSnapshot.liquidityA, pool.currencyA.decimals),
188
+ },
189
+ liquidityB: {
190
+ currency: pool.currencyB,
191
+ value: formatUnits(poolSnapshot.liquidityB, pool.currencyB.decimals),
192
+ },
193
+ totalSupply: {
194
+ currency: pool.currencyLp,
195
+ value: formatUnits(poolSnapshot.totalSupply, pool.currencyLp.decimals),
196
+ },
197
+ })),
198
+ poolSpreadProfits: poolSpreadProfits.map((poolSpreadProfit) => ({
199
+ intervalType: poolSpreadProfit.intervalType,
200
+ timestamp: Number(poolSpreadProfit.timestamp),
201
+ accumulatedProfitInUsd: poolSpreadProfit.accumulatedProfitInUsd,
202
+ })),
203
+ };
204
+ };
205
+ export const getStrategyPrice = async ({ chainId, token0, token1, salt, options, }) => {
206
+ if (isAddressEqual(token0, token1)) {
207
+ throw new Error('Token0 and token1 must be different');
208
+ }
209
+ const publicClient = createPublicClient({
210
+ chain: CHAIN_MAP[chainId],
211
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
212
+ });
213
+ return fetchStrategyPosition(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph), options?.market);
214
+ };
215
+ export const getLastAmounts = async ({ chainId, token0, token1, salt, options, }) => {
29
216
  if (isAddressEqual(token0, token1)) {
30
217
  throw new Error('Token0 and token1 must be different');
31
218
  }
32
- const market = await fetchMarket(chainId, [token0, token1], options?.n);
219
+ const publicClient = createPublicClient({
220
+ chain: CHAIN_MAP[chainId],
221
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
222
+ });
223
+ return fetchLastAmounts(publicClient, chainId, [token0, token1], salt, !!(options && options.useSubgraph), options?.market);
224
+ };
225
+ export const getVCLOBList = async ({ chainId, userAddress, options, }) => {
226
+ const publicClient = createPublicClient({
227
+ chain: CHAIN_MAP[chainId],
228
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
229
+ });
230
+ return fetchVCLOBList(publicClient, chainId, userAddress, !!(options && options.useSubgraph));
231
+ };
232
+ export const getKeepersElectionGovernorMetadata = async ({ chainId, options, }) => {
233
+ const publicClient = createPublicClient({
234
+ chain: CHAIN_MAP[chainId],
235
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
236
+ });
237
+ const [minCandidateBalance, quota] = await publicClient.multicall({
238
+ contracts: [
239
+ {
240
+ address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
241
+ abi: ELECTION_GOVERNOR_ABI,
242
+ functionName: 'minCandidateBalance',
243
+ },
244
+ {
245
+ address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
246
+ abi: ELECTION_GOVERNOR_ABI,
247
+ functionName: 'quota',
248
+ },
249
+ ],
250
+ allowFailure: false,
251
+ });
252
+ return {
253
+ minCandidateBalance,
254
+ quota,
255
+ };
256
+ };
257
+ export const getKeepersElectionCurrentRoundData = async ({ chainId, userAddress, options, }) => {
258
+ const publicClient = createPublicClient({
259
+ chain: CHAIN_MAP[chainId],
260
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
261
+ });
262
+ const [currentRound, nextRoundStartTime, currentKeepers] = await publicClient.multicall({
263
+ contracts: [
264
+ {
265
+ address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
266
+ abi: ELECTION_GOVERNOR_ABI,
267
+ functionName: 'currentRound',
268
+ },
269
+ {
270
+ address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
271
+ abi: ELECTION_GOVERNOR_ABI,
272
+ functionName: 'nextRoundStartTime',
273
+ },
274
+ {
275
+ address: CONTRACT_ADDRESSES[chainId].KeepersRegistry,
276
+ abi: KEEPERS_REGISTRY_ABI,
277
+ functionName: 'getCurrentKeepers',
278
+ },
279
+ ],
280
+ allowFailure: false,
281
+ });
282
+ const [currentRoundData, candidates, finalists] = await publicClient.multicall({
283
+ contracts: [
284
+ {
285
+ address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
286
+ abi: ELECTION_GOVERNOR_ABI,
287
+ functionName: 'getRoundData',
288
+ args: [currentRound],
289
+ },
290
+ {
291
+ address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
292
+ abi: ELECTION_GOVERNOR_ABI,
293
+ functionName: 'getCandidates',
294
+ args: [currentRound],
295
+ },
296
+ {
297
+ address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
298
+ abi: ELECTION_GOVERNOR_ABI,
299
+ functionName: 'getFinalists',
300
+ args: [currentRound],
301
+ },
302
+ ],
303
+ allowFailure: false,
304
+ });
305
+ const [userVCLOBAmount, ...multicallResults] = await publicClient.multicall({
306
+ contracts: [
307
+ {
308
+ address: CONTRACT_ADDRESSES[chainId].VoteLockedCloberToken,
309
+ abi: VCLOB_ABI,
310
+ functionName: 'getPastBalanceOf',
311
+ args: [userAddress, currentRoundData.startTime],
312
+ },
313
+ ...candidates.map((candidate) => ({
314
+ address: CONTRACT_ADDRESSES[chainId].VoteLockedCloberToken,
315
+ abi: VCLOB_ABI,
316
+ functionName: 'getPastBalanceOf',
317
+ args: [candidate, currentRoundData.startTime],
318
+ })),
319
+ ...candidates.map((candidate) => ({
320
+ address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
321
+ abi: ELECTION_GOVERNOR_ABI,
322
+ functionName: 'hasVotedTo',
323
+ args: [currentRound, userAddress, candidate],
324
+ })),
325
+ ...candidates.map((candidate) => ({
326
+ address: CONTRACT_ADDRESSES[chainId].ElectionGovernor,
327
+ abi: ELECTION_GOVERNOR_ABI,
328
+ functionName: 'getVotes',
329
+ args: [currentRound, candidate],
330
+ })),
331
+ ],
332
+ allowFailure: false,
333
+ });
334
+ const vclobAmountOfCandidateList = multicallResults.slice(0, candidates.length);
335
+ const hasVotedToCandidateList = multicallResults.slice(candidates.length, candidates.length * 2);
336
+ const votesForCandidateList = multicallResults.slice(candidates.length * 2);
337
+ const candidateDataMap = new Map();
338
+ for (let i = 0; i < candidates.length; i++) {
339
+ candidateDataMap.set(candidates[i], {
340
+ address: candidates[i],
341
+ vclobAmount: vclobAmountOfCandidateList[i],
342
+ hasVotedTo: hasVotedToCandidateList[i],
343
+ forVotes: votesForCandidateList[i][0],
344
+ againstVotes: votesForCandidateList[i][1],
345
+ });
346
+ }
33
347
  return {
348
+ round: currentRound,
349
+ keepers: currentKeepers,
350
+ nextRoundStartTime: nextRoundStartTime,
351
+ vclobAmount: userVCLOBAmount,
352
+ status: currentRoundData.status,
353
+ quota: currentRoundData.quota,
354
+ finalistsThreshold: currentRoundData.finalistsThreshold,
355
+ startTime: BigInt(currentRoundData.startTime),
356
+ votingEndTime: BigInt(currentRoundData.votingEndTime),
357
+ registrationEndTime: BigInt(currentRoundData.registrationEndTime),
358
+ candidatesLength: currentRoundData.candidatesLength,
359
+ finalistsLength: currentRoundData.finalistsLength,
360
+ candidates: candidates.map((candidate) => candidateDataMap.get(candidate)),
361
+ finalists: finalists.map((finalist) => candidateDataMap.get(finalist)),
362
+ };
363
+ };
364
+ /**
365
+ * Calculates and returns the neighboring price ticks and their corresponding prices for a given input price.
366
+ *
367
+ * @param {CHAIN_IDS} chainId - chain id from {@link CHAIN_IDS}
368
+ * @param {string} price - The input price to calculate the neighborhood for, as a string.
369
+ * @param {Currency} currency0 - token0 currency {@link Currency}.
370
+ * @param {Currency} currency1 - token1 currency {@link Currency}.
371
+ *
372
+ * @returns {Object} An object containing the normal and inverted price neighborhoods. Each neighborhood includes:
373
+ * - up: The tick and price for one tick above the current price.
374
+ * - now: The tick and price for the current price.
375
+ * - down: The tick and price for one tick below the current price.
376
+ */
377
+ export const getPriceNeighborhood = ({ chainId, price, currency0, currency1, }) => {
378
+ const quoteTokenAddress = getQuoteToken({
34
379
  chainId,
35
- quote: market.quote,
36
- base: market.base,
37
- makerFee: market.makerFee,
38
- takerFee: market.takerFee,
39
- bids: market.bids,
40
- bidBookOpen: market.bidBookOpen,
41
- asks: market.asks,
42
- askBookOpen: market.askBookOpen,
380
+ token0: currency0.address,
381
+ token1: currency1.address,
382
+ });
383
+ const quoteCurrency = isAddressEqual(quoteTokenAddress, currency0.address)
384
+ ? currency0
385
+ : currency1;
386
+ const baseCurrency = isAddressEqual(quoteTokenAddress, currency0.address)
387
+ ? currency1
388
+ : currency0;
389
+ const { roundingDownTick, roundingUpTick } = parsePrice(Number(price), quoteCurrency.decimals, baseCurrency.decimals);
390
+ const bidBookTick = roundingDownTick;
391
+ const askBookTick = invertTick(roundingUpTick);
392
+ return {
393
+ normal: {
394
+ nextUp: {
395
+ tick: bidBookTick + 2n,
396
+ price: formatPrice(toPrice(bidBookTick + 2n), quoteCurrency.decimals, baseCurrency.decimals),
397
+ marketPrice: formatPrice(toPrice(bidBookTick + 2n), quoteCurrency.decimals, baseCurrency.decimals),
398
+ },
399
+ up: {
400
+ tick: bidBookTick + 1n,
401
+ price: formatPrice(toPrice(bidBookTick + 1n), quoteCurrency.decimals, baseCurrency.decimals),
402
+ marketPrice: formatPrice(toPrice(bidBookTick + 1n), quoteCurrency.decimals, baseCurrency.decimals),
403
+ },
404
+ now: {
405
+ tick: bidBookTick,
406
+ price: formatPrice(toPrice(bidBookTick), quoteCurrency.decimals, baseCurrency.decimals),
407
+ marketPrice: formatPrice(toPrice(bidBookTick), quoteCurrency.decimals, baseCurrency.decimals),
408
+ },
409
+ down: {
410
+ tick: bidBookTick - 1n,
411
+ price: formatPrice(toPrice(bidBookTick - 1n), quoteCurrency.decimals, baseCurrency.decimals),
412
+ marketPrice: formatPrice(toPrice(bidBookTick - 1n), quoteCurrency.decimals, baseCurrency.decimals),
413
+ },
414
+ nextDown: {
415
+ tick: bidBookTick - 2n,
416
+ price: formatPrice(toPrice(bidBookTick - 2n), quoteCurrency.decimals, baseCurrency.decimals),
417
+ marketPrice: formatPrice(toPrice(bidBookTick - 2n), quoteCurrency.decimals, baseCurrency.decimals),
418
+ },
419
+ },
420
+ inverted: {
421
+ nextUp: {
422
+ tick: askBookTick + 2n,
423
+ price: formatPrice(toPrice(askBookTick + 2n), baseCurrency.decimals, quoteCurrency.decimals),
424
+ marketPrice: formatPrice(toPrice(invertTick(askBookTick + 2n)), quoteCurrency.decimals, baseCurrency.decimals),
425
+ },
426
+ up: {
427
+ tick: askBookTick + 1n,
428
+ price: formatPrice(toPrice(askBookTick + 1n), baseCurrency.decimals, quoteCurrency.decimals),
429
+ marketPrice: formatPrice(toPrice(invertTick(askBookTick + 1n)), quoteCurrency.decimals, baseCurrency.decimals),
430
+ },
431
+ now: {
432
+ tick: askBookTick,
433
+ price: formatPrice(toPrice(askBookTick), baseCurrency.decimals, quoteCurrency.decimals),
434
+ marketPrice: formatPrice(toPrice(invertTick(askBookTick)), quoteCurrency.decimals, baseCurrency.decimals),
435
+ },
436
+ down: {
437
+ tick: askBookTick - 1n,
438
+ price: formatPrice(toPrice(askBookTick - 1n), baseCurrency.decimals, quoteCurrency.decimals),
439
+ marketPrice: formatPrice(toPrice(invertTick(askBookTick - 1n)), quoteCurrency.decimals, baseCurrency.decimals),
440
+ },
441
+ nextDown: {
442
+ tick: askBookTick - 2n,
443
+ price: formatPrice(toPrice(askBookTick - 2n), baseCurrency.decimals, quoteCurrency.decimals),
444
+ marketPrice: formatPrice(toPrice(invertTick(askBookTick - 2n)), quoteCurrency.decimals, baseCurrency.decimals),
445
+ },
446
+ },
43
447
  };
44
- });
448
+ };
45
449
  /**
46
450
  * Calculates the expected output for a given input amount, based on the provided market data.
47
451
  *
@@ -49,40 +453,67 @@ export const getMarket = decorator(async ({ chainId, token0, token1, options, })
49
453
  * @param inputToken The address of the input token.
50
454
  * @param outputToken The address of the output token.
51
455
  * @param amountIn The amount of expected input amount. (ex 1.2 ETH -> 1.2)
52
- * @param options
53
- * @param options.limitPrice The maximum limit price to spend.
54
- * @param options.rpcUrl The RPC URL of the blockchain.
456
+ * @param options {@link DefaultReadContractOptions} options.
457
+ * @param options.limitPrice The maximum limit price to take.
458
+ * @param options.roundingDownTakenBid Whether to round down the taken bid.
459
+ * @param options.roundingUpTakenAsk Whether to round up the taken ask.
55
460
  * @returns A Promise resolving to an object containing the taken amount, spend amount and result of the calculation.
56
461
  * @example
57
462
  * import { getExpectedOutput } from '@clober/v2-sdk'
58
463
  *
59
- * const { takenAmount, spendAmount } = await getExpectedOutput({
464
+ * const { takenAmount, spentAmount } = await getExpectedOutput({
60
465
  * chainId: 421614,
61
466
  * inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
62
467
  * outputToken: '0x0000000000000000000000000000000000000000',
63
468
  * amountIn: '1000.123', // spend 1000.123 USDC
64
469
  * })
65
470
  */
66
- export const getExpectedOutput = decorator(async ({ chainId, inputToken, outputToken, amountIn, options, }) => {
67
- const market = await fetchMarket(chainId, [inputToken, outputToken]);
471
+ export const getExpectedOutput = async ({ chainId, inputToken, outputToken, amountIn, options, }) => {
472
+ const [roundingDownTakenBid, roundingUpTakenAsk] = [
473
+ options?.roundingDownTakenBid ? options.roundingDownTakenBid : false,
474
+ options?.roundingUpTakenAsk ? options.roundingUpTakenAsk : false,
475
+ ];
476
+ const publicClient = createPublicClient({
477
+ chain: CHAIN_MAP[chainId],
478
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
479
+ });
480
+ const market = await fetchMarket(publicClient, chainId, [inputToken, outputToken], !!(options && options.useSubgraph));
68
481
  const isBid = isAddressEqual(market.quote.address, inputToken);
69
- const rawLimitPrice = options && options.limitPrice
482
+ const { roundingDownTick, roundingUpTick } = options && options.limitPrice
70
483
  ? parsePrice(Number(options.limitPrice), market.quote.decimals, market.base.decimals)
71
484
  : isBid
72
- ? MAX_PRICE
73
- : 0n;
485
+ ? {
486
+ roundingDownTick: MAX_TICK,
487
+ roundingUpTick: MAX_TICK,
488
+ }
489
+ : {
490
+ roundingDownTick: MIN_TICK,
491
+ roundingUpTick: MIN_TICK,
492
+ };
74
493
  const inputCurrency = isBid ? market.quote : market.base;
75
- const { takenQuoteAmount, spendBaseAmount, bookId } = market.spend({
76
- spendBase: !isBid,
77
- limitPrice: rawLimitPrice,
494
+ const isTakingBidSide = !isBid;
495
+ const { takenQuoteAmount, spentBaseAmount, bookId, events } = market.spend({
496
+ spentBase: isTakingBidSide,
497
+ limitTick: isTakingBidSide
498
+ ? roundingDownTakenBid
499
+ ? roundingDownTick
500
+ : roundingUpTick
501
+ : roundingUpTakenAsk
502
+ ? roundingUpTick
503
+ : roundingDownTick,
78
504
  amountIn: parseUnits(amountIn, inputCurrency.decimals),
79
505
  });
80
506
  return {
81
507
  takenAmount: formatUnits(takenQuoteAmount, isBid ? market.base.decimals : market.quote.decimals),
82
- spendAmount: formatUnits(spendBaseAmount, isBid ? market.quote.decimals : market.base.decimals),
508
+ spentAmount: formatUnits(spentBaseAmount, isBid ? market.quote.decimals : market.base.decimals),
83
509
  bookId,
510
+ events: events.map(({ tick, takenQuoteAmount, spentBaseAmount }) => ({
511
+ price: formatPrice(toPrice(isBid ? invertTick(BigInt(tick)) : BigInt(tick)), market.quote.decimals, market.base.decimals),
512
+ takenAmount: formatUnits(takenQuoteAmount, isBid ? market.base.decimals : market.quote.decimals),
513
+ spentAmount: formatUnits(spentBaseAmount, isBid ? market.quote.decimals : market.base.decimals),
514
+ })),
84
515
  };
85
- });
516
+ };
86
517
  /**
87
518
  * Calculates the expected input for a given output amount, based on the provided market data.
88
519
  *
@@ -90,47 +521,68 @@ export const getExpectedOutput = decorator(async ({ chainId, inputToken, outputT
90
521
  * @param inputToken The address of the input token.
91
522
  * @param outputToken The address of the output token.
92
523
  * @param amountOut The amount of expected output amount. (ex 1.2 ETH -> 1.2)
93
- * @param options
524
+ * @param options {@link DefaultReadContractOptions} options.
94
525
  * @param options.limitPrice The maximum limit price to take.
95
- * @param options.rpcUrl The RPC URL of the blockchain.
96
- * @returns A Promise resolving to an object containing the taken amount, spend amount and result of the calculation.
526
+ * @param options.roundingDownTakenBid Whether to round down the taken bid.
527
+ * @param options.roundingUpTakenAsk Whether to round up the taken ask.
528
+ * @param options.useSubgraph Whether to use the subgraph to fetch the market data.
529
+ * @returns A Promise resolving to an object containing the taken amount, spent amount and result of the calculation.
97
530
  * @example
98
531
  * import { getExpectedInput } from '@clober/v2-sdk'
99
532
  *
100
- * const { takenAmount, spendAmount } = await getExpectedInput({
533
+ * const { takenAmount, spentAmount } = await getExpectedInput({
101
534
  * chainId: 421614,
102
535
  * inputToken: '0x00bfd44e79fb7f6dd5887a9426c8ef85a0cd23e0',
103
536
  * outputToken: '0x0000000000000000000000000000000000000000',
104
537
  * amountOut: '0.1', // take 0.1 ETH
105
538
  * })
106
539
  */
107
- export const getExpectedInput = decorator(async ({ chainId, inputToken, outputToken, amountOut, options, }) => {
108
- const market = await fetchMarket(chainId, [inputToken, outputToken]);
540
+ export const getExpectedInput = async ({ chainId, inputToken, outputToken, amountOut, options, }) => {
541
+ const [roundingDownTakenBid, roundingUpTakenAsk] = [
542
+ options?.roundingDownTakenBid ? options.roundingDownTakenBid : false,
543
+ options?.roundingUpTakenAsk ? options.roundingUpTakenAsk : false,
544
+ ];
545
+ const publicClient = createPublicClient({
546
+ chain: CHAIN_MAP[chainId],
547
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
548
+ });
549
+ const market = await fetchMarket(publicClient, chainId, [inputToken, outputToken], !!(options && options.useSubgraph));
109
550
  const isBid = isAddressEqual(market.quote.address, inputToken);
110
- const rawLimitPrice = options && options.limitPrice
551
+ const { roundingDownTick, roundingUpTick } = options && options.limitPrice
111
552
  ? parsePrice(Number(options.limitPrice), market.quote.decimals, market.base.decimals)
112
553
  : isBid
113
- ? MAX_PRICE
114
- : 0n;
554
+ ? { roundingDownTick: MAX_TICK, roundingUpTick: MAX_TICK }
555
+ : { roundingDownTick: MIN_TICK, roundingUpTick: MIN_TICK };
115
556
  const outputCurrency = isBid ? market.base : market.quote;
116
- const { takenQuoteAmount, spendBaseAmount, bookId } = market.take({
117
- takeQuote: !isBid,
118
- limitPrice: rawLimitPrice,
557
+ const isTakingBidSide = !isBid;
558
+ const { takenQuoteAmount, spentBaseAmount, bookId, events } = market.take({
559
+ takeQuote: isTakingBidSide,
560
+ limitTick: isTakingBidSide
561
+ ? roundingDownTakenBid
562
+ ? roundingDownTick
563
+ : roundingUpTick
564
+ : roundingUpTakenAsk
565
+ ? roundingUpTick
566
+ : roundingDownTick,
119
567
  amountOut: parseUnits(amountOut, outputCurrency.decimals),
120
568
  });
121
569
  return {
122
570
  takenAmount: formatUnits(takenQuoteAmount, isBid ? market.base.decimals : market.quote.decimals),
123
- spendAmount: formatUnits(spendBaseAmount, isBid ? market.quote.decimals : market.base.decimals),
571
+ spentAmount: formatUnits(spentBaseAmount, isBid ? market.quote.decimals : market.base.decimals),
124
572
  bookId,
573
+ events: events.map(({ tick, takenQuoteAmount, spentBaseAmount }) => ({
574
+ price: formatPrice(toPrice(isBid ? invertTick(BigInt(tick)) : BigInt(tick)), market.quote.decimals, market.base.decimals),
575
+ takenAmount: formatUnits(takenQuoteAmount, isBid ? market.base.decimals : market.quote.decimals),
576
+ spentAmount: formatUnits(spentBaseAmount, isBid ? market.quote.decimals : market.base.decimals),
577
+ })),
125
578
  };
126
- });
579
+ };
127
580
  /**
128
581
  * Retrieves the open order with the specified ID on the given chain.
129
582
  *
130
583
  * @param {CHAIN_IDS} chainId The chain ID.
131
584
  * @param {string} id The ID of the open order.
132
- * @param options
133
- * @param options.rpcUrl The RPC URL of the blockchain.
585
+ * @param options {@link DefaultReadContractOptions} options.
134
586
  * @returns {Promise<OpenOrder>} Promise resolving to the open order object, or undefined if not found.
135
587
  * @example
136
588
  * import { getOpenOrder } from '@clober/v2-sdk'
@@ -140,16 +592,19 @@ export const getExpectedInput = decorator(async ({ chainId, inputToken, outputTo
140
592
  * id: '46223845323662364279893361453861711542636620039907198451770258805035840307200'
141
593
  * })
142
594
  */
143
- export const getOpenOrder = decorator(async ({ chainId, id, }) => {
144
- return fetchOpenOrder(chainId, id);
145
- });
595
+ export const getOpenOrder = async ({ chainId, id, options, }) => {
596
+ const publicClient = createPublicClient({
597
+ chain: CHAIN_MAP[chainId],
598
+ transport: options?.rpcUrl ? http(options.rpcUrl) : http(),
599
+ });
600
+ return fetchOpenOrder(publicClient, chainId, id);
601
+ };
146
602
  /**
147
603
  * Retrieves open orders for the specified user on the given chain.
148
604
  *
149
605
  * @param {CHAIN_IDS} chainId The chain ID.
150
606
  * @param {`0x${string}`} userAddress The Ethereum address of the user.
151
- * @param options
152
- * @param options.rpcUrl The RPC URL of the blockchain.
607
+ * @param options {@link DefaultReadContractOptions} options.
153
608
  * @returns {Promise<OpenOrder[]>} Promise resolving to an array of open orders.
154
609
  * @example
155
610
  * import { getOpenOrders } from '@clober/v2-sdk'
@@ -159,9 +614,9 @@ export const getOpenOrder = decorator(async ({ chainId, id, }) => {
159
614
  * userAddress: '0x5F79EE8f8fA862E98201120d83c4eC39D9468D49'
160
615
  * })
161
616
  */
162
- export const getOpenOrders = decorator(async ({ chainId, userAddress, }) => {
163
- return fetchOpenOrders(chainId, userAddress);
164
- });
617
+ export const getOpenOrders = async ({ chainId, userAddress, }) => {
618
+ return fetchOpenOrdersByUserAddress(chainId, userAddress);
619
+ };
165
620
  /**
166
621
  * Retrieves the latest chart log for a specific market.
167
622
  *
@@ -179,9 +634,9 @@ export const getOpenOrders = decorator(async ({ chainId, userAddress, }) => {
179
634
  * base: '0x0000000000000000000000000000000000000000',
180
635
  * })
181
636
  */
182
- export const getLatestChartLog = decorator(async ({ chainId, quote, base, }) => {
637
+ export const getLatestChartLog = async ({ chainId, quote, base, }) => {
183
638
  return fetchLatestChartLog(chainId, `${base}/${quote}`);
184
- });
639
+ };
185
640
  /**
186
641
  * Retrieves chart logs for a specific market within a specified time interval.
187
642
  *
@@ -205,9 +660,9 @@ export const getLatestChartLog = decorator(async ({ chainId, quote, base, }) =>
205
660
  * to: 1713312000,
206
661
  * })
207
662
  */
208
- export const getChartLogs = decorator(async ({ chainId, quote, base, intervalType, from, to, }) => {
663
+ export const getChartLogs = async ({ chainId, quote, base, intervalType, from, to, }) => {
209
664
  return fetchChartLogs(chainId, `${base}/${quote}`, intervalType, from, to);
210
- });
665
+ };
211
666
  /**
212
667
  * Retrieves the quote token address for a given chain and a pair of tokens.
213
668
  *