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