tempo.ts 0.11.1 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/CHANGELOG.md +67 -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 +3 -13
  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,121 +0,0 @@
1
- import type {
2
- Account,
3
- Address,
4
- Chain,
5
- Client,
6
- Hash,
7
- TransactionReceipt,
8
- Transport,
9
- } from 'viem'
10
- import { waitForTransactionReceipt } from 'viem/actions'
11
- import { parseAccount } from 'viem/utils'
12
-
13
- /**
14
- * Funds an account with an initial amount of set token(s)
15
- * on Tempo's testnet.
16
- *
17
- * @example
18
- * ```ts
19
- * import { createClient, http } from 'viem'
20
- * import { tempo } from 'tempo.ts/chains'
21
- * import { Actions } from 'tempo.ts/viem'
22
- *
23
- * const client = createClient({
24
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
25
- * transport: http(),
26
- * })
27
- *
28
- * const hashes = await Actions.faucet.fund(client, {
29
- * account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
30
- * })
31
- * ```
32
- *
33
- * @param client - Client.
34
- * @param parameters - Parameters.
35
- * @returns The transaction hash.
36
- */
37
- export async function fund<chain extends Chain | undefined>(
38
- client: Client<Transport, chain>,
39
- parameters: fund.Parameters,
40
- ): Promise<fund.ReturnValue> {
41
- const account = parseAccount(parameters.account)
42
- return client.request<{
43
- Method: 'tempo_fundAddress'
44
- Parameters: [address: Address]
45
- ReturnType: readonly Hash[]
46
- }>({
47
- method: 'tempo_fundAddress',
48
- params: [account.address],
49
- })
50
- }
51
-
52
- export declare namespace fund {
53
- export type Parameters = {
54
- /** Account to fund. */
55
- account: Account | Address
56
- }
57
-
58
- export type ReturnValue = readonly Hash[]
59
- }
60
-
61
- /**
62
- * Funds an account with an initial amount of set token(s)
63
- * on Tempo's testnet. Waits for the transactions to be included
64
- * on a block before returning a response.
65
- *
66
- * @example
67
- * ```ts
68
- * import { createClient, http } from 'viem'
69
- * import { tempo } from 'tempo.ts/chains'
70
- * import { Actions } from 'tempo.ts/viem'
71
- *
72
- * const client = createClient({
73
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
74
- * transport: http(),
75
- * })
76
- *
77
- * const hashes = await Actions.faucet.fundSync(client, {
78
- * account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
79
- * })
80
- * ```
81
- *
82
- * @param client - Client.
83
- * @param parameters - Parameters.
84
- * @returns The transaction hash.
85
- */
86
- export async function fundSync<chain extends Chain | undefined>(
87
- client: Client<Transport, chain>,
88
- parameters: fundSync.Parameters,
89
- ): Promise<fundSync.ReturnValue> {
90
- const { timeout = 10_000 } = parameters
91
- const account = parseAccount(parameters.account)
92
- const hashes = await client.request<{
93
- Method: 'tempo_fundAddress'
94
- Parameters: [address: Address]
95
- ReturnType: readonly Hash[]
96
- }>({
97
- method: 'tempo_fundAddress',
98
- params: [account.address],
99
- })
100
- const receipts = await Promise.all(
101
- hashes.map((hash) =>
102
- waitForTransactionReceipt(client, {
103
- hash,
104
- checkReplacement: false,
105
- timeout,
106
- }),
107
- ),
108
- )
109
- return receipts
110
- }
111
-
112
- export declare namespace fundSync {
113
- export type Parameters = {
114
- /** Account to fund. */
115
- account: Account | Address
116
- /** Timeout. */
117
- timeout?: number | undefined
118
- }
119
-
120
- export type ReturnValue = readonly TransactionReceipt[]
121
- }
@@ -1,259 +0,0 @@
1
- import { setTimeout } from 'node:timers/promises'
2
- import { Abis } from 'tempo.ts/viem'
3
- import { parseUnits } from 'viem'
4
- import { writeContractSync } from 'viem/actions'
5
- import { afterEach, describe, expect, test } from 'vitest'
6
- import { rpcUrl } from '../../../test/config.js'
7
- import {
8
- accounts,
9
- clientWithAccount,
10
- fundAddress,
11
- } from '../../../test/viem/config.js'
12
- import * as actions from './index.js'
13
-
14
- const account2 = accounts[1]
15
- const account3 = accounts[2]
16
-
17
- afterEach(async () => {
18
- await fetch(`${rpcUrl}/restart`)
19
- })
20
-
21
- describe('getUserToken', () => {
22
- test('default', async () => {
23
- // Fund accounts
24
- await fundAddress(clientWithAccount, { address: account2.address })
25
- await fundAddress(clientWithAccount, { address: account3.address })
26
-
27
- // Set token (address)
28
- await actions.fee.setUserTokenSync(clientWithAccount, {
29
- account: account2,
30
- token: '0x20c0000000000000000000000000000000000001',
31
- })
32
-
33
- // Set another token (id)
34
- await actions.fee.setUserTokenSync(clientWithAccount, {
35
- account: account3,
36
- token: 2n,
37
- })
38
-
39
- expect(
40
- await actions.fee.getUserToken(clientWithAccount, { account: account2 }),
41
- ).toMatchInlineSnapshot(`
42
- {
43
- "address": "0x20C0000000000000000000000000000000000001",
44
- "id": 1n,
45
- }
46
- `)
47
- expect(
48
- await actions.fee.getUserToken(clientWithAccount, { account: account3 }),
49
- ).toMatchInlineSnapshot(`
50
- {
51
- "address": "0x20C0000000000000000000000000000000000002",
52
- "id": 2n,
53
- }
54
- `)
55
- })
56
- })
57
-
58
- describe('setUserToken', () => {
59
- test('default', async () => {
60
- expect(
61
- await actions.fee.getUserToken(clientWithAccount),
62
- ).toMatchInlineSnapshot(
63
- `
64
- {
65
- "address": "0x20C0000000000000000000000000000000000001",
66
- "id": 1n,
67
- }
68
- `,
69
- )
70
-
71
- const { receipt: setReceipt, ...setResult } =
72
- await actions.fee.setUserTokenSync(clientWithAccount, {
73
- token: 2n,
74
- })
75
- expect(setReceipt).toBeDefined()
76
- expect(setResult).toMatchInlineSnapshot(`
77
- {
78
- "token": "0x20C0000000000000000000000000000000000002",
79
- "user": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
80
- }
81
- `)
82
-
83
- expect(
84
- await actions.fee.getUserToken(clientWithAccount, {}),
85
- ).toMatchInlineSnapshot(
86
- `
87
- {
88
- "address": "0x20C0000000000000000000000000000000000002",
89
- "id": 2n,
90
- }
91
- `,
92
- )
93
-
94
- const { receipt: resetReceipt, ...resetResult } =
95
- await actions.fee.setUserTokenSync(clientWithAccount, {
96
- feeToken: 1n,
97
- token: 1n,
98
- })
99
- expect(resetReceipt).toBeDefined()
100
- expect(resetResult).toMatchInlineSnapshot(`
101
- {
102
- "token": "0x20C0000000000000000000000000000000000001",
103
- "user": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
104
- }
105
- `)
106
-
107
- expect(
108
- await actions.fee.getUserToken(clientWithAccount, {}),
109
- ).toMatchInlineSnapshot(
110
- `
111
- {
112
- "address": "0x20C0000000000000000000000000000000000001",
113
- "id": 1n,
114
- }
115
- `,
116
- )
117
- })
118
- })
119
-
120
- describe('watchSetUserToken', async () => {
121
- test('default', async () => {
122
- const receivedSets: Array<{
123
- args: actions.fee.watchSetUserToken.Args
124
- log: actions.fee.watchSetUserToken.Log
125
- }> = []
126
-
127
- // Start watching for user token set events
128
- const unwatch = actions.fee.watchSetUserToken(clientWithAccount, {
129
- onUserTokenSet: (args, log) => {
130
- receivedSets.push({ args, log })
131
- },
132
- })
133
-
134
- try {
135
- // Set token for account2
136
- await writeContractSync(clientWithAccount, {
137
- abi: Abis.tip20,
138
- address: '0x20c0000000000000000000000000000000000001',
139
- functionName: 'transfer',
140
- args: [account2.address, parseUnits('1', 6)],
141
- })
142
-
143
- await actions.fee.setUserTokenSync(clientWithAccount, {
144
- account: account2,
145
- token: '0x20c0000000000000000000000000000000000001',
146
- })
147
-
148
- // Set token for account3
149
- await writeContractSync(clientWithAccount, {
150
- abi: Abis.tip20,
151
- address: '0x20c0000000000000000000000000000000000001',
152
- functionName: 'transfer',
153
- args: [account3.address, parseUnits('1', 6)],
154
- })
155
-
156
- await actions.fee.setUserTokenSync(clientWithAccount, {
157
- account: account3,
158
- token: '0x20c0000000000000000000000000000000000002',
159
- })
160
-
161
- await setTimeout(500)
162
-
163
- expect(receivedSets).toHaveLength(2)
164
-
165
- expect(receivedSets.at(0)!.args).toMatchInlineSnapshot(`
166
- {
167
- "token": "0x20C0000000000000000000000000000000000001",
168
- "user": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
169
- }
170
- `)
171
- expect(receivedSets.at(1)!.args).toMatchInlineSnapshot(`
172
- {
173
- "token": "0x20C0000000000000000000000000000000000002",
174
- "user": "0x98e503f35D0a019cB0a251aD243a4cCFCF371F46",
175
- }
176
- `)
177
- } finally {
178
- if (unwatch) unwatch()
179
- }
180
- })
181
-
182
- test('behavior: filter by user address', async () => {
183
- const receivedSets: Array<{
184
- args: actions.fee.watchSetUserToken.Args
185
- log: actions.fee.watchSetUserToken.Log
186
- }> = []
187
-
188
- // Start watching for user token set events only for account2
189
- const unwatch = actions.fee.watchSetUserToken(clientWithAccount, {
190
- args: {
191
- user: account2.address,
192
- },
193
- onUserTokenSet: (args, log) => {
194
- receivedSets.push({ args, log })
195
- },
196
- })
197
-
198
- try {
199
- // Transfer gas to accounts
200
- await writeContractSync(clientWithAccount, {
201
- abi: Abis.tip20,
202
- address: '0x20c0000000000000000000000000000000000001',
203
- functionName: 'transfer',
204
- args: [account2.address, parseUnits('1', 6)],
205
- })
206
-
207
- await writeContractSync(clientWithAccount, {
208
- abi: Abis.tip20,
209
- address: '0x20c0000000000000000000000000000000000001',
210
- functionName: 'transfer',
211
- args: [account3.address, parseUnits('1', 6)],
212
- })
213
-
214
- // Set token for account2 (should be captured)
215
- await actions.fee.setUserTokenSync(clientWithAccount, {
216
- account: account2,
217
- token: '0x20c0000000000000000000000000000000000001',
218
- })
219
-
220
- // Set token for account3 (should NOT be captured)
221
- await actions.fee.setUserTokenSync(clientWithAccount, {
222
- account: account3,
223
- token: '0x20c0000000000000000000000000000000000002',
224
- })
225
-
226
- // Set token for account2 again (should be captured)
227
- await actions.fee.setUserTokenSync(clientWithAccount, {
228
- account: account2,
229
- feeToken: 1n,
230
- token: 2n,
231
- })
232
-
233
- await setTimeout(500)
234
-
235
- // Should only receive 2 events (for account2)
236
- expect(receivedSets).toHaveLength(2)
237
-
238
- expect(receivedSets.at(0)!.args).toMatchInlineSnapshot(`
239
- {
240
- "token": "0x20C0000000000000000000000000000000000001",
241
- "user": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
242
- }
243
- `)
244
- expect(receivedSets.at(1)!.args).toMatchInlineSnapshot(`
245
- {
246
- "token": "0x20C0000000000000000000000000000000000002",
247
- "user": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
248
- }
249
- `)
250
-
251
- // Verify all received events are for account2
252
- for (const set of receivedSets) {
253
- expect(set.args.user).toBe(account2.address)
254
- }
255
- } finally {
256
- if (unwatch) unwatch()
257
- }
258
- })
259
- })