tempo.ts 0.10.2 → 0.10.4
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 +12 -0
- package/dist/chains.d.ts +3 -0
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +5 -1
- package/dist/chains.js.map +1 -1
- 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/viem/Chain.d.ts +0 -6
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Chain.js +0 -6
- package/dist/viem/Chain.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/chains.ts +5 -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/viem/Chain.ts +0 -6
- 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,144 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useChainId, useConfig } from 'wagmi';
|
|
3
|
+
import { useQuery } from 'wagmi/query';
|
|
4
|
+
import { getNonce, getNonceKeyCount, watchActiveKeyCountChanged, watchNonceIncremented, } from '../Actions/nonce.js';
|
|
5
|
+
/**
|
|
6
|
+
* Hook for getting the nonce for an account and nonce key.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { Hooks } from 'tempo.ts/wagmi'
|
|
11
|
+
*
|
|
12
|
+
* function App() {
|
|
13
|
+
* const { data, isLoading } = Hooks.nonce.useNonce({
|
|
14
|
+
* account: '0x...',
|
|
15
|
+
* nonceKey: 1n,
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* if (isLoading) return <div>Loading...</div>
|
|
19
|
+
* return <div>Nonce: {data?.toString()}</div>
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @param parameters - Parameters.
|
|
24
|
+
* @returns Query result with nonce value.
|
|
25
|
+
*/
|
|
26
|
+
export function useNonce(parameters = {}) {
|
|
27
|
+
const { account, nonceKey, query = {} } = parameters;
|
|
28
|
+
const config = useConfig(parameters);
|
|
29
|
+
const chainId = useChainId({ config });
|
|
30
|
+
const options = getNonce.queryOptions(config, {
|
|
31
|
+
...parameters,
|
|
32
|
+
chainId: parameters.chainId ?? chainId,
|
|
33
|
+
query: undefined,
|
|
34
|
+
});
|
|
35
|
+
const enabled = Boolean(account && nonceKey !== undefined && (query.enabled ?? true));
|
|
36
|
+
return useQuery({ ...query, ...options, enabled });
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Hook for getting the number of active nonce keys for an account.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* import { Hooks } from 'tempo.ts/wagmi'
|
|
44
|
+
*
|
|
45
|
+
* function App() {
|
|
46
|
+
* const { data, isLoading } = Hooks.nonce.useNonceKeyCount({
|
|
47
|
+
* account: '0x...',
|
|
48
|
+
* })
|
|
49
|
+
*
|
|
50
|
+
* if (isLoading) return <div>Loading...</div>
|
|
51
|
+
* return <div>Active keys: {data?.toString()}</div>
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @param parameters - Parameters.
|
|
56
|
+
* @returns Query result with active nonce key count.
|
|
57
|
+
*/
|
|
58
|
+
export function useNonceKeyCount(parameters = {}) {
|
|
59
|
+
const { account, query = {} } = parameters;
|
|
60
|
+
const config = useConfig(parameters);
|
|
61
|
+
const chainId = useChainId({ config });
|
|
62
|
+
const options = getNonceKeyCount.queryOptions(config, {
|
|
63
|
+
...parameters,
|
|
64
|
+
chainId: parameters.chainId ?? chainId,
|
|
65
|
+
query: undefined,
|
|
66
|
+
});
|
|
67
|
+
const enabled = Boolean(account && (query.enabled ?? true));
|
|
68
|
+
return useQuery({ ...query, ...options, enabled });
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Hook for watching nonce incremented events.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```tsx
|
|
75
|
+
* import { Hooks } from 'tempo.ts/wagmi'
|
|
76
|
+
*
|
|
77
|
+
* function App() {
|
|
78
|
+
* Hooks.nonce.useWatchNonceIncremented({
|
|
79
|
+
* onNonceIncremented(args, log) {
|
|
80
|
+
* console.log('Nonce incremented:', args)
|
|
81
|
+
* },
|
|
82
|
+
* })
|
|
83
|
+
*
|
|
84
|
+
* return <div>Watching for nonce increments...</div>
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @param parameters - Parameters.
|
|
89
|
+
*/
|
|
90
|
+
export function useWatchNonceIncremented(parameters = {}) {
|
|
91
|
+
const { enabled = true, onNonceIncremented, ...rest } = parameters;
|
|
92
|
+
const config = useConfig({ config: parameters.config });
|
|
93
|
+
const configChainId = useChainId({ config });
|
|
94
|
+
const chainId = parameters.chainId ?? configChainId;
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (!enabled)
|
|
97
|
+
return;
|
|
98
|
+
if (!onNonceIncremented)
|
|
99
|
+
return;
|
|
100
|
+
return watchNonceIncremented(config, {
|
|
101
|
+
...rest,
|
|
102
|
+
chainId,
|
|
103
|
+
onNonceIncremented,
|
|
104
|
+
});
|
|
105
|
+
}, [config, enabled, onNonceIncremented, chainId, rest]);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Hook for watching active key count changed events.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```tsx
|
|
112
|
+
* import { Hooks } from 'tempo.ts/wagmi'
|
|
113
|
+
*
|
|
114
|
+
* function App() {
|
|
115
|
+
* Hooks.nonce.useWatchActiveKeyCountChanged({
|
|
116
|
+
* onActiveKeyCountChanged(args, log) {
|
|
117
|
+
* console.log('Active key count changed:', args)
|
|
118
|
+
* },
|
|
119
|
+
* })
|
|
120
|
+
*
|
|
121
|
+
* return <div>Watching for active key count changes...</div>
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @param parameters - Parameters.
|
|
126
|
+
*/
|
|
127
|
+
export function useWatchActiveKeyCountChanged(parameters = {}) {
|
|
128
|
+
const { enabled = true, onActiveKeyCountChanged, ...rest } = parameters;
|
|
129
|
+
const config = useConfig({ config: parameters.config });
|
|
130
|
+
const configChainId = useChainId({ config });
|
|
131
|
+
const chainId = parameters.chainId ?? configChainId;
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (!enabled)
|
|
134
|
+
return;
|
|
135
|
+
if (!onActiveKeyCountChanged)
|
|
136
|
+
return;
|
|
137
|
+
return watchActiveKeyCountChanged(config, {
|
|
138
|
+
...rest,
|
|
139
|
+
chainId,
|
|
140
|
+
onActiveKeyCountChanged,
|
|
141
|
+
});
|
|
142
|
+
}, [config, enabled, onActiveKeyCountChanged, chainId, rest]);
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=nonce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nonce.js","sourceRoot":"","sources":["../../../src/wagmi/Hooks/nonce.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAE7C,OAAO,EAA2B,QAAQ,EAAE,MAAM,aAAa,CAAA;AAG/D,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,qBAAqB,CAAA;AAE5B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,QAAQ,CAGtB,aAAsD,EAAE;IACxD,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,GAAG,EAAE,EAAE,GAAG,UAAU,CAAA;IAEpD,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,CAAA;IACpC,MAAM,OAAO,GAAG,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAEtC,MAAM,OAAO,GAAG,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE;QAC5C,GAAG,UAAU;QACb,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,OAAO;QACtC,KAAK,EAAE,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
13
|
http: ['https://rpc.devnet.tempo.xyz'],
|
|
14
|
+
webSocket: ['wss://rpc.devnet.tempo.xyz'],
|
|
14
15
|
},
|
|
15
16
|
},
|
|
16
17
|
})
|
|
@@ -43,7 +44,10 @@ export const tempoTestnet = /*#__PURE__*/ Chain.define({
|
|
|
43
44
|
decimals: 6,
|
|
44
45
|
},
|
|
45
46
|
rpcUrls: {
|
|
46
|
-
default: {
|
|
47
|
+
default: {
|
|
48
|
+
http: ['https://rpc.testnet.tempo.xyz'],
|
|
49
|
+
webSocket: ['wss://rpc.testnet.tempo.xyz'],
|
|
50
|
+
},
|
|
47
51
|
},
|
|
48
52
|
})
|
|
49
53
|
|
|
@@ -3,6 +3,7 @@ export * as amm from './amm.js'
|
|
|
3
3
|
export * as dex from './dex.js'
|
|
4
4
|
export * as faucet from './faucet.js'
|
|
5
5
|
export * as fee from './fee.js'
|
|
6
|
+
export * as nonce from './nonce.js'
|
|
6
7
|
export * as policy from './policy.js'
|
|
7
8
|
export * as reward from './reward.js'
|
|
8
9
|
export * as token from './token.js'
|
|
@@ -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
|
+
})
|