tempo.ts 0.11.1 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +67 -4
- package/README.md +3 -34
- package/dist/server/Handler.d.ts +14 -14
- package/dist/server/Handler.d.ts.map +1 -1
- package/dist/server/Handler.js +16 -17
- package/dist/server/Handler.js.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +51 -51
- package/dist/wagmi/Actions/amm.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.js +37 -37
- package/dist/wagmi/Actions/amm.js.map +1 -1
- package/dist/wagmi/Actions/dex.d.ts +129 -129
- package/dist/wagmi/Actions/dex.d.ts.map +1 -1
- package/dist/wagmi/Actions/dex.js +73 -73
- package/dist/wagmi/Actions/dex.js.map +1 -1
- package/dist/wagmi/Actions/faucet.d.ts +9 -9
- package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
- package/dist/wagmi/Actions/faucet.js +7 -7
- package/dist/wagmi/Actions/faucet.js.map +1 -1
- package/dist/wagmi/Actions/fee.d.ts +17 -17
- package/dist/wagmi/Actions/fee.d.ts.map +1 -1
- package/dist/wagmi/Actions/fee.js +10 -10
- package/dist/wagmi/Actions/fee.js.map +1 -1
- package/dist/wagmi/Actions/nonce.d.ts +9 -79
- package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
- package/dist/wagmi/Actions/nonce.js +7 -89
- package/dist/wagmi/Actions/nonce.js.map +1 -1
- package/dist/wagmi/Actions/policy.d.ts +69 -70
- package/dist/wagmi/Actions/policy.d.ts.map +1 -1
- package/dist/wagmi/Actions/policy.js +43 -43
- package/dist/wagmi/Actions/policy.js.map +1 -1
- package/dist/wagmi/Actions/reward.d.ts +51 -51
- package/dist/wagmi/Actions/reward.d.ts.map +1 -1
- package/dist/wagmi/Actions/reward.js +31 -31
- package/dist/wagmi/Actions/reward.js.map +1 -1
- package/dist/wagmi/Actions/token.d.ts +238 -238
- package/dist/wagmi/Actions/token.d.ts.map +1 -1
- package/dist/wagmi/Actions/token.js +136 -136
- package/dist/wagmi/Actions/token.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +2 -1
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +83 -22
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/nonce.d.ts +1 -52
- package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
- package/dist/wagmi/Hooks/nonce.js +1 -70
- package/dist/wagmi/Hooks/nonce.js.map +1 -1
- package/dist/wagmi/Hooks/policy.d.ts +0 -1
- package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
- package/dist/wagmi/Hooks/policy.js.map +1 -1
- package/dist/wagmi/KeyManager.d.ts +6 -3
- package/dist/wagmi/KeyManager.d.ts.map +1 -1
- package/dist/wagmi/KeyManager.js +9 -4
- package/dist/wagmi/KeyManager.js.map +1 -1
- package/package.json +3 -13
- package/src/server/Handler.test.ts +2 -2
- package/src/server/Handler.ts +16 -17
- package/src/wagmi/Actions/amm.ts +63 -63
- package/src/wagmi/Actions/dex.test.ts +1 -1
- package/src/wagmi/Actions/dex.ts +153 -153
- package/src/wagmi/Actions/faucet.ts +11 -11
- package/src/wagmi/Actions/fee.ts +20 -20
- package/src/wagmi/Actions/nonce.test.ts +1 -64
- package/src/wagmi/Actions/nonce.ts +10 -142
- package/src/wagmi/Actions/policy.ts +83 -85
- package/src/wagmi/Actions/reward.ts +64 -61
- package/src/wagmi/Actions/token.ts +287 -283
- package/src/wagmi/Connector.ts +105 -31
- package/src/wagmi/Hooks/dex.test.ts +1 -1
- package/src/wagmi/Hooks/fee.test.ts +0 -6
- package/src/wagmi/Hooks/nonce.test.ts +1 -66
- package/src/wagmi/Hooks/nonce.ts +1 -114
- package/src/wagmi/Hooks/policy.ts +0 -2
- package/src/wagmi/KeyManager.ts +18 -5
- package/dist/chains.d.ts +0 -73
- package/dist/chains.d.ts.map +0 -1
- package/dist/chains.js +0 -51
- package/dist/chains.js.map +0 -1
- package/dist/viem/Abis.d.ts +0 -2649
- package/dist/viem/Abis.d.ts.map +0 -1
- package/dist/viem/Abis.js +0 -1677
- package/dist/viem/Abis.js.map +0 -1
- package/dist/viem/Account.d.ts +0 -244
- package/dist/viem/Account.d.ts.map +0 -1
- package/dist/viem/Account.js +0 -382
- package/dist/viem/Account.js.map +0 -1
- package/dist/viem/Actions/account.d.ts +0 -40
- package/dist/viem/Actions/account.d.ts.map +0 -1
- package/dist/viem/Actions/account.js +0 -86
- package/dist/viem/Actions/account.js.map +0 -1
- package/dist/viem/Actions/amm.d.ts +0 -1991
- package/dist/viem/Actions/amm.d.ts.map +0 -1
- package/dist/viem/Actions/amm.js +0 -814
- package/dist/viem/Actions/amm.js.map +0 -1
- package/dist/viem/Actions/dex.d.ts +0 -3900
- package/dist/viem/Actions/dex.d.ts.map +0 -1
- package/dist/viem/Actions/dex.js +0 -1414
- package/dist/viem/Actions/dex.js.map +0 -1
- package/dist/viem/Actions/faucet.d.ts +0 -69
- package/dist/viem/Actions/faucet.d.ts.map +0 -1
- package/dist/viem/Actions/faucet.js +0 -73
- package/dist/viem/Actions/faucet.js.map +0 -1
- package/dist/viem/Actions/fee.d.ts +0 -360
- package/dist/viem/Actions/fee.d.ts.map +0 -1
- package/dist/viem/Actions/fee.js +0 -237
- package/dist/viem/Actions/fee.js.map +0 -1
- package/dist/viem/Actions/index.d.ts +0 -10
- package/dist/viem/Actions/index.d.ts.map +0 -1
- package/dist/viem/Actions/index.js +0 -10
- package/dist/viem/Actions/index.js.map +0 -1
- package/dist/viem/Actions/nonce.d.ts +0 -257
- package/dist/viem/Actions/nonce.d.ts.map +0 -1
- package/dist/viem/Actions/nonce.js +0 -228
- package/dist/viem/Actions/nonce.js.map +0 -1
- package/dist/viem/Actions/policy.d.ts +0 -1680
- package/dist/viem/Actions/policy.d.ts.map +0 -1
- package/dist/viem/Actions/policy.js +0 -875
- package/dist/viem/Actions/policy.js.map +0 -1
- package/dist/viem/Actions/reward.d.ts +0 -2422
- package/dist/viem/Actions/reward.d.ts.map +0 -1
- package/dist/viem/Actions/reward.js +0 -651
- package/dist/viem/Actions/reward.js.map +0 -1
- package/dist/viem/Actions/token.d.ts +0 -16007
- package/dist/viem/Actions/token.d.ts.map +0 -1
- package/dist/viem/Actions/token.js +0 -2936
- package/dist/viem/Actions/token.js.map +0 -1
- package/dist/viem/Addresses.d.ts +0 -9
- package/dist/viem/Addresses.d.ts.map +0 -1
- package/dist/viem/Addresses.js +0 -9
- package/dist/viem/Addresses.js.map +0 -1
- package/dist/viem/Chain.d.ts +0 -451
- package/dist/viem/Chain.d.ts.map +0 -1
- package/dist/viem/Chain.js +0 -96
- package/dist/viem/Chain.js.map +0 -1
- package/dist/viem/Decorator.d.ts +0 -2783
- package/dist/viem/Decorator.d.ts.map +0 -1
- package/dist/viem/Decorator.js +0 -137
- package/dist/viem/Decorator.js.map +0 -1
- package/dist/viem/Formatters.d.ts +0 -10
- package/dist/viem/Formatters.d.ts.map +0 -1
- package/dist/viem/Formatters.js +0 -104
- package/dist/viem/Formatters.js.map +0 -1
- package/dist/viem/P256.d.ts +0 -2
- package/dist/viem/P256.d.ts.map +0 -1
- package/dist/viem/P256.js +0 -2
- package/dist/viem/P256.js.map +0 -1
- package/dist/viem/Secp256k1.d.ts +0 -2
- package/dist/viem/Secp256k1.d.ts.map +0 -1
- package/dist/viem/Secp256k1.js +0 -2
- package/dist/viem/Secp256k1.js.map +0 -1
- package/dist/viem/Storage.d.ts +0 -24
- package/dist/viem/Storage.d.ts.map +0 -1
- package/dist/viem/Storage.js +0 -68
- package/dist/viem/Storage.js.map +0 -1
- package/dist/viem/TokenIds.d.ts +0 -2
- package/dist/viem/TokenIds.d.ts.map +0 -1
- package/dist/viem/TokenIds.js +0 -2
- package/dist/viem/TokenIds.js.map +0 -1
- package/dist/viem/Transaction.d.ts +0 -76
- package/dist/viem/Transaction.d.ts.map +0 -1
- package/dist/viem/Transaction.js +0 -176
- package/dist/viem/Transaction.js.map +0 -1
- package/dist/viem/Transport.d.ts +0 -33
- package/dist/viem/Transport.d.ts.map +0 -1
- package/dist/viem/Transport.js +0 -138
- package/dist/viem/Transport.js.map +0 -1
- package/dist/viem/WebAuthnP256.d.ts +0 -82
- package/dist/viem/WebAuthnP256.d.ts.map +0 -1
- package/dist/viem/WebAuthnP256.js +0 -97
- package/dist/viem/WebAuthnP256.js.map +0 -1
- package/dist/viem/WebCryptoP256.d.ts +0 -2
- package/dist/viem/WebCryptoP256.d.ts.map +0 -1
- package/dist/viem/WebCryptoP256.js +0 -2
- package/dist/viem/WebCryptoP256.js.map +0 -1
- package/dist/viem/index.d.ts +0 -26
- package/dist/viem/index.d.ts.map +0 -1
- package/dist/viem/index.js +0 -17
- package/dist/viem/index.js.map +0 -1
- package/dist/viem/internal/types.d.ts +0 -20
- package/dist/viem/internal/types.d.ts.map +0 -1
- package/dist/viem/internal/types.js +0 -2
- package/dist/viem/internal/types.js.map +0 -1
- package/dist/viem/internal/utils.d.ts +0 -14
- package/dist/viem/internal/utils.d.ts.map +0 -1
- package/dist/viem/internal/utils.js +0 -33
- package/dist/viem/internal/utils.js.map +0 -1
- package/src/chains.ts +0 -54
- package/src/viem/Abis.ts +0 -1688
- package/src/viem/Account.test.ts +0 -444
- package/src/viem/Account.ts +0 -601
- package/src/viem/Actions/account.test.ts +0 -414
- package/src/viem/Actions/account.ts +0 -106
- package/src/viem/Actions/amm.test.ts +0 -381
- package/src/viem/Actions/amm.ts +0 -1227
- package/src/viem/Actions/dex.test.ts +0 -1549
- package/src/viem/Actions/dex.ts +0 -2150
- package/src/viem/Actions/faucet.ts +0 -121
- package/src/viem/Actions/fee.test.ts +0 -259
- package/src/viem/Actions/fee.ts +0 -372
- package/src/viem/Actions/index.ts +0 -9
- package/src/viem/Actions/nonce.test.ts +0 -206
- package/src/viem/Actions/nonce.ts +0 -347
- package/src/viem/Actions/policy.test.ts +0 -534
- package/src/viem/Actions/policy.ts +0 -1335
- package/src/viem/Actions/reward.test.ts +0 -434
- package/src/viem/Actions/reward.ts +0 -944
- package/src/viem/Actions/token.test.ts +0 -3029
- package/src/viem/Actions/token.ts +0 -4458
- package/src/viem/Addresses.ts +0 -9
- package/src/viem/Chain.bench-d.ts +0 -12
- package/src/viem/Chain.test.ts +0 -168
- package/src/viem/Chain.ts +0 -157
- package/src/viem/Decorator.bench-d.ts +0 -11
- package/src/viem/Decorator.test.ts +0 -39
- package/src/viem/Decorator.ts +0 -3179
- package/src/viem/Formatters.ts +0 -164
- package/src/viem/P256.ts +0 -1
- package/src/viem/Secp256k1.ts +0 -1
- package/src/viem/Storage.ts +0 -110
- package/src/viem/TokenIds.ts +0 -1
- package/src/viem/Transaction.ts +0 -382
- package/src/viem/Transport.ts +0 -191
- package/src/viem/WebAuthnP256.ts +0 -146
- package/src/viem/WebCryptoP256.ts +0 -1
- package/src/viem/e2e.test.ts +0 -1602
- package/src/viem/index.ts +0 -30
- package/src/viem/internal/types.ts +0 -69
- package/src/viem/internal/utils.ts +0 -58
- package/src/wagmi/internal/types.ts +0 -16
|
@@ -1,2936 +0,0 @@
|
|
|
1
|
-
import * as Hex from 'ox/Hex';
|
|
2
|
-
import { TokenId, TokenRole } from 'ox/tempo';
|
|
3
|
-
import { encodeFunctionData, parseEventLogs, } from 'viem';
|
|
4
|
-
import { parseAccount } from 'viem/accounts';
|
|
5
|
-
import { multicall, readContract, sendTransaction, sendTransactionSync, watchContractEvent, writeContract, writeContractSync, } from 'viem/actions';
|
|
6
|
-
import * as Abis from '../Abis.js';
|
|
7
|
-
import * as Addresses from '../Addresses.js';
|
|
8
|
-
import { defineCall } from '../internal/utils.js';
|
|
9
|
-
/**
|
|
10
|
-
* Approves a spender to transfer TIP20 tokens on behalf of the caller.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { createClient, http } from 'viem'
|
|
15
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
16
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
17
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
18
|
-
*
|
|
19
|
-
* const client = createClient({
|
|
20
|
-
* account: privateKeyToAccount('0x...'),
|
|
21
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
22
|
-
* transport: http(),
|
|
23
|
-
* })
|
|
24
|
-
*
|
|
25
|
-
* const result = await Actions.token.approve(client, {
|
|
26
|
-
* spender: '0x...',
|
|
27
|
-
* amount: 100n,
|
|
28
|
-
* })
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @param client - Client.
|
|
32
|
-
* @param parameters - Parameters.
|
|
33
|
-
* @returns The transaction hash.
|
|
34
|
-
*/
|
|
35
|
-
export async function approve(client, parameters) {
|
|
36
|
-
const { token, ...rest } = parameters;
|
|
37
|
-
return approve.inner(writeContract, client, parameters, { ...rest, token });
|
|
38
|
-
}
|
|
39
|
-
(function (approve) {
|
|
40
|
-
/** @internal */
|
|
41
|
-
async function inner(action, client, parameters, args) {
|
|
42
|
-
const call = approve.call(args);
|
|
43
|
-
return (await action(client, {
|
|
44
|
-
...parameters,
|
|
45
|
-
...call,
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
approve.inner = inner;
|
|
49
|
-
/**
|
|
50
|
-
* Defines a call to the `approve` function.
|
|
51
|
-
*
|
|
52
|
-
* Can be passed as a parameter to:
|
|
53
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
54
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
55
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
60
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
61
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
62
|
-
*
|
|
63
|
-
* const client = createClient({
|
|
64
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
65
|
-
* transport: http(),
|
|
66
|
-
* }).extend(walletActions)
|
|
67
|
-
*
|
|
68
|
-
* const { result } = await client.sendCalls({
|
|
69
|
-
* calls: [
|
|
70
|
-
* actions.token.approve.call({
|
|
71
|
-
* spender: '0x20c0...beef',
|
|
72
|
-
* amount: 100n,
|
|
73
|
-
* token: '0x20c0...babe',
|
|
74
|
-
* }),
|
|
75
|
-
* ]
|
|
76
|
-
* })
|
|
77
|
-
* ```
|
|
78
|
-
*
|
|
79
|
-
* @param args - Arguments.
|
|
80
|
-
* @returns The call.
|
|
81
|
-
*/
|
|
82
|
-
function call(args) {
|
|
83
|
-
const { spender, amount, token } = args;
|
|
84
|
-
return defineCall({
|
|
85
|
-
address: TokenId.toAddress(token),
|
|
86
|
-
abi: Abis.tip20,
|
|
87
|
-
functionName: 'approve',
|
|
88
|
-
args: [spender, amount],
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
approve.call = call;
|
|
92
|
-
function extractEvent(logs) {
|
|
93
|
-
const [log] = parseEventLogs({
|
|
94
|
-
abi: Abis.tip20,
|
|
95
|
-
logs,
|
|
96
|
-
eventName: 'Approval',
|
|
97
|
-
});
|
|
98
|
-
if (!log)
|
|
99
|
-
throw new Error('`Approval` event not found.');
|
|
100
|
-
return log;
|
|
101
|
-
}
|
|
102
|
-
approve.extractEvent = extractEvent;
|
|
103
|
-
})(approve || (approve = {}));
|
|
104
|
-
/**
|
|
105
|
-
* Approves a spender to transfer TIP20 tokens on behalf of the caller.
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* ```ts
|
|
109
|
-
* import { createClient, http } from 'viem'
|
|
110
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
111
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
112
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
113
|
-
*
|
|
114
|
-
* const client = createClient({
|
|
115
|
-
* account: privateKeyToAccount('0x...'),
|
|
116
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
117
|
-
* transport: http(),
|
|
118
|
-
* })
|
|
119
|
-
*
|
|
120
|
-
* const result = await Actions.token.approveSync(client, {
|
|
121
|
-
* spender: '0x...',
|
|
122
|
-
* amount: 100n,
|
|
123
|
-
* })
|
|
124
|
-
* ```
|
|
125
|
-
*
|
|
126
|
-
* @param client - Client.
|
|
127
|
-
* @param parameters - Parameters.
|
|
128
|
-
* @returns The transaction receipt and event data.
|
|
129
|
-
*/
|
|
130
|
-
export async function approveSync(client, parameters) {
|
|
131
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
132
|
-
const receipt = await approve.inner(writeContractSync, client, { ...parameters, throwOnReceiptRevert }, rest);
|
|
133
|
-
const { args } = approve.extractEvent(receipt.logs);
|
|
134
|
-
return {
|
|
135
|
-
...args,
|
|
136
|
-
receipt,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Burns TIP20 tokens from a blocked address.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```ts
|
|
144
|
-
* import { createClient, http } from 'viem'
|
|
145
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
146
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
147
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
148
|
-
*
|
|
149
|
-
* const client = createClient({
|
|
150
|
-
* account: privateKeyToAccount('0x...'),
|
|
151
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
152
|
-
* transport: http(),
|
|
153
|
-
* })
|
|
154
|
-
*
|
|
155
|
-
* const result = await Actions.token.burnBlocked(client, {
|
|
156
|
-
* from: '0x...',
|
|
157
|
-
* amount: 100n,
|
|
158
|
-
* token: '0x...',
|
|
159
|
-
* })
|
|
160
|
-
* ```
|
|
161
|
-
*
|
|
162
|
-
* @param client - Client.
|
|
163
|
-
* @param parameters - Parameters.
|
|
164
|
-
* @returns The transaction hash.
|
|
165
|
-
*/
|
|
166
|
-
export async function burnBlocked(client, parameters) {
|
|
167
|
-
return burnBlocked.inner(writeContract, client, parameters);
|
|
168
|
-
}
|
|
169
|
-
(function (burnBlocked) {
|
|
170
|
-
/** @internal */
|
|
171
|
-
async function inner(action, client, parameters) {
|
|
172
|
-
const { amount, from, token, ...rest } = parameters;
|
|
173
|
-
const call = burnBlocked.call({ amount, from, token });
|
|
174
|
-
return (await action(client, {
|
|
175
|
-
...rest,
|
|
176
|
-
...call,
|
|
177
|
-
}));
|
|
178
|
-
}
|
|
179
|
-
burnBlocked.inner = inner;
|
|
180
|
-
/**
|
|
181
|
-
* Defines a call to the `burnBlocked` function.
|
|
182
|
-
*
|
|
183
|
-
* Can be passed as a parameter to:
|
|
184
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
185
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
186
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* ```ts
|
|
190
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
191
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
192
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
193
|
-
*
|
|
194
|
-
* const client = createClient({
|
|
195
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
196
|
-
* transport: http(),
|
|
197
|
-
* }).extend(walletActions)
|
|
198
|
-
*
|
|
199
|
-
* const { result } = await client.sendCalls({
|
|
200
|
-
* calls: [
|
|
201
|
-
* actions.token.burnBlocked.call({
|
|
202
|
-
* from: '0x20c0...beef',
|
|
203
|
-
* amount: 100n,
|
|
204
|
-
* token: '0x20c0...babe',
|
|
205
|
-
* }),
|
|
206
|
-
* ]
|
|
207
|
-
* })
|
|
208
|
-
* ```
|
|
209
|
-
*
|
|
210
|
-
* @param args - Arguments.
|
|
211
|
-
* @returns The call.
|
|
212
|
-
*/
|
|
213
|
-
function call(args) {
|
|
214
|
-
const { from, amount, token } = args;
|
|
215
|
-
return defineCall({
|
|
216
|
-
address: TokenId.toAddress(token),
|
|
217
|
-
abi: Abis.tip20,
|
|
218
|
-
functionName: 'burnBlocked',
|
|
219
|
-
args: [from, amount],
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
burnBlocked.call = call;
|
|
223
|
-
/**
|
|
224
|
-
* Extracts the event from the logs.
|
|
225
|
-
*
|
|
226
|
-
* @param logs - Logs.
|
|
227
|
-
* @returns The event.
|
|
228
|
-
*/
|
|
229
|
-
function extractEvent(logs) {
|
|
230
|
-
const [log] = parseEventLogs({
|
|
231
|
-
abi: Abis.tip20,
|
|
232
|
-
logs,
|
|
233
|
-
eventName: 'BurnBlocked',
|
|
234
|
-
});
|
|
235
|
-
if (!log)
|
|
236
|
-
throw new Error('`BurnBlocked` event not found.');
|
|
237
|
-
return log;
|
|
238
|
-
}
|
|
239
|
-
burnBlocked.extractEvent = extractEvent;
|
|
240
|
-
})(burnBlocked || (burnBlocked = {}));
|
|
241
|
-
/**
|
|
242
|
-
* Burns TIP20 tokens from a blocked address.
|
|
243
|
-
*
|
|
244
|
-
* @example
|
|
245
|
-
* ```ts
|
|
246
|
-
* import { createClient, http } from 'viem'
|
|
247
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
248
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
249
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
250
|
-
*
|
|
251
|
-
* const client = createClient({
|
|
252
|
-
* account: privateKeyToAccount('0x...'),
|
|
253
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
254
|
-
* transport: http(),
|
|
255
|
-
* })
|
|
256
|
-
*
|
|
257
|
-
* const result = await Actions.token.burnBlockedSync(client, {
|
|
258
|
-
* from: '0x...',
|
|
259
|
-
* amount: 100n,
|
|
260
|
-
* token: '0x...',
|
|
261
|
-
* })
|
|
262
|
-
* ```
|
|
263
|
-
*
|
|
264
|
-
* @param client - Client.
|
|
265
|
-
* @param parameters - Parameters.
|
|
266
|
-
* @returns The transaction receipt and event data.
|
|
267
|
-
*/
|
|
268
|
-
export async function burnBlockedSync(client, parameters) {
|
|
269
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
270
|
-
const receipt = await burnBlocked.inner(writeContractSync, client, {
|
|
271
|
-
...rest,
|
|
272
|
-
throwOnReceiptRevert,
|
|
273
|
-
});
|
|
274
|
-
const { args } = burnBlocked.extractEvent(receipt.logs);
|
|
275
|
-
return {
|
|
276
|
-
...args,
|
|
277
|
-
receipt,
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Burns TIP20 tokens from the caller's balance.
|
|
282
|
-
*
|
|
283
|
-
* @example
|
|
284
|
-
* ```ts
|
|
285
|
-
* import { createClient, http } from 'viem'
|
|
286
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
287
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
288
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
289
|
-
*
|
|
290
|
-
* const client = createClient({
|
|
291
|
-
* account: privateKeyToAccount('0x...'),
|
|
292
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
293
|
-
* transport: http(),
|
|
294
|
-
* })
|
|
295
|
-
*
|
|
296
|
-
* const result = await Actions.token.burn(client, {
|
|
297
|
-
* amount: 100n,
|
|
298
|
-
* token: '0x...',
|
|
299
|
-
* })
|
|
300
|
-
* ```
|
|
301
|
-
*
|
|
302
|
-
* @param client - Client.
|
|
303
|
-
* @param parameters - Parameters.
|
|
304
|
-
* @returns The transaction hash.
|
|
305
|
-
*/
|
|
306
|
-
export async function burn(client, parameters) {
|
|
307
|
-
return burn.inner(writeContract, client, parameters);
|
|
308
|
-
}
|
|
309
|
-
(function (burn) {
|
|
310
|
-
/** @internal */
|
|
311
|
-
async function inner(action, client, parameters) {
|
|
312
|
-
const { amount, memo, token, ...rest } = parameters;
|
|
313
|
-
const call = burn.call({ amount, memo, token });
|
|
314
|
-
return (await action(client, {
|
|
315
|
-
...rest,
|
|
316
|
-
...call,
|
|
317
|
-
}));
|
|
318
|
-
}
|
|
319
|
-
burn.inner = inner;
|
|
320
|
-
/**
|
|
321
|
-
* Defines a call to the `burn` or `burnWithMemo` function.
|
|
322
|
-
*
|
|
323
|
-
* Can be passed as a parameter to:
|
|
324
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
325
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
326
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
327
|
-
*
|
|
328
|
-
* @example
|
|
329
|
-
* ```ts
|
|
330
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
331
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
332
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
333
|
-
*
|
|
334
|
-
* const client = createClient({
|
|
335
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
336
|
-
* transport: http(),
|
|
337
|
-
* }).extend(walletActions)
|
|
338
|
-
*
|
|
339
|
-
* const { result } = await client.sendCalls({
|
|
340
|
-
* calls: [
|
|
341
|
-
* actions.token.burn.call({
|
|
342
|
-
* amount: 100n,
|
|
343
|
-
* token: '0x20c0...babe',
|
|
344
|
-
* }),
|
|
345
|
-
* ]
|
|
346
|
-
* })
|
|
347
|
-
* ```
|
|
348
|
-
*
|
|
349
|
-
* @param args - Arguments.
|
|
350
|
-
* @returns The call.
|
|
351
|
-
*/
|
|
352
|
-
function call(args) {
|
|
353
|
-
const { amount, memo, token } = args;
|
|
354
|
-
const callArgs = memo
|
|
355
|
-
? {
|
|
356
|
-
functionName: 'burnWithMemo',
|
|
357
|
-
args: [amount, Hex.padLeft(memo, 32)],
|
|
358
|
-
}
|
|
359
|
-
: {
|
|
360
|
-
functionName: 'burn',
|
|
361
|
-
args: [amount],
|
|
362
|
-
};
|
|
363
|
-
return defineCall({
|
|
364
|
-
address: TokenId.toAddress(token),
|
|
365
|
-
abi: Abis.tip20,
|
|
366
|
-
...callArgs,
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
burn.call = call;
|
|
370
|
-
/**
|
|
371
|
-
* Extracts the event from the logs.
|
|
372
|
-
*
|
|
373
|
-
* @param logs - Logs.
|
|
374
|
-
* @returns The event.
|
|
375
|
-
*/
|
|
376
|
-
function extractEvent(logs) {
|
|
377
|
-
const [log] = parseEventLogs({
|
|
378
|
-
abi: Abis.tip20,
|
|
379
|
-
logs,
|
|
380
|
-
eventName: 'Burn',
|
|
381
|
-
});
|
|
382
|
-
if (!log)
|
|
383
|
-
throw new Error('`Burn` event not found.');
|
|
384
|
-
return log;
|
|
385
|
-
}
|
|
386
|
-
burn.extractEvent = extractEvent;
|
|
387
|
-
})(burn || (burn = {}));
|
|
388
|
-
/**
|
|
389
|
-
* Burns TIP20 tokens from the caller's balance.
|
|
390
|
-
*
|
|
391
|
-
* @example
|
|
392
|
-
* ```ts
|
|
393
|
-
* import { createClient, http } from 'viem'
|
|
394
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
395
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
396
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
397
|
-
*
|
|
398
|
-
* const client = createClient({
|
|
399
|
-
* account: privateKeyToAccount('0x...'),
|
|
400
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
401
|
-
* transport: http(),
|
|
402
|
-
* })
|
|
403
|
-
*
|
|
404
|
-
* const result = await Actions.token.burnSync(client, {
|
|
405
|
-
* amount: 100n,
|
|
406
|
-
* token: '0x...',
|
|
407
|
-
* })
|
|
408
|
-
* ```
|
|
409
|
-
*
|
|
410
|
-
* @param client - Client.
|
|
411
|
-
* @param parameters - Parameters.
|
|
412
|
-
* @returns The transaction receipt and event data.
|
|
413
|
-
*/
|
|
414
|
-
export async function burnSync(client, parameters) {
|
|
415
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
416
|
-
const receipt = await burn.inner(writeContractSync, client, {
|
|
417
|
-
...rest,
|
|
418
|
-
throwOnReceiptRevert,
|
|
419
|
-
});
|
|
420
|
-
const { args } = burn.extractEvent(receipt.logs);
|
|
421
|
-
return {
|
|
422
|
-
...args,
|
|
423
|
-
receipt,
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Changes the transfer policy ID for a TIP20 token.
|
|
428
|
-
*
|
|
429
|
-
* @example
|
|
430
|
-
* ```ts
|
|
431
|
-
* import { createClient, http } from 'viem'
|
|
432
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
433
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
434
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
435
|
-
*
|
|
436
|
-
* const client = createClient({
|
|
437
|
-
* account: privateKeyToAccount('0x...'),
|
|
438
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
439
|
-
* transport: http(),
|
|
440
|
-
* })
|
|
441
|
-
*
|
|
442
|
-
* const result = await Actions.token.changeTransferPolicy(client, {
|
|
443
|
-
* token: '0x...',
|
|
444
|
-
* policyId: 1n,
|
|
445
|
-
* })
|
|
446
|
-
* ```
|
|
447
|
-
*
|
|
448
|
-
* @param client - Client.
|
|
449
|
-
* @param parameters - Parameters.
|
|
450
|
-
* @returns The transaction hash.
|
|
451
|
-
*/
|
|
452
|
-
export async function changeTransferPolicy(client, parameters) {
|
|
453
|
-
return changeTransferPolicy.inner(writeContract, client, parameters);
|
|
454
|
-
}
|
|
455
|
-
(function (changeTransferPolicy) {
|
|
456
|
-
/** @internal */
|
|
457
|
-
async function inner(action, client, parameters) {
|
|
458
|
-
const { policyId, token, ...rest } = parameters;
|
|
459
|
-
const call = changeTransferPolicy.call({ policyId, token });
|
|
460
|
-
return (await action(client, {
|
|
461
|
-
...rest,
|
|
462
|
-
...call,
|
|
463
|
-
}));
|
|
464
|
-
}
|
|
465
|
-
changeTransferPolicy.inner = inner;
|
|
466
|
-
/**
|
|
467
|
-
* Defines a call to the `changeTransferPolicyId` function.
|
|
468
|
-
*
|
|
469
|
-
* Can be passed as a parameter to:
|
|
470
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
471
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
472
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
473
|
-
*
|
|
474
|
-
* @example
|
|
475
|
-
* ```ts
|
|
476
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
477
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
478
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
479
|
-
*
|
|
480
|
-
* const client = createClient({
|
|
481
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
482
|
-
* transport: http(),
|
|
483
|
-
* }).extend(walletActions)
|
|
484
|
-
*
|
|
485
|
-
* const { result } = await client.sendCalls({
|
|
486
|
-
* calls: [
|
|
487
|
-
* actions.token.changeTransferPolicy.call({
|
|
488
|
-
* token: '0x20c0...babe',
|
|
489
|
-
* policyId: 1n,
|
|
490
|
-
* }),
|
|
491
|
-
* ]
|
|
492
|
-
* })
|
|
493
|
-
* ```
|
|
494
|
-
*
|
|
495
|
-
* @param args - Arguments.
|
|
496
|
-
* @returns The call.
|
|
497
|
-
*/
|
|
498
|
-
function call(args) {
|
|
499
|
-
const { token, policyId } = args;
|
|
500
|
-
return defineCall({
|
|
501
|
-
address: TokenId.toAddress(token),
|
|
502
|
-
abi: Abis.tip20,
|
|
503
|
-
functionName: 'changeTransferPolicyId',
|
|
504
|
-
args: [policyId],
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
changeTransferPolicy.call = call;
|
|
508
|
-
/**
|
|
509
|
-
* Extracts the event from the logs.
|
|
510
|
-
*
|
|
511
|
-
* @param logs - Logs.
|
|
512
|
-
* @returns The event.
|
|
513
|
-
*/
|
|
514
|
-
function extractEvent(logs) {
|
|
515
|
-
const [log] = parseEventLogs({
|
|
516
|
-
abi: Abis.tip20,
|
|
517
|
-
logs,
|
|
518
|
-
eventName: 'TransferPolicyUpdate',
|
|
519
|
-
});
|
|
520
|
-
if (!log)
|
|
521
|
-
throw new Error('`TransferPolicyUpdate` event not found.');
|
|
522
|
-
return log;
|
|
523
|
-
}
|
|
524
|
-
changeTransferPolicy.extractEvent = extractEvent;
|
|
525
|
-
})(changeTransferPolicy || (changeTransferPolicy = {}));
|
|
526
|
-
/**
|
|
527
|
-
* Changes the transfer policy ID for a TIP20 token.
|
|
528
|
-
*
|
|
529
|
-
* @example
|
|
530
|
-
* ```ts
|
|
531
|
-
* import { createClient, http } from 'viem'
|
|
532
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
533
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
534
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
535
|
-
*
|
|
536
|
-
* const client = createClient({
|
|
537
|
-
* account: privateKeyToAccount('0x...'),
|
|
538
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
539
|
-
* transport: http(),
|
|
540
|
-
* })
|
|
541
|
-
*
|
|
542
|
-
* const result = await Actions.token.changeTransferPolicySync(client, {
|
|
543
|
-
* token: '0x...',
|
|
544
|
-
* policyId: 1n,
|
|
545
|
-
* })
|
|
546
|
-
* ```
|
|
547
|
-
*
|
|
548
|
-
* @param client - Client.
|
|
549
|
-
* @param parameters - Parameters.
|
|
550
|
-
* @returns The transaction receipt and event data.
|
|
551
|
-
*/
|
|
552
|
-
export async function changeTransferPolicySync(client, parameters) {
|
|
553
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
554
|
-
const receipt = await changeTransferPolicy.inner(writeContractSync, client, {
|
|
555
|
-
...rest,
|
|
556
|
-
throwOnReceiptRevert,
|
|
557
|
-
});
|
|
558
|
-
const { args } = changeTransferPolicy.extractEvent(receipt.logs);
|
|
559
|
-
return {
|
|
560
|
-
...args,
|
|
561
|
-
receipt,
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
/**
|
|
565
|
-
* Creates a new TIP20 token.
|
|
566
|
-
*
|
|
567
|
-
* @example
|
|
568
|
-
* ```ts
|
|
569
|
-
* import { createClient, http } from 'viem'
|
|
570
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
571
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
572
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
573
|
-
*
|
|
574
|
-
* const client = createClient({
|
|
575
|
-
* account: privateKeyToAccount('0x...'),
|
|
576
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
577
|
-
* transport: http(),
|
|
578
|
-
* })
|
|
579
|
-
*
|
|
580
|
-
* const result = await Actions.token.create(client, {
|
|
581
|
-
* name: 'My Token',
|
|
582
|
-
* symbol: 'MTK',
|
|
583
|
-
* currency: 'USD',
|
|
584
|
-
* })
|
|
585
|
-
* ```
|
|
586
|
-
*
|
|
587
|
-
* @param client - Client.
|
|
588
|
-
* @param parameters - Parameters.
|
|
589
|
-
* @returns The transaction hash.
|
|
590
|
-
*/
|
|
591
|
-
export async function create(client, parameters) {
|
|
592
|
-
return create.inner(writeContract, client, parameters);
|
|
593
|
-
}
|
|
594
|
-
(function (create) {
|
|
595
|
-
/** @internal */
|
|
596
|
-
async function inner(action, client, parameters) {
|
|
597
|
-
const { account = client.account, admin: admin_ = client.account, chain = client.chain, ...rest } = parameters;
|
|
598
|
-
const admin = admin_ ? parseAccount(admin_) : undefined;
|
|
599
|
-
if (!admin)
|
|
600
|
-
throw new Error('admin is required.');
|
|
601
|
-
const call = create.call({ ...rest, admin: admin.address });
|
|
602
|
-
return (await action(client, {
|
|
603
|
-
...parameters,
|
|
604
|
-
account,
|
|
605
|
-
chain,
|
|
606
|
-
...call,
|
|
607
|
-
}));
|
|
608
|
-
}
|
|
609
|
-
create.inner = inner;
|
|
610
|
-
/**
|
|
611
|
-
* Defines a call to the `createToken` function.
|
|
612
|
-
*
|
|
613
|
-
* Can be passed as a parameter to:
|
|
614
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
615
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
616
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
617
|
-
*
|
|
618
|
-
* @example
|
|
619
|
-
* ```ts
|
|
620
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
621
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
622
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
623
|
-
*
|
|
624
|
-
* const client = createClient({
|
|
625
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
626
|
-
* transport: http(),
|
|
627
|
-
* }).extend(walletActions)
|
|
628
|
-
*
|
|
629
|
-
* const { result } = await client.sendCalls({
|
|
630
|
-
* calls: [
|
|
631
|
-
* actions.token.create.call({
|
|
632
|
-
* name: 'My Token',
|
|
633
|
-
* symbol: 'MTK',
|
|
634
|
-
* currency: 'USD',
|
|
635
|
-
* admin: '0xfeed...fede',
|
|
636
|
-
* }),
|
|
637
|
-
* ]
|
|
638
|
-
* })
|
|
639
|
-
* ```
|
|
640
|
-
*
|
|
641
|
-
* @param args - Arguments.
|
|
642
|
-
* @returns The call.
|
|
643
|
-
*/
|
|
644
|
-
function call(args) {
|
|
645
|
-
const { name, symbol, currency, quoteToken = Addresses.pathUsd, admin, } = args;
|
|
646
|
-
return defineCall({
|
|
647
|
-
address: Addresses.tip20Factory,
|
|
648
|
-
abi: Abis.tip20Factory,
|
|
649
|
-
args: [name, symbol, currency, TokenId.toAddress(quoteToken), admin],
|
|
650
|
-
functionName: 'createToken',
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
create.call = call;
|
|
654
|
-
/**
|
|
655
|
-
* Extracts the `TokenCreated` event from logs.
|
|
656
|
-
*
|
|
657
|
-
* @param logs - The logs.
|
|
658
|
-
* @returns The `TokenCreated` event.
|
|
659
|
-
*/
|
|
660
|
-
function extractEvent(logs) {
|
|
661
|
-
const [log] = parseEventLogs({
|
|
662
|
-
abi: Abis.tip20Factory,
|
|
663
|
-
logs,
|
|
664
|
-
eventName: 'TokenCreated',
|
|
665
|
-
strict: true,
|
|
666
|
-
});
|
|
667
|
-
if (!log)
|
|
668
|
-
throw new Error('`TokenCreated` event not found.');
|
|
669
|
-
return log;
|
|
670
|
-
}
|
|
671
|
-
create.extractEvent = extractEvent;
|
|
672
|
-
})(create || (create = {}));
|
|
673
|
-
/**
|
|
674
|
-
* Creates a new TIP20 token.
|
|
675
|
-
*
|
|
676
|
-
* @example
|
|
677
|
-
* ```ts
|
|
678
|
-
* import { createClient, http } from 'viem'
|
|
679
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
680
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
681
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
682
|
-
*
|
|
683
|
-
* const client = createClient({
|
|
684
|
-
* account: privateKeyToAccount('0x...'),
|
|
685
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
686
|
-
* transport: http(),
|
|
687
|
-
* })
|
|
688
|
-
*
|
|
689
|
-
* const result = await Actions.token.createSync(client, {
|
|
690
|
-
* name: 'My Token',
|
|
691
|
-
* symbol: 'MTK',
|
|
692
|
-
* currency: 'USD',
|
|
693
|
-
* })
|
|
694
|
-
* ```
|
|
695
|
-
*
|
|
696
|
-
* @param client - Client.
|
|
697
|
-
* @param parameters - Parameters.
|
|
698
|
-
* @returns The transaction receipt and event data.
|
|
699
|
-
*/
|
|
700
|
-
export async function createSync(client, parameters) {
|
|
701
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
702
|
-
const receipt = await create.inner(writeContractSync, client, {
|
|
703
|
-
...rest,
|
|
704
|
-
throwOnReceiptRevert,
|
|
705
|
-
});
|
|
706
|
-
const { args } = create.extractEvent(receipt.logs);
|
|
707
|
-
return {
|
|
708
|
-
...args,
|
|
709
|
-
receipt,
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
/**
|
|
713
|
-
* Gets TIP20 token allowance.
|
|
714
|
-
*
|
|
715
|
-
* @example
|
|
716
|
-
* ```ts
|
|
717
|
-
* import { createClient, http } from 'viem'
|
|
718
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
719
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
720
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
721
|
-
*
|
|
722
|
-
* const client = createClient({
|
|
723
|
-
* account: privateKeyToAccount('0x...'),
|
|
724
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
725
|
-
* transport: http(),
|
|
726
|
-
* })
|
|
727
|
-
*
|
|
728
|
-
* const allowance = await Actions.token.getAllowance(client, {
|
|
729
|
-
* spender: '0x...',
|
|
730
|
-
* })
|
|
731
|
-
* ```
|
|
732
|
-
*
|
|
733
|
-
* @param client - Client.
|
|
734
|
-
* @param parameters - Parameters.
|
|
735
|
-
* @returns The token allowance.
|
|
736
|
-
*/
|
|
737
|
-
export async function getAllowance(client, parameters) {
|
|
738
|
-
const { account = client.account } = parameters;
|
|
739
|
-
const address = account ? parseAccount(account).address : undefined;
|
|
740
|
-
if (!address)
|
|
741
|
-
throw new Error('account is required.');
|
|
742
|
-
return readContract(client, {
|
|
743
|
-
...parameters,
|
|
744
|
-
...getAllowance.call({ ...parameters, account: address }),
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
(function (getAllowance) {
|
|
748
|
-
/**
|
|
749
|
-
* Defines a call to the `allowance` function.
|
|
750
|
-
*
|
|
751
|
-
* @param args - Arguments.
|
|
752
|
-
* @returns The call.
|
|
753
|
-
*/
|
|
754
|
-
function call(args) {
|
|
755
|
-
const { account, spender, token } = args;
|
|
756
|
-
return defineCall({
|
|
757
|
-
address: TokenId.toAddress(token),
|
|
758
|
-
abi: Abis.tip20,
|
|
759
|
-
functionName: 'allowance',
|
|
760
|
-
args: [account, spender],
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
getAllowance.call = call;
|
|
764
|
-
})(getAllowance || (getAllowance = {}));
|
|
765
|
-
/**
|
|
766
|
-
* Gets TIP20 token balance for an address.
|
|
767
|
-
*
|
|
768
|
-
* @example
|
|
769
|
-
* ```ts
|
|
770
|
-
* import { createClient, http } from 'viem'
|
|
771
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
772
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
773
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
774
|
-
*
|
|
775
|
-
* const client = createClient({
|
|
776
|
-
* account: privateKeyToAccount('0x...'),
|
|
777
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
778
|
-
* transport: http(),
|
|
779
|
-
* })
|
|
780
|
-
*
|
|
781
|
-
* const balance = await Actions.token.getBalance(client, {
|
|
782
|
-
* token: '0x...',
|
|
783
|
-
* })
|
|
784
|
-
* ```
|
|
785
|
-
*
|
|
786
|
-
* @param client - Client.
|
|
787
|
-
* @param parameters - Parameters.
|
|
788
|
-
* @returns The token balance.
|
|
789
|
-
*/
|
|
790
|
-
export async function getBalance(client, parameters) {
|
|
791
|
-
const { account = client.account, ...rest } = parameters;
|
|
792
|
-
const address = account ? parseAccount(account).address : undefined;
|
|
793
|
-
if (!address)
|
|
794
|
-
throw new Error('account is required.');
|
|
795
|
-
return readContract(client, {
|
|
796
|
-
...rest,
|
|
797
|
-
...getBalance.call({ account: address, ...rest }),
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
(function (getBalance) {
|
|
801
|
-
/**
|
|
802
|
-
* Defines a call to the `balanceOf` function.
|
|
803
|
-
*
|
|
804
|
-
* @param args - Arguments.
|
|
805
|
-
* @returns The call.
|
|
806
|
-
*/
|
|
807
|
-
function call(args) {
|
|
808
|
-
const { account, token } = args;
|
|
809
|
-
return defineCall({
|
|
810
|
-
address: TokenId.toAddress(token),
|
|
811
|
-
abi: Abis.tip20,
|
|
812
|
-
functionName: 'balanceOf',
|
|
813
|
-
args: [account],
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
getBalance.call = call;
|
|
817
|
-
})(getBalance || (getBalance = {}));
|
|
818
|
-
/**
|
|
819
|
-
* Gets TIP20 token metadata including name, symbol, currency, decimals, and total supply.
|
|
820
|
-
*
|
|
821
|
-
* @example
|
|
822
|
-
* ```ts
|
|
823
|
-
* import { createClient, http } from 'viem'
|
|
824
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
825
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
826
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
827
|
-
*
|
|
828
|
-
* const client = createClient({
|
|
829
|
-
* account: privateKeyToAccount('0x...'),
|
|
830
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
831
|
-
* transport: http(),
|
|
832
|
-
* })
|
|
833
|
-
*
|
|
834
|
-
* const metadata = await Actions.token.getMetadata(client, {
|
|
835
|
-
* token: '0x...',
|
|
836
|
-
* })
|
|
837
|
-
* ```
|
|
838
|
-
*
|
|
839
|
-
* @param client - Client.
|
|
840
|
-
* @param parameters - Parameters.
|
|
841
|
-
* @returns The token metadata.
|
|
842
|
-
*/
|
|
843
|
-
export async function getMetadata(client, parameters) {
|
|
844
|
-
const { token, ...rest } = parameters;
|
|
845
|
-
const address = TokenId.toAddress(token);
|
|
846
|
-
const abi = Abis.tip20;
|
|
847
|
-
if (TokenId.from(token) === TokenId.fromAddress(Addresses.pathUsd))
|
|
848
|
-
return multicall(client, {
|
|
849
|
-
...rest,
|
|
850
|
-
contracts: [
|
|
851
|
-
{
|
|
852
|
-
address,
|
|
853
|
-
abi,
|
|
854
|
-
functionName: 'currency',
|
|
855
|
-
},
|
|
856
|
-
{
|
|
857
|
-
address,
|
|
858
|
-
abi,
|
|
859
|
-
functionName: 'decimals',
|
|
860
|
-
},
|
|
861
|
-
{
|
|
862
|
-
address,
|
|
863
|
-
abi,
|
|
864
|
-
functionName: 'name',
|
|
865
|
-
},
|
|
866
|
-
{
|
|
867
|
-
address,
|
|
868
|
-
abi,
|
|
869
|
-
functionName: 'symbol',
|
|
870
|
-
},
|
|
871
|
-
{
|
|
872
|
-
address,
|
|
873
|
-
abi,
|
|
874
|
-
functionName: 'totalSupply',
|
|
875
|
-
},
|
|
876
|
-
],
|
|
877
|
-
allowFailure: false,
|
|
878
|
-
deployless: true,
|
|
879
|
-
}).then(([currency, decimals, name, symbol, totalSupply]) => ({
|
|
880
|
-
name,
|
|
881
|
-
symbol,
|
|
882
|
-
currency,
|
|
883
|
-
decimals,
|
|
884
|
-
totalSupply,
|
|
885
|
-
}));
|
|
886
|
-
return multicall(client, {
|
|
887
|
-
...rest,
|
|
888
|
-
contracts: [
|
|
889
|
-
{
|
|
890
|
-
address,
|
|
891
|
-
abi,
|
|
892
|
-
functionName: 'currency',
|
|
893
|
-
},
|
|
894
|
-
{
|
|
895
|
-
address,
|
|
896
|
-
abi,
|
|
897
|
-
functionName: 'decimals',
|
|
898
|
-
},
|
|
899
|
-
{
|
|
900
|
-
address,
|
|
901
|
-
abi,
|
|
902
|
-
functionName: 'quoteToken',
|
|
903
|
-
},
|
|
904
|
-
{
|
|
905
|
-
address,
|
|
906
|
-
abi,
|
|
907
|
-
functionName: 'name',
|
|
908
|
-
},
|
|
909
|
-
{
|
|
910
|
-
address,
|
|
911
|
-
abi,
|
|
912
|
-
functionName: 'paused',
|
|
913
|
-
},
|
|
914
|
-
{
|
|
915
|
-
address,
|
|
916
|
-
abi,
|
|
917
|
-
functionName: 'supplyCap',
|
|
918
|
-
},
|
|
919
|
-
{
|
|
920
|
-
address,
|
|
921
|
-
abi,
|
|
922
|
-
functionName: 'symbol',
|
|
923
|
-
},
|
|
924
|
-
{
|
|
925
|
-
address,
|
|
926
|
-
abi,
|
|
927
|
-
functionName: 'totalSupply',
|
|
928
|
-
},
|
|
929
|
-
{
|
|
930
|
-
address,
|
|
931
|
-
abi,
|
|
932
|
-
functionName: 'transferPolicyId',
|
|
933
|
-
},
|
|
934
|
-
],
|
|
935
|
-
allowFailure: false,
|
|
936
|
-
deployless: true,
|
|
937
|
-
}).then(([currency, decimals, quoteToken, name, paused, supplyCap, symbol, totalSupply, transferPolicyId,]) => ({
|
|
938
|
-
name,
|
|
939
|
-
symbol,
|
|
940
|
-
currency,
|
|
941
|
-
decimals,
|
|
942
|
-
quoteToken,
|
|
943
|
-
totalSupply,
|
|
944
|
-
paused,
|
|
945
|
-
supplyCap,
|
|
946
|
-
transferPolicyId,
|
|
947
|
-
}));
|
|
948
|
-
}
|
|
949
|
-
/**
|
|
950
|
-
* Gets the admin role for a specific role in a TIP20 token.
|
|
951
|
-
*
|
|
952
|
-
* @example
|
|
953
|
-
* ```ts
|
|
954
|
-
* import { createClient, http } from 'viem'
|
|
955
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
956
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
957
|
-
*
|
|
958
|
-
* const client = createClient({
|
|
959
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
960
|
-
* transport: http(),
|
|
961
|
-
* })
|
|
962
|
-
*
|
|
963
|
-
* const adminRole = await Actions.token.getRoleAdmin(client, {
|
|
964
|
-
* role: 'issuer',
|
|
965
|
-
* token: '0x...',
|
|
966
|
-
* })
|
|
967
|
-
* ```
|
|
968
|
-
*
|
|
969
|
-
* @param client - Client.
|
|
970
|
-
* @param parameters - Parameters.
|
|
971
|
-
* @returns The admin role hash.
|
|
972
|
-
*/
|
|
973
|
-
export async function getRoleAdmin(client, parameters) {
|
|
974
|
-
return readContract(client, {
|
|
975
|
-
...parameters,
|
|
976
|
-
...getRoleAdmin.call(parameters),
|
|
977
|
-
});
|
|
978
|
-
}
|
|
979
|
-
(function (getRoleAdmin) {
|
|
980
|
-
/**
|
|
981
|
-
* Defines a call to the `getRoleAdmin` function.
|
|
982
|
-
*
|
|
983
|
-
* @param args - Arguments.
|
|
984
|
-
* @returns The call.
|
|
985
|
-
*/
|
|
986
|
-
function call(args) {
|
|
987
|
-
const { role, token } = args;
|
|
988
|
-
return defineCall({
|
|
989
|
-
address: TokenId.toAddress(token),
|
|
990
|
-
abi: Abis.tip20,
|
|
991
|
-
functionName: 'getRoleAdmin',
|
|
992
|
-
args: [TokenRole.serialize(role)],
|
|
993
|
-
});
|
|
994
|
-
}
|
|
995
|
-
getRoleAdmin.call = call;
|
|
996
|
-
})(getRoleAdmin || (getRoleAdmin = {}));
|
|
997
|
-
/**
|
|
998
|
-
* Checks if an account has a specific role for a TIP20 token.
|
|
999
|
-
*
|
|
1000
|
-
* @example
|
|
1001
|
-
* ```ts
|
|
1002
|
-
* import { createClient, http } from 'viem'
|
|
1003
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1004
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1005
|
-
*
|
|
1006
|
-
* const client = createClient({
|
|
1007
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1008
|
-
* transport: http(),
|
|
1009
|
-
* })
|
|
1010
|
-
*
|
|
1011
|
-
* const hasRole = await Actions.token.hasRole(client, {
|
|
1012
|
-
* account: '0x...',
|
|
1013
|
-
* role: 'issuer',
|
|
1014
|
-
* token: '0x...',
|
|
1015
|
-
* })
|
|
1016
|
-
* ```
|
|
1017
|
-
*
|
|
1018
|
-
* @param client - Client.
|
|
1019
|
-
* @param parameters - Parameters.
|
|
1020
|
-
* @returns Whether the account has the role.
|
|
1021
|
-
*/
|
|
1022
|
-
export async function hasRole(client, parameters) {
|
|
1023
|
-
const { account = client.account } = parameters;
|
|
1024
|
-
const address = account ? parseAccount(account).address : undefined;
|
|
1025
|
-
if (!address)
|
|
1026
|
-
throw new Error('account is required.');
|
|
1027
|
-
return readContract(client, {
|
|
1028
|
-
...parameters,
|
|
1029
|
-
...hasRole.call({ ...parameters, account: address }),
|
|
1030
|
-
});
|
|
1031
|
-
}
|
|
1032
|
-
(function (hasRole) {
|
|
1033
|
-
/**
|
|
1034
|
-
* Defines a call to the `hasRole` function.
|
|
1035
|
-
*
|
|
1036
|
-
* @param args - Arguments.
|
|
1037
|
-
* @returns The call.
|
|
1038
|
-
*/
|
|
1039
|
-
function call(args) {
|
|
1040
|
-
const { account, role, token } = args;
|
|
1041
|
-
return defineCall({
|
|
1042
|
-
address: TokenId.toAddress(token),
|
|
1043
|
-
abi: Abis.tip20,
|
|
1044
|
-
functionName: 'hasRole',
|
|
1045
|
-
args: [account, TokenRole.serialize(role)],
|
|
1046
|
-
});
|
|
1047
|
-
}
|
|
1048
|
-
hasRole.call = call;
|
|
1049
|
-
})(hasRole || (hasRole = {}));
|
|
1050
|
-
/**
|
|
1051
|
-
* Grants a role for a TIP20 token.
|
|
1052
|
-
*
|
|
1053
|
-
* @example
|
|
1054
|
-
* ```ts
|
|
1055
|
-
* import { createClient, http } from 'viem'
|
|
1056
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1057
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1058
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1059
|
-
*
|
|
1060
|
-
* const client = createClient({
|
|
1061
|
-
* account: privateKeyToAccount('0x...'),
|
|
1062
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1063
|
-
* transport: http(),
|
|
1064
|
-
* })
|
|
1065
|
-
*
|
|
1066
|
-
* const result = await Actions.token.grantRoles(client, {
|
|
1067
|
-
* token: '0x...',
|
|
1068
|
-
* to: '0x...',
|
|
1069
|
-
* roles: ['issuer'],
|
|
1070
|
-
* })
|
|
1071
|
-
* ```
|
|
1072
|
-
*
|
|
1073
|
-
* @param client - Client.
|
|
1074
|
-
* @param parameters - Parameters.
|
|
1075
|
-
* @returns The transaction hash.
|
|
1076
|
-
*/
|
|
1077
|
-
export async function grantRoles(client, parameters) {
|
|
1078
|
-
return grantRoles.inner(sendTransaction, client, parameters);
|
|
1079
|
-
}
|
|
1080
|
-
(function (grantRoles) {
|
|
1081
|
-
/** @internal */
|
|
1082
|
-
async function inner(action, client, parameters) {
|
|
1083
|
-
return (await action(client, {
|
|
1084
|
-
...parameters,
|
|
1085
|
-
calls: parameters.roles.map((role) => {
|
|
1086
|
-
const call = grantRoles.call({ ...parameters, role });
|
|
1087
|
-
return {
|
|
1088
|
-
...call,
|
|
1089
|
-
data: encodeFunctionData(call),
|
|
1090
|
-
};
|
|
1091
|
-
}),
|
|
1092
|
-
}));
|
|
1093
|
-
}
|
|
1094
|
-
grantRoles.inner = inner;
|
|
1095
|
-
/**
|
|
1096
|
-
* Defines a call to the `grantRole` function.
|
|
1097
|
-
*
|
|
1098
|
-
* Can be passed as a parameter to:
|
|
1099
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1100
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1101
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1102
|
-
*
|
|
1103
|
-
* @example
|
|
1104
|
-
* ```ts
|
|
1105
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
1106
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1107
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1108
|
-
*
|
|
1109
|
-
* const client = createClient({
|
|
1110
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1111
|
-
* transport: http(),
|
|
1112
|
-
* }).extend(walletActions)
|
|
1113
|
-
*
|
|
1114
|
-
* const { result } = await client.sendCalls({
|
|
1115
|
-
* calls: [
|
|
1116
|
-
* actions.token.grantRoles.call({
|
|
1117
|
-
* token: '0x20c0...babe',
|
|
1118
|
-
* to: '0x20c0...beef',
|
|
1119
|
-
* role: 'issuer',
|
|
1120
|
-
* }),
|
|
1121
|
-
* ]
|
|
1122
|
-
* })
|
|
1123
|
-
* ```
|
|
1124
|
-
*
|
|
1125
|
-
* @param args - Arguments.
|
|
1126
|
-
* @returns The call.
|
|
1127
|
-
*/
|
|
1128
|
-
function call(args) {
|
|
1129
|
-
const { token, to, role } = args;
|
|
1130
|
-
const roleHash = TokenRole.serialize(role);
|
|
1131
|
-
return defineCall({
|
|
1132
|
-
address: TokenId.toAddress(token),
|
|
1133
|
-
abi: Abis.tip20,
|
|
1134
|
-
functionName: 'grantRole',
|
|
1135
|
-
args: [roleHash, to],
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
grantRoles.call = call;
|
|
1139
|
-
/**
|
|
1140
|
-
* Extracts the events from the logs.
|
|
1141
|
-
*
|
|
1142
|
-
* @param logs - Logs.
|
|
1143
|
-
* @returns The events.
|
|
1144
|
-
*/
|
|
1145
|
-
function extractEvents(logs) {
|
|
1146
|
-
const events = parseEventLogs({
|
|
1147
|
-
abi: Abis.tip20,
|
|
1148
|
-
logs,
|
|
1149
|
-
eventName: 'RoleMembershipUpdated',
|
|
1150
|
-
});
|
|
1151
|
-
if (events.length === 0)
|
|
1152
|
-
throw new Error('`RoleMembershipUpdated` events not found.');
|
|
1153
|
-
return events;
|
|
1154
|
-
}
|
|
1155
|
-
grantRoles.extractEvents = extractEvents;
|
|
1156
|
-
})(grantRoles || (grantRoles = {}));
|
|
1157
|
-
/**
|
|
1158
|
-
* Grants a role for a TIP20 token.
|
|
1159
|
-
*
|
|
1160
|
-
* @example
|
|
1161
|
-
* ```ts
|
|
1162
|
-
* import { createClient, http } from 'viem'
|
|
1163
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1164
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1165
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1166
|
-
*
|
|
1167
|
-
* const client = createClient({
|
|
1168
|
-
* account: privateKeyToAccount('0x...'),
|
|
1169
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1170
|
-
* transport: http(),
|
|
1171
|
-
* })
|
|
1172
|
-
*
|
|
1173
|
-
* const result = await Actions.token.grantRolesSync(client, {
|
|
1174
|
-
* token: '0x...',
|
|
1175
|
-
* to: '0x...',
|
|
1176
|
-
* roles: ['issuer'],
|
|
1177
|
-
* })
|
|
1178
|
-
* ```
|
|
1179
|
-
*
|
|
1180
|
-
* @param client - Client.
|
|
1181
|
-
* @param parameters - Parameters.
|
|
1182
|
-
* @returns The transaction receipt and event data.
|
|
1183
|
-
*/
|
|
1184
|
-
export async function grantRolesSync(client, parameters) {
|
|
1185
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
1186
|
-
const receipt = await grantRoles.inner(sendTransactionSync, client, {
|
|
1187
|
-
...rest,
|
|
1188
|
-
throwOnReceiptRevert,
|
|
1189
|
-
});
|
|
1190
|
-
const events = grantRoles.extractEvents(receipt.logs);
|
|
1191
|
-
const value = events.map((event) => event.args);
|
|
1192
|
-
return {
|
|
1193
|
-
receipt,
|
|
1194
|
-
value,
|
|
1195
|
-
};
|
|
1196
|
-
}
|
|
1197
|
-
/**
|
|
1198
|
-
* Mints TIP20 tokens to an address.
|
|
1199
|
-
*
|
|
1200
|
-
* @example
|
|
1201
|
-
* ```ts
|
|
1202
|
-
* import { createClient, http } from 'viem'
|
|
1203
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1204
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1205
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1206
|
-
*
|
|
1207
|
-
* const client = createClient({
|
|
1208
|
-
* account: privateKeyToAccount('0x...'),
|
|
1209
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1210
|
-
* transport: http(),
|
|
1211
|
-
* })
|
|
1212
|
-
*
|
|
1213
|
-
* const result = await Actions.token.mint(client, {
|
|
1214
|
-
* to: '0x...',
|
|
1215
|
-
* amount: 100n,
|
|
1216
|
-
* token: '0x...',
|
|
1217
|
-
* })
|
|
1218
|
-
* ```
|
|
1219
|
-
*
|
|
1220
|
-
* @param client - Client.
|
|
1221
|
-
* @param parameters - Parameters.
|
|
1222
|
-
* @returns The transaction hash.
|
|
1223
|
-
*/
|
|
1224
|
-
export async function mint(client, parameters) {
|
|
1225
|
-
return mint.inner(writeContract, client, parameters);
|
|
1226
|
-
}
|
|
1227
|
-
(function (mint) {
|
|
1228
|
-
/** @internal */
|
|
1229
|
-
async function inner(action, client, parameters) {
|
|
1230
|
-
const call = mint.call(parameters);
|
|
1231
|
-
return (await action(client, {
|
|
1232
|
-
...parameters,
|
|
1233
|
-
...call,
|
|
1234
|
-
}));
|
|
1235
|
-
}
|
|
1236
|
-
mint.inner = inner;
|
|
1237
|
-
/**
|
|
1238
|
-
* Defines a call to the `mint` or `mintWithMemo` function.
|
|
1239
|
-
*
|
|
1240
|
-
* Can be passed as a parameter to:
|
|
1241
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1242
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1243
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1244
|
-
*
|
|
1245
|
-
* @example
|
|
1246
|
-
* ```ts
|
|
1247
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
1248
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1249
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1250
|
-
*
|
|
1251
|
-
* const client = createClient({
|
|
1252
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1253
|
-
* transport: http(),
|
|
1254
|
-
* }).extend(walletActions)
|
|
1255
|
-
*
|
|
1256
|
-
* const { result } = await client.sendCalls({
|
|
1257
|
-
* calls: [
|
|
1258
|
-
* actions.token.mint.call({
|
|
1259
|
-
* to: '0x20c0...beef',
|
|
1260
|
-
* amount: 100n,
|
|
1261
|
-
* token: '0x20c0...babe',
|
|
1262
|
-
* }),
|
|
1263
|
-
* ]
|
|
1264
|
-
* })
|
|
1265
|
-
* ```
|
|
1266
|
-
*
|
|
1267
|
-
* @param args - Arguments.
|
|
1268
|
-
* @returns The call.
|
|
1269
|
-
*/
|
|
1270
|
-
function call(args) {
|
|
1271
|
-
const { to, amount, memo, token } = args;
|
|
1272
|
-
const callArgs = memo
|
|
1273
|
-
? {
|
|
1274
|
-
functionName: 'mintWithMemo',
|
|
1275
|
-
args: [to, amount, Hex.padLeft(memo, 32)],
|
|
1276
|
-
}
|
|
1277
|
-
: {
|
|
1278
|
-
functionName: 'mint',
|
|
1279
|
-
args: [to, amount],
|
|
1280
|
-
};
|
|
1281
|
-
return defineCall({
|
|
1282
|
-
address: TokenId.toAddress(token),
|
|
1283
|
-
abi: Abis.tip20,
|
|
1284
|
-
...callArgs,
|
|
1285
|
-
});
|
|
1286
|
-
}
|
|
1287
|
-
mint.call = call;
|
|
1288
|
-
/**
|
|
1289
|
-
* Extracts the event from the logs.
|
|
1290
|
-
*
|
|
1291
|
-
* @param logs - Logs.
|
|
1292
|
-
* @returns The event.
|
|
1293
|
-
*/
|
|
1294
|
-
function extractEvent(logs) {
|
|
1295
|
-
const [log] = parseEventLogs({
|
|
1296
|
-
abi: Abis.tip20,
|
|
1297
|
-
logs,
|
|
1298
|
-
eventName: 'Mint',
|
|
1299
|
-
});
|
|
1300
|
-
if (!log)
|
|
1301
|
-
throw new Error('`Mint` event not found.');
|
|
1302
|
-
return log;
|
|
1303
|
-
}
|
|
1304
|
-
mint.extractEvent = extractEvent;
|
|
1305
|
-
})(mint || (mint = {}));
|
|
1306
|
-
/**
|
|
1307
|
-
* Mints TIP20 tokens to an address.
|
|
1308
|
-
*
|
|
1309
|
-
* @example
|
|
1310
|
-
* ```ts
|
|
1311
|
-
* import { createClient, http } from 'viem'
|
|
1312
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1313
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1314
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1315
|
-
*
|
|
1316
|
-
* const client = createClient({
|
|
1317
|
-
* account: privateKeyToAccount('0x...'),
|
|
1318
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1319
|
-
* transport: http(),
|
|
1320
|
-
* })
|
|
1321
|
-
*
|
|
1322
|
-
* const result = await Actions.token.mintSync(client, {
|
|
1323
|
-
* to: '0x...',
|
|
1324
|
-
* amount: 100n,
|
|
1325
|
-
* token: '0x...',
|
|
1326
|
-
* })
|
|
1327
|
-
* ```
|
|
1328
|
-
*
|
|
1329
|
-
* @param client - Client.
|
|
1330
|
-
* @param parameters - Parameters.
|
|
1331
|
-
* @returns The transaction receipt and event data.
|
|
1332
|
-
*/
|
|
1333
|
-
export async function mintSync(client, parameters) {
|
|
1334
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
1335
|
-
const receipt = await mint.inner(writeContractSync, client, {
|
|
1336
|
-
...rest,
|
|
1337
|
-
throwOnReceiptRevert,
|
|
1338
|
-
});
|
|
1339
|
-
const { args } = mint.extractEvent(receipt.logs);
|
|
1340
|
-
return {
|
|
1341
|
-
...args,
|
|
1342
|
-
receipt,
|
|
1343
|
-
};
|
|
1344
|
-
}
|
|
1345
|
-
/**
|
|
1346
|
-
* Pauses a TIP20 token.
|
|
1347
|
-
*
|
|
1348
|
-
* @example
|
|
1349
|
-
* ```ts
|
|
1350
|
-
* import { createClient, http } from 'viem'
|
|
1351
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1352
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1353
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1354
|
-
*
|
|
1355
|
-
* const client = createClient({
|
|
1356
|
-
* account: privateKeyToAccount('0x...'),
|
|
1357
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1358
|
-
* transport: http(),
|
|
1359
|
-
* })
|
|
1360
|
-
*
|
|
1361
|
-
* const result = await Actions.token.pause(client, {
|
|
1362
|
-
* token: '0x...',
|
|
1363
|
-
* })
|
|
1364
|
-
* ```
|
|
1365
|
-
*
|
|
1366
|
-
* @param client - Client.
|
|
1367
|
-
* @param parameters - Parameters.
|
|
1368
|
-
* @returns The transaction hash.
|
|
1369
|
-
*/
|
|
1370
|
-
export async function pause(client, parameters) {
|
|
1371
|
-
return pause.inner(writeContract, client, parameters);
|
|
1372
|
-
}
|
|
1373
|
-
(function (pause) {
|
|
1374
|
-
/** @internal */
|
|
1375
|
-
async function inner(action, client, parameters) {
|
|
1376
|
-
const { token, ...rest } = parameters;
|
|
1377
|
-
const call = pause.call({ token });
|
|
1378
|
-
return (await action(client, {
|
|
1379
|
-
...rest,
|
|
1380
|
-
...call,
|
|
1381
|
-
}));
|
|
1382
|
-
}
|
|
1383
|
-
pause.inner = inner;
|
|
1384
|
-
/**
|
|
1385
|
-
* Defines a call to the `pause` function.
|
|
1386
|
-
*
|
|
1387
|
-
* Can be passed as a parameter to:
|
|
1388
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1389
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1390
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1391
|
-
*
|
|
1392
|
-
* @example
|
|
1393
|
-
* ```ts
|
|
1394
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
1395
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1396
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1397
|
-
*
|
|
1398
|
-
* const client = createClient({
|
|
1399
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1400
|
-
* transport: http(),
|
|
1401
|
-
* }).extend(walletActions)
|
|
1402
|
-
*
|
|
1403
|
-
* const { result } = await client.sendCalls({
|
|
1404
|
-
* calls: [
|
|
1405
|
-
* actions.token.pause.call({
|
|
1406
|
-
* token: '0x20c0...babe',
|
|
1407
|
-
* }),
|
|
1408
|
-
* ]
|
|
1409
|
-
* })
|
|
1410
|
-
* ```
|
|
1411
|
-
*
|
|
1412
|
-
* @param args - Arguments.
|
|
1413
|
-
* @returns The call.
|
|
1414
|
-
*/
|
|
1415
|
-
function call(args) {
|
|
1416
|
-
const { token } = args;
|
|
1417
|
-
return defineCall({
|
|
1418
|
-
address: TokenId.toAddress(token),
|
|
1419
|
-
abi: Abis.tip20,
|
|
1420
|
-
functionName: 'pause',
|
|
1421
|
-
args: [],
|
|
1422
|
-
});
|
|
1423
|
-
}
|
|
1424
|
-
pause.call = call;
|
|
1425
|
-
/**
|
|
1426
|
-
* Extracts the event from the logs.
|
|
1427
|
-
*
|
|
1428
|
-
* @param logs - Logs.
|
|
1429
|
-
* @returns The event.
|
|
1430
|
-
*/
|
|
1431
|
-
function extractEvent(logs) {
|
|
1432
|
-
const [log] = parseEventLogs({
|
|
1433
|
-
abi: Abis.tip20,
|
|
1434
|
-
logs,
|
|
1435
|
-
eventName: 'PauseStateUpdate',
|
|
1436
|
-
});
|
|
1437
|
-
if (!log)
|
|
1438
|
-
throw new Error('`PauseStateUpdate` event not found.');
|
|
1439
|
-
return log;
|
|
1440
|
-
}
|
|
1441
|
-
pause.extractEvent = extractEvent;
|
|
1442
|
-
})(pause || (pause = {}));
|
|
1443
|
-
/**
|
|
1444
|
-
* Pauses a TIP20 token.
|
|
1445
|
-
*
|
|
1446
|
-
* @example
|
|
1447
|
-
* ```ts
|
|
1448
|
-
* import { createClient, http } from 'viem'
|
|
1449
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1450
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1451
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1452
|
-
*
|
|
1453
|
-
* const client = createClient({
|
|
1454
|
-
* account: privateKeyToAccount('0x...'),
|
|
1455
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1456
|
-
* transport: http(),
|
|
1457
|
-
* })
|
|
1458
|
-
*
|
|
1459
|
-
* const result = await Actions.token.pauseSync(client, {
|
|
1460
|
-
* token: '0x...',
|
|
1461
|
-
* })
|
|
1462
|
-
* ```
|
|
1463
|
-
*
|
|
1464
|
-
* @param client - Client.
|
|
1465
|
-
* @param parameters - Parameters.
|
|
1466
|
-
* @returns The transaction receipt and event data.
|
|
1467
|
-
*/
|
|
1468
|
-
export async function pauseSync(client, parameters) {
|
|
1469
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
1470
|
-
const receipt = await pause.inner(writeContractSync, client, {
|
|
1471
|
-
...rest,
|
|
1472
|
-
throwOnReceiptRevert,
|
|
1473
|
-
});
|
|
1474
|
-
const { args } = pause.extractEvent(receipt.logs);
|
|
1475
|
-
return {
|
|
1476
|
-
...args,
|
|
1477
|
-
receipt,
|
|
1478
|
-
};
|
|
1479
|
-
}
|
|
1480
|
-
/**
|
|
1481
|
-
* Renounces a role for a TIP20 token.
|
|
1482
|
-
*
|
|
1483
|
-
* @example
|
|
1484
|
-
* ```ts
|
|
1485
|
-
* import { createClient, http } from 'viem'
|
|
1486
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1487
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1488
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1489
|
-
*
|
|
1490
|
-
* const client = createClient({
|
|
1491
|
-
* account: privateKeyToAccount('0x...'),
|
|
1492
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1493
|
-
* transport: http(),
|
|
1494
|
-
* })
|
|
1495
|
-
*
|
|
1496
|
-
* const result = await Actions.token.renounceRoles(client, {
|
|
1497
|
-
* token: '0x...',
|
|
1498
|
-
* roles: ['issuer'],
|
|
1499
|
-
* })
|
|
1500
|
-
* ```
|
|
1501
|
-
*
|
|
1502
|
-
* @param client - Client.
|
|
1503
|
-
* @param parameters - Parameters.
|
|
1504
|
-
* @returns The transaction hash.
|
|
1505
|
-
*/
|
|
1506
|
-
export async function renounceRoles(client, parameters) {
|
|
1507
|
-
return renounceRoles.inner(sendTransaction, client, parameters);
|
|
1508
|
-
}
|
|
1509
|
-
(function (renounceRoles) {
|
|
1510
|
-
/** @internal */
|
|
1511
|
-
async function inner(action, client, parameters) {
|
|
1512
|
-
return (await action(client, {
|
|
1513
|
-
...parameters,
|
|
1514
|
-
calls: parameters.roles.map((role) => {
|
|
1515
|
-
const call = renounceRoles.call({ ...parameters, role });
|
|
1516
|
-
return {
|
|
1517
|
-
...call,
|
|
1518
|
-
data: encodeFunctionData(call),
|
|
1519
|
-
};
|
|
1520
|
-
}),
|
|
1521
|
-
}));
|
|
1522
|
-
}
|
|
1523
|
-
renounceRoles.inner = inner;
|
|
1524
|
-
/**
|
|
1525
|
-
* Defines a call to the `renounceRole` function.
|
|
1526
|
-
*
|
|
1527
|
-
* Can be passed as a parameter to:
|
|
1528
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1529
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1530
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1531
|
-
*
|
|
1532
|
-
* @example
|
|
1533
|
-
* ```ts
|
|
1534
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
1535
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1536
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1537
|
-
*
|
|
1538
|
-
* const client = createClient({
|
|
1539
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1540
|
-
* transport: http(),
|
|
1541
|
-
* }).extend(walletActions)
|
|
1542
|
-
*
|
|
1543
|
-
* const { result } = await client.sendCalls({
|
|
1544
|
-
* calls: [
|
|
1545
|
-
* actions.token.renounceRoles.call({
|
|
1546
|
-
* token: '0x20c0...babe',
|
|
1547
|
-
* role: 'issuer',
|
|
1548
|
-
* }),
|
|
1549
|
-
* ]
|
|
1550
|
-
* })
|
|
1551
|
-
* ```
|
|
1552
|
-
*
|
|
1553
|
-
* @param args - Arguments.
|
|
1554
|
-
* @returns The call.
|
|
1555
|
-
*/
|
|
1556
|
-
function call(args) {
|
|
1557
|
-
const { token, role } = args;
|
|
1558
|
-
const roleHash = TokenRole.serialize(role);
|
|
1559
|
-
return defineCall({
|
|
1560
|
-
address: TokenId.toAddress(token),
|
|
1561
|
-
abi: Abis.tip20,
|
|
1562
|
-
functionName: 'renounceRole',
|
|
1563
|
-
args: [roleHash],
|
|
1564
|
-
});
|
|
1565
|
-
}
|
|
1566
|
-
renounceRoles.call = call;
|
|
1567
|
-
/**
|
|
1568
|
-
* Extracts the events from the logs.
|
|
1569
|
-
*
|
|
1570
|
-
* @param logs - Logs.
|
|
1571
|
-
* @returns The events.
|
|
1572
|
-
*/
|
|
1573
|
-
function extractEvents(logs) {
|
|
1574
|
-
const events = parseEventLogs({
|
|
1575
|
-
abi: Abis.tip20,
|
|
1576
|
-
logs,
|
|
1577
|
-
eventName: 'RoleMembershipUpdated',
|
|
1578
|
-
});
|
|
1579
|
-
if (events.length === 0)
|
|
1580
|
-
throw new Error('`RoleMembershipUpdated` events not found.');
|
|
1581
|
-
return events;
|
|
1582
|
-
}
|
|
1583
|
-
renounceRoles.extractEvents = extractEvents;
|
|
1584
|
-
})(renounceRoles || (renounceRoles = {}));
|
|
1585
|
-
/**
|
|
1586
|
-
* Renounces a role for a TIP20 token.
|
|
1587
|
-
*
|
|
1588
|
-
* @example
|
|
1589
|
-
* ```ts
|
|
1590
|
-
* import { createClient, http } from 'viem'
|
|
1591
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1592
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1593
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1594
|
-
*
|
|
1595
|
-
* const client = createClient({
|
|
1596
|
-
* account: privateKeyToAccount('0x...'),
|
|
1597
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1598
|
-
* transport: http(),
|
|
1599
|
-
* })
|
|
1600
|
-
*
|
|
1601
|
-
* const result = await Actions.token.renounceRolesSync(client, {
|
|
1602
|
-
* token: '0x...',
|
|
1603
|
-
* roles: ['issuer'],
|
|
1604
|
-
* })
|
|
1605
|
-
* ```
|
|
1606
|
-
*
|
|
1607
|
-
* @param client - Client.
|
|
1608
|
-
* @param parameters - Parameters.
|
|
1609
|
-
* @returns The transaction receipt and event data.
|
|
1610
|
-
*/
|
|
1611
|
-
export async function renounceRolesSync(client, parameters) {
|
|
1612
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
1613
|
-
const receipt = await renounceRoles.inner(sendTransactionSync, client, {
|
|
1614
|
-
...rest,
|
|
1615
|
-
throwOnReceiptRevert,
|
|
1616
|
-
});
|
|
1617
|
-
const events = renounceRoles.extractEvents(receipt.logs);
|
|
1618
|
-
const value = events.map((event) => event.args);
|
|
1619
|
-
return {
|
|
1620
|
-
receipt,
|
|
1621
|
-
value,
|
|
1622
|
-
};
|
|
1623
|
-
}
|
|
1624
|
-
/**
|
|
1625
|
-
* Revokes a role for a TIP20 token.
|
|
1626
|
-
*
|
|
1627
|
-
* @example
|
|
1628
|
-
* ```ts
|
|
1629
|
-
* import { createClient, http } from 'viem'
|
|
1630
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1631
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1632
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1633
|
-
*
|
|
1634
|
-
* const client = createClient({
|
|
1635
|
-
* account: privateKeyToAccount('0x...'),
|
|
1636
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1637
|
-
* transport: http(),
|
|
1638
|
-
* })
|
|
1639
|
-
*
|
|
1640
|
-
* const result = await Actions.token.revokeRoles(client, {
|
|
1641
|
-
* token: '0x...',
|
|
1642
|
-
* from: '0x...',
|
|
1643
|
-
* roles: ['issuer'],
|
|
1644
|
-
* })
|
|
1645
|
-
* ```
|
|
1646
|
-
*
|
|
1647
|
-
* @param client - Client.
|
|
1648
|
-
* @param parameters - Parameters.
|
|
1649
|
-
* @returns The transaction hash.
|
|
1650
|
-
*/
|
|
1651
|
-
export async function revokeRoles(client, parameters) {
|
|
1652
|
-
return revokeRoles.inner(sendTransaction, client, parameters);
|
|
1653
|
-
}
|
|
1654
|
-
(function (revokeRoles) {
|
|
1655
|
-
/** @internal */
|
|
1656
|
-
async function inner(action, client, parameters) {
|
|
1657
|
-
return (await action(client, {
|
|
1658
|
-
...parameters,
|
|
1659
|
-
calls: parameters.roles.map((role) => {
|
|
1660
|
-
const call = revokeRoles.call({ ...parameters, role });
|
|
1661
|
-
return {
|
|
1662
|
-
...call,
|
|
1663
|
-
data: encodeFunctionData(call),
|
|
1664
|
-
};
|
|
1665
|
-
}),
|
|
1666
|
-
}));
|
|
1667
|
-
}
|
|
1668
|
-
revokeRoles.inner = inner;
|
|
1669
|
-
/**
|
|
1670
|
-
* Defines a call to the `revokeRole` function.
|
|
1671
|
-
*
|
|
1672
|
-
* Can be passed as a parameter to:
|
|
1673
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1674
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1675
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1676
|
-
*
|
|
1677
|
-
* @example
|
|
1678
|
-
* ```ts
|
|
1679
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
1680
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1681
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1682
|
-
*
|
|
1683
|
-
* const client = createClient({
|
|
1684
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1685
|
-
* transport: http(),
|
|
1686
|
-
* }).extend(walletActions)
|
|
1687
|
-
*
|
|
1688
|
-
* const { result } = await client.sendCalls({
|
|
1689
|
-
* calls: [
|
|
1690
|
-
* actions.token.revokeRoles.call({
|
|
1691
|
-
* token: '0x20c0...babe',
|
|
1692
|
-
* from: '0x20c0...beef',
|
|
1693
|
-
* role: 'issuer',
|
|
1694
|
-
* }),
|
|
1695
|
-
* ]
|
|
1696
|
-
* })
|
|
1697
|
-
* ```
|
|
1698
|
-
*
|
|
1699
|
-
* @param args - Arguments.
|
|
1700
|
-
* @returns The call.
|
|
1701
|
-
*/
|
|
1702
|
-
function call(args) {
|
|
1703
|
-
const { token, from, role } = args;
|
|
1704
|
-
const roleHash = TokenRole.serialize(role);
|
|
1705
|
-
return defineCall({
|
|
1706
|
-
address: TokenId.toAddress(token),
|
|
1707
|
-
abi: Abis.tip20,
|
|
1708
|
-
functionName: 'revokeRole',
|
|
1709
|
-
args: [roleHash, from],
|
|
1710
|
-
});
|
|
1711
|
-
}
|
|
1712
|
-
revokeRoles.call = call;
|
|
1713
|
-
/**
|
|
1714
|
-
* Extracts the events from the logs.
|
|
1715
|
-
*
|
|
1716
|
-
* @param logs - Logs.
|
|
1717
|
-
* @returns The events.
|
|
1718
|
-
*/
|
|
1719
|
-
function extractEvents(logs) {
|
|
1720
|
-
const events = parseEventLogs({
|
|
1721
|
-
abi: Abis.tip20,
|
|
1722
|
-
logs,
|
|
1723
|
-
eventName: 'RoleMembershipUpdated',
|
|
1724
|
-
});
|
|
1725
|
-
if (events.length === 0)
|
|
1726
|
-
throw new Error('`RoleMembershipUpdated` events not found.');
|
|
1727
|
-
return events;
|
|
1728
|
-
}
|
|
1729
|
-
revokeRoles.extractEvents = extractEvents;
|
|
1730
|
-
})(revokeRoles || (revokeRoles = {}));
|
|
1731
|
-
/**
|
|
1732
|
-
* Revokes a role for a TIP20 token.
|
|
1733
|
-
*
|
|
1734
|
-
* @example
|
|
1735
|
-
* ```ts
|
|
1736
|
-
* import { createClient, http } from 'viem'
|
|
1737
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1738
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1739
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1740
|
-
*
|
|
1741
|
-
* const client = createClient({
|
|
1742
|
-
* account: privateKeyToAccount('0x...'),
|
|
1743
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1744
|
-
* transport: http(),
|
|
1745
|
-
* })
|
|
1746
|
-
*
|
|
1747
|
-
* const result = await Actions.token.revokeRolesSync(client, {
|
|
1748
|
-
* token: '0x...',
|
|
1749
|
-
* from: '0x...',
|
|
1750
|
-
* roles: ['issuer'],
|
|
1751
|
-
* })
|
|
1752
|
-
* ```
|
|
1753
|
-
*
|
|
1754
|
-
* @param client - Client.
|
|
1755
|
-
* @param parameters - Parameters.
|
|
1756
|
-
* @returns The transaction receipt and event data.
|
|
1757
|
-
*/
|
|
1758
|
-
export async function revokeRolesSync(client, parameters) {
|
|
1759
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
1760
|
-
const receipt = await revokeRoles.inner(sendTransactionSync, client, {
|
|
1761
|
-
...rest,
|
|
1762
|
-
throwOnReceiptRevert,
|
|
1763
|
-
});
|
|
1764
|
-
const events = revokeRoles.extractEvents(receipt.logs);
|
|
1765
|
-
const value = events.map((event) => event.args);
|
|
1766
|
-
return {
|
|
1767
|
-
receipt,
|
|
1768
|
-
value,
|
|
1769
|
-
};
|
|
1770
|
-
}
|
|
1771
|
-
/**
|
|
1772
|
-
* Sets the supply cap for a TIP20 token.
|
|
1773
|
-
*
|
|
1774
|
-
* @example
|
|
1775
|
-
* ```ts
|
|
1776
|
-
* import { createClient, http } from 'viem'
|
|
1777
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1778
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1779
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1780
|
-
*
|
|
1781
|
-
* const client = createClient({
|
|
1782
|
-
* account: privateKeyToAccount('0x...'),
|
|
1783
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1784
|
-
* transport: http(),
|
|
1785
|
-
* })
|
|
1786
|
-
*
|
|
1787
|
-
* const result = await Actions.token.setSupplyCap(client, {
|
|
1788
|
-
* token: '0x...',
|
|
1789
|
-
* supplyCap: 1000000n,
|
|
1790
|
-
* })
|
|
1791
|
-
* ```
|
|
1792
|
-
*
|
|
1793
|
-
* @param client - Client.
|
|
1794
|
-
* @param parameters - Parameters.
|
|
1795
|
-
* @returns The transaction hash.
|
|
1796
|
-
*/
|
|
1797
|
-
export async function setSupplyCap(client, parameters) {
|
|
1798
|
-
return setSupplyCap.inner(writeContract, client, parameters);
|
|
1799
|
-
}
|
|
1800
|
-
(function (setSupplyCap) {
|
|
1801
|
-
/** @internal */
|
|
1802
|
-
async function inner(action, client, parameters) {
|
|
1803
|
-
const { supplyCap, token, ...rest } = parameters;
|
|
1804
|
-
const call = setSupplyCap.call({ supplyCap, token });
|
|
1805
|
-
return (await action(client, {
|
|
1806
|
-
...rest,
|
|
1807
|
-
...call,
|
|
1808
|
-
}));
|
|
1809
|
-
}
|
|
1810
|
-
setSupplyCap.inner = inner;
|
|
1811
|
-
/**
|
|
1812
|
-
* Defines a call to the `setSupplyCap` function.
|
|
1813
|
-
*
|
|
1814
|
-
* Can be passed as a parameter to:
|
|
1815
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1816
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1817
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1818
|
-
*
|
|
1819
|
-
* @example
|
|
1820
|
-
* ```ts
|
|
1821
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
1822
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1823
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1824
|
-
*
|
|
1825
|
-
* const client = createClient({
|
|
1826
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1827
|
-
* transport: http(),
|
|
1828
|
-
* }).extend(walletActions)
|
|
1829
|
-
*
|
|
1830
|
-
* const { result } = await client.sendCalls({
|
|
1831
|
-
* calls: [
|
|
1832
|
-
* actions.token.setSupplyCap.call({
|
|
1833
|
-
* token: '0x20c0...babe',
|
|
1834
|
-
* supplyCap: 1000000n,
|
|
1835
|
-
* }),
|
|
1836
|
-
* ]
|
|
1837
|
-
* })
|
|
1838
|
-
* ```
|
|
1839
|
-
*
|
|
1840
|
-
* @param args - Arguments.
|
|
1841
|
-
* @returns The call.
|
|
1842
|
-
*/
|
|
1843
|
-
function call(args) {
|
|
1844
|
-
const { token, supplyCap } = args;
|
|
1845
|
-
return defineCall({
|
|
1846
|
-
address: TokenId.toAddress(token),
|
|
1847
|
-
abi: Abis.tip20,
|
|
1848
|
-
functionName: 'setSupplyCap',
|
|
1849
|
-
args: [supplyCap],
|
|
1850
|
-
});
|
|
1851
|
-
}
|
|
1852
|
-
setSupplyCap.call = call;
|
|
1853
|
-
/**
|
|
1854
|
-
* Extracts the event from the logs.
|
|
1855
|
-
*
|
|
1856
|
-
* @param logs - Logs.
|
|
1857
|
-
* @returns The event.
|
|
1858
|
-
*/
|
|
1859
|
-
function extractEvent(logs) {
|
|
1860
|
-
const [log] = parseEventLogs({
|
|
1861
|
-
abi: Abis.tip20,
|
|
1862
|
-
logs,
|
|
1863
|
-
eventName: 'SupplyCapUpdate',
|
|
1864
|
-
});
|
|
1865
|
-
if (!log)
|
|
1866
|
-
throw new Error('`SupplyCapUpdate` event not found.');
|
|
1867
|
-
return log;
|
|
1868
|
-
}
|
|
1869
|
-
setSupplyCap.extractEvent = extractEvent;
|
|
1870
|
-
})(setSupplyCap || (setSupplyCap = {}));
|
|
1871
|
-
/**
|
|
1872
|
-
* Sets the supply cap for a TIP20 token.
|
|
1873
|
-
*
|
|
1874
|
-
* @example
|
|
1875
|
-
* ```ts
|
|
1876
|
-
* import { createClient, http } from 'viem'
|
|
1877
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1878
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1879
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1880
|
-
*
|
|
1881
|
-
* const client = createClient({
|
|
1882
|
-
* account: privateKeyToAccount('0x...'),
|
|
1883
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1884
|
-
* transport: http(),
|
|
1885
|
-
* })
|
|
1886
|
-
*
|
|
1887
|
-
* const result = await Actions.token.setSupplyCapSync(client, {
|
|
1888
|
-
* token: '0x...',
|
|
1889
|
-
* supplyCap: 1000000n,
|
|
1890
|
-
* })
|
|
1891
|
-
* ```
|
|
1892
|
-
*
|
|
1893
|
-
* @param client - Client.
|
|
1894
|
-
* @param parameters - Parameters.
|
|
1895
|
-
* @returns The transaction receipt and event data.
|
|
1896
|
-
*/
|
|
1897
|
-
export async function setSupplyCapSync(client, parameters) {
|
|
1898
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
1899
|
-
const receipt = await setSupplyCap.inner(writeContractSync, client, {
|
|
1900
|
-
...rest,
|
|
1901
|
-
throwOnReceiptRevert,
|
|
1902
|
-
});
|
|
1903
|
-
const { args } = setSupplyCap.extractEvent(receipt.logs);
|
|
1904
|
-
return {
|
|
1905
|
-
...args,
|
|
1906
|
-
receipt,
|
|
1907
|
-
};
|
|
1908
|
-
}
|
|
1909
|
-
/**
|
|
1910
|
-
* Sets the admin role for a specific role in a TIP20 token.
|
|
1911
|
-
*
|
|
1912
|
-
* @example
|
|
1913
|
-
* ```ts
|
|
1914
|
-
* import { createClient, http } from 'viem'
|
|
1915
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1916
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1917
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
1918
|
-
*
|
|
1919
|
-
* const client = createClient({
|
|
1920
|
-
* account: privateKeyToAccount('0x...'),
|
|
1921
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1922
|
-
* transport: http(),
|
|
1923
|
-
* })
|
|
1924
|
-
*
|
|
1925
|
-
* const result = await Actions.token.setRoleAdmin(client, {
|
|
1926
|
-
* token: '0x...',
|
|
1927
|
-
* role: 'issuer',
|
|
1928
|
-
* adminRole: 'admin',
|
|
1929
|
-
* })
|
|
1930
|
-
* ```
|
|
1931
|
-
*
|
|
1932
|
-
* @param client - Client.
|
|
1933
|
-
* @param parameters - Parameters.
|
|
1934
|
-
* @returns The transaction hash.
|
|
1935
|
-
*/
|
|
1936
|
-
export async function setRoleAdmin(client, parameters) {
|
|
1937
|
-
return setRoleAdmin.inner(writeContract, client, parameters);
|
|
1938
|
-
}
|
|
1939
|
-
(function (setRoleAdmin) {
|
|
1940
|
-
/** @internal */
|
|
1941
|
-
async function inner(action, client, parameters) {
|
|
1942
|
-
const { adminRole, role, token, ...rest } = parameters;
|
|
1943
|
-
const call = setRoleAdmin.call({ adminRole, role, token });
|
|
1944
|
-
return (await action(client, {
|
|
1945
|
-
...rest,
|
|
1946
|
-
...call,
|
|
1947
|
-
}));
|
|
1948
|
-
}
|
|
1949
|
-
setRoleAdmin.inner = inner;
|
|
1950
|
-
/**
|
|
1951
|
-
* Defines a call to the `setRoleAdmin` function.
|
|
1952
|
-
*
|
|
1953
|
-
* Can be passed as a parameter to:
|
|
1954
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
1955
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
1956
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
1957
|
-
*
|
|
1958
|
-
* @example
|
|
1959
|
-
* ```ts
|
|
1960
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
1961
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
1962
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
1963
|
-
*
|
|
1964
|
-
* const client = createClient({
|
|
1965
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
1966
|
-
* transport: http(),
|
|
1967
|
-
* }).extend(walletActions)
|
|
1968
|
-
*
|
|
1969
|
-
* const { result } = await client.sendCalls({
|
|
1970
|
-
* calls: [
|
|
1971
|
-
* actions.token.setRoleAdmin.call({
|
|
1972
|
-
* token: '0x20c0...babe',
|
|
1973
|
-
* role: 'issuer',
|
|
1974
|
-
* adminRole: 'admin',
|
|
1975
|
-
* }),
|
|
1976
|
-
* ]
|
|
1977
|
-
* })
|
|
1978
|
-
* ```
|
|
1979
|
-
*
|
|
1980
|
-
* @param args - Arguments.
|
|
1981
|
-
* @returns The call.
|
|
1982
|
-
*/
|
|
1983
|
-
function call(args) {
|
|
1984
|
-
const { token, role, adminRole } = args;
|
|
1985
|
-
const roleHash = TokenRole.serialize(role);
|
|
1986
|
-
const adminRoleHash = TokenRole.serialize(adminRole);
|
|
1987
|
-
return defineCall({
|
|
1988
|
-
address: TokenId.toAddress(token),
|
|
1989
|
-
abi: Abis.tip20,
|
|
1990
|
-
functionName: 'setRoleAdmin',
|
|
1991
|
-
args: [roleHash, adminRoleHash],
|
|
1992
|
-
});
|
|
1993
|
-
}
|
|
1994
|
-
setRoleAdmin.call = call;
|
|
1995
|
-
/**
|
|
1996
|
-
* Extracts the event from the logs.
|
|
1997
|
-
*
|
|
1998
|
-
* @param logs - Logs.
|
|
1999
|
-
* @returns The event.
|
|
2000
|
-
*/
|
|
2001
|
-
function extractEvent(logs) {
|
|
2002
|
-
const [log] = parseEventLogs({
|
|
2003
|
-
abi: Abis.tip20,
|
|
2004
|
-
logs,
|
|
2005
|
-
eventName: 'RoleAdminUpdated',
|
|
2006
|
-
});
|
|
2007
|
-
if (!log)
|
|
2008
|
-
throw new Error('`RoleAdminUpdated` event not found.');
|
|
2009
|
-
return log;
|
|
2010
|
-
}
|
|
2011
|
-
setRoleAdmin.extractEvent = extractEvent;
|
|
2012
|
-
})(setRoleAdmin || (setRoleAdmin = {}));
|
|
2013
|
-
/**
|
|
2014
|
-
* Sets the admin role for a specific role in a TIP20 token.
|
|
2015
|
-
*
|
|
2016
|
-
* @example
|
|
2017
|
-
* ```ts
|
|
2018
|
-
* import { createClient, http } from 'viem'
|
|
2019
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2020
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2021
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2022
|
-
*
|
|
2023
|
-
* const client = createClient({
|
|
2024
|
-
* account: privateKeyToAccount('0x...'),
|
|
2025
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2026
|
-
* transport: http(),
|
|
2027
|
-
* })
|
|
2028
|
-
*
|
|
2029
|
-
* const result = await Actions.token.setRoleAdminSync(client, {
|
|
2030
|
-
* token: '0x...',
|
|
2031
|
-
* role: 'issuer',
|
|
2032
|
-
* adminRole: 'admin',
|
|
2033
|
-
* })
|
|
2034
|
-
* ```
|
|
2035
|
-
*
|
|
2036
|
-
* @param client - Client.
|
|
2037
|
-
* @param parameters - Parameters.
|
|
2038
|
-
* @returns The transaction receipt and event data.
|
|
2039
|
-
*/
|
|
2040
|
-
export async function setRoleAdminSync(client, parameters) {
|
|
2041
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
2042
|
-
const receipt = await setRoleAdmin.inner(writeContractSync, client, {
|
|
2043
|
-
...rest,
|
|
2044
|
-
throwOnReceiptRevert,
|
|
2045
|
-
});
|
|
2046
|
-
const { args } = setRoleAdmin.extractEvent(receipt.logs);
|
|
2047
|
-
return {
|
|
2048
|
-
...args,
|
|
2049
|
-
receipt,
|
|
2050
|
-
};
|
|
2051
|
-
}
|
|
2052
|
-
/**
|
|
2053
|
-
* Transfers TIP20 tokens to another address.
|
|
2054
|
-
*
|
|
2055
|
-
* @example
|
|
2056
|
-
* ```ts
|
|
2057
|
-
* import { createClient, http } from 'viem'
|
|
2058
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2059
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2060
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2061
|
-
*
|
|
2062
|
-
* const client = createClient({
|
|
2063
|
-
* account: privateKeyToAccount('0x...'),
|
|
2064
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2065
|
-
* transport: http(),
|
|
2066
|
-
* })
|
|
2067
|
-
*
|
|
2068
|
-
* const result = await Actions.token.transfer(client, {
|
|
2069
|
-
* to: '0x...',
|
|
2070
|
-
* amount: 100n,
|
|
2071
|
-
* })
|
|
2072
|
-
* ```
|
|
2073
|
-
*
|
|
2074
|
-
* @param client - Client.
|
|
2075
|
-
* @param parameters - Parameters.
|
|
2076
|
-
* @returns The transaction hash.
|
|
2077
|
-
*/
|
|
2078
|
-
export async function transfer(client, parameters) {
|
|
2079
|
-
return transfer.inner(writeContract, client, parameters);
|
|
2080
|
-
}
|
|
2081
|
-
(function (transfer) {
|
|
2082
|
-
/** @internal */
|
|
2083
|
-
async function inner(action, client, parameters) {
|
|
2084
|
-
const { amount, from, memo, token, to, ...rest } = parameters;
|
|
2085
|
-
const call = transfer.call({ amount, from, memo, token, to });
|
|
2086
|
-
return (await action(client, {
|
|
2087
|
-
...rest,
|
|
2088
|
-
...call,
|
|
2089
|
-
}));
|
|
2090
|
-
}
|
|
2091
|
-
transfer.inner = inner;
|
|
2092
|
-
/**
|
|
2093
|
-
* Defines a call to the `transfer`, `transferFrom`, `transferWithMemo`, or `transferFromWithMemo` function.
|
|
2094
|
-
*
|
|
2095
|
-
* Can be passed as a parameter to:
|
|
2096
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
2097
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
2098
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
2099
|
-
*
|
|
2100
|
-
* @example
|
|
2101
|
-
* ```ts
|
|
2102
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
2103
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2104
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2105
|
-
*
|
|
2106
|
-
* const client = createClient({
|
|
2107
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2108
|
-
* transport: http(),
|
|
2109
|
-
* }).extend(walletActions)
|
|
2110
|
-
*
|
|
2111
|
-
* const { result } = await client.sendCalls({
|
|
2112
|
-
* calls: [
|
|
2113
|
-
* actions.token.transfer.call({
|
|
2114
|
-
* to: '0x20c0...beef',
|
|
2115
|
-
* amount: 100n,
|
|
2116
|
-
* token: '0x20c0...babe',
|
|
2117
|
-
* }),
|
|
2118
|
-
* ]
|
|
2119
|
-
* })
|
|
2120
|
-
* ```
|
|
2121
|
-
*
|
|
2122
|
-
* @param args - Arguments.
|
|
2123
|
-
* @returns The call.
|
|
2124
|
-
*/
|
|
2125
|
-
function call(args) {
|
|
2126
|
-
const { amount, from, memo, token, to } = args;
|
|
2127
|
-
const callArgs = (() => {
|
|
2128
|
-
if (memo && from)
|
|
2129
|
-
return {
|
|
2130
|
-
functionName: 'transferFromWithMemo',
|
|
2131
|
-
args: [from, to, amount, Hex.padLeft(memo, 32)],
|
|
2132
|
-
};
|
|
2133
|
-
if (memo)
|
|
2134
|
-
return {
|
|
2135
|
-
functionName: 'transferWithMemo',
|
|
2136
|
-
args: [to, amount, Hex.padLeft(memo, 32)],
|
|
2137
|
-
};
|
|
2138
|
-
if (from)
|
|
2139
|
-
return {
|
|
2140
|
-
functionName: 'transferFrom',
|
|
2141
|
-
args: [from, to, amount],
|
|
2142
|
-
};
|
|
2143
|
-
return {
|
|
2144
|
-
functionName: 'transfer',
|
|
2145
|
-
args: [to, amount],
|
|
2146
|
-
};
|
|
2147
|
-
})();
|
|
2148
|
-
return defineCall({
|
|
2149
|
-
address: TokenId.toAddress(token),
|
|
2150
|
-
abi: Abis.tip20,
|
|
2151
|
-
...callArgs,
|
|
2152
|
-
});
|
|
2153
|
-
}
|
|
2154
|
-
transfer.call = call;
|
|
2155
|
-
/**
|
|
2156
|
-
* Extracts the event from the logs.
|
|
2157
|
-
*
|
|
2158
|
-
* @param logs - Logs.
|
|
2159
|
-
* @returns The event.
|
|
2160
|
-
*/
|
|
2161
|
-
function extractEvent(logs) {
|
|
2162
|
-
const [log] = parseEventLogs({
|
|
2163
|
-
abi: Abis.tip20,
|
|
2164
|
-
logs,
|
|
2165
|
-
eventName: 'Transfer',
|
|
2166
|
-
});
|
|
2167
|
-
if (!log)
|
|
2168
|
-
throw new Error('`Transfer` event not found.');
|
|
2169
|
-
return log;
|
|
2170
|
-
}
|
|
2171
|
-
transfer.extractEvent = extractEvent;
|
|
2172
|
-
})(transfer || (transfer = {}));
|
|
2173
|
-
/**
|
|
2174
|
-
* Transfers TIP20 tokens to another address.
|
|
2175
|
-
*
|
|
2176
|
-
* @example
|
|
2177
|
-
* ```ts
|
|
2178
|
-
* import { createClient, http } from 'viem'
|
|
2179
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2180
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2181
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2182
|
-
*
|
|
2183
|
-
* const client = createClient({
|
|
2184
|
-
* account: privateKeyToAccount('0x...'),
|
|
2185
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2186
|
-
* transport: http(),
|
|
2187
|
-
* })
|
|
2188
|
-
*
|
|
2189
|
-
* const result = await Actions.token.transferSync(client, {
|
|
2190
|
-
* to: '0x...',
|
|
2191
|
-
* amount: 100n,
|
|
2192
|
-
* })
|
|
2193
|
-
* ```
|
|
2194
|
-
*
|
|
2195
|
-
* @param client - Client.
|
|
2196
|
-
* @param parameters - Parameters.
|
|
2197
|
-
* @returns The transaction receipt and event data.
|
|
2198
|
-
*/
|
|
2199
|
-
export async function transferSync(client, parameters) {
|
|
2200
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
2201
|
-
const receipt = await transfer.inner(writeContractSync, client, {
|
|
2202
|
-
...rest,
|
|
2203
|
-
throwOnReceiptRevert,
|
|
2204
|
-
});
|
|
2205
|
-
const { args } = transfer.extractEvent(receipt.logs);
|
|
2206
|
-
return {
|
|
2207
|
-
...args,
|
|
2208
|
-
receipt,
|
|
2209
|
-
};
|
|
2210
|
-
}
|
|
2211
|
-
/**
|
|
2212
|
-
* Unpauses a TIP20 token.
|
|
2213
|
-
*
|
|
2214
|
-
* @example
|
|
2215
|
-
* ```ts
|
|
2216
|
-
* import { createClient, http } from 'viem'
|
|
2217
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2218
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2219
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2220
|
-
*
|
|
2221
|
-
* const client = createClient({
|
|
2222
|
-
* account: privateKeyToAccount('0x...'),
|
|
2223
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2224
|
-
* transport: http(),
|
|
2225
|
-
* })
|
|
2226
|
-
*
|
|
2227
|
-
* const result = await Actions.token.unpause(client, {
|
|
2228
|
-
* token: '0x...',
|
|
2229
|
-
* })
|
|
2230
|
-
* ```
|
|
2231
|
-
*
|
|
2232
|
-
* @param client - Client.
|
|
2233
|
-
* @param parameters - Parameters.
|
|
2234
|
-
* @returns The transaction hash.
|
|
2235
|
-
*/
|
|
2236
|
-
export async function unpause(client, parameters) {
|
|
2237
|
-
return unpause.inner(writeContract, client, parameters);
|
|
2238
|
-
}
|
|
2239
|
-
(function (unpause) {
|
|
2240
|
-
/** @internal */
|
|
2241
|
-
async function inner(action, client, parameters) {
|
|
2242
|
-
const { token, ...rest } = parameters;
|
|
2243
|
-
const call = unpause.call({ token });
|
|
2244
|
-
return (await action(client, {
|
|
2245
|
-
...rest,
|
|
2246
|
-
...call,
|
|
2247
|
-
}));
|
|
2248
|
-
}
|
|
2249
|
-
unpause.inner = inner;
|
|
2250
|
-
/**
|
|
2251
|
-
* Defines a call to the `unpause` function.
|
|
2252
|
-
*
|
|
2253
|
-
* Can be passed as a parameter to:
|
|
2254
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
2255
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
2256
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
2257
|
-
*
|
|
2258
|
-
* @example
|
|
2259
|
-
* ```ts
|
|
2260
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
2261
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2262
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2263
|
-
*
|
|
2264
|
-
* const client = createClient({
|
|
2265
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2266
|
-
* transport: http(),
|
|
2267
|
-
* }).extend(walletActions)
|
|
2268
|
-
*
|
|
2269
|
-
* const { result } = await client.sendCalls({
|
|
2270
|
-
* calls: [
|
|
2271
|
-
* actions.token.unpause.call({
|
|
2272
|
-
* token: '0x20c0...babe',
|
|
2273
|
-
* }),
|
|
2274
|
-
* ]
|
|
2275
|
-
* })
|
|
2276
|
-
* ```
|
|
2277
|
-
*
|
|
2278
|
-
* @param args - Arguments.
|
|
2279
|
-
* @returns The call.
|
|
2280
|
-
*/
|
|
2281
|
-
function call(args) {
|
|
2282
|
-
const { token } = args;
|
|
2283
|
-
return defineCall({
|
|
2284
|
-
address: TokenId.toAddress(token),
|
|
2285
|
-
abi: Abis.tip20,
|
|
2286
|
-
functionName: 'unpause',
|
|
2287
|
-
args: [],
|
|
2288
|
-
});
|
|
2289
|
-
}
|
|
2290
|
-
unpause.call = call;
|
|
2291
|
-
/**
|
|
2292
|
-
* Extracts the event from the logs.
|
|
2293
|
-
*
|
|
2294
|
-
* @param logs - Logs.
|
|
2295
|
-
* @returns The event.
|
|
2296
|
-
*/
|
|
2297
|
-
function extractEvent(logs) {
|
|
2298
|
-
const [log] = parseEventLogs({
|
|
2299
|
-
abi: Abis.tip20,
|
|
2300
|
-
logs,
|
|
2301
|
-
eventName: 'PauseStateUpdate',
|
|
2302
|
-
});
|
|
2303
|
-
if (!log)
|
|
2304
|
-
throw new Error('`PauseStateUpdate` event not found.');
|
|
2305
|
-
return log;
|
|
2306
|
-
}
|
|
2307
|
-
unpause.extractEvent = extractEvent;
|
|
2308
|
-
})(unpause || (unpause = {}));
|
|
2309
|
-
/**
|
|
2310
|
-
* Unpauses a TIP20 token.
|
|
2311
|
-
*
|
|
2312
|
-
* @example
|
|
2313
|
-
* ```ts
|
|
2314
|
-
* import { createClient, http } from 'viem'
|
|
2315
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2316
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2317
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2318
|
-
*
|
|
2319
|
-
* const client = createClient({
|
|
2320
|
-
* account: privateKeyToAccount('0x...'),
|
|
2321
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2322
|
-
* transport: http(),
|
|
2323
|
-
* })
|
|
2324
|
-
*
|
|
2325
|
-
* const result = await Actions.token.unpauseSync(client, {
|
|
2326
|
-
* token: '0x...',
|
|
2327
|
-
* })
|
|
2328
|
-
* ```
|
|
2329
|
-
*
|
|
2330
|
-
* @param client - Client.
|
|
2331
|
-
* @param parameters - Parameters.
|
|
2332
|
-
* @returns The transaction receipt and event data.
|
|
2333
|
-
*/
|
|
2334
|
-
export async function unpauseSync(client, parameters) {
|
|
2335
|
-
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
2336
|
-
const receipt = await unpause.inner(writeContractSync, client, {
|
|
2337
|
-
...rest,
|
|
2338
|
-
throwOnReceiptRevert,
|
|
2339
|
-
});
|
|
2340
|
-
const { args } = unpause.extractEvent(receipt.logs);
|
|
2341
|
-
return {
|
|
2342
|
-
...args,
|
|
2343
|
-
receipt,
|
|
2344
|
-
};
|
|
2345
|
-
}
|
|
2346
|
-
/**
|
|
2347
|
-
* Updates the quote token for a TIP20 token.
|
|
2348
|
-
*
|
|
2349
|
-
* @example
|
|
2350
|
-
* ```ts
|
|
2351
|
-
* import { createClient, http } from 'viem'
|
|
2352
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2353
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2354
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2355
|
-
*
|
|
2356
|
-
* const client = createClient({
|
|
2357
|
-
* account: privateKeyToAccount('0x...'),
|
|
2358
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2359
|
-
* transport: http(),
|
|
2360
|
-
* })
|
|
2361
|
-
*
|
|
2362
|
-
* const result = await Actions.token.prepareUpdateQuoteToken(client, {
|
|
2363
|
-
* token: '0x...',
|
|
2364
|
-
* quoteToken: '0x...',
|
|
2365
|
-
* })
|
|
2366
|
-
* ```
|
|
2367
|
-
*
|
|
2368
|
-
* @param client - Client.
|
|
2369
|
-
* @param parameters - Parameters.
|
|
2370
|
-
* @returns The transaction hash.
|
|
2371
|
-
*/
|
|
2372
|
-
export async function prepareUpdateQuoteToken(client, parameters) {
|
|
2373
|
-
return prepareUpdateQuoteToken.inner(writeContract, client, parameters);
|
|
2374
|
-
}
|
|
2375
|
-
(function (prepareUpdateQuoteToken) {
|
|
2376
|
-
/** @internal */
|
|
2377
|
-
async function inner(action, client, parameters) {
|
|
2378
|
-
const { quoteToken, token, ...rest } = parameters;
|
|
2379
|
-
const call = prepareUpdateQuoteToken.call({ quoteToken, token });
|
|
2380
|
-
return (await action(client, {
|
|
2381
|
-
...rest,
|
|
2382
|
-
...call,
|
|
2383
|
-
}));
|
|
2384
|
-
}
|
|
2385
|
-
prepareUpdateQuoteToken.inner = inner;
|
|
2386
|
-
/**
|
|
2387
|
-
* Defines a call to the `prepareUpdateQuoteToken` function.
|
|
2388
|
-
*
|
|
2389
|
-
* Can be passed as a parameter to:
|
|
2390
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
2391
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
2392
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
2393
|
-
*
|
|
2394
|
-
* @example
|
|
2395
|
-
* ```ts
|
|
2396
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
2397
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2398
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2399
|
-
*
|
|
2400
|
-
* const client = createClient({
|
|
2401
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2402
|
-
* transport: http(),
|
|
2403
|
-
* }).extend(walletActions)
|
|
2404
|
-
*
|
|
2405
|
-
* const { result } = await client.sendCalls({
|
|
2406
|
-
* calls: [
|
|
2407
|
-
* actions.token.prepareUpdateQuoteToken.call({
|
|
2408
|
-
* token: '0x20c0...babe',
|
|
2409
|
-
* quoteToken: '0x20c0...cafe',
|
|
2410
|
-
* }),
|
|
2411
|
-
* ]
|
|
2412
|
-
* })
|
|
2413
|
-
* ```
|
|
2414
|
-
*
|
|
2415
|
-
* @param args - Arguments.
|
|
2416
|
-
* @returns The call.
|
|
2417
|
-
*/
|
|
2418
|
-
function call(args) {
|
|
2419
|
-
const { token, quoteToken } = args;
|
|
2420
|
-
return defineCall({
|
|
2421
|
-
address: TokenId.toAddress(token),
|
|
2422
|
-
abi: Abis.tip20,
|
|
2423
|
-
functionName: 'setNextQuoteToken',
|
|
2424
|
-
args: [TokenId.toAddress(quoteToken)],
|
|
2425
|
-
});
|
|
2426
|
-
}
|
|
2427
|
-
prepareUpdateQuoteToken.call = call;
|
|
2428
|
-
/**
|
|
2429
|
-
* Extracts the event from the logs.
|
|
2430
|
-
*
|
|
2431
|
-
* @param logs - Logs.
|
|
2432
|
-
* @returns The event.
|
|
2433
|
-
*/
|
|
2434
|
-
function extractEvent(logs) {
|
|
2435
|
-
const [log] = parseEventLogs({
|
|
2436
|
-
abi: Abis.tip20,
|
|
2437
|
-
logs,
|
|
2438
|
-
eventName: 'NextQuoteTokenSet',
|
|
2439
|
-
});
|
|
2440
|
-
if (!log)
|
|
2441
|
-
throw new Error('`NextQuoteTokenSet` event not found.');
|
|
2442
|
-
return log;
|
|
2443
|
-
}
|
|
2444
|
-
prepareUpdateQuoteToken.extractEvent = extractEvent;
|
|
2445
|
-
})(prepareUpdateQuoteToken || (prepareUpdateQuoteToken = {}));
|
|
2446
|
-
/**
|
|
2447
|
-
* Updates the quote token for a TIP20 token.
|
|
2448
|
-
*
|
|
2449
|
-
* @example
|
|
2450
|
-
* ```ts
|
|
2451
|
-
* import { createClient, http } from 'viem'
|
|
2452
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2453
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2454
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2455
|
-
*
|
|
2456
|
-
* const client = createClient({
|
|
2457
|
-
* account: privateKeyToAccount('0x...'),
|
|
2458
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2459
|
-
* transport: http(),
|
|
2460
|
-
* })
|
|
2461
|
-
*
|
|
2462
|
-
* const result = await Actions.token.prepareUpdateQuoteTokenSync(client, {
|
|
2463
|
-
* token: '0x...',
|
|
2464
|
-
* quoteToken: '0x...',
|
|
2465
|
-
* })
|
|
2466
|
-
* ```
|
|
2467
|
-
*
|
|
2468
|
-
* @param client - Client.
|
|
2469
|
-
* @param parameters - Parameters.
|
|
2470
|
-
* @returns The transaction receipt and event data.
|
|
2471
|
-
*/
|
|
2472
|
-
export async function prepareUpdateQuoteTokenSync(client, parameters) {
|
|
2473
|
-
const receipt = await prepareUpdateQuoteToken.inner(writeContractSync, client, parameters);
|
|
2474
|
-
const { args } = prepareUpdateQuoteToken.extractEvent(receipt.logs);
|
|
2475
|
-
return {
|
|
2476
|
-
...args,
|
|
2477
|
-
receipt,
|
|
2478
|
-
};
|
|
2479
|
-
}
|
|
2480
|
-
/**
|
|
2481
|
-
* Updates the quote token for a TIP20 token.
|
|
2482
|
-
*
|
|
2483
|
-
* @example
|
|
2484
|
-
* ```ts
|
|
2485
|
-
* import { createClient, http } from 'viem'
|
|
2486
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2487
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2488
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2489
|
-
*
|
|
2490
|
-
* const client = createClient({
|
|
2491
|
-
* account: privateKeyToAccount('0x...'),
|
|
2492
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2493
|
-
* transport: http(),
|
|
2494
|
-
* })
|
|
2495
|
-
*
|
|
2496
|
-
* const result = await Actions.token.updateQuoteToken(client, {
|
|
2497
|
-
* token: '0x...',
|
|
2498
|
-
* })
|
|
2499
|
-
* ```
|
|
2500
|
-
*
|
|
2501
|
-
* @param client - Client.
|
|
2502
|
-
* @param parameters - Parameters.
|
|
2503
|
-
* @returns The transaction hash.
|
|
2504
|
-
*/
|
|
2505
|
-
export async function updateQuoteToken(client, parameters) {
|
|
2506
|
-
return updateQuoteToken.inner(writeContract, client, parameters);
|
|
2507
|
-
}
|
|
2508
|
-
(function (updateQuoteToken) {
|
|
2509
|
-
/** @internal */
|
|
2510
|
-
async function inner(action, client, parameters) {
|
|
2511
|
-
const { token, ...rest } = parameters;
|
|
2512
|
-
const call = updateQuoteToken.call({ token });
|
|
2513
|
-
return (await action(client, {
|
|
2514
|
-
...rest,
|
|
2515
|
-
...call,
|
|
2516
|
-
}));
|
|
2517
|
-
}
|
|
2518
|
-
updateQuoteToken.inner = inner;
|
|
2519
|
-
/**
|
|
2520
|
-
* Defines a call to the `updateQuoteToken` function.
|
|
2521
|
-
*
|
|
2522
|
-
* Can be passed as a parameter to:
|
|
2523
|
-
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
2524
|
-
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
2525
|
-
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
2526
|
-
*
|
|
2527
|
-
* @example
|
|
2528
|
-
* ```ts
|
|
2529
|
-
* import { createClient, http, walletActions } from 'viem'
|
|
2530
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2531
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2532
|
-
*
|
|
2533
|
-
* const client = createClient({
|
|
2534
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2535
|
-
* transport: http(),
|
|
2536
|
-
* }).extend(walletActions)
|
|
2537
|
-
*
|
|
2538
|
-
* const { result } = await client.sendCalls({
|
|
2539
|
-
* calls: [
|
|
2540
|
-
* actions.token.updateQuoteToken.call({
|
|
2541
|
-
* token: '0x20c0...babe',
|
|
2542
|
-
* }),
|
|
2543
|
-
* ]
|
|
2544
|
-
* })
|
|
2545
|
-
* ```
|
|
2546
|
-
*
|
|
2547
|
-
* @param args - Arguments.
|
|
2548
|
-
* @returns The call.
|
|
2549
|
-
*/
|
|
2550
|
-
function call(args) {
|
|
2551
|
-
const { token } = args;
|
|
2552
|
-
return defineCall({
|
|
2553
|
-
address: TokenId.toAddress(token),
|
|
2554
|
-
abi: Abis.tip20,
|
|
2555
|
-
functionName: 'completeQuoteTokenUpdate',
|
|
2556
|
-
args: [],
|
|
2557
|
-
});
|
|
2558
|
-
}
|
|
2559
|
-
updateQuoteToken.call = call;
|
|
2560
|
-
/**
|
|
2561
|
-
* Extracts the event from the logs.
|
|
2562
|
-
*
|
|
2563
|
-
* @param logs - Logs.
|
|
2564
|
-
* @returns The event.
|
|
2565
|
-
*/
|
|
2566
|
-
function extractEvent(logs) {
|
|
2567
|
-
const [log] = parseEventLogs({
|
|
2568
|
-
abi: Abis.tip20,
|
|
2569
|
-
logs,
|
|
2570
|
-
eventName: 'QuoteTokenUpdate',
|
|
2571
|
-
});
|
|
2572
|
-
if (!log)
|
|
2573
|
-
throw new Error('`QuoteTokenUpdateCompleted` event not found.');
|
|
2574
|
-
return log;
|
|
2575
|
-
}
|
|
2576
|
-
updateQuoteToken.extractEvent = extractEvent;
|
|
2577
|
-
})(updateQuoteToken || (updateQuoteToken = {}));
|
|
2578
|
-
/**
|
|
2579
|
-
* Updates the quote token for a TIP20 token.
|
|
2580
|
-
*
|
|
2581
|
-
* @example
|
|
2582
|
-
* ```ts
|
|
2583
|
-
* import { createClient, http } from 'viem'
|
|
2584
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2585
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2586
|
-
* import { privateKeyToAccount } from 'viem/accounts'
|
|
2587
|
-
*
|
|
2588
|
-
* const client = createClient({
|
|
2589
|
-
* account: privateKeyToAccount('0x...'),
|
|
2590
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2591
|
-
* transport: http(),
|
|
2592
|
-
* })
|
|
2593
|
-
*
|
|
2594
|
-
* const result = await Actions.token.updateQuoteTokenSync(client, {
|
|
2595
|
-
* token: '0x...',
|
|
2596
|
-
* })
|
|
2597
|
-
* ```
|
|
2598
|
-
*
|
|
2599
|
-
* @param client - Client.
|
|
2600
|
-
* @param parameters - Parameters.
|
|
2601
|
-
* @returns The transaction receipt and event data.
|
|
2602
|
-
*/
|
|
2603
|
-
export async function updateQuoteTokenSync(client, parameters) {
|
|
2604
|
-
const receipt = await updateQuoteToken.inner(writeContractSync, client, parameters);
|
|
2605
|
-
const { args } = updateQuoteToken.extractEvent(receipt.logs);
|
|
2606
|
-
return {
|
|
2607
|
-
...args,
|
|
2608
|
-
receipt,
|
|
2609
|
-
};
|
|
2610
|
-
}
|
|
2611
|
-
/**
|
|
2612
|
-
* Watches for TIP20 token approval events.
|
|
2613
|
-
*
|
|
2614
|
-
* @example
|
|
2615
|
-
* ```ts
|
|
2616
|
-
* import { createClient, http } from 'viem'
|
|
2617
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2618
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2619
|
-
*
|
|
2620
|
-
* const client = createClient({
|
|
2621
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2622
|
-
* transport: http(),
|
|
2623
|
-
* })
|
|
2624
|
-
*
|
|
2625
|
-
* const unwatch = actions.token.watchApprove(client, {
|
|
2626
|
-
* onApproval: (args, log) => {
|
|
2627
|
-
* console.log('Approval:', args)
|
|
2628
|
-
* },
|
|
2629
|
-
* })
|
|
2630
|
-
* ```
|
|
2631
|
-
*
|
|
2632
|
-
* @param client - Client.
|
|
2633
|
-
* @param parameters - Parameters.
|
|
2634
|
-
* @returns A function to unsubscribe from the event.
|
|
2635
|
-
*/
|
|
2636
|
-
export function watchApprove(client, parameters) {
|
|
2637
|
-
const { onApproval, token, ...rest } = parameters;
|
|
2638
|
-
return watchContractEvent(client, {
|
|
2639
|
-
...rest,
|
|
2640
|
-
address: TokenId.toAddress(token),
|
|
2641
|
-
abi: Abis.tip20,
|
|
2642
|
-
eventName: 'Approval',
|
|
2643
|
-
onLogs: (logs) => {
|
|
2644
|
-
for (const log of logs)
|
|
2645
|
-
onApproval(log.args, log);
|
|
2646
|
-
},
|
|
2647
|
-
strict: true,
|
|
2648
|
-
});
|
|
2649
|
-
}
|
|
2650
|
-
/**
|
|
2651
|
-
* Watches for TIP20 token burn events.
|
|
2652
|
-
*
|
|
2653
|
-
* @example
|
|
2654
|
-
* ```ts
|
|
2655
|
-
* import { createClient, http } from 'viem'
|
|
2656
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2657
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2658
|
-
*
|
|
2659
|
-
* const client = createClient({
|
|
2660
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2661
|
-
* transport: http(),
|
|
2662
|
-
* })
|
|
2663
|
-
*
|
|
2664
|
-
* const unwatch = actions.token.watchBurn(client, {
|
|
2665
|
-
* onBurn: (args, log) => {
|
|
2666
|
-
* console.log('Burn:', args)
|
|
2667
|
-
* },
|
|
2668
|
-
* })
|
|
2669
|
-
* ```
|
|
2670
|
-
*
|
|
2671
|
-
* @param client - Client.
|
|
2672
|
-
* @param parameters - Parameters.
|
|
2673
|
-
* @returns A function to unsubscribe from the event.
|
|
2674
|
-
*/
|
|
2675
|
-
export function watchBurn(client, parameters) {
|
|
2676
|
-
const { onBurn, token, ...rest } = parameters;
|
|
2677
|
-
return watchContractEvent(client, {
|
|
2678
|
-
...rest,
|
|
2679
|
-
address: TokenId.toAddress(token),
|
|
2680
|
-
abi: Abis.tip20,
|
|
2681
|
-
eventName: 'Burn',
|
|
2682
|
-
onLogs: (logs) => {
|
|
2683
|
-
for (const log of logs)
|
|
2684
|
-
onBurn(log.args, log);
|
|
2685
|
-
},
|
|
2686
|
-
strict: true,
|
|
2687
|
-
});
|
|
2688
|
-
}
|
|
2689
|
-
/**
|
|
2690
|
-
* Watches for new TIP20 tokens created.
|
|
2691
|
-
*
|
|
2692
|
-
* @example
|
|
2693
|
-
* ```ts
|
|
2694
|
-
* import { createClient, http } from 'viem'
|
|
2695
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2696
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2697
|
-
*
|
|
2698
|
-
* const client = createClient({
|
|
2699
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2700
|
-
* transport: http(),
|
|
2701
|
-
* })
|
|
2702
|
-
*
|
|
2703
|
-
* const unwatch = actions.token.watchCreate(client, {
|
|
2704
|
-
* onTokenCreated: (args, log) => {
|
|
2705
|
-
* console.log('Token created:', args)
|
|
2706
|
-
* },
|
|
2707
|
-
* })
|
|
2708
|
-
* ```
|
|
2709
|
-
*
|
|
2710
|
-
* @param client - Client.
|
|
2711
|
-
* @param parameters - Parameters.
|
|
2712
|
-
* @returns A function to unsubscribe from the event.
|
|
2713
|
-
*/
|
|
2714
|
-
export function watchCreate(client, parameters) {
|
|
2715
|
-
const { onTokenCreated, ...rest } = parameters;
|
|
2716
|
-
return watchContractEvent(client, {
|
|
2717
|
-
...rest,
|
|
2718
|
-
address: Addresses.tip20Factory,
|
|
2719
|
-
abi: Abis.tip20Factory,
|
|
2720
|
-
eventName: 'TokenCreated',
|
|
2721
|
-
onLogs: (logs) => {
|
|
2722
|
-
for (const log of logs)
|
|
2723
|
-
onTokenCreated(log.args, log);
|
|
2724
|
-
},
|
|
2725
|
-
strict: true,
|
|
2726
|
-
});
|
|
2727
|
-
}
|
|
2728
|
-
/**
|
|
2729
|
-
* Watches for TIP20 token mint events.
|
|
2730
|
-
*
|
|
2731
|
-
* @example
|
|
2732
|
-
* ```ts
|
|
2733
|
-
* import { createClient, http } from 'viem'
|
|
2734
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2735
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2736
|
-
*
|
|
2737
|
-
* const client = createClient({
|
|
2738
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2739
|
-
* transport: http(),
|
|
2740
|
-
* })
|
|
2741
|
-
*
|
|
2742
|
-
* const unwatch = actions.token.watchMint(client, {
|
|
2743
|
-
* onMint: (args, log) => {
|
|
2744
|
-
* console.log('Mint:', args)
|
|
2745
|
-
* },
|
|
2746
|
-
* })
|
|
2747
|
-
* ```
|
|
2748
|
-
*
|
|
2749
|
-
* @param client - Client.
|
|
2750
|
-
* @param parameters - Parameters.
|
|
2751
|
-
* @returns A function to unsubscribe from the event.
|
|
2752
|
-
*/
|
|
2753
|
-
export function watchMint(client, parameters) {
|
|
2754
|
-
const { onMint, token, ...rest } = parameters;
|
|
2755
|
-
return watchContractEvent(client, {
|
|
2756
|
-
...rest,
|
|
2757
|
-
address: TokenId.toAddress(token),
|
|
2758
|
-
abi: Abis.tip20,
|
|
2759
|
-
eventName: 'Mint',
|
|
2760
|
-
onLogs: (logs) => {
|
|
2761
|
-
for (const log of logs)
|
|
2762
|
-
onMint(log.args, log);
|
|
2763
|
-
},
|
|
2764
|
-
strict: true,
|
|
2765
|
-
});
|
|
2766
|
-
}
|
|
2767
|
-
/**
|
|
2768
|
-
* Watches for TIP20 token role admin updates.
|
|
2769
|
-
*
|
|
2770
|
-
* @example
|
|
2771
|
-
* ```ts
|
|
2772
|
-
* import { createClient, http } from 'viem'
|
|
2773
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2774
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2775
|
-
*
|
|
2776
|
-
* const client = createClient({
|
|
2777
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2778
|
-
* transport: http(),
|
|
2779
|
-
* })
|
|
2780
|
-
*
|
|
2781
|
-
* const unwatch = actions.token.watchAdminRole(client, {
|
|
2782
|
-
* onRoleAdminUpdated: (args, log) => {
|
|
2783
|
-
* console.log('Role admin updated:', args)
|
|
2784
|
-
* },
|
|
2785
|
-
* })
|
|
2786
|
-
* ```
|
|
2787
|
-
*
|
|
2788
|
-
* @param client - Client.
|
|
2789
|
-
* @param parameters - Parameters.
|
|
2790
|
-
* @returns A function to unsubscribe from the event.
|
|
2791
|
-
*/
|
|
2792
|
-
export function watchAdminRole(client, parameters) {
|
|
2793
|
-
const { onRoleAdminUpdated, token, ...rest } = parameters;
|
|
2794
|
-
return watchContractEvent(client, {
|
|
2795
|
-
...rest,
|
|
2796
|
-
address: TokenId.toAddress(token),
|
|
2797
|
-
abi: Abis.tip20,
|
|
2798
|
-
eventName: 'RoleAdminUpdated',
|
|
2799
|
-
onLogs: (logs) => {
|
|
2800
|
-
for (const log of logs)
|
|
2801
|
-
onRoleAdminUpdated(log.args, log);
|
|
2802
|
-
},
|
|
2803
|
-
strict: true,
|
|
2804
|
-
});
|
|
2805
|
-
}
|
|
2806
|
-
/**
|
|
2807
|
-
* Watches for TIP20 token role membership updates.
|
|
2808
|
-
*
|
|
2809
|
-
* @example
|
|
2810
|
-
* ```ts
|
|
2811
|
-
* import { createClient, http } from 'viem'
|
|
2812
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2813
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2814
|
-
*
|
|
2815
|
-
* const client = createClient({
|
|
2816
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2817
|
-
* transport: http(),
|
|
2818
|
-
* })
|
|
2819
|
-
*
|
|
2820
|
-
* const unwatch = actions.token.watchRole(client, {
|
|
2821
|
-
* onRoleUpdated: (args, log) => {
|
|
2822
|
-
* console.log('Role updated:', args)
|
|
2823
|
-
* },
|
|
2824
|
-
* })
|
|
2825
|
-
* ```
|
|
2826
|
-
*
|
|
2827
|
-
* @param client - Client.
|
|
2828
|
-
* @param parameters - Parameters.
|
|
2829
|
-
* @returns A function to unsubscribe from the event.
|
|
2830
|
-
*/
|
|
2831
|
-
export function watchRole(client, parameters) {
|
|
2832
|
-
const { onRoleUpdated, token, ...rest } = parameters;
|
|
2833
|
-
return watchContractEvent(client, {
|
|
2834
|
-
...rest,
|
|
2835
|
-
address: TokenId.toAddress(token),
|
|
2836
|
-
abi: Abis.tip20,
|
|
2837
|
-
eventName: 'RoleMembershipUpdated',
|
|
2838
|
-
onLogs: (logs) => {
|
|
2839
|
-
for (const log of logs) {
|
|
2840
|
-
const type = log.args.hasRole ? 'granted' : 'revoked';
|
|
2841
|
-
onRoleUpdated({ ...log.args, type }, log);
|
|
2842
|
-
}
|
|
2843
|
-
},
|
|
2844
|
-
strict: true,
|
|
2845
|
-
});
|
|
2846
|
-
}
|
|
2847
|
-
/**
|
|
2848
|
-
* Watches for TIP20 token transfer events.
|
|
2849
|
-
*
|
|
2850
|
-
* @example
|
|
2851
|
-
* ```ts
|
|
2852
|
-
* import { createClient, http } from 'viem'
|
|
2853
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2854
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2855
|
-
*
|
|
2856
|
-
* const client = createClient({
|
|
2857
|
-
* account: privateKeyToAccount('0x...'),
|
|
2858
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2859
|
-
* transport: http(),
|
|
2860
|
-
* })
|
|
2861
|
-
*
|
|
2862
|
-
* const unwatch = actions.token.watchTransfer(client, {
|
|
2863
|
-
* onTransfer: (args, log) => {
|
|
2864
|
-
* console.log('Transfer:', args)
|
|
2865
|
-
* },
|
|
2866
|
-
* })
|
|
2867
|
-
* ```
|
|
2868
|
-
*
|
|
2869
|
-
* @param client - Client.
|
|
2870
|
-
* @param parameters - Parameters.
|
|
2871
|
-
* @returns A function to unsubscribe from the event.
|
|
2872
|
-
*/
|
|
2873
|
-
export function watchTransfer(client, parameters) {
|
|
2874
|
-
const { onTransfer, token, ...rest } = parameters;
|
|
2875
|
-
return watchContractEvent(client, {
|
|
2876
|
-
...rest,
|
|
2877
|
-
address: TokenId.toAddress(token),
|
|
2878
|
-
abi: Abis.tip20,
|
|
2879
|
-
eventName: 'Transfer',
|
|
2880
|
-
onLogs: (logs) => {
|
|
2881
|
-
for (const log of logs)
|
|
2882
|
-
onTransfer(log.args, log);
|
|
2883
|
-
},
|
|
2884
|
-
strict: true,
|
|
2885
|
-
});
|
|
2886
|
-
}
|
|
2887
|
-
/**
|
|
2888
|
-
* Watches for TIP20 token quote token update events.
|
|
2889
|
-
*
|
|
2890
|
-
* @example
|
|
2891
|
-
* ```ts
|
|
2892
|
-
* import { createClient, http } from 'viem'
|
|
2893
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
2894
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
2895
|
-
*
|
|
2896
|
-
* const client = createClient({
|
|
2897
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' })
|
|
2898
|
-
* transport: http(),
|
|
2899
|
-
* })
|
|
2900
|
-
*
|
|
2901
|
-
* const unwatch = actions.token.watchUpdateQuoteToken(client, {
|
|
2902
|
-
* onUpdateQuoteToken: (args, log) => {
|
|
2903
|
-
* if (args.completed)
|
|
2904
|
-
* console.log('quote token update completed:', args.newQuoteToken)
|
|
2905
|
-
* else
|
|
2906
|
-
* console.log('quote token update proposed:', args.newQuoteToken)
|
|
2907
|
-
* },
|
|
2908
|
-
* })
|
|
2909
|
-
* ```
|
|
2910
|
-
*
|
|
2911
|
-
* @param client - Client.
|
|
2912
|
-
* @param parameters - Parameters.
|
|
2913
|
-
* @returns A function to unsubscribe from the event.
|
|
2914
|
-
*/
|
|
2915
|
-
export function watchUpdateQuoteToken(client, parameters) {
|
|
2916
|
-
const { onUpdateQuoteToken, token, ...rest } = parameters;
|
|
2917
|
-
const address = TokenId.toAddress(token);
|
|
2918
|
-
return watchContractEvent(client, {
|
|
2919
|
-
...rest,
|
|
2920
|
-
address,
|
|
2921
|
-
abi: Abis.tip20,
|
|
2922
|
-
onLogs: (logs) => {
|
|
2923
|
-
for (const log of logs) {
|
|
2924
|
-
if (log.eventName !== 'NextQuoteTokenSet' &&
|
|
2925
|
-
log.eventName !== 'QuoteTokenUpdate')
|
|
2926
|
-
continue;
|
|
2927
|
-
onUpdateQuoteToken({
|
|
2928
|
-
...log.args,
|
|
2929
|
-
completed: log.eventName === 'QuoteTokenUpdate',
|
|
2930
|
-
}, log);
|
|
2931
|
-
}
|
|
2932
|
-
},
|
|
2933
|
-
strict: true,
|
|
2934
|
-
});
|
|
2935
|
-
}
|
|
2936
|
-
//# sourceMappingURL=token.js.map
|