tempo.ts 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -0
- package/dist/chains.d.ts +1477 -0
- package/dist/chains.d.ts.map +1 -0
- package/dist/chains.js +43 -0
- package/dist/chains.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/types.d.ts +284 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +2 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/ox/TokenId.d.ts +18 -0
- package/dist/ox/TokenId.d.ts.map +1 -0
- package/dist/ox/TokenId.js +29 -0
- package/dist/ox/TokenId.js.map +1 -0
- package/dist/ox/TokenRole.d.ts +11 -0
- package/dist/ox/TokenRole.d.ts.map +1 -0
- package/dist/ox/TokenRole.js +22 -0
- package/dist/ox/TokenRole.js.map +1 -0
- package/dist/ox/Transaction.d.ts +161 -0
- package/dist/ox/Transaction.d.ts.map +1 -0
- package/dist/ox/Transaction.js +117 -0
- package/dist/ox/Transaction.js.map +1 -0
- package/dist/ox/TransactionEnvelopeFeeToken.d.ts +393 -0
- package/dist/ox/TransactionEnvelopeFeeToken.d.ts.map +1 -0
- package/dist/ox/TransactionEnvelopeFeeToken.js +452 -0
- package/dist/ox/TransactionEnvelopeFeeToken.js.map +1 -0
- package/dist/ox/TransactionRequest.d.ts +62 -0
- package/dist/ox/TransactionRequest.d.ts.map +1 -0
- package/dist/ox/TransactionRequest.js +66 -0
- package/dist/ox/TransactionRequest.js.map +1 -0
- package/dist/ox/index.d.ts +5 -0
- package/dist/ox/index.d.ts.map +1 -0
- package/dist/ox/index.js +5 -0
- package/dist/ox/index.js.map +1 -0
- package/dist/prool/Instance.d.ts +92 -0
- package/dist/prool/Instance.d.ts.map +1 -0
- package/dist/prool/Instance.js +96 -0
- package/dist/prool/Instance.js.map +1 -0
- package/dist/prool/index.d.ts +2 -0
- package/dist/prool/index.d.ts.map +1 -0
- package/dist/prool/index.js +2 -0
- package/dist/prool/index.js.map +1 -0
- package/dist/viem/abis.d.ts +2058 -0
- package/dist/viem/abis.d.ts.map +1 -0
- package/dist/viem/abis.js +1599 -0
- package/dist/viem/abis.js.map +1 -0
- package/dist/viem/actions/amm.d.ts +2091 -0
- package/dist/viem/actions/amm.d.ts.map +1 -0
- package/dist/viem/actions/amm.js +876 -0
- package/dist/viem/actions/amm.js.map +1 -0
- package/dist/viem/actions/fee.d.ts +727 -0
- package/dist/viem/actions/fee.d.ts.map +1 -0
- package/dist/viem/actions/fee.js +230 -0
- package/dist/viem/actions/fee.js.map +1 -0
- package/dist/viem/actions/index.d.ts +5 -0
- package/dist/viem/actions/index.d.ts.map +1 -0
- package/dist/viem/actions/index.js +5 -0
- package/dist/viem/actions/index.js.map +1 -0
- package/dist/viem/actions/policy.d.ts +1900 -0
- package/dist/viem/actions/policy.d.ts.map +1 -0
- package/dist/viem/actions/policy.js +841 -0
- package/dist/viem/actions/policy.js.map +1 -0
- package/dist/viem/actions/token.d.ts +13759 -0
- package/dist/viem/actions/token.d.ts.map +1 -0
- package/dist/viem/actions/token.js +2579 -0
- package/dist/viem/actions/token.js.map +1 -0
- package/dist/viem/addresses.d.ts +8 -0
- package/dist/viem/addresses.d.ts.map +1 -0
- package/dist/viem/addresses.js +8 -0
- package/dist/viem/addresses.js.map +1 -0
- package/dist/viem/chain.d.ts +341 -0
- package/dist/viem/chain.d.ts.map +1 -0
- package/dist/viem/chain.js +22 -0
- package/dist/viem/chain.js.map +1 -0
- package/dist/viem/client.d.ts +27 -0
- package/dist/viem/client.d.ts.map +1 -0
- package/dist/viem/client.js +28 -0
- package/dist/viem/client.js.map +1 -0
- package/dist/viem/decorator.d.ts +1636 -0
- package/dist/viem/decorator.d.ts.map +1 -0
- package/dist/viem/decorator.js +95 -0
- package/dist/viem/decorator.js.map +1 -0
- package/dist/viem/formatters.d.ts +4 -0
- package/dist/viem/formatters.d.ts.map +1 -0
- package/dist/viem/formatters.js +69 -0
- package/dist/viem/formatters.js.map +1 -0
- package/dist/viem/index.d.ts +9 -0
- package/dist/viem/index.d.ts.map +1 -0
- package/dist/viem/index.js +9 -0
- package/dist/viem/index.js.map +1 -0
- package/dist/viem/transaction.d.ts +54 -0
- package/dist/viem/transaction.d.ts.map +1 -0
- package/dist/viem/transaction.js +108 -0
- package/dist/viem/transaction.js.map +1 -0
- package/dist/viem/transport.d.ts +16 -0
- package/dist/viem/transport.d.ts.map +1 -0
- package/dist/viem/transport.js +33 -0
- package/dist/viem/transport.js.map +1 -0
- package/dist/viem/types.d.ts +10 -0
- package/dist/viem/types.d.ts.map +1 -0
- package/dist/viem/types.js +2 -0
- package/dist/viem/types.js.map +1 -0
- package/dist/viem/utils.d.ts +8 -0
- package/dist/viem/utils.d.ts.map +1 -0
- package/dist/viem/utils.js +9 -0
- package/dist/viem/utils.js.map +1 -0
- package/package.json +100 -2
- package/src/chains.ts +46 -0
- package/src/index.ts +1 -0
- package/src/internal/types.ts +414 -0
- package/src/ox/TokenId.test.ts +29 -0
- package/src/ox/TokenId.ts +35 -0
- package/src/ox/TokenRole.test.ts +20 -0
- package/src/ox/TokenRole.ts +27 -0
- package/src/ox/Transaction.test.ts +257 -0
- package/src/ox/Transaction.ts +247 -0
- package/src/ox/TransactionEnvelopeFeeToken.test.ts +1215 -0
- package/src/ox/TransactionEnvelopeFeeToken.ts +717 -0
- package/src/ox/TransactionRequest.ts +100 -0
- package/src/ox/index.ts +4 -0
- package/src/prool/Instance.test.ts +43 -0
- package/src/prool/Instance.ts +190 -0
- package/src/prool/index.ts +1 -0
- package/src/prool/internal/chain.json +106 -0
- package/src/prool/internal/consensus.toml +32 -0
- package/src/viem/abis.ts +1606 -0
- package/src/viem/actions/amm.test.ts +425 -0
- package/src/viem/actions/amm.ts +1308 -0
- package/src/viem/actions/fee.test.ts +281 -0
- package/src/viem/actions/fee.ts +362 -0
- package/src/viem/actions/index.ts +4 -0
- package/src/viem/actions/policy.test.ts +514 -0
- package/src/viem/actions/policy.ts +1284 -0
- package/src/viem/actions/token.test.ts +2172 -0
- package/src/viem/actions/token.ts +3830 -0
- package/src/viem/addresses.ts +10 -0
- package/src/viem/chain.ts +27 -0
- package/src/viem/client.bench-d.ts +8 -0
- package/src/viem/client.test.ts +152 -0
- package/src/viem/client.ts +91 -0
- package/src/viem/decorator.bench-d.ts +11 -0
- package/src/viem/decorator.test.ts +35 -0
- package/src/viem/decorator.ts +1914 -0
- package/src/viem/e2e.test.ts +410 -0
- package/src/viem/formatters.ts +100 -0
- package/src/viem/index.ts +8 -0
- package/src/viem/transaction.ts +253 -0
- package/src/viem/transport.ts +47 -0
- package/src/viem/types.ts +55 -0
- package/src/viem/utils.ts +37 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { setTimeout } from 'node:timers/promises'
|
|
2
|
+
import * as actions from 'tempo.ts/viem/actions'
|
|
3
|
+
import { parseEther, publicActions } from 'viem'
|
|
4
|
+
import { mnemonicToAccount } from 'viem/accounts'
|
|
5
|
+
import { writeContractSync } from 'viem/actions'
|
|
6
|
+
import { describe, expect, test } from 'vitest'
|
|
7
|
+
import { tempoTest } from '../../../test/viem/config.js'
|
|
8
|
+
import { tip20Abi } from '../abis.js'
|
|
9
|
+
import { usdAddress } from '../addresses.js'
|
|
10
|
+
import { createTempoClient } from '../client.js'
|
|
11
|
+
|
|
12
|
+
const account = mnemonicToAccount(
|
|
13
|
+
'test test test test test test test test test test test junk',
|
|
14
|
+
)
|
|
15
|
+
const account2 = mnemonicToAccount(
|
|
16
|
+
'test test test test test test test test test test test junk',
|
|
17
|
+
{ accountIndex: 1 },
|
|
18
|
+
)
|
|
19
|
+
const account3 = mnemonicToAccount(
|
|
20
|
+
'test test test test test test test test test test test junk',
|
|
21
|
+
{ accountIndex: 2 },
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const client = createTempoClient({
|
|
25
|
+
account,
|
|
26
|
+
chain: tempoTest,
|
|
27
|
+
pollingInterval: 100,
|
|
28
|
+
}).extend(publicActions)
|
|
29
|
+
|
|
30
|
+
describe('getUserToken', () => {
|
|
31
|
+
test('default', async () => {
|
|
32
|
+
// Fund accounts
|
|
33
|
+
await writeContractSync(client, {
|
|
34
|
+
abi: tip20Abi,
|
|
35
|
+
address: usdAddress,
|
|
36
|
+
functionName: 'transfer',
|
|
37
|
+
args: [account2.address, parseEther('100')],
|
|
38
|
+
})
|
|
39
|
+
await writeContractSync(client, {
|
|
40
|
+
abi: tip20Abi,
|
|
41
|
+
address: usdAddress,
|
|
42
|
+
functionName: 'transfer',
|
|
43
|
+
args: [account3.address, parseEther('100')],
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Set token (address)
|
|
47
|
+
await actions.fee.setUserTokenSync(client, {
|
|
48
|
+
account: account2,
|
|
49
|
+
token: '0x20c0000000000000000000000000000000000001',
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
// Set another token (id)
|
|
53
|
+
await actions.fee.setUserTokenSync(client, {
|
|
54
|
+
account: account3,
|
|
55
|
+
token: 2n,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// Assert that account (with default) & account2 (with custom) tokens are set correctly.
|
|
59
|
+
expect(
|
|
60
|
+
await actions.fee.getUserToken(client, { account }),
|
|
61
|
+
).toMatchInlineSnapshot(`
|
|
62
|
+
{
|
|
63
|
+
"address": "0x20C0000000000000000000000000000000000000",
|
|
64
|
+
"id": 0n,
|
|
65
|
+
}
|
|
66
|
+
`)
|
|
67
|
+
expect(
|
|
68
|
+
await actions.fee.getUserToken(client, { account: account2 }),
|
|
69
|
+
).toMatchInlineSnapshot(`
|
|
70
|
+
{
|
|
71
|
+
"address": "0x20C0000000000000000000000000000000000001",
|
|
72
|
+
"id": 1n,
|
|
73
|
+
}
|
|
74
|
+
`)
|
|
75
|
+
expect(
|
|
76
|
+
await actions.fee.getUserToken(client, { account: account3 }),
|
|
77
|
+
).toMatchInlineSnapshot(`
|
|
78
|
+
{
|
|
79
|
+
"address": "0x20C0000000000000000000000000000000000002",
|
|
80
|
+
"id": 2n,
|
|
81
|
+
}
|
|
82
|
+
`)
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
describe('setUserToken', () => {
|
|
87
|
+
test('default', async () => {
|
|
88
|
+
expect(await actions.fee.getUserToken(client)).toMatchInlineSnapshot(
|
|
89
|
+
`
|
|
90
|
+
{
|
|
91
|
+
"address": "0x20C0000000000000000000000000000000000000",
|
|
92
|
+
"id": 0n,
|
|
93
|
+
}
|
|
94
|
+
`,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
const { receipt: setReceipt, ...setResult } =
|
|
98
|
+
await actions.fee.setUserTokenSync(client, {
|
|
99
|
+
token: '0x20c0000000000000000000000000000000000001',
|
|
100
|
+
})
|
|
101
|
+
expect(setReceipt).toBeDefined()
|
|
102
|
+
expect(setResult).toMatchInlineSnapshot(`
|
|
103
|
+
{
|
|
104
|
+
"token": "0x20C0000000000000000000000000000000000001",
|
|
105
|
+
"user": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
106
|
+
}
|
|
107
|
+
`)
|
|
108
|
+
|
|
109
|
+
expect(await actions.fee.getUserToken(client, {})).toMatchInlineSnapshot(
|
|
110
|
+
`
|
|
111
|
+
{
|
|
112
|
+
"address": "0x20C0000000000000000000000000000000000001",
|
|
113
|
+
"id": 1n,
|
|
114
|
+
}
|
|
115
|
+
`,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
const { receipt: resetReceipt, ...resetResult } =
|
|
119
|
+
await actions.fee.setUserTokenSync(client, {
|
|
120
|
+
feeToken: 0n,
|
|
121
|
+
token: 0n,
|
|
122
|
+
})
|
|
123
|
+
expect(resetReceipt).toBeDefined()
|
|
124
|
+
expect(resetResult).toMatchInlineSnapshot(`
|
|
125
|
+
{
|
|
126
|
+
"token": "0x20C0000000000000000000000000000000000000",
|
|
127
|
+
"user": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
128
|
+
}
|
|
129
|
+
`)
|
|
130
|
+
|
|
131
|
+
expect(await actions.fee.getUserToken(client, {})).toMatchInlineSnapshot(
|
|
132
|
+
`
|
|
133
|
+
{
|
|
134
|
+
"address": "0x20C0000000000000000000000000000000000000",
|
|
135
|
+
"id": 0n,
|
|
136
|
+
}
|
|
137
|
+
`,
|
|
138
|
+
)
|
|
139
|
+
})
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
describe('watchSetUserToken', () => {
|
|
143
|
+
test('default', async () => {
|
|
144
|
+
const receivedSets: Array<{
|
|
145
|
+
args: actions.fee.watchSetUserToken.Args
|
|
146
|
+
log: actions.fee.watchSetUserToken.Log
|
|
147
|
+
}> = []
|
|
148
|
+
|
|
149
|
+
// Start watching for user token set events
|
|
150
|
+
const unwatch = actions.fee.watchSetUserToken(client, {
|
|
151
|
+
onUserTokenSet: (args, log) => {
|
|
152
|
+
receivedSets.push({ args, log })
|
|
153
|
+
},
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
// Set token for account2
|
|
158
|
+
await writeContractSync(client, {
|
|
159
|
+
abi: tip20Abi,
|
|
160
|
+
address: usdAddress,
|
|
161
|
+
functionName: 'transfer',
|
|
162
|
+
args: [account2.address, parseEther('1')],
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
await actions.fee.setUserTokenSync(client, {
|
|
166
|
+
account: account2,
|
|
167
|
+
token: '0x20c0000000000000000000000000000000000001',
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
// Set token for account3
|
|
171
|
+
await writeContractSync(client, {
|
|
172
|
+
abi: tip20Abi,
|
|
173
|
+
address: usdAddress,
|
|
174
|
+
functionName: 'transfer',
|
|
175
|
+
args: [account3.address, parseEther('1')],
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
await actions.fee.setUserTokenSync(client, {
|
|
179
|
+
account: account3,
|
|
180
|
+
token: '0x20c0000000000000000000000000000000000002',
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
await setTimeout(100)
|
|
184
|
+
|
|
185
|
+
expect(receivedSets).toHaveLength(2)
|
|
186
|
+
|
|
187
|
+
expect(receivedSets.at(0)!.args).toMatchInlineSnapshot(`
|
|
188
|
+
{
|
|
189
|
+
"token": "0x20C0000000000000000000000000000000000001",
|
|
190
|
+
"user": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
|
|
191
|
+
}
|
|
192
|
+
`)
|
|
193
|
+
expect(receivedSets.at(1)!.args).toMatchInlineSnapshot(`
|
|
194
|
+
{
|
|
195
|
+
"token": "0x20C0000000000000000000000000000000000002",
|
|
196
|
+
"user": "0x98e503f35D0a019cB0a251aD243a4cCFCF371F46",
|
|
197
|
+
}
|
|
198
|
+
`)
|
|
199
|
+
} finally {
|
|
200
|
+
if (unwatch) unwatch()
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
test('behavior: filter by user address', async () => {
|
|
205
|
+
const receivedSets: Array<{
|
|
206
|
+
args: actions.fee.watchSetUserToken.Args
|
|
207
|
+
log: actions.fee.watchSetUserToken.Log
|
|
208
|
+
}> = []
|
|
209
|
+
|
|
210
|
+
// Start watching for user token set events only for account2
|
|
211
|
+
const unwatch = actions.fee.watchSetUserToken(client, {
|
|
212
|
+
args: {
|
|
213
|
+
user: account2.address,
|
|
214
|
+
},
|
|
215
|
+
onUserTokenSet: (args, log) => {
|
|
216
|
+
receivedSets.push({ args, log })
|
|
217
|
+
},
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
// Transfer gas to accounts
|
|
222
|
+
await writeContractSync(client, {
|
|
223
|
+
abi: tip20Abi,
|
|
224
|
+
address: usdAddress,
|
|
225
|
+
functionName: 'transfer',
|
|
226
|
+
args: [account2.address, parseEther('1')],
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
await writeContractSync(client, {
|
|
230
|
+
abi: tip20Abi,
|
|
231
|
+
address: usdAddress,
|
|
232
|
+
functionName: 'transfer',
|
|
233
|
+
args: [account3.address, parseEther('1')],
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
// Set token for account2 (should be captured)
|
|
237
|
+
await actions.fee.setUserTokenSync(client, {
|
|
238
|
+
account: account2,
|
|
239
|
+
token: '0x20c0000000000000000000000000000000000001',
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
// Set token for account3 (should NOT be captured)
|
|
243
|
+
await actions.fee.setUserTokenSync(client, {
|
|
244
|
+
account: account3,
|
|
245
|
+
token: '0x20c0000000000000000000000000000000000002',
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
// Set token for account2 again (should be captured)
|
|
249
|
+
await actions.fee.setUserTokenSync(client, {
|
|
250
|
+
account: account2,
|
|
251
|
+
feeToken: 0n,
|
|
252
|
+
token: 2n,
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
await setTimeout(100)
|
|
256
|
+
|
|
257
|
+
// Should only receive 2 events (for account2)
|
|
258
|
+
expect(receivedSets).toHaveLength(2)
|
|
259
|
+
|
|
260
|
+
expect(receivedSets.at(0)!.args).toMatchInlineSnapshot(`
|
|
261
|
+
{
|
|
262
|
+
"token": "0x20C0000000000000000000000000000000000001",
|
|
263
|
+
"user": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
|
|
264
|
+
}
|
|
265
|
+
`)
|
|
266
|
+
expect(receivedSets.at(1)!.args).toMatchInlineSnapshot(`
|
|
267
|
+
{
|
|
268
|
+
"token": "0x20C0000000000000000000000000000000000002",
|
|
269
|
+
"user": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
|
|
270
|
+
}
|
|
271
|
+
`)
|
|
272
|
+
|
|
273
|
+
// Verify all received events are for account2
|
|
274
|
+
for (const set of receivedSets) {
|
|
275
|
+
expect(set.args.user).toBe(account2.address)
|
|
276
|
+
}
|
|
277
|
+
} finally {
|
|
278
|
+
if (unwatch) unwatch()
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
})
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
type Address,
|
|
4
|
+
type Chain,
|
|
5
|
+
type Client,
|
|
6
|
+
type ExtractAbiItem,
|
|
7
|
+
type GetEventArgs,
|
|
8
|
+
type Log,
|
|
9
|
+
parseEventLogs,
|
|
10
|
+
type TransactionReceipt,
|
|
11
|
+
type Transport,
|
|
12
|
+
type Log as viem_Log,
|
|
13
|
+
type WatchContractEventParameters,
|
|
14
|
+
type WriteContractReturnType,
|
|
15
|
+
} from 'viem'
|
|
16
|
+
import { parseAccount } from 'viem/accounts'
|
|
17
|
+
import {
|
|
18
|
+
readContract,
|
|
19
|
+
watchContractEvent,
|
|
20
|
+
writeContract,
|
|
21
|
+
writeContractSync,
|
|
22
|
+
} from 'viem/actions'
|
|
23
|
+
import type { Compute, UnionOmit } from '../../internal/types.js'
|
|
24
|
+
import * as TokenId from '../../ox/TokenId.js'
|
|
25
|
+
import { feeManagerAbi } from '../abis.js'
|
|
26
|
+
import { feeManagerAddress } from '../addresses.js'
|
|
27
|
+
import type {
|
|
28
|
+
GetAccountParameter,
|
|
29
|
+
ReadParameters,
|
|
30
|
+
WriteParameters,
|
|
31
|
+
} from '../types.js'
|
|
32
|
+
import { defineCall } from '../utils.js'
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Gets the user's default fee token.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { createClient, http } from 'viem'
|
|
40
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
41
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
42
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
43
|
+
*
|
|
44
|
+
* const client = createClient({
|
|
45
|
+
* account: privateKeyToAccount('0x...'),
|
|
46
|
+
* chain: tempo,
|
|
47
|
+
* transport: http(),
|
|
48
|
+
* })
|
|
49
|
+
*
|
|
50
|
+
* const { address, id } = await actions.fee.getUserToken(client)
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @param client - Client.
|
|
54
|
+
* @param parameters - Parameters.
|
|
55
|
+
* @returns The transaction hash.
|
|
56
|
+
*/
|
|
57
|
+
export async function getUserToken<
|
|
58
|
+
chain extends Chain | undefined,
|
|
59
|
+
account extends Account | undefined,
|
|
60
|
+
>(
|
|
61
|
+
client: Client<Transport, chain, account>,
|
|
62
|
+
...parameters: account extends Account
|
|
63
|
+
? [getUserToken.Parameters<account>] | []
|
|
64
|
+
: [getUserToken.Parameters<account>]
|
|
65
|
+
): Promise<getUserToken.ReturnValue> {
|
|
66
|
+
const { account: account_ = client.account, ...rest } = parameters[0] ?? {}
|
|
67
|
+
if (!account_) throw new Error('account is required.')
|
|
68
|
+
const account = parseAccount(account_)
|
|
69
|
+
const address = await readContract(client, {
|
|
70
|
+
...rest,
|
|
71
|
+
...getUserToken.call({ account: account.address }),
|
|
72
|
+
})
|
|
73
|
+
return {
|
|
74
|
+
address,
|
|
75
|
+
id: TokenId.fromAddress(address),
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export namespace getUserToken {
|
|
80
|
+
export type Parameters<
|
|
81
|
+
account extends Account | undefined = Account | undefined,
|
|
82
|
+
> = ReadParameters & GetAccountParameter<account>
|
|
83
|
+
|
|
84
|
+
export type Args = {
|
|
85
|
+
/** Account address. */
|
|
86
|
+
account: Address
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type ReturnValue = Compute<{
|
|
90
|
+
address: Address
|
|
91
|
+
id: bigint
|
|
92
|
+
}>
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Defines a call to the `userTokens` function.
|
|
96
|
+
*
|
|
97
|
+
* @param args - Arguments.
|
|
98
|
+
* @returns The call.
|
|
99
|
+
*/
|
|
100
|
+
export function call(args: Args) {
|
|
101
|
+
const { account } = args
|
|
102
|
+
return defineCall({
|
|
103
|
+
address: feeManagerAddress,
|
|
104
|
+
abi: feeManagerAbi,
|
|
105
|
+
args: [account],
|
|
106
|
+
functionName: 'userTokens',
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Sets the user's default fee token.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { createClient, http } from 'viem'
|
|
117
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
118
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
119
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
120
|
+
*
|
|
121
|
+
* const client = createClient({
|
|
122
|
+
* account: privateKeyToAccount('0x...'),
|
|
123
|
+
* chain: tempo,
|
|
124
|
+
* transport: http(),
|
|
125
|
+
* })
|
|
126
|
+
*
|
|
127
|
+
* const hash = await actions.fee.setUserToken(client, {
|
|
128
|
+
* token: '0x...',
|
|
129
|
+
* })
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @param client - Client.
|
|
133
|
+
* @param parameters - Parameters.
|
|
134
|
+
* @returns The transaction hash.
|
|
135
|
+
*/
|
|
136
|
+
export async function setUserToken<
|
|
137
|
+
chain extends Chain | undefined,
|
|
138
|
+
account extends Account | undefined,
|
|
139
|
+
>(
|
|
140
|
+
client: Client<Transport, chain, account>,
|
|
141
|
+
parameters: setUserToken.Parameters<chain, account>,
|
|
142
|
+
): Promise<setUserToken.ReturnValue> {
|
|
143
|
+
return setUserToken.inner(writeContract, client, parameters)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export namespace setUserToken {
|
|
147
|
+
export type Parameters<
|
|
148
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
149
|
+
account extends Account | undefined = Account | undefined,
|
|
150
|
+
> = WriteParameters<chain, account> & Args
|
|
151
|
+
|
|
152
|
+
export type Args = {
|
|
153
|
+
/** Address or ID of the TIP20 token. */
|
|
154
|
+
token: TokenId.TokenIdOrAddress
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export type ReturnValue = WriteContractReturnType
|
|
158
|
+
|
|
159
|
+
/** @internal */
|
|
160
|
+
export async function inner<
|
|
161
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
162
|
+
chain extends Chain | undefined,
|
|
163
|
+
account extends Account | undefined,
|
|
164
|
+
>(
|
|
165
|
+
action: action,
|
|
166
|
+
client: Client<Transport, chain, account>,
|
|
167
|
+
parameters: setUserToken.Parameters<chain, account>,
|
|
168
|
+
): Promise<ReturnType<action>> {
|
|
169
|
+
const call = setUserToken.call(parameters)
|
|
170
|
+
return (await action(client, {
|
|
171
|
+
...parameters,
|
|
172
|
+
...call,
|
|
173
|
+
} as never)) as never
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Defines a call to the `setUserToken` function.
|
|
178
|
+
*
|
|
179
|
+
* Can be passed as a parameter to:
|
|
180
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
181
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
182
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
187
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
188
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
189
|
+
*
|
|
190
|
+
* const client = createClient({
|
|
191
|
+
* chain: tempo,
|
|
192
|
+
* transport: http(),
|
|
193
|
+
* }).extend(walletActions)
|
|
194
|
+
*
|
|
195
|
+
* const { result } = await client.sendCalls({
|
|
196
|
+
* calls: [
|
|
197
|
+
* actions.fee.setUserToken.call({
|
|
198
|
+
* token: '0x20c0...beef',
|
|
199
|
+
* }),
|
|
200
|
+
* actions.fee.setUserToken.call({
|
|
201
|
+
* token: '0x20c0...babe',
|
|
202
|
+
* }),
|
|
203
|
+
* ]
|
|
204
|
+
* })
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @param args - Arguments.
|
|
208
|
+
* @returns The call.
|
|
209
|
+
*/
|
|
210
|
+
export function call(args: Args) {
|
|
211
|
+
const { token } = args
|
|
212
|
+
return defineCall({
|
|
213
|
+
address: feeManagerAddress,
|
|
214
|
+
abi: feeManagerAbi,
|
|
215
|
+
functionName: 'setUserToken',
|
|
216
|
+
args: [TokenId.toAddress(token)],
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function extractEvent(logs: Log[]) {
|
|
221
|
+
const [log] = parseEventLogs({
|
|
222
|
+
abi: feeManagerAbi,
|
|
223
|
+
logs,
|
|
224
|
+
eventName: 'UserTokenSet',
|
|
225
|
+
strict: true,
|
|
226
|
+
})
|
|
227
|
+
if (!log) throw new Error('`UserTokenSet` event not found.')
|
|
228
|
+
return log
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Sets the user's default fee token.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* import { createClient, http } from 'viem'
|
|
238
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
239
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
240
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
241
|
+
*
|
|
242
|
+
* const client = createClient({
|
|
243
|
+
* account: privateKeyToAccount('0x...'),
|
|
244
|
+
* chain: tempo,
|
|
245
|
+
* transport: http(),
|
|
246
|
+
* })
|
|
247
|
+
*
|
|
248
|
+
* const result = await actions.fee.setUserTokenSync(client, {
|
|
249
|
+
* token: '0x...',
|
|
250
|
+
* })
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @param client - Client.
|
|
254
|
+
* @param parameters - Parameters.
|
|
255
|
+
* @returns The transaction receipt and event data.
|
|
256
|
+
*/
|
|
257
|
+
export async function setUserTokenSync<
|
|
258
|
+
chain extends Chain | undefined,
|
|
259
|
+
account extends Account | undefined,
|
|
260
|
+
>(
|
|
261
|
+
client: Client<Transport, chain, account>,
|
|
262
|
+
parameters: setUserTokenSync.Parameters<chain, account>,
|
|
263
|
+
): Promise<setUserTokenSync.ReturnValue> {
|
|
264
|
+
const receipt = await setUserToken.inner(
|
|
265
|
+
writeContractSync,
|
|
266
|
+
client,
|
|
267
|
+
parameters,
|
|
268
|
+
)
|
|
269
|
+
const { args } = setUserToken.extractEvent(receipt.logs)
|
|
270
|
+
return {
|
|
271
|
+
...args,
|
|
272
|
+
receipt,
|
|
273
|
+
} as never
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export namespace setUserTokenSync {
|
|
277
|
+
export type Parameters<
|
|
278
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
279
|
+
account extends Account | undefined = Account | undefined,
|
|
280
|
+
> = setUserToken.Parameters<chain, account>
|
|
281
|
+
|
|
282
|
+
export type Args = setUserToken.Args
|
|
283
|
+
|
|
284
|
+
export type ReturnValue = Compute<
|
|
285
|
+
GetEventArgs<
|
|
286
|
+
typeof feeManagerAbi,
|
|
287
|
+
'UserTokenSet',
|
|
288
|
+
{ IndexedOnly: false; Required: true }
|
|
289
|
+
> & {
|
|
290
|
+
receipt: TransactionReceipt
|
|
291
|
+
}
|
|
292
|
+
>
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Watches for user token set events.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```ts
|
|
300
|
+
* import { createClient, http } from 'viem'
|
|
301
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
302
|
+
* import * as actions from 'tempo.ts/viem/actions'
|
|
303
|
+
*
|
|
304
|
+
* const client = createClient({
|
|
305
|
+
* chain: tempo,
|
|
306
|
+
* transport: http(),
|
|
307
|
+
* })
|
|
308
|
+
*
|
|
309
|
+
* const unwatch = actions.fee.watchSetUserToken(client, {
|
|
310
|
+
* onUserTokenSet: (args, log) => {
|
|
311
|
+
* console.log('User token set:', args)
|
|
312
|
+
* },
|
|
313
|
+
* })
|
|
314
|
+
* ```
|
|
315
|
+
*
|
|
316
|
+
* @param client - Client.
|
|
317
|
+
* @param parameters - Parameters.
|
|
318
|
+
* @returns A function to unsubscribe from the event.
|
|
319
|
+
*/
|
|
320
|
+
export function watchSetUserToken<
|
|
321
|
+
chain extends Chain | undefined,
|
|
322
|
+
account extends Account | undefined,
|
|
323
|
+
>(
|
|
324
|
+
client: Client<Transport, chain, account>,
|
|
325
|
+
parameters: watchSetUserToken.Parameters,
|
|
326
|
+
) {
|
|
327
|
+
const { onUserTokenSet, ...rest } = parameters
|
|
328
|
+
return watchContractEvent(client, {
|
|
329
|
+
...rest,
|
|
330
|
+
address: feeManagerAddress,
|
|
331
|
+
abi: feeManagerAbi,
|
|
332
|
+
eventName: 'UserTokenSet',
|
|
333
|
+
onLogs: (logs) => {
|
|
334
|
+
for (const log of logs) onUserTokenSet(log.args, log)
|
|
335
|
+
},
|
|
336
|
+
strict: true,
|
|
337
|
+
})
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export declare namespace watchSetUserToken {
|
|
341
|
+
export type Args = GetEventArgs<
|
|
342
|
+
typeof feeManagerAbi,
|
|
343
|
+
'UserTokenSet',
|
|
344
|
+
{ IndexedOnly: false; Required: true }
|
|
345
|
+
>
|
|
346
|
+
|
|
347
|
+
export type Log = viem_Log<
|
|
348
|
+
bigint,
|
|
349
|
+
number,
|
|
350
|
+
false,
|
|
351
|
+
ExtractAbiItem<typeof feeManagerAbi, 'UserTokenSet'>,
|
|
352
|
+
true
|
|
353
|
+
>
|
|
354
|
+
|
|
355
|
+
export type Parameters = UnionOmit<
|
|
356
|
+
WatchContractEventParameters<typeof feeManagerAbi, 'UserTokenSet', true>,
|
|
357
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
358
|
+
> & {
|
|
359
|
+
/** Callback to invoke when a user token is set. */
|
|
360
|
+
onUserTokenSet: (args: Args, log: Log) => void
|
|
361
|
+
}
|
|
362
|
+
}
|