tempo.ts 0.11.0 → 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 (196) 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 +2 -2
  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/viem/Abis.d.ts +0 -2649
  75. package/dist/viem/Abis.d.ts.map +0 -1
  76. package/dist/viem/Abis.js +0 -1677
  77. package/dist/viem/Abis.js.map +0 -1
  78. package/dist/viem/Account.d.ts +0 -244
  79. package/dist/viem/Account.d.ts.map +0 -1
  80. package/dist/viem/Account.js +0 -382
  81. package/dist/viem/Account.js.map +0 -1
  82. package/dist/viem/Actions/amm.d.ts +0 -1991
  83. package/dist/viem/Actions/amm.d.ts.map +0 -1
  84. package/dist/viem/Actions/amm.js +0 -814
  85. package/dist/viem/Actions/amm.js.map +0 -1
  86. package/dist/viem/Actions/dex.d.ts +0 -3900
  87. package/dist/viem/Actions/dex.d.ts.map +0 -1
  88. package/dist/viem/Actions/dex.js +0 -1414
  89. package/dist/viem/Actions/dex.js.map +0 -1
  90. package/dist/viem/Actions/faucet.d.ts +0 -69
  91. package/dist/viem/Actions/faucet.d.ts.map +0 -1
  92. package/dist/viem/Actions/faucet.js +0 -73
  93. package/dist/viem/Actions/faucet.js.map +0 -1
  94. package/dist/viem/Actions/fee.d.ts +0 -360
  95. package/dist/viem/Actions/fee.d.ts.map +0 -1
  96. package/dist/viem/Actions/fee.js +0 -237
  97. package/dist/viem/Actions/fee.js.map +0 -1
  98. package/dist/viem/Actions/nonce.d.ts +0 -257
  99. package/dist/viem/Actions/nonce.d.ts.map +0 -1
  100. package/dist/viem/Actions/nonce.js +0 -228
  101. package/dist/viem/Actions/nonce.js.map +0 -1
  102. package/dist/viem/Actions/policy.d.ts +0 -1680
  103. package/dist/viem/Actions/policy.d.ts.map +0 -1
  104. package/dist/viem/Actions/policy.js +0 -875
  105. package/dist/viem/Actions/policy.js.map +0 -1
  106. package/dist/viem/Actions/reward.d.ts +0 -2422
  107. package/dist/viem/Actions/reward.d.ts.map +0 -1
  108. package/dist/viem/Actions/reward.js +0 -651
  109. package/dist/viem/Actions/reward.js.map +0 -1
  110. package/dist/viem/Actions/token.d.ts +0 -16007
  111. package/dist/viem/Actions/token.d.ts.map +0 -1
  112. package/dist/viem/Actions/token.js +0 -2936
  113. package/dist/viem/Actions/token.js.map +0 -1
  114. package/dist/viem/Addresses.d.ts +0 -9
  115. package/dist/viem/Addresses.d.ts.map +0 -1
  116. package/dist/viem/Addresses.js +0 -9
  117. package/dist/viem/Addresses.js.map +0 -1
  118. package/dist/viem/Chain.d.ts +0 -451
  119. package/dist/viem/Chain.d.ts.map +0 -1
  120. package/dist/viem/Chain.js +0 -96
  121. package/dist/viem/Chain.js.map +0 -1
  122. package/dist/viem/Formatters.d.ts +0 -10
  123. package/dist/viem/Formatters.d.ts.map +0 -1
  124. package/dist/viem/Formatters.js +0 -104
  125. package/dist/viem/Formatters.js.map +0 -1
  126. package/dist/viem/Storage.d.ts +0 -24
  127. package/dist/viem/Storage.d.ts.map +0 -1
  128. package/dist/viem/Storage.js +0 -68
  129. package/dist/viem/Storage.js.map +0 -1
  130. package/dist/viem/Transaction.d.ts +0 -76
  131. package/dist/viem/Transaction.d.ts.map +0 -1
  132. package/dist/viem/Transaction.js +0 -176
  133. package/dist/viem/Transaction.js.map +0 -1
  134. package/dist/viem/Transport.d.ts +0 -33
  135. package/dist/viem/Transport.d.ts.map +0 -1
  136. package/dist/viem/Transport.js +0 -138
  137. package/dist/viem/Transport.js.map +0 -1
  138. package/dist/viem/WebAuthnP256.d.ts +0 -82
  139. package/dist/viem/WebAuthnP256.d.ts.map +0 -1
  140. package/dist/viem/WebAuthnP256.js +0 -97
  141. package/dist/viem/WebAuthnP256.js.map +0 -1
  142. package/dist/viem/WebCryptoP256.d.ts +0 -2
  143. package/dist/viem/WebCryptoP256.d.ts.map +0 -1
  144. package/dist/viem/WebCryptoP256.js +0 -2
  145. package/dist/viem/WebCryptoP256.js.map +0 -1
  146. package/dist/viem/internal/types.d.ts +0 -20
  147. package/dist/viem/internal/types.d.ts.map +0 -1
  148. package/dist/viem/internal/types.js +0 -2
  149. package/dist/viem/internal/types.js.map +0 -1
  150. package/dist/viem/internal/utils.d.ts +0 -14
  151. package/dist/viem/internal/utils.d.ts.map +0 -1
  152. package/dist/viem/internal/utils.js +0 -33
  153. package/dist/viem/internal/utils.js.map +0 -1
  154. package/src/chains.ts +0 -54
  155. package/src/viem/Abis.ts +0 -1688
  156. package/src/viem/Account.test.ts +0 -444
  157. package/src/viem/Account.ts +0 -601
  158. package/src/viem/Actions/account.test.ts +0 -414
  159. package/src/viem/Actions/account.ts +0 -106
  160. package/src/viem/Actions/amm.test.ts +0 -381
  161. package/src/viem/Actions/amm.ts +0 -1227
  162. package/src/viem/Actions/dex.test.ts +0 -1549
  163. package/src/viem/Actions/dex.ts +0 -2150
  164. package/src/viem/Actions/faucet.ts +0 -121
  165. package/src/viem/Actions/fee.test.ts +0 -259
  166. package/src/viem/Actions/fee.ts +0 -372
  167. package/src/viem/Actions/index.ts +0 -9
  168. package/src/viem/Actions/nonce.test.ts +0 -206
  169. package/src/viem/Actions/nonce.ts +0 -347
  170. package/src/viem/Actions/policy.test.ts +0 -534
  171. package/src/viem/Actions/policy.ts +0 -1335
  172. package/src/viem/Actions/reward.test.ts +0 -434
  173. package/src/viem/Actions/reward.ts +0 -944
  174. package/src/viem/Actions/token.test.ts +0 -3029
  175. package/src/viem/Actions/token.ts +0 -4458
  176. package/src/viem/Addresses.ts +0 -9
  177. package/src/viem/Chain.bench-d.ts +0 -12
  178. package/src/viem/Chain.test.ts +0 -168
  179. package/src/viem/Chain.ts +0 -157
  180. package/src/viem/Decorator.bench-d.ts +0 -11
  181. package/src/viem/Decorator.test.ts +0 -39
  182. package/src/viem/Decorator.ts +0 -3179
  183. package/src/viem/Formatters.ts +0 -164
  184. package/src/viem/P256.ts +0 -1
  185. package/src/viem/Secp256k1.ts +0 -1
  186. package/src/viem/Storage.ts +0 -110
  187. package/src/viem/TokenIds.ts +0 -1
  188. package/src/viem/Transaction.ts +0 -382
  189. package/src/viem/Transport.ts +0 -191
  190. package/src/viem/WebAuthnP256.ts +0 -146
  191. package/src/viem/WebCryptoP256.ts +0 -1
  192. package/src/viem/e2e.test.ts +0 -1602
  193. package/src/viem/index.ts +0 -30
  194. package/src/viem/internal/types.ts +0 -69
  195. package/src/viem/internal/utils.ts +0 -58
  196. package/src/wagmi/internal/types.ts +0 -16
