tempo.ts 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/README.md +33 -2
  2. package/dist/chains.d.ts +509 -115
  3. package/dist/chains.d.ts.map +1 -1
  4. package/dist/chains.js +18 -9
  5. package/dist/chains.js.map +1 -1
  6. package/dist/ox/Order.d.ts +92 -0
  7. package/dist/ox/Order.d.ts.map +1 -0
  8. package/dist/ox/Order.js +88 -0
  9. package/dist/ox/Order.js.map +1 -0
  10. package/dist/ox/OrdersFilters.d.ts +72 -0
  11. package/dist/ox/OrdersFilters.d.ts.map +1 -0
  12. package/dist/ox/OrdersFilters.js +100 -0
  13. package/dist/ox/OrdersFilters.js.map +1 -0
  14. package/dist/ox/Pagination.d.ts +128 -0
  15. package/dist/ox/Pagination.d.ts.map +1 -0
  16. package/dist/ox/Pagination.js +78 -0
  17. package/dist/ox/Pagination.js.map +1 -0
  18. package/dist/ox/PoolId.d.ts +18 -0
  19. package/dist/ox/PoolId.d.ts.map +1 -0
  20. package/dist/ox/PoolId.js +13 -0
  21. package/dist/ox/PoolId.js.map +1 -0
  22. package/dist/ox/RpcSchema.d.ts +32 -0
  23. package/dist/ox/RpcSchema.d.ts.map +1 -0
  24. package/dist/ox/RpcSchema.js +2 -0
  25. package/dist/ox/RpcSchema.js.map +1 -0
  26. package/dist/ox/SignatureEnvelope.d.ts +1 -1
  27. package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
  28. package/dist/ox/SignatureEnvelope.js.map +1 -1
  29. package/dist/{viem → ox}/Tick.d.ts +4 -0
  30. package/dist/ox/Tick.d.ts.map +1 -0
  31. package/dist/ox/Tick.js.map +1 -0
  32. package/dist/ox/Transaction.d.ts.map +1 -1
  33. package/dist/ox/Transaction.js +2 -1
  34. package/dist/ox/Transaction.js.map +1 -1
  35. package/dist/ox/TransactionEnvelopeAA.d.ts +6 -6
  36. package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
  37. package/dist/ox/TransactionEnvelopeAA.js +4 -2
  38. package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
  39. package/dist/ox/TransactionRequest.d.ts +4 -0
  40. package/dist/ox/TransactionRequest.d.ts.map +1 -1
  41. package/dist/ox/TransactionRequest.js.map +1 -1
  42. package/dist/ox/index.d.ts +6 -0
  43. package/dist/ox/index.d.ts.map +1 -1
  44. package/dist/ox/index.js +6 -0
  45. package/dist/ox/index.js.map +1 -1
  46. package/dist/prool/Instance.d.ts.map +1 -1
  47. package/dist/prool/Instance.js +20 -4
  48. package/dist/prool/Instance.js.map +1 -1
  49. package/dist/viem/Abis.d.ts +1469 -1082
  50. package/dist/viem/Abis.d.ts.map +1 -1
  51. package/dist/viem/Abis.js +932 -671
  52. package/dist/viem/Abis.js.map +1 -1
  53. package/dist/viem/Account.d.ts +150 -0
  54. package/dist/viem/Account.d.ts.map +1 -0
  55. package/dist/viem/Account.js +221 -0
  56. package/dist/viem/Account.js.map +1 -0
  57. package/dist/viem/Actions/amm.d.ts +80 -118
  58. package/dist/viem/Actions/amm.d.ts.map +1 -1
  59. package/dist/viem/Actions/amm.js +47 -116
  60. package/dist/viem/Actions/amm.js.map +1 -1
  61. package/dist/viem/Actions/dex.d.ts +889 -633
  62. package/dist/viem/Actions/dex.d.ts.map +1 -1
  63. package/dist/viem/Actions/dex.js +99 -0
  64. package/dist/viem/Actions/dex.js.map +1 -1
  65. package/dist/viem/Actions/fee.d.ts +3 -17
  66. package/dist/viem/Actions/fee.d.ts.map +1 -1
  67. package/dist/viem/Actions/fee.js.map +1 -1
  68. package/dist/viem/Actions/index.d.ts +1 -0
  69. package/dist/viem/Actions/index.d.ts.map +1 -1
  70. package/dist/viem/Actions/index.js +1 -0
  71. package/dist/viem/Actions/index.js.map +1 -1
  72. package/dist/viem/Actions/reward.d.ts +3236 -0
  73. package/dist/viem/Actions/reward.d.ts.map +1 -0
  74. package/dist/viem/Actions/reward.js +725 -0
  75. package/dist/viem/Actions/reward.js.map +1 -0
  76. package/dist/viem/Actions/token.d.ts +4295 -2646
  77. package/dist/viem/Actions/token.d.ts.map +1 -1
  78. package/dist/viem/Actions/token.js +214 -335
  79. package/dist/viem/Actions/token.js.map +1 -1
  80. package/dist/viem/Addresses.d.ts +1 -2
  81. package/dist/viem/Addresses.d.ts.map +1 -1
  82. package/dist/viem/Addresses.js +1 -2
  83. package/dist/viem/Addresses.js.map +1 -1
  84. package/dist/viem/Chain.d.ts +38 -12
  85. package/dist/viem/Chain.d.ts.map +1 -1
  86. package/dist/viem/Chain.js +27 -18
  87. package/dist/viem/Chain.js.map +1 -1
  88. package/dist/viem/Decorator.d.ts +959 -405
  89. package/dist/viem/Decorator.d.ts.map +1 -1
  90. package/dist/viem/Decorator.js +13 -5
  91. package/dist/viem/Decorator.js.map +1 -1
  92. package/dist/viem/Formatters.d.ts +8 -1
  93. package/dist/viem/Formatters.d.ts.map +1 -1
  94. package/dist/viem/Formatters.js +17 -0
  95. package/dist/viem/Formatters.js.map +1 -1
  96. package/dist/viem/P256.d.ts +2 -0
  97. package/dist/viem/P256.d.ts.map +1 -0
  98. package/dist/viem/P256.js +2 -0
  99. package/dist/viem/P256.js.map +1 -0
  100. package/dist/viem/Secp256k1.d.ts +2 -0
  101. package/dist/viem/Secp256k1.d.ts.map +1 -0
  102. package/dist/viem/Secp256k1.js +2 -0
  103. package/dist/viem/Secp256k1.js.map +1 -0
  104. package/dist/viem/TokenIds.d.ts +1 -2
  105. package/dist/viem/TokenIds.d.ts.map +1 -1
  106. package/dist/viem/TokenIds.js +1 -2
  107. package/dist/viem/TokenIds.js.map +1 -1
  108. package/dist/viem/Transaction.d.ts +1 -1
  109. package/dist/viem/Transaction.d.ts.map +1 -1
  110. package/dist/viem/Transaction.js +46 -5
  111. package/dist/viem/Transaction.js.map +1 -1
  112. package/dist/viem/WebAuthnP256.d.ts +79 -0
  113. package/dist/viem/WebAuthnP256.d.ts.map +1 -0
  114. package/dist/viem/WebAuthnP256.js +95 -0
  115. package/dist/viem/WebAuthnP256.js.map +1 -0
  116. package/dist/viem/WebCryptoP256.d.ts +2 -0
  117. package/dist/viem/WebCryptoP256.d.ts.map +1 -0
  118. package/dist/viem/WebCryptoP256.js +2 -0
  119. package/dist/viem/WebCryptoP256.js.map +1 -0
  120. package/dist/viem/index.d.ts +6 -3
  121. package/dist/viem/index.d.ts.map +1 -1
  122. package/dist/viem/index.js +6 -3
  123. package/dist/viem/index.js.map +1 -1
  124. package/dist/viem/internal/account.d.ts +24 -0
  125. package/dist/viem/internal/account.d.ts.map +1 -0
  126. package/dist/viem/internal/account.js +68 -0
  127. package/dist/viem/internal/account.js.map +1 -0
  128. package/dist/viem/internal/types.d.ts +10 -0
  129. package/dist/viem/internal/types.d.ts.map +1 -1
  130. package/dist/wagmi/Actions/amm.d.ts +428 -0
  131. package/dist/wagmi/Actions/amm.d.ts.map +1 -0
  132. package/dist/wagmi/Actions/amm.js +472 -0
  133. package/dist/wagmi/Actions/amm.js.map +1 -0
  134. package/dist/wagmi/Actions/dex.d.ts +908 -0
  135. package/dist/wagmi/Actions/dex.d.ts.map +1 -0
  136. package/dist/wagmi/Actions/dex.js +1023 -0
  137. package/dist/wagmi/Actions/dex.js.map +1 -0
  138. package/dist/wagmi/Actions/fee.d.ts +111 -0
  139. package/dist/wagmi/Actions/fee.d.ts.map +1 -0
  140. package/dist/wagmi/Actions/fee.js +126 -0
  141. package/dist/wagmi/Actions/fee.js.map +1 -0
  142. package/dist/wagmi/Actions/index.d.ts +6 -0
  143. package/dist/wagmi/Actions/index.d.ts.map +1 -0
  144. package/dist/wagmi/Actions/index.js +6 -0
  145. package/dist/wagmi/Actions/index.js.map +1 -0
  146. package/dist/wagmi/Actions/reward.d.ts +348 -0
  147. package/dist/wagmi/Actions/reward.d.ts.map +1 -0
  148. package/dist/wagmi/Actions/reward.js +388 -0
  149. package/dist/wagmi/Actions/reward.js.map +1 -0
  150. package/dist/wagmi/Actions/token.d.ts +1546 -0
  151. package/dist/wagmi/Actions/token.d.ts.map +1 -0
  152. package/dist/wagmi/Actions/token.js +1712 -0
  153. package/dist/wagmi/Actions/token.js.map +1 -0
  154. package/dist/wagmi/Connector.d.ts +73 -0
  155. package/dist/wagmi/Connector.d.ts.map +1 -0
  156. package/dist/wagmi/Connector.js +249 -0
  157. package/dist/wagmi/Connector.js.map +1 -0
  158. package/dist/wagmi/Hooks/amm.d.ts +421 -0
  159. package/dist/wagmi/Hooks/amm.d.ts.map +1 -0
  160. package/dist/wagmi/Hooks/amm.js +504 -0
  161. package/dist/wagmi/Hooks/amm.js.map +1 -0
  162. package/dist/wagmi/Hooks/dex.d.ts +816 -0
  163. package/dist/wagmi/Hooks/dex.d.ts.map +1 -0
  164. package/dist/wagmi/Hooks/dex.js +973 -0
  165. package/dist/wagmi/Hooks/dex.js.map +1 -0
  166. package/dist/wagmi/Hooks/fee.d.ts +97 -0
  167. package/dist/wagmi/Hooks/fee.d.ts.map +1 -0
  168. package/dist/wagmi/Hooks/fee.js +109 -0
  169. package/dist/wagmi/Hooks/fee.js.map +1 -0
  170. package/dist/wagmi/Hooks/index.d.ts +6 -0
  171. package/dist/wagmi/Hooks/index.d.ts.map +1 -0
  172. package/dist/wagmi/Hooks/index.js +6 -0
  173. package/dist/wagmi/Hooks/index.js.map +1 -0
  174. package/dist/wagmi/Hooks/reward.d.ts +307 -0
  175. package/dist/wagmi/Hooks/reward.d.ts.map +1 -0
  176. package/dist/wagmi/Hooks/reward.js +349 -0
  177. package/dist/wagmi/Hooks/reward.js.map +1 -0
  178. package/dist/wagmi/Hooks/token.d.ts +1388 -0
  179. package/dist/wagmi/Hooks/token.d.ts.map +1 -0
  180. package/dist/wagmi/Hooks/token.js +1657 -0
  181. package/dist/wagmi/Hooks/token.js.map +1 -0
  182. package/dist/wagmi/index.d.ts +4 -0
  183. package/dist/wagmi/index.d.ts.map +1 -0
  184. package/dist/wagmi/index.js +4 -0
  185. package/dist/wagmi/index.js.map +1 -0
  186. package/package.json +54 -10
  187. package/src/chains.ts +19 -9
  188. package/src/ox/Order.test.ts +78 -0
  189. package/src/ox/Order.ts +125 -0
  190. package/src/ox/OrdersFilters.test.ts +182 -0
  191. package/src/ox/OrdersFilters.ts +125 -0
  192. package/src/ox/Pagination.test.ts +162 -0
  193. package/src/ox/Pagination.ts +164 -0
  194. package/src/ox/PoolId.test.ts +33 -0
  195. package/src/ox/PoolId.ts +27 -0
  196. package/src/ox/RpcSchema.ts +35 -0
  197. package/src/ox/SignatureEnvelope.ts +3 -1
  198. package/src/{viem → ox}/Tick.test.ts +1 -1
  199. package/src/{viem → ox}/Tick.ts +5 -0
  200. package/src/ox/Transaction.test.ts +1 -1
  201. package/src/ox/Transaction.ts +2 -1
  202. package/src/ox/TransactionEnvelopeAA.test.ts +239 -96
  203. package/src/ox/TransactionEnvelopeAA.ts +9 -7
  204. package/src/ox/TransactionRequest.ts +4 -0
  205. package/src/ox/index.ts +6 -0
  206. package/src/prool/Instance.ts +51 -37
  207. package/src/prool/internal/chain.json +104 -52
  208. package/src/tsconfig.json +9 -0
  209. package/src/viem/Abis.ts +972 -710
  210. package/src/viem/Account.ts +279 -0
  211. package/src/viem/Actions/__snapshots__/dex.test.ts.snap +850 -0
  212. package/src/viem/Actions/amm.test.ts +98 -169
  213. package/src/viem/Actions/amm.ts +68 -155
  214. package/src/viem/Actions/dex.test.ts +563 -484
  215. package/src/viem/Actions/dex.ts +173 -0
  216. package/src/viem/Actions/fee.test.ts +23 -34
  217. package/src/viem/Actions/fee.ts +7 -0
  218. package/src/viem/Actions/index.ts +1 -0
  219. package/src/viem/Actions/policy.test.ts +19 -33
  220. package/src/viem/Actions/reward.test.ts +457 -0
  221. package/src/viem/Actions/reward.ts +999 -0
  222. package/src/viem/Actions/token.test.ts +453 -287
  223. package/src/viem/Actions/token.ts +452 -540
  224. package/src/viem/Addresses.ts +1 -2
  225. package/src/viem/Chain.ts +70 -20
  226. package/src/viem/Decorator.test.ts +2 -1
  227. package/src/viem/Decorator.ts +996 -421
  228. package/src/viem/Formatters.ts +31 -5
  229. package/src/viem/P256.ts +1 -0
  230. package/src/viem/Secp256k1.ts +1 -0
  231. package/src/viem/TokenIds.ts +1 -2
  232. package/src/viem/Transaction.ts +53 -7
  233. package/src/viem/WebAuthnP256.ts +140 -0
  234. package/src/viem/WebCryptoP256.ts +1 -0
  235. package/src/viem/e2e.test.ts +1126 -297
  236. package/src/viem/index.ts +6 -3
  237. package/src/viem/internal/account.ts +107 -0
  238. package/src/viem/internal/types.ts +9 -0
  239. package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +310 -0
  240. package/src/wagmi/Actions/amm.test.ts +198 -0
  241. package/src/wagmi/Actions/amm.ts +691 -0
  242. package/src/wagmi/Actions/dex.test.ts +1507 -0
  243. package/src/wagmi/Actions/dex.ts +1640 -0
  244. package/src/wagmi/Actions/fee.test.ts +63 -0
  245. package/src/wagmi/Actions/fee.ts +208 -0
  246. package/src/wagmi/Actions/index.ts +5 -0
  247. package/src/wagmi/Actions/reward.test.ts +210 -0
  248. package/src/wagmi/Actions/reward.ts +632 -0
  249. package/src/wagmi/Actions/token.test.ts +1308 -0
  250. package/src/wagmi/Actions/token.ts +2613 -0
  251. package/src/wagmi/Connector.test.ts +53 -0
  252. package/src/wagmi/Connector.ts +367 -0
  253. package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +457 -0
  254. package/src/wagmi/Hooks/amm.test.ts +424 -0
  255. package/src/wagmi/Hooks/amm.ts +806 -0
  256. package/src/wagmi/Hooks/dex.test.ts +1017 -0
  257. package/src/wagmi/Hooks/dex.ts +1685 -0
  258. package/src/wagmi/Hooks/fee.test.ts +166 -0
  259. package/src/wagmi/Hooks/fee.ts +206 -0
  260. package/src/wagmi/Hooks/index.ts +5 -0
  261. package/src/wagmi/Hooks/reward.test.ts +219 -0
  262. package/src/wagmi/Hooks/reward.ts +672 -0
  263. package/src/wagmi/Hooks/token.test.ts +1670 -0
  264. package/src/wagmi/Hooks/token.ts +2906 -0
  265. package/src/wagmi/index.ts +3 -0
  266. package/src/wagmi/internal/types.ts +16 -0
  267. package/dist/viem/Client.d.ts +0 -27
  268. package/dist/viem/Client.d.ts.map +0 -1
  269. package/dist/viem/Client.js +0 -28
  270. package/dist/viem/Client.js.map +0 -1
  271. package/dist/viem/Tick.d.ts.map +0 -1
  272. package/dist/viem/Tick.js.map +0 -1
  273. package/src/viem/Client.bench-d.ts +0 -8
  274. package/src/viem/Client.test.ts +0 -178
  275. package/src/viem/Client.ts +0 -91
  276. /package/dist/{viem → ox}/Tick.js +0 -0
