tempo.ts 0.10.4 → 0.11.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 (224) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +0 -41
  3. package/dist/viem/Account.d.ts +8 -3
  4. package/dist/viem/Account.d.ts.map +1 -1
  5. package/dist/viem/Account.js +9 -2
  6. package/dist/viem/Account.js.map +1 -1
  7. package/dist/viem/Actions/amm.d.ts +1 -1
  8. package/dist/viem/Actions/amm.d.ts.map +1 -1
  9. package/dist/viem/Actions/amm.js +1 -2
  10. package/dist/viem/Actions/amm.js.map +1 -1
  11. package/dist/viem/Actions/dex.d.ts +0 -35
  12. package/dist/viem/Actions/dex.d.ts.map +1 -1
  13. package/dist/viem/Actions/dex.js +0 -43
  14. package/dist/viem/Actions/dex.js.map +1 -1
  15. package/dist/viem/Actions/fee.d.ts +1 -1
  16. package/dist/viem/Actions/fee.d.ts.map +1 -1
  17. package/dist/viem/Actions/fee.js +1 -1
  18. package/dist/viem/Actions/fee.js.map +1 -1
  19. package/dist/viem/Actions/nonce.d.ts.map +1 -1
  20. package/dist/viem/Actions/nonce.js +6 -4
  21. package/dist/viem/Actions/nonce.js.map +1 -1
  22. package/dist/viem/Actions/token.d.ts +1 -2
  23. package/dist/viem/Actions/token.d.ts.map +1 -1
  24. package/dist/viem/Actions/token.js +1 -2
  25. package/dist/viem/Actions/token.js.map +1 -1
  26. package/dist/viem/Chain.d.ts +35 -35
  27. package/dist/viem/Chain.d.ts.map +1 -1
  28. package/dist/viem/Chain.js +2 -0
  29. package/dist/viem/Chain.js.map +1 -1
  30. package/dist/viem/Formatters.d.ts.map +1 -1
  31. package/dist/viem/Formatters.js +5 -3
  32. package/dist/viem/Formatters.js.map +1 -1
  33. package/dist/viem/Transaction.d.ts +8 -5
  34. package/dist/viem/Transaction.d.ts.map +1 -1
  35. package/dist/viem/Transaction.js +13 -3
  36. package/dist/viem/Transaction.js.map +1 -1
  37. package/dist/viem/internal/types.d.ts +1 -1
  38. package/dist/viem/internal/types.d.ts.map +1 -1
  39. package/dist/wagmi/Actions/dex.d.ts +1 -45
  40. package/dist/wagmi/Actions/dex.d.ts.map +1 -1
  41. package/dist/wagmi/Actions/dex.js +0 -55
  42. package/dist/wagmi/Actions/dex.js.map +1 -1
  43. package/dist/wagmi/Connector.d.ts +1 -1
  44. package/dist/wagmi/Connector.d.ts.map +1 -1
  45. package/dist/wagmi/Connector.js +1 -2
  46. package/dist/wagmi/Connector.js.map +1 -1
  47. package/dist/wagmi/Hooks/dex.d.ts +3 -46
  48. package/dist/wagmi/Hooks/dex.d.ts.map +1 -1
  49. package/dist/wagmi/Hooks/dex.js +2 -54
  50. package/dist/wagmi/Hooks/dex.js.map +1 -1
  51. package/dist/wagmi/index.d.ts +1 -1
  52. package/dist/wagmi/index.d.ts.map +1 -1
  53. package/dist/wagmi/index.js +1 -1
  54. package/dist/wagmi/index.js.map +1 -1
  55. package/package.json +5 -23
  56. package/src/viem/Account.test.ts +1 -1
  57. package/src/viem/Account.ts +11 -2
  58. package/src/viem/Actions/account.ts +1 -1
  59. package/src/viem/Actions/amm.ts +1 -2
  60. package/src/viem/Actions/dex.test.ts +1 -195
  61. package/src/viem/Actions/dex.ts +0 -53
  62. package/src/viem/Actions/fee.test.ts +2 -2
  63. package/src/viem/Actions/fee.ts +1 -1
  64. package/src/viem/Actions/nonce.test.ts +27 -14
  65. package/src/viem/Actions/nonce.ts +6 -4
  66. package/src/viem/Actions/token.test.ts +18 -52
  67. package/src/viem/Actions/token.ts +1 -2
  68. package/src/viem/Chain.ts +4 -2
  69. package/src/viem/Decorator.ts +0 -30
  70. package/src/viem/Formatters.ts +9 -3
  71. package/src/viem/Transaction.ts +23 -7
  72. package/src/viem/e2e.test.ts +19 -0
  73. package/src/viem/index.ts +12 -1
  74. package/src/viem/internal/types.ts +1 -1
  75. package/src/wagmi/Actions/dex.test.ts +0 -26
  76. package/src/wagmi/Actions/dex.ts +1 -111
  77. package/src/wagmi/Actions/nonce.test.ts +8 -4
  78. package/src/wagmi/Actions/token.test.ts +2 -2
  79. package/src/wagmi/Connector.ts +1 -2
  80. package/src/wagmi/Hooks/dex.test.ts +0 -26
  81. package/src/wagmi/Hooks/dex.ts +1 -88
  82. package/src/wagmi/Hooks/nonce.test.ts +3 -3
  83. package/src/wagmi/index.ts +4 -1
  84. package/dist/chains.d.ts +0 -73
  85. package/dist/chains.d.ts.map +0 -1
  86. package/dist/chains.js +0 -51
  87. package/dist/chains.js.map +0 -1
  88. package/dist/ox/AuthorizationTempo.d.ts +0 -450
  89. package/dist/ox/AuthorizationTempo.d.ts.map +0 -1
  90. package/dist/ox/AuthorizationTempo.js +0 -433
  91. package/dist/ox/AuthorizationTempo.js.map +0 -1
  92. package/dist/ox/KeyAuthorization.d.ts +0 -356
  93. package/dist/ox/KeyAuthorization.d.ts.map +0 -1
  94. package/dist/ox/KeyAuthorization.js +0 -359
  95. package/dist/ox/KeyAuthorization.js.map +0 -1
  96. package/dist/ox/Order.d.ts +0 -92
  97. package/dist/ox/Order.d.ts.map +0 -1
  98. package/dist/ox/Order.js +0 -88
  99. package/dist/ox/Order.js.map +0 -1
  100. package/dist/ox/OrdersFilters.d.ts +0 -72
  101. package/dist/ox/OrdersFilters.d.ts.map +0 -1
  102. package/dist/ox/OrdersFilters.js +0 -100
  103. package/dist/ox/OrdersFilters.js.map +0 -1
  104. package/dist/ox/Pagination.d.ts +0 -128
  105. package/dist/ox/Pagination.d.ts.map +0 -1
  106. package/dist/ox/Pagination.js +0 -78
  107. package/dist/ox/Pagination.js.map +0 -1
  108. package/dist/ox/PoolId.d.ts +0 -18
  109. package/dist/ox/PoolId.d.ts.map +0 -1
  110. package/dist/ox/PoolId.js +0 -13
  111. package/dist/ox/PoolId.js.map +0 -1
  112. package/dist/ox/RpcSchema.d.ts +0 -32
  113. package/dist/ox/RpcSchema.d.ts.map +0 -1
  114. package/dist/ox/RpcSchema.js +0 -2
  115. package/dist/ox/RpcSchema.js.map +0 -1
  116. package/dist/ox/SignatureEnvelope.d.ts +0 -260
  117. package/dist/ox/SignatureEnvelope.d.ts.map +0 -1
  118. package/dist/ox/SignatureEnvelope.js +0 -477
  119. package/dist/ox/SignatureEnvelope.js.map +0 -1
  120. package/dist/ox/Tick.d.ts +0 -115
  121. package/dist/ox/Tick.d.ts.map +0 -1
  122. package/dist/ox/Tick.js +0 -127
  123. package/dist/ox/Tick.js.map +0 -1
  124. package/dist/ox/TokenId.d.ts +0 -25
  125. package/dist/ox/TokenId.d.ts.map +0 -1
  126. package/dist/ox/TokenId.js +0 -41
  127. package/dist/ox/TokenId.js.map +0 -1
  128. package/dist/ox/TokenRole.d.ts +0 -11
  129. package/dist/ox/TokenRole.d.ts.map +0 -1
  130. package/dist/ox/TokenRole.js +0 -22
  131. package/dist/ox/TokenRole.js.map +0 -1
  132. package/dist/ox/Transaction.d.ts +0 -201
  133. package/dist/ox/Transaction.d.ts.map +0 -1
  134. package/dist/ox/Transaction.js +0 -167
  135. package/dist/ox/Transaction.js.map +0 -1
  136. package/dist/ox/TransactionEnvelopeTempo.d.ts +0 -470
  137. package/dist/ox/TransactionEnvelopeTempo.d.ts.map +0 -1
  138. package/dist/ox/TransactionEnvelopeTempo.js +0 -547
  139. package/dist/ox/TransactionEnvelopeTempo.js.map +0 -1
  140. package/dist/ox/TransactionReceipt.d.ts +0 -155
  141. package/dist/ox/TransactionReceipt.d.ts.map +0 -1
  142. package/dist/ox/TransactionReceipt.js +0 -136
  143. package/dist/ox/TransactionReceipt.js.map +0 -1
  144. package/dist/ox/TransactionRequest.d.ts +0 -76
  145. package/dist/ox/TransactionRequest.d.ts.map +0 -1
  146. package/dist/ox/TransactionRequest.js +0 -93
  147. package/dist/ox/TransactionRequest.js.map +0 -1
  148. package/dist/ox/index.d.ts +0 -14
  149. package/dist/ox/index.d.ts.map +0 -1
  150. package/dist/ox/index.js +0 -14
  151. package/dist/ox/index.js.map +0 -1
  152. package/dist/prool/Instance.d.ts +0 -101
  153. package/dist/prool/Instance.d.ts.map +0 -1
  154. package/dist/prool/Instance.js +0 -136
  155. package/dist/prool/Instance.js.map +0 -1
  156. package/dist/prool/chain.json +0 -238
  157. package/dist/prool/index.d.ts +0 -2
  158. package/dist/prool/index.d.ts.map +0 -1
  159. package/dist/prool/index.js +0 -2
  160. package/dist/prool/index.js.map +0 -1
  161. package/dist/viem/Actions/account.d.ts +0 -40
  162. package/dist/viem/Actions/account.d.ts.map +0 -1
  163. package/dist/viem/Actions/account.js +0 -86
  164. package/dist/viem/Actions/account.js.map +0 -1
  165. package/dist/viem/Actions/index.d.ts +0 -10
  166. package/dist/viem/Actions/index.d.ts.map +0 -1
  167. package/dist/viem/Actions/index.js +0 -10
  168. package/dist/viem/Actions/index.js.map +0 -1
  169. package/dist/viem/Decorator.d.ts +0 -2810
  170. package/dist/viem/Decorator.d.ts.map +0 -1
  171. package/dist/viem/Decorator.js +0 -138
  172. package/dist/viem/Decorator.js.map +0 -1
  173. package/dist/viem/P256.d.ts +0 -2
  174. package/dist/viem/P256.d.ts.map +0 -1
  175. package/dist/viem/P256.js +0 -2
  176. package/dist/viem/P256.js.map +0 -1
  177. package/dist/viem/Secp256k1.d.ts +0 -2
  178. package/dist/viem/Secp256k1.d.ts.map +0 -1
  179. package/dist/viem/Secp256k1.js +0 -2
  180. package/dist/viem/Secp256k1.js.map +0 -1
  181. package/dist/viem/TokenIds.d.ts +0 -2
  182. package/dist/viem/TokenIds.d.ts.map +0 -1
  183. package/dist/viem/TokenIds.js +0 -2
  184. package/dist/viem/TokenIds.js.map +0 -1
  185. package/dist/viem/index.d.ts +0 -17
  186. package/dist/viem/index.d.ts.map +0 -1
  187. package/dist/viem/index.js +0 -17
  188. package/dist/viem/index.js.map +0 -1
  189. package/src/ox/AuthorizationTempo.test.ts +0 -1256
  190. package/src/ox/AuthorizationTempo.ts +0 -648
  191. package/src/ox/KeyAuthorization.test.ts +0 -1332
  192. package/src/ox/KeyAuthorization.ts +0 -540
  193. package/src/ox/Order.test.ts +0 -78
  194. package/src/ox/Order.ts +0 -125
  195. package/src/ox/OrdersFilters.test.ts +0 -182
  196. package/src/ox/OrdersFilters.ts +0 -125
  197. package/src/ox/Pagination.test.ts +0 -162
  198. package/src/ox/Pagination.ts +0 -164
  199. package/src/ox/PoolId.test.ts +0 -33
  200. package/src/ox/PoolId.ts +0 -27
  201. package/src/ox/RpcSchema.ts +0 -35
  202. package/src/ox/SignatureEnvelope.test.ts +0 -1876
  203. package/src/ox/SignatureEnvelope.ts +0 -791
  204. package/src/ox/Tick.test.ts +0 -281
  205. package/src/ox/Tick.ts +0 -181
  206. package/src/ox/TokenId.test.ts +0 -40
  207. package/src/ox/TokenId.ts +0 -50
  208. package/src/ox/TokenRole.test.ts +0 -16
  209. package/src/ox/TokenRole.ts +0 -27
  210. package/src/ox/Transaction.test.ts +0 -523
  211. package/src/ox/Transaction.ts +0 -332
  212. package/src/ox/TransactionEnvelopeTempo.test.ts +0 -1352
  213. package/src/ox/TransactionEnvelopeTempo.ts +0 -905
  214. package/src/ox/TransactionReceipt.ts +0 -190
  215. package/src/ox/TransactionRequest.ts +0 -147
  216. package/src/ox/e2e.test.ts +0 -1393
  217. package/src/ox/index.ts +0 -13
  218. package/src/prool/Instance.test.ts +0 -43
  219. package/src/prool/Instance.ts +0 -247
  220. package/src/prool/chain.json +0 -238
  221. package/src/prool/index.ts +0 -1
  222. package/src/viem/Actions/__snapshots__/dex.test.ts.snap +0 -850
  223. package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +0 -310
  224. package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +0 -457