@@ -1,875 +0,0 @@
1
- import { parseEventLogs, } from 'viem';
2
- import { parseAccount } from 'viem/accounts';
3
- import { readContract, watchContractEvent, writeContract, writeContractSync, } from 'viem/actions';
4
- import * as Abis from '../Abis.js';
5
- import * as Addresses from '../Addresses.js';
6
- import { defineCall } from '../internal/utils.js';
7
- const policyTypeMap = {
8
- whitelist: 0,
9
- blacklist: 1,
10
- };
11
- /**
12
- * Creates a new policy.
13
- *
14
- * @example
15
- * ```ts
16
- * import { createClient, http } from 'viem'
17
- * import { tempo } from 'tempo.ts/chains'
18
- * import { Actions } from 'tempo.ts/viem'
19
- * import { privateKeyToAccount } from 'viem/accounts'
20
- *
21
- * const client = createClient({
22
- * account: privateKeyToAccount('0x...'),
23
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
24
- * transport: http(),
25
- * })
26
- *
27
- * const { hash, policyId } = await Actions.policy.create(client, {
28
- * admin: '0x...',
29
- * type: 'whitelist',
30
- * })
31
- * ```
32
- *
33
- * @param client - Client.
34
- * @param parameters - Parameters.
35
- * @returns The transaction hash and policy ID.
36
- */
37
- export async function create(client, parameters) {
38
- return create.inner(writeContract, client, parameters);
39
- }
40
- (function (create) {
41
- /** @internal */
42
- async function inner(action, client, parameters) {
43
- const { account = client.account, addresses, chain = client.chain, type, ...rest } = parameters;
44
- if (!account)
45
- throw new Error('`account` is required');
46
- const admin = parseAccount(account).address;
47
- const call = create.call({ admin, type, addresses });
48
- return action(client, {
49
- ...rest,
50
- account,
51
- chain,
52
- ...call,
53
- });
54
- }
55
- create.inner = inner;
56
- /**
57
- * Defines a call to the `createPolicy` function.
58
- *
59
- * Can be passed as a parameter to:
60
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
61
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
62
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
63
- *
64
- * @example
65
- * ```ts
66
- * import { createClient, http, walletActions } from 'viem'
67
- * import { tempo } from 'tempo.ts/chains'
68
- * import { Actions } from 'tempo.ts/viem'
69
- *
70
- * const client = createClient({
71
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
72
- * transport: http(),
73
- * }).extend(walletActions)
74
- *
75
- * const { result } = await client.sendCalls({
76
- * calls: [
77
- * actions.policy.create.call({
78
- * admin: '0xfeed...fede',
79
- * type: 'whitelist',
80
- * }),
81
- * actions.policy.create.call({
82
- * admin: '0xfeed...fede',
83
- * type: 'blacklist',
84
- * addresses: ['0x20c0...beef', '0x20c0...babe'],
85
- * }),
86
- * ]
87
- * })
88
- * ```
89
- *
90
- * @param args - Arguments.
91
- * @returns The call.
92
- */
93
- function call(args) {
94
- const { admin, type, addresses } = args;
95
- const config = (() => {
96
- if (addresses)
97
- return {
98
- functionName: 'createPolicyWithAccounts',
99
- args: [admin, policyTypeMap[type], addresses],
100
- };
101
- return {
102
- functionName: 'createPolicy',
103
- args: [admin, policyTypeMap[type]],
104
- };
105
- })();
106
- return defineCall({
107
- address: Addresses.tip403Registry,
108
- abi: Abis.tip403Registry,
109
- ...config,
110
- });
111
- }
112
- create.call = call;
113
- /**
114
- * Extracts the `PolicyCreated` event from logs.
115
- *
116
- * @param logs - The logs.
117
- * @returns The `PolicyCreated` event.
118
- */
119
- function extractEvent(logs) {
120
- const [log] = parseEventLogs({
121
- abi: Abis.tip403Registry,
122
- logs,
123
- eventName: 'PolicyCreated',
124
- strict: true,
125
- });
126
- if (!log)
127
- throw new Error('`PolicyCreated` event not found.');
128
- return log;
129
- }
130
- create.extractEvent = extractEvent;
131
- })(create || (create = {}));
132
- /**
133
- * Creates a new policy.
134
- *
135
- * @example
136
- * ```ts
137
- * import { createClient, http } from 'viem'
138
- * import { tempo } from 'tempo.ts/chains'
139
- * import { Actions } from 'tempo.ts/viem'
140
- * import { privateKeyToAccount } from 'viem/accounts'
141
- *
142
- * const client = createClient({
143
- * account: privateKeyToAccount('0x...'),
144
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
145
- * transport: http(),
146
- * })
147
- *
148
- * const result = await Actions.policy.createSync(client, {
149
- * admin: '0x...',
150
- * type: 'whitelist',
151
- * })
152
- * ```
153
- *
154
- * @param client - Client.
155
- * @param parameters - Parameters.
156
- * @returns The transaction receipt and event data.
157
- */
158
- export async function createSync(client, parameters) {
159
- const { throwOnReceiptRevert = true, ...rest } = parameters;
160
- const receipt = await create.inner(writeContractSync, client, {
161
- ...rest,
162
- throwOnReceiptRevert,
163
- });
164
- const { args } = create.extractEvent(receipt.logs);
165
- return {
166
- ...args,
167
- receipt,
168
- };
169
- }
170
- /**
171
- * Sets the admin for a policy.
172
- *
173
- * @example
174
- * ```ts
175
- * import { createClient, http } from 'viem'
176
- * import { tempo } from 'tempo.ts/chains'
177
- * import { Actions } from 'tempo.ts/viem'
178
- * import { privateKeyToAccount } from 'viem/accounts'
179
- *
180
- * const client = createClient({
181
- * account: privateKeyToAccount('0x...'),
182
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
183
- * transport: http(),
184
- * })
185
- *
186
- * const hash = await Actions.policy.setAdmin(client, {
187
- * policyId: 2n,
188
- * admin: '0x...',
189
- * })
190
- * ```
191
- *
192
- * @param client - Client.
193
- * @param parameters - Parameters.
194
- * @returns The transaction hash.
195
- */
196
- export async function setAdmin(client, parameters) {
197
- return setAdmin.inner(writeContract, client, parameters);
198
- }
199
- (function (setAdmin) {
200
- /** @internal */
201
- async function inner(action, client, parameters) {
202
- const { policyId, admin, ...rest } = parameters;
203
- const call = setAdmin.call({ policyId, admin });
204
- return (await action(client, {
205
- ...rest,
206
- ...call,
207
- }));
208
- }
209
- setAdmin.inner = inner;
210
- /**
211
- * Defines a call to the `setPolicyAdmin` function.
212
- *
213
- * Can be passed as a parameter to:
214
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
215
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
216
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
217
- *
218
- * @example
219
- * ```ts
220
- * import { createClient, http, walletActions } from 'viem'
221
- * import { tempo } from 'tempo.ts/chains'
222
- * import { Actions } from 'tempo.ts/viem'
223
- *
224
- * const client = createClient({
225
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
226
- * transport: http(),
227
- * }).extend(walletActions)
228
- *
229
- * const { result } = await client.sendCalls({
230
- * calls: [
231
- * actions.policy.setAdmin.call({
232
- * policyId: 2n,
233
- * admin: '0xfeed...fede',
234
- * }),
235
- * actions.policy.setAdmin.call({
236
- * policyId: 3n,
237
- * admin: '0xfeed...babe',
238
- * }),
239
- * ]
240
- * })
241
- * ```
242
- *
243
- * @param args - Arguments.
244
- * @returns The call.
245
- */
246
- function call(args) {
247
- const { policyId, admin } = args;
248
- return defineCall({
249
- address: Addresses.tip403Registry,
250
- abi: Abis.tip403Registry,
251
- functionName: 'setPolicyAdmin',
252
- args: [policyId, admin],
253
- });
254
- }
255
- setAdmin.call = call;
256
- /**
257
- * Extracts the `PolicyAdminUpdated` event from logs.
258
- *
259
- * @param logs - The logs.
260
- * @returns The `PolicyAdminUpdated` event.
261
- */
262
- function extractEvent(logs) {
263
- const [log] = parseEventLogs({
264
- abi: Abis.tip403Registry,
265
- logs,
266
- eventName: 'PolicyAdminUpdated',
267
- strict: true,
268
- });
269
- if (!log)
270
- throw new Error('`PolicyAdminUpdated` event not found.');
271
- return log;
272
- }
273
- setAdmin.extractEvent = extractEvent;
274
- })(setAdmin || (setAdmin = {}));
275
- /**
276
- * Sets the admin for a policy.
277
- *
278
- * @example
279
- * ```ts
280
- * import { createClient, http } from 'viem'
281
- * import { tempo } from 'tempo.ts/chains'
282
- * import { Actions } from 'tempo.ts/viem'
283
- * import { privateKeyToAccount } from 'viem/accounts'
284
- *
285
- * const client = createClient({
286
- * account: privateKeyToAccount('0x...'),
287
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
288
- * transport: http(),
289
- * })
290
- *
291
- * const result = await Actions.policy.setAdminSync(client, {
292
- * policyId: 2n,
293
- * admin: '0x...',
294
- * })
295
- * ```
296
- *
297
- * @param client - Client.
298
- * @param parameters - Parameters.
299
- * @returns The transaction receipt and event data.
300
- */
301
- export async function setAdminSync(client, parameters) {
302
- const { throwOnReceiptRevert = true, ...rest } = parameters;
303
- const receipt = await setAdmin.inner(writeContractSync, client, {
304
- ...rest,
305
- throwOnReceiptRevert,
306
- });
307
- const { args } = setAdmin.extractEvent(receipt.logs);
308
- return {
309
- ...args,
310
- receipt,
311
- };
312
- }
313
- /**
314
- * Modifies a policy whitelist.
315
- *
316
- * @example
317
- * ```ts
318
- * import { createClient, http } from 'viem'
319
- * import { tempo } from 'tempo.ts/chains'
320
- * import { Actions } from 'tempo.ts/viem'
321
- * import { privateKeyToAccount } from 'viem/accounts'
322
- *
323
- * const client = createClient({
324
- * account: privateKeyToAccount('0x...'),
325
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
326
- * transport: http(),
327
- * })
328
- *
329
- * const hash = await Actions.policy.modifyWhitelist(client, {
330
- * policyId: 2n,
331
- * account: '0x...',
332
- * allowed: true,
333
- * })
334
- * ```
335
- *
336
- * @param client - Client.
337
- * @param parameters - Parameters.
338
- * @returns The transaction hash.
339
- */
340
- export async function modifyWhitelist(client, parameters) {
341
- return modifyWhitelist.inner(writeContract, client, parameters);
342
- }
343
- (function (modifyWhitelist) {
344
- /** @internal */
345
- async function inner(action, client, parameters) {
346
- const { address: targetAccount, allowed, policyId, ...rest } = parameters;
347
- const call = modifyWhitelist.call({
348
- address: targetAccount,
349
- allowed,
350
- policyId,
351
- });
352
- return (await action(client, {
353
- ...rest,
354
- ...call,
355
- }));
356
- }
357
- modifyWhitelist.inner = inner;
358
- /**
359
- * Defines a call to the `modifyPolicyWhitelist` function.
360
- *
361
- * Can be passed as a parameter to:
362
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
363
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
364
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
365
- *
366
- * @example
367
- * ```ts
368
- * import { createClient, http, walletActions } from 'viem'
369
- * import { tempo } from 'tempo.ts/chains'
370
- * import { Actions } from 'tempo.ts/viem'
371
- *
372
- * const client = createClient({
373
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
374
- * transport: http(),
375
- * }).extend(walletActions)
376
- *
377
- * const { result } = await client.sendCalls({
378
- * calls: [
379
- * actions.policy.modifyWhitelist.call({
380
- * policyId: 2n,
381
- * address: '0x20c0...beef',
382
- * allowed: true,
383
- * }),
384
- * actions.policy.modifyWhitelist.call({
385
- * policyId: 2n,
386
- * address: '0x20c0...babe',
387
- * allowed: false,
388
- * }),
389
- * ]
390
- * })
391
- * ```
392
- *
393
- * @param args - Arguments.
394
- * @returns The call.
395
- */
396
- function call(args) {
397
- const { policyId, address, allowed } = args;
398
- return defineCall({
399
- address: Addresses.tip403Registry,
400
- abi: Abis.tip403Registry,
401
- functionName: 'modifyPolicyWhitelist',
402
- args: [policyId, address, allowed],
403
- });
404
- }
405
- modifyWhitelist.call = call;
406
- /**
407
- * Extracts the `WhitelistUpdated` event from logs.
408
- *
409
- * @param logs - The logs.
410
- * @returns The `WhitelistUpdated` event.
411
- */
412
- function extractEvent(logs) {
413
- const [log] = parseEventLogs({
414
- abi: Abis.tip403Registry,
415
- logs,
416
- eventName: 'WhitelistUpdated',
417
- strict: true,
418
- });
419
- if (!log)
420
- throw new Error('`WhitelistUpdated` event not found.');
421
- return log;
422
- }
423
- modifyWhitelist.extractEvent = extractEvent;
424
- })(modifyWhitelist || (modifyWhitelist = {}));
425
- /**
426
- * Modifies a policy whitelist.
427
- *
428
- * @example
429
- * ```ts
430
- * import { createClient, http } from 'viem'
431
- * import { tempo } from 'tempo.ts/chains'
432
- * import { Actions } from 'tempo.ts/viem'
433
- * import { privateKeyToAccount } from 'viem/accounts'
434
- *
435
- * const client = createClient({
436
- * account: privateKeyToAccount('0x...'),
437
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
438
- * transport: http(),
439
- * })
440
- *
441
- * const result = await Actions.policy.modifyWhitelistSync(client, {
442
- * policyId: 2n,
443
- * account: '0x...',
444
- * allowed: true,
445
- * })
446
- * ```
447
- *
448
- * @param client - Client.
449
- * @param parameters - Parameters.
450
- * @returns The transaction receipt and event data.
451
- */
452
- export async function modifyWhitelistSync(client, parameters) {
453
- const { throwOnReceiptRevert = true, ...rest } = parameters;
454
- const receipt = await modifyWhitelist.inner(writeContractSync, client, {
455
- ...rest,
456
- throwOnReceiptRevert,
457
- });
458
- const { args } = modifyWhitelist.extractEvent(receipt.logs);
459
- return {
460
- ...args,
461
- receipt,
462
- };
463
- }
464
- /**
465
- * Modifies a policy blacklist.
466
- *
467
- * @example
468
- * ```ts
469
- * import { createClient, http } from 'viem'
470
- * import { tempo } from 'tempo.ts/chains'
471
- * import { Actions } from 'tempo.ts/viem'
472
- * import { privateKeyToAccount } from 'viem/accounts'
473
- *
474
- * const client = createClient({
475
- * account: privateKeyToAccount('0x...'),
476
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
477
- * transport: http(),
478
- * })
479
- *
480
- * const hash = await Actions.policy.modifyBlacklist(client, {
481
- * policyId: 2n,
482
- * account: '0x...',
483
- * restricted: true,
484
- * })
485
- * ```
486
- *
487
- * @param client - Client.
488
- * @param parameters - Parameters.
489
- * @returns The transaction hash.
490
- */
491
- export async function modifyBlacklist(client, parameters) {
492
- return modifyBlacklist.inner(writeContract, client, parameters);
493
- }
494
- (function (modifyBlacklist) {
495
- /** @internal */
496
- async function inner(action, client, parameters) {
497
- const { address: targetAccount, policyId, restricted, ...rest } = parameters;
498
- const call = modifyBlacklist.call({
499
- address: targetAccount,
500
- policyId,
501
- restricted,
502
- });
503
- return (await action(client, {
504
- ...rest,
505
- ...call,
506
- }));
507
- }
508
- modifyBlacklist.inner = inner;
509
- /**
510
- * Defines a call to the `modifyPolicyBlacklist` function.
511
- *
512
- * Can be passed as a parameter to:
513
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
514
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
515
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
516
- *
517
- * @example
518
- * ```ts
519
- * import { createClient, http, walletActions } from 'viem'
520
- * import { tempo } from 'tempo.ts/chains'
521
- * import { Actions } from 'tempo.ts/viem'
522
- *
523
- * const client = createClient({
524
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
525
- * transport: http(),
526
- * }).extend(walletActions)
527
- *
528
- * const { result } = await client.sendCalls({
529
- * calls: [
530
- * actions.policy.modifyBlacklist.call({
531
- * policyId: 2n,
532
- * address: '0x20c0...beef',
533
- * restricted: true,
534
- * }),
535
- * actions.policy.modifyBlacklist.call({
536
- * policyId: 2n,
537
- * address: '0x20c0...babe',
538
- * restricted: false,
539
- * }),
540
- * ]
541
- * })
542
- * ```
543
- *
544
- * @param args - Arguments.
545
- * @returns The call.
546
- */
547
- function call(args) {
548
- const { policyId, address, restricted } = args;
549
- return defineCall({
550
- address: Addresses.tip403Registry,
551
- abi: Abis.tip403Registry,
552
- functionName: 'modifyPolicyBlacklist',
553
- args: [policyId, address, restricted],
554
- });
555
- }
556
- modifyBlacklist.call = call;
557
- /**
558
- * Extracts the `BlacklistUpdated` event from logs.
559
- *
560
- * @param logs - The logs.
561
- * @returns The `BlacklistUpdated` event.
562
- */
563
- function extractEvent(logs) {
564
- const [log] = parseEventLogs({
565
- abi: Abis.tip403Registry,
566
- logs,
567
- eventName: 'BlacklistUpdated',
568
- strict: true,
569
- });
570
- if (!log)
571
- throw new Error('`BlacklistUpdated` event not found.');
572
- return log;
573
- }
574
- modifyBlacklist.extractEvent = extractEvent;
575
- })(modifyBlacklist || (modifyBlacklist = {}));
576
- /**
577
- * Modifies a policy blacklist.
578
- *
579
- * @example
580
- * ```ts
581
- * import { createClient, http } from 'viem'
582
- * import { tempo } from 'tempo.ts/chains'
583
- * import { Actions } from 'tempo.ts/viem'
584
- * import { privateKeyToAccount } from 'viem/accounts'
585
- *
586
- * const client = createClient({
587
- * account: privateKeyToAccount('0x...'),
588
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
589
- * transport: http(),
590
- * })
591
- *
592
- * const result = await Actions.policy.modifyBlacklistSync(client, {
593
- * policyId: 2n,
594
- * account: '0x...',
595
- * restricted: true,
596
- * })
597
- * ```
598
- *
599
- * @param client - Client.
600
- * @param parameters - Parameters.
601
- * @returns The transaction receipt and event data.
602
- */
603
- export async function modifyBlacklistSync(client, parameters) {
604
- const { throwOnReceiptRevert = true, ...rest } = parameters;
605
- const receipt = await modifyBlacklist.inner(writeContractSync, client, {
606
- ...rest,
607
- throwOnReceiptRevert,
608
- });
609
- const { args } = modifyBlacklist.extractEvent(receipt.logs);
610
- return {
611
- ...args,
612
- receipt,
613
- };
614
- }
615
- /**
616
- * Gets policy data.
617
- *
618
- * @example
619
- * ```ts
620
- * import { createClient, http } from 'viem'
621
- * import { tempo } from 'tempo.ts/chains'
622
- * import { Actions } from 'tempo.ts/viem'
623
- *
624
- * const client = createClient({
625
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
626
- * transport: http(),
627
- * })
628
- *
629
- * const data = await Actions.policy.getData(client, {
630
- * policyId: 2n,
631
- * })
632
- * ```
633
- *
634
- * @param client - Client.
635
- * @param parameters - Parameters.
636
- * @returns The policy data.
637
- */
638
- export async function getData(client, parameters) {
639
- const { policyId, ...rest } = parameters;
640
- const result = await readContract(client, {
641
- ...rest,
642
- ...getData.call({ policyId }),
643
- });
644
- return {
645
- admin: result[1],
646
- type: result[0] === 0 ? 'whitelist' : 'blacklist',
647
- };
648
- }
649
- (function (getData) {
650
- /**
651
- * Defines a call to the `policyData` function.
652
- *
653
- * @param args - Arguments.
654
- * @returns The call.
655
- */
656
- function call(args) {
657
- const { policyId } = args;
658
- return defineCall({
659
- address: Addresses.tip403Registry,
660
- abi: Abis.tip403Registry,
661
- args: [policyId],
662
- functionName: 'policyData',
663
- });
664
- }
665
- getData.call = call;
666
- })(getData || (getData = {}));
667
- /**
668
- * Checks if a user is authorized by a policy.
669
- *
670
- * @example
671
- * ```ts
672
- * import { createClient, http } from 'viem'
673
- * import { tempo } from 'tempo.ts/chains'
674
- * import { Actions } from 'tempo.ts/viem'
675
- *
676
- * const client = createClient({
677
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
678
- * transport: http(),
679
- * })
680
- *
681
- * const authorized = await Actions.policy.isAuthorized(client, {
682
- * policyId: 2n,
683
- * user: '0x...',
684
- * })
685
- * ```
686
- *
687
- * @param client - Client.
688
- * @param parameters - Parameters.
689
- * @returns Whether the user is authorized.
690
- */
691
- export async function isAuthorized(client, parameters) {
692
- const { policyId, user, ...rest } = parameters;
693
- return readContract(client, {
694
- ...rest,
695
- ...isAuthorized.call({ policyId, user }),
696
- });
697
- }
698
- (function (isAuthorized) {
699
- /**
700
- * Defines a call to the `isAuthorized` function.
701
- *
702
- * @param args - Arguments.
703
- * @returns The call.
704
- */
705
- function call(args) {
706
- const { policyId, user } = args;
707
- return defineCall({
708
- address: Addresses.tip403Registry,
709
- abi: Abis.tip403Registry,
710
- args: [policyId, user],
711
- functionName: 'isAuthorized',
712
- });
713
- }
714
- isAuthorized.call = call;
715
- })(isAuthorized || (isAuthorized = {}));
716
- /**
717
- * Watches for policy creation events.
718
- *
719
- * @example
720
- * ```ts
721
- * import { createClient, http } from 'viem'
722
- * import { tempo } from 'tempo.ts/chains'
723
- * import { Actions } from 'tempo.ts/viem'
724
- *
725
- * const client = createClient({
726
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
727
- * transport: http(),
728
- * })
729
- *
730
- * const unwatch = actions.policy.watchCreate(client, {
731
- * onPolicyCreated: (args, log) => {
732
- * console.log('Policy created:', args)
733
- * },
734
- * })
735
- * ```
736
- *
737
- * @param client - Client.
738
- * @param parameters - Parameters.
739
- * @returns A function to unsubscribe from the event.
740
- */
741
- export function watchCreate(client, parameters) {
742
- const { onPolicyCreated, ...rest } = parameters;
743
- return watchContractEvent(client, {
744
- ...rest,
745
- address: Addresses.tip403Registry,
746
- abi: Abis.tip403Registry,
747
- eventName: 'PolicyCreated',
748
- onLogs: (logs) => {
749
- for (const log of logs)
750
- onPolicyCreated({
751
- ...log.args,
752
- type: log.args.policyType === 0 ? 'whitelist' : 'blacklist',
753
- }, log);
754
- },
755
- strict: true,
756
- });
757
- }
758
- /**
759
- * Watches for policy admin update events.
760
- *
761
- * @example
762
- * ```ts
763
- * import { createClient, http } from 'viem'
764
- * import { tempo } from 'tempo.ts/chains'
765
- * import { Actions } from 'tempo.ts/viem'
766
- *
767
- * const client = createClient({
768
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
769
- * transport: http(),
770
- * })
771
- *
772
- * const unwatch = actions.policy.watchAdminUpdated(client, {
773
- * onAdminUpdated: (args, log) => {
774
- * console.log('Policy admin updated:', args)
775
- * },
776
- * })
777
- * ```
778
- *
779
- * @param client - Client.
780
- * @param parameters - Parameters.
781
- * @returns A function to unsubscribe from the event.
782
- */
783
- export function watchAdminUpdated(client, parameters) {
784
- const { onAdminUpdated, ...rest } = parameters;
785
- return watchContractEvent(client, {
786
- ...rest,
787
- address: Addresses.tip403Registry,
788
- abi: Abis.tip403Registry,
789
- eventName: 'PolicyAdminUpdated',
790
- onLogs: (logs) => {
791
- for (const log of logs)
792
- onAdminUpdated(log.args, log);
793
- },
794
- strict: true,
795
- });
796
- }
797
- /**
798
- * Watches for whitelist update events.
799
- *
800
- * @example
801
- * ```ts
802
- * import { createClient, http } from 'viem'
803
- * import { tempo } from 'tempo.ts/chains'
804
- * import { Actions } from 'tempo.ts/viem'
805
- *
806
- * const client = createClient({
807
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
808
- * transport: http(),
809
- * })
810
- *
811
- * const unwatch = actions.policy.watchWhitelistUpdated(client, {
812
- * onWhitelistUpdated: (args, log) => {
813
- * console.log('Whitelist updated:', args)
814
- * },
815
- * })
816
- * ```
817
- *
818
- * @param client - Client.
819
- * @param parameters - Parameters.
820
- * @returns A function to unsubscribe from the event.
821
- */
822
- export function watchWhitelistUpdated(client, parameters) {
823
- const { onWhitelistUpdated, ...rest } = parameters;
824
- return watchContractEvent(client, {
825
- ...rest,
826
- address: Addresses.tip403Registry,
827
- abi: Abis.tip403Registry,
828
- eventName: 'WhitelistUpdated',
829
- onLogs: (logs) => {
830
- for (const log of logs)
831
- onWhitelistUpdated(log.args, log);
832
- },
833
- strict: true,
834
- });
835
- }
836
- /**
837
- * Watches for blacklist update events.
838
- *
839
- * @example
840
- * ```ts
841
- * import { createClient, http } from 'viem'
842
- * import { tempo } from 'tempo.ts/chains'
843
- * import { Actions } from 'tempo.ts/viem'
844
- *
845
- * const client = createClient({
846
- * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
847
- * transport: http(),
848
- * })
849
- *
850
- * const unwatch = actions.policy.watchBlacklistUpdated(client, {
851
- * onBlacklistUpdated: (args, log) => {
852
- * console.log('Blacklist updated:', args)
853
- * },
854
- * })
855
- * ```
856
- *
857
- * @param client - Client.
858
- * @param parameters - Parameters.
859
- * @returns A function to unsubscribe from the event.
860
- */
861
- export function watchBlacklistUpdated(client, parameters) {
862
- const { onBlacklistUpdated, ...rest } = parameters;
863
- return watchContractEvent(client, {
864
- ...rest,
865
- address: Addresses.tip403Registry,
866
- abi: Abis.tip403Registry,
867
- eventName: 'BlacklistUpdated',
868
- onLogs: (logs) => {
869
- for (const log of logs)
870
- onBlacklistUpdated(log.args, log);
871
- },
872
- strict: true,
873
- });
874
- }
875
- //# sourceMappingURL=policy.js.map