@@ -0,0 +1,125 @@
1
+ import type * as Address from 'ox/Address'
2
+ import * as Hex from 'ox/Hex'
3
+ import type * as Pagination from './Pagination.js'
4
+ import type * as Tick from './Tick.js'
5
+
6
+ /**
7
+ * Filter configuration for orders query.
8
+ */
9
+ export type OrdersFilters<bigintType = bigint> = {
10
+ /** Filter by specific base token. */
11
+ baseToken?: Address.Address | undefined
12
+ /** Filter by order side (true=buy, false=sell). */
13
+ isBid?: boolean | undefined
14
+ /** Filter flip orders. */
15
+ isFlip?: boolean | undefined
16
+ /** Filter by maker address. */
17
+ maker?: Address.Address | undefined
18
+ /** Filter by quote token. */
19
+ quoteToken?: Address.Address | undefined
20
+ /** Remaining amount in range. */
21
+ remaining?: Pagination.FilterRange<bigintType> | undefined
22
+ /** Tick in range (from -2000 to 2000). */
23
+ tick?: Pagination.FilterRange<Tick.Tick> | undefined
24
+ }
25
+
26
+ /**
27
+ * RPC-formatted orders filters.
28
+ */
29
+ export type Rpc = OrdersFilters<Hex.Hex>
30
+
31
+ /**
32
+ * Converts RPC-formatted orders filters to internal representation.
33
+ *
34
+ * @example
35
+ * ```ts twoslash
36
+ * import { OrdersRequest } from 'tempo.ts/ox'
37
+ *
38
+ * const filters = OrdersRequest.fromRpc({
39
+ * baseToken: '0x20c0000000000000000000000000000000000001',
40
+ * isBid: true,
41
+ * remaining: {
42
+ * min: '0x64',
43
+ * max: '0x3e8',
44
+ * },
45
+ * })
46
+ * // @log: { baseToken: '0x20c0...', isBid: true, remaining: { min: 100n, max: 1000n } }
47
+ * ```
48
+ *
49
+ * @param filters - RPC-formatted filters.
50
+ * @returns Internal filters representation.
51
+ */
52
+ export function fromRpc(filters: Rpc): OrdersFilters {
53
+ const result: OrdersFilters = {}
54
+
55
+ if (filters.baseToken !== undefined) result.baseToken = filters.baseToken
56
+ if (filters.isBid !== undefined) result.isBid = filters.isBid
57
+ if (filters.isFlip !== undefined) result.isFlip = filters.isFlip
58
+ if (filters.maker !== undefined) result.maker = filters.maker
59
+ if (filters.quoteToken !== undefined) result.quoteToken = filters.quoteToken
60
+
61
+ if (filters.remaining !== undefined) {
62
+ const remaining: Pagination.FilterRange<bigint> = {}
63
+ remaining.min =
64
+ typeof filters.remaining.min === 'string'
65
+ ? Hex.toBigInt(filters.remaining.min)
66
+ : null
67
+ remaining.max =
68
+ typeof filters.remaining.max === 'string'
69
+ ? Hex.toBigInt(filters.remaining.max)
70
+ : null
71
+ result.remaining = remaining
72
+ }
73
+
74
+ if (filters.tick !== undefined) result.tick = filters.tick
75
+
76
+ return result
77
+ }
78
+
79
+ /**
80
+ * Converts internal orders filters to RPC format.
81
+ *
82
+ * @example
83
+ * ```ts twoslash
84
+ * import { OrdersRequest } from 'tempo.ts/ox'
85
+ *
86
+ * const rpcFilters = OrdersRequest.toRpc({
87
+ * baseToken: '0x20c0000000000000000000000000000000000001',
88
+ * isBid: true,
89
+ * remaining: {
90
+ * min: 100n,
91
+ * max: 1000n,
92
+ * },
93
+ * })
94
+ * // @log: { baseToken: '0x20c0...', isBid: true, remaining: { min: '0x64', max: '0x3e8' } }
95
+ * ```
96
+ *
97
+ * @param filters - Internal filters representation.
98
+ * @returns RPC-formatted filters.
99
+ */
100
+ export function toRpc(filters: OrdersFilters): Rpc {
101
+ const result: Rpc = {}
102
+
103
+ if (filters.baseToken !== undefined) result.baseToken = filters.baseToken
104
+ if (filters.isBid !== undefined) result.isBid = filters.isBid
105
+ if (filters.isFlip !== undefined) result.isFlip = filters.isFlip
106
+ if (filters.maker !== undefined) result.maker = filters.maker
107
+ if (filters.quoteToken !== undefined) result.quoteToken = filters.quoteToken
108
+
109
+ if (filters.remaining !== undefined) {
110
+ const remaining: Pagination.FilterRange<Hex.Hex> = {}
111
+ remaining.min =
112
+ typeof filters.remaining.min === 'bigint'
113
+ ? Hex.fromNumber(filters.remaining.min)
114
+ : null
115
+ remaining.max =
116
+ typeof filters.remaining.max === 'bigint'
117
+ ? Hex.fromNumber(filters.remaining.max)
118
+ : null
119
+ result.remaining = remaining
120
+ }
121
+
122
+ if (filters.tick !== undefined) result.tick = filters.tick
123
+
124
+ return result
125
+ }
@@ -0,0 +1,162 @@
1
+ import { Order, OrdersFilters, Pagination } from 'tempo.ts/ox'
2
+ import { describe, expect, test } from 'vitest'
3
+
4
+ describe('toRpcParameters', () => {
5
+ test('default', () => {
6
+ const params = Pagination.toRpcParameters(
7
+ {
8
+ cursor: '0x123',
9
+ limit: 50,
10
+ sort: {
11
+ on: 'orderId',
12
+ order: 'asc',
13
+ },
14
+ filters: {
15
+ baseToken: '0x20c0000000000000000000000000000000000001',
16
+ remaining: {
17
+ max: 1000n,
18
+ },
19
+ },
20
+ },
21
+ {
22
+ toRpcFilters: OrdersFilters.toRpc,
23
+ },
24
+ )
25
+
26
+ expect(params).toMatchInlineSnapshot(`
27
+ {
28
+ "cursor": "0x123",
29
+ "filters": {
30
+ "baseToken": "0x20c0000000000000000000000000000000000001",
31
+ "remaining": {
32
+ "max": "0x3e8",
33
+ "min": null,
34
+ },
35
+ },
36
+ "limit": 50,
37
+ "sort": {
38
+ "on": "orderId",
39
+ "order": "asc",
40
+ },
41
+ }
42
+ `)
43
+ })
44
+ })
45
+
46
+ describe('fromRpcResponse', () => {
47
+ test('default', () => {
48
+ const response = Pagination.fromRpcResponse(
49
+ {
50
+ nextCursor: '0x123',
51
+ orders: [
52
+ {
53
+ amount: '0x64',
54
+ baseToken: '0x20c0000000000000000000000000000000000001',
55
+ flipTick: 0,
56
+ isBid: true,
57
+ isFlip: false,
58
+ maker: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
59
+ next: '0x0',
60
+ orderId: '0x1',
61
+ quoteToken: '0x20c0000000000000000000000000000000000002',
62
+ prev: '0x0',
63
+ remaining: '0x64',
64
+ tick: 100,
65
+ },
66
+ ],
67
+ },
68
+ {
69
+ key: 'orders',
70
+ fromRpc: Order.fromRpc,
71
+ },
72
+ )
73
+
74
+ expect(response).toMatchInlineSnapshot(`
75
+ {
76
+ "nextCursor": "0x123",
77
+ "orders": [
78
+ {
79
+ "amount": 100n,
80
+ "baseToken": "0x20c0000000000000000000000000000000000001",
81
+ "flipTick": 0,
82
+ "isBid": true,
83
+ "isFlip": false,
84
+ "maker": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
85
+ "next": 0n,
86
+ "orderId": 1n,
87
+ "prev": 0n,
88
+ "quoteToken": "0x20c0000000000000000000000000000000000002",
89
+ "remaining": 100n,
90
+ "tick": 100,
91
+ },
92
+ ],
93
+ }
94
+ `)
95
+ })
96
+
97
+ test('with multiple items', () => {
98
+ const response = Pagination.fromRpcResponse(
99
+ {
100
+ nextCursor: '0xabc',
101
+ orders: [
102
+ {
103
+ amount: '0x64',
104
+ baseToken: '0x20c0000000000000000000000000000000000001',
105
+ flipTick: 0,
106
+ isBid: true,
107
+ isFlip: false,
108
+ maker: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
109
+ next: '0x2',
110
+ orderId: '0x1',
111
+ quoteToken: '0x20c0000000000000000000000000000000000002',
112
+ prev: '0x0',
113
+ remaining: '0x64',
114
+ tick: 100,
115
+ },
116
+ {
117
+ amount: '0xc8',
118
+ baseToken: '0x20c0000000000000000000000000000000000001',
119
+ flipTick: 0,
120
+ isBid: false,
121
+ isFlip: false,
122
+ maker: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
123
+ next: '0x0',
124
+ orderId: '0x2',
125
+ quoteToken: '0x20c0000000000000000000000000000000000002',
126
+ prev: '0x1',
127
+ remaining: '0xc8',
128
+ tick: -100,
129
+ },
130
+ ],
131
+ },
132
+ {
133
+ key: 'orders',
134
+ fromRpc: Order.fromRpc,
135
+ },
136
+ )
137
+
138
+ expect(response.orders).toHaveLength(2)
139
+ expect(response.orders[0]?.orderId).toBe(1n)
140
+ expect(response.orders[1]?.orderId).toBe(2n)
141
+ })
142
+
143
+ test('with null nextCursor', () => {
144
+ const response = Pagination.fromRpcResponse(
145
+ {
146
+ nextCursor: null,
147
+ orders: [],
148
+ },
149
+ {
150
+ key: 'orders',
151
+ fromRpc: Order.fromRpc,
152
+ },
153
+ )
154
+
155
+ expect(response).toMatchInlineSnapshot(`
156
+ {
157
+ "nextCursor": null,
158
+ "orders": [],
159
+ }
160
+ `)
161
+ })
162
+ })
@@ -0,0 +1,164 @@
1
+ import type * as Hex from 'ox/Hex'
2
+
3
+ /**
4
+ * Filter range for numeric values.
5
+ */
6
+ export type FilterRange<type> = {
7
+ /** Maximum value (inclusive). */
8
+ max?: type | null | undefined
9
+ /** Minimum value (inclusive). */
10
+ min?: type | null | undefined
11
+ }
12
+
13
+ /**
14
+ * Sort order direction.
15
+ */
16
+ export type SortOrder = 'asc' | 'desc'
17
+
18
+ /**
19
+ * Sort configuration.
20
+ */
21
+ export type Sort<on extends string = string> = {
22
+ /** A field the items are compared with. */
23
+ on: on
24
+ /** An ordering direction. */
25
+ order: SortOrder
26
+ }
27
+
28
+ /**
29
+ * Pagination parameters.
30
+ */
31
+ export type Params<
32
+ filters extends Record<string, unknown> = Record<string, unknown>,
33
+ cursor = Hex.Hex,
34
+ sortOn extends string = string,
35
+ > = {
36
+ /**
37
+ * Cursor for pagination.
38
+ *
39
+ * Defaults to first entry based on the sort and filter configuration.
40
+ * Use the `nextCursor` in response to get the next set of results.
41
+ */
42
+ cursor?: cursor | undefined
43
+ /** Determines which items should be yielded in the response. */
44
+ filters?: filters | undefined
45
+ /**
46
+ * Maximum number of items to return.
47
+ *
48
+ * Defaults to 10.
49
+ * Maximum is 100.
50
+ */
51
+ limit?: number | undefined
52
+ /** Determines the order of the items yielded in the response. */
53
+ sort?: Sort<sortOn> | undefined
54
+ }
55
+
56
+ /**
57
+ * Pagination response.
58
+ */
59
+ export type Response<key extends string, type, cursor = Hex.Hex> = {
60
+ /** Cursor for next page, null if no more results. */
61
+ nextCursor: cursor | null
62
+ } & {
63
+ [K in key]: readonly type[]
64
+ }
65
+
66
+ /**
67
+ * Converts internal pagination parameters to RPC format.
68
+ *
69
+ * @example
70
+ * ```ts twoslash
71
+ * import { OrdersFilters, Pagination } from 'tempo.ts/ox'
72
+ *
73
+ * const rpcParameters = Pagination.toRpcParameters({
74
+ * cursor: '0x123',
75
+ * limit: 50,
76
+ * filters: {
77
+ * baseToken: '0x20c0000000000000000000000000000000000001',
78
+ * remaining: {
79
+ * min: 100n,
80
+ * max: 1000n,
81
+ * },
82
+ * },
83
+ * }, {
84
+ * toRpcFilters: OrdersFilters.toRpc,
85
+ * })
86
+ * // @log: { cursor: '0x123', limit: 50, filters: { baseToken: '0x20c0...', remaining: { min: '0x64', max: '0x3e8' } } }
87
+ * ```
88
+ *
89
+ * @param request - Internal request representation.
90
+ * @returns RPC-formatted request.
91
+ */
92
+ export function toRpcParameters<toRpcFilters extends (args: any) => any>(
93
+ request: Params<Parameters<toRpcFilters>[0]>,
94
+ options: toRpcParameters.Options<toRpcFilters>,
95
+ ): Params<ReturnType<toRpcFilters>> {
96
+ const result: Params<ReturnType<toRpcFilters>> = {}
97
+
98
+ if (request.cursor !== undefined) result.cursor = request.cursor
99
+ if (request.limit !== undefined) result.limit = request.limit
100
+ if (request.sort !== undefined) result.sort = request.sort
101
+ if (request.filters !== undefined)
102
+ result.filters = options.toRpcFilters(request.filters)
103
+
104
+ return result
105
+ }
106
+
107
+ export declare namespace toRpcParameters {
108
+ type Options<toRpcFilters extends (args: any) => any> = {
109
+ toRpcFilters: toRpcFilters
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Converts RPC-formatted pagination response to internal representation.
115
+ *
116
+ * @example
117
+ * ```ts twoslash
118
+ * import { Order, Pagination } from 'tempo.ts/ox'
119
+ *
120
+ * const response = Pagination.fromRpcResponse({
121
+ * nextCursor: '0x123',
122
+ * items: [{
123
+ * amount: '0x64',
124
+ * baseToken: '0x20c0000000000000000000000000000000000001',
125
+ * flipTick: 0,
126
+ * isBid: true,
127
+ * isFlip: false,
128
+ * maker: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
129
+ * next: '0x0',
130
+ * orderId: '0x1',
131
+ * quoteToken: '0x20c0000000000000000000000000000000000002',
132
+ * prev: '0x0',
133
+ * remaining: '0x64',
134
+ * tick: 100,
135
+ * }],
136
+ * }, {
137
+ * fromRpc: Order.fromRpc,
138
+ * })
139
+ * // @log: { nextCursor: '0x123', items: [{ amount: 100n, orderId: 1n, ... }] }
140
+ * ```
141
+ *
142
+ * @param response - RPC-formatted response.
143
+ * @param options - Conversion options.
144
+ * @returns Internal response representation.
145
+ */
146
+ export function fromRpcResponse<
147
+ key extends string,
148
+ fromRpc extends (args: any) => any,
149
+ >(
150
+ response: Response<key, Parameters<fromRpc>[0]>,
151
+ options: fromRpcResponse.Options<key, fromRpc>,
152
+ ): Response<key, ReturnType<fromRpc>> {
153
+ return {
154
+ nextCursor: response.nextCursor,
155
+ [options.key]: response[options.key].map(options.fromRpc),
156
+ } as never
157
+ }
158
+
159
+ export declare namespace fromRpcResponse {
160
+ type Options<key extends string, fromRpc extends (args: any) => any> = {
161
+ key: key
162
+ fromRpc: fromRpc
163
+ }
164
+ }
@@ -0,0 +1,33 @@
1
+ import { PoolId } from 'tempo.ts/ox'
2
+ import { expect, test } from 'vitest'
3
+
4
+ test('from', () => {
5
+ // Test with bigint token IDs
6
+ const poolId1 = PoolId.from({
7
+ userToken: 0n,
8
+ validatorToken: 1n,
9
+ })
10
+ expect(poolId1).toMatchInlineSnapshot(
11
+ `"0x24fc92718dfd933b7f831893444e0dc6072ce0fff68198eaf48e86cb1f2ee2dc"`,
12
+ )
13
+
14
+ // Test with address token IDs
15
+ const poolId2 = PoolId.from({
16
+ userToken: '0x20c0000000000000000000000000000000000000',
17
+ validatorToken: '0x20c0000000000000000000000000000000000001',
18
+ })
19
+ expect(poolId2).toBe(poolId1)
20
+
21
+ // Test with mixed types
22
+ const poolId3 = PoolId.from({
23
+ userToken: 0n,
24
+ validatorToken: '0x20c0000000000000000000000000000000000001',
25
+ })
26
+ expect(poolId3).toBe(poolId1)
27
+
28
+ const poolId4 = PoolId.from({
29
+ userToken: '0x20c0000000000000000000000000000000000000',
30
+ validatorToken: 1n,
31
+ })
32
+ expect(poolId4).toBe(poolId1)
33
+ })
@@ -0,0 +1,27 @@
1
+ import * as Hash from 'ox/Hash'
2
+ import * as Hex from 'ox/Hex'
3
+ import * as TokenId from './TokenId.js'
4
+
5
+ /**
6
+ * Converts a user token and validator token to a pool ID.
7
+ *
8
+ * @param value - User token and validator token.
9
+ * @returns The pool ID.
10
+ */
11
+ export function from(value: from.Value): Hex.Hex {
12
+ return Hash.keccak256(
13
+ Hex.concat(
14
+ Hex.padLeft(TokenId.toAddress(value.userToken), 32),
15
+ Hex.padLeft(TokenId.toAddress(value.validatorToken), 32),
16
+ ),
17
+ )
18
+ }
19
+
20
+ export declare namespace from {
21
+ export type Value = {
22
+ /** User token. */
23
+ userToken: TokenId.TokenIdOrAddress
24
+ /** Validator token. */
25
+ validatorToken: TokenId.TokenIdOrAddress
26
+ }
27
+ }
@@ -0,0 +1,35 @@
1
+ import type * as RpcSchema from 'ox/RpcSchema'
2
+ import type { UnionToTuple } from '../internal/types.js'
3
+ import type * as Order from './Order.js'
4
+ import type * as OrdersFilters from './OrdersFilters.js'
5
+ import type * as Pagination from './Pagination.js'
6
+
7
+ /**
8
+ * Union of all JSON-RPC Methods for the `dex_` namespace.
9
+ */
10
+ export type Dex = RpcSchema.From<{
11
+ Request: {
12
+ method: 'dex_getOrders'
13
+ params: Pagination.Params<OrdersFilters.Rpc>
14
+ }
15
+ ReturnType: Pagination.Response<'orders', Order.Rpc>
16
+ }>
17
+
18
+ /**
19
+ * Viem-compatible RPC schema for the `dex_` namespace.
20
+ */
21
+ export type DexViem = ToViem<Dex>
22
+
23
+ type ToViem<schema extends RpcSchema.Generic> = UnionToTuple<schema> extends [
24
+ infer head extends RpcSchema.Generic,
25
+ ...infer tail extends RpcSchema.Generic[],
26
+ ]
27
+ ? [
28
+ {
29
+ Method: head['Request']['method']
30
+ Parameters: head['Request']['params']
31
+ ReturnType: head['ReturnType']
32
+ },
33
+ ...ToViem<tail[number]>,
34
+ ]
35
+ : []
@@ -530,7 +530,9 @@ export function getType<
530
530
  * @returns The hex-encoded serialized signature.
531
531
  * @throws {CoercionError} If the envelope cannot be serialized.
532
532
  */
533
- export function serialize(envelope: SignatureEnvelope): Serialized {
533
+ export function serialize(
534
+ envelope: PartialBy<SignatureEnvelope, 'prehash'>,
535
+ ): Serialized {
534
536
  const type = getType(envelope)
535
537
 
536
538
  // Backward compatibility: no type identifier for secp256k1
@@ -1,5 +1,5 @@
1
+ import { Tick } from 'tempo.ts/ox'
1
2
  import { describe, expect, test } from 'vitest'
2
- import * as Tick from './Tick.js'
3
3
 
4
4
  describe('toPrice', () => {
5
5
  test('converts tick 0 to price 1', () => {
@@ -20,6 +20,11 @@ export const maxTick = 2000
20
20
  */
21
21
  export const priceScale = 100_000
22
22
 
23
+ /**
24
+ * Tick type.
25
+ */
26
+ export type Tick = number
27
+
23
28
  /**
24
29
  * Converts a tick to a price string.
25
30
  *
@@ -124,7 +124,7 @@ describe('fromRpc', () => {
124
124
  ],
125
125
  "chainId": 1,
126
126
  "data": undefined,
127
- "feePayer": "0xa5dd355188d0cd90324e13fc82ce7f3a2f3e44bc",
127
+ "feePayer": "0x697ac7512fe48fa16a7926f4647d9587f86997cd",
128
128
  "feePayerSignature": {
129
129
  "r": 8574245934337799659042750864278046211314109527666697413298781631396794530078n,
130
130
  "s": 22549658598721143185960614158212618570884225122794367192341714237232002247296n,
@@ -193,7 +193,8 @@ export function fromRpc<
193
193
  transaction_.calls = transaction.calls.map((call) => ({
194
194
  to: call.to,
195
195
  value: call.value ? BigInt(call.value) : undefined,
196
- data: call.input,
196
+ // @ts-expect-error
197
+ data: call.input || call.data || '0x',
197
198
  }))
198
199
  if (transaction.feeToken) transaction_.feeToken = transaction.feeToken
199
200
  if (transaction.nonceKey) transaction_.nonceKey = BigInt(transaction.nonceKey)