package/src/ox/Order.ts DELETED
@@ -1,125 +0,0 @@
1
- import type * as Address from 'ox/Address'
2
- import * as Hex from 'ox/Hex'
3
-
4
- /**
5
- * Represents an order from the DEX orderbook.
6
- */
7
- export type Order<bigintType = bigint> = {
8
- /** Original order amount. */
9
- amount: bigintType
10
- /** Address of the base token. */
11
- baseToken: Address.Address
12
- /** Target tick to flip to when order is filled. */
13
- flipTick: number
14
- /** Order side: true for buy (bid), false for sell (ask). */
15
- isBid: boolean
16
- /** Whether this is a flip order that auto-flips when filled. */
17
- isFlip: boolean
18
- /** Address of order maker. */
19
- maker: Address.Address
20
- /** Next order ID in FIFO queue. */
21
- next: bigintType
22
- /** Unique order ID. */
23
- orderId: bigintType
24
- /** Address of the quote token. */
25
- quoteToken: Address.Address
26
- /** Previous order ID in FIFO queue. */
27
- prev: bigintType
28
- /** Remaining amount to fill. */
29
- remaining: bigintType
30
- /** Price tick. */
31
- tick: number
32
- }
33
-
34
- /**
35
- * RPC-formatted order from the DEX orderbook.
36
- */
37
- export type Rpc = Order<Hex.Hex>
38
-
39
- /**
40
- * Converts an RPC-formatted order to an internal order representation.
41
- *
42
- * @example
43
- * ```ts twoslash
44
- * import { Order } from 'tempo.ts/ox'
45
- *
46
- * const order = Order.fromRpc({
47
- * amount: '0x64',
48
- * baseToken: '0x20c0000000000000000000000000000000000001',
49
- * flipTick: 0,
50
- * isBid: true,
51
- * isFlip: false,
52
- * maker: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
53
- * next: '0x0',
54
- * orderId: '0x1',
55
- * quoteToken: '0x20c0000000000000000000000000000000000002',
56
- * prev: '0x0',
57
- * remaining: '0x64',
58
- * tick: 100,
59
- * })
60
- * // @log: { amount: 100n, orderId: 1n, ... }
61
- * ```
62
- *
63
- * @param order - RPC-formatted order.
64
- * @returns Internal order representation.
65
- */
66
- export function fromRpc(order: Rpc): Order {
67
- return {
68
- amount: Hex.toBigInt(order.amount),
69
- baseToken: order.baseToken,
70
- flipTick: order.flipTick,
71
- isBid: order.isBid,
72
- isFlip: order.isFlip,
73
- maker: order.maker,
74
- next: Hex.toBigInt(order.next),
75
- orderId: Hex.toBigInt(order.orderId),
76
- quoteToken: order.quoteToken,
77
- prev: Hex.toBigInt(order.prev),
78
- remaining: Hex.toBigInt(order.remaining),
79
- tick: order.tick,
80
- }
81
- }
82
-
83
- /**
84
- * Converts an internal order representation to RPC format.
85
- *
86
- * @example
87
- * ```ts twoslash
88
- * import { Order } from 'tempo.ts/ox'
89
- *
90
- * const rpcOrder = Order.toRpc({
91
- * amount: 100n,
92
- * baseToken: '0x20c0000000000000000000000000000000000001',
93
- * flipTick: 0,
94
- * isBid: true,
95
- * isFlip: false,
96
- * maker: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
97
- * next: 0n,
98
- * orderId: 1n,
99
- * quoteToken: '0x20c0000000000000000000000000000000000002',
100
- * prev: 0n,
101
- * remaining: 100n,
102
- * tick: 100,
103
- * })
104
- * // @log: { amount: '0x64', orderId: '0x1', ... }
105
- * ```
106
- *
107
- * @param order - Internal order representation.
108
- * @returns RPC-formatted order.
109
- */
110
- export function toRpc(order: Order): Rpc {
111
- return {
112
- amount: Hex.fromNumber(order.amount),
113
- baseToken: order.baseToken,
114
- flipTick: order.flipTick,
115
- isBid: order.isBid,
116
- isFlip: order.isFlip,
117
- maker: order.maker,
118
- next: Hex.fromNumber(order.next),
119
- orderId: Hex.fromNumber(order.orderId),
120
- quoteToken: order.quoteToken,
121
- prev: Hex.fromNumber(order.prev),
122
- remaining: Hex.fromNumber(order.remaining),
123
- tick: order.tick,
124
- }
125
- }
@@ -1,182 +0,0 @@
1
- import { OrdersFilters } from 'tempo.ts/ox'
2
- import { describe, expect, test } from 'vitest'
3
-
4
- describe('fromRpc', () => {
5
- test('default', () => {
6
- const rpcFilters: OrdersFilters.Rpc = {
7
- baseToken: '0x20c0000000000000000000000000000000000001',
8
- isBid: true,
9
- remaining: {
10
- min: '0x64',
11
- max: '0x3e8',
12
- },
13
- }
14
-
15
- const filters = OrdersFilters.fromRpc(rpcFilters)
16
-
17
- expect(filters).toMatchInlineSnapshot(`
18
- {
19
- "baseToken": "0x20c0000000000000000000000000000000000001",
20
- "isBid": true,
21
- "remaining": {
22
- "max": 1000n,
23
- "min": 100n,
24
- },
25
- }
26
- `)
27
- })
28
-
29
- test('with all fields', () => {
30
- const rpcFilters: OrdersFilters.Rpc = {
31
- baseToken: '0x20c0000000000000000000000000000000000001',
32
- quoteToken: '0x20c0000000000000000000000000000000000002',
33
- maker: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
34
- isBid: true,
35
- isFlip: false,
36
- remaining: {
37
- min: '0x64',
38
- max: '0x3e8',
39
- },
40
- tick: {
41
- min: -100,
42
- max: 100,
43
- },
44
- }
45
-
46
- const filters = OrdersFilters.fromRpc(rpcFilters)
47
-
48
- expect(filters).toMatchInlineSnapshot(`
49
- {
50
- "baseToken": "0x20c0000000000000000000000000000000000001",
51
- "isBid": true,
52
- "isFlip": false,
53
- "maker": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
54
- "quoteToken": "0x20c0000000000000000000000000000000000002",
55
- "remaining": {
56
- "max": 1000n,
57
- "min": 100n,
58
- },
59
- "tick": {
60
- "max": 100,
61
- "min": -100,
62
- },
63
- }
64
- `)
65
- })
66
-
67
- test('with partial remaining range', () => {
68
- const rpcFilters: OrdersFilters.Rpc = {
69
- baseToken: '0x20c0000000000000000000000000000000000001',
70
- remaining: {
71
- min: '0x64',
72
- },
73
- }
74
-
75
- const filters = OrdersFilters.fromRpc(rpcFilters)
76
-
77
- expect(filters.remaining).toMatchInlineSnapshot(`
78
- {
79
- "max": null,
80
- "min": 100n,
81
- }
82
- `)
83
- })
84
-
85
- test('with empty filters', () => {
86
- const rpcFilters: OrdersFilters.Rpc = {}
87
-
88
- const filters = OrdersFilters.fromRpc(rpcFilters)
89
-
90
- expect(filters).toMatchInlineSnapshot(`{}`)
91
- })
92
- })
93
-
94
- describe('toRpc', () => {
95
- test('default', () => {
96
- const filters: OrdersFilters.OrdersFilters = {
97
- baseToken: '0x20c0000000000000000000000000000000000001',
98
- isBid: true,
99
- remaining: {
100
- min: 100n,
101
- max: 1000n,
102
- },
103
- }
104
-
105
- const rpcFilters = OrdersFilters.toRpc(filters)
106
-
107
- expect(rpcFilters).toMatchInlineSnapshot(`
108
- {
109
- "baseToken": "0x20c0000000000000000000000000000000000001",
110
- "isBid": true,
111
- "remaining": {
112
- "max": "0x3e8",
113
- "min": "0x64",
114
- },
115
- }
116
- `)
117
- })
118
-
119
- test('with all fields', () => {
120
- const filters: OrdersFilters.OrdersFilters = {
121
- baseToken: '0x20c0000000000000000000000000000000000001',
122
- quoteToken: '0x20c0000000000000000000000000000000000002',
123
- maker: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
124
- isBid: false,
125
- isFlip: true,
126
- remaining: {
127
- min: 100n,
128
- max: 1000n,
129
- },
130
- tick: {
131
- min: -100,
132
- max: 100,
133
- },
134
- }
135
-
136
- const rpcFilters = OrdersFilters.toRpc(filters)
137
-
138
- expect(rpcFilters).toMatchInlineSnapshot(`
139
- {
140
- "baseToken": "0x20c0000000000000000000000000000000000001",
141
- "isBid": false,
142
- "isFlip": true,
143
- "maker": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
144
- "quoteToken": "0x20c0000000000000000000000000000000000002",
145
- "remaining": {
146
- "max": "0x3e8",
147
- "min": "0x64",
148
- },
149
- "tick": {
150
- "max": 100,
151
- "min": -100,
152
- },
153
- }
154
- `)
155
- })
156
-
157
- test('with partial remaining range', () => {
158
- const filters: OrdersFilters.OrdersFilters = {
159
- baseToken: '0x20c0000000000000000000000000000000000001',
160
- remaining: {
161
- max: 1000n,
162
- },
163
- }
164
-
165
- const rpcFilters = OrdersFilters.toRpc(filters)
166
-
167
- expect(rpcFilters.remaining).toMatchInlineSnapshot(`
168
- {
169
- "max": "0x3e8",
170
- "min": null,
171
- }
172
- `)
173
- })
174
-
175
- test('with empty filters', () => {
176
- const filters: OrdersFilters.OrdersFilters = {}
177
-
178
- const rpcFilters = OrdersFilters.toRpc(filters)
179
-
180
- expect(rpcFilters).toMatchInlineSnapshot(`{}`)
181
- })
182
- })
@@ -1,125 +0,0 @@
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
- }
@@ -1,162 +0,0 @@
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
- })