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,372 +0,0 @@
1
- import { TokenId } from 'ox/tempo'
2
- import {
3
- type Account,
4
- type Address,
5
- type BaseErrorType,
6
- type Chain,
7
- type Client,
8
- type ExtractAbiItem,
9
- type GetEventArgs,
10
- type Log,
11
- parseEventLogs,
12
- type TransactionReceipt,
13
- type Transport,
14
- type Log as viem_Log,
15
- type WatchContractEventParameters,
16
- type WriteContractReturnType,
17
- zeroAddress,
18
- } from 'viem'
19
- import { parseAccount } from 'viem/accounts'
20
- import {
21
- readContract,
22
- watchContractEvent,
23
- writeContract,
24
- writeContractSync,
25
- } from 'viem/actions'
26
- import type { Compute, UnionOmit } from '../../internal/types.js'
27
- import * as Abis from '../Abis.js'
28
- import * as Addresses from '../Addresses.js'
29
- import type {
30
- GetAccountParameter,
31
- ReadParameters,
32
- WriteParameters,
33
- } from '../internal/types.js'
34
- import { defineCall } from '../internal/utils.js'
35
-
36
- /**
37
- * Gets the user's default fee token.
38
- *
39
- * @example
40
- * ```ts
41
- * import { createClient, http } from 'viem'
42
- * import { tempo } from 'tempo.ts/chains'
43
- * import { Actions } from 'tempo.ts/viem'
44
- * import { privateKeyToAccount } from 'viem/accounts'
45
- *
46
- * const client = createClient({
47
- * account: privateKeyToAccount('0x...'),
48
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
49
- * transport: http(),
50
- * })
51
- *
52
- * const { address, id } = await Actions.fee.getUserToken(client)
53
- * ```
54
- *
55
- * @param client - Client.
56
- * @param parameters - Parameters.
57
- * @returns The transaction hash.
58
- */
59
- export async function getUserToken<
60
- chain extends Chain | undefined,
61
- account extends Account | undefined,
62
- >(
63
- client: Client<Transport, chain, account>,
64
- ...parameters: account extends Account
65
- ? [getUserToken.Parameters<account>] | []
66
- : [getUserToken.Parameters<account>]
67
- ): Promise<getUserToken.ReturnValue> {
68
- const { account: account_ = client.account, ...rest } = parameters[0] ?? {}
69
- if (!account_) throw new Error('account is required.')
70
- const account = parseAccount(account_)
71
- const address = await readContract(client, {
72
- ...rest,
73
- ...getUserToken.call({ account: account.address }),
74
- })
75
- if (address === zeroAddress) return null
76
- return {
77
- address,
78
- id: TokenId.fromAddress(address),
79
- }
80
- }
81
-
82
- export namespace getUserToken {
83
- export type Parameters<
84
- account extends Account | undefined = Account | undefined,
85
- > = ReadParameters & GetAccountParameter<account>
86
-
87
- export type Args = {
88
- /** Account address. */
89
- account: Address
90
- }
91
-
92
- export type ReturnValue = Compute<{
93
- address: Address
94
- id: bigint
95
- } | null>
96
-
97
- /**
98
- * Defines a call to the `userTokens` function.
99
- *
100
- * @param args - Arguments.
101
- * @returns The call.
102
- */
103
- export function call(args: Args) {
104
- const { account } = args
105
- return defineCall({
106
- address: Addresses.feeManager,
107
- abi: Abis.feeManager,
108
- args: [account],
109
- functionName: 'userTokens',
110
- })
111
- }
112
- }
113
-
114
- /**
115
- * Sets the user's default fee token.
116
- *
117
- * @example
118
- * ```ts
119
- * import { createClient, http } from 'viem'
120
- * import { tempo } from 'tempo.ts/chains'
121
- * import { Actions } from 'tempo.ts/viem'
122
- * import { privateKeyToAccount } from 'viem/accounts'
123
- *
124
- * const client = createClient({
125
- * account: privateKeyToAccount('0x...'),
126
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
127
- * transport: http(),
128
- * })
129
- *
130
- * const hash = await Actions.fee.setUserToken(client, {
131
- * token: '0x...',
132
- * })
133
- * ```
134
- *
135
- * @param client - Client.
136
- * @param parameters - Parameters.
137
- * @returns The transaction hash.
138
- */
139
- export async function setUserToken<
140
- chain extends Chain | undefined,
141
- account extends Account | undefined,
142
- >(
143
- client: Client<Transport, chain, account>,
144
- parameters: setUserToken.Parameters<chain, account>,
145
- ): Promise<setUserToken.ReturnValue> {
146
- return setUserToken.inner(writeContract, client, parameters)
147
- }
148
-
149
- export namespace setUserToken {
150
- export type Parameters<
151
- chain extends Chain | undefined = Chain | undefined,
152
- account extends Account | undefined = Account | undefined,
153
- > = WriteParameters<chain, account> & Args
154
-
155
- export type Args = {
156
- /** Address or ID of the TIP20 token. */
157
- token: TokenId.TokenIdOrAddress
158
- }
159
-
160
- export type ReturnValue = WriteContractReturnType
161
-
162
- // TODO: exhaustive error type
163
- export type ErrorType = BaseErrorType
164
-
165
- /** @internal */
166
- export async function inner<
167
- action extends typeof writeContract | typeof writeContractSync,
168
- chain extends Chain | undefined,
169
- account extends Account | undefined,
170
- >(
171
- action: action,
172
- client: Client<Transport, chain, account>,
173
- parameters: setUserToken.Parameters<chain, account>,
174
- ): Promise<ReturnType<action>> {
175
- const { token, ...rest } = parameters
176
- const call = setUserToken.call({ token })
177
- return (await action(client, {
178
- ...rest,
179
- ...call,
180
- } as never)) as never
181
- }
182
-
183
- /**
184
- * Defines a call to the `setUserToken` function.
185
- *
186
- * Can be passed as a parameter to:
187
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
188
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
189
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
190
- *
191
- * @example
192
- * ```ts
193
- * import { createClient, http, walletActions } from 'viem'
194
- * import { tempo } from 'tempo.ts/chains'
195
- * import { Actions } from 'tempo.ts/viem'
196
- *
197
- * const client = createClient({
198
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
199
- * transport: http(),
200
- * }).extend(walletActions)
201
- *
202
- * const { result } = await client.sendCalls({
203
- * calls: [
204
- * actions.fee.setUserToken.call({
205
- * token: '0x20c0...beef',
206
- * }),
207
- * actions.fee.setUserToken.call({
208
- * token: '0x20c0...babe',
209
- * }),
210
- * ]
211
- * })
212
- * ```
213
- *
214
- * @param args - Arguments.
215
- * @returns The call.
216
- */
217
- export function call(args: Args) {
218
- const { token } = args
219
- return defineCall({
220
- address: Addresses.feeManager,
221
- abi: Abis.feeManager,
222
- functionName: 'setUserToken',
223
- args: [TokenId.toAddress(token)],
224
- })
225
- }
226
-
227
- export function extractEvent(logs: Log[]) {
228
- const [log] = parseEventLogs({
229
- abi: Abis.feeManager,
230
- logs,
231
- eventName: 'UserTokenSet',
232
- strict: true,
233
- })
234
- if (!log) throw new Error('`UserTokenSet` event not found.')
235
- return log
236
- }
237
- }
238
-
239
- /**
240
- * Sets the user's default fee token.
241
- *
242
- * @example
243
- * ```ts
244
- * import { createClient, http } from 'viem'
245
- * import { tempo } from 'tempo.ts/chains'
246
- * import { Actions } from 'tempo.ts/viem'
247
- * import { privateKeyToAccount } from 'viem/accounts'
248
- *
249
- * const client = createClient({
250
- * account: privateKeyToAccount('0x...'),
251
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
252
- * transport: http(),
253
- * })
254
- *
255
- * const result = await Actions.fee.setUserTokenSync(client, {
256
- * token: '0x...',
257
- * })
258
- * ```
259
- *
260
- * @param client - Client.
261
- * @param parameters - Parameters.
262
- * @returns The transaction receipt and event data.
263
- */
264
- export async function setUserTokenSync<
265
- chain extends Chain | undefined,
266
- account extends Account | undefined,
267
- >(
268
- client: Client<Transport, chain, account>,
269
- parameters: setUserTokenSync.Parameters<chain, account>,
270
- ): Promise<setUserTokenSync.ReturnValue> {
271
- const { throwOnReceiptRevert = true, ...rest } = parameters
272
- const receipt = await setUserToken.inner(writeContractSync, client, {
273
- ...rest,
274
- throwOnReceiptRevert,
275
- } as never)
276
- const { args } = setUserToken.extractEvent(receipt.logs)
277
- return {
278
- ...args,
279
- receipt,
280
- } as never
281
- }
282
-
283
- export namespace setUserTokenSync {
284
- export type Parameters<
285
- chain extends Chain | undefined = Chain | undefined,
286
- account extends Account | undefined = Account | undefined,
287
- > = setUserToken.Parameters<chain, account>
288
-
289
- export type Args = setUserToken.Args
290
-
291
- export type ReturnValue = Compute<
292
- GetEventArgs<
293
- typeof Abis.feeManager,
294
- 'UserTokenSet',
295
- { IndexedOnly: false; Required: true }
296
- > & {
297
- receipt: TransactionReceipt
298
- }
299
- >
300
-
301
- // TODO: exhaustive error type
302
- export type ErrorType = BaseErrorType
303
- }
304
-
305
- /**
306
- * Watches for user token set events.
307
- *
308
- * @example
309
- * ```ts
310
- * import { createClient, http } from 'viem'
311
- * import { tempo } from 'tempo.ts/chains'
312
- * import { Actions } from 'tempo.ts/viem'
313
- *
314
- * const client = createClient({
315
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
316
- * transport: http(),
317
- * })
318
- *
319
- * const unwatch = actions.fee.watchSetUserToken(client, {
320
- * onUserTokenSet: (args, log) => {
321
- * console.log('User token set:', args)
322
- * },
323
- * })
324
- * ```
325
- *
326
- * @param client - Client.
327
- * @param parameters - Parameters.
328
- * @returns A function to unsubscribe from the event.
329
- */
330
- export function watchSetUserToken<
331
- chain extends Chain | undefined,
332
- account extends Account | undefined,
333
- >(
334
- client: Client<Transport, chain, account>,
335
- parameters: watchSetUserToken.Parameters,
336
- ) {
337
- const { onUserTokenSet, ...rest } = parameters
338
- return watchContractEvent(client, {
339
- ...rest,
340
- address: Addresses.feeManager,
341
- abi: Abis.feeManager,
342
- eventName: 'UserTokenSet',
343
- onLogs: (logs) => {
344
- for (const log of logs) onUserTokenSet(log.args, log)
345
- },
346
- strict: true,
347
- })
348
- }
349
-
350
- export declare namespace watchSetUserToken {
351
- export type Args = GetEventArgs<
352
- typeof Abis.feeManager,
353
- 'UserTokenSet',
354
- { IndexedOnly: false; Required: true }
355
- >
356
-
357
- export type Log = viem_Log<
358
- bigint,
359
- number,
360
- false,
361
- ExtractAbiItem<typeof Abis.feeManager, 'UserTokenSet'>,
362
- true
363
- >
364
-
365
- export type Parameters = UnionOmit<
366
- WatchContractEventParameters<typeof Abis.feeManager, 'UserTokenSet', true>,
367
- 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
368
- > & {
369
- /** Callback to invoke when a user token is set. */
370
- onUserTokenSet: (args: Args, log: Log) => void
371
- }
372
- }
@@ -1,9 +0,0 @@
1
- export { verifyHash } from './account.js'
2
- export * as amm from './amm.js'
3
- export * as dex from './dex.js'
4
- export * as faucet from './faucet.js'
5
- export * as fee from './fee.js'
6
- export * as nonce from './nonce.js'
7
- export * as policy from './policy.js'
8
- export * as reward from './reward.js'
9
- export * as token from './token.js'
@@ -1,206 +0,0 @@
1
- import { setTimeout } from 'node:timers/promises'
2
- import { beforeEach, describe, expect, test } from 'vitest'
3
- import { rpcUrl } from '../../../test/config.js'
4
- import { accounts, clientWithAccount } from '../../../test/viem/config.js'
5
- import * as actions from './index.js'
6
-
7
- const account = accounts[0]
8
- const account2 = accounts[1]
9
-
10
- beforeEach(async () => {
11
- await fetch(`${rpcUrl}/restart`)
12
- })
13
-
14
- describe('getNonce', () => {
15
- test('default', async () => {
16
- // Get nonce for an account with previously unused noncekey
17
- const nonce = await actions.nonce.getNonce(clientWithAccount, {
18
- account: account.address,
19
- nonceKey: 1n,
20
- })
21
-
22
- expect(nonce).toBe(0n)
23
- })
24
-
25
- test('behavior: different nonce keys are independent', async () => {
26
- let nonce1 = await actions.nonce.getNonce(clientWithAccount, {
27
- account: account.address,
28
- nonceKey: 1n,
29
- })
30
- let nonce2 = await actions.nonce.getNonce(clientWithAccount, {
31
- account: account.address,
32
- nonceKey: 2n,
33
- })
34
-
35
- expect(nonce1).toBe(0n)
36
- expect(nonce2).toBe(0n)
37
-
38
- await actions.token.transferSync(clientWithAccount, {
39
- to: account2.address,
40
- amount: 1n,
41
- token: 1n,
42
- nonceKey: 2n,
43
- })
44
-
45
- nonce1 = await actions.nonce.getNonce(clientWithAccount, {
46
- account: account.address,
47
- nonceKey: 1n,
48
- })
49
- nonce2 = await actions.nonce.getNonce(clientWithAccount, {
50
- account: account.address,
51
- nonceKey: 2n,
52
- })
53
-
54
- // nonceKey 2 should be incremented to 2
55
- expect(nonce1).toBe(0n)
56
- expect(nonce2).toBe(1n)
57
- })
58
-
59
- test('behavior: different accounts are independent', async () => {
60
- await actions.token.transferSync(clientWithAccount, {
61
- to: account2.address,
62
- amount: 1n,
63
- token: 1n,
64
- nonceKey: 1n,
65
- })
66
- const nonce1 = await actions.nonce.getNonce(clientWithAccount, {
67
- account: account.address,
68
- nonceKey: 1n,
69
- })
70
- const nonce2 = await actions.nonce.getNonce(clientWithAccount, {
71
- account: account2.address,
72
- nonceKey: 1n,
73
- })
74
-
75
- expect(nonce1).toBe(1n)
76
- expect(nonce2).toBe(0n)
77
- })
78
- })
79
-
80
- describe('getNonceKeyCount', () => {
81
- test('default', async () => {
82
- // Get active nonce key count for a fresh account
83
- const count = await actions.nonce.getNonceKeyCount(clientWithAccount, {
84
- account: accounts.at(10)!.address,
85
- })
86
-
87
- // Fresh account should have 0 active nonce keys
88
- expect(count).toBe(0n)
89
- })
90
-
91
- test('behavior: different accounts are independent', async () => {
92
- const count1 = await actions.nonce.getNonceKeyCount(clientWithAccount, {
93
- account: accounts.at(10)!.address,
94
- })
95
- const count2 = await actions.nonce.getNonceKeyCount(clientWithAccount, {
96
- account: accounts.at(11)!.address,
97
- })
98
-
99
- // Both should be 0 for fresh accounts
100
- expect(count1).toBe(0n)
101
- expect(count2).toBe(0n)
102
- })
103
- })
104
-
105
- describe('watchNonceIncremented', () => {
106
- test('default', async () => {
107
- const events: Array<{
108
- args: actions.nonce.watchNonceIncremented.Args
109
- log: actions.nonce.watchNonceIncremented.Log
110
- }> = []
111
-
112
- const unwatch = actions.nonce.watchNonceIncremented(clientWithAccount, {
113
- onNonceIncremented: (args, log) => {
114
- events.push({ args, log })
115
- },
116
- args: {
117
- account: account.address,
118
- nonceKey: 5n,
119
- },
120
- })
121
-
122
- try {
123
- // Have to manually set nonce because eth_FillTransaction does not support nonce keys
124
- await actions.token.transferSync(clientWithAccount, {
125
- to: account2.address,
126
- amount: 1n,
127
- token: 1n,
128
- nonceKey: 5n,
129
- nonce: 0,
130
- })
131
-
132
- await actions.token.transferSync(clientWithAccount, {
133
- to: account2.address,
134
- amount: 1n,
135
- token: 1n,
136
- nonceKey: 5n,
137
- nonce: 1,
138
- })
139
-
140
- await setTimeout(1000)
141
-
142
- expect(events).toHaveLength(2)
143
- expect(events[0]!.args.account).toBe(account.address)
144
- expect(events[0]!.args.nonceKey).toBe(5n)
145
- expect(events[0]!.args.newNonce).toBe(1n)
146
- expect(events[1]!.args.newNonce).toBe(2n)
147
- } finally {
148
- unwatch()
149
- }
150
- })
151
- })
152
-
153
- describe('watchActiveKeyCountChanged', () => {
154
- test('default', async () => {
155
- const events: Array<{
156
- args: actions.nonce.watchActiveKeyCountChanged.Args
157
- log: actions.nonce.watchActiveKeyCountChanged.Log
158
- }> = []
159
-
160
- const unwatch = actions.nonce.watchActiveKeyCountChanged(
161
- clientWithAccount,
162
- {
163
- onActiveKeyCountChanged: (args, log) => {
164
- events.push({ args, log })
165
- },
166
- },
167
- )
168
-
169
- const priorKeyCount = await actions.nonce.getNonceKeyCount(
170
- clientWithAccount,
171
- {
172
- account: account.address,
173
- },
174
- )
175
-
176
- try {
177
- // First use of nonceKey 10 should increment active key count
178
- await actions.token.transferSync(clientWithAccount, {
179
- to: account2.address,
180
- amount: 1n,
181
- token: 1n,
182
- nonceKey: 10n,
183
- nonce: 0,
184
- })
185
-
186
- // First use of nonceKey 11 should increment again
187
- await actions.token.transferSync(clientWithAccount, {
188
- to: account2.address,
189
- amount: 1n,
190
- token: 1n,
191
- nonceKey: 11n,
192
- nonce: 0,
193
- })
194
-
195
- await setTimeout(1000)
196
-
197
- expect(events).toHaveLength(2)
198
- expect(events[0]!.args.account).toBe(account.address)
199
- // Assert the number of new active keys
200
- expect(events[0]!.args.newCount - priorKeyCount).toBe(1n)
201
- expect(events[1]!.args.newCount - priorKeyCount).toBe(2n)
202
- } finally {
203
- unwatch()
204
- }
205
- })
206
- })