viem 2.51.3 → 2.52.2
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.
- package/CHANGELOG.md +32 -0
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/chains/definitions/citrate.js +17 -0
- package/_cjs/chains/definitions/citrate.js.map +1 -0
- package/_cjs/chains/definitions/grav.js +24 -0
- package/_cjs/chains/definitions/grav.js.map +1 -0
- package/_cjs/chains/definitions/ladyChain.js +22 -0
- package/_cjs/chains/definitions/ladyChain.js.map +1 -0
- package/_cjs/chains/definitions/tempoModerato.js +1 -0
- package/_cjs/chains/definitions/tempoModerato.js.map +1 -1
- package/_cjs/chains/definitions/valygoNft.js +37 -0
- package/_cjs/chains/definitions/valygoNft.js.map +1 -0
- package/_cjs/chains/definitions/valygoSmartchain.js +37 -0
- package/_cjs/chains/definitions/valygoSmartchain.js.map +1 -0
- package/_cjs/chains/index.js +23 -13
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/tempo/Abis.js +189 -1
- package/_cjs/tempo/Abis.js.map +1 -1
- package/_cjs/tempo/Account.js +62 -23
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/Addresses.js +3 -1
- package/_cjs/tempo/Addresses.js.map +1 -1
- package/_cjs/tempo/Decorator.js +23 -0
- package/_cjs/tempo/Decorator.js.map +1 -1
- package/_cjs/tempo/Formatters.js +2 -1
- package/_cjs/tempo/Formatters.js.map +1 -1
- package/_cjs/tempo/Hardfork.js +3 -0
- package/_cjs/tempo/Hardfork.js.map +1 -1
- package/_cjs/tempo/Transaction.js +22 -0
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/actions/accessKey.js +238 -72
- package/_cjs/tempo/actions/accessKey.js.map +1 -1
- package/_cjs/tempo/actions/index.js +2 -1
- package/_cjs/tempo/actions/index.js.map +1 -1
- package/_cjs/tempo/actions/receivePolicy.js +363 -0
- package/_cjs/tempo/actions/receivePolicy.js.map +1 -0
- package/_cjs/tempo/chainConfig.js +10 -0
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/index.js +3 -1
- package/_cjs/tempo/index.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/chains/definitions/citrate.js +14 -0
- package/_esm/chains/definitions/citrate.js.map +1 -0
- package/_esm/chains/definitions/grav.js +21 -0
- package/_esm/chains/definitions/grav.js.map +1 -0
- package/_esm/chains/definitions/ladyChain.js +19 -0
- package/_esm/chains/definitions/ladyChain.js.map +1 -0
- package/_esm/chains/definitions/tempoModerato.js +1 -0
- package/_esm/chains/definitions/tempoModerato.js.map +1 -1
- package/_esm/chains/definitions/valygoNft.js +34 -0
- package/_esm/chains/definitions/valygoNft.js.map +1 -0
- package/_esm/chains/definitions/valygoSmartchain.js +34 -0
- package/_esm/chains/definitions/valygoSmartchain.js.map +1 -0
- package/_esm/chains/index.js +5 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/tempo/Abis.js +188 -0
- package/_esm/tempo/Abis.js.map +1 -1
- package/_esm/tempo/Account.js +116 -24
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/Addresses.js +2 -0
- package/_esm/tempo/Addresses.js.map +1 -1
- package/_esm/tempo/Decorator.js +23 -0
- package/_esm/tempo/Decorator.js.map +1 -1
- package/_esm/tempo/Formatters.js +5 -1
- package/_esm/tempo/Formatters.js.map +1 -1
- package/_esm/tempo/Hardfork.js +3 -0
- package/_esm/tempo/Hardfork.js.map +1 -1
- package/_esm/tempo/Transaction.js +34 -0
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/actions/accessKey.js +562 -128
- package/_esm/tempo/actions/accessKey.js.map +1 -1
- package/_esm/tempo/actions/index.js +1 -0
- package/_esm/tempo/actions/index.js.map +1 -1
- package/_esm/tempo/actions/receivePolicy.js +753 -0
- package/_esm/tempo/actions/receivePolicy.js.map +1 -0
- package/_esm/tempo/chainConfig.js +24 -1
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/index.js +1 -1
- package/_esm/tempo/index.js.map +1 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts +12 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/chains/definitions/citrate.d.ts +57 -0
- package/_types/chains/definitions/citrate.d.ts.map +1 -0
- package/_types/chains/definitions/grav.d.ts +43 -0
- package/_types/chains/definitions/grav.d.ts.map +1 -0
- package/_types/chains/definitions/ladyChain.d.ts +50 -0
- package/_types/chains/definitions/ladyChain.d.ts.map +1 -0
- package/_types/chains/definitions/tempo.d.ts +36 -0
- package/_types/chains/definitions/tempo.d.ts.map +1 -1
- package/_types/chains/definitions/tempoDevnet.d.ts +36 -0
- package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempoLocalnet.d.ts +36 -0
- package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempoModerato.d.ts +38 -0
- package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
- package/_types/chains/definitions/valygoNft.d.ts +48 -0
- package/_types/chains/definitions/valygoNft.d.ts.map +1 -0
- package/_types/chains/definitions/valygoSmartchain.d.ts +48 -0
- package/_types/chains/definitions/valygoSmartchain.d.ts.map +1 -0
- package/_types/chains/index.d.ts +5 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/tempo/Abis.d.ts +671 -4
- package/_types/tempo/Abis.d.ts.map +1 -1
- package/_types/tempo/Account.d.ts +61 -3
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Addresses.d.ts +2 -0
- package/_types/tempo/Addresses.d.ts.map +1 -1
- package/_types/tempo/Decorator.d.ts +501 -0
- package/_types/tempo/Decorator.d.ts.map +1 -1
- package/_types/tempo/Formatters.d.ts.map +1 -1
- package/_types/tempo/Hardfork.d.ts +1 -1
- package/_types/tempo/Hardfork.d.ts.map +1 -1
- package/_types/tempo/Transaction.d.ts +5 -1
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/actions/accessKey.d.ts +1520 -304
- package/_types/tempo/actions/accessKey.d.ts.map +1 -1
- package/_types/tempo/actions/dex.d.ts +75 -0
- package/_types/tempo/actions/dex.d.ts.map +1 -1
- package/_types/tempo/actions/index.d.ts +1 -0
- package/_types/tempo/actions/index.d.ts.map +1 -1
- package/_types/tempo/actions/policy.d.ts +352 -0
- package/_types/tempo/actions/policy.d.ts.map +1 -1
- package/_types/tempo/actions/receivePolicy.d.ts +1511 -0
- package/_types/tempo/actions/receivePolicy.d.ts.map +1 -0
- package/_types/tempo/chainConfig.d.ts +34 -15
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/index.d.ts +1 -1
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/tempo/zones/zone.d.ts +108 -0
- package/_types/tempo/zones/zone.d.ts.map +1 -1
- package/actions/wallet/prepareTransactionRequest.ts +40 -5
- package/chains/definitions/citrate.ts +14 -0
- package/chains/definitions/grav.ts +21 -0
- package/chains/definitions/ladyChain.ts +19 -0
- package/chains/definitions/tempoModerato.ts +1 -0
- package/chains/definitions/valygoNft.ts +34 -0
- package/chains/definitions/valygoSmartchain.ts +34 -0
- package/chains/index.ts +5 -0
- package/errors/version.ts +1 -1
- package/package.json +3 -4
- package/tempo/Abis.ts +189 -0
- package/tempo/Account.ts +153 -31
- package/tempo/Addresses.ts +2 -0
- package/tempo/Decorator.ts +578 -0
- package/tempo/Formatters.ts +12 -1
- package/tempo/Hardfork.ts +3 -0
- package/tempo/Transaction.ts +42 -0
- package/tempo/actions/accessKey.ts +1002 -279
- package/tempo/actions/index.ts +1 -0
- package/tempo/actions/receivePolicy.ts +1266 -0
- package/tempo/chainConfig.ts +32 -3
- package/tempo/index.ts +2 -0
|
@@ -0,0 +1,1266 @@
|
|
|
1
|
+
import type { Address } from 'abitype'
|
|
2
|
+
import type { ReceivePolicyReceipt } from 'ox/tempo'
|
|
3
|
+
import type { Account } from '../../accounts/types.js'
|
|
4
|
+
import { parseAccount } from '../../accounts/utils/parseAccount.js'
|
|
5
|
+
import type { ReadContractReturnType } from '../../actions/public/readContract.js'
|
|
6
|
+
import { readContract } from '../../actions/public/readContract.js'
|
|
7
|
+
import type { WatchContractEventParameters } from '../../actions/public/watchContractEvent.js'
|
|
8
|
+
import { watchContractEvent } from '../../actions/public/watchContractEvent.js'
|
|
9
|
+
import type { WriteContractReturnType } from '../../actions/wallet/writeContract.js'
|
|
10
|
+
import { writeContract } from '../../actions/wallet/writeContract.js'
|
|
11
|
+
import { writeContractSync } from '../../actions/wallet/writeContractSync.js'
|
|
12
|
+
import type { Client } from '../../clients/createClient.js'
|
|
13
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
|
14
|
+
import { zeroAddress } from '../../constants/address.js'
|
|
15
|
+
import type { BaseErrorType } from '../../errors/base.js'
|
|
16
|
+
import type { Chain } from '../../types/chain.js'
|
|
17
|
+
import type { ExtractAbiItem, GetEventArgs } from '../../types/contract.js'
|
|
18
|
+
import type { Log, Log as viem_Log } from '../../types/log.js'
|
|
19
|
+
import type { Hex } from '../../types/misc.js'
|
|
20
|
+
import type { Compute, UnionOmit } from '../../types/utils.js'
|
|
21
|
+
import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
|
|
22
|
+
import { isAddressEqual } from '../../utils/index.js'
|
|
23
|
+
import * as Abis from '../Abis.js'
|
|
24
|
+
import * as Addresses from '../Addresses.js'
|
|
25
|
+
import type {
|
|
26
|
+
GetAccountParameter,
|
|
27
|
+
ReadParameters,
|
|
28
|
+
WriteParameters,
|
|
29
|
+
} from '../internal/types.js'
|
|
30
|
+
import { defineCall } from '../internal/utils.js'
|
|
31
|
+
import type { TransactionReceipt } from '../Transaction.js'
|
|
32
|
+
|
|
33
|
+
/** TIP-403 policy type. */
|
|
34
|
+
export type PolicyType = 'whitelist' | 'blacklist'
|
|
35
|
+
|
|
36
|
+
/** @internal */
|
|
37
|
+
const policyTypes = ['whitelist', 'blacklist'] as const
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Reference to a TIP-403 policy.
|
|
41
|
+
*
|
|
42
|
+
* - `'reject-all'` – built-in policy that rejects everything (id `0`).
|
|
43
|
+
* - `'allow-all'` – built-in policy that allows everything (id `1`).
|
|
44
|
+
* - `bigint` – a custom policy id (`>= 2`), e.g. one returned by
|
|
45
|
+
* {@link policy.create}.
|
|
46
|
+
*/
|
|
47
|
+
export type PolicyRef = 'reject-all' | 'allow-all' | bigint
|
|
48
|
+
|
|
49
|
+
/** @internal Built-in TIP-403 policy id that rejects everything. */
|
|
50
|
+
const rejectAllPolicyId = 0n
|
|
51
|
+
/** @internal Built-in TIP-403 policy id that allows everything. */
|
|
52
|
+
const allowAllPolicyId = 1n
|
|
53
|
+
|
|
54
|
+
/** Reason an inbound transfer or mint was blocked by a receive policy. */
|
|
55
|
+
export type BlockedReason = ReceivePolicyReceipt.BlockedReason
|
|
56
|
+
|
|
57
|
+
/** @internal */
|
|
58
|
+
const blockedReasons = ['none', 'tokenFilter', 'receivePolicy'] as const
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Claimer authorized to reclaim blocked funds.
|
|
62
|
+
*
|
|
63
|
+
* - `'sender'` – the originator of the funds may reclaim them (default).
|
|
64
|
+
* - `'self'` – the account configuring the policy may reclaim them.
|
|
65
|
+
* - `Address` – a delegated third party may reclaim them.
|
|
66
|
+
*/
|
|
67
|
+
export type Claimer = 'sender' | 'self' | Address
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Burns the funds backing a blocked receipt.
|
|
71
|
+
*
|
|
72
|
+
* Requires the caller to hold the token's `BURN_BLOCKED_ROLE`, and is only
|
|
73
|
+
* valid when the receipt's policy subject is currently unauthorized as a sender
|
|
74
|
+
* under the token's TIP-403 policy.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { createClient, http } from 'viem'
|
|
79
|
+
* import { tempo } from 'viem/chains'
|
|
80
|
+
* import { Actions } from 'viem/tempo'
|
|
81
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
82
|
+
*
|
|
83
|
+
* const client = createClient({
|
|
84
|
+
* account: privateKeyToAccount('0x...'),
|
|
85
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
86
|
+
* transport: http(),
|
|
87
|
+
* })
|
|
88
|
+
*
|
|
89
|
+
* const hash = await Actions.receivePolicy.burn(client, {
|
|
90
|
+
* receipt: '0x...',
|
|
91
|
+
* })
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @param client - Client.
|
|
95
|
+
* @param parameters - Parameters.
|
|
96
|
+
* @returns The transaction hash.
|
|
97
|
+
*/
|
|
98
|
+
export async function burn<
|
|
99
|
+
chain extends Chain | undefined,
|
|
100
|
+
account extends Account | undefined,
|
|
101
|
+
>(
|
|
102
|
+
client: Client<Transport, chain, account>,
|
|
103
|
+
parameters: burn.Parameters<chain, account>,
|
|
104
|
+
): Promise<burn.ReturnValue> {
|
|
105
|
+
return burn.inner(writeContract, client, parameters)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export namespace burn {
|
|
109
|
+
export type Parameters<
|
|
110
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
111
|
+
account extends Account | undefined = Account | undefined,
|
|
112
|
+
> = WriteParameters<chain, account> & Args
|
|
113
|
+
|
|
114
|
+
export type Args = {
|
|
115
|
+
/** The encoded claim receipt (witness from a `TransferBlocked` event). */
|
|
116
|
+
receipt: Hex
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type ReturnValue = WriteContractReturnType
|
|
120
|
+
|
|
121
|
+
// TODO: exhaustive error type
|
|
122
|
+
export type ErrorType = BaseErrorType
|
|
123
|
+
|
|
124
|
+
/** @internal */
|
|
125
|
+
export async function inner<
|
|
126
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
127
|
+
chain extends Chain | undefined,
|
|
128
|
+
account extends Account | undefined,
|
|
129
|
+
>(
|
|
130
|
+
action: action,
|
|
131
|
+
client: Client<Transport, chain, account>,
|
|
132
|
+
parameters: Parameters<chain, account>,
|
|
133
|
+
): Promise<ReturnType<action>> {
|
|
134
|
+
const {
|
|
135
|
+
account = client.account,
|
|
136
|
+
chain = client.chain,
|
|
137
|
+
receipt,
|
|
138
|
+
...rest
|
|
139
|
+
} = parameters
|
|
140
|
+
|
|
141
|
+
if (!account) throw new Error('`account` is required')
|
|
142
|
+
|
|
143
|
+
const call = burn.call({ receipt })
|
|
144
|
+
return action(client, {
|
|
145
|
+
...rest,
|
|
146
|
+
account,
|
|
147
|
+
chain,
|
|
148
|
+
...call,
|
|
149
|
+
} as never) as never
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Defines a call to the `burnBlockedReceipt` function.
|
|
154
|
+
*
|
|
155
|
+
* @param args - Arguments.
|
|
156
|
+
* @returns The call.
|
|
157
|
+
*/
|
|
158
|
+
export function call(args: Args) {
|
|
159
|
+
const { receipt } = args
|
|
160
|
+
return defineCall({
|
|
161
|
+
address: Addresses.receivePolicyGuard,
|
|
162
|
+
abi: Abis.receivePolicyGuard,
|
|
163
|
+
functionName: 'burnBlockedReceipt',
|
|
164
|
+
args: [receipt],
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Extracts the `ReceiptBurned` event from logs.
|
|
170
|
+
*
|
|
171
|
+
* @param logs - The logs.
|
|
172
|
+
* @returns The `ReceiptBurned` event.
|
|
173
|
+
*/
|
|
174
|
+
export function extractEvent(logs: Log[]) {
|
|
175
|
+
const [log] = parseEventLogs({
|
|
176
|
+
abi: Abis.receivePolicyGuard,
|
|
177
|
+
logs,
|
|
178
|
+
eventName: 'ReceiptBurned',
|
|
179
|
+
strict: true,
|
|
180
|
+
})
|
|
181
|
+
if (!log) throw new Error('`ReceiptBurned` event not found.')
|
|
182
|
+
return log
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Burns the funds backing a blocked receipt and waits for the receipt.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* import { createClient, http } from 'viem'
|
|
192
|
+
* import { tempo } from 'viem/chains'
|
|
193
|
+
* import { Actions } from 'viem/tempo'
|
|
194
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
195
|
+
*
|
|
196
|
+
* const client = createClient({
|
|
197
|
+
* account: privateKeyToAccount('0x...'),
|
|
198
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
199
|
+
* transport: http(),
|
|
200
|
+
* })
|
|
201
|
+
*
|
|
202
|
+
* const { receipt, ...result } = await Actions.receivePolicy.burnSync(client, {
|
|
203
|
+
* receipt: '0x...',
|
|
204
|
+
* })
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @param client - Client.
|
|
208
|
+
* @param parameters - Parameters.
|
|
209
|
+
* @returns The transaction receipt and event data.
|
|
210
|
+
*/
|
|
211
|
+
export async function burnSync<
|
|
212
|
+
chain extends Chain | undefined,
|
|
213
|
+
account extends Account | undefined,
|
|
214
|
+
>(
|
|
215
|
+
client: Client<Transport, chain, account>,
|
|
216
|
+
parameters: burnSync.Parameters<chain, account>,
|
|
217
|
+
): Promise<burnSync.ReturnValue> {
|
|
218
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
219
|
+
const receipt = await burn.inner(writeContractSync, client, {
|
|
220
|
+
...rest,
|
|
221
|
+
throwOnReceiptRevert,
|
|
222
|
+
} as never)
|
|
223
|
+
const { args } = burn.extractEvent(receipt.logs)
|
|
224
|
+
return {
|
|
225
|
+
...args,
|
|
226
|
+
receipt,
|
|
227
|
+
} as never
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export namespace burnSync {
|
|
231
|
+
export type Parameters<
|
|
232
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
233
|
+
account extends Account | undefined = Account | undefined,
|
|
234
|
+
> = burn.Parameters<chain, account>
|
|
235
|
+
|
|
236
|
+
export type Args = burn.Args
|
|
237
|
+
|
|
238
|
+
export type ReturnValue = Compute<
|
|
239
|
+
GetEventArgs<
|
|
240
|
+
typeof Abis.receivePolicyGuard,
|
|
241
|
+
'ReceiptBurned',
|
|
242
|
+
{ IndexedOnly: false; Required: true }
|
|
243
|
+
> & {
|
|
244
|
+
receipt: TransactionReceipt
|
|
245
|
+
}
|
|
246
|
+
>
|
|
247
|
+
|
|
248
|
+
// TODO: exhaustive error type
|
|
249
|
+
export type ErrorType = BaseErrorType
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Claims blocked funds for a receipt, releasing them to a destination.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* import { createClient, http } from 'viem'
|
|
258
|
+
* import { tempo } from 'viem/chains'
|
|
259
|
+
* import { Actions } from 'viem/tempo'
|
|
260
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
261
|
+
*
|
|
262
|
+
* const client = createClient({
|
|
263
|
+
* account: privateKeyToAccount('0x...'),
|
|
264
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
265
|
+
* transport: http(),
|
|
266
|
+
* })
|
|
267
|
+
*
|
|
268
|
+
* const hash = await Actions.receivePolicy.claim(client, {
|
|
269
|
+
* to: '0x...',
|
|
270
|
+
* receipt: '0x...',
|
|
271
|
+
* })
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
274
|
+
* @param client - Client.
|
|
275
|
+
* @param parameters - Parameters.
|
|
276
|
+
* @returns The transaction hash.
|
|
277
|
+
*/
|
|
278
|
+
export async function claim<
|
|
279
|
+
chain extends Chain | undefined,
|
|
280
|
+
account extends Account | undefined,
|
|
281
|
+
>(
|
|
282
|
+
client: Client<Transport, chain, account>,
|
|
283
|
+
parameters: claim.Parameters<chain, account>,
|
|
284
|
+
): Promise<claim.ReturnValue> {
|
|
285
|
+
return claim.inner(writeContract, client, parameters)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export namespace claim {
|
|
289
|
+
export type Parameters<
|
|
290
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
291
|
+
account extends Account | undefined = Account | undefined,
|
|
292
|
+
> = WriteParameters<chain, account> & Args
|
|
293
|
+
|
|
294
|
+
export type Args = {
|
|
295
|
+
/** Destination to release the blocked funds to. */
|
|
296
|
+
to: Address
|
|
297
|
+
/** The encoded claim receipt (witness from a `TransferBlocked` event). */
|
|
298
|
+
receipt: Hex
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export type ReturnValue = WriteContractReturnType
|
|
302
|
+
|
|
303
|
+
// TODO: exhaustive error type
|
|
304
|
+
export type ErrorType = BaseErrorType
|
|
305
|
+
|
|
306
|
+
/** @internal */
|
|
307
|
+
export async function inner<
|
|
308
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
309
|
+
chain extends Chain | undefined,
|
|
310
|
+
account extends Account | undefined,
|
|
311
|
+
>(
|
|
312
|
+
action: action,
|
|
313
|
+
client: Client<Transport, chain, account>,
|
|
314
|
+
parameters: Parameters<chain, account>,
|
|
315
|
+
): Promise<ReturnType<action>> {
|
|
316
|
+
const {
|
|
317
|
+
account = client.account,
|
|
318
|
+
chain = client.chain,
|
|
319
|
+
to,
|
|
320
|
+
receipt,
|
|
321
|
+
...rest
|
|
322
|
+
} = parameters
|
|
323
|
+
|
|
324
|
+
if (!account) throw new Error('`account` is required')
|
|
325
|
+
|
|
326
|
+
const call = claim.call({ to, receipt })
|
|
327
|
+
return action(client, {
|
|
328
|
+
...rest,
|
|
329
|
+
account,
|
|
330
|
+
chain,
|
|
331
|
+
...call,
|
|
332
|
+
} as never) as never
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Defines a call to the `claim` function.
|
|
337
|
+
*
|
|
338
|
+
* @param args - Arguments.
|
|
339
|
+
* @returns The call.
|
|
340
|
+
*/
|
|
341
|
+
export function call(args: Args) {
|
|
342
|
+
const { to, receipt } = args
|
|
343
|
+
return defineCall({
|
|
344
|
+
address: Addresses.receivePolicyGuard,
|
|
345
|
+
abi: Abis.receivePolicyGuard,
|
|
346
|
+
functionName: 'claim',
|
|
347
|
+
args: [to, receipt],
|
|
348
|
+
})
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Extracts the `ReceiptClaimed` event from logs.
|
|
353
|
+
*
|
|
354
|
+
* @param logs - The logs.
|
|
355
|
+
* @returns The `ReceiptClaimed` event.
|
|
356
|
+
*/
|
|
357
|
+
export function extractEvent(logs: Log[]) {
|
|
358
|
+
const [log] = parseEventLogs({
|
|
359
|
+
abi: Abis.receivePolicyGuard,
|
|
360
|
+
logs,
|
|
361
|
+
eventName: 'ReceiptClaimed',
|
|
362
|
+
strict: true,
|
|
363
|
+
})
|
|
364
|
+
if (!log) throw new Error('`ReceiptClaimed` event not found.')
|
|
365
|
+
return log
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Claims blocked funds for a receipt and waits for the receipt.
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* ```ts
|
|
374
|
+
* import { createClient, http } from 'viem'
|
|
375
|
+
* import { tempo } from 'viem/chains'
|
|
376
|
+
* import { Actions } from 'viem/tempo'
|
|
377
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
378
|
+
*
|
|
379
|
+
* const client = createClient({
|
|
380
|
+
* account: privateKeyToAccount('0x...'),
|
|
381
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
382
|
+
* transport: http(),
|
|
383
|
+
* })
|
|
384
|
+
*
|
|
385
|
+
* const { receipt, ...result } = await Actions.receivePolicy.claimSync(client, {
|
|
386
|
+
* to: '0x...',
|
|
387
|
+
* receipt: '0x...',
|
|
388
|
+
* })
|
|
389
|
+
* ```
|
|
390
|
+
*
|
|
391
|
+
* @param client - Client.
|
|
392
|
+
* @param parameters - Parameters.
|
|
393
|
+
* @returns The transaction receipt and event data.
|
|
394
|
+
*/
|
|
395
|
+
export async function claimSync<
|
|
396
|
+
chain extends Chain | undefined,
|
|
397
|
+
account extends Account | undefined,
|
|
398
|
+
>(
|
|
399
|
+
client: Client<Transport, chain, account>,
|
|
400
|
+
parameters: claimSync.Parameters<chain, account>,
|
|
401
|
+
): Promise<claimSync.ReturnValue> {
|
|
402
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
403
|
+
const receipt = await claim.inner(writeContractSync, client, {
|
|
404
|
+
...rest,
|
|
405
|
+
throwOnReceiptRevert,
|
|
406
|
+
} as never)
|
|
407
|
+
const { args } = claim.extractEvent(receipt.logs)
|
|
408
|
+
return {
|
|
409
|
+
...args,
|
|
410
|
+
receipt,
|
|
411
|
+
} as never
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export namespace claimSync {
|
|
415
|
+
export type Parameters<
|
|
416
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
417
|
+
account extends Account | undefined = Account | undefined,
|
|
418
|
+
> = claim.Parameters<chain, account>
|
|
419
|
+
|
|
420
|
+
export type Args = claim.Args
|
|
421
|
+
|
|
422
|
+
export type ReturnValue = Compute<
|
|
423
|
+
GetEventArgs<
|
|
424
|
+
typeof Abis.receivePolicyGuard,
|
|
425
|
+
'ReceiptClaimed',
|
|
426
|
+
{ IndexedOnly: false; Required: true }
|
|
427
|
+
> & {
|
|
428
|
+
receipt: TransactionReceipt
|
|
429
|
+
}
|
|
430
|
+
>
|
|
431
|
+
|
|
432
|
+
// TODO: exhaustive error type
|
|
433
|
+
export type ErrorType = BaseErrorType
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Gets the receive policy configured for an account.
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* ```ts
|
|
441
|
+
* import { createClient, http } from 'viem'
|
|
442
|
+
* import { tempo } from 'viem/chains'
|
|
443
|
+
* import { Actions } from 'viem/tempo'
|
|
444
|
+
*
|
|
445
|
+
* const client = createClient({
|
|
446
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
447
|
+
* transport: http(),
|
|
448
|
+
* })
|
|
449
|
+
*
|
|
450
|
+
* const policy = await Actions.receivePolicy.get(client, {
|
|
451
|
+
* account: '0x...',
|
|
452
|
+
* })
|
|
453
|
+
* ```
|
|
454
|
+
*
|
|
455
|
+
* @param client - Client.
|
|
456
|
+
* @param parameters - Parameters.
|
|
457
|
+
* @returns The receive policy.
|
|
458
|
+
*/
|
|
459
|
+
export async function get<
|
|
460
|
+
chain extends Chain | undefined,
|
|
461
|
+
account extends Account | undefined,
|
|
462
|
+
>(
|
|
463
|
+
client: Client<Transport, chain, account>,
|
|
464
|
+
parameters: get.Parameters<account>,
|
|
465
|
+
): Promise<get.ReturnValue> {
|
|
466
|
+
const { account: account_ = client.account, ...rest } = parameters
|
|
467
|
+
if (!account_) throw new Error('`account` is required.')
|
|
468
|
+
const account = parseAccount(account_)
|
|
469
|
+
const [
|
|
470
|
+
hasReceivePolicy,
|
|
471
|
+
senderPolicyId,
|
|
472
|
+
senderPolicyType,
|
|
473
|
+
tokenPolicyId,
|
|
474
|
+
tokenPolicyType,
|
|
475
|
+
recoveryAuthority,
|
|
476
|
+
] = await readContract(client, {
|
|
477
|
+
...rest,
|
|
478
|
+
account: null as never,
|
|
479
|
+
...get.call({ account: account.address }),
|
|
480
|
+
})
|
|
481
|
+
return {
|
|
482
|
+
hasReceivePolicy,
|
|
483
|
+
senderPolicyId: toPolicyRef(senderPolicyId),
|
|
484
|
+
senderPolicyType: policyTypes[senderPolicyType] ?? 'whitelist',
|
|
485
|
+
tokenPolicyId: toPolicyRef(tokenPolicyId),
|
|
486
|
+
tokenPolicyType: policyTypes[tokenPolicyType] ?? 'whitelist',
|
|
487
|
+
claimer: toClaimer(recoveryAuthority, account.address),
|
|
488
|
+
recoveryAuthority,
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
export namespace get {
|
|
493
|
+
export type Parameters<
|
|
494
|
+
account extends Account | undefined = Account | undefined,
|
|
495
|
+
> = ReadParameters & GetAccountParameter<account>
|
|
496
|
+
|
|
497
|
+
export type Args = {
|
|
498
|
+
/** Account address. */
|
|
499
|
+
account: Address
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export type ReturnValue = Compute<{
|
|
503
|
+
/** Whether the account has a receive policy configured. */
|
|
504
|
+
hasReceivePolicy: boolean
|
|
505
|
+
/** TIP-403 policy restricting which senders are allowed. */
|
|
506
|
+
senderPolicyId: PolicyRef
|
|
507
|
+
/** Type of the sender policy. */
|
|
508
|
+
senderPolicyType: PolicyType
|
|
509
|
+
/** TIP-403 policy restricting which tokens are allowed. */
|
|
510
|
+
tokenPolicyId: PolicyRef
|
|
511
|
+
/** Type of the token policy. */
|
|
512
|
+
tokenPolicyType: PolicyType
|
|
513
|
+
/** Who can reclaim funds blocked by this policy. */
|
|
514
|
+
claimer: Claimer
|
|
515
|
+
/** Raw recovery authority address. */
|
|
516
|
+
recoveryAuthority: Address
|
|
517
|
+
}>
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Defines a call to the `receivePolicy` function.
|
|
521
|
+
*
|
|
522
|
+
* @param args - Arguments.
|
|
523
|
+
* @returns The call.
|
|
524
|
+
*/
|
|
525
|
+
export function call(args: Args) {
|
|
526
|
+
const { account } = args
|
|
527
|
+
return defineCall({
|
|
528
|
+
address: Addresses.tip403Registry,
|
|
529
|
+
abi: Abis.tip403Registry,
|
|
530
|
+
functionName: 'receivePolicy',
|
|
531
|
+
args: [account],
|
|
532
|
+
})
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Gets the blocked balance for an encoded receipt.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```ts
|
|
541
|
+
* import { createClient, http } from 'viem'
|
|
542
|
+
* import { tempo } from 'viem/chains'
|
|
543
|
+
* import { Actions } from 'viem/tempo'
|
|
544
|
+
*
|
|
545
|
+
* const client = createClient({
|
|
546
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
547
|
+
* transport: http(),
|
|
548
|
+
* })
|
|
549
|
+
*
|
|
550
|
+
* const amount = await Actions.receivePolicy.getBlockedBalance(client, {
|
|
551
|
+
* receipt: '0x...',
|
|
552
|
+
* })
|
|
553
|
+
* ```
|
|
554
|
+
*
|
|
555
|
+
* @param client - Client.
|
|
556
|
+
* @param parameters - Parameters.
|
|
557
|
+
* @returns The blocked amount for the receipt.
|
|
558
|
+
*/
|
|
559
|
+
export async function getBlockedBalance<chain extends Chain | undefined>(
|
|
560
|
+
client: Client<Transport, chain>,
|
|
561
|
+
parameters: getBlockedBalance.Parameters,
|
|
562
|
+
): Promise<getBlockedBalance.ReturnValue> {
|
|
563
|
+
const { receipt, ...rest } = parameters
|
|
564
|
+
return readContract(client, {
|
|
565
|
+
...rest,
|
|
566
|
+
...getBlockedBalance.call({ receipt }),
|
|
567
|
+
})
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
export namespace getBlockedBalance {
|
|
571
|
+
export type Parameters = ReadParameters & Args
|
|
572
|
+
|
|
573
|
+
export type Args = {
|
|
574
|
+
/** The encoded claim receipt. */
|
|
575
|
+
receipt: Hex
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
export type ReturnValue = ReadContractReturnType<
|
|
579
|
+
typeof Abis.receivePolicyGuard,
|
|
580
|
+
'balanceOf',
|
|
581
|
+
never
|
|
582
|
+
>
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Defines a call to the `balanceOf` function.
|
|
586
|
+
*
|
|
587
|
+
* @param args - Arguments.
|
|
588
|
+
* @returns The call.
|
|
589
|
+
*/
|
|
590
|
+
export function call(args: Args) {
|
|
591
|
+
const { receipt } = args
|
|
592
|
+
return defineCall({
|
|
593
|
+
address: Addresses.receivePolicyGuard,
|
|
594
|
+
abi: Abis.receivePolicyGuard,
|
|
595
|
+
functionName: 'balanceOf',
|
|
596
|
+
args: [receipt],
|
|
597
|
+
})
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Sets the receive policy for the calling account.
|
|
603
|
+
*
|
|
604
|
+
* A receive policy controls which TIP-20 tokens and which senders an account
|
|
605
|
+
* accepts. Inbound transfers and mints that violate the policy are not
|
|
606
|
+
* reverted – instead the funds are redirected to the `ReceivePolicyGuard` and
|
|
607
|
+
* can be reclaimed later (see {@link claim}).
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```ts
|
|
611
|
+
* import { createClient, http } from 'viem'
|
|
612
|
+
* import { tempo } from 'viem/chains'
|
|
613
|
+
* import { Actions } from 'viem/tempo'
|
|
614
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
615
|
+
*
|
|
616
|
+
* const client = createClient({
|
|
617
|
+
* account: privateKeyToAccount('0x...'),
|
|
618
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
619
|
+
* transport: http(),
|
|
620
|
+
* })
|
|
621
|
+
*
|
|
622
|
+
* const hash = await Actions.receivePolicy.set(client, {
|
|
623
|
+
* senderPolicyId: 'allow-all',
|
|
624
|
+
* tokenPolicyId: 'allow-all',
|
|
625
|
+
* claimer: 'self',
|
|
626
|
+
* })
|
|
627
|
+
* ```
|
|
628
|
+
*
|
|
629
|
+
* @param client - Client.
|
|
630
|
+
* @param parameters - Parameters.
|
|
631
|
+
* @returns The transaction hash.
|
|
632
|
+
*/
|
|
633
|
+
export async function set<
|
|
634
|
+
chain extends Chain | undefined,
|
|
635
|
+
account extends Account | undefined,
|
|
636
|
+
>(
|
|
637
|
+
client: Client<Transport, chain, account>,
|
|
638
|
+
parameters: set.Parameters<chain, account>,
|
|
639
|
+
): Promise<set.ReturnValue> {
|
|
640
|
+
return set.inner(writeContract, client, parameters)
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
export namespace set {
|
|
644
|
+
export type Parameters<
|
|
645
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
646
|
+
account extends Account | undefined = Account | undefined,
|
|
647
|
+
> = WriteParameters<chain, account> & Omit<Args, 'recoveryAuthority'>
|
|
648
|
+
|
|
649
|
+
export type Args = {
|
|
650
|
+
/**
|
|
651
|
+
* TIP-403 policy restricting which senders are allowed.
|
|
652
|
+
* @default 'allow-all'
|
|
653
|
+
*/
|
|
654
|
+
senderPolicyId?: PolicyRef | undefined
|
|
655
|
+
/**
|
|
656
|
+
* TIP-403 policy restricting which tokens are allowed.
|
|
657
|
+
* @default 'allow-all'
|
|
658
|
+
*/
|
|
659
|
+
tokenPolicyId?: PolicyRef | undefined
|
|
660
|
+
/**
|
|
661
|
+
* Who can reclaim funds blocked by this policy.
|
|
662
|
+
* @default 'sender'
|
|
663
|
+
*/
|
|
664
|
+
claimer?: Claimer | undefined
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
export type ReturnValue = WriteContractReturnType
|
|
668
|
+
|
|
669
|
+
// TODO: exhaustive error type
|
|
670
|
+
export type ErrorType = BaseErrorType
|
|
671
|
+
|
|
672
|
+
/** @internal */
|
|
673
|
+
export async function inner<
|
|
674
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
675
|
+
chain extends Chain | undefined,
|
|
676
|
+
account extends Account | undefined,
|
|
677
|
+
>(
|
|
678
|
+
action: action,
|
|
679
|
+
client: Client<Transport, chain, account>,
|
|
680
|
+
parameters: Parameters<chain, account>,
|
|
681
|
+
): Promise<ReturnType<action>> {
|
|
682
|
+
const {
|
|
683
|
+
account = client.account,
|
|
684
|
+
chain = client.chain,
|
|
685
|
+
senderPolicyId = 'allow-all',
|
|
686
|
+
tokenPolicyId = 'allow-all',
|
|
687
|
+
claimer = 'sender',
|
|
688
|
+
...rest
|
|
689
|
+
} = parameters
|
|
690
|
+
|
|
691
|
+
if (!account) throw new Error('`account` is required')
|
|
692
|
+
|
|
693
|
+
const address = parseAccount(account).address
|
|
694
|
+
const recoveryAuthority = resolveClaimer(claimer, address)
|
|
695
|
+
|
|
696
|
+
const call = set.call({
|
|
697
|
+
senderPolicyId: resolvePolicyRef(senderPolicyId),
|
|
698
|
+
tokenFilterId: resolvePolicyRef(tokenPolicyId),
|
|
699
|
+
recoveryAuthority,
|
|
700
|
+
})
|
|
701
|
+
return action(client, {
|
|
702
|
+
...rest,
|
|
703
|
+
account,
|
|
704
|
+
chain,
|
|
705
|
+
...call,
|
|
706
|
+
} as never) as never
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Defines a call to the `setReceivePolicy` function.
|
|
711
|
+
*
|
|
712
|
+
* @param args - Arguments.
|
|
713
|
+
* @returns The call.
|
|
714
|
+
*/
|
|
715
|
+
export function call(args: {
|
|
716
|
+
/** Resolved TIP-403 sender policy id. */
|
|
717
|
+
senderPolicyId: bigint
|
|
718
|
+
/** Resolved TIP-403 token filter id. */
|
|
719
|
+
tokenFilterId: bigint
|
|
720
|
+
/** Resolved recovery authority. */
|
|
721
|
+
recoveryAuthority: Address
|
|
722
|
+
}) {
|
|
723
|
+
const { senderPolicyId, tokenFilterId, recoveryAuthority } = args
|
|
724
|
+
return defineCall({
|
|
725
|
+
address: Addresses.tip403Registry,
|
|
726
|
+
abi: Abis.tip403Registry,
|
|
727
|
+
functionName: 'setReceivePolicy',
|
|
728
|
+
args: [senderPolicyId, tokenFilterId, recoveryAuthority],
|
|
729
|
+
})
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Extracts the `ReceivePolicyUpdated` event from logs.
|
|
734
|
+
*
|
|
735
|
+
* @param logs - The logs.
|
|
736
|
+
* @returns The `ReceivePolicyUpdated` event.
|
|
737
|
+
*/
|
|
738
|
+
export function extractEvent(logs: Log[]) {
|
|
739
|
+
const [log] = parseEventLogs({
|
|
740
|
+
abi: Abis.tip403Registry,
|
|
741
|
+
logs,
|
|
742
|
+
eventName: 'ReceivePolicyUpdated',
|
|
743
|
+
strict: true,
|
|
744
|
+
})
|
|
745
|
+
if (!log) throw new Error('`ReceivePolicyUpdated` event not found.')
|
|
746
|
+
return log
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Sets the receive policy for the calling account and waits for the receipt.
|
|
752
|
+
*
|
|
753
|
+
* @example
|
|
754
|
+
* ```ts
|
|
755
|
+
* import { createClient, http } from 'viem'
|
|
756
|
+
* import { tempo } from 'viem/chains'
|
|
757
|
+
* import { Actions } from 'viem/tempo'
|
|
758
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
759
|
+
*
|
|
760
|
+
* const client = createClient({
|
|
761
|
+
* account: privateKeyToAccount('0x...'),
|
|
762
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
763
|
+
* transport: http(),
|
|
764
|
+
* })
|
|
765
|
+
*
|
|
766
|
+
* const { receipt, ...result } = await Actions.receivePolicy.setSync(client, {
|
|
767
|
+
* senderPolicyId: 'allow-all',
|
|
768
|
+
* tokenPolicyId: 'allow-all',
|
|
769
|
+
* claimer: 'self',
|
|
770
|
+
* })
|
|
771
|
+
* ```
|
|
772
|
+
*
|
|
773
|
+
* @param client - Client.
|
|
774
|
+
* @param parameters - Parameters.
|
|
775
|
+
* @returns The transaction receipt and event data.
|
|
776
|
+
*/
|
|
777
|
+
export async function setSync<
|
|
778
|
+
chain extends Chain | undefined,
|
|
779
|
+
account extends Account | undefined,
|
|
780
|
+
>(
|
|
781
|
+
client: Client<Transport, chain, account>,
|
|
782
|
+
parameters: setSync.Parameters<chain, account>,
|
|
783
|
+
): Promise<setSync.ReturnValue> {
|
|
784
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
785
|
+
const receipt = await set.inner(writeContractSync, client, {
|
|
786
|
+
...rest,
|
|
787
|
+
throwOnReceiptRevert,
|
|
788
|
+
} as never)
|
|
789
|
+
const { tokenFilterId, ...args } = set.extractEvent(receipt.logs).args
|
|
790
|
+
return {
|
|
791
|
+
...args,
|
|
792
|
+
senderPolicyId: toPolicyRef(args.senderPolicyId),
|
|
793
|
+
tokenPolicyId: toPolicyRef(tokenFilterId),
|
|
794
|
+
claimer: toClaimer(args.recoveryAuthority, args.account),
|
|
795
|
+
receipt,
|
|
796
|
+
} as never
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
export namespace setSync {
|
|
800
|
+
export type Parameters<
|
|
801
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
802
|
+
account extends Account | undefined = Account | undefined,
|
|
803
|
+
> = set.Parameters<chain, account>
|
|
804
|
+
|
|
805
|
+
export type Args = set.Args
|
|
806
|
+
|
|
807
|
+
export type ReturnValue = Compute<
|
|
808
|
+
UnionOmit<
|
|
809
|
+
GetEventArgs<
|
|
810
|
+
typeof Abis.tip403Registry,
|
|
811
|
+
'ReceivePolicyUpdated',
|
|
812
|
+
{ IndexedOnly: false; Required: true }
|
|
813
|
+
>,
|
|
814
|
+
'senderPolicyId' | 'tokenFilterId'
|
|
815
|
+
> & {
|
|
816
|
+
/** TIP-403 policy restricting which senders are allowed. */
|
|
817
|
+
senderPolicyId: PolicyRef
|
|
818
|
+
/** TIP-403 policy restricting which tokens are allowed. */
|
|
819
|
+
tokenPolicyId: PolicyRef
|
|
820
|
+
/** Who can reclaim funds blocked by this policy. */
|
|
821
|
+
claimer: Claimer
|
|
822
|
+
receipt: TransactionReceipt
|
|
823
|
+
}
|
|
824
|
+
>
|
|
825
|
+
|
|
826
|
+
// TODO: exhaustive error type
|
|
827
|
+
export type ErrorType = BaseErrorType
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Checks whether a transfer or mint to a receiver is allowed by the receiver's
|
|
832
|
+
* receive policy.
|
|
833
|
+
*
|
|
834
|
+
* @example
|
|
835
|
+
* ```ts
|
|
836
|
+
* import { createClient, http } from 'viem'
|
|
837
|
+
* import { tempo } from 'viem/chains'
|
|
838
|
+
* import { Actions } from 'viem/tempo'
|
|
839
|
+
*
|
|
840
|
+
* const client = createClient({
|
|
841
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
842
|
+
* transport: http(),
|
|
843
|
+
* })
|
|
844
|
+
*
|
|
845
|
+
* const { authorized, blockedReason } = await Actions.receivePolicy.validate(
|
|
846
|
+
* client,
|
|
847
|
+
* {
|
|
848
|
+
* token: '0x...',
|
|
849
|
+
* sender: '0x...',
|
|
850
|
+
* receiver: '0x...',
|
|
851
|
+
* },
|
|
852
|
+
* )
|
|
853
|
+
* ```
|
|
854
|
+
*
|
|
855
|
+
* @param client - Client.
|
|
856
|
+
* @param parameters - Parameters.
|
|
857
|
+
* @returns Whether the transfer is authorized and, if not, why.
|
|
858
|
+
*/
|
|
859
|
+
export async function validate<chain extends Chain | undefined>(
|
|
860
|
+
client: Client<Transport, chain>,
|
|
861
|
+
parameters: validate.Parameters,
|
|
862
|
+
): Promise<validate.ReturnValue> {
|
|
863
|
+
const { token, sender, receiver, ...rest } = parameters
|
|
864
|
+
const [authorized, blockedReason] = await readContract(client, {
|
|
865
|
+
...rest,
|
|
866
|
+
...validate.call({ token, sender, receiver }),
|
|
867
|
+
})
|
|
868
|
+
return {
|
|
869
|
+
authorized,
|
|
870
|
+
blockedReason: blockedReasons[blockedReason] ?? 'none',
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
export namespace validate {
|
|
875
|
+
export type Parameters = ReadParameters & Args
|
|
876
|
+
|
|
877
|
+
export type Args = {
|
|
878
|
+
/** Token address. */
|
|
879
|
+
token: Address
|
|
880
|
+
/** Sender address. */
|
|
881
|
+
sender: Address
|
|
882
|
+
/** Receiver address. */
|
|
883
|
+
receiver: Address
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
export type ReturnValue = Compute<{
|
|
887
|
+
/** Whether the transfer is authorized. */
|
|
888
|
+
authorized: boolean
|
|
889
|
+
/** Reason the transfer would be blocked. */
|
|
890
|
+
blockedReason: BlockedReason
|
|
891
|
+
}>
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Defines a call to the `validateReceivePolicy` function.
|
|
895
|
+
*
|
|
896
|
+
* @param args - Arguments.
|
|
897
|
+
* @returns The call.
|
|
898
|
+
*/
|
|
899
|
+
export function call(args: Args) {
|
|
900
|
+
const { token, sender, receiver } = args
|
|
901
|
+
return defineCall({
|
|
902
|
+
address: Addresses.tip403Registry,
|
|
903
|
+
abi: Abis.tip403Registry,
|
|
904
|
+
functionName: 'validateReceivePolicy',
|
|
905
|
+
args: [token, sender, receiver],
|
|
906
|
+
})
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* Watches for blocked transfer events.
|
|
912
|
+
*
|
|
913
|
+
* @example
|
|
914
|
+
* ```ts
|
|
915
|
+
* import { createClient, http } from 'viem'
|
|
916
|
+
* import { tempo } from 'viem/chains'
|
|
917
|
+
* import { Actions } from 'viem/tempo'
|
|
918
|
+
*
|
|
919
|
+
* const client = createClient({
|
|
920
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
921
|
+
* transport: http(),
|
|
922
|
+
* })
|
|
923
|
+
*
|
|
924
|
+
* const unwatch = Actions.receivePolicy.watchBlocked(client, {
|
|
925
|
+
* onBlocked: (args, log) => {
|
|
926
|
+
* console.log('Transfer blocked:', args)
|
|
927
|
+
* },
|
|
928
|
+
* })
|
|
929
|
+
* ```
|
|
930
|
+
*
|
|
931
|
+
* @param client - Client.
|
|
932
|
+
* @param parameters - Parameters.
|
|
933
|
+
* @returns A function to unsubscribe from the event.
|
|
934
|
+
*/
|
|
935
|
+
export function watchBlocked<
|
|
936
|
+
chain extends Chain | undefined,
|
|
937
|
+
account extends Account | undefined,
|
|
938
|
+
>(
|
|
939
|
+
client: Client<Transport, chain, account>,
|
|
940
|
+
parameters: watchBlocked.Parameters,
|
|
941
|
+
) {
|
|
942
|
+
const { onBlocked, ...rest } = parameters
|
|
943
|
+
return watchContractEvent(client, {
|
|
944
|
+
...rest,
|
|
945
|
+
address: Addresses.receivePolicyGuard,
|
|
946
|
+
abi: Abis.receivePolicyGuard,
|
|
947
|
+
eventName: 'TransferBlocked',
|
|
948
|
+
onLogs: (logs) => {
|
|
949
|
+
for (const log of logs) {
|
|
950
|
+
const { receipt, ...args } = log.args
|
|
951
|
+
onBlocked({ ...args, claimReceipt: receipt }, log)
|
|
952
|
+
}
|
|
953
|
+
},
|
|
954
|
+
strict: true,
|
|
955
|
+
})
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
export declare namespace watchBlocked {
|
|
959
|
+
export type Args = Compute<
|
|
960
|
+
UnionOmit<
|
|
961
|
+
GetEventArgs<
|
|
962
|
+
typeof Abis.receivePolicyGuard,
|
|
963
|
+
'TransferBlocked',
|
|
964
|
+
{ IndexedOnly: false; Required: true }
|
|
965
|
+
>,
|
|
966
|
+
'receipt'
|
|
967
|
+
> & {
|
|
968
|
+
/** The encoded claim receipt (witness for `claim`/`burn`). */
|
|
969
|
+
claimReceipt: Hex
|
|
970
|
+
}
|
|
971
|
+
>
|
|
972
|
+
|
|
973
|
+
export type Log = viem_Log<
|
|
974
|
+
bigint,
|
|
975
|
+
number,
|
|
976
|
+
false,
|
|
977
|
+
ExtractAbiItem<typeof Abis.receivePolicyGuard, 'TransferBlocked'>,
|
|
978
|
+
true
|
|
979
|
+
>
|
|
980
|
+
|
|
981
|
+
export type Parameters = UnionOmit<
|
|
982
|
+
WatchContractEventParameters<
|
|
983
|
+
typeof Abis.receivePolicyGuard,
|
|
984
|
+
'TransferBlocked',
|
|
985
|
+
true
|
|
986
|
+
>,
|
|
987
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
988
|
+
> & {
|
|
989
|
+
/** Callback to invoke when a transfer is blocked. */
|
|
990
|
+
onBlocked: (args: Args, log: Log) => void
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
/**
|
|
995
|
+
* Watches for receipt burned events.
|
|
996
|
+
*
|
|
997
|
+
* @example
|
|
998
|
+
* ```ts
|
|
999
|
+
* import { createClient, http } from 'viem'
|
|
1000
|
+
* import { tempo } from 'viem/chains'
|
|
1001
|
+
* import { Actions } from 'viem/tempo'
|
|
1002
|
+
*
|
|
1003
|
+
* const client = createClient({
|
|
1004
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
1005
|
+
* transport: http(),
|
|
1006
|
+
* })
|
|
1007
|
+
*
|
|
1008
|
+
* const unwatch = Actions.receivePolicy.watchBurned(client, {
|
|
1009
|
+
* onBurned: (args, log) => {
|
|
1010
|
+
* console.log('Receipt burned:', args)
|
|
1011
|
+
* },
|
|
1012
|
+
* })
|
|
1013
|
+
* ```
|
|
1014
|
+
*
|
|
1015
|
+
* @param client - Client.
|
|
1016
|
+
* @param parameters - Parameters.
|
|
1017
|
+
* @returns A function to unsubscribe from the event.
|
|
1018
|
+
*/
|
|
1019
|
+
export function watchBurned<
|
|
1020
|
+
chain extends Chain | undefined,
|
|
1021
|
+
account extends Account | undefined,
|
|
1022
|
+
>(
|
|
1023
|
+
client: Client<Transport, chain, account>,
|
|
1024
|
+
parameters: watchBurned.Parameters,
|
|
1025
|
+
) {
|
|
1026
|
+
const { onBurned, ...rest } = parameters
|
|
1027
|
+
return watchContractEvent(client, {
|
|
1028
|
+
...rest,
|
|
1029
|
+
address: Addresses.receivePolicyGuard,
|
|
1030
|
+
abi: Abis.receivePolicyGuard,
|
|
1031
|
+
eventName: 'ReceiptBurned',
|
|
1032
|
+
onLogs: (logs) => {
|
|
1033
|
+
for (const log of logs) onBurned(log.args, log)
|
|
1034
|
+
},
|
|
1035
|
+
strict: true,
|
|
1036
|
+
})
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
export declare namespace watchBurned {
|
|
1040
|
+
export type Args = Compute<
|
|
1041
|
+
GetEventArgs<
|
|
1042
|
+
typeof Abis.receivePolicyGuard,
|
|
1043
|
+
'ReceiptBurned',
|
|
1044
|
+
{ IndexedOnly: false; Required: true }
|
|
1045
|
+
>
|
|
1046
|
+
>
|
|
1047
|
+
|
|
1048
|
+
export type Log = viem_Log<
|
|
1049
|
+
bigint,
|
|
1050
|
+
number,
|
|
1051
|
+
false,
|
|
1052
|
+
ExtractAbiItem<typeof Abis.receivePolicyGuard, 'ReceiptBurned'>,
|
|
1053
|
+
true
|
|
1054
|
+
>
|
|
1055
|
+
|
|
1056
|
+
export type Parameters = UnionOmit<
|
|
1057
|
+
WatchContractEventParameters<
|
|
1058
|
+
typeof Abis.receivePolicyGuard,
|
|
1059
|
+
'ReceiptBurned',
|
|
1060
|
+
true
|
|
1061
|
+
>,
|
|
1062
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1063
|
+
> & {
|
|
1064
|
+
/** Callback to invoke when a receipt is burned. */
|
|
1065
|
+
onBurned: (args: Args, log: Log) => void
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* Watches for receipt claimed events.
|
|
1071
|
+
*
|
|
1072
|
+
* @example
|
|
1073
|
+
* ```ts
|
|
1074
|
+
* import { createClient, http } from 'viem'
|
|
1075
|
+
* import { tempo } from 'viem/chains'
|
|
1076
|
+
* import { Actions } from 'viem/tempo'
|
|
1077
|
+
*
|
|
1078
|
+
* const client = createClient({
|
|
1079
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
1080
|
+
* transport: http(),
|
|
1081
|
+
* })
|
|
1082
|
+
*
|
|
1083
|
+
* const unwatch = Actions.receivePolicy.watchClaimed(client, {
|
|
1084
|
+
* onClaimed: (args, log) => {
|
|
1085
|
+
* console.log('Receipt claimed:', args)
|
|
1086
|
+
* },
|
|
1087
|
+
* })
|
|
1088
|
+
* ```
|
|
1089
|
+
*
|
|
1090
|
+
* @param client - Client.
|
|
1091
|
+
* @param parameters - Parameters.
|
|
1092
|
+
* @returns A function to unsubscribe from the event.
|
|
1093
|
+
*/
|
|
1094
|
+
export function watchClaimed<
|
|
1095
|
+
chain extends Chain | undefined,
|
|
1096
|
+
account extends Account | undefined,
|
|
1097
|
+
>(
|
|
1098
|
+
client: Client<Transport, chain, account>,
|
|
1099
|
+
parameters: watchClaimed.Parameters,
|
|
1100
|
+
) {
|
|
1101
|
+
const { onClaimed, ...rest } = parameters
|
|
1102
|
+
return watchContractEvent(client, {
|
|
1103
|
+
...rest,
|
|
1104
|
+
address: Addresses.receivePolicyGuard,
|
|
1105
|
+
abi: Abis.receivePolicyGuard,
|
|
1106
|
+
eventName: 'ReceiptClaimed',
|
|
1107
|
+
onLogs: (logs) => {
|
|
1108
|
+
for (const log of logs) onClaimed(log.args, log)
|
|
1109
|
+
},
|
|
1110
|
+
strict: true,
|
|
1111
|
+
})
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
export declare namespace watchClaimed {
|
|
1115
|
+
export type Args = Compute<
|
|
1116
|
+
GetEventArgs<
|
|
1117
|
+
typeof Abis.receivePolicyGuard,
|
|
1118
|
+
'ReceiptClaimed',
|
|
1119
|
+
{ IndexedOnly: false; Required: true }
|
|
1120
|
+
>
|
|
1121
|
+
>
|
|
1122
|
+
|
|
1123
|
+
export type Log = viem_Log<
|
|
1124
|
+
bigint,
|
|
1125
|
+
number,
|
|
1126
|
+
false,
|
|
1127
|
+
ExtractAbiItem<typeof Abis.receivePolicyGuard, 'ReceiptClaimed'>,
|
|
1128
|
+
true
|
|
1129
|
+
>
|
|
1130
|
+
|
|
1131
|
+
export type Parameters = UnionOmit<
|
|
1132
|
+
WatchContractEventParameters<
|
|
1133
|
+
typeof Abis.receivePolicyGuard,
|
|
1134
|
+
'ReceiptClaimed',
|
|
1135
|
+
true
|
|
1136
|
+
>,
|
|
1137
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1138
|
+
> & {
|
|
1139
|
+
/** Callback to invoke when a receipt is claimed. */
|
|
1140
|
+
onClaimed: (args: Args, log: Log) => void
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Watches for receive policy update events.
|
|
1146
|
+
*
|
|
1147
|
+
* @example
|
|
1148
|
+
* ```ts
|
|
1149
|
+
* import { createClient, http } from 'viem'
|
|
1150
|
+
* import { tempo } from 'viem/chains'
|
|
1151
|
+
* import { Actions } from 'viem/tempo'
|
|
1152
|
+
*
|
|
1153
|
+
* const client = createClient({
|
|
1154
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
1155
|
+
* transport: http(),
|
|
1156
|
+
* })
|
|
1157
|
+
*
|
|
1158
|
+
* const unwatch = Actions.receivePolicy.watchUpdated(client, {
|
|
1159
|
+
* onUpdated: (args, log) => {
|
|
1160
|
+
* console.log('Receive policy updated:', args)
|
|
1161
|
+
* },
|
|
1162
|
+
* })
|
|
1163
|
+
* ```
|
|
1164
|
+
*
|
|
1165
|
+
* @param client - Client.
|
|
1166
|
+
* @param parameters - Parameters.
|
|
1167
|
+
* @returns A function to unsubscribe from the event.
|
|
1168
|
+
*/
|
|
1169
|
+
export function watchUpdated<
|
|
1170
|
+
chain extends Chain | undefined,
|
|
1171
|
+
account extends Account | undefined,
|
|
1172
|
+
>(
|
|
1173
|
+
client: Client<Transport, chain, account>,
|
|
1174
|
+
parameters: watchUpdated.Parameters,
|
|
1175
|
+
) {
|
|
1176
|
+
const { onUpdated, ...rest } = parameters
|
|
1177
|
+
return watchContractEvent(client, {
|
|
1178
|
+
...rest,
|
|
1179
|
+
address: Addresses.tip403Registry,
|
|
1180
|
+
abi: Abis.tip403Registry,
|
|
1181
|
+
eventName: 'ReceivePolicyUpdated',
|
|
1182
|
+
onLogs: (logs) => {
|
|
1183
|
+
for (const log of logs) {
|
|
1184
|
+
const { tokenFilterId, ...args } = log.args
|
|
1185
|
+
onUpdated(
|
|
1186
|
+
{
|
|
1187
|
+
...args,
|
|
1188
|
+
senderPolicyId: toPolicyRef(args.senderPolicyId),
|
|
1189
|
+
tokenPolicyId: toPolicyRef(tokenFilterId),
|
|
1190
|
+
claimer: toClaimer(args.recoveryAuthority, args.account),
|
|
1191
|
+
},
|
|
1192
|
+
log,
|
|
1193
|
+
)
|
|
1194
|
+
}
|
|
1195
|
+
},
|
|
1196
|
+
strict: true,
|
|
1197
|
+
})
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
export declare namespace watchUpdated {
|
|
1201
|
+
export type Args = Compute<
|
|
1202
|
+
UnionOmit<
|
|
1203
|
+
GetEventArgs<
|
|
1204
|
+
typeof Abis.tip403Registry,
|
|
1205
|
+
'ReceivePolicyUpdated',
|
|
1206
|
+
{ IndexedOnly: false; Required: true }
|
|
1207
|
+
>,
|
|
1208
|
+
'senderPolicyId' | 'tokenFilterId'
|
|
1209
|
+
> & {
|
|
1210
|
+
/** TIP-403 policy restricting which senders are allowed. */
|
|
1211
|
+
senderPolicyId: PolicyRef
|
|
1212
|
+
/** TIP-403 policy restricting which tokens are allowed. */
|
|
1213
|
+
tokenPolicyId: PolicyRef
|
|
1214
|
+
/** Who can reclaim funds blocked by this policy. */
|
|
1215
|
+
claimer: Claimer
|
|
1216
|
+
}
|
|
1217
|
+
>
|
|
1218
|
+
|
|
1219
|
+
export type Log = viem_Log<
|
|
1220
|
+
bigint,
|
|
1221
|
+
number,
|
|
1222
|
+
false,
|
|
1223
|
+
ExtractAbiItem<typeof Abis.tip403Registry, 'ReceivePolicyUpdated'>,
|
|
1224
|
+
true
|
|
1225
|
+
>
|
|
1226
|
+
|
|
1227
|
+
export type Parameters = UnionOmit<
|
|
1228
|
+
WatchContractEventParameters<
|
|
1229
|
+
typeof Abis.tip403Registry,
|
|
1230
|
+
'ReceivePolicyUpdated',
|
|
1231
|
+
true
|
|
1232
|
+
>,
|
|
1233
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
1234
|
+
> & {
|
|
1235
|
+
/** Callback to invoke when a receive policy is updated. */
|
|
1236
|
+
onUpdated: (args: Args, log: Log) => void
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
/** @internal */
|
|
1241
|
+
function resolvePolicyRef(ref: PolicyRef): bigint {
|
|
1242
|
+
if (ref === 'reject-all') return rejectAllPolicyId
|
|
1243
|
+
if (ref === 'allow-all') return allowAllPolicyId
|
|
1244
|
+
return ref
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
/** @internal */
|
|
1248
|
+
function toPolicyRef(id: bigint): PolicyRef {
|
|
1249
|
+
if (id === rejectAllPolicyId) return 'reject-all'
|
|
1250
|
+
if (id === allowAllPolicyId) return 'allow-all'
|
|
1251
|
+
return id
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
/** @internal */
|
|
1255
|
+
function resolveClaimer(claimer: Claimer, self: Address): Address {
|
|
1256
|
+
if (claimer === 'sender') return zeroAddress
|
|
1257
|
+
if (claimer === 'self') return self
|
|
1258
|
+
return claimer
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
/** @internal */
|
|
1262
|
+
function toClaimer(recoveryAuthority: Address, account: Address): Claimer {
|
|
1263
|
+
if (recoveryAuthority === zeroAddress) return 'sender'
|
|
1264
|
+
if (isAddressEqual(recoveryAuthority, account)) return 'self'
|
|
1265
|
+
return recoveryAuthority
|
|
1266
|
+
}
|