tempo.ts 0.1.2 → 0.1.3

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 (125) hide show
  1. package/dist/chains.d.ts +1180 -0
  2. package/dist/chains.d.ts.map +1 -0
  3. package/dist/chains.js +30 -0
  4. package/dist/chains.js.map +1 -0
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +2 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/internal/types.d.ts +284 -0
  10. package/dist/internal/types.d.ts.map +1 -0
  11. package/dist/internal/types.js +2 -0
  12. package/dist/internal/types.js.map +1 -0
  13. package/dist/ox/SignatureEnvelope.d.ts +245 -0
  14. package/dist/ox/SignatureEnvelope.d.ts.map +1 -0
  15. package/dist/ox/SignatureEnvelope.js +437 -0
  16. package/dist/ox/SignatureEnvelope.js.map +1 -0
  17. package/dist/ox/TokenId.d.ts +25 -0
  18. package/dist/ox/TokenId.d.ts.map +1 -0
  19. package/dist/ox/TokenId.js +41 -0
  20. package/dist/ox/TokenId.js.map +1 -0
  21. package/dist/ox/TokenRole.d.ts +11 -0
  22. package/dist/ox/TokenRole.d.ts.map +1 -0
  23. package/dist/ox/TokenRole.js +22 -0
  24. package/dist/ox/TokenRole.js.map +1 -0
  25. package/dist/ox/Transaction.d.ts +198 -0
  26. package/dist/ox/Transaction.d.ts.map +1 -0
  27. package/dist/ox/Transaction.js +162 -0
  28. package/dist/ox/Transaction.js.map +1 -0
  29. package/dist/ox/TransactionEnvelopeAA.d.ts +461 -0
  30. package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -0
  31. package/dist/ox/TransactionEnvelopeAA.js +528 -0
  32. package/dist/ox/TransactionEnvelopeAA.js.map +1 -0
  33. package/dist/ox/TransactionRequest.d.ts +64 -0
  34. package/dist/ox/TransactionRequest.d.ts.map +1 -0
  35. package/dist/ox/TransactionRequest.js +75 -0
  36. package/dist/ox/TransactionRequest.js.map +1 -0
  37. package/dist/ox/index.d.ts +6 -0
  38. package/dist/ox/index.d.ts.map +1 -0
  39. package/dist/ox/index.js +6 -0
  40. package/dist/ox/index.js.map +1 -0
  41. package/dist/prool/Instance.d.ts +88 -0
  42. package/dist/prool/Instance.d.ts.map +1 -0
  43. package/dist/prool/Instance.js +96 -0
  44. package/dist/prool/Instance.js.map +1 -0
  45. package/dist/prool/index.d.ts +2 -0
  46. package/dist/prool/index.d.ts.map +1 -0
  47. package/dist/prool/index.js +2 -0
  48. package/dist/prool/index.js.map +1 -0
  49. package/dist/viem/Abis.d.ts +1885 -0
  50. package/dist/viem/Abis.d.ts.map +1 -0
  51. package/dist/viem/Abis.js +1174 -0
  52. package/dist/viem/Abis.js.map +1 -0
  53. package/dist/viem/Actions/amm.d.ts +2006 -0
  54. package/dist/viem/Actions/amm.d.ts.map +1 -0
  55. package/dist/viem/Actions/amm.js +900 -0
  56. package/dist/viem/Actions/amm.js.map +1 -0
  57. package/dist/viem/Actions/dex.d.ts +3279 -0
  58. package/dist/viem/Actions/dex.d.ts.map +1 -0
  59. package/dist/viem/Actions/dex.js +1357 -0
  60. package/dist/viem/Actions/dex.js.map +1 -0
  61. package/dist/viem/Actions/fee.d.ts +374 -0
  62. package/dist/viem/Actions/fee.d.ts.map +1 -0
  63. package/dist/viem/Actions/fee.js +235 -0
  64. package/dist/viem/Actions/fee.js.map +1 -0
  65. package/dist/viem/Actions/index.d.ts +6 -0
  66. package/dist/viem/Actions/index.d.ts.map +1 -0
  67. package/dist/viem/Actions/index.js +6 -0
  68. package/dist/viem/Actions/index.js.map +1 -0
  69. package/dist/viem/Actions/policy.d.ts +1672 -0
  70. package/dist/viem/Actions/policy.d.ts.map +1 -0
  71. package/dist/viem/Actions/policy.js +875 -0
  72. package/dist/viem/Actions/policy.js.map +1 -0
  73. package/dist/viem/Actions/token.d.ts +13714 -0
  74. package/dist/viem/Actions/token.d.ts.map +1 -0
  75. package/dist/viem/Actions/token.js +3058 -0
  76. package/dist/viem/Actions/token.js.map +1 -0
  77. package/dist/viem/Addresses.d.ts +9 -0
  78. package/dist/viem/Addresses.d.ts.map +1 -0
  79. package/dist/viem/Addresses.js +9 -0
  80. package/dist/viem/Addresses.js.map +1 -0
  81. package/dist/viem/Chain.d.ts +365 -0
  82. package/dist/viem/Chain.d.ts.map +1 -0
  83. package/dist/viem/Chain.js +22 -0
  84. package/dist/viem/Chain.js.map +1 -0
  85. package/dist/viem/Client.d.ts +27 -0
  86. package/dist/viem/Client.d.ts.map +1 -0
  87. package/dist/viem/Client.js +28 -0
  88. package/dist/viem/Client.js.map +1 -0
  89. package/dist/viem/Decorator.d.ts +2161 -0
  90. package/dist/viem/Decorator.d.ts.map +1 -0
  91. package/dist/viem/Decorator.js +122 -0
  92. package/dist/viem/Decorator.js.map +1 -0
  93. package/dist/viem/Formatters.d.ts +4 -0
  94. package/dist/viem/Formatters.d.ts.map +1 -0
  95. package/dist/viem/Formatters.js +76 -0
  96. package/dist/viem/Formatters.js.map +1 -0
  97. package/dist/viem/Tick.d.ts +111 -0
  98. package/dist/viem/Tick.d.ts.map +1 -0
  99. package/dist/viem/Tick.js +127 -0
  100. package/dist/viem/Tick.js.map +1 -0
  101. package/dist/viem/TokenIds.d.ts +3 -0
  102. package/dist/viem/TokenIds.d.ts.map +1 -0
  103. package/dist/viem/TokenIds.js +3 -0
  104. package/dist/viem/TokenIds.js.map +1 -0
  105. package/dist/viem/Transaction.d.ts +57 -0
  106. package/dist/viem/Transaction.d.ts.map +1 -0
  107. package/dist/viem/Transaction.js +137 -0
  108. package/dist/viem/Transaction.js.map +1 -0
  109. package/dist/viem/Transport.d.ts +16 -0
  110. package/dist/viem/Transport.d.ts.map +1 -0
  111. package/dist/viem/Transport.js +33 -0
  112. package/dist/viem/Transport.js.map +1 -0
  113. package/dist/viem/index.d.ts +14 -0
  114. package/dist/viem/index.d.ts.map +1 -0
  115. package/dist/viem/index.js +14 -0
  116. package/dist/viem/index.js.map +1 -0
  117. package/dist/viem/internal/types.d.ts +10 -0
  118. package/dist/viem/internal/types.d.ts.map +1 -0
  119. package/dist/viem/internal/types.js +2 -0
  120. package/dist/viem/internal/types.js.map +1 -0
  121. package/dist/viem/internal/utils.d.ts +8 -0
  122. package/dist/viem/internal/utils.d.ts.map +1 -0
  123. package/dist/viem/internal/utils.js +9 -0
  124. package/dist/viem/internal/utils.js.map +1 -0
  125. package/package.json +2 -2
