tempo.ts 0.0.0 → 0.0.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.
- package/README.md +92 -0
- package/dist/chains.d.ts +1477 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +43 -0
- package/dist/chains.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/types.d.ts +284 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +2 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/ox/TokenId.d.ts +18 -0
- package/dist/ox/TokenId.d.ts.map +1 -0
- package/dist/ox/TokenId.js +29 -0
- package/dist/ox/TokenId.js.map +1 -0
- package/dist/ox/TokenRole.d.ts +11 -0
- package/dist/ox/TokenRole.d.ts.map +1 -0
- package/dist/ox/TokenRole.js +22 -0
- package/dist/ox/TokenRole.js.map +1 -0
- package/dist/ox/Transaction.d.ts +161 -0
- package/dist/ox/Transaction.d.ts.map +1 -0
- package/dist/ox/Transaction.js +117 -0
- package/dist/ox/Transaction.js.map +1 -0
- package/dist/ox/TransactionEnvelopeFeeToken.d.ts +393 -0
- package/dist/ox/TransactionEnvelopeFeeToken.d.ts.map +1 -0
- package/dist/ox/TransactionEnvelopeFeeToken.js +452 -0
- package/dist/ox/TransactionEnvelopeFeeToken.js.map +1 -0
- package/dist/ox/TransactionRequest.d.ts +62 -0
- package/dist/ox/TransactionRequest.d.ts.map +1 -0
- package/dist/ox/TransactionRequest.js +66 -0
- package/dist/ox/TransactionRequest.js.map +1 -0
- package/dist/ox/index.d.ts +5 -0
- package/dist/ox/index.d.ts.map +1 -0
- package/dist/ox/index.js +5 -0
- package/dist/ox/index.js.map +1 -0
- package/dist/prool/Instance.d.ts +92 -0
- package/dist/prool/Instance.d.ts.map +1 -0
- package/dist/prool/Instance.js +96 -0
- package/dist/prool/Instance.js.map +1 -0
- package/dist/prool/index.d.ts +2 -0
- package/dist/prool/index.d.ts.map +1 -0
- package/dist/prool/index.js +2 -0
- package/dist/prool/index.js.map +1 -0
- package/dist/viem/abis.d.ts +2058 -0
- package/dist/viem/abis.d.ts.map +1 -0
- package/dist/viem/abis.js +1599 -0
- package/dist/viem/abis.js.map +1 -0
- package/dist/viem/actions/amm.d.ts +2091 -0
- package/dist/viem/actions/amm.d.ts.map +1 -0
- package/dist/viem/actions/amm.js +876 -0
- package/dist/viem/actions/amm.js.map +1 -0
- package/dist/viem/actions/fee.d.ts +727 -0
- package/dist/viem/actions/fee.d.ts.map +1 -0
- package/dist/viem/actions/fee.js +230 -0
- package/dist/viem/actions/fee.js.map +1 -0
- package/dist/viem/actions/index.d.ts +5 -0
- package/dist/viem/actions/index.d.ts.map +1 -0
- package/dist/viem/actions/index.js +5 -0
- package/dist/viem/actions/index.js.map +1 -0
- package/dist/viem/actions/policy.d.ts +1900 -0
- package/dist/viem/actions/policy.d.ts.map +1 -0
- package/dist/viem/actions/policy.js +841 -0
- package/dist/viem/actions/policy.js.map +1 -0
- package/dist/viem/actions/token.d.ts +13759 -0
- package/dist/viem/actions/token.d.ts.map +1 -0
- package/dist/viem/actions/token.js +2579 -0
- package/dist/viem/actions/token.js.map +1 -0
- package/dist/viem/addresses.d.ts +8 -0
- package/dist/viem/addresses.d.ts.map +1 -0
- package/dist/viem/addresses.js +8 -0
- package/dist/viem/addresses.js.map +1 -0
- package/dist/viem/chain.d.ts +341 -0
- package/dist/viem/chain.d.ts.map +1 -0
- package/dist/viem/chain.js +22 -0
- package/dist/viem/chain.js.map +1 -0
- package/dist/viem/client.d.ts +27 -0
- package/dist/viem/client.d.ts.map +1 -0
- package/dist/viem/client.js +28 -0
- package/dist/viem/client.js.map +1 -0
- package/dist/viem/decorator.d.ts +1636 -0
- package/dist/viem/decorator.d.ts.map +1 -0
- package/dist/viem/decorator.js +95 -0
- package/dist/viem/decorator.js.map +1 -0
- package/dist/viem/formatters.d.ts +4 -0
- package/dist/viem/formatters.d.ts.map +1 -0
- package/dist/viem/formatters.js +69 -0
- package/dist/viem/formatters.js.map +1 -0
- package/dist/viem/index.d.ts +9 -0
- package/dist/viem/index.d.ts.map +1 -0
- package/dist/viem/index.js +9 -0
- package/dist/viem/index.js.map +1 -0
- package/dist/viem/transaction.d.ts +54 -0
- package/dist/viem/transaction.d.ts.map +1 -0
- package/dist/viem/transaction.js +108 -0
- package/dist/viem/transaction.js.map +1 -0
- package/dist/viem/transport.d.ts +16 -0
- package/dist/viem/transport.d.ts.map +1 -0
- package/dist/viem/transport.js +33 -0
- package/dist/viem/transport.js.map +1 -0
- package/dist/viem/types.d.ts +10 -0
- package/dist/viem/types.d.ts.map +1 -0
- package/dist/viem/types.js +2 -0
- package/dist/viem/types.js.map +1 -0
- package/dist/viem/utils.d.ts +8 -0
- package/dist/viem/utils.d.ts.map +1 -0
- package/dist/viem/utils.js +9 -0
- package/dist/viem/utils.js.map +1 -0
- package/package.json +100 -2
- package/src/chains.ts +46 -0
- package/src/index.ts +1 -0
- package/src/internal/types.ts +414 -0
- package/src/ox/TokenId.test.ts +29 -0
- package/src/ox/TokenId.ts +35 -0
- package/src/ox/TokenRole.test.ts +20 -0
- package/src/ox/TokenRole.ts +27 -0
- package/src/ox/Transaction.test.ts +257 -0
- package/src/ox/Transaction.ts +247 -0
- package/src/ox/TransactionEnvelopeFeeToken.test.ts +1215 -0
- package/src/ox/TransactionEnvelopeFeeToken.ts +717 -0
- package/src/ox/TransactionRequest.ts +100 -0
- package/src/ox/index.ts +4 -0
- package/src/prool/Instance.test.ts +43 -0
- package/src/prool/Instance.ts +190 -0
- package/src/prool/index.ts +1 -0
- package/src/prool/internal/chain.json +106 -0
- package/src/prool/internal/consensus.toml +32 -0
- package/src/viem/abis.ts +1606 -0
- package/src/viem/actions/amm.test.ts +425 -0
- package/src/viem/actions/amm.ts +1308 -0
- package/src/viem/actions/fee.test.ts +281 -0
- package/src/viem/actions/fee.ts +362 -0
- package/src/viem/actions/index.ts +4 -0
- package/src/viem/actions/policy.test.ts +514 -0
- package/src/viem/actions/policy.ts +1284 -0
- package/src/viem/actions/token.test.ts +2172 -0
- package/src/viem/actions/token.ts +3830 -0
- package/src/viem/addresses.ts +10 -0
- package/src/viem/chain.ts +27 -0
- package/src/viem/client.bench-d.ts +8 -0
- package/src/viem/client.test.ts +152 -0
- package/src/viem/client.ts +91 -0
- package/src/viem/decorator.bench-d.ts +11 -0
- package/src/viem/decorator.test.ts +35 -0
- package/src/viem/decorator.ts +1914 -0
- package/src/viem/e2e.test.ts +410 -0
- package/src/viem/formatters.ts +100 -0
- package/src/viem/index.ts +8 -0
- package/src/viem/transaction.ts +253 -0
- package/src/viem/transport.ts +47 -0
- package/src/viem/types.ts +55 -0
- package/src/viem/utils.ts +37 -0
|
@@ -0,0 +1,3830 @@
|
|
|
1
|
+
import * as Hex from 'ox/Hex'
|
|
2
|
+
import * as Signature from 'ox/Signature'
|
|
3
|
+
import {
|
|
4
|
+
type Account,
|
|
5
|
+
type Address,
|
|
6
|
+
type Chain,
|
|
7
|
+
type Client,
|
|
8
|
+
type ExtractAbiItem,
|
|
9
|
+
encodeFunctionData,
|
|
10
|
+
type GetEventArgs,
|
|
11
|
+
type Log,
|
|
12
|
+
parseEventLogs,
|
|
13
|
+
type ReadContractReturnType,
|
|
14
|
+
type SendTransactionSyncParameters,
|
|
15
|
+
type TransactionReceipt,
|
|
16
|
+
type Transport,
|
|
17
|
+
type ValueOf,
|
|
18
|
+
type Log as viem_Log,
|
|
19
|
+
type WatchContractEventParameters,
|
|
20
|
+
type WriteContractReturnType,
|
|
21
|
+
} from 'viem'
|
|
22
|
+
import { parseAccount } from 'viem/accounts'
|
|
23
|
+
import {
|
|
24
|
+
multicall,
|
|
25
|
+
readContract,
|
|
26
|
+
sendTransaction,
|
|
27
|
+
sendTransactionSync,
|
|
28
|
+
watchContractEvent,
|
|
29
|
+
writeContract,
|
|
30
|
+
writeContractSync,
|
|
31
|
+
} from 'viem/actions'
|
|
32
|
+
import type { Compute, UnionOmit } from '../../internal/types.js'
|
|
33
|
+
import * as TokenId from '../../ox/TokenId.js'
|
|
34
|
+
import * as TokenRole from '../../ox/TokenRole.js'
|
|
35
|
+
import { tip20Abi, tip20FactoryAbi } from '../abis.js'
|
|
36
|
+
import { tip20FactoryAddress, usdAddress } from '../addresses.js'
|
|
37
|
+
import type {
|
|
38
|
+
GetAccountParameter,
|
|
39
|
+
ReadParameters,
|
|
40
|
+
WriteParameters,
|
|
41
|
+
} from '../types.js'
|
|
42
|
+
import { defineCall } from '../utils.js'
|
|
43
|
+
|
|
44
|
+
const transferPolicy = {
|
|
45
|
+
0: 'always-reject',
|
|
46
|
+
1: 'always-allow',
|
|
47
|
+
} as const
|
|
48
|
+
type TransferPolicy = ValueOf<typeof transferPolicy>
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Approves a spender to transfer TIP20 tokens on behalf of the caller.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { createClient, http } from 'viem'
|
|
56
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
57
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
58
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
59
|
+
*
|
|
60
|
+
* const client = createClient({
|
|
61
|
+
* account: privateKeyToAccount('0x...'),
|
|
62
|
+
* chain: tempo,
|
|
63
|
+
* transport: http(),
|
|
64
|
+
* })
|
|
65
|
+
*
|
|
66
|
+
* const result = await actions.token.approve(client, {
|
|
67
|
+
* spender: '0x...',
|
|
68
|
+
* amount: 100n,
|
|
69
|
+
* })
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @param client - Client.
|
|
73
|
+
* @param parameters - Parameters.
|
|
74
|
+
* @returns The transaction hash.
|
|
75
|
+
*/
|
|
76
|
+
export async function approve<
|
|
77
|
+
chain extends Chain | undefined,
|
|
78
|
+
account extends Account | undefined,
|
|
79
|
+
>(
|
|
80
|
+
client: Client<Transport, chain, account>,
|
|
81
|
+
parameters: approve.Parameters<chain, account>,
|
|
82
|
+
): Promise<approve.ReturnValue> {
|
|
83
|
+
const { token = usdAddress, ...rest } = parameters
|
|
84
|
+
return approve.inner(writeContract, client, parameters, { ...rest, token })
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export namespace approve {
|
|
88
|
+
export type Parameters<
|
|
89
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
90
|
+
account extends Account | undefined = Account | undefined,
|
|
91
|
+
> = WriteParameters<chain, account> & Args
|
|
92
|
+
|
|
93
|
+
export type Args = {
|
|
94
|
+
/** Amount of tokens to approve. */
|
|
95
|
+
amount: bigint
|
|
96
|
+
/** Address of the spender. */
|
|
97
|
+
spender: Address
|
|
98
|
+
/** Address or ID of the TIP20 token. @default `usdAddress` */
|
|
99
|
+
token?: TokenId.TokenIdOrAddress | undefined
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type ReturnValue = WriteContractReturnType
|
|
103
|
+
|
|
104
|
+
/** @internal */
|
|
105
|
+
export async function inner<
|
|
106
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
107
|
+
chain extends Chain | undefined,
|
|
108
|
+
account extends Account | undefined,
|
|
109
|
+
>(
|
|
110
|
+
action: action,
|
|
111
|
+
client: Client<Transport, chain, account>,
|
|
112
|
+
parameters: approve.Parameters<chain, account>,
|
|
113
|
+
args: Args,
|
|
114
|
+
): Promise<ReturnType<action>> {
|
|
115
|
+
const call = approve.call(args)
|
|
116
|
+
return (await action(client, {
|
|
117
|
+
...parameters,
|
|
118
|
+
...call,
|
|
119
|
+
} as never)) as never
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Defines a call to the `approve` function.
|
|
124
|
+
*
|
|
125
|
+
* Can be passed as a parameter to:
|
|
126
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
127
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
128
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
133
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
134
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
135
|
+
*
|
|
136
|
+
* const client = createClient({
|
|
137
|
+
* chain: tempo,
|
|
138
|
+
* transport: http(),
|
|
139
|
+
* }).extend(walletActions)
|
|
140
|
+
*
|
|
141
|
+
* const { result } = await client.sendCalls({
|
|
142
|
+
* calls: [
|
|
143
|
+
* actions.token.approve.call({
|
|
144
|
+
* spender: '0x20c0...beef',
|
|
145
|
+
* amount: 100n,
|
|
146
|
+
* token: '0x20c0...babe',
|
|
147
|
+
* }),
|
|
148
|
+
* ]
|
|
149
|
+
* })
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @param args - Arguments.
|
|
153
|
+
* @returns The call.
|
|
154
|
+
*/
|
|
155
|
+
export function call(args: Args) {
|
|
156
|
+
const { spender, amount, token = usdAddress } = args
|
|
157
|
+
return defineCall({
|
|
158
|
+
address: TokenId.toAddress(token),
|
|
159
|
+
abi: tip20Abi,
|
|
160
|
+
functionName: 'approve',
|
|
161
|
+
args: [spender, amount],
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function extractEvent(logs: Log[]) {
|
|
166
|
+
const [log] = parseEventLogs({
|
|
167
|
+
abi: tip20Abi,
|
|
168
|
+
logs,
|
|
169
|
+
eventName: 'Approval',
|
|
170
|
+
})
|
|
171
|
+
if (!log) throw new Error('`Approval` event not found.')
|
|
172
|
+
return log
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Approves a spender to transfer TIP20 tokens on behalf of the caller.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* import { createClient, http } from 'viem'
|
|
182
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
183
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
184
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
185
|
+
*
|
|
186
|
+
* const client = createClient({
|
|
187
|
+
* account: privateKeyToAccount('0x...'),
|
|
188
|
+
* chain: tempo,
|
|
189
|
+
* transport: http(),
|
|
190
|
+
* })
|
|
191
|
+
*
|
|
192
|
+
* const result = await actions.token.approveSync(client, {
|
|
193
|
+
* spender: '0x...',
|
|
194
|
+
* amount: 100n,
|
|
195
|
+
* })
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @param client - Client.
|
|
199
|
+
* @param parameters - Parameters.
|
|
200
|
+
* @returns The transaction receipt and event data.
|
|
201
|
+
*/
|
|
202
|
+
export async function approveSync<
|
|
203
|
+
chain extends Chain | undefined,
|
|
204
|
+
account extends Account | undefined,
|
|
205
|
+
>(
|
|
206
|
+
client: Client<Transport, chain, account>,
|
|
207
|
+
parameters: approveSync.Parameters<chain, account>,
|
|
208
|
+
): Promise<approveSync.ReturnValue> {
|
|
209
|
+
const { token = usdAddress, ...rest } = parameters
|
|
210
|
+
const receipt = await approve.inner(writeContractSync, client, parameters, {
|
|
211
|
+
...rest,
|
|
212
|
+
token,
|
|
213
|
+
})
|
|
214
|
+
const { args } = approve.extractEvent(receipt.logs)
|
|
215
|
+
return {
|
|
216
|
+
...args,
|
|
217
|
+
receipt,
|
|
218
|
+
} as never
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export namespace approveSync {
|
|
222
|
+
export type Parameters<
|
|
223
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
224
|
+
account extends Account | undefined = Account | undefined,
|
|
225
|
+
> = approve.Parameters<chain, account>
|
|
226
|
+
|
|
227
|
+
export type Args = approve.Args
|
|
228
|
+
|
|
229
|
+
export type ReturnValue = Compute<
|
|
230
|
+
GetEventArgs<
|
|
231
|
+
typeof tip20Abi,
|
|
232
|
+
'Approval',
|
|
233
|
+
{
|
|
234
|
+
IndexedOnly: false
|
|
235
|
+
Required: true
|
|
236
|
+
}
|
|
237
|
+
> & {
|
|
238
|
+
/** Transaction receipt. */
|
|
239
|
+
receipt: TransactionReceipt
|
|
240
|
+
}
|
|
241
|
+
>
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Burns TIP20 tokens from a blocked address.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* import { createClient, http } from 'viem'
|
|
250
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
251
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
252
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
253
|
+
*
|
|
254
|
+
* const client = createClient({
|
|
255
|
+
* account: privateKeyToAccount('0x...'),
|
|
256
|
+
* chain: tempo,
|
|
257
|
+
* transport: http(),
|
|
258
|
+
* })
|
|
259
|
+
*
|
|
260
|
+
* const result = await actions.token.burnBlocked(client, {
|
|
261
|
+
* from: '0x...',
|
|
262
|
+
* amount: 100n,
|
|
263
|
+
* token: '0x...',
|
|
264
|
+
* })
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* @param client - Client.
|
|
268
|
+
* @param parameters - Parameters.
|
|
269
|
+
* @returns The transaction hash.
|
|
270
|
+
*/
|
|
271
|
+
export async function burnBlocked<
|
|
272
|
+
chain extends Chain | undefined,
|
|
273
|
+
account extends Account | undefined,
|
|
274
|
+
>(
|
|
275
|
+
client: Client<Transport, chain, account>,
|
|
276
|
+
parameters: burnBlocked.Parameters<chain, account>,
|
|
277
|
+
): Promise<burnBlocked.ReturnValue> {
|
|
278
|
+
return burnBlocked.inner(writeContract, client, parameters)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export namespace burnBlocked {
|
|
282
|
+
export type Parameters<
|
|
283
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
284
|
+
account extends Account | undefined = Account | undefined,
|
|
285
|
+
> = WriteParameters<chain, account> & Args
|
|
286
|
+
|
|
287
|
+
export type Args = {
|
|
288
|
+
/** Amount of tokens to burn. */
|
|
289
|
+
amount: bigint
|
|
290
|
+
/** Address to burn tokens from. */
|
|
291
|
+
from: Address
|
|
292
|
+
/** Address or ID of the TIP20 token. */
|
|
293
|
+
token: TokenId.TokenIdOrAddress
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export type ReturnValue = WriteContractReturnType
|
|
297
|
+
|
|
298
|
+
/** @internal */
|
|
299
|
+
export async function inner<
|
|
300
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
301
|
+
chain extends Chain | undefined,
|
|
302
|
+
account extends Account | undefined,
|
|
303
|
+
>(
|
|
304
|
+
action: action,
|
|
305
|
+
client: Client<Transport, chain, account>,
|
|
306
|
+
parameters: burnBlocked.Parameters<chain, account>,
|
|
307
|
+
): Promise<ReturnType<action>> {
|
|
308
|
+
const call = burnBlocked.call(parameters)
|
|
309
|
+
return (await action(client, {
|
|
310
|
+
...parameters,
|
|
311
|
+
...call,
|
|
312
|
+
} as never)) as never
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Defines a call to the `burnBlocked` function.
|
|
317
|
+
*
|
|
318
|
+
* Can be passed as a parameter to:
|
|
319
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
320
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
321
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```ts
|
|
325
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
326
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
327
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
328
|
+
*
|
|
329
|
+
* const client = createClient({
|
|
330
|
+
* chain: tempo,
|
|
331
|
+
* transport: http(),
|
|
332
|
+
* }).extend(walletActions)
|
|
333
|
+
*
|
|
334
|
+
* const { result } = await client.sendCalls({
|
|
335
|
+
* calls: [
|
|
336
|
+
* actions.token.burnBlocked.call({
|
|
337
|
+
* from: '0x20c0...beef',
|
|
338
|
+
* amount: 100n,
|
|
339
|
+
* token: '0x20c0...babe',
|
|
340
|
+
* }),
|
|
341
|
+
* ]
|
|
342
|
+
* })
|
|
343
|
+
* ```
|
|
344
|
+
*
|
|
345
|
+
* @param args - Arguments.
|
|
346
|
+
* @returns The call.
|
|
347
|
+
*/
|
|
348
|
+
export function call(args: Args) {
|
|
349
|
+
const { from, amount, token } = args
|
|
350
|
+
return defineCall({
|
|
351
|
+
address: TokenId.toAddress(token),
|
|
352
|
+
abi: tip20Abi,
|
|
353
|
+
functionName: 'burnBlocked',
|
|
354
|
+
args: [from, amount],
|
|
355
|
+
})
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Extracts the event from the logs.
|
|
360
|
+
*
|
|
361
|
+
* @param logs - Logs.
|
|
362
|
+
* @returns The event.
|
|
363
|
+
*/
|
|
364
|
+
export function extractEvent(logs: Log[]) {
|
|
365
|
+
const [log] = parseEventLogs({
|
|
366
|
+
abi: tip20Abi,
|
|
367
|
+
logs,
|
|
368
|
+
eventName: 'BurnBlocked',
|
|
369
|
+
})
|
|
370
|
+
if (!log) throw new Error('`BurnBlocked` event not found.')
|
|
371
|
+
return log
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Burns TIP20 tokens from a blocked address.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```ts
|
|
380
|
+
* import { createClient, http } from 'viem'
|
|
381
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
382
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
383
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
384
|
+
*
|
|
385
|
+
* const client = createClient({
|
|
386
|
+
* account: privateKeyToAccount('0x...'),
|
|
387
|
+
* chain: tempo,
|
|
388
|
+
* transport: http(),
|
|
389
|
+
* })
|
|
390
|
+
*
|
|
391
|
+
* const result = await actions.token.burnBlockedSync(client, {
|
|
392
|
+
* from: '0x...',
|
|
393
|
+
* amount: 100n,
|
|
394
|
+
* token: '0x...',
|
|
395
|
+
* })
|
|
396
|
+
* ```
|
|
397
|
+
*
|
|
398
|
+
* @param client - Client.
|
|
399
|
+
* @param parameters - Parameters.
|
|
400
|
+
* @returns The transaction receipt and event data.
|
|
401
|
+
*/
|
|
402
|
+
export async function burnBlockedSync<
|
|
403
|
+
chain extends Chain | undefined,
|
|
404
|
+
account extends Account | undefined,
|
|
405
|
+
>(
|
|
406
|
+
client: Client<Transport, chain, account>,
|
|
407
|
+
parameters: burnBlockedSync.Parameters<chain, account>,
|
|
408
|
+
): Promise<burnBlockedSync.ReturnValue> {
|
|
409
|
+
const receipt = await burnBlocked.inner(writeContractSync, client, parameters)
|
|
410
|
+
const { args } = burnBlocked.extractEvent(receipt.logs)
|
|
411
|
+
return {
|
|
412
|
+
...args,
|
|
413
|
+
receipt,
|
|
414
|
+
} as never
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export namespace burnBlockedSync {
|
|
418
|
+
export type Parameters<
|
|
419
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
420
|
+
account extends Account | undefined = Account | undefined,
|
|
421
|
+
> = burnBlocked.Parameters<chain, account>
|
|
422
|
+
|
|
423
|
+
export type Args = burnBlocked.Args
|
|
424
|
+
|
|
425
|
+
export type ReturnValue = Compute<
|
|
426
|
+
GetEventArgs<
|
|
427
|
+
typeof tip20Abi,
|
|
428
|
+
'BurnBlocked',
|
|
429
|
+
{
|
|
430
|
+
IndexedOnly: false
|
|
431
|
+
Required: true
|
|
432
|
+
}
|
|
433
|
+
> & {
|
|
434
|
+
/** Transaction receipt. */
|
|
435
|
+
receipt: TransactionReceipt
|
|
436
|
+
}
|
|
437
|
+
>
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Burns TIP20 tokens from the caller's balance.
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* ```ts
|
|
445
|
+
* import { createClient, http } from 'viem'
|
|
446
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
447
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
448
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
449
|
+
*
|
|
450
|
+
* const client = createClient({
|
|
451
|
+
* account: privateKeyToAccount('0x...'),
|
|
452
|
+
* chain: tempo,
|
|
453
|
+
* transport: http(),
|
|
454
|
+
* })
|
|
455
|
+
*
|
|
456
|
+
* const result = await actions.token.burn(client, {
|
|
457
|
+
* amount: 100n,
|
|
458
|
+
* token: '0x...',
|
|
459
|
+
* })
|
|
460
|
+
* ```
|
|
461
|
+
*
|
|
462
|
+
* @param client - Client.
|
|
463
|
+
* @param parameters - Parameters.
|
|
464
|
+
* @returns The transaction hash.
|
|
465
|
+
*/
|
|
466
|
+
export async function burn<
|
|
467
|
+
chain extends Chain | undefined,
|
|
468
|
+
account extends Account | undefined,
|
|
469
|
+
>(
|
|
470
|
+
client: Client<Transport, chain, account>,
|
|
471
|
+
parameters: burn.Parameters<chain, account>,
|
|
472
|
+
): Promise<burn.ReturnValue> {
|
|
473
|
+
return burn.inner(writeContract, client, parameters)
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export namespace burn {
|
|
477
|
+
export type Parameters<
|
|
478
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
479
|
+
account extends Account | undefined = Account | undefined,
|
|
480
|
+
> = WriteParameters<chain, account> & Args
|
|
481
|
+
|
|
482
|
+
export type Args = {
|
|
483
|
+
/** Amount of tokens to burn. */
|
|
484
|
+
amount: bigint
|
|
485
|
+
/** Memo to include in the transfer. */
|
|
486
|
+
memo?: Hex.Hex | undefined
|
|
487
|
+
/** Address or ID of the TIP20 token. */
|
|
488
|
+
token: TokenId.TokenIdOrAddress
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export type ReturnValue = WriteContractReturnType
|
|
492
|
+
|
|
493
|
+
/** @internal */
|
|
494
|
+
export async function inner<
|
|
495
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
496
|
+
chain extends Chain | undefined,
|
|
497
|
+
account extends Account | undefined,
|
|
498
|
+
>(
|
|
499
|
+
action: action,
|
|
500
|
+
client: Client<Transport, chain, account>,
|
|
501
|
+
parameters: burn.Parameters<chain, account>,
|
|
502
|
+
): Promise<ReturnType<action>> {
|
|
503
|
+
const call = burn.call(parameters)
|
|
504
|
+
return (await action(client, {
|
|
505
|
+
...parameters,
|
|
506
|
+
...call,
|
|
507
|
+
} as never)) as never
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Defines a call to the `burn` or `burnWithMemo` function.
|
|
512
|
+
*
|
|
513
|
+
* Can be passed as a parameter to:
|
|
514
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
515
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
516
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```ts
|
|
520
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
521
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
522
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
523
|
+
*
|
|
524
|
+
* const client = createClient({
|
|
525
|
+
* chain: tempo,
|
|
526
|
+
* transport: http(),
|
|
527
|
+
* }).extend(walletActions)
|
|
528
|
+
*
|
|
529
|
+
* const { result } = await client.sendCalls({
|
|
530
|
+
* calls: [
|
|
531
|
+
* actions.token.burn.call({
|
|
532
|
+
* amount: 100n,
|
|
533
|
+
* token: '0x20c0...babe',
|
|
534
|
+
* }),
|
|
535
|
+
* ]
|
|
536
|
+
* })
|
|
537
|
+
* ```
|
|
538
|
+
*
|
|
539
|
+
* @param args - Arguments.
|
|
540
|
+
* @returns The call.
|
|
541
|
+
*/
|
|
542
|
+
export function call(args: Args) {
|
|
543
|
+
const { amount, memo, token } = args
|
|
544
|
+
const callArgs = memo
|
|
545
|
+
? ({
|
|
546
|
+
functionName: 'burnWithMemo',
|
|
547
|
+
args: [amount, Hex.padLeft(memo, 32)],
|
|
548
|
+
} as const)
|
|
549
|
+
: ({
|
|
550
|
+
functionName: 'burn',
|
|
551
|
+
args: [amount],
|
|
552
|
+
} as const)
|
|
553
|
+
return defineCall({
|
|
554
|
+
address: TokenId.toAddress(token),
|
|
555
|
+
abi: tip20Abi,
|
|
556
|
+
...callArgs,
|
|
557
|
+
})
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Extracts the event from the logs.
|
|
562
|
+
*
|
|
563
|
+
* @param logs - Logs.
|
|
564
|
+
* @returns The event.
|
|
565
|
+
*/
|
|
566
|
+
export function extractEvent(logs: Log[]) {
|
|
567
|
+
const [log] = parseEventLogs({
|
|
568
|
+
abi: tip20Abi,
|
|
569
|
+
logs,
|
|
570
|
+
eventName: 'Burn',
|
|
571
|
+
})
|
|
572
|
+
if (!log) throw new Error('`Burn` event not found.')
|
|
573
|
+
return log
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Burns TIP20 tokens from the caller's balance.
|
|
579
|
+
*
|
|
580
|
+
* @example
|
|
581
|
+
* ```ts
|
|
582
|
+
* import { createClient, http } from 'viem'
|
|
583
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
584
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
585
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
586
|
+
*
|
|
587
|
+
* const client = createClient({
|
|
588
|
+
* account: privateKeyToAccount('0x...'),
|
|
589
|
+
* chain: tempo,
|
|
590
|
+
* transport: http(),
|
|
591
|
+
* })
|
|
592
|
+
*
|
|
593
|
+
* const result = await actions.token.burnSync(client, {
|
|
594
|
+
* amount: 100n,
|
|
595
|
+
* token: '0x...',
|
|
596
|
+
* })
|
|
597
|
+
* ```
|
|
598
|
+
*
|
|
599
|
+
* @param client - Client.
|
|
600
|
+
* @param parameters - Parameters.
|
|
601
|
+
* @returns The transaction receipt and event data.
|
|
602
|
+
*/
|
|
603
|
+
export async function burnSync<
|
|
604
|
+
chain extends Chain | undefined,
|
|
605
|
+
account extends Account | undefined,
|
|
606
|
+
>(
|
|
607
|
+
client: Client<Transport, chain, account>,
|
|
608
|
+
parameters: burnSync.Parameters<chain, account>,
|
|
609
|
+
): Promise<burnSync.ReturnValue> {
|
|
610
|
+
const receipt = await burn.inner(writeContractSync, client, parameters)
|
|
611
|
+
const { args } = burn.extractEvent(receipt.logs)
|
|
612
|
+
return {
|
|
613
|
+
...args,
|
|
614
|
+
receipt,
|
|
615
|
+
} as never
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
export namespace burnSync {
|
|
619
|
+
export type Parameters<
|
|
620
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
621
|
+
account extends Account | undefined = Account | undefined,
|
|
622
|
+
> = burn.Parameters<chain, account>
|
|
623
|
+
|
|
624
|
+
export type Args = burn.Args
|
|
625
|
+
|
|
626
|
+
export type ReturnValue = Compute<
|
|
627
|
+
GetEventArgs<
|
|
628
|
+
typeof tip20Abi,
|
|
629
|
+
'Burn',
|
|
630
|
+
{
|
|
631
|
+
IndexedOnly: false
|
|
632
|
+
Required: true
|
|
633
|
+
}
|
|
634
|
+
> & {
|
|
635
|
+
receipt: TransactionReceipt
|
|
636
|
+
}
|
|
637
|
+
>
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Changes the transfer policy ID for a TIP20 token.
|
|
642
|
+
*
|
|
643
|
+
* @example
|
|
644
|
+
* ```ts
|
|
645
|
+
* import { createClient, http } from 'viem'
|
|
646
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
647
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
648
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
649
|
+
*
|
|
650
|
+
* const client = createClient({
|
|
651
|
+
* account: privateKeyToAccount('0x...'),
|
|
652
|
+
* chain: tempo,
|
|
653
|
+
* transport: http(),
|
|
654
|
+
* })
|
|
655
|
+
*
|
|
656
|
+
* const result = await actions.token.changeTransferPolicy(client, {
|
|
657
|
+
* token: '0x...',
|
|
658
|
+
* policyId: 1n,
|
|
659
|
+
* })
|
|
660
|
+
* ```
|
|
661
|
+
*
|
|
662
|
+
* @param client - Client.
|
|
663
|
+
* @param parameters - Parameters.
|
|
664
|
+
* @returns The transaction hash.
|
|
665
|
+
*/
|
|
666
|
+
export async function changeTransferPolicy<
|
|
667
|
+
chain extends Chain | undefined,
|
|
668
|
+
account extends Account | undefined,
|
|
669
|
+
>(
|
|
670
|
+
client: Client<Transport, chain, account>,
|
|
671
|
+
parameters: changeTransferPolicy.Parameters<chain, account>,
|
|
672
|
+
): Promise<changeTransferPolicy.ReturnValue> {
|
|
673
|
+
return changeTransferPolicy.inner(writeContract, client, parameters)
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
export namespace changeTransferPolicy {
|
|
677
|
+
export type Parameters<
|
|
678
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
679
|
+
account extends Account | undefined = Account | undefined,
|
|
680
|
+
> = WriteParameters<chain, account> & Args
|
|
681
|
+
|
|
682
|
+
export type Args = {
|
|
683
|
+
/** New transfer policy ID. */
|
|
684
|
+
policyId: bigint
|
|
685
|
+
/** Address or ID of the TIP20 token. */
|
|
686
|
+
token: TokenId.TokenIdOrAddress
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
export type ReturnValue = WriteContractReturnType
|
|
690
|
+
|
|
691
|
+
/** @internal */
|
|
692
|
+
export async function inner<
|
|
693
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
694
|
+
chain extends Chain | undefined,
|
|
695
|
+
account extends Account | undefined,
|
|
696
|
+
>(
|
|
697
|
+
action: action,
|
|
698
|
+
client: Client<Transport, chain, account>,
|
|
699
|
+
parameters: changeTransferPolicy.Parameters<chain, account>,
|
|
700
|
+
): Promise<ReturnType<action>> {
|
|
701
|
+
const call = changeTransferPolicy.call(parameters)
|
|
702
|
+
return (await action(client, {
|
|
703
|
+
...parameters,
|
|
704
|
+
...call,
|
|
705
|
+
} as never)) as never
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Defines a call to the `changeTransferPolicyId` function.
|
|
710
|
+
*
|
|
711
|
+
* Can be passed as a parameter to:
|
|
712
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
713
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
714
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* ```ts
|
|
718
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
719
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
720
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
721
|
+
*
|
|
722
|
+
* const client = createClient({
|
|
723
|
+
* chain: tempo,
|
|
724
|
+
* transport: http(),
|
|
725
|
+
* }).extend(walletActions)
|
|
726
|
+
*
|
|
727
|
+
* const { result } = await client.sendCalls({
|
|
728
|
+
* calls: [
|
|
729
|
+
* actions.token.changeTransferPolicy.call({
|
|
730
|
+
* token: '0x20c0...babe',
|
|
731
|
+
* policyId: 1n,
|
|
732
|
+
* }),
|
|
733
|
+
* ]
|
|
734
|
+
* })
|
|
735
|
+
* ```
|
|
736
|
+
*
|
|
737
|
+
* @param args - Arguments.
|
|
738
|
+
* @returns The call.
|
|
739
|
+
*/
|
|
740
|
+
export function call(args: Args) {
|
|
741
|
+
const { token, policyId } = args
|
|
742
|
+
return defineCall({
|
|
743
|
+
address: TokenId.toAddress(token),
|
|
744
|
+
abi: tip20Abi,
|
|
745
|
+
functionName: 'changeTransferPolicyId',
|
|
746
|
+
args: [policyId],
|
|
747
|
+
})
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Extracts the event from the logs.
|
|
752
|
+
*
|
|
753
|
+
* @param logs - Logs.
|
|
754
|
+
* @returns The event.
|
|
755
|
+
*/
|
|
756
|
+
export function extractEvent(logs: Log[]) {
|
|
757
|
+
const [log] = parseEventLogs({
|
|
758
|
+
abi: tip20Abi,
|
|
759
|
+
logs,
|
|
760
|
+
eventName: 'TransferPolicyUpdate',
|
|
761
|
+
})
|
|
762
|
+
if (!log) throw new Error('`TransferPolicyUpdate` event not found.')
|
|
763
|
+
return log
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Changes the transfer policy ID for a TIP20 token.
|
|
769
|
+
*
|
|
770
|
+
* @example
|
|
771
|
+
* ```ts
|
|
772
|
+
* import { createClient, http } from 'viem'
|
|
773
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
774
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
775
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
776
|
+
*
|
|
777
|
+
* const client = createClient({
|
|
778
|
+
* account: privateKeyToAccount('0x...'),
|
|
779
|
+
* chain: tempo,
|
|
780
|
+
* transport: http(),
|
|
781
|
+
* })
|
|
782
|
+
*
|
|
783
|
+
* const result = await actions.token.changeTransferPolicySync(client, {
|
|
784
|
+
* token: '0x...',
|
|
785
|
+
* policyId: 1n,
|
|
786
|
+
* })
|
|
787
|
+
* ```
|
|
788
|
+
*
|
|
789
|
+
* @param client - Client.
|
|
790
|
+
* @param parameters - Parameters.
|
|
791
|
+
* @returns The transaction receipt and event data.
|
|
792
|
+
*/
|
|
793
|
+
export async function changeTransferPolicySync<
|
|
794
|
+
chain extends Chain | undefined,
|
|
795
|
+
account extends Account | undefined,
|
|
796
|
+
>(
|
|
797
|
+
client: Client<Transport, chain, account>,
|
|
798
|
+
parameters: changeTransferPolicySync.Parameters<chain, account>,
|
|
799
|
+
): Promise<changeTransferPolicySync.ReturnValue> {
|
|
800
|
+
const receipt = await changeTransferPolicy.inner(
|
|
801
|
+
writeContractSync,
|
|
802
|
+
client,
|
|
803
|
+
parameters,
|
|
804
|
+
)
|
|
805
|
+
const { args } = changeTransferPolicy.extractEvent(receipt.logs)
|
|
806
|
+
return {
|
|
807
|
+
...args,
|
|
808
|
+
receipt,
|
|
809
|
+
} as never
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
export namespace changeTransferPolicySync {
|
|
813
|
+
export type Parameters<
|
|
814
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
815
|
+
account extends Account | undefined = Account | undefined,
|
|
816
|
+
> = changeTransferPolicy.Parameters<chain, account>
|
|
817
|
+
|
|
818
|
+
export type Args = changeTransferPolicy.Args
|
|
819
|
+
|
|
820
|
+
export type ReturnValue = Compute<
|
|
821
|
+
GetEventArgs<
|
|
822
|
+
typeof tip20Abi,
|
|
823
|
+
'TransferPolicyUpdate',
|
|
824
|
+
{
|
|
825
|
+
IndexedOnly: false
|
|
826
|
+
Required: true
|
|
827
|
+
}
|
|
828
|
+
> & {
|
|
829
|
+
receipt: TransactionReceipt
|
|
830
|
+
}
|
|
831
|
+
>
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Creates a new TIP20 token.
|
|
836
|
+
*
|
|
837
|
+
* @example
|
|
838
|
+
* ```ts
|
|
839
|
+
* import { createClient, http } from 'viem'
|
|
840
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
841
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
842
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
843
|
+
*
|
|
844
|
+
* const client = createClient({
|
|
845
|
+
* account: privateKeyToAccount('0x...'),
|
|
846
|
+
* chain: tempo,
|
|
847
|
+
* transport: http(),
|
|
848
|
+
* })
|
|
849
|
+
*
|
|
850
|
+
* const result = await actions.token.create(client, {
|
|
851
|
+
* name: 'My Token',
|
|
852
|
+
* symbol: 'MTK',
|
|
853
|
+
* currency: 'USD',
|
|
854
|
+
* })
|
|
855
|
+
* ```
|
|
856
|
+
*
|
|
857
|
+
* @param client - Client.
|
|
858
|
+
* @param parameters - Parameters.
|
|
859
|
+
* @returns The transaction hash.
|
|
860
|
+
*/
|
|
861
|
+
export async function create<
|
|
862
|
+
chain extends Chain | undefined,
|
|
863
|
+
account extends Account | undefined,
|
|
864
|
+
>(
|
|
865
|
+
client: Client<Transport, chain, account>,
|
|
866
|
+
parameters: create.Parameters<chain, account>,
|
|
867
|
+
): Promise<create.ReturnValue> {
|
|
868
|
+
return create.inner(writeContract, client, parameters)
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
export namespace create {
|
|
872
|
+
export type Parameters<
|
|
873
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
874
|
+
account extends Account | undefined = Account | undefined,
|
|
875
|
+
> = WriteParameters<chain, account> &
|
|
876
|
+
Omit<Args, 'admin'> &
|
|
877
|
+
(account extends Account
|
|
878
|
+
? { admin?: Account | Address | undefined }
|
|
879
|
+
: { admin: Account | Address })
|
|
880
|
+
|
|
881
|
+
export type Args = {
|
|
882
|
+
/** Admin address. */
|
|
883
|
+
admin: Address
|
|
884
|
+
/** Currency (e.g. "USD"). */
|
|
885
|
+
currency: string
|
|
886
|
+
/** Token name. */
|
|
887
|
+
name: string
|
|
888
|
+
/** Token symbol. */
|
|
889
|
+
symbol: string
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
export type ReturnValue = WriteContractReturnType
|
|
893
|
+
|
|
894
|
+
/** @internal */
|
|
895
|
+
export async function inner<
|
|
896
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
897
|
+
chain extends Chain | undefined,
|
|
898
|
+
account extends Account | undefined,
|
|
899
|
+
>(
|
|
900
|
+
action: action,
|
|
901
|
+
client: Client<Transport, chain, account>,
|
|
902
|
+
parameters: any,
|
|
903
|
+
): Promise<ReturnType<action>> {
|
|
904
|
+
const {
|
|
905
|
+
account = client.account,
|
|
906
|
+
admin: admin_ = client.account,
|
|
907
|
+
chain = client.chain,
|
|
908
|
+
...rest
|
|
909
|
+
} = parameters
|
|
910
|
+
const admin = admin_ ? parseAccount(admin_) : undefined
|
|
911
|
+
if (!admin) throw new Error('admin is required.')
|
|
912
|
+
|
|
913
|
+
const call = create.call({ ...rest, admin: admin.address })
|
|
914
|
+
|
|
915
|
+
return (await action(
|
|
916
|
+
client as never,
|
|
917
|
+
{
|
|
918
|
+
...parameters,
|
|
919
|
+
account,
|
|
920
|
+
chain,
|
|
921
|
+
...call,
|
|
922
|
+
} as never,
|
|
923
|
+
)) as never
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Defines a call to the `createToken` function.
|
|
928
|
+
*
|
|
929
|
+
* Can be passed as a parameter to:
|
|
930
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
931
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
932
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
933
|
+
*
|
|
934
|
+
* @example
|
|
935
|
+
* ```ts
|
|
936
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
937
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
938
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
939
|
+
*
|
|
940
|
+
* const client = createClient({
|
|
941
|
+
* chain: tempo,
|
|
942
|
+
* transport: http(),
|
|
943
|
+
* }).extend(walletActions)
|
|
944
|
+
*
|
|
945
|
+
* const { result } = await client.sendCalls({
|
|
946
|
+
* calls: [
|
|
947
|
+
* actions.token.create.call({
|
|
948
|
+
* name: 'My Token',
|
|
949
|
+
* symbol: 'MTK',
|
|
950
|
+
* currency: 'USD',
|
|
951
|
+
* admin: '0xfeed...fede',
|
|
952
|
+
* }),
|
|
953
|
+
* ]
|
|
954
|
+
* })
|
|
955
|
+
* ```
|
|
956
|
+
*
|
|
957
|
+
* @param args - Arguments.
|
|
958
|
+
* @returns The call.
|
|
959
|
+
*/
|
|
960
|
+
export function call(args: Args) {
|
|
961
|
+
const { name, symbol, currency, admin } = args
|
|
962
|
+
return defineCall({
|
|
963
|
+
address: tip20FactoryAddress,
|
|
964
|
+
abi: tip20FactoryAbi,
|
|
965
|
+
args: [name, symbol, currency, admin],
|
|
966
|
+
functionName: 'createToken',
|
|
967
|
+
})
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/**
|
|
971
|
+
* Extracts the `TokenCreated` event from logs.
|
|
972
|
+
*
|
|
973
|
+
* @param logs - The logs.
|
|
974
|
+
* @returns The `TokenCreated` event.
|
|
975
|
+
*/
|
|
976
|
+
export function extractEvent(logs: Log[]) {
|
|
977
|
+
const [log] = parseEventLogs({
|
|
978
|
+
abi: tip20FactoryAbi,
|
|
979
|
+
logs,
|
|
980
|
+
eventName: 'TokenCreated',
|
|
981
|
+
strict: true,
|
|
982
|
+
})
|
|
983
|
+
if (!log) throw new Error('`TokenCreated` event not found.')
|
|
984
|
+
return log
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* Creates a new TIP20 token.
|
|
990
|
+
*
|
|
991
|
+
* @example
|
|
992
|
+
* ```ts
|
|
993
|
+
* import { createClient, http } from 'viem'
|
|
994
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
995
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
996
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
997
|
+
*
|
|
998
|
+
* const client = createClient({
|
|
999
|
+
* account: privateKeyToAccount('0x...'),
|
|
1000
|
+
* chain: tempo,
|
|
1001
|
+
* transport: http(),
|
|
1002
|
+
* })
|
|
1003
|
+
*
|
|
1004
|
+
* const result = await actions.token.createSync(client, {
|
|
1005
|
+
* name: 'My Token',
|
|
1006
|
+
* symbol: 'MTK',
|
|
1007
|
+
* currency: 'USD',
|
|
1008
|
+
* })
|
|
1009
|
+
* ```
|
|
1010
|
+
*
|
|
1011
|
+
* @param client - Client.
|
|
1012
|
+
* @param parameters - Parameters.
|
|
1013
|
+
* @returns The transaction receipt and event data.
|
|
1014
|
+
*/
|
|
1015
|
+
export async function createSync<
|
|
1016
|
+
chain extends Chain | undefined,
|
|
1017
|
+
account extends Account | undefined,
|
|
1018
|
+
>(
|
|
1019
|
+
client: Client<Transport, chain, account>,
|
|
1020
|
+
parameters: createSync.Parameters<chain, account>,
|
|
1021
|
+
): Promise<createSync.ReturnValue> {
|
|
1022
|
+
const receipt = await create.inner(writeContractSync, client, parameters)
|
|
1023
|
+
|
|
1024
|
+
const { args } = create.extractEvent(receipt.logs)
|
|
1025
|
+
|
|
1026
|
+
return {
|
|
1027
|
+
...args,
|
|
1028
|
+
receipt,
|
|
1029
|
+
} as never
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
export namespace createSync {
|
|
1033
|
+
export type Parameters<
|
|
1034
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1035
|
+
account extends Account | undefined = Account | undefined,
|
|
1036
|
+
> = create.Parameters<chain, account>
|
|
1037
|
+
|
|
1038
|
+
export type Args = create.Args
|
|
1039
|
+
|
|
1040
|
+
export type ReturnValue = Compute<
|
|
1041
|
+
GetEventArgs<
|
|
1042
|
+
typeof tip20FactoryAbi,
|
|
1043
|
+
'TokenCreated',
|
|
1044
|
+
{ IndexedOnly: false; Required: true }
|
|
1045
|
+
> & {
|
|
1046
|
+
/** Transaction receipt. */
|
|
1047
|
+
receipt: TransactionReceipt
|
|
1048
|
+
}
|
|
1049
|
+
>
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* Gets TIP20 token allowance.
|
|
1054
|
+
*
|
|
1055
|
+
* @example
|
|
1056
|
+
* ```ts
|
|
1057
|
+
* import { createClient, http } from 'viem'
|
|
1058
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1059
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1060
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1061
|
+
*
|
|
1062
|
+
* const client = createClient({
|
|
1063
|
+
* account: privateKeyToAccount('0x...'),
|
|
1064
|
+
* chain: tempo,
|
|
1065
|
+
* transport: http(),
|
|
1066
|
+
* })
|
|
1067
|
+
*
|
|
1068
|
+
* const allowance = await actions.token.getAllowance(client, {
|
|
1069
|
+
* spender: '0x...',
|
|
1070
|
+
* })
|
|
1071
|
+
* ```
|
|
1072
|
+
*
|
|
1073
|
+
* @param client - Client.
|
|
1074
|
+
* @param parameters - Parameters.
|
|
1075
|
+
* @returns The token allowance.
|
|
1076
|
+
*/
|
|
1077
|
+
export async function getAllowance<
|
|
1078
|
+
chain extends Chain | undefined,
|
|
1079
|
+
account extends Account | undefined,
|
|
1080
|
+
>(
|
|
1081
|
+
client: Client<Transport, chain, account>,
|
|
1082
|
+
parameters: getAllowance.Parameters<account>,
|
|
1083
|
+
): Promise<getAllowance.ReturnValue> {
|
|
1084
|
+
const { account = client.account, ...rest } = parameters
|
|
1085
|
+
const address = account ? parseAccount(account).address : undefined
|
|
1086
|
+
if (!address) throw new Error('account is required.')
|
|
1087
|
+
return readContract(client, {
|
|
1088
|
+
...rest,
|
|
1089
|
+
...getAllowance.call({ account: address, ...rest }),
|
|
1090
|
+
})
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
export namespace getAllowance {
|
|
1094
|
+
export type Parameters<
|
|
1095
|
+
account extends Account | undefined = Account | undefined,
|
|
1096
|
+
> = ReadParameters & GetAccountParameter<account> & Omit<Args, 'account'> & {}
|
|
1097
|
+
|
|
1098
|
+
export type Args = {
|
|
1099
|
+
/** Account address. */
|
|
1100
|
+
account: Address
|
|
1101
|
+
/** Address of the spender. */
|
|
1102
|
+
spender: Address
|
|
1103
|
+
/** Address or ID of the TIP20 token. @default `usdAddress` */
|
|
1104
|
+
token?: TokenId.TokenIdOrAddress | undefined
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
export type ReturnValue = ReadContractReturnType<
|
|
1108
|
+
typeof tip20Abi,
|
|
1109
|
+
'allowance',
|
|
1110
|
+
never
|
|
1111
|
+
>
|
|
1112
|
+
|
|
1113
|
+
/**
|
|
1114
|
+
* Defines a call to the `allowance` function.
|
|
1115
|
+
*
|
|
1116
|
+
* @param args - Arguments.
|
|
1117
|
+
* @returns The call.
|
|
1118
|
+
*/
|
|
1119
|
+
export function call(args: Args) {
|
|
1120
|
+
const { account, spender, token = usdAddress } = args
|
|
1121
|
+
return defineCall({
|
|
1122
|
+
address: TokenId.toAddress(token),
|
|
1123
|
+
abi: tip20Abi,
|
|
1124
|
+
functionName: 'allowance',
|
|
1125
|
+
args: [account, spender],
|
|
1126
|
+
})
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* Gets TIP20 token balance for an address.
|
|
1132
|
+
*
|
|
1133
|
+
* @example
|
|
1134
|
+
* ```ts
|
|
1135
|
+
* import { createClient, http } from 'viem'
|
|
1136
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1137
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1138
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1139
|
+
*
|
|
1140
|
+
* const client = createClient({
|
|
1141
|
+
* account: privateKeyToAccount('0x...'),
|
|
1142
|
+
* chain: tempo,
|
|
1143
|
+
* transport: http(),
|
|
1144
|
+
* })
|
|
1145
|
+
*
|
|
1146
|
+
* const balance = await actions.token.getBalance(client, {
|
|
1147
|
+
* token: '0x...',
|
|
1148
|
+
* })
|
|
1149
|
+
* ```
|
|
1150
|
+
*
|
|
1151
|
+
* @param client - Client.
|
|
1152
|
+
* @param parameters - Parameters.
|
|
1153
|
+
* @returns The token balance.
|
|
1154
|
+
*/
|
|
1155
|
+
export async function getBalance<
|
|
1156
|
+
chain extends Chain | undefined,
|
|
1157
|
+
account extends Account | undefined,
|
|
1158
|
+
>(
|
|
1159
|
+
client: Client<Transport, chain, account>,
|
|
1160
|
+
...parameters: account extends Account
|
|
1161
|
+
? [getBalance.Parameters<account>] | []
|
|
1162
|
+
: [getBalance.Parameters<account>]
|
|
1163
|
+
): Promise<getBalance.ReturnValue> {
|
|
1164
|
+
const { account = client.account, ...rest } = parameters[0] ?? {}
|
|
1165
|
+
const address = account ? parseAccount(account).address : undefined
|
|
1166
|
+
if (!address) throw new Error('account is required.')
|
|
1167
|
+
return readContract(client, {
|
|
1168
|
+
...rest,
|
|
1169
|
+
...getBalance.call({ account: address, ...rest }),
|
|
1170
|
+
})
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
export namespace getBalance {
|
|
1174
|
+
export type Parameters<
|
|
1175
|
+
account extends Account | undefined = Account | undefined,
|
|
1176
|
+
> = ReadParameters & GetAccountParameter<account> & Omit<Args, 'account'>
|
|
1177
|
+
|
|
1178
|
+
export type Args = {
|
|
1179
|
+
/** Account address. */
|
|
1180
|
+
account: Address
|
|
1181
|
+
/** Address or ID of the TIP20 token. @default `usdAddress` */
|
|
1182
|
+
token?: TokenId.TokenIdOrAddress | undefined
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
export type ReturnValue = ReadContractReturnType<
|
|
1186
|
+
typeof tip20Abi,
|
|
1187
|
+
'balanceOf',
|
|
1188
|
+
never
|
|
1189
|
+
>
|
|
1190
|
+
|
|
1191
|
+
/**
|
|
1192
|
+
* Defines a call to the `balanceOf` function.
|
|
1193
|
+
*
|
|
1194
|
+
* @param args - Arguments.
|
|
1195
|
+
* @returns The call.
|
|
1196
|
+
*/
|
|
1197
|
+
export function call(args: Args) {
|
|
1198
|
+
const { account, token = usdAddress } = args
|
|
1199
|
+
return defineCall({
|
|
1200
|
+
address: TokenId.toAddress(token),
|
|
1201
|
+
abi: tip20Abi,
|
|
1202
|
+
functionName: 'balanceOf',
|
|
1203
|
+
args: [account],
|
|
1204
|
+
})
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* Gets TIP20 token metadata including name, symbol, currency, decimals, and total supply.
|
|
1210
|
+
*
|
|
1211
|
+
* @example
|
|
1212
|
+
* ```ts
|
|
1213
|
+
* import { createClient, http } from 'viem'
|
|
1214
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1215
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1216
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1217
|
+
*
|
|
1218
|
+
* const client = createClient({
|
|
1219
|
+
* account: privateKeyToAccount('0x...'),
|
|
1220
|
+
* chain: tempo,
|
|
1221
|
+
* transport: http(),
|
|
1222
|
+
* })
|
|
1223
|
+
*
|
|
1224
|
+
* const metadata = await actions.token.getMetadata(client, {
|
|
1225
|
+
* token: '0x...',
|
|
1226
|
+
* })
|
|
1227
|
+
* ```
|
|
1228
|
+
*
|
|
1229
|
+
* @param client - Client.
|
|
1230
|
+
* @param parameters - Parameters.
|
|
1231
|
+
* @returns The token metadata.
|
|
1232
|
+
*/
|
|
1233
|
+
export async function getMetadata<chain extends Chain | undefined>(
|
|
1234
|
+
client: Client<Transport, chain>,
|
|
1235
|
+
parameters: getMetadata.Parameters = {},
|
|
1236
|
+
): Promise<getMetadata.ReturnValue> {
|
|
1237
|
+
const { token = usdAddress, ...rest } = parameters
|
|
1238
|
+
const address = TokenId.toAddress(token)
|
|
1239
|
+
const abi = tip20Abi
|
|
1240
|
+
return multicall(client, {
|
|
1241
|
+
...rest,
|
|
1242
|
+
contracts: [
|
|
1243
|
+
{
|
|
1244
|
+
address,
|
|
1245
|
+
abi,
|
|
1246
|
+
functionName: 'currency',
|
|
1247
|
+
},
|
|
1248
|
+
{
|
|
1249
|
+
address,
|
|
1250
|
+
abi,
|
|
1251
|
+
functionName: 'decimals',
|
|
1252
|
+
},
|
|
1253
|
+
{
|
|
1254
|
+
address,
|
|
1255
|
+
abi,
|
|
1256
|
+
functionName: 'name',
|
|
1257
|
+
},
|
|
1258
|
+
{
|
|
1259
|
+
address,
|
|
1260
|
+
abi,
|
|
1261
|
+
functionName: 'paused',
|
|
1262
|
+
},
|
|
1263
|
+
{
|
|
1264
|
+
address,
|
|
1265
|
+
abi,
|
|
1266
|
+
functionName: 'supplyCap',
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
address,
|
|
1270
|
+
abi,
|
|
1271
|
+
functionName: 'symbol',
|
|
1272
|
+
},
|
|
1273
|
+
{
|
|
1274
|
+
address,
|
|
1275
|
+
abi,
|
|
1276
|
+
functionName: 'totalSupply',
|
|
1277
|
+
},
|
|
1278
|
+
{
|
|
1279
|
+
address,
|
|
1280
|
+
abi,
|
|
1281
|
+
functionName: 'transferPolicyId',
|
|
1282
|
+
},
|
|
1283
|
+
] as const,
|
|
1284
|
+
allowFailure: false,
|
|
1285
|
+
deployless: true,
|
|
1286
|
+
}).then(
|
|
1287
|
+
([
|
|
1288
|
+
currency,
|
|
1289
|
+
decimals,
|
|
1290
|
+
name,
|
|
1291
|
+
paused,
|
|
1292
|
+
supplyCap,
|
|
1293
|
+
symbol,
|
|
1294
|
+
totalSupply,
|
|
1295
|
+
transferPolicyId,
|
|
1296
|
+
]) => ({
|
|
1297
|
+
name,
|
|
1298
|
+
symbol,
|
|
1299
|
+
currency,
|
|
1300
|
+
decimals,
|
|
1301
|
+
totalSupply,
|
|
1302
|
+
paused,
|
|
1303
|
+
supplyCap,
|
|
1304
|
+
transferPolicy:
|
|
1305
|
+
transferPolicy[Number(transferPolicyId) as keyof typeof transferPolicy],
|
|
1306
|
+
}),
|
|
1307
|
+
)
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
export declare namespace getMetadata {
|
|
1311
|
+
export type Parameters = {
|
|
1312
|
+
/** Address or ID of the TIP20 token. @default `usdAddress` */
|
|
1313
|
+
token?: TokenId.TokenIdOrAddress | undefined
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
export type ReturnValue = Compute<{
|
|
1317
|
+
/** Currency (e.g. "USD"). */
|
|
1318
|
+
currency: string
|
|
1319
|
+
/** Decimals. */
|
|
1320
|
+
decimals: number
|
|
1321
|
+
/** Name. */
|
|
1322
|
+
name: string
|
|
1323
|
+
/** Whether the token is paused. */
|
|
1324
|
+
paused: boolean
|
|
1325
|
+
/** Supply cap. */
|
|
1326
|
+
supplyCap: bigint
|
|
1327
|
+
/** Symbol. */
|
|
1328
|
+
symbol: string
|
|
1329
|
+
/** Total supply. */
|
|
1330
|
+
totalSupply: bigint
|
|
1331
|
+
/** Transfer policy. */
|
|
1332
|
+
transferPolicy: TransferPolicy
|
|
1333
|
+
}>
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
/**
|
|
1337
|
+
* Grants a role for a TIP20 token.
|
|
1338
|
+
*
|
|
1339
|
+
* @example
|
|
1340
|
+
* ```ts
|
|
1341
|
+
* import { createClient, http } from 'viem'
|
|
1342
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1343
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1344
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1345
|
+
*
|
|
1346
|
+
* const client = createClient({
|
|
1347
|
+
* account: privateKeyToAccount('0x...'),
|
|
1348
|
+
* chain: tempo,
|
|
1349
|
+
* transport: http(),
|
|
1350
|
+
* })
|
|
1351
|
+
*
|
|
1352
|
+
* const result = await actions.token.grantRoles(client, {
|
|
1353
|
+
* token: '0x...',
|
|
1354
|
+
* to: '0x...',
|
|
1355
|
+
* roles: ['minter'],
|
|
1356
|
+
* })
|
|
1357
|
+
* ```
|
|
1358
|
+
*
|
|
1359
|
+
* @param client - Client.
|
|
1360
|
+
* @param parameters - Parameters.
|
|
1361
|
+
* @returns The transaction hash.
|
|
1362
|
+
*/
|
|
1363
|
+
export async function grantRoles<
|
|
1364
|
+
chain extends Chain | undefined,
|
|
1365
|
+
account extends Account | undefined,
|
|
1366
|
+
>(
|
|
1367
|
+
client: Client<Transport, chain, account>,
|
|
1368
|
+
parameters: grantRoles.Parameters<chain, account>,
|
|
1369
|
+
): Promise<grantRoles.ReturnValue> {
|
|
1370
|
+
return grantRoles.inner(sendTransaction, client, parameters)
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
export namespace grantRoles {
|
|
1374
|
+
export type Parameters<
|
|
1375
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1376
|
+
account extends Account | undefined = Account | undefined,
|
|
1377
|
+
> = WriteParameters<chain, account> &
|
|
1378
|
+
Omit<Args, 'role'> & {
|
|
1379
|
+
/** Role to grant. */
|
|
1380
|
+
roles: readonly TokenRole.TokenRole[]
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
export type Args = {
|
|
1384
|
+
/** Role to grant. */
|
|
1385
|
+
role: TokenRole.TokenRole
|
|
1386
|
+
/** Address or ID of the TIP20 token. */
|
|
1387
|
+
token: TokenId.TokenIdOrAddress
|
|
1388
|
+
/** Address to grant the role to. */
|
|
1389
|
+
to: Address
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
export type ReturnValue = WriteContractReturnType
|
|
1393
|
+
|
|
1394
|
+
/** @internal */
|
|
1395
|
+
export async function inner<
|
|
1396
|
+
action extends typeof sendTransaction | typeof sendTransactionSync,
|
|
1397
|
+
chain extends Chain | undefined,
|
|
1398
|
+
account extends Account | undefined,
|
|
1399
|
+
>(
|
|
1400
|
+
action: action,
|
|
1401
|
+
client: Client<Transport, chain, account>,
|
|
1402
|
+
parameters: grantRoles.Parameters<chain, account>,
|
|
1403
|
+
): Promise<ReturnType<action>> {
|
|
1404
|
+
return (await action(client, {
|
|
1405
|
+
...parameters,
|
|
1406
|
+
calls: parameters.roles.map((role) => {
|
|
1407
|
+
const call = grantRoles.call({ ...parameters, role })
|
|
1408
|
+
return {
|
|
1409
|
+
...call,
|
|
1410
|
+
data: encodeFunctionData(call),
|
|
1411
|
+
}
|
|
1412
|
+
}),
|
|
1413
|
+
} as never)) as never
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
/**
|
|
1417
|
+
* Defines a call to the `grantRole` function.
|
|
1418
|
+
*
|
|
1419
|
+
* Can be passed as a parameter to:
|
|
1420
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1421
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1422
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1423
|
+
*
|
|
1424
|
+
* @example
|
|
1425
|
+
* ```ts
|
|
1426
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
1427
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1428
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1429
|
+
*
|
|
1430
|
+
* const client = createClient({
|
|
1431
|
+
* chain: tempo,
|
|
1432
|
+
* transport: http(),
|
|
1433
|
+
* }).extend(walletActions)
|
|
1434
|
+
*
|
|
1435
|
+
* const { result } = await client.sendCalls({
|
|
1436
|
+
* calls: [
|
|
1437
|
+
* actions.token.grantRoles.call({
|
|
1438
|
+
* token: '0x20c0...babe',
|
|
1439
|
+
* to: '0x20c0...beef',
|
|
1440
|
+
* role: 'minter',
|
|
1441
|
+
* }),
|
|
1442
|
+
* ]
|
|
1443
|
+
* })
|
|
1444
|
+
* ```
|
|
1445
|
+
*
|
|
1446
|
+
* @param args - Arguments.
|
|
1447
|
+
* @returns The call.
|
|
1448
|
+
*/
|
|
1449
|
+
export function call(args: Args) {
|
|
1450
|
+
const { token, to, role } = args
|
|
1451
|
+
const roleHash = TokenRole.serialize(role)
|
|
1452
|
+
return defineCall({
|
|
1453
|
+
address: TokenId.toAddress(token),
|
|
1454
|
+
abi: tip20Abi,
|
|
1455
|
+
functionName: 'grantRole',
|
|
1456
|
+
args: [roleHash, to],
|
|
1457
|
+
})
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
/**
|
|
1461
|
+
* Extracts the events from the logs.
|
|
1462
|
+
*
|
|
1463
|
+
* @param logs - Logs.
|
|
1464
|
+
* @returns The events.
|
|
1465
|
+
*/
|
|
1466
|
+
export function extractEvents(logs: Log[]) {
|
|
1467
|
+
const events = parseEventLogs({
|
|
1468
|
+
abi: tip20Abi,
|
|
1469
|
+
logs,
|
|
1470
|
+
eventName: 'RoleMembershipUpdated',
|
|
1471
|
+
})
|
|
1472
|
+
if (events.length === 0)
|
|
1473
|
+
throw new Error('`RoleMembershipUpdated` events not found.')
|
|
1474
|
+
return events
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
/**
|
|
1479
|
+
* Grants a role for a TIP20 token.
|
|
1480
|
+
*
|
|
1481
|
+
* @example
|
|
1482
|
+
* ```ts
|
|
1483
|
+
* import { createClient, http } from 'viem'
|
|
1484
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1485
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1486
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1487
|
+
*
|
|
1488
|
+
* const client = createClient({
|
|
1489
|
+
* account: privateKeyToAccount('0x...'),
|
|
1490
|
+
* chain: tempo,
|
|
1491
|
+
* transport: http(),
|
|
1492
|
+
* })
|
|
1493
|
+
*
|
|
1494
|
+
* const result = await actions.token.grantRolesSync(client, {
|
|
1495
|
+
* token: '0x...',
|
|
1496
|
+
* to: '0x...',
|
|
1497
|
+
* roles: ['minter'],
|
|
1498
|
+
* })
|
|
1499
|
+
* ```
|
|
1500
|
+
*
|
|
1501
|
+
* @param client - Client.
|
|
1502
|
+
* @param parameters - Parameters.
|
|
1503
|
+
* @returns The transaction receipt and event data.
|
|
1504
|
+
*/
|
|
1505
|
+
export async function grantRolesSync<
|
|
1506
|
+
chain extends Chain | undefined,
|
|
1507
|
+
account extends Account | undefined,
|
|
1508
|
+
>(
|
|
1509
|
+
client: Client<Transport, chain, account>,
|
|
1510
|
+
parameters: grantRolesSync.Parameters<chain, account>,
|
|
1511
|
+
): Promise<grantRolesSync.ReturnValue> {
|
|
1512
|
+
const receipt = await grantRoles.inner(
|
|
1513
|
+
sendTransactionSync,
|
|
1514
|
+
client,
|
|
1515
|
+
parameters,
|
|
1516
|
+
)
|
|
1517
|
+
const events = grantRoles.extractEvents(receipt.logs)
|
|
1518
|
+
const value = events.map((event) => event.args)
|
|
1519
|
+
return {
|
|
1520
|
+
receipt,
|
|
1521
|
+
value,
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
export namespace grantRolesSync {
|
|
1526
|
+
export type Parameters<
|
|
1527
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1528
|
+
account extends Account | undefined = Account | undefined,
|
|
1529
|
+
> = grantRoles.Parameters<chain, account>
|
|
1530
|
+
|
|
1531
|
+
export type Args = grantRoles.Args
|
|
1532
|
+
|
|
1533
|
+
export type ReturnValue = {
|
|
1534
|
+
receipt: TransactionReceipt
|
|
1535
|
+
value: readonly GetEventArgs<
|
|
1536
|
+
typeof tip20Abi,
|
|
1537
|
+
'RoleMembershipUpdated',
|
|
1538
|
+
{ IndexedOnly: false; Required: true }
|
|
1539
|
+
>[]
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
/**
|
|
1544
|
+
* Mints TIP20 tokens to an address.
|
|
1545
|
+
*
|
|
1546
|
+
* @example
|
|
1547
|
+
* ```ts
|
|
1548
|
+
* import { createClient, http } from 'viem'
|
|
1549
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1550
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1551
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1552
|
+
*
|
|
1553
|
+
* const client = createClient({
|
|
1554
|
+
* account: privateKeyToAccount('0x...'),
|
|
1555
|
+
* chain: tempo,
|
|
1556
|
+
* transport: http(),
|
|
1557
|
+
* })
|
|
1558
|
+
*
|
|
1559
|
+
* const result = await actions.token.mint(client, {
|
|
1560
|
+
* to: '0x...',
|
|
1561
|
+
* amount: 100n,
|
|
1562
|
+
* token: '0x...',
|
|
1563
|
+
* })
|
|
1564
|
+
* ```
|
|
1565
|
+
*
|
|
1566
|
+
* @param client - Client.
|
|
1567
|
+
* @param parameters - Parameters.
|
|
1568
|
+
* @returns The transaction hash.
|
|
1569
|
+
*/
|
|
1570
|
+
export async function mint<
|
|
1571
|
+
chain extends Chain | undefined,
|
|
1572
|
+
account extends Account | undefined,
|
|
1573
|
+
>(
|
|
1574
|
+
client: Client<Transport, chain, account>,
|
|
1575
|
+
parameters: mint.Parameters<chain, account>,
|
|
1576
|
+
): Promise<mint.ReturnValue> {
|
|
1577
|
+
return mint.inner(writeContract, client, parameters)
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
export namespace mint {
|
|
1581
|
+
export type Parameters<
|
|
1582
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1583
|
+
account extends Account | undefined = Account | undefined,
|
|
1584
|
+
> = WriteParameters<chain, account> & Args
|
|
1585
|
+
|
|
1586
|
+
export type Args = {
|
|
1587
|
+
/** Amount of tokens to mint. */
|
|
1588
|
+
amount: bigint
|
|
1589
|
+
/** Memo to include in the mint. */
|
|
1590
|
+
memo?: Hex.Hex | undefined
|
|
1591
|
+
/** Address to mint tokens to. */
|
|
1592
|
+
to: Address
|
|
1593
|
+
/** Address or ID of the TIP20 token. */
|
|
1594
|
+
token: TokenId.TokenIdOrAddress
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
export type ReturnValue = WriteContractReturnType
|
|
1598
|
+
|
|
1599
|
+
/** @internal */
|
|
1600
|
+
export async function inner<
|
|
1601
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
1602
|
+
chain extends Chain | undefined,
|
|
1603
|
+
account extends Account | undefined,
|
|
1604
|
+
>(
|
|
1605
|
+
action: action,
|
|
1606
|
+
client: Client<Transport, chain, account>,
|
|
1607
|
+
parameters: any,
|
|
1608
|
+
): Promise<ReturnType<action>> {
|
|
1609
|
+
const call = mint.call(parameters)
|
|
1610
|
+
return (await action(client, {
|
|
1611
|
+
...parameters,
|
|
1612
|
+
gas: 30_000n,
|
|
1613
|
+
...call,
|
|
1614
|
+
} as never)) as never
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
/**
|
|
1618
|
+
* Defines a call to the `mint` or `mintWithMemo` function.
|
|
1619
|
+
*
|
|
1620
|
+
* Can be passed as a parameter to:
|
|
1621
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1622
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1623
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1624
|
+
*
|
|
1625
|
+
* @example
|
|
1626
|
+
* ```ts
|
|
1627
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
1628
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1629
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1630
|
+
*
|
|
1631
|
+
* const client = createClient({
|
|
1632
|
+
* chain: tempo,
|
|
1633
|
+
* transport: http(),
|
|
1634
|
+
* }).extend(walletActions)
|
|
1635
|
+
*
|
|
1636
|
+
* const { result } = await client.sendCalls({
|
|
1637
|
+
* calls: [
|
|
1638
|
+
* actions.token.mint.call({
|
|
1639
|
+
* to: '0x20c0...beef',
|
|
1640
|
+
* amount: 100n,
|
|
1641
|
+
* token: '0x20c0...babe',
|
|
1642
|
+
* }),
|
|
1643
|
+
* ]
|
|
1644
|
+
* })
|
|
1645
|
+
* ```
|
|
1646
|
+
*
|
|
1647
|
+
* @param args - Arguments.
|
|
1648
|
+
* @returns The call.
|
|
1649
|
+
*/
|
|
1650
|
+
export function call(args: Args) {
|
|
1651
|
+
const { to, amount, memo, token } = args
|
|
1652
|
+
const callArgs = memo
|
|
1653
|
+
? ({
|
|
1654
|
+
functionName: 'mintWithMemo',
|
|
1655
|
+
args: [to, amount, Hex.padLeft(memo, 32)],
|
|
1656
|
+
} as const)
|
|
1657
|
+
: ({
|
|
1658
|
+
functionName: 'mint',
|
|
1659
|
+
args: [to, amount],
|
|
1660
|
+
} as const)
|
|
1661
|
+
return defineCall({
|
|
1662
|
+
address: TokenId.toAddress(token),
|
|
1663
|
+
abi: tip20Abi,
|
|
1664
|
+
...callArgs,
|
|
1665
|
+
})
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
/**
|
|
1669
|
+
* Extracts the event from the logs.
|
|
1670
|
+
*
|
|
1671
|
+
* @param logs - Logs.
|
|
1672
|
+
* @returns The event.
|
|
1673
|
+
*/
|
|
1674
|
+
export function extractEvent(logs: Log[]) {
|
|
1675
|
+
const [log] = parseEventLogs({
|
|
1676
|
+
abi: tip20Abi,
|
|
1677
|
+
logs,
|
|
1678
|
+
eventName: 'Mint',
|
|
1679
|
+
})
|
|
1680
|
+
if (!log) throw new Error('`Mint` event not found.')
|
|
1681
|
+
return log
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
/**
|
|
1686
|
+
* Mints TIP20 tokens to an address.
|
|
1687
|
+
*
|
|
1688
|
+
* @example
|
|
1689
|
+
* ```ts
|
|
1690
|
+
* import { createClient, http } from 'viem'
|
|
1691
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1692
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1693
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1694
|
+
*
|
|
1695
|
+
* const client = createClient({
|
|
1696
|
+
* account: privateKeyToAccount('0x...'),
|
|
1697
|
+
* chain: tempo,
|
|
1698
|
+
* transport: http(),
|
|
1699
|
+
* })
|
|
1700
|
+
*
|
|
1701
|
+
* const result = await actions.token.mintSync(client, {
|
|
1702
|
+
* to: '0x...',
|
|
1703
|
+
* amount: 100n,
|
|
1704
|
+
* token: '0x...',
|
|
1705
|
+
* })
|
|
1706
|
+
* ```
|
|
1707
|
+
*
|
|
1708
|
+
* @param client - Client.
|
|
1709
|
+
* @param parameters - Parameters.
|
|
1710
|
+
* @returns The transaction receipt and event data.
|
|
1711
|
+
*/
|
|
1712
|
+
export async function mintSync<
|
|
1713
|
+
chain extends Chain | undefined,
|
|
1714
|
+
account extends Account | undefined,
|
|
1715
|
+
>(
|
|
1716
|
+
client: Client<Transport, chain, account>,
|
|
1717
|
+
parameters: mintSync.Parameters<chain, account>,
|
|
1718
|
+
): Promise<mintSync.ReturnValue> {
|
|
1719
|
+
const receipt = await mint.inner(writeContractSync, client, parameters)
|
|
1720
|
+
const { args } = mint.extractEvent(receipt.logs)
|
|
1721
|
+
return {
|
|
1722
|
+
...args,
|
|
1723
|
+
receipt,
|
|
1724
|
+
} as never
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
export namespace mintSync {
|
|
1728
|
+
export type Parameters<
|
|
1729
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1730
|
+
account extends Account | undefined = Account | undefined,
|
|
1731
|
+
> = mint.Parameters<chain, account>
|
|
1732
|
+
|
|
1733
|
+
export type Args = mint.Args
|
|
1734
|
+
|
|
1735
|
+
export type ReturnValue = Compute<
|
|
1736
|
+
GetEventArgs<
|
|
1737
|
+
typeof tip20Abi,
|
|
1738
|
+
'Mint',
|
|
1739
|
+
{
|
|
1740
|
+
IndexedOnly: false
|
|
1741
|
+
Required: true
|
|
1742
|
+
}
|
|
1743
|
+
> & {
|
|
1744
|
+
receipt: TransactionReceipt
|
|
1745
|
+
}
|
|
1746
|
+
>
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
/**
|
|
1750
|
+
* Pauses a TIP20 token.
|
|
1751
|
+
*
|
|
1752
|
+
* @example
|
|
1753
|
+
* ```ts
|
|
1754
|
+
* import { createClient, http } from 'viem'
|
|
1755
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1756
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1757
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1758
|
+
*
|
|
1759
|
+
* const client = createClient({
|
|
1760
|
+
* account: privateKeyToAccount('0x...'),
|
|
1761
|
+
* chain: tempo,
|
|
1762
|
+
* transport: http(),
|
|
1763
|
+
* })
|
|
1764
|
+
*
|
|
1765
|
+
* const result = await actions.token.pause(client, {
|
|
1766
|
+
* token: '0x...',
|
|
1767
|
+
* })
|
|
1768
|
+
* ```
|
|
1769
|
+
*
|
|
1770
|
+
* @param client - Client.
|
|
1771
|
+
* @param parameters - Parameters.
|
|
1772
|
+
* @returns The transaction hash.
|
|
1773
|
+
*/
|
|
1774
|
+
export async function pause<
|
|
1775
|
+
chain extends Chain | undefined,
|
|
1776
|
+
account extends Account | undefined,
|
|
1777
|
+
>(
|
|
1778
|
+
client: Client<Transport, chain, account>,
|
|
1779
|
+
parameters: pause.Parameters<chain, account>,
|
|
1780
|
+
): Promise<pause.ReturnValue> {
|
|
1781
|
+
return pause.inner(writeContract, client, parameters)
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
export namespace pause {
|
|
1785
|
+
export type Parameters<
|
|
1786
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1787
|
+
account extends Account | undefined = Account | undefined,
|
|
1788
|
+
> = WriteParameters<chain, account> & Args
|
|
1789
|
+
|
|
1790
|
+
export type Args = {
|
|
1791
|
+
/** Address or ID of the TIP20 token. */
|
|
1792
|
+
token: TokenId.TokenIdOrAddress
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
export type ReturnValue = WriteContractReturnType
|
|
1796
|
+
|
|
1797
|
+
/** @internal */
|
|
1798
|
+
export async function inner<
|
|
1799
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
1800
|
+
chain extends Chain | undefined,
|
|
1801
|
+
account extends Account | undefined,
|
|
1802
|
+
>(
|
|
1803
|
+
action: action,
|
|
1804
|
+
client: Client<Transport, chain, account>,
|
|
1805
|
+
parameters: pause.Parameters<chain, account>,
|
|
1806
|
+
): Promise<ReturnType<action>> {
|
|
1807
|
+
const call = pause.call(parameters)
|
|
1808
|
+
return (await action(client, {
|
|
1809
|
+
...parameters,
|
|
1810
|
+
...call,
|
|
1811
|
+
} as never)) as never
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
/**
|
|
1815
|
+
* Defines a call to the `pause` function.
|
|
1816
|
+
*
|
|
1817
|
+
* Can be passed as a parameter to:
|
|
1818
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1819
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1820
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1821
|
+
*
|
|
1822
|
+
* @example
|
|
1823
|
+
* ```ts
|
|
1824
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
1825
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1826
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1827
|
+
*
|
|
1828
|
+
* const client = createClient({
|
|
1829
|
+
* chain: tempo,
|
|
1830
|
+
* transport: http(),
|
|
1831
|
+
* }).extend(walletActions)
|
|
1832
|
+
*
|
|
1833
|
+
* const { result } = await client.sendCalls({
|
|
1834
|
+
* calls: [
|
|
1835
|
+
* actions.token.pause.call({
|
|
1836
|
+
* token: '0x20c0...babe',
|
|
1837
|
+
* }),
|
|
1838
|
+
* ]
|
|
1839
|
+
* })
|
|
1840
|
+
* ```
|
|
1841
|
+
*
|
|
1842
|
+
* @param args - Arguments.
|
|
1843
|
+
* @returns The call.
|
|
1844
|
+
*/
|
|
1845
|
+
export function call(args: Args) {
|
|
1846
|
+
const { token } = args
|
|
1847
|
+
return defineCall({
|
|
1848
|
+
address: TokenId.toAddress(token),
|
|
1849
|
+
abi: tip20Abi,
|
|
1850
|
+
functionName: 'pause',
|
|
1851
|
+
args: [],
|
|
1852
|
+
})
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
/**
|
|
1856
|
+
* Extracts the event from the logs.
|
|
1857
|
+
*
|
|
1858
|
+
* @param logs - Logs.
|
|
1859
|
+
* @returns The event.
|
|
1860
|
+
*/
|
|
1861
|
+
export function extractEvent(logs: Log[]) {
|
|
1862
|
+
const [log] = parseEventLogs({
|
|
1863
|
+
abi: tip20Abi,
|
|
1864
|
+
logs,
|
|
1865
|
+
eventName: 'PauseStateUpdate',
|
|
1866
|
+
})
|
|
1867
|
+
if (!log) throw new Error('`PauseStateUpdate` event not found.')
|
|
1868
|
+
return log
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
/**
|
|
1873
|
+
* Pauses a TIP20 token.
|
|
1874
|
+
*
|
|
1875
|
+
* @example
|
|
1876
|
+
* ```ts
|
|
1877
|
+
* import { createClient, http } from 'viem'
|
|
1878
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1879
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1880
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1881
|
+
*
|
|
1882
|
+
* const client = createClient({
|
|
1883
|
+
* account: privateKeyToAccount('0x...'),
|
|
1884
|
+
* chain: tempo,
|
|
1885
|
+
* transport: http(),
|
|
1886
|
+
* })
|
|
1887
|
+
*
|
|
1888
|
+
* const result = await actions.token.pauseSync(client, {
|
|
1889
|
+
* token: '0x...',
|
|
1890
|
+
* })
|
|
1891
|
+
* ```
|
|
1892
|
+
*
|
|
1893
|
+
* @param client - Client.
|
|
1894
|
+
* @param parameters - Parameters.
|
|
1895
|
+
* @returns The transaction receipt and event data.
|
|
1896
|
+
*/
|
|
1897
|
+
export async function pauseSync<
|
|
1898
|
+
chain extends Chain | undefined,
|
|
1899
|
+
account extends Account | undefined,
|
|
1900
|
+
>(
|
|
1901
|
+
client: Client<Transport, chain, account>,
|
|
1902
|
+
parameters: pauseSync.Parameters<chain, account>,
|
|
1903
|
+
): Promise<pauseSync.ReturnValue> {
|
|
1904
|
+
const receipt = await pause.inner(writeContractSync, client, parameters)
|
|
1905
|
+
const { args } = pause.extractEvent(receipt.logs)
|
|
1906
|
+
return {
|
|
1907
|
+
...args,
|
|
1908
|
+
receipt,
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
export namespace pauseSync {
|
|
1913
|
+
export type Parameters<
|
|
1914
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1915
|
+
account extends Account | undefined = Account | undefined,
|
|
1916
|
+
> = pause.Parameters<chain, account>
|
|
1917
|
+
|
|
1918
|
+
export type Args = pause.Args
|
|
1919
|
+
|
|
1920
|
+
export type ReturnValue = GetEventArgs<
|
|
1921
|
+
typeof tip20Abi,
|
|
1922
|
+
'PauseStateUpdate',
|
|
1923
|
+
{ IndexedOnly: false; Required: true }
|
|
1924
|
+
> & {
|
|
1925
|
+
receipt: TransactionReceipt
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
/**
|
|
1930
|
+
* Approves a spender using a signed permit.
|
|
1931
|
+
*
|
|
1932
|
+
* @example
|
|
1933
|
+
* ```ts
|
|
1934
|
+
* import { createClient, http } from 'viem'
|
|
1935
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
1936
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
1937
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1938
|
+
*
|
|
1939
|
+
* const client = createClient({
|
|
1940
|
+
* account: privateKeyToAccount('0x...'),
|
|
1941
|
+
* chain: tempo,
|
|
1942
|
+
* transport: http(),
|
|
1943
|
+
* })
|
|
1944
|
+
*
|
|
1945
|
+
* const result = await actions.token.permit(client, {
|
|
1946
|
+
* owner: '0x...',
|
|
1947
|
+
* spender: '0x...',
|
|
1948
|
+
* value: 100n,
|
|
1949
|
+
* deadline: 1234567890n,
|
|
1950
|
+
* signature: { r: 0n, s: 0n, yParity: 0 },
|
|
1951
|
+
* })
|
|
1952
|
+
* ```
|
|
1953
|
+
*
|
|
1954
|
+
* @param client - Client.
|
|
1955
|
+
* @param parameters - Parameters.
|
|
1956
|
+
* @returns The transaction hash.
|
|
1957
|
+
*/
|
|
1958
|
+
export async function permit<
|
|
1959
|
+
chain extends Chain | undefined,
|
|
1960
|
+
account extends Account | undefined,
|
|
1961
|
+
>(
|
|
1962
|
+
client: Client<Transport, chain, account>,
|
|
1963
|
+
parameters: permit.Parameters<chain, account>,
|
|
1964
|
+
): Promise<permit.ReturnValue> {
|
|
1965
|
+
return permit.inner(writeContract, client, parameters)
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
export namespace permit {
|
|
1969
|
+
export type Parameters<
|
|
1970
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1971
|
+
account extends Account | undefined = Account | undefined,
|
|
1972
|
+
> = WriteParameters<chain, account> & Args
|
|
1973
|
+
|
|
1974
|
+
export type Args = {
|
|
1975
|
+
/** Deadline for the permit. */
|
|
1976
|
+
deadline: bigint
|
|
1977
|
+
/** Address of the owner. */
|
|
1978
|
+
owner: Address
|
|
1979
|
+
/** Signature. */
|
|
1980
|
+
signature: Signature.Signature
|
|
1981
|
+
/** Address of the spender. */
|
|
1982
|
+
spender: Address
|
|
1983
|
+
/** Address or ID of the TIP20 token. @default `usdAddress` */
|
|
1984
|
+
token?: TokenId.TokenIdOrAddress | undefined
|
|
1985
|
+
/** Amount to approve. */
|
|
1986
|
+
value: bigint
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
export type ReturnValue = WriteContractReturnType
|
|
1990
|
+
|
|
1991
|
+
/** @internal */
|
|
1992
|
+
export async function inner<
|
|
1993
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
1994
|
+
chain extends Chain | undefined,
|
|
1995
|
+
account extends Account | undefined,
|
|
1996
|
+
>(
|
|
1997
|
+
action: action,
|
|
1998
|
+
client: Client<Transport, chain, account>,
|
|
1999
|
+
parameters: permit.Parameters<chain, account>,
|
|
2000
|
+
): Promise<ReturnType<action>> {
|
|
2001
|
+
const call = permit.call(parameters)
|
|
2002
|
+
return (await action(client, {
|
|
2003
|
+
...parameters,
|
|
2004
|
+
...call,
|
|
2005
|
+
} as never)) as never
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
/**
|
|
2009
|
+
* Defines a call to the `permit` function.
|
|
2010
|
+
*
|
|
2011
|
+
* Can be passed as a parameter to:
|
|
2012
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
2013
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
2014
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
2015
|
+
*
|
|
2016
|
+
* @example
|
|
2017
|
+
* ```ts
|
|
2018
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
2019
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2020
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2021
|
+
*
|
|
2022
|
+
* const client = createClient({
|
|
2023
|
+
* chain: tempo,
|
|
2024
|
+
* transport: http(),
|
|
2025
|
+
* }).extend(walletActions)
|
|
2026
|
+
*
|
|
2027
|
+
* const { result } = await client.sendCalls({
|
|
2028
|
+
* calls: [
|
|
2029
|
+
* actions.token.permit.call({
|
|
2030
|
+
* owner: '0x20c0...beef',
|
|
2031
|
+
* spender: '0x20c0...babe',
|
|
2032
|
+
* value: 100n,
|
|
2033
|
+
* deadline: 1234567890n,
|
|
2034
|
+
* signature: { r: 0n, s: 0n, yParity: 0 },
|
|
2035
|
+
* token: '0x20c0...cafe',
|
|
2036
|
+
* }),
|
|
2037
|
+
* ]
|
|
2038
|
+
* })
|
|
2039
|
+
* ```
|
|
2040
|
+
*
|
|
2041
|
+
* @param args - Arguments.
|
|
2042
|
+
* @returns The call.
|
|
2043
|
+
*/
|
|
2044
|
+
export function call(args: Args) {
|
|
2045
|
+
const {
|
|
2046
|
+
owner,
|
|
2047
|
+
spender,
|
|
2048
|
+
value,
|
|
2049
|
+
deadline,
|
|
2050
|
+
signature,
|
|
2051
|
+
token = usdAddress,
|
|
2052
|
+
} = args
|
|
2053
|
+
const { r, s, yParity } = Signature.from(signature)
|
|
2054
|
+
const v = Signature.yParityToV(yParity)
|
|
2055
|
+
return defineCall({
|
|
2056
|
+
address: TokenId.toAddress(token),
|
|
2057
|
+
abi: tip20Abi,
|
|
2058
|
+
functionName: 'permit',
|
|
2059
|
+
args: [
|
|
2060
|
+
owner,
|
|
2061
|
+
spender,
|
|
2062
|
+
value,
|
|
2063
|
+
deadline,
|
|
2064
|
+
v,
|
|
2065
|
+
Hex.trimLeft(Hex.fromNumber(r!)),
|
|
2066
|
+
Hex.trimLeft(Hex.fromNumber(s!)),
|
|
2067
|
+
],
|
|
2068
|
+
})
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
/**
|
|
2072
|
+
* Extracts the event from the logs.
|
|
2073
|
+
*
|
|
2074
|
+
* @param logs - Logs.
|
|
2075
|
+
* @returns The event.
|
|
2076
|
+
*/
|
|
2077
|
+
export function extractEvent(logs: Log[]) {
|
|
2078
|
+
const [log] = parseEventLogs({
|
|
2079
|
+
abi: tip20Abi,
|
|
2080
|
+
logs,
|
|
2081
|
+
eventName: 'Approval',
|
|
2082
|
+
})
|
|
2083
|
+
if (!log) throw new Error('`Approval` event not found.')
|
|
2084
|
+
return log
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
/**
|
|
2089
|
+
* Approves a spender using a signed permit.
|
|
2090
|
+
*
|
|
2091
|
+
* @example
|
|
2092
|
+
* ```ts
|
|
2093
|
+
* import { createClient, http } from 'viem'
|
|
2094
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2095
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2096
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2097
|
+
*
|
|
2098
|
+
* const client = createClient({
|
|
2099
|
+
* account: privateKeyToAccount('0x...'),
|
|
2100
|
+
* chain: tempo,
|
|
2101
|
+
* transport: http(),
|
|
2102
|
+
* })
|
|
2103
|
+
*
|
|
2104
|
+
* const result = await actions.token.permitSync(client, {
|
|
2105
|
+
* owner: '0x...',
|
|
2106
|
+
* spender: '0x...',
|
|
2107
|
+
* value: 100n,
|
|
2108
|
+
* deadline: 1234567890n,
|
|
2109
|
+
* signature: { r: 0n, s: 0n, yParity: 0 },
|
|
2110
|
+
* })
|
|
2111
|
+
* ```
|
|
2112
|
+
*
|
|
2113
|
+
* @param client - Client.
|
|
2114
|
+
* @param parameters - Parameters.
|
|
2115
|
+
* @returns The transaction receipt and event data.
|
|
2116
|
+
*/
|
|
2117
|
+
export async function permitSync<
|
|
2118
|
+
chain extends Chain | undefined,
|
|
2119
|
+
account extends Account | undefined,
|
|
2120
|
+
>(
|
|
2121
|
+
client: Client<Transport, chain, account>,
|
|
2122
|
+
parameters: permitSync.Parameters<chain, account>,
|
|
2123
|
+
): Promise<permitSync.ReturnValue> {
|
|
2124
|
+
const receipt = await permit.inner(writeContractSync, client, parameters)
|
|
2125
|
+
const { args } = permit.extractEvent(receipt.logs)
|
|
2126
|
+
return {
|
|
2127
|
+
...args,
|
|
2128
|
+
receipt,
|
|
2129
|
+
} as never
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
export namespace permitSync {
|
|
2133
|
+
export type Parameters<
|
|
2134
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
2135
|
+
account extends Account | undefined = Account | undefined,
|
|
2136
|
+
> = permit.Parameters<chain, account>
|
|
2137
|
+
|
|
2138
|
+
export type Args = permit.Args
|
|
2139
|
+
|
|
2140
|
+
export type ReturnValue = GetEventArgs<
|
|
2141
|
+
typeof tip20Abi,
|
|
2142
|
+
'Approval',
|
|
2143
|
+
{ IndexedOnly: false; Required: true }
|
|
2144
|
+
> & {
|
|
2145
|
+
receipt: TransactionReceipt
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
/**
|
|
2150
|
+
* Renounces a role for a TIP20 token.
|
|
2151
|
+
*
|
|
2152
|
+
* @example
|
|
2153
|
+
* ```ts
|
|
2154
|
+
* import { createClient, http } from 'viem'
|
|
2155
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2156
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2157
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2158
|
+
*
|
|
2159
|
+
* const client = createClient({
|
|
2160
|
+
* account: privateKeyToAccount('0x...'),
|
|
2161
|
+
* chain: tempo,
|
|
2162
|
+
* transport: http(),
|
|
2163
|
+
* })
|
|
2164
|
+
*
|
|
2165
|
+
* const result = await actions.token.renounceRoles(client, {
|
|
2166
|
+
* token: '0x...',
|
|
2167
|
+
* roles: ['minter'],
|
|
2168
|
+
* })
|
|
2169
|
+
* ```
|
|
2170
|
+
*
|
|
2171
|
+
* @param client - Client.
|
|
2172
|
+
* @param parameters - Parameters.
|
|
2173
|
+
* @returns The transaction hash.
|
|
2174
|
+
*/
|
|
2175
|
+
export async function renounceRoles<
|
|
2176
|
+
chain extends Chain | undefined,
|
|
2177
|
+
account extends Account | undefined,
|
|
2178
|
+
>(
|
|
2179
|
+
client: Client<Transport, chain, account>,
|
|
2180
|
+
parameters: renounceRoles.Parameters<chain, account>,
|
|
2181
|
+
): Promise<renounceRoles.ReturnValue> {
|
|
2182
|
+
return renounceRoles.inner(sendTransaction, client, parameters)
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
export namespace renounceRoles {
|
|
2186
|
+
export type Parameters<
|
|
2187
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
2188
|
+
account extends Account | undefined = Account | undefined,
|
|
2189
|
+
> = WriteParameters<chain, account> &
|
|
2190
|
+
Omit<Args, 'role'> & {
|
|
2191
|
+
/** Roles to renounce. */
|
|
2192
|
+
roles: readonly TokenRole.TokenRole[]
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
export type Args = {
|
|
2196
|
+
/** Role to renounce. */
|
|
2197
|
+
role: TokenRole.TokenRole
|
|
2198
|
+
/** Address or ID of the TIP20 token. */
|
|
2199
|
+
token: TokenId.TokenIdOrAddress
|
|
2200
|
+
}
|
|
2201
|
+
|
|
2202
|
+
export type ReturnValue = WriteContractReturnType
|
|
2203
|
+
|
|
2204
|
+
/** @internal */
|
|
2205
|
+
export async function inner<
|
|
2206
|
+
action extends typeof sendTransaction | typeof sendTransactionSync,
|
|
2207
|
+
chain extends Chain | undefined,
|
|
2208
|
+
account extends Account | undefined,
|
|
2209
|
+
>(
|
|
2210
|
+
action: action,
|
|
2211
|
+
client: Client<Transport, chain, account>,
|
|
2212
|
+
parameters: renounceRoles.Parameters<chain, account>,
|
|
2213
|
+
): Promise<ReturnType<action>> {
|
|
2214
|
+
return (await action(client, {
|
|
2215
|
+
...parameters,
|
|
2216
|
+
calls: parameters.roles.map((role) => {
|
|
2217
|
+
const call = renounceRoles.call({ ...parameters, role })
|
|
2218
|
+
return {
|
|
2219
|
+
...call,
|
|
2220
|
+
data: encodeFunctionData(call),
|
|
2221
|
+
}
|
|
2222
|
+
}),
|
|
2223
|
+
} as never)) as never
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
/**
|
|
2227
|
+
* Defines a call to the `renounceRole` function.
|
|
2228
|
+
*
|
|
2229
|
+
* Can be passed as a parameter to:
|
|
2230
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
2231
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
2232
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
2233
|
+
*
|
|
2234
|
+
* @example
|
|
2235
|
+
* ```ts
|
|
2236
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
2237
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2238
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2239
|
+
*
|
|
2240
|
+
* const client = createClient({
|
|
2241
|
+
* chain: tempo,
|
|
2242
|
+
* transport: http(),
|
|
2243
|
+
* }).extend(walletActions)
|
|
2244
|
+
*
|
|
2245
|
+
* const { result } = await client.sendCalls({
|
|
2246
|
+
* calls: [
|
|
2247
|
+
* actions.token.renounceRoles.call({
|
|
2248
|
+
* token: '0x20c0...babe',
|
|
2249
|
+
* role: 'minter',
|
|
2250
|
+
* }),
|
|
2251
|
+
* ]
|
|
2252
|
+
* })
|
|
2253
|
+
* ```
|
|
2254
|
+
*
|
|
2255
|
+
* @param args - Arguments.
|
|
2256
|
+
* @returns The call.
|
|
2257
|
+
*/
|
|
2258
|
+
export function call(args: Args) {
|
|
2259
|
+
const { token, role } = args
|
|
2260
|
+
const roleHash = TokenRole.serialize(role)
|
|
2261
|
+
return defineCall({
|
|
2262
|
+
address: TokenId.toAddress(token),
|
|
2263
|
+
abi: tip20Abi,
|
|
2264
|
+
functionName: 'renounceRole',
|
|
2265
|
+
args: [roleHash],
|
|
2266
|
+
})
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
/**
|
|
2270
|
+
* Extracts the events from the logs.
|
|
2271
|
+
*
|
|
2272
|
+
* @param logs - Logs.
|
|
2273
|
+
* @returns The events.
|
|
2274
|
+
*/
|
|
2275
|
+
export function extractEvents(logs: Log[]) {
|
|
2276
|
+
const events = parseEventLogs({
|
|
2277
|
+
abi: tip20Abi,
|
|
2278
|
+
logs,
|
|
2279
|
+
eventName: 'RoleMembershipUpdated',
|
|
2280
|
+
})
|
|
2281
|
+
if (events.length === 0)
|
|
2282
|
+
throw new Error('`RoleMembershipUpdated` events not found.')
|
|
2283
|
+
return events
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
/**
|
|
2288
|
+
* Renounces a role for a TIP20 token.
|
|
2289
|
+
*
|
|
2290
|
+
* @example
|
|
2291
|
+
* ```ts
|
|
2292
|
+
* import { createClient, http } from 'viem'
|
|
2293
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2294
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2295
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2296
|
+
*
|
|
2297
|
+
* const client = createClient({
|
|
2298
|
+
* account: privateKeyToAccount('0x...'),
|
|
2299
|
+
* chain: tempo,
|
|
2300
|
+
* transport: http(),
|
|
2301
|
+
* })
|
|
2302
|
+
*
|
|
2303
|
+
* const result = await actions.token.renounceRolesSync(client, {
|
|
2304
|
+
* token: '0x...',
|
|
2305
|
+
* roles: ['minter'],
|
|
2306
|
+
* })
|
|
2307
|
+
* ```
|
|
2308
|
+
*
|
|
2309
|
+
* @param client - Client.
|
|
2310
|
+
* @param parameters - Parameters.
|
|
2311
|
+
* @returns The transaction receipt and event data.
|
|
2312
|
+
*/
|
|
2313
|
+
export async function renounceRolesSync<
|
|
2314
|
+
chain extends Chain | undefined,
|
|
2315
|
+
account extends Account | undefined,
|
|
2316
|
+
>(
|
|
2317
|
+
client: Client<Transport, chain, account>,
|
|
2318
|
+
parameters: renounceRolesSync.Parameters<chain, account>,
|
|
2319
|
+
): Promise<renounceRolesSync.ReturnValue> {
|
|
2320
|
+
const receipt = await renounceRoles.inner(
|
|
2321
|
+
sendTransactionSync,
|
|
2322
|
+
client,
|
|
2323
|
+
parameters,
|
|
2324
|
+
)
|
|
2325
|
+
const events = renounceRoles.extractEvents(receipt.logs)
|
|
2326
|
+
const value = events.map((event) => event.args)
|
|
2327
|
+
return {
|
|
2328
|
+
receipt,
|
|
2329
|
+
value,
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
export namespace renounceRolesSync {
|
|
2334
|
+
export type Parameters<
|
|
2335
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
2336
|
+
account extends Account | undefined = Account | undefined,
|
|
2337
|
+
> = renounceRoles.Parameters<chain, account>
|
|
2338
|
+
|
|
2339
|
+
export type Args = renounceRoles.Args
|
|
2340
|
+
|
|
2341
|
+
export type ReturnValue = {
|
|
2342
|
+
receipt: TransactionReceipt
|
|
2343
|
+
value: readonly GetEventArgs<
|
|
2344
|
+
typeof tip20Abi,
|
|
2345
|
+
'RoleMembershipUpdated',
|
|
2346
|
+
{ IndexedOnly: false; Required: true }
|
|
2347
|
+
>[]
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
/**
|
|
2352
|
+
* Revokes a role for a TIP20 token.
|
|
2353
|
+
*
|
|
2354
|
+
* @example
|
|
2355
|
+
* ```ts
|
|
2356
|
+
* import { createClient, http } from 'viem'
|
|
2357
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2358
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2359
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2360
|
+
*
|
|
2361
|
+
* const client = createClient({
|
|
2362
|
+
* account: privateKeyToAccount('0x...'),
|
|
2363
|
+
* chain: tempo,
|
|
2364
|
+
* transport: http(),
|
|
2365
|
+
* })
|
|
2366
|
+
*
|
|
2367
|
+
* const result = await actions.token.revokeRoles(client, {
|
|
2368
|
+
* token: '0x...',
|
|
2369
|
+
* from: '0x...',
|
|
2370
|
+
* roles: ['minter'],
|
|
2371
|
+
* })
|
|
2372
|
+
* ```
|
|
2373
|
+
*
|
|
2374
|
+
* @param client - Client.
|
|
2375
|
+
* @param parameters - Parameters.
|
|
2376
|
+
* @returns The transaction hash.
|
|
2377
|
+
*/
|
|
2378
|
+
export async function revokeRoles<
|
|
2379
|
+
chain extends Chain | undefined,
|
|
2380
|
+
account extends Account | undefined,
|
|
2381
|
+
>(
|
|
2382
|
+
client: Client<Transport, chain, account>,
|
|
2383
|
+
parameters: revokeRoles.Parameters<chain, account>,
|
|
2384
|
+
): Promise<revokeRoles.ReturnValue> {
|
|
2385
|
+
return revokeRoles.inner(sendTransaction, client, parameters)
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
export namespace revokeRoles {
|
|
2389
|
+
export type Parameters<
|
|
2390
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
2391
|
+
account extends Account | undefined = Account | undefined,
|
|
2392
|
+
> = SendTransactionSyncParameters<chain, account> &
|
|
2393
|
+
Omit<Args, 'role'> & {
|
|
2394
|
+
/** Role to revoke. */
|
|
2395
|
+
roles: readonly TokenRole.TokenRole[]
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
export type Args = {
|
|
2399
|
+
/** Address to revoke the role from. */
|
|
2400
|
+
from: Address
|
|
2401
|
+
/** Role to revoke. */
|
|
2402
|
+
role: TokenRole.TokenRole
|
|
2403
|
+
/** Address or ID of the TIP20 token. */
|
|
2404
|
+
token: TokenId.TokenIdOrAddress
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
export type ReturnValue = WriteContractReturnType
|
|
2408
|
+
|
|
2409
|
+
/** @internal */
|
|
2410
|
+
export async function inner<
|
|
2411
|
+
action extends typeof sendTransaction | typeof sendTransactionSync,
|
|
2412
|
+
chain extends Chain | undefined,
|
|
2413
|
+
account extends Account | undefined,
|
|
2414
|
+
>(
|
|
2415
|
+
action: action,
|
|
2416
|
+
client: Client<Transport, chain, account>,
|
|
2417
|
+
parameters: revokeRoles.Parameters<chain, account>,
|
|
2418
|
+
): Promise<ReturnType<action>> {
|
|
2419
|
+
return (await action(client, {
|
|
2420
|
+
...parameters,
|
|
2421
|
+
calls: parameters.roles.map((role) => {
|
|
2422
|
+
const call = revokeRoles.call({ ...parameters, role })
|
|
2423
|
+
return {
|
|
2424
|
+
...call,
|
|
2425
|
+
data: encodeFunctionData(call),
|
|
2426
|
+
}
|
|
2427
|
+
}),
|
|
2428
|
+
} as never)) as never
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
/**
|
|
2432
|
+
* Defines a call to the `revokeRole` function.
|
|
2433
|
+
*
|
|
2434
|
+
* Can be passed as a parameter to:
|
|
2435
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
2436
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
2437
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
2438
|
+
*
|
|
2439
|
+
* @example
|
|
2440
|
+
* ```ts
|
|
2441
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
2442
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2443
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2444
|
+
*
|
|
2445
|
+
* const client = createClient({
|
|
2446
|
+
* chain: tempo,
|
|
2447
|
+
* transport: http(),
|
|
2448
|
+
* }).extend(walletActions)
|
|
2449
|
+
*
|
|
2450
|
+
* const { result } = await client.sendCalls({
|
|
2451
|
+
* calls: [
|
|
2452
|
+
* actions.token.revokeRoles.call({
|
|
2453
|
+
* token: '0x20c0...babe',
|
|
2454
|
+
* from: '0x20c0...beef',
|
|
2455
|
+
* role: 'minter',
|
|
2456
|
+
* }),
|
|
2457
|
+
* ]
|
|
2458
|
+
* })
|
|
2459
|
+
* ```
|
|
2460
|
+
*
|
|
2461
|
+
* @param args - Arguments.
|
|
2462
|
+
* @returns The call.
|
|
2463
|
+
*/
|
|
2464
|
+
export function call(args: Args) {
|
|
2465
|
+
const { token, from, role } = args
|
|
2466
|
+
const roleHash = TokenRole.serialize(role)
|
|
2467
|
+
return defineCall({
|
|
2468
|
+
address: TokenId.toAddress(token),
|
|
2469
|
+
abi: tip20Abi,
|
|
2470
|
+
functionName: 'revokeRole',
|
|
2471
|
+
args: [roleHash, from],
|
|
2472
|
+
})
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
/**
|
|
2476
|
+
* Extracts the events from the logs.
|
|
2477
|
+
*
|
|
2478
|
+
* @param logs - Logs.
|
|
2479
|
+
* @returns The events.
|
|
2480
|
+
*/
|
|
2481
|
+
export function extractEvents(logs: Log[]) {
|
|
2482
|
+
const events = parseEventLogs({
|
|
2483
|
+
abi: tip20Abi,
|
|
2484
|
+
logs,
|
|
2485
|
+
eventName: 'RoleMembershipUpdated',
|
|
2486
|
+
})
|
|
2487
|
+
if (events.length === 0)
|
|
2488
|
+
throw new Error('`RoleMembershipUpdated` events not found.')
|
|
2489
|
+
return events
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
/**
|
|
2494
|
+
* Revokes a role for a TIP20 token.
|
|
2495
|
+
*
|
|
2496
|
+
* @example
|
|
2497
|
+
* ```ts
|
|
2498
|
+
* import { createClient, http } from 'viem'
|
|
2499
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2500
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2501
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2502
|
+
*
|
|
2503
|
+
* const client = createClient({
|
|
2504
|
+
* account: privateKeyToAccount('0x...'),
|
|
2505
|
+
* chain: tempo,
|
|
2506
|
+
* transport: http(),
|
|
2507
|
+
* })
|
|
2508
|
+
*
|
|
2509
|
+
* const result = await actions.token.revokeRolesSync(client, {
|
|
2510
|
+
* token: '0x...',
|
|
2511
|
+
* from: '0x...',
|
|
2512
|
+
* roles: ['minter'],
|
|
2513
|
+
* })
|
|
2514
|
+
* ```
|
|
2515
|
+
*
|
|
2516
|
+
* @param client - Client.
|
|
2517
|
+
* @param parameters - Parameters.
|
|
2518
|
+
* @returns The transaction receipt and event data.
|
|
2519
|
+
*/
|
|
2520
|
+
export async function revokeRolesSync<
|
|
2521
|
+
chain extends Chain | undefined,
|
|
2522
|
+
account extends Account | undefined,
|
|
2523
|
+
>(
|
|
2524
|
+
client: Client<Transport, chain, account>,
|
|
2525
|
+
parameters: revokeRolesSync.Parameters<chain, account>,
|
|
2526
|
+
): Promise<revokeRolesSync.ReturnValue> {
|
|
2527
|
+
const receipt = await revokeRoles.inner(
|
|
2528
|
+
sendTransactionSync,
|
|
2529
|
+
client,
|
|
2530
|
+
parameters,
|
|
2531
|
+
)
|
|
2532
|
+
const events = revokeRoles.extractEvents(receipt.logs)
|
|
2533
|
+
const value = events.map((event) => event.args)
|
|
2534
|
+
return {
|
|
2535
|
+
receipt,
|
|
2536
|
+
value,
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
export namespace revokeRolesSync {
|
|
2541
|
+
export type Parameters<
|
|
2542
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
2543
|
+
account extends Account | undefined = Account | undefined,
|
|
2544
|
+
> = revokeRoles.Parameters<chain, account>
|
|
2545
|
+
|
|
2546
|
+
export type Args = revokeRoles.Args
|
|
2547
|
+
|
|
2548
|
+
export type ReturnValue = {
|
|
2549
|
+
receipt: TransactionReceipt
|
|
2550
|
+
value: readonly GetEventArgs<
|
|
2551
|
+
typeof tip20Abi,
|
|
2552
|
+
'RoleMembershipUpdated',
|
|
2553
|
+
{ IndexedOnly: false; Required: true }
|
|
2554
|
+
>[]
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2558
|
+
/**
|
|
2559
|
+
* Sets the supply cap for a TIP20 token.
|
|
2560
|
+
*
|
|
2561
|
+
* @example
|
|
2562
|
+
* ```ts
|
|
2563
|
+
* import { createClient, http } from 'viem'
|
|
2564
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2565
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2566
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2567
|
+
*
|
|
2568
|
+
* const client = createClient({
|
|
2569
|
+
* account: privateKeyToAccount('0x...'),
|
|
2570
|
+
* chain: tempo,
|
|
2571
|
+
* transport: http(),
|
|
2572
|
+
* })
|
|
2573
|
+
*
|
|
2574
|
+
* const result = await actions.token.setSupplyCap(client, {
|
|
2575
|
+
* token: '0x...',
|
|
2576
|
+
* supplyCap: 1000000n,
|
|
2577
|
+
* })
|
|
2578
|
+
* ```
|
|
2579
|
+
*
|
|
2580
|
+
* @param client - Client.
|
|
2581
|
+
* @param parameters - Parameters.
|
|
2582
|
+
* @returns The transaction hash.
|
|
2583
|
+
*/
|
|
2584
|
+
export async function setSupplyCap<
|
|
2585
|
+
chain extends Chain | undefined,
|
|
2586
|
+
account extends Account | undefined,
|
|
2587
|
+
>(
|
|
2588
|
+
client: Client<Transport, chain, account>,
|
|
2589
|
+
parameters: setSupplyCap.Parameters<chain, account>,
|
|
2590
|
+
): Promise<setSupplyCap.ReturnValue> {
|
|
2591
|
+
return setSupplyCap.inner(writeContract, client, parameters)
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
export namespace setSupplyCap {
|
|
2595
|
+
export type Parameters<
|
|
2596
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
2597
|
+
account extends Account | undefined = Account | undefined,
|
|
2598
|
+
> = WriteParameters<chain, account> & Args
|
|
2599
|
+
|
|
2600
|
+
export type Args = {
|
|
2601
|
+
/** New supply cap. */
|
|
2602
|
+
supplyCap: bigint
|
|
2603
|
+
/** Address or ID of the TIP20 token. */
|
|
2604
|
+
token: TokenId.TokenIdOrAddress
|
|
2605
|
+
}
|
|
2606
|
+
|
|
2607
|
+
export type ReturnValue = WriteContractReturnType
|
|
2608
|
+
|
|
2609
|
+
/** @internal */
|
|
2610
|
+
export async function inner<
|
|
2611
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
2612
|
+
chain extends Chain | undefined,
|
|
2613
|
+
account extends Account | undefined,
|
|
2614
|
+
>(
|
|
2615
|
+
action: action,
|
|
2616
|
+
client: Client<Transport, chain, account>,
|
|
2617
|
+
parameters: setSupplyCap.Parameters<chain, account>,
|
|
2618
|
+
): Promise<ReturnType<action>> {
|
|
2619
|
+
const call = setSupplyCap.call(parameters)
|
|
2620
|
+
return (await action(client, {
|
|
2621
|
+
...parameters,
|
|
2622
|
+
...call,
|
|
2623
|
+
} as never)) as never
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
/**
|
|
2627
|
+
* Defines a call to the `setSupplyCap` function.
|
|
2628
|
+
*
|
|
2629
|
+
* Can be passed as a parameter to:
|
|
2630
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
2631
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
2632
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
2633
|
+
*
|
|
2634
|
+
* @example
|
|
2635
|
+
* ```ts
|
|
2636
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
2637
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2638
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2639
|
+
*
|
|
2640
|
+
* const client = createClient({
|
|
2641
|
+
* chain: tempo,
|
|
2642
|
+
* transport: http(),
|
|
2643
|
+
* }).extend(walletActions)
|
|
2644
|
+
*
|
|
2645
|
+
* const { result } = await client.sendCalls({
|
|
2646
|
+
* calls: [
|
|
2647
|
+
* actions.token.setSupplyCap.call({
|
|
2648
|
+
* token: '0x20c0...babe',
|
|
2649
|
+
* supplyCap: 1000000n,
|
|
2650
|
+
* }),
|
|
2651
|
+
* ]
|
|
2652
|
+
* })
|
|
2653
|
+
* ```
|
|
2654
|
+
*
|
|
2655
|
+
* @param args - Arguments.
|
|
2656
|
+
* @returns The call.
|
|
2657
|
+
*/
|
|
2658
|
+
export function call(args: Args) {
|
|
2659
|
+
const { token, supplyCap } = args
|
|
2660
|
+
return defineCall({
|
|
2661
|
+
address: TokenId.toAddress(token),
|
|
2662
|
+
abi: tip20Abi,
|
|
2663
|
+
functionName: 'setSupplyCap',
|
|
2664
|
+
args: [supplyCap],
|
|
2665
|
+
})
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
/**
|
|
2669
|
+
* Extracts the event from the logs.
|
|
2670
|
+
*
|
|
2671
|
+
* @param logs - Logs.
|
|
2672
|
+
* @returns The event.
|
|
2673
|
+
*/
|
|
2674
|
+
export function extractEvent(logs: Log[]) {
|
|
2675
|
+
const [log] = parseEventLogs({
|
|
2676
|
+
abi: tip20Abi,
|
|
2677
|
+
logs,
|
|
2678
|
+
eventName: 'SupplyCapUpdate',
|
|
2679
|
+
})
|
|
2680
|
+
if (!log) throw new Error('`SupplyCapUpdate` event not found.')
|
|
2681
|
+
return log
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
|
|
2685
|
+
/**
|
|
2686
|
+
* Sets the supply cap for a TIP20 token.
|
|
2687
|
+
*
|
|
2688
|
+
* @example
|
|
2689
|
+
* ```ts
|
|
2690
|
+
* import { createClient, http } from 'viem'
|
|
2691
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2692
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2693
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2694
|
+
*
|
|
2695
|
+
* const client = createClient({
|
|
2696
|
+
* account: privateKeyToAccount('0x...'),
|
|
2697
|
+
* chain: tempo,
|
|
2698
|
+
* transport: http(),
|
|
2699
|
+
* })
|
|
2700
|
+
*
|
|
2701
|
+
* const result = await actions.token.setSupplyCapSync(client, {
|
|
2702
|
+
* token: '0x...',
|
|
2703
|
+
* supplyCap: 1000000n,
|
|
2704
|
+
* })
|
|
2705
|
+
* ```
|
|
2706
|
+
*
|
|
2707
|
+
* @param client - Client.
|
|
2708
|
+
* @param parameters - Parameters.
|
|
2709
|
+
* @returns The transaction receipt and event data.
|
|
2710
|
+
*/
|
|
2711
|
+
export async function setSupplyCapSync<
|
|
2712
|
+
chain extends Chain | undefined,
|
|
2713
|
+
account extends Account | undefined,
|
|
2714
|
+
>(
|
|
2715
|
+
client: Client<Transport, chain, account>,
|
|
2716
|
+
parameters: setSupplyCapSync.Parameters<chain, account>,
|
|
2717
|
+
): Promise<setSupplyCapSync.ReturnValue> {
|
|
2718
|
+
const receipt = await setSupplyCap.inner(
|
|
2719
|
+
writeContractSync,
|
|
2720
|
+
client,
|
|
2721
|
+
parameters,
|
|
2722
|
+
)
|
|
2723
|
+
const { args } = setSupplyCap.extractEvent(receipt.logs)
|
|
2724
|
+
return {
|
|
2725
|
+
...args,
|
|
2726
|
+
receipt,
|
|
2727
|
+
} as never
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
export namespace setSupplyCapSync {
|
|
2731
|
+
export type Parameters<
|
|
2732
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
2733
|
+
account extends Account | undefined = Account | undefined,
|
|
2734
|
+
> = setSupplyCap.Parameters<chain, account>
|
|
2735
|
+
|
|
2736
|
+
export type Args = setSupplyCap.Args
|
|
2737
|
+
|
|
2738
|
+
export type ReturnValue = GetEventArgs<
|
|
2739
|
+
typeof tip20Abi,
|
|
2740
|
+
'SupplyCapUpdate',
|
|
2741
|
+
{ IndexedOnly: false; Required: true }
|
|
2742
|
+
> & {
|
|
2743
|
+
receipt: TransactionReceipt
|
|
2744
|
+
}
|
|
2745
|
+
}
|
|
2746
|
+
|
|
2747
|
+
/**
|
|
2748
|
+
* Sets the admin role for a specific role in a TIP20 token.
|
|
2749
|
+
*
|
|
2750
|
+
* @example
|
|
2751
|
+
* ```ts
|
|
2752
|
+
* import { createClient, http } from 'viem'
|
|
2753
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2754
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2755
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2756
|
+
*
|
|
2757
|
+
* const client = createClient({
|
|
2758
|
+
* account: privateKeyToAccount('0x...'),
|
|
2759
|
+
* chain: tempo,
|
|
2760
|
+
* transport: http(),
|
|
2761
|
+
* })
|
|
2762
|
+
*
|
|
2763
|
+
* const result = await actions.token.setRoleAdmin(client, {
|
|
2764
|
+
* token: '0x...',
|
|
2765
|
+
* role: 'minter',
|
|
2766
|
+
* adminRole: 'admin',
|
|
2767
|
+
* })
|
|
2768
|
+
* ```
|
|
2769
|
+
*
|
|
2770
|
+
* @param client - Client.
|
|
2771
|
+
* @param parameters - Parameters.
|
|
2772
|
+
* @returns The transaction hash.
|
|
2773
|
+
*/
|
|
2774
|
+
export async function setRoleAdmin<
|
|
2775
|
+
chain extends Chain | undefined,
|
|
2776
|
+
account extends Account | undefined,
|
|
2777
|
+
>(
|
|
2778
|
+
client: Client<Transport, chain, account>,
|
|
2779
|
+
parameters: setRoleAdmin.Parameters<chain, account>,
|
|
2780
|
+
): Promise<setRoleAdmin.ReturnValue> {
|
|
2781
|
+
return setRoleAdmin.inner(writeContract, client, parameters)
|
|
2782
|
+
}
|
|
2783
|
+
|
|
2784
|
+
export namespace setRoleAdmin {
|
|
2785
|
+
export type Parameters<
|
|
2786
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
2787
|
+
account extends Account | undefined = Account | undefined,
|
|
2788
|
+
> = WriteParameters<chain, account> & Args
|
|
2789
|
+
|
|
2790
|
+
export type Args = {
|
|
2791
|
+
/** New admin role. */
|
|
2792
|
+
adminRole: TokenRole.TokenRole
|
|
2793
|
+
/** Role to set admin for. */
|
|
2794
|
+
role: TokenRole.TokenRole
|
|
2795
|
+
/** Address or ID of the TIP20 token. */
|
|
2796
|
+
token: TokenId.TokenIdOrAddress
|
|
2797
|
+
}
|
|
2798
|
+
|
|
2799
|
+
export type ReturnValue = WriteContractReturnType
|
|
2800
|
+
|
|
2801
|
+
/** @internal */
|
|
2802
|
+
export async function inner<
|
|
2803
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
2804
|
+
chain extends Chain | undefined,
|
|
2805
|
+
account extends Account | undefined,
|
|
2806
|
+
>(
|
|
2807
|
+
action: action,
|
|
2808
|
+
client: Client<Transport, chain, account>,
|
|
2809
|
+
parameters: setRoleAdmin.Parameters<chain, account>,
|
|
2810
|
+
): Promise<ReturnType<action>> {
|
|
2811
|
+
const call = setRoleAdmin.call(parameters)
|
|
2812
|
+
return (await action(client, {
|
|
2813
|
+
...parameters,
|
|
2814
|
+
...call,
|
|
2815
|
+
} as never)) as never
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
/**
|
|
2819
|
+
* Defines a call to the `setRoleAdmin` function.
|
|
2820
|
+
*
|
|
2821
|
+
* Can be passed as a parameter to:
|
|
2822
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
2823
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
2824
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
2825
|
+
*
|
|
2826
|
+
* @example
|
|
2827
|
+
* ```ts
|
|
2828
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
2829
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2830
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2831
|
+
*
|
|
2832
|
+
* const client = createClient({
|
|
2833
|
+
* chain: tempo,
|
|
2834
|
+
* transport: http(),
|
|
2835
|
+
* }).extend(walletActions)
|
|
2836
|
+
*
|
|
2837
|
+
* const { result } = await client.sendCalls({
|
|
2838
|
+
* calls: [
|
|
2839
|
+
* actions.token.setRoleAdmin.call({
|
|
2840
|
+
* token: '0x20c0...babe',
|
|
2841
|
+
* role: 'minter',
|
|
2842
|
+
* adminRole: 'admin',
|
|
2843
|
+
* }),
|
|
2844
|
+
* ]
|
|
2845
|
+
* })
|
|
2846
|
+
* ```
|
|
2847
|
+
*
|
|
2848
|
+
* @param args - Arguments.
|
|
2849
|
+
* @returns The call.
|
|
2850
|
+
*/
|
|
2851
|
+
export function call(args: Args) {
|
|
2852
|
+
const { token, role, adminRole } = args
|
|
2853
|
+
const roleHash = TokenRole.serialize(role)
|
|
2854
|
+
const adminRoleHash = TokenRole.serialize(adminRole)
|
|
2855
|
+
return defineCall({
|
|
2856
|
+
address: TokenId.toAddress(token),
|
|
2857
|
+
abi: tip20Abi,
|
|
2858
|
+
functionName: 'setRoleAdmin',
|
|
2859
|
+
args: [roleHash, adminRoleHash],
|
|
2860
|
+
})
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
/**
|
|
2864
|
+
* Extracts the event from the logs.
|
|
2865
|
+
*
|
|
2866
|
+
* @param logs - Logs.
|
|
2867
|
+
* @returns The event.
|
|
2868
|
+
*/
|
|
2869
|
+
export function extractEvent(logs: Log[]) {
|
|
2870
|
+
const [log] = parseEventLogs({
|
|
2871
|
+
abi: tip20Abi,
|
|
2872
|
+
logs,
|
|
2873
|
+
eventName: 'RoleAdminUpdated',
|
|
2874
|
+
})
|
|
2875
|
+
if (!log) throw new Error('`RoleAdminUpdated` event not found.')
|
|
2876
|
+
return log
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2879
|
+
|
|
2880
|
+
/**
|
|
2881
|
+
* Sets the admin role for a specific role in a TIP20 token.
|
|
2882
|
+
*
|
|
2883
|
+
* @example
|
|
2884
|
+
* ```ts
|
|
2885
|
+
* import { createClient, http } from 'viem'
|
|
2886
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2887
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2888
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2889
|
+
*
|
|
2890
|
+
* const client = createClient({
|
|
2891
|
+
* account: privateKeyToAccount('0x...'),
|
|
2892
|
+
* chain: tempo,
|
|
2893
|
+
* transport: http(),
|
|
2894
|
+
* })
|
|
2895
|
+
*
|
|
2896
|
+
* const result = await actions.token.setRoleAdminSync(client, {
|
|
2897
|
+
* token: '0x...',
|
|
2898
|
+
* role: 'minter',
|
|
2899
|
+
* adminRole: 'admin',
|
|
2900
|
+
* })
|
|
2901
|
+
* ```
|
|
2902
|
+
*
|
|
2903
|
+
* @param client - Client.
|
|
2904
|
+
* @param parameters - Parameters.
|
|
2905
|
+
* @returns The transaction receipt and event data.
|
|
2906
|
+
*/
|
|
2907
|
+
export async function setRoleAdminSync<
|
|
2908
|
+
chain extends Chain | undefined,
|
|
2909
|
+
account extends Account | undefined,
|
|
2910
|
+
>(
|
|
2911
|
+
client: Client<Transport, chain, account>,
|
|
2912
|
+
parameters: setRoleAdminSync.Parameters<chain, account>,
|
|
2913
|
+
): Promise<setRoleAdminSync.ReturnValue> {
|
|
2914
|
+
const receipt = await setRoleAdmin.inner(
|
|
2915
|
+
writeContractSync,
|
|
2916
|
+
client,
|
|
2917
|
+
parameters,
|
|
2918
|
+
)
|
|
2919
|
+
const { args } = setRoleAdmin.extractEvent(receipt.logs)
|
|
2920
|
+
return {
|
|
2921
|
+
...args,
|
|
2922
|
+
receipt,
|
|
2923
|
+
} as never
|
|
2924
|
+
}
|
|
2925
|
+
|
|
2926
|
+
export namespace setRoleAdminSync {
|
|
2927
|
+
export type Parameters<
|
|
2928
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
2929
|
+
account extends Account | undefined = Account | undefined,
|
|
2930
|
+
> = setRoleAdmin.Parameters<chain, account>
|
|
2931
|
+
|
|
2932
|
+
export type Args = setRoleAdmin.Args
|
|
2933
|
+
|
|
2934
|
+
export type ReturnValue = GetEventArgs<
|
|
2935
|
+
typeof tip20Abi,
|
|
2936
|
+
'RoleAdminUpdated',
|
|
2937
|
+
{ IndexedOnly: false; Required: true }
|
|
2938
|
+
> & {
|
|
2939
|
+
receipt: TransactionReceipt
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2942
|
+
|
|
2943
|
+
/**
|
|
2944
|
+
* Transfers TIP20 tokens to another address.
|
|
2945
|
+
*
|
|
2946
|
+
* @example
|
|
2947
|
+
* ```ts
|
|
2948
|
+
* import { createClient, http } from 'viem'
|
|
2949
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
2950
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
2951
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2952
|
+
*
|
|
2953
|
+
* const client = createClient({
|
|
2954
|
+
* account: privateKeyToAccount('0x...'),
|
|
2955
|
+
* chain: tempo,
|
|
2956
|
+
* transport: http(),
|
|
2957
|
+
* })
|
|
2958
|
+
*
|
|
2959
|
+
* const result = await actions.token.transfer(client, {
|
|
2960
|
+
* to: '0x...',
|
|
2961
|
+
* amount: 100n,
|
|
2962
|
+
* })
|
|
2963
|
+
* ```
|
|
2964
|
+
*
|
|
2965
|
+
* @param client - Client.
|
|
2966
|
+
* @param parameters - Parameters.
|
|
2967
|
+
* @returns The transaction hash.
|
|
2968
|
+
*/
|
|
2969
|
+
export async function transfer<
|
|
2970
|
+
chain extends Chain | undefined,
|
|
2971
|
+
account extends Account | undefined,
|
|
2972
|
+
>(
|
|
2973
|
+
client: Client<Transport, chain, account>,
|
|
2974
|
+
parameters: transfer.Parameters<chain, account>,
|
|
2975
|
+
): Promise<transfer.ReturnValue> {
|
|
2976
|
+
return transfer.inner(writeContract, client, parameters)
|
|
2977
|
+
}
|
|
2978
|
+
|
|
2979
|
+
export namespace transfer {
|
|
2980
|
+
export type Parameters<
|
|
2981
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
2982
|
+
account extends Account | undefined = Account | undefined,
|
|
2983
|
+
> = WriteParameters<chain, account> & Args
|
|
2984
|
+
|
|
2985
|
+
export type Args = {
|
|
2986
|
+
/** Amount of tokens to transfer. */
|
|
2987
|
+
amount: bigint
|
|
2988
|
+
/** Address to transfer tokens from. */
|
|
2989
|
+
from?: Address | undefined
|
|
2990
|
+
/** Memo to include in the transfer. */
|
|
2991
|
+
memo?: Hex.Hex | undefined
|
|
2992
|
+
/** Address or ID of the TIP20 token. @default `usdAddress` */
|
|
2993
|
+
token?: TokenId.TokenIdOrAddress | undefined
|
|
2994
|
+
/** Address to transfer tokens to. */
|
|
2995
|
+
to: Address
|
|
2996
|
+
}
|
|
2997
|
+
|
|
2998
|
+
export type ReturnValue = WriteContractReturnType
|
|
2999
|
+
|
|
3000
|
+
/** @internal */
|
|
3001
|
+
export async function inner<
|
|
3002
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
3003
|
+
chain extends Chain | undefined,
|
|
3004
|
+
account extends Account | undefined,
|
|
3005
|
+
>(
|
|
3006
|
+
action: action,
|
|
3007
|
+
client: Client<Transport, chain, account>,
|
|
3008
|
+
parameters: transfer.Parameters<chain, account>,
|
|
3009
|
+
): Promise<ReturnType<action>> {
|
|
3010
|
+
const call = transfer.call(parameters)
|
|
3011
|
+
return (await action(client, {
|
|
3012
|
+
...parameters,
|
|
3013
|
+
...call,
|
|
3014
|
+
} as never)) as never
|
|
3015
|
+
}
|
|
3016
|
+
|
|
3017
|
+
/**
|
|
3018
|
+
* Defines a call to the `transfer`, `transferFrom`, `transferWithMemo`, or `transferFromWithMemo` function.
|
|
3019
|
+
*
|
|
3020
|
+
* Can be passed as a parameter to:
|
|
3021
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
3022
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
3023
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
3024
|
+
*
|
|
3025
|
+
* @example
|
|
3026
|
+
* ```ts
|
|
3027
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
3028
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
3029
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
3030
|
+
*
|
|
3031
|
+
* const client = createClient({
|
|
3032
|
+
* chain: tempo,
|
|
3033
|
+
* transport: http(),
|
|
3034
|
+
* }).extend(walletActions)
|
|
3035
|
+
*
|
|
3036
|
+
* const { result } = await client.sendCalls({
|
|
3037
|
+
* calls: [
|
|
3038
|
+
* actions.token.transfer.call({
|
|
3039
|
+
* to: '0x20c0...beef',
|
|
3040
|
+
* amount: 100n,
|
|
3041
|
+
* token: '0x20c0...babe',
|
|
3042
|
+
* }),
|
|
3043
|
+
* ]
|
|
3044
|
+
* })
|
|
3045
|
+
* ```
|
|
3046
|
+
*
|
|
3047
|
+
* @param args - Arguments.
|
|
3048
|
+
* @returns The call.
|
|
3049
|
+
*/
|
|
3050
|
+
export function call(args: Args) {
|
|
3051
|
+
const { amount, from, memo, token = usdAddress, to } = args
|
|
3052
|
+
const callArgs = (() => {
|
|
3053
|
+
if (memo && from)
|
|
3054
|
+
return {
|
|
3055
|
+
functionName: 'transferFromWithMemo',
|
|
3056
|
+
args: [from, to, amount, Hex.padLeft(memo, 32)],
|
|
3057
|
+
} as const
|
|
3058
|
+
if (memo)
|
|
3059
|
+
return {
|
|
3060
|
+
functionName: 'transferWithMemo',
|
|
3061
|
+
args: [to, amount, Hex.padLeft(memo, 32)],
|
|
3062
|
+
} as const
|
|
3063
|
+
if (from)
|
|
3064
|
+
return {
|
|
3065
|
+
functionName: 'transferFrom',
|
|
3066
|
+
args: [from, to, amount],
|
|
3067
|
+
} as const
|
|
3068
|
+
return {
|
|
3069
|
+
functionName: 'transfer',
|
|
3070
|
+
args: [to, amount],
|
|
3071
|
+
} as const
|
|
3072
|
+
})()
|
|
3073
|
+
return defineCall({
|
|
3074
|
+
address: TokenId.toAddress(token),
|
|
3075
|
+
abi: tip20Abi,
|
|
3076
|
+
...callArgs,
|
|
3077
|
+
})
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
/**
|
|
3081
|
+
* Extracts the event from the logs.
|
|
3082
|
+
*
|
|
3083
|
+
* @param logs - Logs.
|
|
3084
|
+
* @returns The event.
|
|
3085
|
+
*/
|
|
3086
|
+
export function extractEvent(logs: Log[]) {
|
|
3087
|
+
const [log] = parseEventLogs({
|
|
3088
|
+
abi: tip20Abi,
|
|
3089
|
+
logs,
|
|
3090
|
+
eventName: 'Transfer',
|
|
3091
|
+
})
|
|
3092
|
+
if (!log) throw new Error('`Transfer` event not found.')
|
|
3093
|
+
return log
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
|
|
3097
|
+
/**
|
|
3098
|
+
* Transfers TIP20 tokens to another address.
|
|
3099
|
+
*
|
|
3100
|
+
* @example
|
|
3101
|
+
* ```ts
|
|
3102
|
+
* import { createClient, http } from 'viem'
|
|
3103
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
3104
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
3105
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
3106
|
+
*
|
|
3107
|
+
* const client = createClient({
|
|
3108
|
+
* account: privateKeyToAccount('0x...'),
|
|
3109
|
+
* chain: tempo,
|
|
3110
|
+
* transport: http(),
|
|
3111
|
+
* })
|
|
3112
|
+
*
|
|
3113
|
+
* const result = await actions.token.transferSync(client, {
|
|
3114
|
+
* to: '0x...',
|
|
3115
|
+
* amount: 100n,
|
|
3116
|
+
* })
|
|
3117
|
+
* ```
|
|
3118
|
+
*
|
|
3119
|
+
* @param client - Client.
|
|
3120
|
+
* @param parameters - Parameters.
|
|
3121
|
+
* @returns The transaction receipt and event data.
|
|
3122
|
+
*/
|
|
3123
|
+
export async function transferSync<
|
|
3124
|
+
chain extends Chain | undefined,
|
|
3125
|
+
account extends Account | undefined,
|
|
3126
|
+
>(
|
|
3127
|
+
client: Client<Transport, chain, account>,
|
|
3128
|
+
parameters: transferSync.Parameters<chain, account>,
|
|
3129
|
+
): Promise<transferSync.ReturnValue> {
|
|
3130
|
+
const receipt = await transfer.inner(writeContractSync, client, parameters)
|
|
3131
|
+
const { args } = transfer.extractEvent(receipt.logs)
|
|
3132
|
+
return {
|
|
3133
|
+
...args,
|
|
3134
|
+
receipt,
|
|
3135
|
+
} as never
|
|
3136
|
+
}
|
|
3137
|
+
|
|
3138
|
+
export namespace transferSync {
|
|
3139
|
+
export type Parameters<
|
|
3140
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
3141
|
+
account extends Account | undefined = Account | undefined,
|
|
3142
|
+
> = transfer.Parameters<chain, account>
|
|
3143
|
+
|
|
3144
|
+
export type Args = transfer.Args
|
|
3145
|
+
|
|
3146
|
+
export type ReturnValue = GetEventArgs<
|
|
3147
|
+
typeof tip20Abi,
|
|
3148
|
+
'Transfer',
|
|
3149
|
+
{ IndexedOnly: false; Required: true }
|
|
3150
|
+
> & {
|
|
3151
|
+
receipt: TransactionReceipt
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
/**
|
|
3156
|
+
* Unpauses a TIP20 token.
|
|
3157
|
+
*
|
|
3158
|
+
* @example
|
|
3159
|
+
* ```ts
|
|
3160
|
+
* import { createClient, http } from 'viem'
|
|
3161
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
3162
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
3163
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
3164
|
+
*
|
|
3165
|
+
* const client = createClient({
|
|
3166
|
+
* account: privateKeyToAccount('0x...'),
|
|
3167
|
+
* chain: tempo,
|
|
3168
|
+
* transport: http(),
|
|
3169
|
+
* })
|
|
3170
|
+
*
|
|
3171
|
+
* const result = await actions.token.unpause(client, {
|
|
3172
|
+
* token: '0x...',
|
|
3173
|
+
* })
|
|
3174
|
+
* ```
|
|
3175
|
+
*
|
|
3176
|
+
* @param client - Client.
|
|
3177
|
+
* @param parameters - Parameters.
|
|
3178
|
+
* @returns The transaction hash.
|
|
3179
|
+
*/
|
|
3180
|
+
export async function unpause<
|
|
3181
|
+
chain extends Chain | undefined,
|
|
3182
|
+
account extends Account | undefined,
|
|
3183
|
+
>(
|
|
3184
|
+
client: Client<Transport, chain, account>,
|
|
3185
|
+
parameters: unpause.Parameters<chain, account>,
|
|
3186
|
+
): Promise<unpause.ReturnValue> {
|
|
3187
|
+
return unpause.inner(writeContract, client, parameters)
|
|
3188
|
+
}
|
|
3189
|
+
|
|
3190
|
+
export namespace unpause {
|
|
3191
|
+
export type Parameters<
|
|
3192
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
3193
|
+
account extends Account | undefined = Account | undefined,
|
|
3194
|
+
> = WriteParameters<chain, account> & Args
|
|
3195
|
+
|
|
3196
|
+
export type Args = {
|
|
3197
|
+
/** Address or ID of the TIP20 token. */
|
|
3198
|
+
token: TokenId.TokenIdOrAddress
|
|
3199
|
+
}
|
|
3200
|
+
|
|
3201
|
+
export type ReturnValue = WriteContractReturnType
|
|
3202
|
+
|
|
3203
|
+
/** @internal */
|
|
3204
|
+
export async function inner<
|
|
3205
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
3206
|
+
chain extends Chain | undefined,
|
|
3207
|
+
account extends Account | undefined,
|
|
3208
|
+
>(
|
|
3209
|
+
action: action,
|
|
3210
|
+
client: Client<Transport, chain, account>,
|
|
3211
|
+
parameters: unpause.Parameters<chain, account>,
|
|
3212
|
+
): Promise<ReturnType<action>> {
|
|
3213
|
+
const call = unpause.call(parameters)
|
|
3214
|
+
return (await action(client, {
|
|
3215
|
+
...parameters,
|
|
3216
|
+
...call,
|
|
3217
|
+
} as never)) as never
|
|
3218
|
+
}
|
|
3219
|
+
|
|
3220
|
+
/**
|
|
3221
|
+
* Defines a call to the `unpause` function.
|
|
3222
|
+
*
|
|
3223
|
+
* Can be passed as a parameter to:
|
|
3224
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
3225
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
3226
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
3227
|
+
*
|
|
3228
|
+
* @example
|
|
3229
|
+
* ```ts
|
|
3230
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
3231
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
3232
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
3233
|
+
*
|
|
3234
|
+
* const client = createClient({
|
|
3235
|
+
* chain: tempo,
|
|
3236
|
+
* transport: http(),
|
|
3237
|
+
* }).extend(walletActions)
|
|
3238
|
+
*
|
|
3239
|
+
* const { result } = await client.sendCalls({
|
|
3240
|
+
* calls: [
|
|
3241
|
+
* actions.token.unpause.call({
|
|
3242
|
+
* token: '0x20c0...babe',
|
|
3243
|
+
* }),
|
|
3244
|
+
* ]
|
|
3245
|
+
* })
|
|
3246
|
+
* ```
|
|
3247
|
+
*
|
|
3248
|
+
* @param args - Arguments.
|
|
3249
|
+
* @returns The call.
|
|
3250
|
+
*/
|
|
3251
|
+
export function call(args: Args) {
|
|
3252
|
+
const { token } = args
|
|
3253
|
+
return defineCall({
|
|
3254
|
+
address: TokenId.toAddress(token),
|
|
3255
|
+
abi: tip20Abi,
|
|
3256
|
+
functionName: 'unpause',
|
|
3257
|
+
args: [],
|
|
3258
|
+
})
|
|
3259
|
+
}
|
|
3260
|
+
|
|
3261
|
+
/**
|
|
3262
|
+
* Extracts the event from the logs.
|
|
3263
|
+
*
|
|
3264
|
+
* @param logs - Logs.
|
|
3265
|
+
* @returns The event.
|
|
3266
|
+
*/
|
|
3267
|
+
export function extractEvent(logs: Log[]) {
|
|
3268
|
+
const [log] = parseEventLogs({
|
|
3269
|
+
abi: tip20Abi,
|
|
3270
|
+
logs,
|
|
3271
|
+
eventName: 'PauseStateUpdate',
|
|
3272
|
+
})
|
|
3273
|
+
if (!log) throw new Error('`PauseStateUpdate` event not found.')
|
|
3274
|
+
return log
|
|
3275
|
+
}
|
|
3276
|
+
}
|
|
3277
|
+
|
|
3278
|
+
/**
|
|
3279
|
+
* Unpauses a TIP20 token.
|
|
3280
|
+
*
|
|
3281
|
+
* @example
|
|
3282
|
+
* ```ts
|
|
3283
|
+
* import { createClient, http } from 'viem'
|
|
3284
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
3285
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
3286
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
3287
|
+
*
|
|
3288
|
+
* const client = createClient({
|
|
3289
|
+
* account: privateKeyToAccount('0x...'),
|
|
3290
|
+
* chain: tempo,
|
|
3291
|
+
* transport: http(),
|
|
3292
|
+
* })
|
|
3293
|
+
*
|
|
3294
|
+
* const result = await actions.token.unpauseSync(client, {
|
|
3295
|
+
* token: '0x...',
|
|
3296
|
+
* })
|
|
3297
|
+
* ```
|
|
3298
|
+
*
|
|
3299
|
+
* @param client - Client.
|
|
3300
|
+
* @param parameters - Parameters.
|
|
3301
|
+
* @returns The transaction receipt and event data.
|
|
3302
|
+
*/
|
|
3303
|
+
export async function unpauseSync<
|
|
3304
|
+
chain extends Chain | undefined,
|
|
3305
|
+
account extends Account | undefined,
|
|
3306
|
+
>(
|
|
3307
|
+
client: Client<Transport, chain, account>,
|
|
3308
|
+
parameters: unpauseSync.Parameters<chain, account>,
|
|
3309
|
+
): Promise<unpauseSync.ReturnValue> {
|
|
3310
|
+
const receipt = await unpause.inner(writeContractSync, client, parameters)
|
|
3311
|
+
const { args } = unpause.extractEvent(receipt.logs)
|
|
3312
|
+
return {
|
|
3313
|
+
...args,
|
|
3314
|
+
receipt,
|
|
3315
|
+
} as never
|
|
3316
|
+
}
|
|
3317
|
+
|
|
3318
|
+
export namespace unpauseSync {
|
|
3319
|
+
export type Parameters<
|
|
3320
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
3321
|
+
account extends Account | undefined = Account | undefined,
|
|
3322
|
+
> = unpause.Parameters<chain, account>
|
|
3323
|
+
|
|
3324
|
+
export type Args = unpause.Args
|
|
3325
|
+
|
|
3326
|
+
export type ReturnValue = GetEventArgs<
|
|
3327
|
+
typeof tip20Abi,
|
|
3328
|
+
'PauseStateUpdate',
|
|
3329
|
+
{ IndexedOnly: false; Required: true }
|
|
3330
|
+
> & {
|
|
3331
|
+
receipt: TransactionReceipt
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
|
|
3335
|
+
/**
|
|
3336
|
+
* Watches for TIP20 token approval events.
|
|
3337
|
+
*
|
|
3338
|
+
* @example
|
|
3339
|
+
* ```ts
|
|
3340
|
+
* import { createClient, http } from 'viem'
|
|
3341
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
3342
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
3343
|
+
*
|
|
3344
|
+
* const client = createClient({
|
|
3345
|
+
* chain: tempo,
|
|
3346
|
+
* transport: http(),
|
|
3347
|
+
* })
|
|
3348
|
+
*
|
|
3349
|
+
* const unwatch = actions.token.watchApprove(client, {
|
|
3350
|
+
* onApproval: (args, log) => {
|
|
3351
|
+
* console.log('Approval:', args)
|
|
3352
|
+
* },
|
|
3353
|
+
* })
|
|
3354
|
+
* ```
|
|
3355
|
+
*
|
|
3356
|
+
* @param client - Client.
|
|
3357
|
+
* @param parameters - Parameters.
|
|
3358
|
+
* @returns A function to unsubscribe from the event.
|
|
3359
|
+
*/
|
|
3360
|
+
export function watchApprove<
|
|
3361
|
+
chain extends Chain | undefined,
|
|
3362
|
+
account extends Account | undefined,
|
|
3363
|
+
>(
|
|
3364
|
+
client: Client<Transport, chain, account>,
|
|
3365
|
+
parameters: watchApprove.Parameters,
|
|
3366
|
+
) {
|
|
3367
|
+
const { onApproval, token = usdAddress, ...rest } = parameters
|
|
3368
|
+
return watchContractEvent(client, {
|
|
3369
|
+
...rest,
|
|
3370
|
+
address: TokenId.toAddress(token),
|
|
3371
|
+
abi: tip20Abi,
|
|
3372
|
+
eventName: 'Approval',
|
|
3373
|
+
onLogs: (logs) => {
|
|
3374
|
+
for (const log of logs) onApproval(log.args, log)
|
|
3375
|
+
},
|
|
3376
|
+
strict: true,
|
|
3377
|
+
})
|
|
3378
|
+
}
|
|
3379
|
+
|
|
3380
|
+
export declare namespace watchApprove {
|
|
3381
|
+
export type Args = GetEventArgs<
|
|
3382
|
+
typeof tip20Abi,
|
|
3383
|
+
'Approval',
|
|
3384
|
+
{ IndexedOnly: false; Required: true }
|
|
3385
|
+
>
|
|
3386
|
+
|
|
3387
|
+
export type Log = viem_Log<
|
|
3388
|
+
bigint,
|
|
3389
|
+
number,
|
|
3390
|
+
false,
|
|
3391
|
+
ExtractAbiItem<typeof tip20Abi, 'Approval'>,
|
|
3392
|
+
true
|
|
3393
|
+
>
|
|
3394
|
+
|
|
3395
|
+
export type Parameters = UnionOmit<
|
|
3396
|
+
WatchContractEventParameters<typeof tip20Abi, 'Approval', true>,
|
|
3397
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
3398
|
+
> & {
|
|
3399
|
+
/** Callback to invoke when tokens are approved. */
|
|
3400
|
+
onApproval: (args: Args, log: Log) => void
|
|
3401
|
+
/** Address or ID of the TIP20 token. @default `usdAddress` */
|
|
3402
|
+
token?: TokenId.TokenIdOrAddress | undefined
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
|
|
3406
|
+
/**
|
|
3407
|
+
* Watches for TIP20 token burn events.
|
|
3408
|
+
*
|
|
3409
|
+
* @example
|
|
3410
|
+
* ```ts
|
|
3411
|
+
* import { createClient, http } from 'viem'
|
|
3412
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
3413
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
3414
|
+
*
|
|
3415
|
+
* const client = createClient({
|
|
3416
|
+
* chain: tempo,
|
|
3417
|
+
* transport: http(),
|
|
3418
|
+
* })
|
|
3419
|
+
*
|
|
3420
|
+
* const unwatch = actions.token.watchBurn(client, {
|
|
3421
|
+
* onBurn: (args, log) => {
|
|
3422
|
+
* console.log('Burn:', args)
|
|
3423
|
+
* },
|
|
3424
|
+
* })
|
|
3425
|
+
* ```
|
|
3426
|
+
*
|
|
3427
|
+
* @param client - Client.
|
|
3428
|
+
* @param parameters - Parameters.
|
|
3429
|
+
* @returns A function to unsubscribe from the event.
|
|
3430
|
+
*/
|
|
3431
|
+
export function watchBurn<
|
|
3432
|
+
chain extends Chain | undefined,
|
|
3433
|
+
account extends Account | undefined,
|
|
3434
|
+
>(client: Client<Transport, chain, account>, parameters: watchBurn.Parameters) {
|
|
3435
|
+
const { onBurn, token = usdAddress, ...rest } = parameters
|
|
3436
|
+
return watchContractEvent(client, {
|
|
3437
|
+
...rest,
|
|
3438
|
+
address: TokenId.toAddress(token),
|
|
3439
|
+
abi: tip20Abi,
|
|
3440
|
+
eventName: 'Burn',
|
|
3441
|
+
onLogs: (logs) => {
|
|
3442
|
+
for (const log of logs) onBurn(log.args, log)
|
|
3443
|
+
},
|
|
3444
|
+
strict: true,
|
|
3445
|
+
})
|
|
3446
|
+
}
|
|
3447
|
+
|
|
3448
|
+
export declare namespace watchBurn {
|
|
3449
|
+
export type Args = GetEventArgs<
|
|
3450
|
+
typeof tip20Abi,
|
|
3451
|
+
'Burn',
|
|
3452
|
+
{ IndexedOnly: false; Required: true }
|
|
3453
|
+
>
|
|
3454
|
+
|
|
3455
|
+
export type Log = viem_Log<
|
|
3456
|
+
bigint,
|
|
3457
|
+
number,
|
|
3458
|
+
false,
|
|
3459
|
+
ExtractAbiItem<typeof tip20Abi, 'Burn'>,
|
|
3460
|
+
true
|
|
3461
|
+
>
|
|
3462
|
+
|
|
3463
|
+
export type Parameters = UnionOmit<
|
|
3464
|
+
WatchContractEventParameters<typeof tip20Abi, 'Burn', true>,
|
|
3465
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
3466
|
+
> & {
|
|
3467
|
+
/** Callback to invoke when tokens are burned. */
|
|
3468
|
+
onBurn: (args: Args, log: Log) => void
|
|
3469
|
+
/** Address or ID of the TIP20 token. @default `usdAddress` */
|
|
3470
|
+
token?: TokenId.TokenIdOrAddress | undefined
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
/**
|
|
3475
|
+
* Watches for new TIP20 tokens created.
|
|
3476
|
+
*
|
|
3477
|
+
* @example
|
|
3478
|
+
* ```ts
|
|
3479
|
+
* import { createClient, http } from 'viem'
|
|
3480
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
3481
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
3482
|
+
*
|
|
3483
|
+
* const client = createClient({
|
|
3484
|
+
* chain: tempo,
|
|
3485
|
+
* transport: http(),
|
|
3486
|
+
* })
|
|
3487
|
+
*
|
|
3488
|
+
* const unwatch = actions.token.watchCreate(client, {
|
|
3489
|
+
* onTokenCreated: (args, log) => {
|
|
3490
|
+
* console.log('Token created:', args)
|
|
3491
|
+
* },
|
|
3492
|
+
* })
|
|
3493
|
+
* ```
|
|
3494
|
+
*
|
|
3495
|
+
* @param client - Client.
|
|
3496
|
+
* @param parameters - Parameters.
|
|
3497
|
+
* @returns A function to unsubscribe from the event.
|
|
3498
|
+
*/
|
|
3499
|
+
export function watchCreate<
|
|
3500
|
+
chain extends Chain | undefined,
|
|
3501
|
+
account extends Account | undefined,
|
|
3502
|
+
>(
|
|
3503
|
+
client: Client<Transport, chain, account>,
|
|
3504
|
+
parameters: watchCreate.Parameters,
|
|
3505
|
+
) {
|
|
3506
|
+
const { onTokenCreated, ...rest } = parameters
|
|
3507
|
+
return watchContractEvent(client, {
|
|
3508
|
+
...rest,
|
|
3509
|
+
address: tip20FactoryAddress,
|
|
3510
|
+
abi: tip20FactoryAbi,
|
|
3511
|
+
eventName: 'TokenCreated',
|
|
3512
|
+
onLogs: (logs) => {
|
|
3513
|
+
for (const log of logs) onTokenCreated(log.args, log)
|
|
3514
|
+
},
|
|
3515
|
+
strict: true,
|
|
3516
|
+
})
|
|
3517
|
+
}
|
|
3518
|
+
|
|
3519
|
+
export declare namespace watchCreate {
|
|
3520
|
+
export type Args = GetEventArgs<
|
|
3521
|
+
typeof tip20FactoryAbi,
|
|
3522
|
+
'TokenCreated',
|
|
3523
|
+
{ IndexedOnly: false; Required: true }
|
|
3524
|
+
>
|
|
3525
|
+
|
|
3526
|
+
export type Log = viem_Log<
|
|
3527
|
+
bigint,
|
|
3528
|
+
number,
|
|
3529
|
+
false,
|
|
3530
|
+
ExtractAbiItem<typeof tip20FactoryAbi, 'TokenCreated'>,
|
|
3531
|
+
true
|
|
3532
|
+
>
|
|
3533
|
+
|
|
3534
|
+
export type Parameters = UnionOmit<
|
|
3535
|
+
WatchContractEventParameters<typeof tip20FactoryAbi, 'TokenCreated', true>,
|
|
3536
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
3537
|
+
> & {
|
|
3538
|
+
/** Callback to invoke when a new TIP20 token is created. */
|
|
3539
|
+
onTokenCreated: (args: Args, log: Log) => void
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3543
|
+
/**
|
|
3544
|
+
* Watches for TIP20 token mint events.
|
|
3545
|
+
*
|
|
3546
|
+
* @example
|
|
3547
|
+
* ```ts
|
|
3548
|
+
* import { createClient, http } from 'viem'
|
|
3549
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
3550
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
3551
|
+
*
|
|
3552
|
+
* const client = createClient({
|
|
3553
|
+
* chain: tempo,
|
|
3554
|
+
* transport: http(),
|
|
3555
|
+
* })
|
|
3556
|
+
*
|
|
3557
|
+
* const unwatch = actions.token.watchMint(client, {
|
|
3558
|
+
* onMint: (args, log) => {
|
|
3559
|
+
* console.log('Mint:', args)
|
|
3560
|
+
* },
|
|
3561
|
+
* })
|
|
3562
|
+
* ```
|
|
3563
|
+
*
|
|
3564
|
+
* @param client - Client.
|
|
3565
|
+
* @param parameters - Parameters.
|
|
3566
|
+
* @returns A function to unsubscribe from the event.
|
|
3567
|
+
*/
|
|
3568
|
+
export function watchMint<
|
|
3569
|
+
chain extends Chain | undefined,
|
|
3570
|
+
account extends Account | undefined,
|
|
3571
|
+
>(client: Client<Transport, chain, account>, parameters: watchMint.Parameters) {
|
|
3572
|
+
const { onMint, token = usdAddress, ...rest } = parameters
|
|
3573
|
+
return watchContractEvent(client, {
|
|
3574
|
+
...rest,
|
|
3575
|
+
address: TokenId.toAddress(token),
|
|
3576
|
+
abi: tip20Abi,
|
|
3577
|
+
eventName: 'Mint',
|
|
3578
|
+
onLogs: (logs) => {
|
|
3579
|
+
for (const log of logs) onMint(log.args, log)
|
|
3580
|
+
},
|
|
3581
|
+
strict: true,
|
|
3582
|
+
})
|
|
3583
|
+
}
|
|
3584
|
+
|
|
3585
|
+
export declare namespace watchMint {
|
|
3586
|
+
export type Args = GetEventArgs<
|
|
3587
|
+
typeof tip20Abi,
|
|
3588
|
+
'Mint',
|
|
3589
|
+
{ IndexedOnly: false; Required: true }
|
|
3590
|
+
>
|
|
3591
|
+
|
|
3592
|
+
export type Log = viem_Log<
|
|
3593
|
+
bigint,
|
|
3594
|
+
number,
|
|
3595
|
+
false,
|
|
3596
|
+
ExtractAbiItem<typeof tip20Abi, 'Mint'>,
|
|
3597
|
+
true
|
|
3598
|
+
>
|
|
3599
|
+
|
|
3600
|
+
export type Parameters = UnionOmit<
|
|
3601
|
+
WatchContractEventParameters<typeof tip20Abi, 'Mint', true>,
|
|
3602
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
3603
|
+
> & {
|
|
3604
|
+
/** Callback to invoke when tokens are minted. */
|
|
3605
|
+
onMint: (args: Args, log: Log) => void
|
|
3606
|
+
/** Address or ID of the TIP20 token. @default `usdAddress` */
|
|
3607
|
+
token?: TokenId.TokenIdOrAddress | undefined
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
|
|
3611
|
+
/**
|
|
3612
|
+
* Watches for TIP20 token role admin updates.
|
|
3613
|
+
*
|
|
3614
|
+
* @example
|
|
3615
|
+
* ```ts
|
|
3616
|
+
* import { createClient, http } from 'viem'
|
|
3617
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
3618
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
3619
|
+
*
|
|
3620
|
+
* const client = createClient({
|
|
3621
|
+
* chain: tempo,
|
|
3622
|
+
* transport: http(),
|
|
3623
|
+
* })
|
|
3624
|
+
*
|
|
3625
|
+
* const unwatch = actions.token.watchAdminRole(client, {
|
|
3626
|
+
* onRoleAdminUpdated: (args, log) => {
|
|
3627
|
+
* console.log('Role admin updated:', args)
|
|
3628
|
+
* },
|
|
3629
|
+
* })
|
|
3630
|
+
* ```
|
|
3631
|
+
*
|
|
3632
|
+
* @param client - Client.
|
|
3633
|
+
* @param parameters - Parameters.
|
|
3634
|
+
* @returns A function to unsubscribe from the event.
|
|
3635
|
+
*/
|
|
3636
|
+
export function watchAdminRole<
|
|
3637
|
+
chain extends Chain | undefined,
|
|
3638
|
+
account extends Account | undefined,
|
|
3639
|
+
>(
|
|
3640
|
+
client: Client<Transport, chain, account>,
|
|
3641
|
+
parameters: watchAdminRole.Parameters,
|
|
3642
|
+
) {
|
|
3643
|
+
const { onRoleAdminUpdated, token = usdAddress, ...rest } = parameters
|
|
3644
|
+
return watchContractEvent(client, {
|
|
3645
|
+
...rest,
|
|
3646
|
+
address: TokenId.toAddress(token),
|
|
3647
|
+
abi: tip20Abi,
|
|
3648
|
+
eventName: 'RoleAdminUpdated',
|
|
3649
|
+
onLogs: (logs) => {
|
|
3650
|
+
for (const log of logs) onRoleAdminUpdated(log.args, log)
|
|
3651
|
+
},
|
|
3652
|
+
strict: true,
|
|
3653
|
+
})
|
|
3654
|
+
}
|
|
3655
|
+
|
|
3656
|
+
export declare namespace watchAdminRole {
|
|
3657
|
+
export type Args = GetEventArgs<
|
|
3658
|
+
typeof tip20Abi,
|
|
3659
|
+
'RoleAdminUpdated',
|
|
3660
|
+
{ IndexedOnly: false; Required: true }
|
|
3661
|
+
>
|
|
3662
|
+
|
|
3663
|
+
export type Log = viem_Log<
|
|
3664
|
+
bigint,
|
|
3665
|
+
number,
|
|
3666
|
+
false,
|
|
3667
|
+
ExtractAbiItem<typeof tip20Abi, 'RoleAdminUpdated'>,
|
|
3668
|
+
true
|
|
3669
|
+
>
|
|
3670
|
+
|
|
3671
|
+
export type Parameters = UnionOmit<
|
|
3672
|
+
WatchContractEventParameters<typeof tip20Abi, 'RoleAdminUpdated', true>,
|
|
3673
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
3674
|
+
> & {
|
|
3675
|
+
/** Callback to invoke when a role admin is updated. */
|
|
3676
|
+
onRoleAdminUpdated: (args: Args, log: Log) => void
|
|
3677
|
+
/** Address or ID of the TIP20 token. @default `usdAddress` */
|
|
3678
|
+
token?: TokenId.TokenIdOrAddress | undefined
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
|
|
3682
|
+
/**
|
|
3683
|
+
* Watches for TIP20 token role membership updates.
|
|
3684
|
+
*
|
|
3685
|
+
* @example
|
|
3686
|
+
* ```ts
|
|
3687
|
+
* import { createClient, http } from 'viem'
|
|
3688
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
3689
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
3690
|
+
*
|
|
3691
|
+
* const client = createClient({
|
|
3692
|
+
* chain: tempo,
|
|
3693
|
+
* transport: http(),
|
|
3694
|
+
* })
|
|
3695
|
+
*
|
|
3696
|
+
* const unwatch = actions.token.watchRole(client, {
|
|
3697
|
+
* onRoleUpdated: (args, log) => {
|
|
3698
|
+
* console.log('Role updated:', args)
|
|
3699
|
+
* },
|
|
3700
|
+
* })
|
|
3701
|
+
* ```
|
|
3702
|
+
*
|
|
3703
|
+
* @param client - Client.
|
|
3704
|
+
* @param parameters - Parameters.
|
|
3705
|
+
* @returns A function to unsubscribe from the event.
|
|
3706
|
+
*/
|
|
3707
|
+
export function watchRole<
|
|
3708
|
+
chain extends Chain | undefined,
|
|
3709
|
+
account extends Account | undefined,
|
|
3710
|
+
>(client: Client<Transport, chain, account>, parameters: watchRole.Parameters) {
|
|
3711
|
+
const { onRoleUpdated, token = usdAddress, ...rest } = parameters
|
|
3712
|
+
return watchContractEvent(client, {
|
|
3713
|
+
...rest,
|
|
3714
|
+
address: TokenId.toAddress(token),
|
|
3715
|
+
abi: tip20Abi,
|
|
3716
|
+
eventName: 'RoleMembershipUpdated',
|
|
3717
|
+
onLogs: (logs) => {
|
|
3718
|
+
for (const log of logs) {
|
|
3719
|
+
const type = log.args.hasRole ? 'granted' : 'revoked'
|
|
3720
|
+
onRoleUpdated({ ...log.args, type }, log)
|
|
3721
|
+
}
|
|
3722
|
+
},
|
|
3723
|
+
strict: true,
|
|
3724
|
+
})
|
|
3725
|
+
}
|
|
3726
|
+
|
|
3727
|
+
export declare namespace watchRole {
|
|
3728
|
+
export type Args = GetEventArgs<
|
|
3729
|
+
typeof tip20Abi,
|
|
3730
|
+
'RoleMembershipUpdated',
|
|
3731
|
+
{ IndexedOnly: false; Required: true }
|
|
3732
|
+
> & {
|
|
3733
|
+
/** Type of role update. */
|
|
3734
|
+
type: 'granted' | 'revoked'
|
|
3735
|
+
}
|
|
3736
|
+
|
|
3737
|
+
export type Log = viem_Log<
|
|
3738
|
+
bigint,
|
|
3739
|
+
number,
|
|
3740
|
+
false,
|
|
3741
|
+
ExtractAbiItem<typeof tip20Abi, 'RoleMembershipUpdated'>,
|
|
3742
|
+
true
|
|
3743
|
+
>
|
|
3744
|
+
|
|
3745
|
+
export type Parameters = UnionOmit<
|
|
3746
|
+
WatchContractEventParameters<
|
|
3747
|
+
typeof tip20Abi,
|
|
3748
|
+
'RoleMembershipUpdated',
|
|
3749
|
+
true
|
|
3750
|
+
>,
|
|
3751
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
3752
|
+
> & {
|
|
3753
|
+
/** Callback to invoke when a role membership is updated. */
|
|
3754
|
+
onRoleUpdated: (args: Args, log: Log) => void
|
|
3755
|
+
/** Address or ID of the TIP20 token. @default `usdAddress` */
|
|
3756
|
+
token?: TokenId.TokenIdOrAddress | undefined
|
|
3757
|
+
}
|
|
3758
|
+
}
|
|
3759
|
+
|
|
3760
|
+
/**
|
|
3761
|
+
* Watches for TIP20 token transfer events.
|
|
3762
|
+
*
|
|
3763
|
+
* @example
|
|
3764
|
+
* ```ts
|
|
3765
|
+
* import { createClient, http } from 'viem'
|
|
3766
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
3767
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
3768
|
+
*
|
|
3769
|
+
* const client = createClient({
|
|
3770
|
+
* account: privateKeyToAccount('0x...'),
|
|
3771
|
+
* chain: tempo,
|
|
3772
|
+
* transport: http(),
|
|
3773
|
+
* })
|
|
3774
|
+
*
|
|
3775
|
+
* const unwatch = actions.token.watchTransfer(client, {
|
|
3776
|
+
* onTransfer: (args, log) => {
|
|
3777
|
+
* console.log('Transfer:', args)
|
|
3778
|
+
* },
|
|
3779
|
+
* })
|
|
3780
|
+
* ```
|
|
3781
|
+
*
|
|
3782
|
+
* @param client - Client.
|
|
3783
|
+
* @param parameters - Parameters.
|
|
3784
|
+
* @returns A function to unsubscribe from the event.
|
|
3785
|
+
*/
|
|
3786
|
+
export function watchTransfer<
|
|
3787
|
+
chain extends Chain | undefined,
|
|
3788
|
+
account extends Account | undefined,
|
|
3789
|
+
>(
|
|
3790
|
+
client: Client<Transport, chain, account>,
|
|
3791
|
+
parameters: watchTransfer.Parameters,
|
|
3792
|
+
) {
|
|
3793
|
+
const { onTransfer, token = usdAddress, ...rest } = parameters
|
|
3794
|
+
return watchContractEvent(client, {
|
|
3795
|
+
...rest,
|
|
3796
|
+
address: TokenId.toAddress(token),
|
|
3797
|
+
abi: tip20Abi,
|
|
3798
|
+
eventName: 'Transfer',
|
|
3799
|
+
onLogs: (logs) => {
|
|
3800
|
+
for (const log of logs) onTransfer(log.args, log)
|
|
3801
|
+
},
|
|
3802
|
+
strict: true,
|
|
3803
|
+
})
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
export declare namespace watchTransfer {
|
|
3807
|
+
export type Args = GetEventArgs<
|
|
3808
|
+
typeof tip20Abi,
|
|
3809
|
+
'Transfer',
|
|
3810
|
+
{ IndexedOnly: false; Required: true }
|
|
3811
|
+
>
|
|
3812
|
+
|
|
3813
|
+
export type Log = viem_Log<
|
|
3814
|
+
bigint,
|
|
3815
|
+
number,
|
|
3816
|
+
false,
|
|
3817
|
+
ExtractAbiItem<typeof tip20Abi, 'Transfer'>,
|
|
3818
|
+
true
|
|
3819
|
+
>
|
|
3820
|
+
|
|
3821
|
+
export type Parameters = UnionOmit<
|
|
3822
|
+
WatchContractEventParameters<typeof tip20Abi, 'Transfer', true>,
|
|
3823
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
3824
|
+
> & {
|
|
3825
|
+
/** Callback to invoke when tokens are transferred. */
|
|
3826
|
+
onTransfer: (args: Args, log: Log) => void
|
|
3827
|
+
/** Address or ID of the TIP20 token. @default `usdAddress` */
|
|
3828
|
+
token?: TokenId.TokenIdOrAddress | undefined
|
|
3829
|
+
}
|
|
3830
|
+
}
|