@wagmi/core 3.0.2 → 3.1.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/dist/esm/exports/internal.js.map +1 -1
- package/dist/esm/exports/query.js +1 -1
- package/dist/esm/exports/query.js.map +1 -1
- package/dist/esm/exports/tempo.js +9 -0
- package/dist/esm/exports/tempo.js.map +1 -0
- package/dist/esm/tempo/Actions/amm.js +469 -0
- package/dist/esm/tempo/Actions/amm.js.map +1 -0
- package/dist/esm/tempo/Actions/dex.js +983 -0
- package/dist/esm/tempo/Actions/dex.js.map +1 -0
- package/dist/esm/tempo/Actions/faucet.js +64 -0
- package/dist/esm/tempo/Actions/faucet.js.map +1 -0
- package/dist/esm/tempo/Actions/fee.js +160 -0
- package/dist/esm/tempo/Actions/fee.js.map +1 -0
- package/dist/esm/tempo/Actions/index.js +11 -0
- package/dist/esm/tempo/Actions/index.js.map +1 -0
- package/dist/esm/tempo/Actions/nonce.js +176 -0
- package/dist/esm/tempo/Actions/nonce.js.map +1 -0
- package/dist/esm/tempo/Actions/policy.js +532 -0
- package/dist/esm/tempo/Actions/policy.js.map +1 -0
- package/dist/esm/tempo/Actions/reward.js +384 -0
- package/dist/esm/tempo/Actions/reward.js.map +1 -0
- package/dist/esm/tempo/Actions/token.js +1717 -0
- package/dist/esm/tempo/Actions/token.js.map +1 -0
- package/dist/esm/tempo/Actions/utils.js +2 -0
- package/dist/esm/tempo/Actions/utils.js.map +1 -0
- package/dist/esm/tempo/Connectors.js +534 -0
- package/dist/esm/tempo/Connectors.js.map +1 -0
- package/dist/esm/tempo/KeyManager.js +106 -0
- package/dist/esm/tempo/KeyManager.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/exports/internal.d.ts +1 -1
- package/dist/types/exports/internal.d.ts.map +1 -1
- package/dist/types/exports/query.d.ts +1 -1
- package/dist/types/exports/query.d.ts.map +1 -1
- package/dist/types/exports/tempo.d.ts +5 -0
- package/dist/types/exports/tempo.d.ts.map +1 -0
- package/dist/types/tempo/Actions/amm.d.ts +418 -0
- package/dist/types/tempo/Actions/amm.d.ts.map +1 -0
- package/dist/types/tempo/Actions/dex.d.ts +858 -0
- package/dist/types/tempo/Actions/dex.d.ts.map +1 -0
- package/dist/types/tempo/Actions/faucet.d.ts +70 -0
- package/dist/types/tempo/Actions/faucet.d.ts.map +1 -0
- package/dist/types/tempo/Actions/fee.d.ts +141 -0
- package/dist/types/tempo/Actions/fee.d.ts.map +1 -0
- package/dist/types/tempo/Actions/index.d.ts +10 -0
- package/dist/types/tempo/Actions/index.d.ts.map +1 -0
- package/dist/types/tempo/Actions/nonce.d.ts +150 -0
- package/dist/types/tempo/Actions/nonce.d.ts.map +1 -0
- package/dist/types/tempo/Actions/policy.d.ts +478 -0
- package/dist/types/tempo/Actions/policy.d.ts.map +1 -0
- package/dist/types/tempo/Actions/reward.d.ts +340 -0
- package/dist/types/tempo/Actions/reward.d.ts.map +1 -0
- package/dist/types/tempo/Actions/token.d.ts +1531 -0
- package/dist/types/tempo/Actions/token.d.ts.map +1 -0
- package/dist/types/tempo/Actions/utils.d.ts +9 -0
- package/dist/types/tempo/Actions/utils.d.ts.map +1 -0
- package/dist/types/tempo/Connectors.d.ts +99 -0
- package/dist/types/tempo/Connectors.d.ts.map +1 -0
- package/dist/types/tempo/KeyManager.d.ts +71 -0
- package/dist/types/tempo/KeyManager.d.ts.map +1 -0
- package/dist/types/types/utils.d.ts +16 -0
- package/dist/types/types/utils.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +14 -2
- package/src/exports/internal.ts +3 -0
- package/src/exports/query.ts +4 -1
- package/src/exports/tempo.ts +14 -0
- package/src/tempo/Actions/amm.ts +719 -0
- package/src/tempo/Actions/dex.ts +1571 -0
- package/src/tempo/Actions/faucet.ts +95 -0
- package/src/tempo/Actions/fee.ts +259 -0
- package/src/tempo/Actions/index.ts +10 -0
- package/src/tempo/Actions/nonce.ts +283 -0
- package/src/tempo/Actions/policy.ts +827 -0
- package/src/tempo/Actions/reward.ts +621 -0
- package/src/tempo/Actions/token.ts +2598 -0
- package/src/tempo/Actions/utils.ts +26 -0
- package/src/tempo/Connectors.ts +762 -0
- package/src/tempo/KeyManager.ts +176 -0
- package/src/types/utils.ts +19 -0
- package/src/version.ts +1 -1
- package/tempo/package.json +5 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { BaseErrorType } from 'viem'
|
|
2
|
+
import { Actions } from 'viem/tempo'
|
|
3
|
+
import type { Config } from '../../createConfig.js'
|
|
4
|
+
import type { ChainIdParameter } from '../../types/properties.js'
|
|
5
|
+
import type { UnionCompute } from '../../types/utils.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Funds an account with an initial amount of set token(s)
|
|
9
|
+
* on Tempo's testnet.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { createConfig, http } from '@wagmi/core'
|
|
14
|
+
* import { tempo } from '@wagmi/core/chains'
|
|
15
|
+
* import { Actions } from '@wagmi/core/tempo'
|
|
16
|
+
*
|
|
17
|
+
* const config = createConfig({
|
|
18
|
+
* chains: [tempoTestnet],
|
|
19
|
+
* transports: {
|
|
20
|
+
* [tempo.id]: http(),
|
|
21
|
+
* },
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* const hashes = await Actions.faucet.fund(config, {
|
|
25
|
+
* account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param config - Config.
|
|
30
|
+
* @param parameters - Parameters.
|
|
31
|
+
* @returns The transaction hashes.
|
|
32
|
+
*/
|
|
33
|
+
export async function fund<config extends Config>(
|
|
34
|
+
config: config,
|
|
35
|
+
parameters: fund.Parameters<config>,
|
|
36
|
+
): Promise<fund.ReturnValue> {
|
|
37
|
+
const { chainId, ...rest } = parameters
|
|
38
|
+
const client = config.getClient({ chainId })
|
|
39
|
+
return Actions.faucet.fund(client, rest)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export declare namespace fund {
|
|
43
|
+
export type Parameters<config extends Config> = UnionCompute<
|
|
44
|
+
ChainIdParameter<config> & Actions.faucet.fund.Parameters
|
|
45
|
+
>
|
|
46
|
+
|
|
47
|
+
export type ReturnValue = Actions.faucet.fund.ReturnValue
|
|
48
|
+
|
|
49
|
+
export type ErrorType = BaseErrorType // TODO: Actions.faucet.fund.ErrorType
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Funds an account with an initial amount of set token(s)
|
|
54
|
+
* on Tempo's testnet. Returns with the transaction receipts.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { createConfig, http } from '@wagmi/core'
|
|
59
|
+
* import { tempo } from '@wagmi/core/chains'
|
|
60
|
+
* import { Actions } from '@wagmi/core/tempo'
|
|
61
|
+
*
|
|
62
|
+
* const config = createConfig({
|
|
63
|
+
* chains: [tempoTestnet],
|
|
64
|
+
* transports: {
|
|
65
|
+
* [tempo.id]: http(),
|
|
66
|
+
* },
|
|
67
|
+
* })
|
|
68
|
+
*
|
|
69
|
+
* const receipts = await Actions.faucet.fundSync(config, {
|
|
70
|
+
* account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
|
|
71
|
+
* })
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @param config - Config.
|
|
75
|
+
* @param parameters - Parameters.
|
|
76
|
+
* @returns The transaction hashes.
|
|
77
|
+
*/
|
|
78
|
+
export async function fundSync<config extends Config>(
|
|
79
|
+
config: config,
|
|
80
|
+
parameters: fundSync.Parameters<config>,
|
|
81
|
+
): Promise<fundSync.ReturnValue> {
|
|
82
|
+
const { chainId, ...rest } = parameters
|
|
83
|
+
const client = config.getClient({ chainId })
|
|
84
|
+
return Actions.faucet.fundSync(client, rest)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export declare namespace fundSync {
|
|
88
|
+
export type Parameters<config extends Config> = UnionCompute<
|
|
89
|
+
ChainIdParameter<config> & Actions.faucet.fundSync.Parameters
|
|
90
|
+
>
|
|
91
|
+
|
|
92
|
+
export type ReturnValue = Actions.faucet.fundSync.ReturnValue
|
|
93
|
+
|
|
94
|
+
export type ErrorType = BaseErrorType // TODO: Actions.faucet.fundSync.ErrorType
|
|
95
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import type { Account, BaseErrorType } from 'viem'
|
|
2
|
+
import { Actions } from 'viem/tempo'
|
|
3
|
+
import { getConnectorClient } from '../../actions/getConnectorClient.js'
|
|
4
|
+
import type { Config } from '../../createConfig.js'
|
|
5
|
+
import { filterQueryOptions } from '../../query/utils.js'
|
|
6
|
+
import type {
|
|
7
|
+
ChainIdParameter,
|
|
8
|
+
ConnectorParameter,
|
|
9
|
+
} from '../../types/properties.js'
|
|
10
|
+
import type { PartialBy, UnionLooseOmit } from '../../types/utils.js'
|
|
11
|
+
import type { QueryOptions, QueryParameter } from './utils.js'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Gets the user's default fee token.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { createConfig, http } from '@wagmi/core'
|
|
19
|
+
* import { tempo } from '@wagmi/core/chains'
|
|
20
|
+
* import { Actions } from '@wagmi/core/tempo'
|
|
21
|
+
*
|
|
22
|
+
* const config = createConfig({
|
|
23
|
+
* chains: [tempoTestnet],
|
|
24
|
+
* transports: {
|
|
25
|
+
* [tempo.id]: http(),
|
|
26
|
+
* },
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* const hash = await Actions.fee.getUserToken(config, {
|
|
30
|
+
* account: '0x20c...0055',
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param config - Config.
|
|
35
|
+
* @param parameters - Parameters.
|
|
36
|
+
* @returns Transaction hash.
|
|
37
|
+
*/
|
|
38
|
+
export function getUserToken<config extends Config>(
|
|
39
|
+
config: config,
|
|
40
|
+
parameters: getUserToken.Parameters<config>,
|
|
41
|
+
): Promise<getUserToken.ReturnValue> {
|
|
42
|
+
const { chainId, ...rest } = parameters
|
|
43
|
+
const client = config.getClient({ chainId })
|
|
44
|
+
return Actions.fee.getUserToken(client, rest)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export namespace getUserToken {
|
|
48
|
+
export type Parameters<config extends Config> = ChainIdParameter<config> &
|
|
49
|
+
Actions.fee.getUserToken.Parameters
|
|
50
|
+
|
|
51
|
+
export type ReturnValue = Actions.fee.getUserToken.ReturnValue
|
|
52
|
+
|
|
53
|
+
export type ErrorType = BaseErrorType
|
|
54
|
+
|
|
55
|
+
export function queryKey<config extends Config>(
|
|
56
|
+
parameters: PartialBy<Parameters<config>, 'account'>,
|
|
57
|
+
) {
|
|
58
|
+
return ['getUserToken', filterQueryOptions(parameters)] as const
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type QueryKey<config extends Config> = ReturnType<
|
|
62
|
+
typeof queryKey<config>
|
|
63
|
+
>
|
|
64
|
+
|
|
65
|
+
export function queryOptions<config extends Config, selectData = ReturnValue>(
|
|
66
|
+
config: Config,
|
|
67
|
+
parameters: queryOptions.Parameters<config, selectData>,
|
|
68
|
+
): queryOptions.ReturnValue<config, selectData> {
|
|
69
|
+
const { query, ...rest } = parameters
|
|
70
|
+
return {
|
|
71
|
+
...query,
|
|
72
|
+
enabled: Boolean(rest.account && (query?.enabled ?? true)),
|
|
73
|
+
queryKey: queryKey(rest),
|
|
74
|
+
async queryFn(context) {
|
|
75
|
+
const [, { account, ...parameters }] = context.queryKey
|
|
76
|
+
if (!account) throw new Error('account is required.')
|
|
77
|
+
return await getUserToken(config, { account, ...parameters })
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export declare namespace queryOptions {
|
|
83
|
+
export type Parameters<
|
|
84
|
+
config extends Config,
|
|
85
|
+
selectData = getUserToken.ReturnValue,
|
|
86
|
+
> = PartialBy<getUserToken.Parameters<config>, 'account'> &
|
|
87
|
+
QueryParameter<
|
|
88
|
+
getUserToken.ReturnValue,
|
|
89
|
+
getUserToken.ErrorType,
|
|
90
|
+
selectData,
|
|
91
|
+
getUserToken.QueryKey<config>
|
|
92
|
+
>
|
|
93
|
+
|
|
94
|
+
export type ReturnValue<
|
|
95
|
+
config extends Config,
|
|
96
|
+
selectData = getUserToken.ReturnValue,
|
|
97
|
+
> = QueryOptions<
|
|
98
|
+
getUserToken.ReturnValue,
|
|
99
|
+
getUserToken.ErrorType,
|
|
100
|
+
selectData,
|
|
101
|
+
getUserToken.QueryKey<config>
|
|
102
|
+
>
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Sets the user's default fee token.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { createConfig, http } from '@wagmi/core'
|
|
112
|
+
* import { tempo } from '@wagmi/core/chains'
|
|
113
|
+
* import { Actions } from '@wagmi/core/tempo'
|
|
114
|
+
*
|
|
115
|
+
* const config = createConfig({
|
|
116
|
+
* chains: [tempoTestnet],
|
|
117
|
+
* transports: {
|
|
118
|
+
* [tempo.id]: http(),
|
|
119
|
+
* },
|
|
120
|
+
* })
|
|
121
|
+
*
|
|
122
|
+
* const result = await Actions.fee.setUserToken(config, {
|
|
123
|
+
* token: '0x20c...0055',
|
|
124
|
+
* })
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @param config - Config.
|
|
128
|
+
* @param parameters - Parameters.
|
|
129
|
+
* @returns The transaction receipt and event data.
|
|
130
|
+
*/
|
|
131
|
+
export async function setUserToken<config extends Config>(
|
|
132
|
+
config: config,
|
|
133
|
+
parameters: setUserToken.Parameters<config>,
|
|
134
|
+
): Promise<Actions.fee.setUserToken.ReturnValue> {
|
|
135
|
+
const { account, chainId, connector } = parameters
|
|
136
|
+
|
|
137
|
+
const client = await getConnectorClient(config, {
|
|
138
|
+
account,
|
|
139
|
+
assertChainId: false,
|
|
140
|
+
chainId,
|
|
141
|
+
connector,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
return Actions.fee.setUserToken(client, parameters as never)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export declare namespace setUserToken {
|
|
148
|
+
export type Parameters<config extends Config> = ChainIdParameter<config> &
|
|
149
|
+
ConnectorParameter &
|
|
150
|
+
UnionLooseOmit<
|
|
151
|
+
Actions.fee.setUserToken.Parameters<config['chains'][number], Account>,
|
|
152
|
+
'chain'
|
|
153
|
+
>
|
|
154
|
+
|
|
155
|
+
export type ReturnValue = Actions.fee.setUserToken.ReturnValue
|
|
156
|
+
|
|
157
|
+
export type ErrorType = BaseErrorType // TODO: Actions.fee.setUserToken.ErrorType
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Sets the user's default fee token.
|
|
162
|
+
*
|
|
163
|
+
* Note: This is a synchronous action that waits for the transaction to
|
|
164
|
+
* be included on a block before returning a response.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* import { createConfig, http } from '@wagmi/core'
|
|
169
|
+
* import { tempo } from '@wagmi/core/chains'
|
|
170
|
+
* import { Actions } from '@wagmi/core/tempo'
|
|
171
|
+
*
|
|
172
|
+
* const config = createConfig({
|
|
173
|
+
* chains: [tempoTestnet],
|
|
174
|
+
* transports: {
|
|
175
|
+
* [tempo.id]: http(),
|
|
176
|
+
* },
|
|
177
|
+
* })
|
|
178
|
+
*
|
|
179
|
+
* const result = await Actions.fee.setUserTokenSync(config, {
|
|
180
|
+
* token: '0x20c...0055',
|
|
181
|
+
* })
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @param config - Config.
|
|
185
|
+
* @param parameters - Parameters.
|
|
186
|
+
* @returns The transaction receipt and event data.
|
|
187
|
+
*/
|
|
188
|
+
export async function setUserTokenSync<config extends Config>(
|
|
189
|
+
config: config,
|
|
190
|
+
parameters: setUserTokenSync.Parameters<config>,
|
|
191
|
+
): Promise<Actions.fee.setUserTokenSync.ReturnValue> {
|
|
192
|
+
const { account, chainId, connector } = parameters
|
|
193
|
+
|
|
194
|
+
const client = await getConnectorClient(config, {
|
|
195
|
+
account,
|
|
196
|
+
assertChainId: false,
|
|
197
|
+
chainId,
|
|
198
|
+
connector,
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
return Actions.fee.setUserTokenSync(client, parameters as never)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export declare namespace setUserTokenSync {
|
|
205
|
+
export type Parameters<config extends Config> = ChainIdParameter<config> &
|
|
206
|
+
ConnectorParameter &
|
|
207
|
+
UnionLooseOmit<
|
|
208
|
+
Actions.fee.setUserTokenSync.Parameters<
|
|
209
|
+
config['chains'][number],
|
|
210
|
+
Account
|
|
211
|
+
>,
|
|
212
|
+
'chain'
|
|
213
|
+
>
|
|
214
|
+
|
|
215
|
+
export type ReturnValue = Actions.fee.setUserTokenSync.ReturnValue
|
|
216
|
+
|
|
217
|
+
export type ErrorType = BaseErrorType // TODO: Actions.fee.setUserTokenSync.ErrorType
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Watches for user token set events on the Fee Manager.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* import { createConfig, http } from '@wagmi/core'
|
|
226
|
+
* import { tempo } from '@wagmi/core/chains'
|
|
227
|
+
* import { Actions } from '@wagmi/core/tempo'
|
|
228
|
+
*
|
|
229
|
+
* const config = createConfig({
|
|
230
|
+
* chains: [tempo],
|
|
231
|
+
* transports: {
|
|
232
|
+
* [tempo.id]: http(),
|
|
233
|
+
* },
|
|
234
|
+
* })
|
|
235
|
+
*
|
|
236
|
+
* const unwatch = Actions.fee.watchSetUserToken(config, {
|
|
237
|
+
* onUserTokenSet: (args, log) => {
|
|
238
|
+
* console.log('User token set:', args)
|
|
239
|
+
* },
|
|
240
|
+
* })
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
243
|
+
* @param config - Config.
|
|
244
|
+
* @param parameters - Parameters.
|
|
245
|
+
* @returns A function to unsubscribe from the event.
|
|
246
|
+
*/
|
|
247
|
+
export function watchSetUserToken<config extends Config>(
|
|
248
|
+
config: config,
|
|
249
|
+
parameters: watchSetUserToken.Parameters<config>,
|
|
250
|
+
): () => void {
|
|
251
|
+
const { chainId, ...rest } = parameters
|
|
252
|
+
const client = config.getClient({ chainId })
|
|
253
|
+
return Actions.fee.watchSetUserToken(client, rest)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export declare namespace watchSetUserToken {
|
|
257
|
+
export type Parameters<config extends Config> = ChainIdParameter<config> &
|
|
258
|
+
Actions.fee.watchSetUserToken.Parameters
|
|
259
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** biome-ignore-all lint/performance/noReExportAll: entrypoint */
|
|
2
|
+
// biome-ignore lint/performance/noBarrelFile: stable
|
|
3
|
+
export * as amm from './amm.js'
|
|
4
|
+
export * as dex from './dex.js'
|
|
5
|
+
export * as faucet from './faucet.js'
|
|
6
|
+
export * as fee from './fee.js'
|
|
7
|
+
export * as nonce from './nonce.js'
|
|
8
|
+
export * as policy from './policy.js'
|
|
9
|
+
export * as reward from './reward.js'
|
|
10
|
+
export * as token from './token.js'
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import type { BaseErrorType } from 'viem'
|
|
2
|
+
import { Actions } from 'viem/tempo'
|
|
3
|
+
import type { Config } from '../../createConfig.js'
|
|
4
|
+
import { filterQueryOptions } from '../../query/utils.js'
|
|
5
|
+
import type { ChainIdParameter } from '../../types/properties.js'
|
|
6
|
+
import type { PartialBy } from '../../types/utils.js'
|
|
7
|
+
import type { QueryOptions, QueryParameter } from './utils.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Gets the nonce for an account and nonce key.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { createConfig, http } from '@wagmi/core'
|
|
15
|
+
* import { tempo } from '@wagmi/core/chains'
|
|
16
|
+
* import { Actions } from '@wagmi/core/tempo'
|
|
17
|
+
*
|
|
18
|
+
* const config = createConfig({
|
|
19
|
+
* chains: [tempo],
|
|
20
|
+
* transports: {
|
|
21
|
+
* [tempo.id]: http(),
|
|
22
|
+
* },
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* const nonce = await Actions.nonce.getNonce(config, {
|
|
26
|
+
* account: '0x...',
|
|
27
|
+
* nonceKey: 1n,
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param config - Config.
|
|
32
|
+
* @param parameters - Parameters.
|
|
33
|
+
* @returns The nonce value.
|
|
34
|
+
*/
|
|
35
|
+
export function getNonce<config extends Config>(
|
|
36
|
+
config: config,
|
|
37
|
+
parameters: getNonce.Parameters<config>,
|
|
38
|
+
): Promise<getNonce.ReturnValue> {
|
|
39
|
+
const { chainId, ...rest } = parameters
|
|
40
|
+
const client = config.getClient({ chainId })
|
|
41
|
+
return Actions.nonce.getNonce(client, rest)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export namespace getNonce {
|
|
45
|
+
export type Parameters<config extends Config> = ChainIdParameter<config> &
|
|
46
|
+
Actions.nonce.getNonce.Parameters
|
|
47
|
+
|
|
48
|
+
export type ReturnValue = Actions.nonce.getNonce.ReturnValue
|
|
49
|
+
|
|
50
|
+
export type ErrorType = BaseErrorType
|
|
51
|
+
|
|
52
|
+
export function queryKey<config extends Config>(
|
|
53
|
+
parameters: PartialBy<Parameters<config>, 'account' | 'nonceKey'>,
|
|
54
|
+
) {
|
|
55
|
+
return ['getNonce', filterQueryOptions(parameters)] as const
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type QueryKey<config extends Config> = ReturnType<
|
|
59
|
+
typeof queryKey<config>
|
|
60
|
+
>
|
|
61
|
+
|
|
62
|
+
export function queryOptions<config extends Config, selectData = ReturnValue>(
|
|
63
|
+
config: Config,
|
|
64
|
+
parameters: queryOptions.Parameters<config, selectData>,
|
|
65
|
+
): queryOptions.ReturnValue<config, selectData> {
|
|
66
|
+
const { query, ...rest } = parameters
|
|
67
|
+
return {
|
|
68
|
+
...query,
|
|
69
|
+
enabled: Boolean(
|
|
70
|
+
rest.account && rest.nonceKey !== undefined && (query?.enabled ?? true),
|
|
71
|
+
),
|
|
72
|
+
queryKey: queryKey(rest),
|
|
73
|
+
async queryFn(context) {
|
|
74
|
+
const [, { account, nonceKey, ...parameters }] = context.queryKey
|
|
75
|
+
if (!account) throw new Error('account is required.')
|
|
76
|
+
if (nonceKey === undefined) throw new Error('nonceKey is required.')
|
|
77
|
+
return await getNonce(config, { account, nonceKey, ...parameters })
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export declare namespace queryOptions {
|
|
83
|
+
export type Parameters<
|
|
84
|
+
config extends Config,
|
|
85
|
+
selectData = getNonce.ReturnValue,
|
|
86
|
+
> = PartialBy<getNonce.Parameters<config>, 'account' | 'nonceKey'> &
|
|
87
|
+
QueryParameter<
|
|
88
|
+
getNonce.ReturnValue,
|
|
89
|
+
getNonce.ErrorType,
|
|
90
|
+
selectData,
|
|
91
|
+
getNonce.QueryKey<config>
|
|
92
|
+
>
|
|
93
|
+
|
|
94
|
+
export type ReturnValue<
|
|
95
|
+
config extends Config,
|
|
96
|
+
selectData = getNonce.ReturnValue,
|
|
97
|
+
> = QueryOptions<
|
|
98
|
+
getNonce.ReturnValue,
|
|
99
|
+
getNonce.ErrorType,
|
|
100
|
+
selectData,
|
|
101
|
+
getNonce.QueryKey<config>
|
|
102
|
+
>
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Watches for nonce incremented events.
|
|
108
|
+
*
|
|
109
|
+
* @deprecated This function has been deprecated post-AllegroModerato. It will be removed in a future version.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { createConfig, http } from '@wagmi/core'
|
|
114
|
+
* import { tempo } from '@wagmi/core/chains'
|
|
115
|
+
* import { Actions } from '@wagmi/core/tempo'
|
|
116
|
+
*
|
|
117
|
+
* const config = createConfig({
|
|
118
|
+
* chains: [tempo],
|
|
119
|
+
* transports: {
|
|
120
|
+
* [tempo.id]: http(),
|
|
121
|
+
* },
|
|
122
|
+
* })
|
|
123
|
+
*
|
|
124
|
+
* const unwatch = Actions.nonce.watchNonceIncremented(config, {
|
|
125
|
+
* onNonceIncremented: (args, log) => {
|
|
126
|
+
* console.log('Nonce incremented:', args)
|
|
127
|
+
* },
|
|
128
|
+
* })
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @param config - Config.
|
|
132
|
+
* @param parameters - Parameters.
|
|
133
|
+
* @returns A function to unsubscribe from the event.
|
|
134
|
+
*/
|
|
135
|
+
export function watchNonceIncremented<config extends Config>(
|
|
136
|
+
config: config,
|
|
137
|
+
parameters: watchNonceIncremented.Parameters<config>,
|
|
138
|
+
): () => void {
|
|
139
|
+
const { chainId, ...rest } = parameters
|
|
140
|
+
const client = config.getClient({ chainId })
|
|
141
|
+
return Actions.nonce.watchNonceIncremented(client, rest)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export declare namespace watchNonceIncremented {
|
|
145
|
+
export type Parameters<config extends Config> = ChainIdParameter<config> &
|
|
146
|
+
Actions.nonce.watchNonceIncremented.Parameters
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Watches for active key count changed events.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* import { createConfig, http } from '@wagmi/core'
|
|
155
|
+
* import { tempo } from '@wagmi/core/chains'
|
|
156
|
+
* import { Actions } from '@wagmi/core/tempo'
|
|
157
|
+
*
|
|
158
|
+
* const config = createConfig({
|
|
159
|
+
* chains: [tempo],
|
|
160
|
+
* transports: {
|
|
161
|
+
* [tempo.id]: http(),
|
|
162
|
+
* },
|
|
163
|
+
* })
|
|
164
|
+
*
|
|
165
|
+
* const unwatch = Actions.nonce.watchActiveKeyCountChanged(config, {
|
|
166
|
+
* onActiveKeyCountChanged: (args, log) => {
|
|
167
|
+
* console.log('Active key count changed:', args)
|
|
168
|
+
* },
|
|
169
|
+
* })
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @param config - Config.
|
|
173
|
+
* @param parameters - Parameters.
|
|
174
|
+
* @returns A function to unsubscribe from the event.
|
|
175
|
+
*/
|
|
176
|
+
export function watchActiveKeyCountChanged<config extends Config>(
|
|
177
|
+
config: config,
|
|
178
|
+
parameters: watchActiveKeyCountChanged.Parameters<config>,
|
|
179
|
+
): () => void {
|
|
180
|
+
const { chainId, ...rest } = parameters
|
|
181
|
+
const client = config.getClient({ chainId })
|
|
182
|
+
return Actions.nonce.watchActiveKeyCountChanged(client, rest)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export declare namespace watchActiveKeyCountChanged {
|
|
186
|
+
export type Parameters<config extends Config> = ChainIdParameter<config> &
|
|
187
|
+
Actions.nonce.watchActiveKeyCountChanged.Parameters
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Gets the number of active nonce keys for an account.
|
|
192
|
+
*
|
|
193
|
+
* @deprecated This function has been deprecated post-AllegroModerato. It will be removed in a future version.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* import { createConfig, http } from '@wagmi/core'
|
|
198
|
+
* import { tempo } from '@wagmi/core/chains'
|
|
199
|
+
* import { Actions } from '@wagmi/core/tempo'
|
|
200
|
+
*
|
|
201
|
+
* const config = createConfig({
|
|
202
|
+
* chains: [tempo],
|
|
203
|
+
* transports: {
|
|
204
|
+
* [tempo.id]: http(),
|
|
205
|
+
* },
|
|
206
|
+
* })
|
|
207
|
+
*
|
|
208
|
+
* const count = await Actions.nonce.getNonceKeyCount(config, {
|
|
209
|
+
* account: '0x...',
|
|
210
|
+
* })
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* @param config - Config.
|
|
214
|
+
* @param parameters - Parameters.
|
|
215
|
+
* @returns The number of active nonce keys.
|
|
216
|
+
*/
|
|
217
|
+
export function getNonceKeyCount<config extends Config>(
|
|
218
|
+
config: config,
|
|
219
|
+
parameters: getNonceKeyCount.Parameters<config>,
|
|
220
|
+
): Promise<getNonceKeyCount.ReturnValue> {
|
|
221
|
+
const { chainId, ...rest } = parameters
|
|
222
|
+
const client = config.getClient({ chainId })
|
|
223
|
+
return Actions.nonce.getNonceKeyCount(client, rest)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export namespace getNonceKeyCount {
|
|
227
|
+
export type Parameters<config extends Config> = ChainIdParameter<config> &
|
|
228
|
+
Actions.nonce.getNonceKeyCount.Parameters
|
|
229
|
+
|
|
230
|
+
export type ReturnValue = Actions.nonce.getNonceKeyCount.ReturnValue
|
|
231
|
+
|
|
232
|
+
export type ErrorType = BaseErrorType
|
|
233
|
+
|
|
234
|
+
export function queryKey<config extends Config>(
|
|
235
|
+
parameters: PartialBy<Parameters<config>, 'account'>,
|
|
236
|
+
) {
|
|
237
|
+
return ['getNonceKeyCount', filterQueryOptions(parameters)] as const
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export type QueryKey<config extends Config> = ReturnType<
|
|
241
|
+
typeof queryKey<config>
|
|
242
|
+
>
|
|
243
|
+
|
|
244
|
+
export function queryOptions<config extends Config, selectData = ReturnValue>(
|
|
245
|
+
config: Config,
|
|
246
|
+
parameters: queryOptions.Parameters<config, selectData>,
|
|
247
|
+
): queryOptions.ReturnValue<config, selectData> {
|
|
248
|
+
const { query, ...rest } = parameters
|
|
249
|
+
return {
|
|
250
|
+
...query,
|
|
251
|
+
enabled: Boolean(rest.account && (query?.enabled ?? true)),
|
|
252
|
+
queryKey: queryKey(rest),
|
|
253
|
+
async queryFn(context) {
|
|
254
|
+
const [, { account, ...parameters }] = context.queryKey
|
|
255
|
+
if (!account) throw new Error('account is required.')
|
|
256
|
+
return await getNonceKeyCount(config, { account, ...parameters })
|
|
257
|
+
},
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export declare namespace queryOptions {
|
|
262
|
+
export type Parameters<
|
|
263
|
+
config extends Config,
|
|
264
|
+
selectData = getNonceKeyCount.ReturnValue,
|
|
265
|
+
> = PartialBy<getNonceKeyCount.Parameters<config>, 'account'> &
|
|
266
|
+
QueryParameter<
|
|
267
|
+
getNonceKeyCount.ReturnValue,
|
|
268
|
+
getNonceKeyCount.ErrorType,
|
|
269
|
+
selectData,
|
|
270
|
+
getNonceKeyCount.QueryKey<config>
|
|
271
|
+
>
|
|
272
|
+
|
|
273
|
+
export type ReturnValue<
|
|
274
|
+
config extends Config,
|
|
275
|
+
selectData = getNonceKeyCount.ReturnValue,
|
|
276
|
+
> = QueryOptions<
|
|
277
|
+
getNonceKeyCount.ReturnValue,
|
|
278
|
+
getNonceKeyCount.ErrorType,
|
|
279
|
+
selectData,
|
|
280
|
+
getNonceKeyCount.QueryKey<config>
|
|
281
|
+
>
|
|
282
|
+
}
|
|
283
|
+
}
|