@@ -0,0 +1,1357 @@
1
+ import { parseEventLogs, } from 'viem';
2
+ import { parseAccount } from 'viem/accounts';
3
+ import { readContract, watchContractEvent, writeContract, writeContractSync, } from 'viem/actions';
4
+ import * as Abis from '../Abis.js';
5
+ import * as Addresses from '../Addresses.js';
6
+ import { defineCall } from '../internal/utils.js';
7
+ /**
8
+ * Buys a specific amount of tokens.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { createClient, http, parseUnits } from 'viem'
13
+ * import { privateKeyToAccount } from 'viem/accounts'
14
+ * import { tempo } from 'tempo.ts/chains'
15
+ * import { Actions } from 'tempo.ts/viem'
16
+ *
17
+ * const client = createClient({
18
+ * account: privateKeyToAccount('0x...'),
19
+ * chain: tempo,
20
+ * transport: http(),
21
+ * })
22
+ *
23
+ * const hash = await Actions.dex.buy(client, {
24
+ * tokenIn: '0x20c...11',
25
+ * tokenOut: '0x20c...20',
26
+ * amountOut: parseUnits('100', 6),
27
+ * maxAmountIn: parseUnits('105', 6),
28
+ * })
29
+ * ```
30
+ *
31
+ * @param client - Client.
32
+ * @param parameters - Parameters.
33
+ * @returns The transaction hash.
34
+ */
35
+ export async function buy(client, parameters) {
36
+ return buy.inner(writeContract, client, parameters);
37
+ }
38
+ (function (buy) {
39
+ /** @internal */
40
+ async function inner(action, client, parameters) {
41
+ const { tokenIn, tokenOut, amountOut, maxAmountIn, ...rest } = parameters;
42
+ const call = buy.call({ tokenIn, tokenOut, amountOut, maxAmountIn });
43
+ return (await action(client, {
44
+ ...rest,
45
+ ...call,
46
+ }));
47
+ }
48
+ buy.inner = inner;
49
+ /**
50
+ * Defines a call to the `swapExactAmountOut` function.
51
+ *
52
+ * Can be passed as a parameter to:
53
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
54
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
55
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * import { createClient, http, parseUnits, walletActions } from 'viem'
60
+ * import { tempo } from 'tempo.ts/chains'
61
+ * import { Actions } from 'tempo.ts/viem'
62
+ *
63
+ * const client = createClient({
64
+ * chain: tempo,
65
+ * transport: http(),
66
+ * }).extend(walletActions)
67
+ *
68
+ * const { result } = await client.sendCalls({
69
+ * calls: [
70
+ * Actions.dex.buy.call({
71
+ * tokenIn: '0x20c0...beef',
72
+ * tokenOut: '0x20c0...babe',
73
+ * amountOut: parseUnits('100', 6),
74
+ * maxAmountIn: parseUnits('105', 6),
75
+ * }),
76
+ * ]
77
+ * })
78
+ * ```
79
+ *
80
+ * @param args - Arguments.
81
+ * @returns The call.
82
+ */
83
+ function call(args) {
84
+ const { tokenIn, tokenOut, amountOut, maxAmountIn } = args;
85
+ return defineCall({
86
+ address: Addresses.stablecoinExchange,
87
+ abi: Abis.stablecoinExchange,
88
+ functionName: 'swapExactAmountOut',
89
+ args: [tokenIn, tokenOut, amountOut, maxAmountIn],
90
+ });
91
+ }
92
+ buy.call = call;
93
+ })(buy || (buy = {}));
94
+ /**
95
+ * Buys a specific amount of tokens.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * import { createClient, http, parseUnits } from 'viem'
100
+ * import { privateKeyToAccount } from 'viem/accounts'
101
+ * import { tempo } from 'tempo.ts/chains'
102
+ * import { Actions } from 'tempo.ts/viem'
103
+ *
104
+ * const client = createClient({
105
+ * account: privateKeyToAccount('0x...'),
106
+ * chain: tempo,
107
+ * transport: http(),
108
+ * })
109
+ *
110
+ * const result = await Actions.dex.buySync(client, {
111
+ * tokenIn: '0x20c...11',
112
+ * tokenOut: '0x20c...20',
113
+ * amountOut: parseUnits('100', 6),
114
+ * maxAmountIn: parseUnits('105', 6),
115
+ * })
116
+ * ```
117
+ *
118
+ * @param client - Client.
119
+ * @param parameters - Parameters.
120
+ * @returns The transaction receipt.
121
+ */
122
+ export async function buySync(client, parameters) {
123
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
124
+ const receipt = await buy.inner(writeContractSync, client, {
125
+ ...rest,
126
+ throwOnReceiptRevert,
127
+ });
128
+ return { receipt };
129
+ }
130
+ /**
131
+ * Cancels an order from the orderbook.
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * import { createClient, http } from 'viem'
136
+ * import { privateKeyToAccount } from 'viem/accounts'
137
+ * import { tempo } from 'tempo.ts/chains'
138
+ * import { Actions } from 'tempo.ts/viem'
139
+ *
140
+ * const client = createClient({
141
+ * account: privateKeyToAccount('0x...'),
142
+ * chain: tempo,
143
+ * transport: http(),
144
+ * })
145
+ *
146
+ * const hash = await Actions.dex.cancel(client, {
147
+ * orderId: 123n,
148
+ * })
149
+ * ```
150
+ *
151
+ * @param client - Client.
152
+ * @param parameters - Parameters.
153
+ * @returns The transaction hash.
154
+ */
155
+ export async function cancel(client, parameters) {
156
+ return cancel.inner(writeContract, client, parameters);
157
+ }
158
+ (function (cancel) {
159
+ /** @internal */
160
+ async function inner(action, client, parameters) {
161
+ const { orderId, ...rest } = parameters;
162
+ const call = cancel.call({ orderId });
163
+ return (await action(client, {
164
+ ...rest,
165
+ ...call,
166
+ }));
167
+ }
168
+ cancel.inner = inner;
169
+ /**
170
+ * Defines a call to the `cancel` function.
171
+ *
172
+ * Can be passed as a parameter to:
173
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
174
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
175
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * import { createClient, http, walletActions } from 'viem'
180
+ * import { tempo } from 'tempo.ts/chains'
181
+ * import { Actions } from 'tempo.ts/viem'
182
+ *
183
+ * const client = createClient({
184
+ * chain: tempo,
185
+ * transport: http(),
186
+ * }).extend(walletActions)
187
+ *
188
+ * const { result } = await client.sendCalls({
189
+ * calls: [
190
+ * Actions.dex.cancel.call({
191
+ * orderId: 123n,
192
+ * }),
193
+ * ]
194
+ * })
195
+ * ```
196
+ *
197
+ * @param args - Arguments.
198
+ * @returns The call.
199
+ */
200
+ function call(args) {
201
+ const { orderId } = args;
202
+ return defineCall({
203
+ address: Addresses.stablecoinExchange,
204
+ abi: Abis.stablecoinExchange,
205
+ functionName: 'cancel',
206
+ args: [orderId],
207
+ });
208
+ }
209
+ cancel.call = call;
210
+ /**
211
+ * Extracts the `OrderCancelled` event from logs.
212
+ *
213
+ * @param logs - The logs.
214
+ * @returns The `OrderCancelled` event.
215
+ */
216
+ function extractEvent(logs) {
217
+ const [log] = parseEventLogs({
218
+ abi: Abis.stablecoinExchange,
219
+ logs,
220
+ eventName: 'OrderCancelled',
221
+ strict: true,
222
+ });
223
+ if (!log)
224
+ throw new Error('`OrderCancelled` event not found.');
225
+ return log;
226
+ }
227
+ cancel.extractEvent = extractEvent;
228
+ })(cancel || (cancel = {}));
229
+ /**
230
+ * Cancels an order from the orderbook.
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * import { createClient, http } from 'viem'
235
+ * import { privateKeyToAccount } from 'viem/accounts'
236
+ * import { tempo } from 'tempo.ts/chains'
237
+ * import { Actions } from 'tempo.ts/viem'
238
+ *
239
+ * const client = createClient({
240
+ * account: privateKeyToAccount('0x...'),
241
+ * chain: tempo,
242
+ * transport: http(),
243
+ * })
244
+ *
245
+ * const result = await Actions.dex.cancelSync(client, {
246
+ * orderId: 123n,
247
+ * })
248
+ * ```
249
+ *
250
+ * @param client - Client.
251
+ * @param parameters - Parameters.
252
+ * @returns The transaction receipt and event data.
253
+ */
254
+ export async function cancelSync(client, parameters) {
255
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
256
+ const receipt = await cancel.inner(writeContractSync, client, {
257
+ ...rest,
258
+ throwOnReceiptRevert,
259
+ });
260
+ const { args } = cancel.extractEvent(receipt.logs);
261
+ return {
262
+ ...args,
263
+ receipt,
264
+ };
265
+ }
266
+ /**
267
+ * Creates a new trading pair on the DEX.
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * import { createClient, http } from 'viem'
272
+ * import { privateKeyToAccount } from 'viem/accounts'
273
+ * import { tempo } from 'tempo.ts/chains'
274
+ * import { Actions } from 'tempo.ts/viem'
275
+ *
276
+ * const client = createClient({
277
+ * account: privateKeyToAccount('0x...'),
278
+ * chain: tempo,
279
+ * transport: http(),
280
+ * })
281
+ *
282
+ * const hash = await Actions.dex.createPair(client, {
283
+ * base: '0x20c...11',
284
+ * })
285
+ * ```
286
+ *
287
+ * @param client - Client.
288
+ * @param parameters - Parameters.
289
+ * @returns The transaction hash.
290
+ */
291
+ export async function createPair(client, parameters) {
292
+ return createPair.inner(writeContract, client, parameters);
293
+ }
294
+ (function (createPair) {
295
+ /** @internal */
296
+ async function inner(action, client, parameters) {
297
+ const { base, ...rest } = parameters;
298
+ const call = createPair.call({ base });
299
+ return (await action(client, {
300
+ ...rest,
301
+ ...call,
302
+ }));
303
+ }
304
+ createPair.inner = inner;
305
+ /**
306
+ * Defines a call to the `createPair` function.
307
+ *
308
+ * Can be passed as a parameter to:
309
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
310
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
311
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
312
+ *
313
+ * @example
314
+ * ```ts
315
+ * import { createClient, http, walletActions } from 'viem'
316
+ * import { tempo } from 'tempo.ts/chains'
317
+ * import { Actions } from 'tempo.ts/viem'
318
+ *
319
+ * const client = createClient({
320
+ * chain: tempo,
321
+ * transport: http(),
322
+ * }).extend(walletActions)
323
+ *
324
+ * const { result } = await client.sendCalls({
325
+ * calls: [
326
+ * Actions.dex.createPair.call({
327
+ * base: '0x20c0...beef',
328
+ * }),
329
+ * ]
330
+ * })
331
+ * ```
332
+ *
333
+ * @param args - Arguments.
334
+ * @returns The call.
335
+ */
336
+ function call(args) {
337
+ const { base } = args;
338
+ return defineCall({
339
+ address: Addresses.stablecoinExchange,
340
+ abi: Abis.stablecoinExchange,
341
+ functionName: 'createPair',
342
+ args: [base],
343
+ });
344
+ }
345
+ createPair.call = call;
346
+ /**
347
+ * Extracts the `PairCreated` event from logs.
348
+ *
349
+ * @param logs - The logs.
350
+ * @returns The `PairCreated` event.
351
+ */
352
+ function extractEvent(logs) {
353
+ const [log] = parseEventLogs({
354
+ abi: Abis.stablecoinExchange,
355
+ logs,
356
+ eventName: 'PairCreated',
357
+ strict: true,
358
+ });
359
+ if (!log)
360
+ throw new Error('`PairCreated` event not found.');
361
+ return log;
362
+ }
363
+ createPair.extractEvent = extractEvent;
364
+ })(createPair || (createPair = {}));
365
+ /**
366
+ * Creates a new trading pair on the DEX.
367
+ *
368
+ * @example
369
+ * ```ts
370
+ * import { createClient, http } from 'viem'
371
+ * import { privateKeyToAccount } from 'viem/accounts'
372
+ * import { tempo } from 'tempo.ts/chains'
373
+ * import { Actions } from 'tempo.ts/viem'
374
+ *
375
+ * const client = createClient({
376
+ * account: privateKeyToAccount('0x...'),
377
+ * chain: tempo,
378
+ * transport: http(),
379
+ * })
380
+ *
381
+ * const result = await Actions.dex.createPairSync(client, {
382
+ * base: '0x20c...11',
383
+ * })
384
+ * ```
385
+ *
386
+ * @param client - Client.
387
+ * @param parameters - Parameters.
388
+ * @returns The transaction receipt and event data.
389
+ */
390
+ export async function createPairSync(client, parameters) {
391
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
392
+ const receipt = await createPair.inner(writeContractSync, client, {
393
+ ...rest,
394
+ throwOnReceiptRevert,
395
+ });
396
+ const { args } = createPair.extractEvent(receipt.logs);
397
+ return {
398
+ ...args,
399
+ receipt,
400
+ };
401
+ }
402
+ /**
403
+ * Gets a user's token balance on the DEX.
404
+ *
405
+ * @example
406
+ * ```ts
407
+ * import { createClient, http } from 'viem'
408
+ * import { tempo } from 'tempo.ts/chains'
409
+ * import { Actions } from 'tempo.ts/viem'
410
+ *
411
+ * const client = createClient({
412
+ * chain: tempo,
413
+ * transport: http(),
414
+ * })
415
+ *
416
+ * const balance = await Actions.dex.getBalance(client, {
417
+ * account: '0x...',
418
+ * token: '0x20c...11',
419
+ * })
420
+ * ```
421
+ *
422
+ * @param client - Client.
423
+ * @param parameters - Parameters.
424
+ * @returns The user's token balance on the DEX.
425
+ */
426
+ export async function getBalance(client, parameters) {
427
+ const { account: acc = client.account, token, ...rest } = parameters;
428
+ const address = acc ? parseAccount(acc).address : undefined;
429
+ if (!address)
430
+ throw new Error('account is required.');
431
+ return readContract(client, {
432
+ ...rest,
433
+ ...getBalance.call({ account: address, token }),
434
+ });
435
+ }
436
+ (function (getBalance) {
437
+ /**
438
+ * Defines a call to the `balanceOf` function.
439
+ *
440
+ * @param args - Arguments.
441
+ * @returns The call.
442
+ */
443
+ function call(args) {
444
+ const { account, token } = args;
445
+ return defineCall({
446
+ address: Addresses.stablecoinExchange,
447
+ abi: Abis.stablecoinExchange,
448
+ args: [account, token],
449
+ functionName: 'balanceOf',
450
+ });
451
+ }
452
+ getBalance.call = call;
453
+ })(getBalance || (getBalance = {}));
454
+ /**
455
+ * Gets the quote for buying a specific amount of tokens.
456
+ *
457
+ * @example
458
+ * ```ts
459
+ * import { createClient, http, parseUnits } from 'viem'
460
+ * import { tempo } from 'tempo.ts/chains'
461
+ * import { Actions } from 'tempo.ts/viem'
462
+ *
463
+ * const client = createClient({
464
+ * chain: tempo,
465
+ * transport: http(),
466
+ * })
467
+ *
468
+ * const amountIn = await Actions.dex.getBuyQuote(client, {
469
+ * amountOut: parseUnits('100', 6),
470
+ * tokenIn: '0x20c...11',
471
+ * tokenOut: '0x20c...20',
472
+ * })
473
+ * ```
474
+ *
475
+ * @param client - Client.
476
+ * @param parameters - Parameters.
477
+ * @returns The amount of tokenIn needed to buy the specified amountOut.
478
+ */
479
+ export async function getBuyQuote(client, parameters) {
480
+ const { tokenIn, tokenOut, amountOut, ...rest } = parameters;
481
+ return readContract(client, {
482
+ ...rest,
483
+ ...getBuyQuote.call({ tokenIn, tokenOut, amountOut }),
484
+ });
485
+ }
486
+ (function (getBuyQuote) {
487
+ /**
488
+ * Defines a call to the `quoteSwapExactAmountOut` function.
489
+ *
490
+ * @param args - Arguments.
491
+ * @returns The call.
492
+ */
493
+ function call(args) {
494
+ const { tokenIn, tokenOut, amountOut } = args;
495
+ return defineCall({
496
+ address: Addresses.stablecoinExchange,
497
+ abi: Abis.stablecoinExchange,
498
+ args: [tokenIn, tokenOut, amountOut],
499
+ functionName: 'quoteSwapExactAmountOut',
500
+ });
501
+ }
502
+ getBuyQuote.call = call;
503
+ })(getBuyQuote || (getBuyQuote = {}));
504
+ /**
505
+ * Gets an order's details from the orderbook.
506
+ *
507
+ * @example
508
+ * ```ts
509
+ * import { createClient, http } from 'viem'
510
+ * import { tempo } from 'tempo.ts/chains'
511
+ * import { Actions } from 'tempo.ts/viem'
512
+ *
513
+ * const client = createClient({
514
+ * chain: tempo,
515
+ * transport: http(),
516
+ * })
517
+ *
518
+ * const order = await Actions.dex.getOrder(client, {
519
+ * orderId: 123n,
520
+ * })
521
+ * ```
522
+ *
523
+ * @param client - Client.
524
+ * @param parameters - Parameters.
525
+ * @returns The order details.
526
+ */
527
+ export async function getOrder(client, parameters) {
528
+ const { orderId, ...rest } = parameters;
529
+ return readContract(client, {
530
+ ...rest,
531
+ ...getOrder.call({ orderId }),
532
+ });
533
+ }
534
+ (function (getOrder) {
535
+ /**
536
+ * Defines a call to the `getOrder` function.
537
+ *
538
+ * @param args - Arguments.
539
+ * @returns The call.
540
+ */
541
+ function call(args) {
542
+ const { orderId } = args;
543
+ return defineCall({
544
+ address: Addresses.stablecoinExchange,
545
+ abi: Abis.stablecoinExchange,
546
+ args: [orderId],
547
+ functionName: 'getOrder',
548
+ });
549
+ }
550
+ getOrder.call = call;
551
+ })(getOrder || (getOrder = {}));
552
+ /**
553
+ * Gets the price level information at a specific tick.
554
+ *
555
+ * @example
556
+ * ```ts
557
+ * import { createClient, http } from 'viem'
558
+ * import { tempo } from 'tempo.ts/chains'
559
+ * import { Actions, Tick } from 'tempo.ts/viem'
560
+ *
561
+ * const client = createClient({
562
+ * chain: tempo,
563
+ * transport: http(),
564
+ * })
565
+ *
566
+ * const level = await Actions.dex.getPriceLevel(client, {
567
+ * base: '0x20c...11',
568
+ * tick: Tick.fromPrice('1.001'),
569
+ * isBid: true,
570
+ * })
571
+ * ```
572
+ *
573
+ * @param client - Client.
574
+ * @param parameters - Parameters.
575
+ * @returns The price level information.
576
+ */
577
+ export async function getPriceLevel(client, parameters) {
578
+ const { base, tick, isBid, ...rest } = parameters;
579
+ return readContract(client, {
580
+ ...rest,
581
+ ...getPriceLevel.call({ base, tick, isBid }),
582
+ });
583
+ }
584
+ (function (getPriceLevel) {
585
+ /**
586
+ * Defines a call to the `getPriceLevel` function.
587
+ *
588
+ * @param args - Arguments.
589
+ * @returns The call.
590
+ */
591
+ function call(args) {
592
+ const { base, tick, isBid } = args;
593
+ return defineCall({
594
+ address: Addresses.stablecoinExchange,
595
+ abi: Abis.stablecoinExchange,
596
+ args: [base, tick, isBid],
597
+ functionName: 'getPriceLevel',
598
+ });
599
+ }
600
+ getPriceLevel.call = call;
601
+ })(getPriceLevel || (getPriceLevel = {}));
602
+ /**
603
+ * Gets the quote for selling a specific amount of tokens.
604
+ *
605
+ * @example
606
+ * ```ts
607
+ * import { createClient, http, parseUnits } from 'viem'
608
+ * import { tempo } from 'tempo.ts/chains'
609
+ * import { Actions } from 'tempo.ts/viem'
610
+ *
611
+ * const client = createClient({
612
+ * chain: tempo,
613
+ * transport: http(),
614
+ * })
615
+ *
616
+ * const amountOut = await Actions.dex.getSellQuote(client, {
617
+ * amountIn: parseUnits('100', 6),
618
+ * tokenIn: '0x20c...11',
619
+ * tokenOut: '0x20c...20',
620
+ * })
621
+ * ```
622
+ *
623
+ * @param client - Client.
624
+ * @param parameters - Parameters.
625
+ * @returns The amount of tokenOut received for selling the specified amountIn.
626
+ */
627
+ export async function getSellQuote(client, parameters) {
628
+ const { tokenIn, tokenOut, amountIn, ...rest } = parameters;
629
+ return readContract(client, {
630
+ ...rest,
631
+ ...getSellQuote.call({ tokenIn, tokenOut, amountIn }),
632
+ });
633
+ }
634
+ (function (getSellQuote) {
635
+ /**
636
+ * Defines a call to the `quoteSwapExactAmountIn` function.
637
+ *
638
+ * @param args - Arguments.
639
+ * @returns The call.
640
+ */
641
+ function call(args) {
642
+ const { tokenIn, tokenOut, amountIn } = args;
643
+ return defineCall({
644
+ address: Addresses.stablecoinExchange,
645
+ abi: Abis.stablecoinExchange,
646
+ args: [tokenIn, tokenOut, amountIn],
647
+ functionName: 'quoteSwapExactAmountIn',
648
+ });
649
+ }
650
+ getSellQuote.call = call;
651
+ })(getSellQuote || (getSellQuote = {}));
652
+ /**
653
+ * Places a limit order on the orderbook.
654
+ *
655
+ * @example
656
+ * ```ts
657
+ * import { createClient, http, parseUnits } from 'viem'
658
+ * import { privateKeyToAccount } from 'viem/accounts'
659
+ * import { tempo } from 'tempo.ts/chains'
660
+ * import { Actions, Tick } from 'tempo.ts/viem'
661
+ *
662
+ * const client = createClient({
663
+ * account: privateKeyToAccount('0x...'),
664
+ * chain: tempo,
665
+ * transport: http(),
666
+ * })
667
+ *
668
+ * const hash = await Actions.dex.place(client, {
669
+ * amount: parseUnits('100', 6),
670
+ * tick: Tick.fromPrice('0.99'),
671
+ * token: '0x20c...11',
672
+ * type: 'buy',
673
+ * })
674
+ * ```
675
+ *
676
+ * @param client - Client.
677
+ * @param parameters - Parameters.
678
+ * @returns The transaction hash.
679
+ */
680
+ export async function place(client, parameters) {
681
+ return place.inner(writeContract, client, parameters);
682
+ }
683
+ (function (place) {
684
+ /** @internal */
685
+ async function inner(action, client, parameters) {
686
+ const { amount, token, type, tick, ...rest } = parameters;
687
+ const call = place.call({ amount, token, type, tick });
688
+ return (await action(client, {
689
+ ...rest,
690
+ ...call,
691
+ }));
692
+ }
693
+ place.inner = inner;
694
+ /**
695
+ * Defines a call to the `place` function.
696
+ *
697
+ * Can be passed as a parameter to:
698
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
699
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
700
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
701
+ *
702
+ * @example
703
+ * ```ts
704
+ * import { createClient, http, parseUnits, walletActions } from 'viem'
705
+ * import { tempo } from 'tempo.ts/chains'
706
+ * import { Actions, Tick } from 'tempo.ts/viem'
707
+ *
708
+ * const client = createClient({
709
+ * chain: tempo,
710
+ * transport: http(),
711
+ * }).extend(walletActions)
712
+ *
713
+ * const { result } = await client.sendCalls({
714
+ * calls: [
715
+ * Actions.dex.place.call({
716
+ * amount: parseUnits('100', 6),
717
+ * tick: Tick.fromPrice('0.99'),
718
+ * token: '0x20c0...beef',
719
+ * type: 'buy',
720
+ * }),
721
+ * ]
722
+ * })
723
+ * ```
724
+ *
725
+ * @param args - Arguments.
726
+ * @returns The call.
727
+ */
728
+ function call(args) {
729
+ const { token, amount, type, tick } = args;
730
+ const isBid = type === 'buy';
731
+ return defineCall({
732
+ address: Addresses.stablecoinExchange,
733
+ abi: Abis.stablecoinExchange,
734
+ functionName: 'place',
735
+ args: [token, amount, isBid, tick],
736
+ });
737
+ }
738
+ place.call = call;
739
+ /**
740
+ * Extracts the `OrderPlaced` event from logs.
741
+ *
742
+ * @param logs - The logs.
743
+ * @returns The `OrderPlaced` event.
744
+ */
745
+ function extractEvent(logs) {
746
+ const [log] = parseEventLogs({
747
+ abi: Abis.stablecoinExchange,
748
+ logs,
749
+ eventName: 'OrderPlaced',
750
+ strict: true,
751
+ });
752
+ if (!log)
753
+ throw new Error('`OrderPlaced` event not found.');
754
+ return log;
755
+ }
756
+ place.extractEvent = extractEvent;
757
+ })(place || (place = {}));
758
+ /**
759
+ * Places a flip order that automatically flips when filled.
760
+ *
761
+ * @example
762
+ * ```ts
763
+ * import { createClient, http, parseUnits } from 'viem'
764
+ * import { privateKeyToAccount } from 'viem/accounts'
765
+ * import { tempo } from 'tempo.ts/chains'
766
+ * import { Actions, Tick } from 'tempo.ts/viem'
767
+ *
768
+ * const client = createClient({
769
+ * account: privateKeyToAccount('0x...'),
770
+ * chain: tempo,
771
+ * transport: http(),
772
+ * })
773
+ *
774
+ * const hash = await Actions.dex.placeFlip(client, {
775
+ * amount: parseUnits('100', 6),
776
+ * flipTick: Tick.fromPrice('1.01'),
777
+ * tick: Tick.fromPrice('0.99'),
778
+ * token: '0x20c...11',
779
+ * type: 'buy',
780
+ * })
781
+ * ```
782
+ *
783
+ * @param client - Client.
784
+ * @param parameters - Parameters.
785
+ * @returns The transaction hash.
786
+ */
787
+ export async function placeFlip(client, parameters) {
788
+ return placeFlip.inner(writeContract, client, parameters);
789
+ }
790
+ (function (placeFlip) {
791
+ /** @internal */
792
+ async function inner(action, client, parameters) {
793
+ const { amount, flipTick, tick, token, type, ...rest } = parameters;
794
+ const call = placeFlip.call({ amount, flipTick, tick, token, type });
795
+ return (await action(client, {
796
+ ...rest,
797
+ ...call,
798
+ }));
799
+ }
800
+ placeFlip.inner = inner;
801
+ /**
802
+ * Defines a call to the `placeFlip` function.
803
+ *
804
+ * Can be passed as a parameter to:
805
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
806
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
807
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
808
+ *
809
+ * @example
810
+ * ```ts
811
+ * import { createClient, http, parseUnits, walletActions } from 'viem'
812
+ * import { tempo } from 'tempo.ts/chains'
813
+ * import { Actions, Tick } from 'tempo.ts/viem'
814
+ *
815
+ * const client = createClient({
816
+ * chain: tempo,
817
+ * transport: http(),
818
+ * }).extend(walletActions)
819
+ *
820
+ * const { result } = await client.sendCalls({
821
+ * calls: [
822
+ * Actions.dex.placeFlip.call({
823
+ * amount: parseUnits('100', 6),
824
+ * flipTick: Tick.fromPrice('1.01'),
825
+ * tick: Tick.fromPrice('0.99'),
826
+ * token: '0x20c0...beef',
827
+ * type: 'buy',
828
+ * }),
829
+ * ]
830
+ * })
831
+ * ```
832
+ *
833
+ * @param args - Arguments.
834
+ * @returns The call.
835
+ */
836
+ function call(args) {
837
+ const { token, amount, type, tick, flipTick } = args;
838
+ const isBid = type === 'buy';
839
+ return defineCall({
840
+ address: Addresses.stablecoinExchange,
841
+ abi: Abis.stablecoinExchange,
842
+ functionName: 'placeFlip',
843
+ args: [token, amount, isBid, tick, flipTick],
844
+ });
845
+ }
846
+ placeFlip.call = call;
847
+ /**
848
+ * Extracts the `FlipOrderPlaced` event from logs.
849
+ *
850
+ * @param logs - The logs.
851
+ * @returns The `FlipOrderPlaced` event.
852
+ */
853
+ function extractEvent(logs) {
854
+ const [log] = parseEventLogs({
855
+ abi: Abis.stablecoinExchange,
856
+ logs,
857
+ eventName: 'FlipOrderPlaced',
858
+ strict: true,
859
+ });
860
+ if (!log)
861
+ throw new Error('`FlipOrderPlaced` event not found.');
862
+ return log;
863
+ }
864
+ placeFlip.extractEvent = extractEvent;
865
+ })(placeFlip || (placeFlip = {}));
866
+ /**
867
+ * Places a flip order that automatically flips when filled.
868
+ *
869
+ * @example
870
+ * ```ts
871
+ * import { createClient, http, parseUnits } from 'viem'
872
+ * import { privateKeyToAccount } from 'viem/accounts'
873
+ * import { tempo } from 'tempo.ts/chains'
874
+ * import { Actions, Tick } from 'tempo.ts/viem'
875
+ *
876
+ * const client = createClient({
877
+ * account: privateKeyToAccount('0x...'),
878
+ * chain: tempo,
879
+ * transport: http(),
880
+ * })
881
+ *
882
+ * const result = await Actions.dex.placeFlipSync(client, {
883
+ * amount: parseUnits('100', 6),
884
+ * flipTick: Tick.fromPrice('1.01'),
885
+ * tick: Tick.fromPrice('0.99'),
886
+ * token: '0x20c...11',
887
+ * type: 'buy',
888
+ * })
889
+ * ```
890
+ *
891
+ * @param client - Client.
892
+ * @param parameters - Parameters.
893
+ * @returns The transaction receipt and event data.
894
+ */
895
+ export async function placeFlipSync(client, parameters) {
896
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
897
+ const receipt = await placeFlip.inner(writeContractSync, client, {
898
+ ...rest,
899
+ throwOnReceiptRevert,
900
+ });
901
+ const { args } = placeFlip.extractEvent(receipt.logs);
902
+ return {
903
+ ...args,
904
+ receipt,
905
+ };
906
+ }
907
+ /**
908
+ * Places a limit order on the orderbook.
909
+ *
910
+ * @example
911
+ * ```ts
912
+ * import { createClient, http, parseUnits } from 'viem'
913
+ * import { privateKeyToAccount } from 'viem/accounts'
914
+ * import { tempo } from 'tempo.ts/chains'
915
+ * import { Actions, Tick } from 'tempo.ts/viem'
916
+ *
917
+ * const client = createClient({
918
+ * account: privateKeyToAccount('0x...'),
919
+ * chain: tempo,
920
+ * transport: http(),
921
+ * })
922
+ *
923
+ * const result = await Actions.dex.placeSync(client, {
924
+ * amount: parseUnits('100', 6),
925
+ * tick: Tick.fromPrice('0.99'),
926
+ * token: '0x20c...11',
927
+ * type: 'buy',
928
+ * })
929
+ * ```
930
+ *
931
+ * @param client - Client.
932
+ * @param parameters - Parameters.
933
+ * @returns The transaction receipt and event data.
934
+ */
935
+ export async function placeSync(client, parameters) {
936
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
937
+ const receipt = await place.inner(writeContractSync, client, {
938
+ ...rest,
939
+ throwOnReceiptRevert,
940
+ });
941
+ const { args } = place.extractEvent(receipt.logs);
942
+ return {
943
+ ...args,
944
+ receipt,
945
+ };
946
+ }
947
+ /**
948
+ * Sells a specific amount of tokens.
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 } 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.sell(client, {
964
+ * amountIn: parseUnits('100', 6),
965
+ * minAmountOut: parseUnits('95', 6),
966
+ * tokenIn: '0x20c...11',
967
+ * tokenOut: '0x20c...20',
968
+ * })
969
+ * ```
970
+ *
971
+ * @param client - Client.
972
+ * @param parameters - Parameters.
973
+ * @returns The transaction hash.
974
+ */
975
+ export async function sell(client, parameters) {
976
+ return sell.inner(writeContract, client, parameters);
977
+ }
978
+ (function (sell) {
979
+ /** @internal */
980
+ async function inner(action, client, parameters) {
981
+ const { tokenIn, tokenOut, amountIn, minAmountOut, ...rest } = parameters;
982
+ const call = sell.call({ tokenIn, tokenOut, amountIn, minAmountOut });
983
+ return (await action(client, {
984
+ ...rest,
985
+ ...call,
986
+ }));
987
+ }
988
+ sell.inner = inner;
989
+ /**
990
+ * Defines a call to the `swapExactAmountIn` function.
991
+ *
992
+ * Can be passed as a parameter to:
993
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
994
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
995
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
996
+ *
997
+ * @example
998
+ * ```ts
999
+ * import { createClient, http, parseUnits, walletActions } from 'viem'
1000
+ * import { tempo } from 'tempo.ts/chains'
1001
+ * import { Actions } from 'tempo.ts/viem'
1002
+ *
1003
+ * const client = createClient({
1004
+ * chain: tempo,
1005
+ * transport: http(),
1006
+ * }).extend(walletActions)
1007
+ *
1008
+ * const { result } = await client.sendCalls({
1009
+ * calls: [
1010
+ * Actions.dex.sell.call({
1011
+ * amountIn: parseUnits('100', 6),
1012
+ * minAmountOut: parseUnits('95', 6),
1013
+ * tokenIn: '0x20c0...beef',
1014
+ * tokenOut: '0x20c0...babe',
1015
+ * }),
1016
+ * ]
1017
+ * })
1018
+ * ```
1019
+ *
1020
+ * @param args - Arguments.
1021
+ * @returns The call.
1022
+ */
1023
+ function call(args) {
1024
+ const { tokenIn, tokenOut, amountIn, minAmountOut } = args;
1025
+ return defineCall({
1026
+ address: Addresses.stablecoinExchange,
1027
+ abi: Abis.stablecoinExchange,
1028
+ functionName: 'swapExactAmountIn',
1029
+ args: [tokenIn, tokenOut, amountIn, minAmountOut],
1030
+ });
1031
+ }
1032
+ sell.call = call;
1033
+ })(sell || (sell = {}));
1034
+ /**
1035
+ * Sells a specific amount of tokens.
1036
+ *
1037
+ * @example
1038
+ * ```ts
1039
+ * import { createClient, http, parseUnits } from 'viem'
1040
+ * import { privateKeyToAccount } from 'viem/accounts'
1041
+ * import { tempo } from 'tempo.ts/chains'
1042
+ * import { Actions } from 'tempo.ts/viem'
1043
+ *
1044
+ * const client = createClient({
1045
+ * account: privateKeyToAccount('0x...'),
1046
+ * chain: tempo,
1047
+ * transport: http(),
1048
+ * })
1049
+ *
1050
+ * const result = await Actions.dex.sellSync(client, {
1051
+ * amountIn: parseUnits('100', 6),
1052
+ * minAmountOut: parseUnits('95', 6),
1053
+ * tokenIn: '0x20c...11',
1054
+ * tokenOut: '0x20c...20',
1055
+ * })
1056
+ * ```
1057
+ *
1058
+ * @param client - Client.
1059
+ * @param parameters - Parameters.
1060
+ * @returns The transaction receipt.
1061
+ */
1062
+ export async function sellSync(client, parameters) {
1063
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
1064
+ const receipt = await sell.inner(writeContractSync, client, {
1065
+ ...rest,
1066
+ throwOnReceiptRevert,
1067
+ });
1068
+ return { receipt };
1069
+ }
1070
+ /**
1071
+ * Watches for flip order placed events.
1072
+ *
1073
+ * @example
1074
+ * ```ts
1075
+ * import { createClient, http } from 'viem'
1076
+ * import { tempo } from 'tempo.ts/chains'
1077
+ * import { Actions } from 'tempo.ts/viem'
1078
+ *
1079
+ * const client = createClient({
1080
+ * chain: tempo,
1081
+ * transport: http(),
1082
+ * })
1083
+ *
1084
+ * const unwatch = Actions.dex.watchFlipOrderPlaced(client, {
1085
+ * onFlipOrderPlaced: (args, log) => {
1086
+ * console.log('Flip order placed:', args)
1087
+ * },
1088
+ * })
1089
+ * ```
1090
+ *
1091
+ * @param client - Client.
1092
+ * @param parameters - Parameters.
1093
+ * @returns A function to unsubscribe from the event.
1094
+ */
1095
+ export function watchFlipOrderPlaced(client, parameters) {
1096
+ const { onFlipOrderPlaced, maker, token, ...rest } = parameters;
1097
+ return watchContractEvent(client, {
1098
+ ...rest,
1099
+ address: Addresses.stablecoinExchange,
1100
+ abi: Abis.stablecoinExchange,
1101
+ eventName: 'FlipOrderPlaced',
1102
+ args: {
1103
+ ...(maker !== undefined && { maker }),
1104
+ ...(token !== undefined && { token }),
1105
+ },
1106
+ onLogs: (logs) => {
1107
+ for (const log of logs)
1108
+ onFlipOrderPlaced(log.args, log);
1109
+ },
1110
+ strict: true,
1111
+ });
1112
+ }
1113
+ /**
1114
+ * Watches for order cancelled events.
1115
+ *
1116
+ * @example
1117
+ * ```ts
1118
+ * import { createClient, http } from 'viem'
1119
+ * import { tempo } from 'tempo.ts/chains'
1120
+ * import { Actions } from 'tempo.ts/viem'
1121
+ *
1122
+ * const client = createClient({
1123
+ * chain: tempo,
1124
+ * transport: http(),
1125
+ * })
1126
+ *
1127
+ * const unwatch = Actions.dex.watchOrderCancelled(client, {
1128
+ * onOrderCancelled: (args, log) => {
1129
+ * console.log('Order cancelled:', args)
1130
+ * },
1131
+ * })
1132
+ * ```
1133
+ *
1134
+ * @param client - Client.
1135
+ * @param parameters - Parameters.
1136
+ * @returns A function to unsubscribe from the event.
1137
+ */
1138
+ export function watchOrderCancelled(client, parameters) {
1139
+ const { onOrderCancelled, orderId, ...rest } = parameters;
1140
+ return watchContractEvent(client, {
1141
+ ...rest,
1142
+ address: Addresses.stablecoinExchange,
1143
+ abi: Abis.stablecoinExchange,
1144
+ eventName: 'OrderCancelled',
1145
+ args: orderId !== undefined ? { orderId } : undefined,
1146
+ onLogs: (logs) => {
1147
+ for (const log of logs)
1148
+ onOrderCancelled(log.args, log);
1149
+ },
1150
+ strict: true,
1151
+ });
1152
+ }
1153
+ /**
1154
+ * Watches for order filled events.
1155
+ *
1156
+ * @example
1157
+ * ```ts
1158
+ * import { createClient, http } from 'viem'
1159
+ * import { tempo } from 'tempo.ts/chains'
1160
+ * import { Actions } from 'tempo.ts/viem'
1161
+ *
1162
+ * const client = createClient({
1163
+ * chain: tempo,
1164
+ * transport: http(),
1165
+ * })
1166
+ *
1167
+ * const unwatch = Actions.dex.watchOrderFilled(client, {
1168
+ * onOrderFilled: (args, log) => {
1169
+ * console.log('Order filled:', args)
1170
+ * },
1171
+ * })
1172
+ * ```
1173
+ *
1174
+ * @param client - Client.
1175
+ * @param parameters - Parameters.
1176
+ * @returns A function to unsubscribe from the event.
1177
+ */
1178
+ export function watchOrderFilled(client, parameters) {
1179
+ const { onOrderFilled, maker, taker, orderId, ...rest } = parameters;
1180
+ return watchContractEvent(client, {
1181
+ ...rest,
1182
+ address: Addresses.stablecoinExchange,
1183
+ abi: Abis.stablecoinExchange,
1184
+ eventName: 'OrderFilled',
1185
+ args: {
1186
+ ...(orderId !== undefined && { orderId }),
1187
+ ...(maker !== undefined && { maker }),
1188
+ ...(taker !== undefined && { taker }),
1189
+ },
1190
+ onLogs: (logs) => {
1191
+ for (const log of logs)
1192
+ onOrderFilled(log.args, log);
1193
+ },
1194
+ strict: true,
1195
+ });
1196
+ }
1197
+ /**
1198
+ * Watches for order placed events.
1199
+ *
1200
+ * @example
1201
+ * ```ts
1202
+ * import { createClient, http } from 'viem'
1203
+ * import { tempo } from 'tempo.ts/chains'
1204
+ * import { Actions } from 'tempo.ts/viem'
1205
+ *
1206
+ * const client = createClient({
1207
+ * chain: tempo,
1208
+ * transport: http(),
1209
+ * })
1210
+ *
1211
+ * const unwatch = Actions.dex.watchOrderPlaced(client, {
1212
+ * onOrderPlaced: (args, log) => {
1213
+ * console.log('Order placed:', args)
1214
+ * },
1215
+ * })
1216
+ * ```
1217
+ *
1218
+ * @param client - Client.
1219
+ * @param parameters - Parameters.
1220
+ * @returns A function to unsubscribe from the event.
1221
+ */
1222
+ export function watchOrderPlaced(client, parameters) {
1223
+ const { onOrderPlaced, maker, token, ...rest } = parameters;
1224
+ return watchContractEvent(client, {
1225
+ ...rest,
1226
+ address: Addresses.stablecoinExchange,
1227
+ abi: Abis.stablecoinExchange,
1228
+ eventName: 'OrderPlaced',
1229
+ args: {
1230
+ ...(maker !== undefined && { maker }),
1231
+ ...(token !== undefined && { token }),
1232
+ },
1233
+ onLogs: (logs) => {
1234
+ for (const log of logs)
1235
+ onOrderPlaced(log.args, log);
1236
+ },
1237
+ strict: true,
1238
+ });
1239
+ }
1240
+ /**
1241
+ * Withdraws tokens from the DEX to the caller's wallet.
1242
+ *
1243
+ * @example
1244
+ * ```ts
1245
+ * import { createClient, http } from 'viem'
1246
+ * import { privateKeyToAccount } from 'viem/accounts'
1247
+ * import { tempo } from 'tempo.ts/chains'
1248
+ * import { Actions } from 'tempo.ts/viem'
1249
+ *
1250
+ * const client = createClient({
1251
+ * account: privateKeyToAccount('0x...'),
1252
+ * chain: tempo,
1253
+ * transport: http(),
1254
+ * })
1255
+ *
1256
+ * const hash = await Actions.dex.withdraw(client, {
1257
+ * amount: 100n,
1258
+ * token: '0x20c...11',
1259
+ * })
1260
+ * ```
1261
+ *
1262
+ * @param client - Client.
1263
+ * @param parameters - Parameters.
1264
+ * @returns The transaction hash.
1265
+ */
1266
+ export async function withdraw(client, parameters) {
1267
+ return withdraw.inner(writeContract, client, parameters);
1268
+ }
1269
+ (function (withdraw) {
1270
+ /** @internal */
1271
+ async function inner(action, client, parameters) {
1272
+ const { token, amount, ...rest } = parameters;
1273
+ const call = withdraw.call({ token, amount });
1274
+ return (await action(client, {
1275
+ ...rest,
1276
+ ...call,
1277
+ }));
1278
+ }
1279
+ withdraw.inner = inner;
1280
+ /**
1281
+ * Defines a call to the `withdraw` function.
1282
+ *
1283
+ * Can be passed as a parameter to:
1284
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1285
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1286
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1287
+ *
1288
+ * @example
1289
+ * ```ts
1290
+ * import { createClient, http, parseUnits, walletActions } from 'viem'
1291
+ * import { tempo } from 'tempo.ts/chains'
1292
+ * import { Actions } from 'tempo.ts/viem'
1293
+ *
1294
+ * const client = createClient({
1295
+ * chain: tempo,
1296
+ * transport: http(),
1297
+ * }).extend(walletActions)
1298
+ *
1299
+ * const { result } = await client.sendCalls({
1300
+ * calls: [
1301
+ * Actions.dex.withdraw.call({
1302
+ * amount: parseUnits('100', 6),
1303
+ * token: '0x20c0...beef',
1304
+ * }),
1305
+ * ]
1306
+ * })
1307
+ * ```
1308
+ *
1309
+ * @param args - Arguments.
1310
+ * @returns The call.
1311
+ */
1312
+ function call(args) {
1313
+ const { token, amount } = args;
1314
+ return defineCall({
1315
+ address: Addresses.stablecoinExchange,
1316
+ abi: Abis.stablecoinExchange,
1317
+ functionName: 'withdraw',
1318
+ args: [token, amount],
1319
+ });
1320
+ }
1321
+ withdraw.call = call;
1322
+ })(withdraw || (withdraw = {}));
1323
+ /**
1324
+ * Withdraws tokens from the DEX to the caller's wallet.
1325
+ *
1326
+ * @example
1327
+ * ```ts
1328
+ * import { createClient, http } from 'viem'
1329
+ * import { privateKeyToAccount } from 'viem/accounts'
1330
+ * import { tempo } from 'tempo.ts/chains'
1331
+ * import { Actions } from 'tempo.ts/viem'
1332
+ *
1333
+ * const client = createClient({
1334
+ * account: privateKeyToAccount('0x...'),
1335
+ * chain: tempo,
1336
+ * transport: http(),
1337
+ * })
1338
+ *
1339
+ * const result = await Actions.dex.withdrawSync(client, {
1340
+ * amount: 100n,
1341
+ * token: '0x20c...11',
1342
+ * })
1343
+ * ```
1344
+ *
1345
+ * @param client - Client.
1346
+ * @param parameters - Parameters.
1347
+ * @returns The transaction receipt.
1348
+ */
1349
+ export async function withdrawSync(client, parameters) {
1350
+ const { throwOnReceiptRevert = true, ...rest } = parameters;
1351
+ const receipt = await withdraw.inner(writeContractSync, client, {
1352
+ ...rest,
1353
+ throwOnReceiptRevert,
1354
+ });
1355
+ return { receipt };
1356
+ }
1357
+ //# sourceMappingURL=dex.js.map