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