tempo.ts 0.0.6 → 0.1.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 (195) hide show
  1. package/dist/chains.d.ts +244 -541
  2. package/dist/chains.d.ts.map +1 -1
  3. package/dist/chains.js +10 -23
  4. package/dist/chains.js.map +1 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/ox/SignatureEnvelope.d.ts +245 -0
  7. package/dist/ox/SignatureEnvelope.d.ts.map +1 -0
  8. package/dist/ox/SignatureEnvelope.js +437 -0
  9. package/dist/ox/SignatureEnvelope.js.map +1 -0
  10. package/dist/ox/Transaction.d.ts +61 -24
  11. package/dist/ox/Transaction.d.ts.map +1 -1
  12. package/dist/ox/Transaction.js +63 -18
  13. package/dist/ox/Transaction.js.map +1 -1
  14. package/dist/ox/TransactionEnvelopeAA.d.ts +461 -0
  15. package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -0
  16. package/dist/ox/TransactionEnvelopeAA.js +528 -0
  17. package/dist/ox/TransactionEnvelopeAA.js.map +1 -0
  18. package/dist/ox/TransactionRequest.d.ts +7 -5
  19. package/dist/ox/TransactionRequest.d.ts.map +1 -1
  20. package/dist/ox/TransactionRequest.js +21 -12
  21. package/dist/ox/TransactionRequest.js.map +1 -1
  22. package/dist/ox/index.d.ts +5 -4
  23. package/dist/ox/index.d.ts.map +1 -1
  24. package/dist/ox/index.js +5 -4
  25. package/dist/ox/index.js.map +1 -1
  26. package/dist/prool/Instance.d.ts +0 -4
  27. package/dist/prool/Instance.d.ts.map +1 -1
  28. package/dist/prool/Instance.js +7 -7
  29. package/dist/prool/Instance.js.map +1 -1
  30. package/dist/prool/index.d.ts +1 -1
  31. package/dist/prool/index.d.ts.map +1 -1
  32. package/dist/prool/index.js +1 -1
  33. package/dist/prool/index.js.map +1 -1
  34. package/dist/viem/{abis.d.ts → Abis.d.ts} +523 -9
  35. package/dist/viem/Abis.d.ts.map +1 -0
  36. package/dist/viem/{abis.js → Abis.js} +321 -9
  37. package/dist/viem/Abis.js.map +1 -0
  38. package/dist/viem/{actions → Actions}/amm.d.ts +21 -21
  39. package/dist/viem/Actions/amm.d.ts.map +1 -0
  40. package/dist/viem/{actions → Actions}/amm.js +55 -43
  41. package/dist/viem/Actions/amm.js.map +1 -0
  42. package/dist/viem/Actions/dex.d.ts +3263 -0
  43. package/dist/viem/Actions/dex.d.ts.map +1 -0
  44. package/dist/viem/Actions/dex.js +1357 -0
  45. package/dist/viem/Actions/dex.js.map +1 -0
  46. package/dist/viem/{actions → Actions}/fee.d.ts +8 -8
  47. package/dist/viem/Actions/fee.d.ts.map +1 -0
  48. package/dist/viem/{actions → Actions}/fee.js +14 -13
  49. package/dist/viem/Actions/fee.js.map +1 -0
  50. package/dist/viem/Actions/index.d.ts +6 -0
  51. package/dist/viem/Actions/index.d.ts.map +1 -0
  52. package/dist/viem/Actions/index.js +6 -0
  53. package/dist/viem/Actions/index.js.map +1 -0
  54. package/dist/viem/{actions → Actions}/policy.d.ts +19 -19
  55. package/dist/viem/Actions/policy.d.ts.map +1 -0
  56. package/dist/viem/{actions → Actions}/policy.js +59 -46
  57. package/dist/viem/Actions/policy.js.map +1 -0
  58. package/dist/viem/{actions → Actions}/token.d.ts +3250 -700
  59. package/dist/viem/Actions/token.d.ts.map +1 -0
  60. package/dist/viem/{actions → Actions}/token.js +419 -83
  61. package/dist/viem/Actions/token.js.map +1 -0
  62. package/dist/viem/Addresses.d.ts +9 -0
  63. package/dist/viem/Addresses.d.ts.map +1 -0
  64. package/dist/viem/Addresses.js +9 -0
  65. package/dist/viem/Addresses.js.map +1 -0
  66. package/dist/viem/{chain.d.ts → Chain.d.ts} +81 -57
  67. package/dist/viem/Chain.d.ts.map +1 -0
  68. package/dist/viem/{chain.js → Chain.js} +7 -7
  69. package/dist/viem/Chain.js.map +1 -0
  70. package/dist/viem/{client.d.ts → Client.d.ts} +4 -4
  71. package/dist/viem/Client.d.ts.map +1 -0
  72. package/dist/viem/{client.js → Client.js} +3 -3
  73. package/dist/viem/Client.js.map +1 -0
  74. package/dist/viem/{decorator.d.ts → Decorator.d.ts} +507 -5
  75. package/dist/viem/Decorator.d.ts.map +1 -0
  76. package/dist/viem/{decorator.js → Decorator.js} +31 -5
  77. package/dist/viem/Decorator.js.map +1 -0
  78. package/dist/viem/{formatters.d.ts → Formatters.d.ts} +2 -2
  79. package/dist/viem/Formatters.d.ts.map +1 -0
  80. package/dist/viem/{formatters.js → Formatters.js} +24 -17
  81. package/dist/viem/Formatters.js.map +1 -0
  82. package/dist/viem/Tick.d.ts +111 -0
  83. package/dist/viem/Tick.d.ts.map +1 -0
  84. package/dist/viem/Tick.js +127 -0
  85. package/dist/viem/Tick.js.map +1 -0
  86. package/dist/viem/TokenIds.d.ts +3 -0
  87. package/dist/viem/TokenIds.d.ts.map +1 -0
  88. package/dist/viem/TokenIds.js +3 -0
  89. package/dist/viem/TokenIds.js.map +1 -0
  90. package/dist/viem/Transaction.d.ts +57 -0
  91. package/dist/viem/Transaction.d.ts.map +1 -0
  92. package/dist/viem/Transaction.js +137 -0
  93. package/dist/viem/Transaction.js.map +1 -0
  94. package/dist/viem/{transport.d.ts → Transport.d.ts} +3 -3
  95. package/dist/viem/Transport.d.ts.map +1 -0
  96. package/dist/viem/{transport.js → Transport.js} +3 -3
  97. package/dist/viem/Transport.js.map +1 -0
  98. package/dist/viem/index.d.ts +13 -9
  99. package/dist/viem/index.d.ts.map +1 -1
  100. package/dist/viem/index.js +13 -9
  101. package/dist/viem/index.js.map +1 -1
  102. package/dist/viem/{types.d.ts → internal/types.d.ts} +3 -3
  103. package/dist/viem/internal/types.d.ts.map +1 -0
  104. package/dist/viem/{types.js.map → internal/types.js.map} +1 -1
  105. package/dist/viem/internal/utils.d.ts.map +1 -0
  106. package/dist/viem/internal/utils.js.map +1 -0
  107. package/package.json +87 -101
  108. package/src/chains.ts +10 -24
  109. package/src/ox/SignatureEnvelope.test.ts +1252 -0
  110. package/src/ox/SignatureEnvelope.ts +709 -0
  111. package/src/ox/Transaction.test.ts +144 -89
  112. package/src/ox/Transaction.ts +104 -29
  113. package/src/ox/TransactionEnvelopeAA.test.ts +1533 -0
  114. package/src/ox/TransactionEnvelopeAA.ts +858 -0
  115. package/src/ox/TransactionRequest.ts +25 -17
  116. package/src/ox/index.ts +2 -1
  117. package/src/prool/Instance.ts +6 -14
  118. package/src/prool/internal/chain.json +101 -27
  119. package/src/viem/{abis.ts → Abis.ts} +322 -8
  120. package/src/viem/{actions → Actions}/amm.test.ts +65 -68
  121. package/src/viem/{actions → Actions}/amm.ts +72 -60
  122. package/src/viem/Actions/dex.test.ts +1608 -0
  123. package/src/viem/Actions/dex.ts +2026 -0
  124. package/src/viem/{actions → Actions}/fee.test.ts +34 -36
  125. package/src/viem/{actions → Actions}/fee.ts +18 -17
  126. package/src/viem/{actions → Actions}/index.ts +1 -0
  127. package/src/viem/{actions → Actions}/policy.test.ts +2 -2
  128. package/src/viem/{actions → Actions}/policy.ts +77 -64
  129. package/src/viem/{actions → Actions}/token.test.ts +403 -64
  130. package/src/viem/{actions → Actions}/token.ts +672 -133
  131. package/src/viem/Addresses.ts +9 -0
  132. package/src/viem/{chain.ts → Chain.ts} +6 -6
  133. package/src/viem/{client.bench-d.ts → Client.bench-d.ts} +2 -2
  134. package/src/viem/{client.test.ts → Client.test.ts} +31 -6
  135. package/src/viem/{client.ts → Client.ts} +1 -1
  136. package/src/viem/{decorator.bench-d.ts → Decorator.bench-d.ts} +2 -2
  137. package/src/viem/{decorator.test.ts → Decorator.test.ts} +1 -0
  138. package/src/viem/{decorator.ts → Decorator.ts} +586 -4
  139. package/src/viem/{formatters.ts → Formatters.ts} +31 -20
  140. package/src/viem/Tick.test.ts +281 -0
  141. package/src/viem/Tick.ts +176 -0
  142. package/src/viem/TokenIds.ts +2 -0
  143. package/src/viem/Transaction.ts +303 -0
  144. package/src/viem/{transport.ts → Transport.ts} +5 -5
  145. package/src/viem/e2e.test.ts +153 -78
  146. package/src/viem/index.ts +13 -9
  147. package/src/viem/{types.ts → internal/types.ts} +3 -3
  148. package/dist/ox/TransactionEnvelopeFeeToken.d.ts +0 -393
  149. package/dist/ox/TransactionEnvelopeFeeToken.d.ts.map +0 -1
  150. package/dist/ox/TransactionEnvelopeFeeToken.js +0 -452
  151. package/dist/ox/TransactionEnvelopeFeeToken.js.map +0 -1
  152. package/dist/viem/abis.d.ts.map +0 -1
  153. package/dist/viem/abis.js.map +0 -1
  154. package/dist/viem/actions/amm.d.ts.map +0 -1
  155. package/dist/viem/actions/amm.js.map +0 -1
  156. package/dist/viem/actions/fee.d.ts.map +0 -1
  157. package/dist/viem/actions/fee.js.map +0 -1
  158. package/dist/viem/actions/index.d.ts +0 -5
  159. package/dist/viem/actions/index.d.ts.map +0 -1
  160. package/dist/viem/actions/index.js +0 -5
  161. package/dist/viem/actions/index.js.map +0 -1
  162. package/dist/viem/actions/policy.d.ts.map +0 -1
  163. package/dist/viem/actions/policy.js.map +0 -1
  164. package/dist/viem/actions/token.d.ts.map +0 -1
  165. package/dist/viem/actions/token.js.map +0 -1
  166. package/dist/viem/addresses.d.ts +0 -8
  167. package/dist/viem/addresses.d.ts.map +0 -1
  168. package/dist/viem/addresses.js +0 -8
  169. package/dist/viem/addresses.js.map +0 -1
  170. package/dist/viem/chain.d.ts.map +0 -1
  171. package/dist/viem/chain.js.map +0 -1
  172. package/dist/viem/client.d.ts.map +0 -1
  173. package/dist/viem/client.js.map +0 -1
  174. package/dist/viem/decorator.d.ts.map +0 -1
  175. package/dist/viem/decorator.js.map +0 -1
  176. package/dist/viem/formatters.d.ts.map +0 -1
  177. package/dist/viem/formatters.js.map +0 -1
  178. package/dist/viem/transaction.d.ts +0 -54
  179. package/dist/viem/transaction.d.ts.map +0 -1
  180. package/dist/viem/transaction.js +0 -108
  181. package/dist/viem/transaction.js.map +0 -1
  182. package/dist/viem/transport.d.ts.map +0 -1
  183. package/dist/viem/transport.js.map +0 -1
  184. package/dist/viem/types.d.ts.map +0 -1
  185. package/dist/viem/utils.d.ts.map +0 -1
  186. package/dist/viem/utils.js.map +0 -1
  187. package/src/ox/TransactionEnvelopeFeeToken.test.ts +0 -1119
  188. package/src/ox/TransactionEnvelopeFeeToken.ts +0 -717
  189. package/src/prool/internal/consensus.toml +0 -32
  190. package/src/viem/addresses.ts +0 -10
  191. package/src/viem/transaction.ts +0 -253
  192. /package/dist/viem/{types.js → internal/types.js} +0 -0
  193. /package/dist/viem/{utils.d.ts → internal/utils.d.ts} +0 -0
  194. /package/dist/viem/{utils.js → internal/utils.js} +0 -0
  195. /package/src/viem/{utils.ts → internal/utils.ts} +0 -0
