tempo.ts 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -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 +2 -12
- 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,121 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Account,
|
|
3
|
-
Address,
|
|
4
|
-
Chain,
|
|
5
|
-
Client,
|
|
6
|
-
Hash,
|
|
7
|
-
TransactionReceipt,
|
|
8
|
-
Transport,
|
|
9
|
-
} from 'viem'
|
|
10
|
-
import { waitForTransactionReceipt } from 'viem/actions'
|
|
11
|
-
import { parseAccount } from 'viem/utils'
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Funds an account with an initial amount of set token(s)
|
|
15
|
-
* on Tempo's testnet.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* import { createClient, http } from 'viem'
|
|
20
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
21
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
22
|
-
*
|
|
23
|
-
* const client = createClient({
|
|
24
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
25
|
-
* transport: http(),
|
|
26
|
-
* })
|
|
27
|
-
*
|
|
28
|
-
* const hashes = await Actions.faucet.fund(client, {
|
|
29
|
-
* account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
|
|
30
|
-
* })
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* @param client - Client.
|
|
34
|
-
* @param parameters - Parameters.
|
|
35
|
-
* @returns The transaction hash.
|
|
36
|
-
*/
|
|
37
|
-
export async function fund<chain extends Chain | undefined>(
|
|
38
|
-
client: Client<Transport, chain>,
|
|
39
|
-
parameters: fund.Parameters,
|
|
40
|
-
): Promise<fund.ReturnValue> {
|
|
41
|
-
const account = parseAccount(parameters.account)
|
|
42
|
-
return client.request<{
|
|
43
|
-
Method: 'tempo_fundAddress'
|
|
44
|
-
Parameters: [address: Address]
|
|
45
|
-
ReturnType: readonly Hash[]
|
|
46
|
-
}>({
|
|
47
|
-
method: 'tempo_fundAddress',
|
|
48
|
-
params: [account.address],
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export declare namespace fund {
|
|
53
|
-
export type Parameters = {
|
|
54
|
-
/** Account to fund. */
|
|
55
|
-
account: Account | Address
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type ReturnValue = readonly Hash[]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Funds an account with an initial amount of set token(s)
|
|
63
|
-
* on Tempo's testnet. Waits for the transactions to be included
|
|
64
|
-
* on a block before returning a response.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```ts
|
|
68
|
-
* import { createClient, http } from 'viem'
|
|
69
|
-
* import { tempo } from 'tempo.ts/chains'
|
|
70
|
-
* import { Actions } from 'tempo.ts/viem'
|
|
71
|
-
*
|
|
72
|
-
* const client = createClient({
|
|
73
|
-
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
74
|
-
* transport: http(),
|
|
75
|
-
* })
|
|
76
|
-
*
|
|
77
|
-
* const hashes = await Actions.faucet.fundSync(client, {
|
|
78
|
-
* account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
|
|
79
|
-
* })
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* @param client - Client.
|
|
83
|
-
* @param parameters - Parameters.
|
|
84
|
-
* @returns The transaction hash.
|
|
85
|
-
*/
|
|
86
|
-
export async function fundSync<chain extends Chain | undefined>(
|
|
87
|
-
client: Client<Transport, chain>,
|
|
88
|
-
parameters: fundSync.Parameters,
|
|
89
|
-
): Promise<fundSync.ReturnValue> {
|
|
90
|
-
const { timeout = 10_000 } = parameters
|
|
91
|
-
const account = parseAccount(parameters.account)
|
|
92
|
-
const hashes = await client.request<{
|
|
93
|
-
Method: 'tempo_fundAddress'
|
|
94
|
-
Parameters: [address: Address]
|
|
95
|
-
ReturnType: readonly Hash[]
|
|
96
|
-
}>({
|
|
97
|
-
method: 'tempo_fundAddress',
|
|
98
|
-
params: [account.address],
|
|
99
|
-
})
|
|
100
|
-
const receipts = await Promise.all(
|
|
101
|
-
hashes.map((hash) =>
|
|
102
|
-
waitForTransactionReceipt(client, {
|
|
103
|
-
hash,
|
|
104
|
-
checkReplacement: false,
|
|
105
|
-
timeout,
|
|
106
|
-
}),
|
|
107
|
-
),
|
|
108
|
-
)
|
|
109
|
-
return receipts
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export declare namespace fundSync {
|
|
113
|
-
export type Parameters = {
|
|
114
|
-
/** Account to fund. */
|
|
115
|
-
account: Account | Address
|
|
116
|
-
/** Timeout. */
|
|
117
|
-
timeout?: number | undefined
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export type ReturnValue = readonly TransactionReceipt[]
|
|
121
|
-
}
|
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import { setTimeout } from 'node:timers/promises'
|
|
2
|
-
import { Abis } from 'tempo.ts/viem'
|
|
3
|
-
import { parseUnits } from 'viem'
|
|
4
|
-
import { writeContractSync } from 'viem/actions'
|
|
5
|
-
import { afterEach, describe, expect, test } from 'vitest'
|
|
6
|
-
import { rpcUrl } from '../../../test/config.js'
|
|
7
|
-
import {
|
|
8
|
-
accounts,
|
|
9
|
-
clientWithAccount,
|
|
10
|
-
fundAddress,
|
|
11
|
-
} from '../../../test/viem/config.js'
|
|
12
|
-
import * as actions from './index.js'
|
|
13
|
-
|
|
14
|
-
const account2 = accounts[1]
|
|
15
|
-
const account3 = accounts[2]
|
|
16
|
-
|
|
17
|
-
afterEach(async () => {
|
|
18
|
-
await fetch(`${rpcUrl}/restart`)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
describe('getUserToken', () => {
|
|
22
|
-
test('default', async () => {
|
|
23
|
-
// Fund accounts
|
|
24
|
-
await fundAddress(clientWithAccount, { address: account2.address })
|
|
25
|
-
await fundAddress(clientWithAccount, { address: account3.address })
|
|
26
|
-
|
|
27
|
-
// Set token (address)
|
|
28
|
-
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
29
|
-
account: account2,
|
|
30
|
-
token: '0x20c0000000000000000000000000000000000001',
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
// Set another token (id)
|
|
34
|
-
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
35
|
-
account: account3,
|
|
36
|
-
token: 2n,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
expect(
|
|
40
|
-
await actions.fee.getUserToken(clientWithAccount, { account: account2 }),
|
|
41
|
-
).toMatchInlineSnapshot(`
|
|
42
|
-
{
|
|
43
|
-
"address": "0x20C0000000000000000000000000000000000001",
|
|
44
|
-
"id": 1n,
|
|
45
|
-
}
|
|
46
|
-
`)
|
|
47
|
-
expect(
|
|
48
|
-
await actions.fee.getUserToken(clientWithAccount, { account: account3 }),
|
|
49
|
-
).toMatchInlineSnapshot(`
|
|
50
|
-
{
|
|
51
|
-
"address": "0x20C0000000000000000000000000000000000002",
|
|
52
|
-
"id": 2n,
|
|
53
|
-
}
|
|
54
|
-
`)
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
describe('setUserToken', () => {
|
|
59
|
-
test('default', async () => {
|
|
60
|
-
expect(
|
|
61
|
-
await actions.fee.getUserToken(clientWithAccount),
|
|
62
|
-
).toMatchInlineSnapshot(
|
|
63
|
-
`
|
|
64
|
-
{
|
|
65
|
-
"address": "0x20C0000000000000000000000000000000000001",
|
|
66
|
-
"id": 1n,
|
|
67
|
-
}
|
|
68
|
-
`,
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
const { receipt: setReceipt, ...setResult } =
|
|
72
|
-
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
73
|
-
token: 2n,
|
|
74
|
-
})
|
|
75
|
-
expect(setReceipt).toBeDefined()
|
|
76
|
-
expect(setResult).toMatchInlineSnapshot(`
|
|
77
|
-
{
|
|
78
|
-
"token": "0x20C0000000000000000000000000000000000002",
|
|
79
|
-
"user": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
80
|
-
}
|
|
81
|
-
`)
|
|
82
|
-
|
|
83
|
-
expect(
|
|
84
|
-
await actions.fee.getUserToken(clientWithAccount, {}),
|
|
85
|
-
).toMatchInlineSnapshot(
|
|
86
|
-
`
|
|
87
|
-
{
|
|
88
|
-
"address": "0x20C0000000000000000000000000000000000002",
|
|
89
|
-
"id": 2n,
|
|
90
|
-
}
|
|
91
|
-
`,
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
const { receipt: resetReceipt, ...resetResult } =
|
|
95
|
-
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
96
|
-
feeToken: 1n,
|
|
97
|
-
token: 1n,
|
|
98
|
-
})
|
|
99
|
-
expect(resetReceipt).toBeDefined()
|
|
100
|
-
expect(resetResult).toMatchInlineSnapshot(`
|
|
101
|
-
{
|
|
102
|
-
"token": "0x20C0000000000000000000000000000000000001",
|
|
103
|
-
"user": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
104
|
-
}
|
|
105
|
-
`)
|
|
106
|
-
|
|
107
|
-
expect(
|
|
108
|
-
await actions.fee.getUserToken(clientWithAccount, {}),
|
|
109
|
-
).toMatchInlineSnapshot(
|
|
110
|
-
`
|
|
111
|
-
{
|
|
112
|
-
"address": "0x20C0000000000000000000000000000000000001",
|
|
113
|
-
"id": 1n,
|
|
114
|
-
}
|
|
115
|
-
`,
|
|
116
|
-
)
|
|
117
|
-
})
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
describe('watchSetUserToken', async () => {
|
|
121
|
-
test('default', async () => {
|
|
122
|
-
const receivedSets: Array<{
|
|
123
|
-
args: actions.fee.watchSetUserToken.Args
|
|
124
|
-
log: actions.fee.watchSetUserToken.Log
|
|
125
|
-
}> = []
|
|
126
|
-
|
|
127
|
-
// Start watching for user token set events
|
|
128
|
-
const unwatch = actions.fee.watchSetUserToken(clientWithAccount, {
|
|
129
|
-
onUserTokenSet: (args, log) => {
|
|
130
|
-
receivedSets.push({ args, log })
|
|
131
|
-
},
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
// Set token for account2
|
|
136
|
-
await writeContractSync(clientWithAccount, {
|
|
137
|
-
abi: Abis.tip20,
|
|
138
|
-
address: '0x20c0000000000000000000000000000000000001',
|
|
139
|
-
functionName: 'transfer',
|
|
140
|
-
args: [account2.address, parseUnits('1', 6)],
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
144
|
-
account: account2,
|
|
145
|
-
token: '0x20c0000000000000000000000000000000000001',
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
// Set token for account3
|
|
149
|
-
await writeContractSync(clientWithAccount, {
|
|
150
|
-
abi: Abis.tip20,
|
|
151
|
-
address: '0x20c0000000000000000000000000000000000001',
|
|
152
|
-
functionName: 'transfer',
|
|
153
|
-
args: [account3.address, parseUnits('1', 6)],
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
157
|
-
account: account3,
|
|
158
|
-
token: '0x20c0000000000000000000000000000000000002',
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
await setTimeout(500)
|
|
162
|
-
|
|
163
|
-
expect(receivedSets).toHaveLength(2)
|
|
164
|
-
|
|
165
|
-
expect(receivedSets.at(0)!.args).toMatchInlineSnapshot(`
|
|
166
|
-
{
|
|
167
|
-
"token": "0x20C0000000000000000000000000000000000001",
|
|
168
|
-
"user": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
|
|
169
|
-
}
|
|
170
|
-
`)
|
|
171
|
-
expect(receivedSets.at(1)!.args).toMatchInlineSnapshot(`
|
|
172
|
-
{
|
|
173
|
-
"token": "0x20C0000000000000000000000000000000000002",
|
|
174
|
-
"user": "0x98e503f35D0a019cB0a251aD243a4cCFCF371F46",
|
|
175
|
-
}
|
|
176
|
-
`)
|
|
177
|
-
} finally {
|
|
178
|
-
if (unwatch) unwatch()
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
test('behavior: filter by user address', async () => {
|
|
183
|
-
const receivedSets: Array<{
|
|
184
|
-
args: actions.fee.watchSetUserToken.Args
|
|
185
|
-
log: actions.fee.watchSetUserToken.Log
|
|
186
|
-
}> = []
|
|
187
|
-
|
|
188
|
-
// Start watching for user token set events only for account2
|
|
189
|
-
const unwatch = actions.fee.watchSetUserToken(clientWithAccount, {
|
|
190
|
-
args: {
|
|
191
|
-
user: account2.address,
|
|
192
|
-
},
|
|
193
|
-
onUserTokenSet: (args, log) => {
|
|
194
|
-
receivedSets.push({ args, log })
|
|
195
|
-
},
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
try {
|
|
199
|
-
// Transfer gas to accounts
|
|
200
|
-
await writeContractSync(clientWithAccount, {
|
|
201
|
-
abi: Abis.tip20,
|
|
202
|
-
address: '0x20c0000000000000000000000000000000000001',
|
|
203
|
-
functionName: 'transfer',
|
|
204
|
-
args: [account2.address, parseUnits('1', 6)],
|
|
205
|
-
})
|
|
206
|
-
|
|
207
|
-
await writeContractSync(clientWithAccount, {
|
|
208
|
-
abi: Abis.tip20,
|
|
209
|
-
address: '0x20c0000000000000000000000000000000000001',
|
|
210
|
-
functionName: 'transfer',
|
|
211
|
-
args: [account3.address, parseUnits('1', 6)],
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
// Set token for account2 (should be captured)
|
|
215
|
-
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
216
|
-
account: account2,
|
|
217
|
-
token: '0x20c0000000000000000000000000000000000001',
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
// Set token for account3 (should NOT be captured)
|
|
221
|
-
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
222
|
-
account: account3,
|
|
223
|
-
token: '0x20c0000000000000000000000000000000000002',
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
// Set token for account2 again (should be captured)
|
|
227
|
-
await actions.fee.setUserTokenSync(clientWithAccount, {
|
|
228
|
-
account: account2,
|
|
229
|
-
feeToken: 1n,
|
|
230
|
-
token: 2n,
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
await setTimeout(500)
|
|
234
|
-
|
|
235
|
-
// Should only receive 2 events (for account2)
|
|
236
|
-
expect(receivedSets).toHaveLength(2)
|
|
237
|
-
|
|
238
|
-
expect(receivedSets.at(0)!.args).toMatchInlineSnapshot(`
|
|
239
|
-
{
|
|
240
|
-
"token": "0x20C0000000000000000000000000000000000001",
|
|
241
|
-
"user": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
|
|
242
|
-
}
|
|
243
|
-
`)
|
|
244
|
-
expect(receivedSets.at(1)!.args).toMatchInlineSnapshot(`
|
|
245
|
-
{
|
|
246
|
-
"token": "0x20C0000000000000000000000000000000000002",
|
|
247
|
-
"user": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
|
|
248
|
-
}
|
|
249
|
-
`)
|
|
250
|
-
|
|
251
|
-
// Verify all received events are for account2
|
|
252
|
-
for (const set of receivedSets) {
|
|
253
|
-
expect(set.args.user).toBe(account2.address)
|
|
254
|
-
}
|
|
255
|
-
} finally {
|
|
256
|
-
if (unwatch) unwatch()
|
|
257
|
-
}
|
|
258
|
-
})
|
|
259
|
-
})
|