tempo.ts 0.10.2 → 0.10.3
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 +6 -0
- package/dist/viem/Actions/index.d.ts +1 -0
- package/dist/viem/Actions/index.d.ts.map +1 -1
- package/dist/viem/Actions/index.js +1 -0
- package/dist/viem/Actions/index.js.map +1 -1
- package/dist/viem/Actions/nonce.d.ts +257 -0
- package/dist/viem/Actions/nonce.d.ts.map +1 -0
- package/dist/viem/Actions/nonce.js +226 -0
- package/dist/viem/Actions/nonce.js.map +1 -0
- package/dist/viem/Addresses.d.ts +1 -0
- package/dist/viem/Addresses.d.ts.map +1 -1
- package/dist/viem/Addresses.js +1 -0
- package/dist/viem/Addresses.js.map +1 -1
- package/dist/wagmi/Actions/index.d.ts +1 -0
- package/dist/wagmi/Actions/index.d.ts.map +1 -1
- package/dist/wagmi/Actions/index.js +1 -0
- package/dist/wagmi/Actions/index.js.map +1 -1
- package/dist/wagmi/Actions/nonce.d.ts +147 -0
- package/dist/wagmi/Actions/nonce.d.ts.map +1 -0
- package/dist/wagmi/Actions/nonce.js +169 -0
- package/dist/wagmi/Actions/nonce.js.map +1 -0
- package/dist/wagmi/Hooks/index.d.ts +1 -0
- package/dist/wagmi/Hooks/index.d.ts.map +1 -1
- package/dist/wagmi/Hooks/index.js +1 -0
- package/dist/wagmi/Hooks/index.js.map +1 -1
- package/dist/wagmi/Hooks/nonce.d.ts +110 -0
- package/dist/wagmi/Hooks/nonce.d.ts.map +1 -0
- package/dist/wagmi/Hooks/nonce.js +144 -0
- package/dist/wagmi/Hooks/nonce.js.map +1 -0
- package/package.json +1 -1
- package/src/viem/Actions/index.ts +1 -0
- package/src/viem/Actions/nonce.test.ts +193 -0
- package/src/viem/Actions/nonce.ts +345 -0
- package/src/viem/Addresses.ts +1 -0
- package/src/viem/Chain.test.ts +9 -9
- package/src/wagmi/Actions/index.ts +1 -0
- package/src/wagmi/Actions/nonce.test.ts +141 -0
- package/src/wagmi/Actions/nonce.ts +271 -0
- package/src/wagmi/Hooks/index.ts +1 -0
- package/src/wagmi/Hooks/nonce.test.ts +207 -0
- package/src/wagmi/Hooks/nonce.ts +230 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { setTimeout } from 'node:timers/promises'
|
|
2
|
+
import { afterEach, describe, expect, test } from 'vitest'
|
|
3
|
+
import { rpcUrl } from '../../../test/config.js'
|
|
4
|
+
import { accounts, clientWithAccount } from '../../../test/viem/config.js'
|
|
5
|
+
import * as actions from './index.js'
|
|
6
|
+
|
|
7
|
+
const account = accounts[0]
|
|
8
|
+
const account2 = accounts[1]
|
|
9
|
+
|
|
10
|
+
afterEach(async () => {
|
|
11
|
+
await fetch(`${rpcUrl}/restart`)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
describe('getNonce', () => {
|
|
15
|
+
test('default', async () => {
|
|
16
|
+
// Get nonce for an account with previously unused noncekey
|
|
17
|
+
const nonce = await actions.nonce.getNonce(clientWithAccount, {
|
|
18
|
+
account: account.address,
|
|
19
|
+
nonceKey: 1n,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
expect(nonce).toBe(1n)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('behavior: different nonce keys are independent', async () => {
|
|
26
|
+
let nonce1 = await actions.nonce.getNonce(clientWithAccount, {
|
|
27
|
+
account: account.address,
|
|
28
|
+
nonceKey: 1n,
|
|
29
|
+
})
|
|
30
|
+
let nonce2 = await actions.nonce.getNonce(clientWithAccount, {
|
|
31
|
+
account: account.address,
|
|
32
|
+
nonceKey: 2n,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
expect(nonce1).toBe(1n)
|
|
36
|
+
expect(nonce2).toBe(1n)
|
|
37
|
+
|
|
38
|
+
await actions.token.transferSync(clientWithAccount, {
|
|
39
|
+
to: account2.address,
|
|
40
|
+
amount: 1n,
|
|
41
|
+
token: 1n,
|
|
42
|
+
nonceKey: 2n,
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
nonce1 = await actions.nonce.getNonce(clientWithAccount, {
|
|
46
|
+
account: account.address,
|
|
47
|
+
nonceKey: 1n,
|
|
48
|
+
})
|
|
49
|
+
nonce2 = await actions.nonce.getNonce(clientWithAccount, {
|
|
50
|
+
account: account.address,
|
|
51
|
+
nonceKey: 2n,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
// nonceKey 2 should be incremented to 2
|
|
55
|
+
expect(nonce1).toBe(1n)
|
|
56
|
+
expect(nonce2).toBe(2n)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('behavior: different accounts are independent', async () => {
|
|
60
|
+
const nonce1 = await actions.nonce.getNonce(clientWithAccount, {
|
|
61
|
+
account: account.address,
|
|
62
|
+
nonceKey: 1n,
|
|
63
|
+
})
|
|
64
|
+
const nonce2 = await actions.nonce.getNonce(clientWithAccount, {
|
|
65
|
+
account: account2.address,
|
|
66
|
+
nonceKey: 1n,
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
// Both should return bigint values
|
|
70
|
+
expect(nonce1).toBe(1n)
|
|
71
|
+
expect(nonce2).toBe(1n)
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe('getNonceKeyCount', () => {
|
|
76
|
+
test('default', async () => {
|
|
77
|
+
// Get active nonce key count for a fresh account
|
|
78
|
+
const count = await actions.nonce.getNonceKeyCount(clientWithAccount, {
|
|
79
|
+
account: account.address,
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
// Fresh account should have 0 active nonce keys
|
|
83
|
+
expect(count).toBe(0n)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('behavior: different accounts are independent', async () => {
|
|
87
|
+
const count1 = await actions.nonce.getNonceKeyCount(clientWithAccount, {
|
|
88
|
+
account: account.address,
|
|
89
|
+
})
|
|
90
|
+
const count2 = await actions.nonce.getNonceKeyCount(clientWithAccount, {
|
|
91
|
+
account: account2.address,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
// Both should be 0 for fresh accounts
|
|
95
|
+
expect(count1).toBe(0n)
|
|
96
|
+
expect(count2).toBe(0n)
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
describe('watchNonceIncremented', () => {
|
|
101
|
+
test('default', async () => {
|
|
102
|
+
const events: Array<{
|
|
103
|
+
args: actions.nonce.watchNonceIncremented.Args
|
|
104
|
+
log: actions.nonce.watchNonceIncremented.Log
|
|
105
|
+
}> = []
|
|
106
|
+
|
|
107
|
+
const unwatch = actions.nonce.watchNonceIncremented(clientWithAccount, {
|
|
108
|
+
onNonceIncremented: (args, log) => {
|
|
109
|
+
events.push({ args, log })
|
|
110
|
+
},
|
|
111
|
+
args: {
|
|
112
|
+
account: account.address,
|
|
113
|
+
nonceKey: 5n,
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
// Have to manually set nonce because eth_FillTransaction does not support nonce keys
|
|
119
|
+
await actions.token.transferSync(clientWithAccount, {
|
|
120
|
+
to: account2.address,
|
|
121
|
+
amount: 1n,
|
|
122
|
+
token: 1n,
|
|
123
|
+
nonceKey: 5n,
|
|
124
|
+
nonce: 0,
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
await actions.token.transferSync(clientWithAccount, {
|
|
128
|
+
to: account2.address,
|
|
129
|
+
amount: 1n,
|
|
130
|
+
token: 1n,
|
|
131
|
+
nonceKey: 5n,
|
|
132
|
+
nonce: 1,
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
await setTimeout(1000)
|
|
136
|
+
|
|
137
|
+
expect(events).toHaveLength(2)
|
|
138
|
+
expect(events[0]!.args.account).toBe(account.address)
|
|
139
|
+
expect(events[0]!.args.nonceKey).toBe(5n)
|
|
140
|
+
expect(events[0]!.args.newNonce).toBe(1n)
|
|
141
|
+
expect(events[1]!.args.newNonce).toBe(2n)
|
|
142
|
+
} finally {
|
|
143
|
+
unwatch()
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
describe('watchActiveKeyCountChanged', () => {
|
|
149
|
+
test('default', async () => {
|
|
150
|
+
const events: Array<{
|
|
151
|
+
args: actions.nonce.watchActiveKeyCountChanged.Args
|
|
152
|
+
log: actions.nonce.watchActiveKeyCountChanged.Log
|
|
153
|
+
}> = []
|
|
154
|
+
|
|
155
|
+
const unwatch = actions.nonce.watchActiveKeyCountChanged(
|
|
156
|
+
clientWithAccount,
|
|
157
|
+
{
|
|
158
|
+
onActiveKeyCountChanged: (args, log) => {
|
|
159
|
+
events.push({ args, log })
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
// First use of nonceKey 10 should increment active key count
|
|
166
|
+
await actions.token.transferSync(clientWithAccount, {
|
|
167
|
+
to: account2.address,
|
|
168
|
+
amount: 1n,
|
|
169
|
+
token: 1n,
|
|
170
|
+
nonceKey: 10n,
|
|
171
|
+
nonce: 0,
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
// First use of nonceKey 11 should increment again
|
|
175
|
+
await actions.token.transferSync(clientWithAccount, {
|
|
176
|
+
to: account2.address,
|
|
177
|
+
amount: 1n,
|
|
178
|
+
token: 1n,
|
|
179
|
+
nonceKey: 11n,
|
|
180
|
+
nonce: 0,
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
await setTimeout(1000)
|
|
184
|
+
|
|
185
|
+
expect(events).toHaveLength(2)
|
|
186
|
+
expect(events[0]!.args.account).toBe(account.address)
|
|
187
|
+
expect(events[0]!.args.newCount).toBe(1n)
|
|
188
|
+
expect(events[1]!.args.newCount).toBe(2n)
|
|
189
|
+
} finally {
|
|
190
|
+
unwatch()
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
})
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Account,
|
|
3
|
+
Address,
|
|
4
|
+
Chain,
|
|
5
|
+
Client,
|
|
6
|
+
ExtractAbiItem,
|
|
7
|
+
GetEventArgs,
|
|
8
|
+
ReadContractReturnType,
|
|
9
|
+
Transport,
|
|
10
|
+
Log as viem_Log,
|
|
11
|
+
WatchContractEventParameters,
|
|
12
|
+
} from 'viem'
|
|
13
|
+
import { readContract, watchContractEvent } from 'viem/actions'
|
|
14
|
+
import type { UnionOmit } from '../../internal/types.js'
|
|
15
|
+
import * as Abis from '../Abis.js'
|
|
16
|
+
import * as Addresses from '../Addresses.js'
|
|
17
|
+
import type { ReadParameters } from '../internal/types.js'
|
|
18
|
+
import { defineCall } from '../internal/utils.js'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Gets the nonce for an account and nonce key.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { createClient, http } from 'viem'
|
|
26
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
27
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
28
|
+
*
|
|
29
|
+
* const client = createClient({
|
|
30
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
31
|
+
* transport: http(),
|
|
32
|
+
* })
|
|
33
|
+
*
|
|
34
|
+
* const nonce = await Actions.nonce.getNonce(client, {
|
|
35
|
+
* account: '0x...',
|
|
36
|
+
* nonceKey: 1n,
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param client - Client.
|
|
41
|
+
* @param parameters - Parameters.
|
|
42
|
+
* @returns The nonce value.
|
|
43
|
+
*/
|
|
44
|
+
export async function getNonce<
|
|
45
|
+
chain extends Chain | undefined,
|
|
46
|
+
account extends Account | undefined,
|
|
47
|
+
>(
|
|
48
|
+
client: Client<Transport, chain, account>,
|
|
49
|
+
parameters: getNonce.Parameters,
|
|
50
|
+
): Promise<getNonce.ReturnValue> {
|
|
51
|
+
return readContract(client, {
|
|
52
|
+
...parameters,
|
|
53
|
+
...getNonce.call(parameters),
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export namespace getNonce {
|
|
58
|
+
export type Parameters = ReadParameters & Args
|
|
59
|
+
|
|
60
|
+
export type Args = {
|
|
61
|
+
/** Account address. */
|
|
62
|
+
account: Address
|
|
63
|
+
/** Nonce key (must be > 0, key 0 is reserved for protocol nonces). */
|
|
64
|
+
nonceKey: bigint
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type ReturnValue = ReadContractReturnType<
|
|
68
|
+
typeof Abis.nonce,
|
|
69
|
+
'getNonce',
|
|
70
|
+
never
|
|
71
|
+
>
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Defines a call to the `getNonce` function.
|
|
75
|
+
*
|
|
76
|
+
* Can be passed as a parameter to:
|
|
77
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
78
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
79
|
+
* - [`multicall`](https://viem.sh/docs/contract/multicall): execute multiple calls in parallel
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { createClient, http } from 'viem'
|
|
84
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
85
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
86
|
+
*
|
|
87
|
+
* const client = createClient({
|
|
88
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
89
|
+
* transport: http(),
|
|
90
|
+
* })
|
|
91
|
+
*
|
|
92
|
+
* const result = await client.multicall({
|
|
93
|
+
* contracts: [
|
|
94
|
+
* Actions.nonce.getNonce.call({ account: '0x...', nonceKey: 1n }),
|
|
95
|
+
* Actions.nonce.getNonce.call({ account: '0x...', nonceKey: 2n }),
|
|
96
|
+
* ],
|
|
97
|
+
* })
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @param args - Arguments.
|
|
101
|
+
* @returns The call.
|
|
102
|
+
*/
|
|
103
|
+
export function call(args: Args) {
|
|
104
|
+
const { account, nonceKey } = args
|
|
105
|
+
return defineCall({
|
|
106
|
+
address: Addresses.nonceManager,
|
|
107
|
+
abi: Abis.nonce,
|
|
108
|
+
args: [account, nonceKey],
|
|
109
|
+
functionName: 'getNonce',
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Gets the number of active nonce keys for an account.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* import { createClient, http } from 'viem'
|
|
120
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
121
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
122
|
+
*
|
|
123
|
+
* const client = createClient({
|
|
124
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
125
|
+
* transport: http(),
|
|
126
|
+
* })
|
|
127
|
+
*
|
|
128
|
+
* const count = await Actions.nonce.getNonceKeyCount(client, {
|
|
129
|
+
* account: '0x...',
|
|
130
|
+
* })
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @param client - Client.
|
|
134
|
+
* @param parameters - Parameters.
|
|
135
|
+
* @returns The number of active nonce keys.
|
|
136
|
+
*/
|
|
137
|
+
export async function getNonceKeyCount<
|
|
138
|
+
chain extends Chain | undefined,
|
|
139
|
+
account extends Account | undefined,
|
|
140
|
+
>(
|
|
141
|
+
client: Client<Transport, chain, account>,
|
|
142
|
+
parameters: getNonceKeyCount.Parameters,
|
|
143
|
+
): Promise<getNonceKeyCount.ReturnValue> {
|
|
144
|
+
return readContract(client, {
|
|
145
|
+
...parameters,
|
|
146
|
+
...getNonceKeyCount.call(parameters),
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export namespace getNonceKeyCount {
|
|
151
|
+
export type Parameters = ReadParameters & Args
|
|
152
|
+
|
|
153
|
+
export type Args = {
|
|
154
|
+
/** Account address. */
|
|
155
|
+
account: Address
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export type ReturnValue = ReadContractReturnType<
|
|
159
|
+
typeof Abis.nonce,
|
|
160
|
+
'getActiveNonceKeyCount',
|
|
161
|
+
never
|
|
162
|
+
>
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Defines a call to the `getNonceKeyCount` function.
|
|
166
|
+
*
|
|
167
|
+
* Can be passed as a parameter to:
|
|
168
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
169
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
170
|
+
* - [`multicall`](https://viem.sh/docs/contract/multicall): execute multiple calls in parallel
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* import { createClient, http } from 'viem'
|
|
175
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
176
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
177
|
+
*
|
|
178
|
+
* const client = createClient({
|
|
179
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
180
|
+
* transport: http(),
|
|
181
|
+
* })
|
|
182
|
+
*
|
|
183
|
+
* const result = await client.multicall({
|
|
184
|
+
* contracts: [
|
|
185
|
+
* Actions.nonce.getNonceKeyCount.call({ account: '0x...' }),
|
|
186
|
+
* Actions.nonce.getNonceKeyCount.call({ account: '0x...' }),
|
|
187
|
+
* ],
|
|
188
|
+
* })
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* @param args - Arguments.
|
|
192
|
+
* @returns The call.
|
|
193
|
+
*/
|
|
194
|
+
export function call(args: Args) {
|
|
195
|
+
const { account } = args
|
|
196
|
+
return defineCall({
|
|
197
|
+
address: Addresses.nonceManager,
|
|
198
|
+
abi: Abis.nonce,
|
|
199
|
+
args: [account],
|
|
200
|
+
functionName: 'getActiveNonceKeyCount',
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Watches for nonce incremented events.
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* import { createClient, http } from 'viem'
|
|
211
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
212
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
213
|
+
*
|
|
214
|
+
* const client = createClient({
|
|
215
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
216
|
+
* transport: http(),
|
|
217
|
+
* })
|
|
218
|
+
*
|
|
219
|
+
* const unwatch = Actions.nonce.watchNonceIncremented(client, {
|
|
220
|
+
* onNonceIncremented: (args, log) => {
|
|
221
|
+
* console.log('Nonce incremented:', args)
|
|
222
|
+
* },
|
|
223
|
+
* })
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @param client - Client.
|
|
227
|
+
* @param parameters - Parameters.
|
|
228
|
+
* @returns A function to unsubscribe from the event.
|
|
229
|
+
*/
|
|
230
|
+
export function watchNonceIncremented<
|
|
231
|
+
chain extends Chain | undefined,
|
|
232
|
+
account extends Account | undefined,
|
|
233
|
+
>(
|
|
234
|
+
client: Client<Transport, chain, account>,
|
|
235
|
+
parameters: watchNonceIncremented.Parameters,
|
|
236
|
+
) {
|
|
237
|
+
const { onNonceIncremented, ...rest } = parameters
|
|
238
|
+
return watchContractEvent(client, {
|
|
239
|
+
...rest,
|
|
240
|
+
address: Addresses.nonceManager,
|
|
241
|
+
abi: Abis.nonce,
|
|
242
|
+
eventName: 'NonceIncremented',
|
|
243
|
+
onLogs: (logs) => {
|
|
244
|
+
for (const log of logs) onNonceIncremented(log.args, log)
|
|
245
|
+
},
|
|
246
|
+
strict: true,
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export declare namespace watchNonceIncremented {
|
|
251
|
+
export type Args = GetEventArgs<
|
|
252
|
+
typeof Abis.nonce,
|
|
253
|
+
'NonceIncremented',
|
|
254
|
+
{ IndexedOnly: false; Required: true }
|
|
255
|
+
>
|
|
256
|
+
|
|
257
|
+
export type Log = viem_Log<
|
|
258
|
+
bigint,
|
|
259
|
+
number,
|
|
260
|
+
false,
|
|
261
|
+
ExtractAbiItem<typeof Abis.nonce, 'NonceIncremented'>,
|
|
262
|
+
true
|
|
263
|
+
>
|
|
264
|
+
|
|
265
|
+
export type Parameters = UnionOmit<
|
|
266
|
+
WatchContractEventParameters<typeof Abis.nonce, 'NonceIncremented', true>,
|
|
267
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
268
|
+
> & {
|
|
269
|
+
/** Callback to invoke when a nonce is incremented. */
|
|
270
|
+
onNonceIncremented: (args: Args, log: Log) => void
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Watches for active key count changed events.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* import { createClient, http } from 'viem'
|
|
280
|
+
* import { tempo } from 'tempo.ts/chains'
|
|
281
|
+
* import { Actions } from 'tempo.ts/viem'
|
|
282
|
+
*
|
|
283
|
+
* const client = createClient({
|
|
284
|
+
* chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
285
|
+
* transport: http(),
|
|
286
|
+
* })
|
|
287
|
+
*
|
|
288
|
+
* const unwatch = Actions.nonce.watchActiveKeyCountChanged(client, {
|
|
289
|
+
* onActiveKeyCountChanged: (args, log) => {
|
|
290
|
+
* console.log('Active key count changed:', args)
|
|
291
|
+
* },
|
|
292
|
+
* })
|
|
293
|
+
* ```
|
|
294
|
+
*
|
|
295
|
+
* @param client - Client.
|
|
296
|
+
* @param parameters - Parameters.
|
|
297
|
+
* @returns A function to unsubscribe from the event.
|
|
298
|
+
*/
|
|
299
|
+
export function watchActiveKeyCountChanged<
|
|
300
|
+
chain extends Chain | undefined,
|
|
301
|
+
account extends Account | undefined,
|
|
302
|
+
>(
|
|
303
|
+
client: Client<Transport, chain, account>,
|
|
304
|
+
parameters: watchActiveKeyCountChanged.Parameters,
|
|
305
|
+
) {
|
|
306
|
+
const { onActiveKeyCountChanged, ...rest } = parameters
|
|
307
|
+
return watchContractEvent(client, {
|
|
308
|
+
...rest,
|
|
309
|
+
address: Addresses.nonceManager,
|
|
310
|
+
abi: Abis.nonce,
|
|
311
|
+
eventName: 'ActiveKeyCountChanged',
|
|
312
|
+
onLogs: (logs) => {
|
|
313
|
+
for (const log of logs) onActiveKeyCountChanged(log.args, log)
|
|
314
|
+
},
|
|
315
|
+
strict: true,
|
|
316
|
+
})
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export declare namespace watchActiveKeyCountChanged {
|
|
320
|
+
export type Args = GetEventArgs<
|
|
321
|
+
typeof Abis.nonce,
|
|
322
|
+
'ActiveKeyCountChanged',
|
|
323
|
+
{ IndexedOnly: false; Required: true }
|
|
324
|
+
>
|
|
325
|
+
|
|
326
|
+
export type Log = viem_Log<
|
|
327
|
+
bigint,
|
|
328
|
+
number,
|
|
329
|
+
false,
|
|
330
|
+
ExtractAbiItem<typeof Abis.nonce, 'ActiveKeyCountChanged'>,
|
|
331
|
+
true
|
|
332
|
+
>
|
|
333
|
+
|
|
334
|
+
export type Parameters = UnionOmit<
|
|
335
|
+
WatchContractEventParameters<
|
|
336
|
+
typeof Abis.nonce,
|
|
337
|
+
'ActiveKeyCountChanged',
|
|
338
|
+
true
|
|
339
|
+
>,
|
|
340
|
+
'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
|
|
341
|
+
> & {
|
|
342
|
+
/** Callback to invoke when the active key count changes. */
|
|
343
|
+
onActiveKeyCountChanged: (args: Args, log: Log) => void
|
|
344
|
+
}
|
|
345
|
+
}
|
package/src/viem/Addresses.ts
CHANGED
|
@@ -2,6 +2,7 @@ export const accountImplementation =
|
|
|
2
2
|
'0x7702c00000000000000000000000000000000000'
|
|
3
3
|
export const accountRegistrar = '0x7702ac0000000000000000000000000000000000'
|
|
4
4
|
export const feeManager = '0xfeec000000000000000000000000000000000000'
|
|
5
|
+
export const nonceManager = '0x4e4F4E4345000000000000000000000000000000'
|
|
5
6
|
export const pathUsd = '0x20c0000000000000000000000000000000000000'
|
|
6
7
|
export const stablecoinExchange = '0xdec0000000000000000000000000000000000000'
|
|
7
8
|
export const tip20Factory = '0x20fc000000000000000000000000000000000000'
|
package/src/viem/Chain.test.ts
CHANGED
|
@@ -14,7 +14,7 @@ describe('chain.prepareTransactionRequest', () => {
|
|
|
14
14
|
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
15
15
|
])
|
|
16
16
|
|
|
17
|
-
expect((requests[0] as any)?.nonceKey).toBe(
|
|
17
|
+
expect((requests[0] as any)?.nonceKey).toBe(undefined)
|
|
18
18
|
expect((requests[1] as any)?.nonceKey).toBeGreaterThan(0n)
|
|
19
19
|
expect((requests[2] as any)?.nonceKey).toBeGreaterThan(0n)
|
|
20
20
|
})
|
|
@@ -25,7 +25,7 @@ describe('chain.prepareTransactionRequest', () => {
|
|
|
25
25
|
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
26
26
|
])
|
|
27
27
|
|
|
28
|
-
expect((requests1[0] as any)?.nonceKey).toBe(
|
|
28
|
+
expect((requests1[0] as any)?.nonceKey).toBe(undefined)
|
|
29
29
|
expect((requests1[1] as any)?.nonceKey).toBeGreaterThan(0n)
|
|
30
30
|
|
|
31
31
|
// Wait for microtask queue to flush
|
|
@@ -37,7 +37,7 @@ describe('chain.prepareTransactionRequest', () => {
|
|
|
37
37
|
])
|
|
38
38
|
|
|
39
39
|
// Counter should have reset
|
|
40
|
-
expect((requests2[0] as any)?.nonceKey).toBe(
|
|
40
|
+
expect((requests2[0] as any)?.nonceKey).toBe(undefined)
|
|
41
41
|
expect((requests2[1] as any)?.nonceKey).toBeGreaterThan(0n)
|
|
42
42
|
})
|
|
43
43
|
|
|
@@ -55,13 +55,13 @@ describe('chain.prepareTransactionRequest', () => {
|
|
|
55
55
|
])
|
|
56
56
|
|
|
57
57
|
expect((requests[0] as any)?.nonceKey).toBe(42n)
|
|
58
|
-
expect((requests[1] as any)?.nonceKey).toBe(
|
|
58
|
+
expect((requests[1] as any)?.nonceKey).toBe(undefined)
|
|
59
59
|
expect((requests[2] as any)?.nonceKey).toBe(100n)
|
|
60
60
|
})
|
|
61
61
|
|
|
62
62
|
test('behavior: default nonceKey when feePayer is not true', async () => {
|
|
63
63
|
const request = await chain.prepareTransactionRequest({} as never)
|
|
64
|
-
expect((request as any)?.nonceKey).toBe(
|
|
64
|
+
expect((request as any)?.nonceKey).toBe(undefined)
|
|
65
65
|
})
|
|
66
66
|
|
|
67
67
|
test('behavior: nonce with sequential nonceKey', async () => {
|
|
@@ -73,7 +73,7 @@ describe('chain.prepareTransactionRequest', () => {
|
|
|
73
73
|
|
|
74
74
|
// Note: 0n is falsy, so first request has nonce undefined
|
|
75
75
|
expect((requests[0] as any)?.nonce).toBe(undefined)
|
|
76
|
-
expect((requests[0] as any)?.nonceKey).toBe(
|
|
76
|
+
expect((requests[0] as any)?.nonceKey).toBe(undefined)
|
|
77
77
|
|
|
78
78
|
// nonceKey >= 1n is truthy, so nonce is 0
|
|
79
79
|
expect((requests[1] as any)?.nonce).toBe(0)
|
|
@@ -89,12 +89,12 @@ describe('chain.prepareTransactionRequest', () => {
|
|
|
89
89
|
nonce: 123,
|
|
90
90
|
} as never)
|
|
91
91
|
expect((request as any)?.nonce).toBe(123)
|
|
92
|
-
expect((request as any)?.nonceKey).toBe(
|
|
92
|
+
expect((request as any)?.nonceKey).toBe(undefined)
|
|
93
93
|
})
|
|
94
94
|
|
|
95
95
|
test('behavior: default nonceKey is 0n (falsy)', async () => {
|
|
96
96
|
const request = await chain.prepareTransactionRequest({} as never)
|
|
97
|
-
expect((request as any)?.nonceKey).toBe(
|
|
97
|
+
expect((request as any)?.nonceKey).toBe(undefined)
|
|
98
98
|
expect((request as any)?.nonce).toBe(undefined)
|
|
99
99
|
})
|
|
100
100
|
|
|
@@ -132,7 +132,7 @@ describe('chain.prepareTransactionRequest', () => {
|
|
|
132
132
|
to: '0x0000000000000000000000000000000000000000',
|
|
133
133
|
}),
|
|
134
134
|
])
|
|
135
|
-
expect(request.nonceKey).toBe(
|
|
135
|
+
expect(request.nonceKey).toBe(undefined)
|
|
136
136
|
expect(request2.nonceKey).toBeGreaterThan(0n)
|
|
137
137
|
expect(request3.nonceKey).toBeGreaterThan(0n)
|
|
138
138
|
})
|
|
@@ -2,6 +2,7 @@ export * as amm from './amm.js'
|
|
|
2
2
|
export * as dex from './dex.js'
|
|
3
3
|
export * as faucet from './faucet.js'
|
|
4
4
|
export * as fee from './fee.js'
|
|
5
|
+
export * as nonce from './nonce.js'
|
|
5
6
|
export * as policy from './policy.js'
|
|
6
7
|
export * as reward from './reward.js'
|
|
7
8
|
export * as token from './token.js'
|