@@ -0,0 +1,2026 @@
1
+ import {
2
+ type Account,
3
+ type Address,
4
+ type Chain,
5
+ type Client,
6
+ type ExtractAbiItem,
7
+ type GetEventArgs,
8
+ type Log,
9
+ parseEventLogs,
10
+ type ReadContractReturnType,
11
+ type TransactionReceipt,
12
+ type Transport,
13
+ type Log as viem_Log,
14
+ type WatchContractEventParameters,
15
+ type WriteContractReturnType,
16
+ } from 'viem'
17
+ import { parseAccount } from 'viem/accounts'
18
+ import {
19
+ readContract,
20
+ watchContractEvent,
21
+ writeContract,
22
+ writeContractSync,
23
+ } from 'viem/actions'
24
+ import type { Compute, UnionOmit } from '../../internal/types.js'
25
+ import * as Abis from '../Abis.js'
26
+ import * as Addresses from '../Addresses.js'
27
+ import type {
28
+ GetAccountParameter,
29
+ ReadParameters,
30
+ WriteParameters,
31
+ } from '../internal/types.js'
32
+ import { defineCall } from '../internal/utils.js'
33
+
34
+ /**
35
+ * Order type for limit orders.
36
+ */
37
+ type OrderType = 'buy' | 'sell'
38
+
39
+ /**
40
+ * Buys a specific amount of tokens.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { createClient, http, parseUnits } from 'viem'
45
+ * import { privateKeyToAccount } from 'viem/accounts'
46
+ * import { tempo } from 'tempo.ts/chains'
47
+ * import { Actions } from 'tempo.ts/viem'
48
+ *
49
+ * const client = createClient({
50
+ * account: privateKeyToAccount('0x...'),
51
+ * chain: tempo,
52
+ * transport: http(),
53
+ * })
54
+ *
55
+ * const hash = await Actions.dex.buy(client, {
56
+ * tokenIn: '0x20c...11',
57
+ * tokenOut: '0x20c...20',
58
+ * amountOut: parseUnits('100', 6),
59
+ * maxAmountIn: parseUnits('105', 6),
60
+ * })
61
+ * ```
62
+ *
63
+ * @param client - Client.
64
+ * @param parameters - Parameters.
65
+ * @returns The transaction hash.
66
+ */
67
+ export async function buy<
68
+ chain extends Chain | undefined,
69
+ account extends Account | undefined,
70
+ >(
71
+ client: Client<Transport, chain, account>,
72
+ parameters: buy.Parameters<chain, account>,
73
+ ): Promise<buy.ReturnValue> {
74
+ return buy.inner(writeContract, client, parameters)
75
+ }
76
+
77
+ export namespace buy {
78
+ export type Parameters<
79
+ chain extends Chain | undefined = Chain | undefined,
80
+ account extends Account | undefined = Account | undefined,
81
+ > = WriteParameters<chain, account> & Args
82
+
83
+ export type Args = {
84
+ /** Amount of tokenOut to buy. */
85
+ amountOut: bigint
86
+ /** Maximum amount of tokenIn to spend. */
87
+ maxAmountIn: bigint
88
+ /** Address of the token to spend. */
89
+ tokenIn: Address
90
+ /** Address of the token to buy. */
91
+ tokenOut: Address
92
+ }
93
+
94
+ export type ReturnValue = WriteContractReturnType
95
+
96
+ /** @internal */
97
+ export async function inner<
98
+ action extends typeof writeContract | typeof writeContractSync,
99
+ chain extends Chain | undefined,
100
+ account extends Account | undefined,
101
+ >(
102
+ action: action,
103
+ client: Client<Transport, chain, account>,
104
+ parameters: buy.Parameters<chain, account>,
105
+ ): Promise<ReturnType<action>> {
106
+ const { tokenIn, tokenOut, amountOut, maxAmountIn, ...rest } = parameters
107
+ const call = buy.call({ tokenIn, tokenOut, amountOut, maxAmountIn })
108
+ return (await action(client, {
109
+ ...rest,
110
+ ...call,
111
+ } as never)) as never
112
+ }
113
+
114
+ /**
115
+ * Defines a call to the `swapExactAmountOut` function.
116
+ *
117
+ * Can be passed as a parameter to:
118
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
119
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
120
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * import { createClient, http, parseUnits, walletActions } from 'viem'
125
+ * import { tempo } from 'tempo.ts/chains'
126
+ * import { Actions } from 'tempo.ts/viem'
127
+ *
128
+ * const client = createClient({
129
+ * chain: tempo,
130
+ * transport: http(),
131
+ * }).extend(walletActions)
132
+ *
133
+ * const { result } = await client.sendCalls({
134
+ * calls: [
135
+ * Actions.dex.buy.call({
136
+ * tokenIn: '0x20c0...beef',
137
+ * tokenOut: '0x20c0...babe',
138
+ * amountOut: parseUnits('100', 6),
139
+ * maxAmountIn: parseUnits('105', 6),
140
+ * }),
141
+ * ]
142
+ * })
143
+ * ```
144
+ *
145
+ * @param args - Arguments.
146
+ * @returns The call.
147
+ */
148
+ export function call(args: Args) {
149
+ const { tokenIn, tokenOut, amountOut, maxAmountIn } = args
150
+ return defineCall({
151
+ address: Addresses.stablecoinExchange,
152
+ abi: Abis.stablecoinExchange,
153
+ functionName: 'swapExactAmountOut',
154
+ args: [tokenIn, tokenOut, amountOut, maxAmountIn],
155
+ })
156
+ }
157
+ }
158
+
159
+ /**
160
+ * Buys a specific amount of tokens.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * import { createClient, http, parseUnits } from 'viem'
165
+ * import { privateKeyToAccount } from 'viem/accounts'
166
+ * import { tempo } from 'tempo.ts/chains'
167
+ * import { Actions } from 'tempo.ts/viem'
168
+ *
169
+ * const client = createClient({
170
+ * account: privateKeyToAccount('0x...'),
171
+ * chain: tempo,
172
+ * transport: http(),
173
+ * })
174
+ *
175
+ * const result = await Actions.dex.buySync(client, {
176
+ * tokenIn: '0x20c...11',
177
+ * tokenOut: '0x20c...20',
178
+ * amountOut: parseUnits('100', 6),
179
+ * maxAmountIn: parseUnits('105', 6),
180
+ * })
181
+ * ```
182
+ *
183
+ * @param client - Client.
184
+ * @param parameters - Parameters.
185
+ * @returns The transaction receipt.
186
+ */
187
+ export async function buySync<
188
+ chain extends Chain | undefined,
189
+ account extends Account | undefined,
190
+ >(
191
+ client: Client<Transport, chain, account>,
192
+ parameters: buySync.Parameters<chain, account>,
193
+ ): Promise<buySync.ReturnValue> {
194
+ const { throwOnReceiptRevert = true, ...rest } = parameters
195
+ const receipt = await buy.inner(writeContractSync, client, {
196
+ ...rest,
197
+ throwOnReceiptRevert,
198
+ } as never)
199
+ return { receipt }
200
+ }
201
+
202
+ export namespace buySync {
203
+ export type Parameters<
204
+ chain extends Chain | undefined = Chain | undefined,
205
+ account extends Account | undefined = Account | undefined,
206
+ > = buy.Parameters<chain, account>
207
+
208
+ export type Args = buy.Args
209
+
210
+ export type ReturnValue = Compute<{
211
+ /** Transaction receipt. */
212
+ receipt: TransactionReceipt
213
+ }>
214
+ }
215
+
216
+ /**
217
+ * Cancels an order from the orderbook.
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * import { createClient, http } from 'viem'
222
+ * import { privateKeyToAccount } from 'viem/accounts'
223
+ * import { tempo } from 'tempo.ts/chains'
224
+ * import { Actions } from 'tempo.ts/viem'
225
+ *
226
+ * const client = createClient({
227
+ * account: privateKeyToAccount('0x...'),
228
+ * chain: tempo,
229
+ * transport: http(),
230
+ * })
231
+ *
232
+ * const hash = await Actions.dex.cancel(client, {
233
+ * orderId: 123n,
234
+ * })
235
+ * ```
236
+ *
237
+ * @param client - Client.
238
+ * @param parameters - Parameters.
239
+ * @returns The transaction hash.
240
+ */
241
+ export async function cancel<
242
+ chain extends Chain | undefined,
243
+ account extends Account | undefined,
244
+ >(
245
+ client: Client<Transport, chain, account>,
246
+ parameters: cancel.Parameters<chain, account>,
247
+ ): Promise<cancel.ReturnValue> {
248
+ return cancel.inner(writeContract, client, parameters)
249
+ }
250
+
251
+ export namespace cancel {
252
+ export type Parameters<
253
+ chain extends Chain | undefined = Chain | undefined,
254
+ account extends Account | undefined = Account | undefined,
255
+ > = WriteParameters<chain, account> & Args
256
+
257
+ export type Args = {
258
+ /** Order ID to cancel. */
259
+ orderId: bigint
260
+ }
261
+
262
+ export type ReturnValue = WriteContractReturnType
263
+
264
+ /** @internal */
265
+ export async function inner<
266
+ action extends typeof writeContract | typeof writeContractSync,
267
+ chain extends Chain | undefined,
268
+ account extends Account | undefined,
269
+ >(
270
+ action: action,
271
+ client: Client<Transport, chain, account>,
272
+ parameters: cancel.Parameters<chain, account>,
273
+ ): Promise<ReturnType<action>> {
274
+ const { orderId, ...rest } = parameters
275
+ const call = cancel.call({ orderId })
276
+ return (await action(client, {
277
+ ...rest,
278
+ ...call,
279
+ } as never)) as never
280
+ }
281
+
282
+ /**
283
+ * Defines a call to the `cancel` function.
284
+ *
285
+ * Can be passed as a parameter to:
286
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
287
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
288
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
289
+ *
290
+ * @example
291
+ * ```ts
292
+ * import { createClient, http, walletActions } from 'viem'
293
+ * import { tempo } from 'tempo.ts/chains'
294
+ * import { Actions } from 'tempo.ts/viem'
295
+ *
296
+ * const client = createClient({
297
+ * chain: tempo,
298
+ * transport: http(),
299
+ * }).extend(walletActions)
300
+ *
301
+ * const { result } = await client.sendCalls({
302
+ * calls: [
303
+ * Actions.dex.cancel.call({
304
+ * orderId: 123n,
305
+ * }),
306
+ * ]
307
+ * })
308
+ * ```
309
+ *
310
+ * @param args - Arguments.
311
+ * @returns The call.
312
+ */
313
+ export function call(args: Args) {
314
+ const { orderId } = args
315
+ return defineCall({
316
+ address: Addresses.stablecoinExchange,
317
+ abi: Abis.stablecoinExchange,
318
+ functionName: 'cancel',
319
+ args: [orderId],
320
+ })
321
+ }
322
+
323
+ /**
324
+ * Extracts the `OrderCancelled` event from logs.
325
+ *
326
+ * @param logs - The logs.
327
+ * @returns The `OrderCancelled` event.
328
+ */
329
+ export function extractEvent(logs: Log[]) {
330
+ const [log] = parseEventLogs({
331
+ abi: Abis.stablecoinExchange,
332
+ logs,
333
+ eventName: 'OrderCancelled',
334
+ strict: true,
335
+ })
336
+ if (!log) throw new Error('`OrderCancelled` event not found.')
337
+ return log
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Cancels an order from the orderbook.
343
+ *
344
+ * @example
345
+ * ```ts
346
+ * import { createClient, http } from 'viem'
347
+ * import { privateKeyToAccount } from 'viem/accounts'
348
+ * import { tempo } from 'tempo.ts/chains'
349
+ * import { Actions } from 'tempo.ts/viem'
350
+ *
351
+ * const client = createClient({
352
+ * account: privateKeyToAccount('0x...'),
353
+ * chain: tempo,
354
+ * transport: http(),
355
+ * })
356
+ *
357
+ * const result = await Actions.dex.cancelSync(client, {
358
+ * orderId: 123n,
359
+ * })
360
+ * ```
361
+ *
362
+ * @param client - Client.
363
+ * @param parameters - Parameters.
364
+ * @returns The transaction receipt and event data.
365
+ */
366
+ export async function cancelSync<
367
+ chain extends Chain | undefined,
368
+ account extends Account | undefined,
369
+ >(
370
+ client: Client<Transport, chain, account>,
371
+ parameters: cancelSync.Parameters<chain, account>,
372
+ ): Promise<cancelSync.ReturnValue> {
373
+ const { throwOnReceiptRevert = true, ...rest } = parameters
374
+ const receipt = await cancel.inner(writeContractSync, client, {
375
+ ...rest,
376
+ throwOnReceiptRevert,
377
+ } as never)
378
+ const { args } = cancel.extractEvent(receipt.logs)
379
+ return {
380
+ ...args,
381
+ receipt,
382
+ } as never
383
+ }
384
+
385
+ export namespace cancelSync {
386
+ export type Parameters<
387
+ chain extends Chain | undefined = Chain | undefined,
388
+ account extends Account | undefined = Account | undefined,
389
+ > = cancel.Parameters<chain, account>
390
+
391
+ export type Args = cancel.Args
392
+
393
+ export type ReturnValue = Compute<
394
+ GetEventArgs<
395
+ typeof Abis.stablecoinExchange,
396
+ 'OrderCancelled',
397
+ { IndexedOnly: false; Required: true }
398
+ > & {
399
+ /** Transaction receipt. */
400
+ receipt: TransactionReceipt
401
+ }
402
+ >
403
+ }
404
+
405
+ /**
406
+ * Creates a new trading pair on the DEX.
407
+ *
408
+ * @example
409
+ * ```ts
410
+ * import { createClient, http } from 'viem'
411
+ * import { privateKeyToAccount } from 'viem/accounts'
412
+ * import { tempo } from 'tempo.ts/chains'
413
+ * import { Actions } from 'tempo.ts/viem'
414
+ *
415
+ * const client = createClient({
416
+ * account: privateKeyToAccount('0x...'),
417
+ * chain: tempo,
418
+ * transport: http(),
419
+ * })
420
+ *
421
+ * const hash = await Actions.dex.createPair(client, {
422
+ * base: '0x20c...11',
423
+ * })
424
+ * ```
425
+ *
426
+ * @param client - Client.
427
+ * @param parameters - Parameters.
428
+ * @returns The transaction hash.
429
+ */
430
+ export async function createPair<
431
+ chain extends Chain | undefined,
432
+ account extends Account | undefined,
433
+ >(
434
+ client: Client<Transport, chain, account>,
435
+ parameters: createPair.Parameters<chain, account>,
436
+ ): Promise<createPair.ReturnValue> {
437
+ return createPair.inner(writeContract, client, parameters)
438
+ }
439
+
440
+ export namespace createPair {
441
+ export type Parameters<
442
+ chain extends Chain | undefined = Chain | undefined,
443
+ account extends Account | undefined = Account | undefined,
444
+ > = WriteParameters<chain, account> & Args
445
+
446
+ export type Args = {
447
+ /** Address of the base token for the pair. */
448
+ base: Address
449
+ }
450
+
451
+ export type ReturnValue = WriteContractReturnType
452
+
453
+ /** @internal */
454
+ export async function inner<
455
+ action extends typeof writeContract | typeof writeContractSync,
456
+ chain extends Chain | undefined,
457
+ account extends Account | undefined,
458
+ >(
459
+ action: action,
460
+ client: Client<Transport, chain, account>,
461
+ parameters: createPair.Parameters<chain, account>,
462
+ ): Promise<ReturnType<action>> {
463
+ const { base, ...rest } = parameters
464
+ const call = createPair.call({ base })
465
+ return (await action(client, {
466
+ ...rest,
467
+ ...call,
468
+ } as never)) as never
469
+ }
470
+
471
+ /**
472
+ * Defines a call to the `createPair` function.
473
+ *
474
+ * Can be passed as a parameter to:
475
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
476
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
477
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
478
+ *
479
+ * @example
480
+ * ```ts
481
+ * import { createClient, http, walletActions } from 'viem'
482
+ * import { tempo } from 'tempo.ts/chains'
483
+ * import { Actions } from 'tempo.ts/viem'
484
+ *
485
+ * const client = createClient({
486
+ * chain: tempo,
487
+ * transport: http(),
488
+ * }).extend(walletActions)
489
+ *
490
+ * const { result } = await client.sendCalls({
491
+ * calls: [
492
+ * Actions.dex.createPair.call({
493
+ * base: '0x20c0...beef',
494
+ * }),
495
+ * ]
496
+ * })
497
+ * ```
498
+ *
499
+ * @param args - Arguments.
500
+ * @returns The call.
501
+ */
502
+ export function call(args: Args) {
503
+ const { base } = args
504
+ return defineCall({
505
+ address: Addresses.stablecoinExchange,
506
+ abi: Abis.stablecoinExchange,
507
+ functionName: 'createPair',
508
+ args: [base],
509
+ })
510
+ }
511
+
512
+ /**
513
+ * Extracts the `PairCreated` event from logs.
514
+ *
515
+ * @param logs - The logs.
516
+ * @returns The `PairCreated` event.
517
+ */
518
+ export function extractEvent(logs: Log[]) {
519
+ const [log] = parseEventLogs({
520
+ abi: Abis.stablecoinExchange,
521
+ logs,
522
+ eventName: 'PairCreated',
523
+ strict: true,
524
+ })
525
+ if (!log) throw new Error('`PairCreated` event not found.')
526
+ return log
527
+ }
528
+ }
529
+
530
+ /**
531
+ * Creates a new trading pair on the DEX.
532
+ *
533
+ * @example
534
+ * ```ts
535
+ * import { createClient, http } from 'viem'
536
+ * import { privateKeyToAccount } from 'viem/accounts'
537
+ * import { tempo } from 'tempo.ts/chains'
538
+ * import { Actions } from 'tempo.ts/viem'
539
+ *
540
+ * const client = createClient({
541
+ * account: privateKeyToAccount('0x...'),
542
+ * chain: tempo,
543
+ * transport: http(),
544
+ * })
545
+ *
546
+ * const result = await Actions.dex.createPairSync(client, {
547
+ * base: '0x20c...11',
548
+ * })
549
+ * ```
550
+ *
551
+ * @param client - Client.
552
+ * @param parameters - Parameters.
553
+ * @returns The transaction receipt and event data.
554
+ */
555
+ export async function createPairSync<
556
+ chain extends Chain | undefined,
557
+ account extends Account | undefined,
558
+ >(
559
+ client: Client<Transport, chain, account>,
560
+ parameters: createPairSync.Parameters<chain, account>,
561
+ ): Promise<createPairSync.ReturnValue> {
562
+ const { throwOnReceiptRevert = true, ...rest } = parameters
563
+ const receipt = await createPair.inner(writeContractSync, client, {
564
+ ...rest,
565
+ throwOnReceiptRevert,
566
+ } as never)
567
+ const { args } = createPair.extractEvent(receipt.logs)
568
+ return {
569
+ ...args,
570
+ receipt,
571
+ } as never
572
+ }
573
+
574
+ export namespace createPairSync {
575
+ export type Parameters<
576
+ chain extends Chain | undefined = Chain | undefined,
577
+ account extends Account | undefined = Account | undefined,
578
+ > = createPair.Parameters<chain, account>
579
+
580
+ export type Args = createPair.Args
581
+
582
+ export type ReturnValue = Compute<
583
+ GetEventArgs<
584
+ typeof Abis.stablecoinExchange,
585
+ 'PairCreated',
586
+ { IndexedOnly: false; Required: true }
587
+ > & {
588
+ /** Transaction receipt. */
589
+ receipt: TransactionReceipt
590
+ }
591
+ >
592
+ }
593
+
594
+ /**
595
+ * Gets a user's token balance on the DEX.
596
+ *
597
+ * @example
598
+ * ```ts
599
+ * import { createClient, http } from 'viem'
600
+ * import { tempo } from 'tempo.ts/chains'
601
+ * import { Actions } from 'tempo.ts/viem'
602
+ *
603
+ * const client = createClient({
604
+ * chain: tempo,
605
+ * transport: http(),
606
+ * })
607
+ *
608
+ * const balance = await Actions.dex.getBalance(client, {
609
+ * account: '0x...',
610
+ * token: '0x20c...11',
611
+ * })
612
+ * ```
613
+ *
614
+ * @param client - Client.
615
+ * @param parameters - Parameters.
616
+ * @returns The user's token balance on the DEX.
617
+ */
618
+ export async function getBalance<
619
+ chain extends Chain | undefined,
620
+ account extends Account | undefined,
621
+ >(
622
+ client: Client<Transport, chain, account>,
623
+ parameters: getBalance.Parameters<account>,
624
+ ): Promise<getBalance.ReturnValue> {
625
+ const { account: acc = client.account, token, ...rest } = parameters
626
+ const address = acc ? parseAccount(acc).address : undefined
627
+ if (!address) throw new Error('account is required.')
628
+ return readContract(client, {
629
+ ...rest,
630
+ ...getBalance.call({ account: address, token }),
631
+ })
632
+ }
633
+
634
+ export namespace getBalance {
635
+ export type Parameters<
636
+ account extends Account | undefined = Account | undefined,
637
+ > = ReadParameters & GetAccountParameter<account> & Args
638
+
639
+ export type Args = {
640
+ /** Address of the account. */
641
+ account: Address
642
+ /** Address of the token. */
643
+ token: Address
644
+ }
645
+
646
+ export type ReturnValue = ReadContractReturnType<
647
+ typeof Abis.stablecoinExchange,
648
+ 'balanceOf',
649
+ never
650
+ >
651
+
652
+ /**
653
+ * Defines a call to the `balanceOf` function.
654
+ *
655
+ * @param args - Arguments.
656
+ * @returns The call.
657
+ */
658
+ export function call(args: Args) {
659
+ const { account, token } = args
660
+ return defineCall({
661
+ address: Addresses.stablecoinExchange,
662
+ abi: Abis.stablecoinExchange,
663
+ args: [account, token],
664
+ functionName: 'balanceOf',
665
+ })
666
+ }
667
+ }
668
+
669
+ /**
670
+ * Gets the quote for buying a specific amount of tokens.
671
+ *
672
+ * @example
673
+ * ```ts
674
+ * import { createClient, http, parseUnits } from 'viem'
675
+ * import { tempo } from 'tempo.ts/chains'
676
+ * import { Actions } from 'tempo.ts/viem'
677
+ *
678
+ * const client = createClient({
679
+ * chain: tempo,
680
+ * transport: http(),
681
+ * })
682
+ *
683
+ * const amountIn = await Actions.dex.getBuyQuote(client, {
684
+ * amountOut: parseUnits('100', 6),
685
+ * tokenIn: '0x20c...11',
686
+ * tokenOut: '0x20c...20',
687
+ * })
688
+ * ```
689
+ *
690
+ * @param client - Client.
691
+ * @param parameters - Parameters.
692
+ * @returns The amount of tokenIn needed to buy the specified amountOut.
693
+ */
694
+ export async function getBuyQuote<chain extends Chain | undefined>(
695
+ client: Client<Transport, chain>,
696
+ parameters: getBuyQuote.Parameters,
697
+ ): Promise<getBuyQuote.ReturnValue> {
698
+ const { tokenIn, tokenOut, amountOut, ...rest } = parameters
699
+ return readContract(client, {
700
+ ...rest,
701
+ ...getBuyQuote.call({ tokenIn, tokenOut, amountOut }),
702
+ })
703
+ }
704
+
705
+ export namespace getBuyQuote {
706
+ export type Parameters = ReadParameters & Args
707
+
708
+ export type Args = {
709
+ /** Amount of tokenOut to buy. */
710
+ amountOut: bigint
711
+ /** Address of the token to spend. */
712
+ tokenIn: Address
713
+ /** Address of the token to buy. */
714
+ tokenOut: Address
715
+ }
716
+
717
+ export type ReturnValue = ReadContractReturnType<
718
+ typeof Abis.stablecoinExchange,
719
+ 'quoteSwapExactAmountOut',
720
+ never
721
+ >
722
+
723
+ /**
724
+ * Defines a call to the `quoteSwapExactAmountOut` function.
725
+ *
726
+ * @param args - Arguments.
727
+ * @returns The call.
728
+ */
729
+ export function call(args: Args) {
730
+ const { tokenIn, tokenOut, amountOut } = args
731
+ return defineCall({
732
+ address: Addresses.stablecoinExchange,
733
+ abi: Abis.stablecoinExchange,
734
+ args: [tokenIn, tokenOut, amountOut],
735
+ functionName: 'quoteSwapExactAmountOut',
736
+ })
737
+ }
738
+ }
739
+
740
+ /**
741
+ * Gets an order's details from the orderbook.
742
+ *
743
+ * @example
744
+ * ```ts
745
+ * import { createClient, http } from 'viem'
746
+ * import { tempo } from 'tempo.ts/chains'
747
+ * import { Actions } from 'tempo.ts/viem'
748
+ *
749
+ * const client = createClient({
750
+ * chain: tempo,
751
+ * transport: http(),
752
+ * })
753
+ *
754
+ * const order = await Actions.dex.getOrder(client, {
755
+ * orderId: 123n,
756
+ * })
757
+ * ```
758
+ *
759
+ * @param client - Client.
760
+ * @param parameters - Parameters.
761
+ * @returns The order details.
762
+ */
763
+ export async function getOrder<chain extends Chain | undefined>(
764
+ client: Client<Transport, chain>,
765
+ parameters: getOrder.Parameters,
766
+ ): Promise<getOrder.ReturnValue> {
767
+ const { orderId, ...rest } = parameters
768
+ return readContract(client, {
769
+ ...rest,
770
+ ...getOrder.call({ orderId }),
771
+ })
772
+ }
773
+
774
+ export namespace getOrder {
775
+ export type Parameters = ReadParameters & Args
776
+
777
+ export type Args = {
778
+ /** Order ID to query. */
779
+ orderId: bigint
780
+ }
781
+
782
+ export type ReturnValue = ReadContractReturnType<
783
+ typeof Abis.stablecoinExchange,
784
+ 'getOrder',
785
+ never
786
+ >
787
+
788
+ /**
789
+ * Defines a call to the `getOrder` function.
790
+ *
791
+ * @param args - Arguments.
792
+ * @returns The call.
793
+ */
794
+ export function call(args: Args) {
795
+ const { orderId } = args
796
+ return defineCall({
797
+ address: Addresses.stablecoinExchange,
798
+ abi: Abis.stablecoinExchange,
799
+ args: [orderId],
800
+ functionName: 'getOrder',
801
+ })
802
+ }
803
+ }
804
+
805
+ /**
806
+ * Gets the price level information at a specific tick.
807
+ *
808
+ * @example
809
+ * ```ts
810
+ * import { createClient, http } from 'viem'
811
+ * import { tempo } from 'tempo.ts/chains'
812
+ * import { Actions, Tick } from 'tempo.ts/viem'
813
+ *
814
+ * const client = createClient({
815
+ * chain: tempo,
816
+ * transport: http(),
817
+ * })
818
+ *
819
+ * const level = await Actions.dex.getPriceLevel(client, {
820
+ * base: '0x20c...11',
821
+ * tick: Tick.fromPrice('1.001'),
822
+ * isBid: true,
823
+ * })
824
+ * ```
825
+ *
826
+ * @param client - Client.
827
+ * @param parameters - Parameters.
828
+ * @returns The price level information.
829
+ */
830
+ export async function getPriceLevel<chain extends Chain | undefined>(
831
+ client: Client<Transport, chain>,
832
+ parameters: getPriceLevel.Parameters,
833
+ ): Promise<getPriceLevel.ReturnValue> {
834
+ const { base, tick, isBid, ...rest } = parameters
835
+ return readContract(client, {
836
+ ...rest,
837
+ ...getPriceLevel.call({ base, tick, isBid }),
838
+ })
839
+ }
840
+
841
+ export namespace getPriceLevel {
842
+ export type Parameters = ReadParameters & Args
843
+
844
+ export type Args = {
845
+ /** Address of the base token. */
846
+ base: Address
847
+ /** Whether to query the bid side (true) or ask side (false). */
848
+ isBid: boolean
849
+ /** Price tick to query. */
850
+ tick: number
851
+ }
852
+
853
+ export type ReturnValue = ReadContractReturnType<
854
+ typeof Abis.stablecoinExchange,
855
+ 'getPriceLevel',
856
+ never
857
+ >
858
+
859
+ /**
860
+ * Defines a call to the `getPriceLevel` function.
861
+ *
862
+ * @param args - Arguments.
863
+ * @returns The call.
864
+ */
865
+ export function call(args: Args) {
866
+ const { base, tick, isBid } = args
867
+ return defineCall({
868
+ address: Addresses.stablecoinExchange,
869
+ abi: Abis.stablecoinExchange,
870
+ args: [base, tick, isBid],
871
+ functionName: 'getPriceLevel',
872
+ })
873
+ }
874
+ }
875
+
876
+ /**
877
+ * Gets the quote for selling a specific amount of tokens.
878
+ *
879
+ * @example
880
+ * ```ts
881
+ * import { createClient, http, parseUnits } from 'viem'
882
+ * import { tempo } from 'tempo.ts/chains'
883
+ * import { Actions } from 'tempo.ts/viem'
884
+ *
885
+ * const client = createClient({
886
+ * chain: tempo,
887
+ * transport: http(),
888
+ * })
889
+ *
890
+ * const amountOut = await Actions.dex.getSellQuote(client, {
891
+ * amountIn: parseUnits('100', 6),
892
+ * tokenIn: '0x20c...11',
893
+ * tokenOut: '0x20c...20',
894
+ * })
895
+ * ```
896
+ *
897
+ * @param client - Client.
898
+ * @param parameters - Parameters.
899
+ * @returns The amount of tokenOut received for selling the specified amountIn.
900
+ */
901
+ export async function getSellQuote<chain extends Chain | undefined>(
902
+ client: Client<Transport, chain>,
903
+ parameters: getSellQuote.Parameters,
904
+ ): Promise<getSellQuote.ReturnValue> {
905
+ const { tokenIn, tokenOut, amountIn, ...rest } = parameters
906
+ return readContract(client, {
907
+ ...rest,
908
+ ...getSellQuote.call({ tokenIn, tokenOut, amountIn }),
909
+ })
910
+ }
911
+
912
+ export namespace getSellQuote {
913
+ export type Parameters = ReadParameters & Args
914
+
915
+ export type Args = {
916
+ /** Amount of tokenIn to sell. */
917
+ amountIn: bigint
918
+ /** Address of the token to sell. */
919
+ tokenIn: Address
920
+ /** Address of the token to receive. */
921
+ tokenOut: Address
922
+ }
923
+
924
+ export type ReturnValue = ReadContractReturnType<
925
+ typeof Abis.stablecoinExchange,
926
+ 'quoteSwapExactAmountIn',
927
+ never
928
+ >
929
+
930
+ /**
931
+ * Defines a call to the `quoteSwapExactAmountIn` function.
932
+ *
933
+ * @param args - Arguments.
934
+ * @returns The call.
935
+ */
936
+ export function call(args: Args) {
937
+ const { tokenIn, tokenOut, amountIn } = args
938
+ return defineCall({
939
+ address: Addresses.stablecoinExchange,
940
+ abi: Abis.stablecoinExchange,
941
+ args: [tokenIn, tokenOut, amountIn],
942
+ functionName: 'quoteSwapExactAmountIn',
943
+ })
944
+ }
945
+ }
946
+
947
+ /**
948
+ * Places a limit order on the orderbook.
949
+ *
950
+ * @example
951
+ * ```ts
952
+ * import { createClient, http, parseUnits } from 'viem'
953
+ * import { privateKeyToAccount } from 'viem/accounts'
954
+ * import { tempo } from 'tempo.ts/chains'
955
+ * import { Actions, Tick } from 'tempo.ts/viem'
956
+ *
957
+ * const client = createClient({
958
+ * account: privateKeyToAccount('0x...'),
959
+ * chain: tempo,
960
+ * transport: http(),
961
+ * })
962
+ *
963
+ * const hash = await Actions.dex.place(client, {
964
+ * amount: parseUnits('100', 6),
965
+ * tick: Tick.fromPrice('0.99'),
966
+ * token: '0x20c...11',
967
+ * type: 'buy',
968
+ * })
969
+ * ```
970
+ *
971
+ * @param client - Client.
972
+ * @param parameters - Parameters.
973
+ * @returns The transaction hash.
974
+ */
975
+ export async function place<
976
+ chain extends Chain | undefined,
977
+ account extends Account | undefined,
978
+ >(
979
+ client: Client<Transport, chain, account>,
980
+ parameters: place.Parameters<chain, account>,
981
+ ): Promise<place.ReturnValue> {
982
+ return place.inner(writeContract, client, parameters)
983
+ }
984
+
985
+ export namespace place {
986
+ export type Parameters<
987
+ chain extends Chain | undefined = Chain | undefined,
988
+ account extends Account | undefined = Account | undefined,
989
+ > = WriteParameters<chain, account> & Args
990
+
991
+ export type Args = {
992
+ /** Amount of tokens to place in the order. */
993
+ amount: bigint
994
+ /** Price tick for the order. */
995
+ tick: number
996
+ /** Address of the base token. */
997
+ token: Address
998
+ /** Order type - 'buy' to buy the token, 'sell' to sell it. */
999
+ type: OrderType
1000
+ }
1001
+
1002
+ export type ReturnValue = WriteContractReturnType
1003
+
1004
+ /** @internal */
1005
+ export async function inner<
1006
+ action extends typeof writeContract | typeof writeContractSync,
1007
+ chain extends Chain | undefined,
1008
+ account extends Account | undefined,
1009
+ >(
1010
+ action: action,
1011
+ client: Client<Transport, chain, account>,
1012
+ parameters: place.Parameters<chain, account>,
1013
+ ): Promise<ReturnType<action>> {
1014
+ const { amount, token, type, tick, ...rest } = parameters
1015
+ const call = place.call({ amount, token, type, tick })
1016
+ return (await action(client, {
1017
+ ...rest,
1018
+ ...call,
1019
+ } as never)) as never
1020
+ }
1021
+
1022
+ /**
1023
+ * Defines a call to the `place` function.
1024
+ *
1025
+ * Can be passed as a parameter to:
1026
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1027
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1028
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1029
+ *
1030
+ * @example
1031
+ * ```ts
1032
+ * import { createClient, http, parseUnits, walletActions } from 'viem'
1033
+ * import { tempo } from 'tempo.ts/chains'
1034
+ * import { Actions, Tick } from 'tempo.ts/viem'
1035
+ *
1036
+ * const client = createClient({
1037
+ * chain: tempo,
1038
+ * transport: http(),
1039
+ * }).extend(walletActions)
1040
+ *
1041
+ * const { result } = await client.sendCalls({
1042
+ * calls: [
1043
+ * Actions.dex.place.call({
1044
+ * amount: parseUnits('100', 6),
1045
+ * tick: Tick.fromPrice('0.99'),
1046
+ * token: '0x20c0...beef',
1047
+ * type: 'buy',
1048
+ * }),
1049
+ * ]
1050
+ * })
1051
+ * ```
1052
+ *
1053
+ * @param args - Arguments.
1054
+ * @returns The call.
1055
+ */
1056
+ export function call(args: Args) {
1057
+ const { token, amount, type, tick } = args
1058
+ const isBid = type === 'buy'
1059
+ return defineCall({
1060
+ address: Addresses.stablecoinExchange,
1061
+ abi: Abis.stablecoinExchange,
1062
+ functionName: 'place',
1063
+ args: [token, amount, isBid, tick],
1064
+ })
1065
+ }
1066
+
1067
+ /**
1068
+ * Extracts the `OrderPlaced` event from logs.
1069
+ *
1070
+ * @param logs - The logs.
1071
+ * @returns The `OrderPlaced` event.
1072
+ */
1073
+ export function extractEvent(logs: Log[]) {
1074
+ const [log] = parseEventLogs({
1075
+ abi: Abis.stablecoinExchange,
1076
+ logs,
1077
+ eventName: 'OrderPlaced',
1078
+ strict: true,
1079
+ })
1080
+ if (!log) throw new Error('`OrderPlaced` event not found.')
1081
+ return log
1082
+ }
1083
+ }
1084
+
1085
+ /**
1086
+ * Places a flip order that automatically flips when filled.
1087
+ *
1088
+ * @example
1089
+ * ```ts
1090
+ * import { createClient, http, parseUnits } from 'viem'
1091
+ * import { privateKeyToAccount } from 'viem/accounts'
1092
+ * import { tempo } from 'tempo.ts/chains'
1093
+ * import { Actions, Tick } from 'tempo.ts/viem'
1094
+ *
1095
+ * const client = createClient({
1096
+ * account: privateKeyToAccount('0x...'),
1097
+ * chain: tempo,
1098
+ * transport: http(),
1099
+ * })
1100
+ *
1101
+ * const hash = await Actions.dex.placeFlip(client, {
1102
+ * amount: parseUnits('100', 6),
1103
+ * flipTick: Tick.fromPrice('1.01'),
1104
+ * tick: Tick.fromPrice('0.99'),
1105
+ * token: '0x20c...11',
1106
+ * type: 'buy',
1107
+ * })
1108
+ * ```
1109
+ *
1110
+ * @param client - Client.
1111
+ * @param parameters - Parameters.
1112
+ * @returns The transaction hash.
1113
+ */
1114
+ export async function placeFlip<
1115
+ chain extends Chain | undefined,
1116
+ account extends Account | undefined,
1117
+ >(
1118
+ client: Client<Transport, chain, account>,
1119
+ parameters: placeFlip.Parameters<chain, account>,
1120
+ ): Promise<placeFlip.ReturnValue> {
1121
+ return placeFlip.inner(writeContract, client, parameters)
1122
+ }
1123
+
1124
+ export namespace placeFlip {
1125
+ export type Parameters<
1126
+ chain extends Chain | undefined = Chain | undefined,
1127
+ account extends Account | undefined = Account | undefined,
1128
+ > = WriteParameters<chain, account> & Args
1129
+
1130
+ export type Args = {
1131
+ /** Amount of tokens to place in the order. */
1132
+ amount: bigint
1133
+ /** Target tick to flip to when order is filled. */
1134
+ flipTick: number
1135
+ /** Price tick for the order. */
1136
+ tick: number
1137
+ /** Address of the base token. */
1138
+ token: Address
1139
+ /** Order type - 'buy' to buy the token, 'sell' to sell it. */
1140
+ type: OrderType
1141
+ }
1142
+
1143
+ export type ReturnValue = WriteContractReturnType
1144
+
1145
+ /** @internal */
1146
+ export async function inner<
1147
+ action extends typeof writeContract | typeof writeContractSync,
1148
+ chain extends Chain | undefined,
1149
+ account extends Account | undefined,
1150
+ >(
1151
+ action: action,
1152
+ client: Client<Transport, chain, account>,
1153
+ parameters: placeFlip.Parameters<chain, account>,
1154
+ ): Promise<ReturnType<action>> {
1155
+ const { amount, flipTick, tick, token, type, ...rest } = parameters
1156
+ const call = placeFlip.call({ amount, flipTick, tick, token, type })
1157
+ return (await action(client, {
1158
+ ...rest,
1159
+ ...call,
1160
+ } as never)) as never
1161
+ }
1162
+
1163
+ /**
1164
+ * Defines a call to the `placeFlip` function.
1165
+ *
1166
+ * Can be passed as a parameter to:
1167
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1168
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1169
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1170
+ *
1171
+ * @example
1172
+ * ```ts
1173
+ * import { createClient, http, parseUnits, walletActions } from 'viem'
1174
+ * import { tempo } from 'tempo.ts/chains'
1175
+ * import { Actions, Tick } from 'tempo.ts/viem'
1176
+ *
1177
+ * const client = createClient({
1178
+ * chain: tempo,
1179
+ * transport: http(),
1180
+ * }).extend(walletActions)
1181
+ *
1182
+ * const { result } = await client.sendCalls({
1183
+ * calls: [
1184
+ * Actions.dex.placeFlip.call({
1185
+ * amount: parseUnits('100', 6),
1186
+ * flipTick: Tick.fromPrice('1.01'),
1187
+ * tick: Tick.fromPrice('0.99'),
1188
+ * token: '0x20c0...beef',
1189
+ * type: 'buy',
1190
+ * }),
1191
+ * ]
1192
+ * })
1193
+ * ```
1194
+ *
1195
+ * @param args - Arguments.
1196
+ * @returns The call.
1197
+ */
1198
+ export function call(args: Args) {
1199
+ const { token, amount, type, tick, flipTick } = args
1200
+ const isBid = type === 'buy'
1201
+ return defineCall({
1202
+ address: Addresses.stablecoinExchange,
1203
+ abi: Abis.stablecoinExchange,
1204
+ functionName: 'placeFlip',
1205
+ args: [token, amount, isBid, tick, flipTick],
1206
+ })
1207
+ }
1208
+
1209
+ /**
1210
+ * Extracts the `FlipOrderPlaced` event from logs.
1211
+ *
1212
+ * @param logs - The logs.
1213
+ * @returns The `FlipOrderPlaced` event.
1214
+ */
1215
+ export function extractEvent(logs: Log[]) {
1216
+ const [log] = parseEventLogs({
1217
+ abi: Abis.stablecoinExchange,
1218
+ logs,
1219
+ eventName: 'FlipOrderPlaced',
1220
+ strict: true,
1221
+ })
1222
+ if (!log) throw new Error('`FlipOrderPlaced` event not found.')
1223
+ return log
1224
+ }
1225
+ }
1226
+
1227
+ /**
1228
+ * Places a flip order that automatically flips when filled.
1229
+ *
1230
+ * @example
1231
+ * ```ts
1232
+ * import { createClient, http, parseUnits } from 'viem'
1233
+ * import { privateKeyToAccount } from 'viem/accounts'
1234
+ * import { tempo } from 'tempo.ts/chains'
1235
+ * import { Actions, Tick } from 'tempo.ts/viem'
1236
+ *
1237
+ * const client = createClient({
1238
+ * account: privateKeyToAccount('0x...'),
1239
+ * chain: tempo,
1240
+ * transport: http(),
1241
+ * })
1242
+ *
1243
+ * const result = await Actions.dex.placeFlipSync(client, {
1244
+ * amount: parseUnits('100', 6),
1245
+ * flipTick: Tick.fromPrice('1.01'),
1246
+ * tick: Tick.fromPrice('0.99'),
1247
+ * token: '0x20c...11',
1248
+ * type: 'buy',
1249
+ * })
1250
+ * ```
1251
+ *
1252
+ * @param client - Client.
1253
+ * @param parameters - Parameters.
1254
+ * @returns The transaction receipt and event data.
1255
+ */
1256
+ export async function placeFlipSync<
1257
+ chain extends Chain | undefined,
1258
+ account extends Account | undefined,
1259
+ >(
1260
+ client: Client<Transport, chain, account>,
1261
+ parameters: placeFlipSync.Parameters<chain, account>,
1262
+ ): Promise<placeFlipSync.ReturnValue> {
1263
+ const { throwOnReceiptRevert = true, ...rest } = parameters
1264
+ const receipt = await placeFlip.inner(writeContractSync, client, {
1265
+ ...rest,
1266
+ throwOnReceiptRevert,
1267
+ } as never)
1268
+ const { args } = placeFlip.extractEvent(receipt.logs)
1269
+ return {
1270
+ ...args,
1271
+ receipt,
1272
+ } as never
1273
+ }
1274
+
1275
+ export namespace placeFlipSync {
1276
+ export type Parameters<
1277
+ chain extends Chain | undefined = Chain | undefined,
1278
+ account extends Account | undefined = Account | undefined,
1279
+ > = placeFlip.Parameters<chain, account>
1280
+
1281
+ export type Args = placeFlip.Args
1282
+
1283
+ export type ReturnValue = Compute<
1284
+ GetEventArgs<
1285
+ typeof Abis.stablecoinExchange,
1286
+ 'FlipOrderPlaced',
1287
+ { IndexedOnly: false; Required: true }
1288
+ > & {
1289
+ /** Transaction receipt. */
1290
+ receipt: TransactionReceipt
1291
+ }
1292
+ >
1293
+ }
1294
+
1295
+ /**
1296
+ * Places a limit order on the orderbook.
1297
+ *
1298
+ * @example
1299
+ * ```ts
1300
+ * import { createClient, http, parseUnits } from 'viem'
1301
+ * import { privateKeyToAccount } from 'viem/accounts'
1302
+ * import { tempo } from 'tempo.ts/chains'
1303
+ * import { Actions, Tick } from 'tempo.ts/viem'
1304
+ *
1305
+ * const client = createClient({
1306
+ * account: privateKeyToAccount('0x...'),
1307
+ * chain: tempo,
1308
+ * transport: http(),
1309
+ * })
1310
+ *
1311
+ * const result = await Actions.dex.placeSync(client, {
1312
+ * amount: parseUnits('100', 6),
1313
+ * tick: Tick.fromPrice('0.99'),
1314
+ * token: '0x20c...11',
1315
+ * type: 'buy',
1316
+ * })
1317
+ * ```
1318
+ *
1319
+ * @param client - Client.
1320
+ * @param parameters - Parameters.
1321
+ * @returns The transaction receipt and event data.
1322
+ */
1323
+ export async function placeSync<
1324
+ chain extends Chain | undefined,
1325
+ account extends Account | undefined,
1326
+ >(
1327
+ client: Client<Transport, chain, account>,
1328
+ parameters: placeSync.Parameters<chain, account>,
1329
+ ): Promise<placeSync.ReturnValue> {
1330
+ const { throwOnReceiptRevert = true, ...rest } = parameters
1331
+ const receipt = await place.inner(writeContractSync, client, {
1332
+ ...rest,
1333
+ throwOnReceiptRevert,
1334
+ } as never)
1335
+ const { args } = place.extractEvent(receipt.logs)
1336
+ return {
1337
+ ...args,
1338
+ receipt,
1339
+ } as never
1340
+ }
1341
+
1342
+ export namespace placeSync {
1343
+ export type Parameters<
1344
+ chain extends Chain | undefined = Chain | undefined,
1345
+ account extends Account | undefined = Account | undefined,
1346
+ > = place.Parameters<chain, account>
1347
+
1348
+ export type Args = place.Args
1349
+
1350
+ export type ReturnValue = Compute<
1351
+ GetEventArgs<
1352
+ typeof Abis.stablecoinExchange,
1353
+ 'OrderPlaced',
1354
+ { IndexedOnly: false; Required: true }
1355
+ > & {
1356
+ /** Transaction receipt. */
1357
+ receipt: TransactionReceipt
1358
+ }
1359
+ >
1360
+ }
1361
+
1362
+ /**
1363
+ * Sells a specific amount of tokens.
1364
+ *
1365
+ * @example
1366
+ * ```ts
1367
+ * import { createClient, http, parseUnits } from 'viem'
1368
+ * import { privateKeyToAccount } from 'viem/accounts'
1369
+ * import { tempo } from 'tempo.ts/chains'
1370
+ * import { Actions } from 'tempo.ts/viem'
1371
+ *
1372
+ * const client = createClient({
1373
+ * account: privateKeyToAccount('0x...'),
1374
+ * chain: tempo,
1375
+ * transport: http(),
1376
+ * })
1377
+ *
1378
+ * const hash = await Actions.dex.sell(client, {
1379
+ * amountIn: parseUnits('100', 6),
1380
+ * minAmountOut: parseUnits('95', 6),
1381
+ * tokenIn: '0x20c...11',
1382
+ * tokenOut: '0x20c...20',
1383
+ * })
1384
+ * ```
1385
+ *
1386
+ * @param client - Client.
1387
+ * @param parameters - Parameters.
1388
+ * @returns The transaction hash.
1389
+ */
1390
+ export async function sell<
1391
+ chain extends Chain | undefined,
1392
+ account extends Account | undefined,
1393
+ >(
1394
+ client: Client<Transport, chain, account>,
1395
+ parameters: sell.Parameters<chain, account>,
1396
+ ): Promise<sell.ReturnValue> {
1397
+ return sell.inner(writeContract, client, parameters)
1398
+ }
1399
+
1400
+ export namespace sell {
1401
+ export type Parameters<
1402
+ chain extends Chain | undefined = Chain | undefined,
1403
+ account extends Account | undefined = Account | undefined,
1404
+ > = WriteParameters<chain, account> & Args
1405
+
1406
+ export type Args = {
1407
+ /** Amount of tokenIn to sell. */
1408
+ amountIn: bigint
1409
+ /** Minimum amount of tokenOut to receive. */
1410
+ minAmountOut: bigint
1411
+ /** Address of the token to sell. */
1412
+ tokenIn: Address
1413
+ /** Address of the token to receive. */
1414
+ tokenOut: Address
1415
+ }
1416
+
1417
+ export type ReturnValue = WriteContractReturnType
1418
+
1419
+ /** @internal */
1420
+ export async function inner<
1421
+ action extends typeof writeContract | typeof writeContractSync,
1422
+ chain extends Chain | undefined,
1423
+ account extends Account | undefined,
1424
+ >(
1425
+ action: action,
1426
+ client: Client<Transport, chain, account>,
1427
+ parameters: sell.Parameters<chain, account>,
1428
+ ): Promise<ReturnType<action>> {
1429
+ const { tokenIn, tokenOut, amountIn, minAmountOut, ...rest } = parameters
1430
+ const call = sell.call({ tokenIn, tokenOut, amountIn, minAmountOut })
1431
+ return (await action(client, {
1432
+ ...rest,
1433
+ ...call,
1434
+ } as never)) as never
1435
+ }
1436
+
1437
+ /**
1438
+ * Defines a call to the `swapExactAmountIn` function.
1439
+ *
1440
+ * Can be passed as a parameter to:
1441
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1442
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1443
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1444
+ *
1445
+ * @example
1446
+ * ```ts
1447
+ * import { createClient, http, parseUnits, walletActions } from 'viem'
1448
+ * import { tempo } from 'tempo.ts/chains'
1449
+ * import { Actions } from 'tempo.ts/viem'
1450
+ *
1451
+ * const client = createClient({
1452
+ * chain: tempo,
1453
+ * transport: http(),
1454
+ * }).extend(walletActions)
1455
+ *
1456
+ * const { result } = await client.sendCalls({
1457
+ * calls: [
1458
+ * Actions.dex.sell.call({
1459
+ * amountIn: parseUnits('100', 6),
1460
+ * minAmountOut: parseUnits('95', 6),
1461
+ * tokenIn: '0x20c0...beef',
1462
+ * tokenOut: '0x20c0...babe',
1463
+ * }),
1464
+ * ]
1465
+ * })
1466
+ * ```
1467
+ *
1468
+ * @param args - Arguments.
1469
+ * @returns The call.
1470
+ */
1471
+ export function call(args: Args) {
1472
+ const { tokenIn, tokenOut, amountIn, minAmountOut } = args
1473
+ return defineCall({
1474
+ address: Addresses.stablecoinExchange,
1475
+ abi: Abis.stablecoinExchange,
1476
+ functionName: 'swapExactAmountIn',
1477
+ args: [tokenIn, tokenOut, amountIn, minAmountOut],
1478
+ })
1479
+ }
1480
+ }
1481
+
1482
+ /**
1483
+ * Sells a specific amount of tokens.
1484
+ *
1485
+ * @example
1486
+ * ```ts
1487
+ * import { createClient, http, parseUnits } from 'viem'
1488
+ * import { privateKeyToAccount } from 'viem/accounts'
1489
+ * import { tempo } from 'tempo.ts/chains'
1490
+ * import { Actions } from 'tempo.ts/viem'
1491
+ *
1492
+ * const client = createClient({
1493
+ * account: privateKeyToAccount('0x...'),
1494
+ * chain: tempo,
1495
+ * transport: http(),
1496
+ * })
1497
+ *
1498
+ * const result = await Actions.dex.sellSync(client, {
1499
+ * amountIn: parseUnits('100', 6),
1500
+ * minAmountOut: parseUnits('95', 6),
1501
+ * tokenIn: '0x20c...11',
1502
+ * tokenOut: '0x20c...20',
1503
+ * })
1504
+ * ```
1505
+ *
1506
+ * @param client - Client.
1507
+ * @param parameters - Parameters.
1508
+ * @returns The transaction receipt.
1509
+ */
1510
+ export async function sellSync<
1511
+ chain extends Chain | undefined,
1512
+ account extends Account | undefined,
1513
+ >(
1514
+ client: Client<Transport, chain, account>,
1515
+ parameters: sellSync.Parameters<chain, account>,
1516
+ ): Promise<sellSync.ReturnValue> {
1517
+ const { throwOnReceiptRevert = true, ...rest } = parameters
1518
+ const receipt = await sell.inner(writeContractSync, client, {
1519
+ ...rest,
1520
+ throwOnReceiptRevert,
1521
+ } as never)
1522
+ return { receipt }
1523
+ }
1524
+
1525
+ export namespace sellSync {
1526
+ export type Parameters<
1527
+ chain extends Chain | undefined = Chain | undefined,
1528
+ account extends Account | undefined = Account | undefined,
1529
+ > = sell.Parameters<chain, account>
1530
+
1531
+ export type Args = sell.Args
1532
+
1533
+ export type ReturnValue = Compute<{
1534
+ /** Transaction receipt. */
1535
+ receipt: TransactionReceipt
1536
+ }>
1537
+ }
1538
+
1539
+ /**
1540
+ * Watches for flip order placed events.
1541
+ *
1542
+ * @example
1543
+ * ```ts
1544
+ * import { createClient, http } from 'viem'
1545
+ * import { tempo } from 'tempo.ts/chains'
1546
+ * import { Actions } from 'tempo.ts/viem'
1547
+ *
1548
+ * const client = createClient({
1549
+ * chain: tempo,
1550
+ * transport: http(),
1551
+ * })
1552
+ *
1553
+ * const unwatch = Actions.dex.watchFlipOrderPlaced(client, {
1554
+ * onFlipOrderPlaced: (args, log) => {
1555
+ * console.log('Flip order placed:', args)
1556
+ * },
1557
+ * })
1558
+ * ```
1559
+ *
1560
+ * @param client - Client.
1561
+ * @param parameters - Parameters.
1562
+ * @returns A function to unsubscribe from the event.
1563
+ */
1564
+ export function watchFlipOrderPlaced<
1565
+ chain extends Chain | undefined,
1566
+ account extends Account | undefined,
1567
+ >(
1568
+ client: Client<Transport, chain, account>,
1569
+ parameters: watchFlipOrderPlaced.Parameters,
1570
+ ) {
1571
+ const { onFlipOrderPlaced, maker, token, ...rest } = parameters
1572
+ return watchContractEvent(client, {
1573
+ ...rest,
1574
+ address: Addresses.stablecoinExchange,
1575
+ abi: Abis.stablecoinExchange,
1576
+ eventName: 'FlipOrderPlaced',
1577
+ args: {
1578
+ ...(maker !== undefined && { maker }),
1579
+ ...(token !== undefined && { token }),
1580
+ },
1581
+ onLogs: (logs) => {
1582
+ for (const log of logs) onFlipOrderPlaced(log.args, log)
1583
+ },
1584
+ strict: true,
1585
+ })
1586
+ }
1587
+
1588
+ export declare namespace watchFlipOrderPlaced {
1589
+ export type Args = GetEventArgs<
1590
+ typeof Abis.stablecoinExchange,
1591
+ 'FlipOrderPlaced',
1592
+ { IndexedOnly: false; Required: true }
1593
+ >
1594
+
1595
+ export type Log = viem_Log<
1596
+ bigint,
1597
+ number,
1598
+ false,
1599
+ ExtractAbiItem<typeof Abis.stablecoinExchange, 'FlipOrderPlaced'>,
1600
+ true
1601
+ >
1602
+
1603
+ export type Parameters = UnionOmit<
1604
+ WatchContractEventParameters<
1605
+ typeof Abis.stablecoinExchange,
1606
+ 'FlipOrderPlaced',
1607
+ true
1608
+ >,
1609
+ 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
1610
+ > & {
1611
+ /** Address of the maker to filter events. */
1612
+ maker?: Address | undefined
1613
+ /** Callback to invoke when a flip order is placed. */
1614
+ onFlipOrderPlaced: (args: Args, log: Log) => void
1615
+ /** Address of the token to filter events. */
1616
+ token?: Address | undefined
1617
+ }
1618
+ }
1619
+
1620
+ /**
1621
+ * Watches for order cancelled events.
1622
+ *
1623
+ * @example
1624
+ * ```ts
1625
+ * import { createClient, http } from 'viem'
1626
+ * import { tempo } from 'tempo.ts/chains'
1627
+ * import { Actions } from 'tempo.ts/viem'
1628
+ *
1629
+ * const client = createClient({
1630
+ * chain: tempo,
1631
+ * transport: http(),
1632
+ * })
1633
+ *
1634
+ * const unwatch = Actions.dex.watchOrderCancelled(client, {
1635
+ * onOrderCancelled: (args, log) => {
1636
+ * console.log('Order cancelled:', args)
1637
+ * },
1638
+ * })
1639
+ * ```
1640
+ *
1641
+ * @param client - Client.
1642
+ * @param parameters - Parameters.
1643
+ * @returns A function to unsubscribe from the event.
1644
+ */
1645
+ export function watchOrderCancelled<
1646
+ chain extends Chain | undefined,
1647
+ account extends Account | undefined,
1648
+ >(
1649
+ client: Client<Transport, chain, account>,
1650
+ parameters: watchOrderCancelled.Parameters,
1651
+ ) {
1652
+ const { onOrderCancelled, orderId, ...rest } = parameters
1653
+ return watchContractEvent(client, {
1654
+ ...rest,
1655
+ address: Addresses.stablecoinExchange,
1656
+ abi: Abis.stablecoinExchange,
1657
+ eventName: 'OrderCancelled',
1658
+ args: orderId !== undefined ? { orderId } : undefined,
1659
+ onLogs: (logs) => {
1660
+ for (const log of logs) onOrderCancelled(log.args, log)
1661
+ },
1662
+ strict: true,
1663
+ })
1664
+ }
1665
+
1666
+ export declare namespace watchOrderCancelled {
1667
+ export type Args = GetEventArgs<
1668
+ typeof Abis.stablecoinExchange,
1669
+ 'OrderCancelled',
1670
+ { IndexedOnly: false; Required: true }
1671
+ >
1672
+
1673
+ export type Log = viem_Log<
1674
+ bigint,
1675
+ number,
1676
+ false,
1677
+ ExtractAbiItem<typeof Abis.stablecoinExchange, 'OrderCancelled'>,
1678
+ true
1679
+ >
1680
+
1681
+ export type Parameters = UnionOmit<
1682
+ WatchContractEventParameters<
1683
+ typeof Abis.stablecoinExchange,
1684
+ 'OrderCancelled',
1685
+ true
1686
+ >,
1687
+ 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
1688
+ > & {
1689
+ /** Callback to invoke when an order is cancelled. */
1690
+ onOrderCancelled: (args: Args, log: Log) => void
1691
+ /** Order ID to filter events. */
1692
+ orderId?: bigint | undefined
1693
+ }
1694
+ }
1695
+
1696
+ /**
1697
+ * Watches for order filled events.
1698
+ *
1699
+ * @example
1700
+ * ```ts
1701
+ * import { createClient, http } from 'viem'
1702
+ * import { tempo } from 'tempo.ts/chains'
1703
+ * import { Actions } from 'tempo.ts/viem'
1704
+ *
1705
+ * const client = createClient({
1706
+ * chain: tempo,
1707
+ * transport: http(),
1708
+ * })
1709
+ *
1710
+ * const unwatch = Actions.dex.watchOrderFilled(client, {
1711
+ * onOrderFilled: (args, log) => {
1712
+ * console.log('Order filled:', args)
1713
+ * },
1714
+ * })
1715
+ * ```
1716
+ *
1717
+ * @param client - Client.
1718
+ * @param parameters - Parameters.
1719
+ * @returns A function to unsubscribe from the event.
1720
+ */
1721
+ export function watchOrderFilled<
1722
+ chain extends Chain | undefined,
1723
+ account extends Account | undefined,
1724
+ >(
1725
+ client: Client<Transport, chain, account>,
1726
+ parameters: watchOrderFilled.Parameters,
1727
+ ) {
1728
+ const { onOrderFilled, maker, taker, orderId, ...rest } = parameters
1729
+ return watchContractEvent(client, {
1730
+ ...rest,
1731
+ address: Addresses.stablecoinExchange,
1732
+ abi: Abis.stablecoinExchange,
1733
+ eventName: 'OrderFilled',
1734
+ args: {
1735
+ ...(orderId !== undefined && { orderId }),
1736
+ ...(maker !== undefined && { maker }),
1737
+ ...(taker !== undefined && { taker }),
1738
+ },
1739
+ onLogs: (logs) => {
1740
+ for (const log of logs) onOrderFilled(log.args, log)
1741
+ },
1742
+ strict: true,
1743
+ })
1744
+ }
1745
+
1746
+ export declare namespace watchOrderFilled {
1747
+ export type Args = GetEventArgs<
1748
+ typeof Abis.stablecoinExchange,
1749
+ 'OrderFilled',
1750
+ { IndexedOnly: false; Required: true }
1751
+ >
1752
+
1753
+ export type Log = viem_Log<
1754
+ bigint,
1755
+ number,
1756
+ false,
1757
+ ExtractAbiItem<typeof Abis.stablecoinExchange, 'OrderFilled'>,
1758
+ true
1759
+ >
1760
+
1761
+ export type Parameters = UnionOmit<
1762
+ WatchContractEventParameters<
1763
+ typeof Abis.stablecoinExchange,
1764
+ 'OrderFilled',
1765
+ true
1766
+ >,
1767
+ 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
1768
+ > & {
1769
+ /** Address of the maker to filter events. */
1770
+ maker?: Address | undefined
1771
+ /** Callback to invoke when an order is filled. */
1772
+ onOrderFilled: (args: Args, log: Log) => void
1773
+ /** Order ID to filter events. */
1774
+ orderId?: bigint | undefined
1775
+ /** Address of the taker to filter events. */
1776
+ taker?: Address | undefined
1777
+ }
1778
+ }
1779
+
1780
+ /**
1781
+ * Watches for order placed events.
1782
+ *
1783
+ * @example
1784
+ * ```ts
1785
+ * import { createClient, http } from 'viem'
1786
+ * import { tempo } from 'tempo.ts/chains'
1787
+ * import { Actions } from 'tempo.ts/viem'
1788
+ *
1789
+ * const client = createClient({
1790
+ * chain: tempo,
1791
+ * transport: http(),
1792
+ * })
1793
+ *
1794
+ * const unwatch = Actions.dex.watchOrderPlaced(client, {
1795
+ * onOrderPlaced: (args, log) => {
1796
+ * console.log('Order placed:', args)
1797
+ * },
1798
+ * })
1799
+ * ```
1800
+ *
1801
+ * @param client - Client.
1802
+ * @param parameters - Parameters.
1803
+ * @returns A function to unsubscribe from the event.
1804
+ */
1805
+ export function watchOrderPlaced<
1806
+ chain extends Chain | undefined,
1807
+ account extends Account | undefined,
1808
+ >(
1809
+ client: Client<Transport, chain, account>,
1810
+ parameters: watchOrderPlaced.Parameters,
1811
+ ) {
1812
+ const { onOrderPlaced, maker, token, ...rest } = parameters
1813
+ return watchContractEvent(client, {
1814
+ ...rest,
1815
+ address: Addresses.stablecoinExchange,
1816
+ abi: Abis.stablecoinExchange,
1817
+ eventName: 'OrderPlaced',
1818
+ args: {
1819
+ ...(maker !== undefined && { maker }),
1820
+ ...(token !== undefined && { token }),
1821
+ },
1822
+ onLogs: (logs) => {
1823
+ for (const log of logs) onOrderPlaced(log.args, log)
1824
+ },
1825
+ strict: true,
1826
+ })
1827
+ }
1828
+
1829
+ export declare namespace watchOrderPlaced {
1830
+ export type Args = GetEventArgs<
1831
+ typeof Abis.stablecoinExchange,
1832
+ 'OrderPlaced',
1833
+ { IndexedOnly: false; Required: true }
1834
+ >
1835
+
1836
+ export type Log = viem_Log<
1837
+ bigint,
1838
+ number,
1839
+ false,
1840
+ ExtractAbiItem<typeof Abis.stablecoinExchange, 'OrderPlaced'>,
1841
+ true
1842
+ >
1843
+
1844
+ export type Parameters = UnionOmit<
1845
+ WatchContractEventParameters<
1846
+ typeof Abis.stablecoinExchange,
1847
+ 'OrderPlaced',
1848
+ true
1849
+ >,
1850
+ 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
1851
+ > & {
1852
+ /** Address of the maker to filter events. */
1853
+ maker?: Address | undefined
1854
+ /** Callback to invoke when an order is placed. */
1855
+ onOrderPlaced: (args: Args, log: Log) => void
1856
+ /** Address of the token to filter events. */
1857
+ token?: Address | undefined
1858
+ }
1859
+ }
1860
+
1861
+ /**
1862
+ * Withdraws tokens from the DEX to the caller's wallet.
1863
+ *
1864
+ * @example
1865
+ * ```ts
1866
+ * import { createClient, http } from 'viem'
1867
+ * import { privateKeyToAccount } from 'viem/accounts'
1868
+ * import { tempo } from 'tempo.ts/chains'
1869
+ * import { Actions } from 'tempo.ts/viem'
1870
+ *
1871
+ * const client = createClient({
1872
+ * account: privateKeyToAccount('0x...'),
1873
+ * chain: tempo,
1874
+ * transport: http(),
1875
+ * })
1876
+ *
1877
+ * const hash = await Actions.dex.withdraw(client, {
1878
+ * amount: 100n,
1879
+ * token: '0x20c...11',
1880
+ * })
1881
+ * ```
1882
+ *
1883
+ * @param client - Client.
1884
+ * @param parameters - Parameters.
1885
+ * @returns The transaction hash.
1886
+ */
1887
+ export async function withdraw<
1888
+ chain extends Chain | undefined,
1889
+ account extends Account | undefined,
1890
+ >(
1891
+ client: Client<Transport, chain, account>,
1892
+ parameters: withdraw.Parameters<chain, account>,
1893
+ ): Promise<withdraw.ReturnValue> {
1894
+ return withdraw.inner(writeContract, client, parameters)
1895
+ }
1896
+
1897
+ export namespace withdraw {
1898
+ export type Parameters<
1899
+ chain extends Chain | undefined = Chain | undefined,
1900
+ account extends Account | undefined = Account | undefined,
1901
+ > = WriteParameters<chain, account> & Args
1902
+
1903
+ export type Args = {
1904
+ /** Amount to withdraw. */
1905
+ amount: bigint
1906
+ /** Address of the token to withdraw. */
1907
+ token: Address
1908
+ }
1909
+
1910
+ export type ReturnValue = WriteContractReturnType
1911
+
1912
+ /** @internal */
1913
+ export async function inner<
1914
+ action extends typeof writeContract | typeof writeContractSync,
1915
+ chain extends Chain | undefined,
1916
+ account extends Account | undefined,
1917
+ >(
1918
+ action: action,
1919
+ client: Client<Transport, chain, account>,
1920
+ parameters: withdraw.Parameters<chain, account>,
1921
+ ): Promise<ReturnType<action>> {
1922
+ const { token, amount, ...rest } = parameters
1923
+ const call = withdraw.call({ token, amount })
1924
+ return (await action(client, {
1925
+ ...rest,
1926
+ ...call,
1927
+ } as never)) as never
1928
+ }
1929
+
1930
+ /**
1931
+ * Defines a call to the `withdraw` function.
1932
+ *
1933
+ * Can be passed as a parameter to:
1934
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1935
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1936
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1937
+ *
1938
+ * @example
1939
+ * ```ts
1940
+ * import { createClient, http, parseUnits, walletActions } from 'viem'
1941
+ * import { tempo } from 'tempo.ts/chains'
1942
+ * import { Actions } from 'tempo.ts/viem'
1943
+ *
1944
+ * const client = createClient({
1945
+ * chain: tempo,
1946
+ * transport: http(),
1947
+ * }).extend(walletActions)
1948
+ *
1949
+ * const { result } = await client.sendCalls({
1950
+ * calls: [
1951
+ * Actions.dex.withdraw.call({
1952
+ * amount: parseUnits('100', 6),
1953
+ * token: '0x20c0...beef',
1954
+ * }),
1955
+ * ]
1956
+ * })
1957
+ * ```
1958
+ *
1959
+ * @param args - Arguments.
1960
+ * @returns The call.
1961
+ */
1962
+ export function call(args: Args) {
1963
+ const { token, amount } = args
1964
+ return defineCall({
1965
+ address: Addresses.stablecoinExchange,
1966
+ abi: Abis.stablecoinExchange,
1967
+ functionName: 'withdraw',
1968
+ args: [token, amount],
1969
+ })
1970
+ }
1971
+ }
1972
+
1973
+ /**
1974
+ * Withdraws tokens from the DEX to the caller's wallet.
1975
+ *
1976
+ * @example
1977
+ * ```ts
1978
+ * import { createClient, http } from 'viem'
1979
+ * import { privateKeyToAccount } from 'viem/accounts'
1980
+ * import { tempo } from 'tempo.ts/chains'
1981
+ * import { Actions } from 'tempo.ts/viem'
1982
+ *
1983
+ * const client = createClient({
1984
+ * account: privateKeyToAccount('0x...'),
1985
+ * chain: tempo,
1986
+ * transport: http(),
1987
+ * })
1988
+ *
1989
+ * const result = await Actions.dex.withdrawSync(client, {
1990
+ * amount: 100n,
1991
+ * token: '0x20c...11',
1992
+ * })
1993
+ * ```
1994
+ *
1995
+ * @param client - Client.
1996
+ * @param parameters - Parameters.
1997
+ * @returns The transaction receipt.
1998
+ */
1999
+ export async function withdrawSync<
2000
+ chain extends Chain | undefined,
2001
+ account extends Account | undefined,
2002
+ >(
2003
+ client: Client<Transport, chain, account>,
2004
+ parameters: withdrawSync.Parameters<chain, account>,
2005
+ ): Promise<withdrawSync.ReturnValue> {
2006
+ const { throwOnReceiptRevert = true, ...rest } = parameters
2007
+ const receipt = await withdraw.inner(writeContractSync, client, {
2008
+ ...rest,
2009
+ throwOnReceiptRevert,
2010
+ } as never)
2011
+ return { receipt }
2012
+ }
2013
+
2014
+ export namespace withdrawSync {
2015
+ export type Parameters<
2016
+ chain extends Chain | undefined = Chain | undefined,
2017
+ account extends Account | undefined = Account | undefined,
2018
+ > = withdraw.Parameters<chain, account>
2019
+
2020
+ export type Args = withdraw.Args
2021
+
2022
+ export type ReturnValue = Compute<{
2023
+ /** Transaction receipt. */
2024
+ receipt: TransactionReceipt
2025
+ }>
2026
+ }