tempo.ts 0.10.5 → 0.11.1

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 (203) 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/account.d.ts.map +1 -1
  8. package/dist/viem/Actions/account.js +1 -1
  9. package/dist/viem/Actions/account.js.map +1 -1
  10. package/dist/viem/Actions/amm.d.ts +1 -1
  11. package/dist/viem/Actions/amm.d.ts.map +1 -1
  12. package/dist/viem/Actions/amm.js +1 -2
  13. package/dist/viem/Actions/amm.js.map +1 -1
  14. package/dist/viem/Actions/dex.d.ts +0 -35
  15. package/dist/viem/Actions/dex.d.ts.map +1 -1
  16. package/dist/viem/Actions/dex.js +0 -43
  17. package/dist/viem/Actions/dex.js.map +1 -1
  18. package/dist/viem/Actions/fee.d.ts +1 -1
  19. package/dist/viem/Actions/fee.d.ts.map +1 -1
  20. package/dist/viem/Actions/fee.js +1 -1
  21. package/dist/viem/Actions/fee.js.map +1 -1
  22. package/dist/viem/Actions/nonce.d.ts.map +1 -1
  23. package/dist/viem/Actions/nonce.js +6 -4
  24. package/dist/viem/Actions/nonce.js.map +1 -1
  25. package/dist/viem/Actions/token.d.ts +1 -2
  26. package/dist/viem/Actions/token.d.ts.map +1 -1
  27. package/dist/viem/Actions/token.js +1 -2
  28. package/dist/viem/Actions/token.js.map +1 -1
  29. package/dist/viem/Chain.d.ts +34 -34
  30. package/dist/viem/Chain.d.ts.map +1 -1
  31. package/dist/viem/Chain.js +2 -0
  32. package/dist/viem/Chain.js.map +1 -1
  33. package/dist/viem/Decorator.d.ts +0 -27
  34. package/dist/viem/Decorator.d.ts.map +1 -1
  35. package/dist/viem/Decorator.js +0 -1
  36. package/dist/viem/Decorator.js.map +1 -1
  37. package/dist/viem/Formatters.d.ts.map +1 -1
  38. package/dist/viem/Formatters.js +5 -3
  39. package/dist/viem/Formatters.js.map +1 -1
  40. package/dist/viem/Transaction.d.ts +8 -5
  41. package/dist/viem/Transaction.d.ts.map +1 -1
  42. package/dist/viem/Transaction.js +13 -3
  43. package/dist/viem/Transaction.js.map +1 -1
  44. package/dist/viem/index.d.ts +10 -1
  45. package/dist/viem/index.d.ts.map +1 -1
  46. package/dist/viem/index.js +1 -1
  47. package/dist/viem/index.js.map +1 -1
  48. package/dist/viem/internal/types.d.ts +1 -1
  49. package/dist/viem/internal/types.d.ts.map +1 -1
  50. package/dist/wagmi/Actions/dex.d.ts +1 -45
  51. package/dist/wagmi/Actions/dex.d.ts.map +1 -1
  52. package/dist/wagmi/Actions/dex.js +0 -55
  53. package/dist/wagmi/Actions/dex.js.map +1 -1
  54. package/dist/wagmi/Connector.d.ts +1 -1
  55. package/dist/wagmi/Connector.d.ts.map +1 -1
  56. package/dist/wagmi/Connector.js +1 -2
  57. package/dist/wagmi/Connector.js.map +1 -1
  58. package/dist/wagmi/Hooks/dex.d.ts +3 -46
  59. package/dist/wagmi/Hooks/dex.d.ts.map +1 -1
  60. package/dist/wagmi/Hooks/dex.js +2 -54
  61. package/dist/wagmi/Hooks/dex.js.map +1 -1
  62. package/dist/wagmi/index.d.ts +1 -1
  63. package/dist/wagmi/index.d.ts.map +1 -1
  64. package/dist/wagmi/index.js +1 -1
  65. package/dist/wagmi/index.js.map +1 -1
  66. package/package.json +5 -13
  67. package/src/viem/Account.test.ts +1 -1
  68. package/src/viem/Account.ts +11 -2
  69. package/src/viem/Actions/account.ts +1 -1
  70. package/src/viem/Actions/amm.ts +1 -2
  71. package/src/viem/Actions/dex.test.ts +1 -195
  72. package/src/viem/Actions/dex.ts +0 -53
  73. package/src/viem/Actions/fee.test.ts +2 -2
  74. package/src/viem/Actions/fee.ts +1 -1
  75. package/src/viem/Actions/nonce.test.ts +27 -14
  76. package/src/viem/Actions/nonce.ts +6 -4
  77. package/src/viem/Actions/token.test.ts +18 -52
  78. package/src/viem/Actions/token.ts +1 -2
  79. package/src/viem/Chain.ts +3 -1
  80. package/src/viem/Decorator.ts +0 -30
  81. package/src/viem/Formatters.ts +9 -3
  82. package/src/viem/Transaction.ts +23 -7
  83. package/src/viem/e2e.test.ts +19 -0
  84. package/src/viem/index.ts +12 -1
  85. package/src/viem/internal/types.ts +1 -1
  86. package/src/wagmi/Actions/dex.test.ts +0 -26
  87. package/src/wagmi/Actions/dex.ts +1 -111
  88. package/src/wagmi/Actions/nonce.test.ts +8 -4
  89. package/src/wagmi/Actions/token.test.ts +2 -2
  90. package/src/wagmi/Connector.ts +1 -2
  91. package/src/wagmi/Hooks/dex.test.ts +0 -26
  92. package/src/wagmi/Hooks/dex.ts +1 -88
  93. package/src/wagmi/Hooks/nonce.test.ts +3 -3
  94. package/src/wagmi/index.ts +4 -1
  95. package/dist/ox/AuthorizationTempo.d.ts +0 -450
  96. package/dist/ox/AuthorizationTempo.d.ts.map +0 -1
  97. package/dist/ox/AuthorizationTempo.js +0 -433
  98. package/dist/ox/AuthorizationTempo.js.map +0 -1
  99. package/dist/ox/KeyAuthorization.d.ts +0 -356
  100. package/dist/ox/KeyAuthorization.d.ts.map +0 -1
  101. package/dist/ox/KeyAuthorization.js +0 -359
  102. package/dist/ox/KeyAuthorization.js.map +0 -1
  103. package/dist/ox/Order.d.ts +0 -92
  104. package/dist/ox/Order.d.ts.map +0 -1
  105. package/dist/ox/Order.js +0 -88
  106. package/dist/ox/Order.js.map +0 -1
  107. package/dist/ox/OrdersFilters.d.ts +0 -72
  108. package/dist/ox/OrdersFilters.d.ts.map +0 -1
  109. package/dist/ox/OrdersFilters.js +0 -100
  110. package/dist/ox/OrdersFilters.js.map +0 -1
  111. package/dist/ox/Pagination.d.ts +0 -128
  112. package/dist/ox/Pagination.d.ts.map +0 -1
  113. package/dist/ox/Pagination.js +0 -78
  114. package/dist/ox/Pagination.js.map +0 -1
  115. package/dist/ox/PoolId.d.ts +0 -18
  116. package/dist/ox/PoolId.d.ts.map +0 -1
  117. package/dist/ox/PoolId.js +0 -13
  118. package/dist/ox/PoolId.js.map +0 -1
  119. package/dist/ox/RpcSchema.d.ts +0 -32
  120. package/dist/ox/RpcSchema.d.ts.map +0 -1
  121. package/dist/ox/RpcSchema.js +0 -2
  122. package/dist/ox/RpcSchema.js.map +0 -1
  123. package/dist/ox/SignatureEnvelope.d.ts +0 -260
  124. package/dist/ox/SignatureEnvelope.d.ts.map +0 -1
  125. package/dist/ox/SignatureEnvelope.js +0 -477
  126. package/dist/ox/SignatureEnvelope.js.map +0 -1
  127. package/dist/ox/Tick.d.ts +0 -115
  128. package/dist/ox/Tick.d.ts.map +0 -1
  129. package/dist/ox/Tick.js +0 -127
  130. package/dist/ox/Tick.js.map +0 -1
  131. package/dist/ox/TokenId.d.ts +0 -25
  132. package/dist/ox/TokenId.d.ts.map +0 -1
  133. package/dist/ox/TokenId.js +0 -41
  134. package/dist/ox/TokenId.js.map +0 -1
  135. package/dist/ox/TokenRole.d.ts +0 -11
  136. package/dist/ox/TokenRole.d.ts.map +0 -1
  137. package/dist/ox/TokenRole.js +0 -22
  138. package/dist/ox/TokenRole.js.map +0 -1
  139. package/dist/ox/Transaction.d.ts +0 -201
  140. package/dist/ox/Transaction.d.ts.map +0 -1
  141. package/dist/ox/Transaction.js +0 -167
  142. package/dist/ox/Transaction.js.map +0 -1
  143. package/dist/ox/TransactionEnvelopeTempo.d.ts +0 -470
  144. package/dist/ox/TransactionEnvelopeTempo.d.ts.map +0 -1
  145. package/dist/ox/TransactionEnvelopeTempo.js +0 -547
  146. package/dist/ox/TransactionEnvelopeTempo.js.map +0 -1
  147. package/dist/ox/TransactionReceipt.d.ts +0 -155
  148. package/dist/ox/TransactionReceipt.d.ts.map +0 -1
  149. package/dist/ox/TransactionReceipt.js +0 -136
  150. package/dist/ox/TransactionReceipt.js.map +0 -1
  151. package/dist/ox/TransactionRequest.d.ts +0 -76
  152. package/dist/ox/TransactionRequest.d.ts.map +0 -1
  153. package/dist/ox/TransactionRequest.js +0 -93
  154. package/dist/ox/TransactionRequest.js.map +0 -1
  155. package/dist/ox/index.d.ts +0 -14
  156. package/dist/ox/index.d.ts.map +0 -1
  157. package/dist/ox/index.js +0 -14
  158. package/dist/ox/index.js.map +0 -1
  159. package/dist/prool/Instance.d.ts +0 -101
  160. package/dist/prool/Instance.d.ts.map +0 -1
  161. package/dist/prool/Instance.js +0 -136
  162. package/dist/prool/Instance.js.map +0 -1
  163. package/dist/prool/chain.json +0 -238
  164. package/dist/prool/index.d.ts +0 -2
  165. package/dist/prool/index.d.ts.map +0 -1
  166. package/dist/prool/index.js +0 -2
  167. package/dist/prool/index.js.map +0 -1
  168. package/src/ox/AuthorizationTempo.test.ts +0 -1256
  169. package/src/ox/AuthorizationTempo.ts +0 -648
  170. package/src/ox/KeyAuthorization.test.ts +0 -1332
  171. package/src/ox/KeyAuthorization.ts +0 -540
  172. package/src/ox/Order.test.ts +0 -78
  173. package/src/ox/Order.ts +0 -125
  174. package/src/ox/OrdersFilters.test.ts +0 -182
  175. package/src/ox/OrdersFilters.ts +0 -125
  176. package/src/ox/Pagination.test.ts +0 -162
  177. package/src/ox/Pagination.ts +0 -164
  178. package/src/ox/PoolId.test.ts +0 -33
  179. package/src/ox/PoolId.ts +0 -27
  180. package/src/ox/RpcSchema.ts +0 -35
  181. package/src/ox/SignatureEnvelope.test.ts +0 -1876
  182. package/src/ox/SignatureEnvelope.ts +0 -791
  183. package/src/ox/Tick.test.ts +0 -281
  184. package/src/ox/Tick.ts +0 -181
  185. package/src/ox/TokenId.test.ts +0 -40
  186. package/src/ox/TokenId.ts +0 -50
  187. package/src/ox/TokenRole.test.ts +0 -16
  188. package/src/ox/TokenRole.ts +0 -27
  189. package/src/ox/Transaction.test.ts +0 -523
  190. package/src/ox/Transaction.ts +0 -332
  191. package/src/ox/TransactionEnvelopeTempo.test.ts +0 -1352
  192. package/src/ox/TransactionEnvelopeTempo.ts +0 -905
  193. package/src/ox/TransactionReceipt.ts +0 -190
  194. package/src/ox/TransactionRequest.ts +0 -147
  195. package/src/ox/e2e.test.ts +0 -1393
  196. package/src/ox/index.ts +0 -13
  197. package/src/prool/Instance.test.ts +0 -43
  198. package/src/prool/Instance.ts +0 -247
  199. package/src/prool/chain.json +0 -238
  200. package/src/prool/index.ts +0 -1
  201. package/src/viem/Actions/__snapshots__/dex.test.ts.snap +0 -850
  202. package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +0 -310
  203. 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
- })