@clober/v2-sdk 0.0.8 → 0.0.9-6.dev-2

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