tempo.ts 0.12.1 → 0.13.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.
Files changed (123) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +28 -34
  3. package/package.json +2 -28
  4. package/dist/wagmi/Actions/amm.d.ts +0 -418
  5. package/dist/wagmi/Actions/amm.d.ts.map +0 -1
  6. package/dist/wagmi/Actions/amm.js +0 -462
  7. package/dist/wagmi/Actions/amm.js.map +0 -1
  8. package/dist/wagmi/Actions/dex.d.ts +0 -864
  9. package/dist/wagmi/Actions/dex.d.ts.map +0 -1
  10. package/dist/wagmi/Actions/dex.js +0 -968
  11. package/dist/wagmi/Actions/dex.js.map +0 -1
  12. package/dist/wagmi/Actions/faucet.d.ts +0 -66
  13. package/dist/wagmi/Actions/faucet.d.ts.map +0 -1
  14. package/dist/wagmi/Actions/faucet.js +0 -64
  15. package/dist/wagmi/Actions/faucet.js.map +0 -1
  16. package/dist/wagmi/Actions/fee.d.ts +0 -111
  17. package/dist/wagmi/Actions/fee.d.ts.map +0 -1
  18. package/dist/wagmi/Actions/fee.js +0 -126
  19. package/dist/wagmi/Actions/fee.js.map +0 -1
  20. package/dist/wagmi/Actions/index.d.ts +0 -9
  21. package/dist/wagmi/Actions/index.d.ts.map +0 -1
  22. package/dist/wagmi/Actions/index.js +0 -9
  23. package/dist/wagmi/Actions/index.js.map +0 -1
  24. package/dist/wagmi/Actions/nonce.d.ts +0 -77
  25. package/dist/wagmi/Actions/nonce.d.ts.map +0 -1
  26. package/dist/wagmi/Actions/nonce.js +0 -87
  27. package/dist/wagmi/Actions/nonce.js.map +0 -1
  28. package/dist/wagmi/Actions/policy.d.ts +0 -480
  29. package/dist/wagmi/Actions/policy.d.ts.map +0 -1
  30. package/dist/wagmi/Actions/policy.js +0 -530
  31. package/dist/wagmi/Actions/policy.js.map +0 -1
  32. package/dist/wagmi/Actions/reward.d.ts +0 -346
  33. package/dist/wagmi/Actions/reward.d.ts.map +0 -1
  34. package/dist/wagmi/Actions/reward.js +0 -382
  35. package/dist/wagmi/Actions/reward.js.map +0 -1
  36. package/dist/wagmi/Actions/token.d.ts +0 -1546
  37. package/dist/wagmi/Actions/token.d.ts.map +0 -1
  38. package/dist/wagmi/Actions/token.js +0 -1712
  39. package/dist/wagmi/Actions/token.js.map +0 -1
  40. package/dist/wagmi/Connector.d.ts +0 -91
  41. package/dist/wagmi/Connector.d.ts.map +0 -1
  42. package/dist/wagmi/Connector.js +0 -473
  43. package/dist/wagmi/Connector.js.map +0 -1
  44. package/dist/wagmi/Hooks/amm.d.ts +0 -411
  45. package/dist/wagmi/Hooks/amm.d.ts.map +0 -1
  46. package/dist/wagmi/Hooks/amm.js +0 -494
  47. package/dist/wagmi/Hooks/amm.js.map +0 -1
  48. package/dist/wagmi/Hooks/dex.d.ts +0 -773
  49. package/dist/wagmi/Hooks/dex.d.ts.map +0 -1
  50. package/dist/wagmi/Hooks/dex.js +0 -921
  51. package/dist/wagmi/Hooks/dex.js.map +0 -1
  52. package/dist/wagmi/Hooks/faucet.d.ts +0 -71
  53. package/dist/wagmi/Hooks/faucet.d.ts.map +0 -1
  54. package/dist/wagmi/Hooks/faucet.js +0 -76
  55. package/dist/wagmi/Hooks/faucet.js.map +0 -1
  56. package/dist/wagmi/Hooks/fee.d.ts +0 -97
  57. package/dist/wagmi/Hooks/fee.d.ts.map +0 -1
  58. package/dist/wagmi/Hooks/fee.js +0 -109
  59. package/dist/wagmi/Hooks/fee.js.map +0 -1
  60. package/dist/wagmi/Hooks/index.d.ts +0 -9
  61. package/dist/wagmi/Hooks/index.d.ts.map +0 -1
  62. package/dist/wagmi/Hooks/index.js +0 -9
  63. package/dist/wagmi/Hooks/index.js.map +0 -1
  64. package/dist/wagmi/Hooks/nonce.d.ts +0 -59
  65. package/dist/wagmi/Hooks/nonce.d.ts.map +0 -1
  66. package/dist/wagmi/Hooks/nonce.js +0 -75
  67. package/dist/wagmi/Hooks/nonce.js.map +0 -1
  68. package/dist/wagmi/Hooks/policy.d.ts +0 -423
  69. package/dist/wagmi/Hooks/policy.d.ts.map +0 -1
  70. package/dist/wagmi/Hooks/policy.js +0 -510
  71. package/dist/wagmi/Hooks/policy.js.map +0 -1
  72. package/dist/wagmi/Hooks/reward.d.ts +0 -305
  73. package/dist/wagmi/Hooks/reward.d.ts.map +0 -1
  74. package/dist/wagmi/Hooks/reward.js +0 -368
  75. package/dist/wagmi/Hooks/reward.js.map +0 -1
  76. package/dist/wagmi/Hooks/token.d.ts +0 -1388
  77. package/dist/wagmi/Hooks/token.d.ts.map +0 -1
  78. package/dist/wagmi/Hooks/token.js +0 -1657
  79. package/dist/wagmi/Hooks/token.js.map +0 -1
  80. package/dist/wagmi/KeyManager.d.ts +0 -60
  81. package/dist/wagmi/KeyManager.d.ts.map +0 -1
  82. package/dist/wagmi/KeyManager.js +0 -106
  83. package/dist/wagmi/KeyManager.js.map +0 -1
  84. package/dist/wagmi/index.d.ts +0 -5
  85. package/dist/wagmi/index.d.ts.map +0 -1
  86. package/dist/wagmi/index.js +0 -5
  87. package/dist/wagmi/index.js.map +0 -1
  88. package/src/wagmi/Actions/amm.test.ts +0 -208
  89. package/src/wagmi/Actions/amm.ts +0 -690
  90. package/src/wagmi/Actions/dex.test.ts +0 -1482
  91. package/src/wagmi/Actions/dex.ts +0 -1540
  92. package/src/wagmi/Actions/faucet.ts +0 -89
  93. package/src/wagmi/Actions/fee.test.ts +0 -63
  94. package/src/wagmi/Actions/fee.ts +0 -211
  95. package/src/wagmi/Actions/index.ts +0 -8
  96. package/src/wagmi/Actions/nonce.test.ts +0 -82
  97. package/src/wagmi/Actions/nonce.ts +0 -139
  98. package/src/wagmi/Actions/policy.test.ts +0 -461
  99. package/src/wagmi/Actions/policy.ts +0 -817
  100. package/src/wagmi/Actions/reward.test.ts +0 -216
  101. package/src/wagmi/Actions/reward.ts +0 -613
  102. package/src/wagmi/Actions/token.test.ts +0 -1309
  103. package/src/wagmi/Actions/token.ts +0 -2644
  104. package/src/wagmi/Connector.test.ts +0 -56
  105. package/src/wagmi/Connector.ts +0 -670
  106. package/src/wagmi/Hooks/amm.test.ts +0 -564
  107. package/src/wagmi/Hooks/amm.ts +0 -796
  108. package/src/wagmi/Hooks/dex.test.ts +0 -992
  109. package/src/wagmi/Hooks/dex.ts +0 -1598
  110. package/src/wagmi/Hooks/faucet.ts +0 -144
  111. package/src/wagmi/Hooks/fee.test.ts +0 -166
  112. package/src/wagmi/Hooks/fee.ts +0 -206
  113. package/src/wagmi/Hooks/index.ts +0 -8
  114. package/src/wagmi/Hooks/nonce.test.ts +0 -142
  115. package/src/wagmi/Hooks/nonce.ts +0 -117
  116. package/src/wagmi/Hooks/policy.test.ts +0 -665
  117. package/src/wagmi/Hooks/policy.ts +0 -873
  118. package/src/wagmi/Hooks/reward.test.ts +0 -249
  119. package/src/wagmi/Hooks/reward.ts +0 -645
  120. package/src/wagmi/Hooks/token.test.ts +0 -1183
  121. package/src/wagmi/Hooks/token.ts +0 -2906
  122. package/src/wagmi/KeyManager.ts +0 -172
  123. package/src/wagmi/index.ts +0 -7
@@ -1,89 +0,0 @@
1
- import type { Config } from '@wagmi/core'
2
- import type { ChainIdParameter, UnionCompute } from '@wagmi/core/internal'
3
- import { Actions } from 'viem/tempo'
4
-
5
- /**
6
- * Funds an account with an initial amount of set token(s)
7
- * on Tempo's testnet.
8
- *
9
- * @example
10
- * ```ts
11
- * import { createConfig, http } from '@wagmi/core'
12
- * import { tempo } from 'viem/chains'
13
- * import { Actions } from 'tempo.ts/wagmi'
14
- *
15
- * const config = createConfig({
16
- * chains: [tempoTestnet],
17
- * transports: {
18
- * [tempo.id]: http(),
19
- * },
20
- * })
21
- *
22
- * const hashes = await Actions.faucet.fund(config, {
23
- * account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
24
- * })
25
- * ```
26
- *
27
- * @param config - Config.
28
- * @param parameters - Parameters.
29
- * @returns The transaction hashes.
30
- */
31
- export async function fund<config extends Config>(
32
- config: config,
33
- parameters: fund.Parameters<config>,
34
- ): Promise<fund.ReturnValue> {
35
- const { chainId, ...rest } = parameters
36
- const client = config.getClient({ chainId })
37
- return Actions.faucet.fund(client, rest)
38
- }
39
-
40
- export declare namespace fund {
41
- export type Parameters<config extends Config> = UnionCompute<
42
- ChainIdParameter<config> & Actions.faucet.fund.Parameters
43
- >
44
-
45
- export type ReturnValue = Actions.faucet.fund.ReturnValue
46
- }
47
-
48
- /**
49
- * Funds an account with an initial amount of set token(s)
50
- * on Tempo's testnet. Returns with the transaction receipts.
51
- *
52
- * @example
53
- * ```ts
54
- * import { createConfig, http } from '@wagmi/core'
55
- * import { tempo } from 'viem/chains'
56
- * import { Actions } from 'tempo.ts/wagmi'
57
- *
58
- * const config = createConfig({
59
- * chains: [tempoTestnet],
60
- * transports: {
61
- * [tempo.id]: http(),
62
- * },
63
- * })
64
- *
65
- * const receipts = await Actions.faucet.fundSync(config, {
66
- * account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
67
- * })
68
- * ```
69
- *
70
- * @param config - Config.
71
- * @param parameters - Parameters.
72
- * @returns The transaction hashes.
73
- */
74
- export async function fundSync<config extends Config>(
75
- config: config,
76
- parameters: fundSync.Parameters<config>,
77
- ): Promise<fundSync.ReturnValue> {
78
- const { chainId, ...rest } = parameters
79
- const client = config.getClient({ chainId })
80
- return Actions.faucet.fundSync(client, rest)
81
- }
82
-
83
- export declare namespace fundSync {
84
- export type Parameters<config extends Config> = UnionCompute<
85
- ChainIdParameter<config> & Actions.faucet.fundSync.Parameters
86
- >
87
-
88
- export type ReturnValue = Actions.faucet.fundSync.ReturnValue
89
- }
@@ -1,63 +0,0 @@
1
- import { connect } from '@wagmi/core'
2
- import { describe, expect, test } from 'vitest'
3
- import { accounts } from '../../../test/viem/config.js'
4
- import { config, queryClient } from '../../../test/wagmi/config.js'
5
- import { getUserToken, setUserToken, setUserTokenSync } from './fee.js'
6
-
7
- const account = accounts[0]
8
-
9
- describe('getUserToken', () => {
10
- test('default', async () => {
11
- const result = await getUserToken(config, {
12
- account,
13
- })
14
- expect(result).toMatchInlineSnapshot(`
15
- {
16
- "address": "0x20C0000000000000000000000000000000000001",
17
- "id": 1n,
18
- }
19
- `)
20
- })
21
-
22
- describe('queryOptions', () => {
23
- test('default', async () => {
24
- const options = getUserToken.queryOptions(config, {
25
- account,
26
- })
27
- expect(await queryClient.fetchQuery(options)).toMatchInlineSnapshot(
28
- `
29
- {
30
- "address": "0x20C0000000000000000000000000000000000001",
31
- "id": 1n,
32
- }
33
- `,
34
- )
35
- })
36
- })
37
- })
38
-
39
- describe.skip('setUserToken', () => {
40
- test('default', async () => {
41
- await connect(config, {
42
- connector: config.connectors[0]!,
43
- })
44
- const hash = await setUserToken(config, {
45
- account,
46
- token: '0x20C0000000000000000000000000000000000001',
47
- })
48
- expect(hash).toBeDefined()
49
- })
50
- })
51
-
52
- describe.skip('setUserTokenSync', () => {
53
- test('default', async () => {
54
- await connect(config, {
55
- connector: config.connectors[0]!,
56
- })
57
- const result = await setUserTokenSync(config, {
58
- account,
59
- token: '0x20C0000000000000000000000000000000000001',
60
- })
61
- expect(result).toBeDefined()
62
- })
63
- })
@@ -1,211 +0,0 @@
1
- import type * as Query from '@tanstack/query-core'
2
- import { type Config, getConnectorClient } from '@wagmi/core'
3
- import type { ChainIdParameter, ConnectorParameter } from '@wagmi/core/internal'
4
- import type { Account } from 'viem'
5
- import { Actions } from 'viem/tempo'
6
- import type { PartialBy, RequiredBy, UnionOmit } from '../../internal/types.js'
7
-
8
- /**
9
- * Gets the user's default fee token.
10
- *
11
- * @example
12
- * ```ts
13
- * import { createConfig, http } from '@wagmi/core'
14
- * import { tempo } from 'viem/chains'
15
- * import { Actions } from 'tempo.ts/wagmi'
16
- *
17
- * const config = createConfig({
18
- * chains: [tempoTestnet],
19
- * transports: {
20
- * [tempo.id]: http(),
21
- * },
22
- * })
23
- *
24
- * const hash = await Actions.fee.getUserToken(config, {
25
- * account: '0x20c...0055',
26
- * })
27
- * ```
28
- *
29
- * @param config - Config.
30
- * @param parameters - Parameters.
31
- * @returns Transaction hash.
32
- */
33
- export function getUserToken<config extends Config>(
34
- config: config,
35
- parameters: getUserToken.Parameters<config>,
36
- ): Promise<getUserToken.ReturnValue> {
37
- const { chainId, ...rest } = parameters
38
- const client = config.getClient({ chainId })
39
- return Actions.fee.getUserToken(client, rest)
40
- }
41
-
42
- export namespace getUserToken {
43
- export type Parameters<config extends Config> = ChainIdParameter<config> &
44
- Actions.fee.getUserToken.Parameters
45
-
46
- export type ReturnValue = Actions.fee.getUserToken.ReturnValue
47
-
48
- export function queryKey<config extends Config>(
49
- parameters: PartialBy<Parameters<config>, 'account'>,
50
- ) {
51
- return ['getUserToken', parameters] as const
52
- }
53
-
54
- export type QueryKey<config extends Config> = ReturnType<
55
- typeof queryKey<config>
56
- >
57
-
58
- export function queryOptions<config extends Config, selectData = ReturnValue>(
59
- config: Config,
60
- parameters: queryOptions.Parameters<config, selectData>,
61
- ): queryOptions.ReturnValue<config, selectData> {
62
- const { query, ...rest } = parameters
63
- return {
64
- ...query,
65
- queryKey: queryKey(rest),
66
- async queryFn({ queryKey }) {
67
- const [, { account, ...parameters }] = queryKey
68
- if (!account) throw new Error('account is required.')
69
- return await getUserToken(config, { account, ...parameters })
70
- },
71
- }
72
- }
73
-
74
- export declare namespace queryOptions {
75
- export type Parameters<
76
- config extends Config,
77
- selectData = getUserToken.ReturnValue,
78
- > = PartialBy<getUserToken.Parameters<config>, 'account'> & {
79
- query?:
80
- | Omit<ReturnValue<config, selectData>, 'queryKey' | 'queryFn'>
81
- | undefined
82
- }
83
-
84
- export type ReturnValue<
85
- config extends Config,
86
- selectData = getUserToken.ReturnValue,
87
- > = RequiredBy<
88
- Query.QueryOptions<
89
- getUserToken.ReturnValue,
90
- Query.DefaultError,
91
- selectData,
92
- getUserToken.QueryKey<config>
93
- >,
94
- 'queryKey' | 'queryFn'
95
- >
96
- }
97
- }
98
-
99
- /**
100
- * Sets the user's default fee token.
101
- *
102
- * @example
103
- * ```ts
104
- * import { createConfig, http } from '@wagmi/core'
105
- * import { tempo } from 'viem/chains'
106
- * import { Actions } from 'tempo.ts/wagmi'
107
- *
108
- * const config = createConfig({
109
- * chains: [tempoTestnet],
110
- * transports: {
111
- * [tempo.id]: http(),
112
- * },
113
- * })
114
- *
115
- * const result = await Actions.fee.setUserToken(config, {
116
- * token: '0x20c...0055',
117
- * })
118
- * ```
119
- *
120
- * @param config - Config.
121
- * @param parameters - Parameters.
122
- * @returns The transaction receipt and event data.
123
- */
124
- export async function setUserToken<config extends Config>(
125
- config: config,
126
- parameters: setUserToken.Parameters<config>,
127
- ): Promise<Actions.fee.setUserToken.ReturnValue> {
128
- const { account, chainId, connector } = parameters
129
-
130
- const client = await getConnectorClient(config, {
131
- account,
132
- assertChainId: false,
133
- chainId,
134
- connector,
135
- })
136
-
137
- return Actions.fee.setUserToken(client, parameters as never)
138
- }
139
-
140
- export declare namespace setUserToken {
141
- export type Parameters<config extends Config> = ChainIdParameter<config> &
142
- ConnectorParameter &
143
- UnionOmit<
144
- Actions.fee.setUserToken.Parameters<config['chains'][number], Account>,
145
- 'chain'
146
- >
147
-
148
- export type ReturnValue = Actions.fee.setUserToken.ReturnValue
149
-
150
- export type ErrorType = Actions.fee.setUserToken.ErrorType
151
- }
152
-
153
- /**
154
- * Sets the user's default fee token.
155
- *
156
- * Note: This is a synchronous action that waits for the transaction to
157
- * be included on a block before returning a response.
158
- *
159
- * @example
160
- * ```ts
161
- * import { createConfig, http } from '@wagmi/core'
162
- * import { tempo } from 'viem/chains'
163
- * import { Actions } from 'tempo.ts/wagmi'
164
- *
165
- * const config = createConfig({
166
- * chains: [tempoTestnet],
167
- * transports: {
168
- * [tempo.id]: http(),
169
- * },
170
- * })
171
- *
172
- * const result = await Actions.fee.setUserTokenSync(config, {
173
- * token: '0x20c...0055',
174
- * })
175
- * ```
176
- *
177
- * @param config - Config.
178
- * @param parameters - Parameters.
179
- * @returns The transaction receipt and event data.
180
- */
181
- export async function setUserTokenSync<config extends Config>(
182
- config: config,
183
- parameters: setUserTokenSync.Parameters<config>,
184
- ): Promise<Actions.fee.setUserTokenSync.ReturnValue> {
185
- const { account, chainId, connector } = parameters
186
-
187
- const client = await getConnectorClient(config, {
188
- account,
189
- assertChainId: false,
190
- chainId,
191
- connector,
192
- })
193
-
194
- return Actions.fee.setUserTokenSync(client, parameters as never)
195
- }
196
-
197
- export declare namespace setUserTokenSync {
198
- export type Parameters<config extends Config> = ChainIdParameter<config> &
199
- ConnectorParameter &
200
- UnionOmit<
201
- Actions.fee.setUserTokenSync.Parameters<
202
- config['chains'][number],
203
- Account
204
- >,
205
- 'chain'
206
- >
207
-
208
- export type ReturnValue = Actions.fee.setUserTokenSync.ReturnValue
209
-
210
- export type ErrorType = Actions.fee.setUserTokenSync.ErrorType
211
- }
@@ -1,8 +0,0 @@
1
- export * as amm from './amm.js'
2
- export * as dex from './dex.js'
3
- export * as faucet from './faucet.js'
4
- export * as fee from './fee.js'
5
- export * as nonce from './nonce.js'
6
- export * as policy from './policy.js'
7
- export * as reward from './reward.js'
8
- export * as token from './token.js'
@@ -1,82 +0,0 @@
1
- import { connect } from '@wagmi/core'
2
- import { afterEach, describe, expect, test } from 'vitest'
3
- import { rpcUrl } from '../../../test/config.js'
4
- import { accounts } from '../../../test/viem/config.js'
5
- import { config, queryClient } from '../../../test/wagmi/config.js'
6
- import * as nonce from './nonce.js'
7
- import * as token from './token.js'
8
-
9
- const { getNonce } = nonce
10
-
11
- const account = accounts[0]
12
- const account2 = accounts[1]
13
-
14
- afterEach(async () => {
15
- await fetch(`${rpcUrl}/restart`)
16
- })
17
-
18
- describe('getNonce', () => {
19
- test('default', async () => {
20
- const result = await getNonce(config, {
21
- account: account.address,
22
- nonceKey: 1n,
23
- })
24
- expect(result).toBe(0n)
25
- })
26
-
27
- describe('queryOptions', () => {
28
- test('default', async () => {
29
- const options = getNonce.queryOptions(config, {
30
- account: account.address,
31
- nonceKey: 1n,
32
- })
33
- const result = await queryClient.fetchQuery(options)
34
- expect(result).toBe(0n)
35
- })
36
- })
37
- })
38
-
39
- describe('watchNonceIncremented', () => {
40
- test('default', async () => {
41
- await connect(config, {
42
- connector: config.connectors[0]!,
43
- })
44
-
45
- const events: any[] = []
46
- const unwatch = nonce.watchNonceIncremented(config, {
47
- onNonceIncremented: (args) => {
48
- events.push(args)
49
- },
50
- args: {
51
- account: account.address,
52
- nonceKey: 5n,
53
- },
54
- })
55
-
56
- // Have to manually set nonce because eth_FillTransaction does not support nonce keys
57
- await token.transferSync(config, {
58
- to: account2.address,
59
- amount: 1n,
60
- token: 1n,
61
- nonceKey: 5n,
62
- nonce: 0,
63
- })
64
-
65
- await token.transferSync(config, {
66
- to: account2.address,
67
- amount: 1n,
68
- token: 1n,
69
- nonceKey: 5n,
70
- nonce: 1,
71
- })
72
-
73
- await new Promise((resolve) => setTimeout(resolve, 1000))
74
-
75
- expect(events).toHaveLength(2)
76
- expect(events[0]?.account).toBe(account.address)
77
- expect(events[0]?.nonceKey).toBe(5n)
78
- expect(events[0]?.newNonce).toBe(1n)
79
- expect(events[1]?.newNonce).toBe(2n)
80
- unwatch()
81
- })
82
- })
@@ -1,139 +0,0 @@
1
- import type * as Query from '@tanstack/query-core'
2
- import type { Config } from '@wagmi/core'
3
- import type { ChainIdParameter } from '@wagmi/core/internal'
4
- import { Actions } from 'viem/tempo'
5
- import type { PartialBy, RequiredBy } from '../../internal/types.js'
6
-
7
- /**
8
- * Gets the nonce for an account and nonce key.
9
- *
10
- * @example
11
- * ```ts
12
- * import { createConfig, http } from '@wagmi/core'
13
- * import { tempo } from 'viem/chains'
14
- * import { Actions } from 'tempo.ts/wagmi'
15
- *
16
- * const config = createConfig({
17
- * chains: [tempoTestnet],
18
- * transports: {
19
- * [tempo.id]: http(),
20
- * },
21
- * })
22
- *
23
- * const nonce = await Actions.nonce.getNonce(config, {
24
- * account: '0x...',
25
- * nonceKey: 1n,
26
- * })
27
- * ```
28
- *
29
- * @param config - Config.
30
- * @param parameters - Parameters.
31
- * @returns The nonce value.
32
- */
33
- export function getNonce<config extends Config>(
34
- config: config,
35
- parameters: getNonce.Parameters<config>,
36
- ): Promise<getNonce.ReturnValue> {
37
- const { chainId, ...rest } = parameters
38
- const client = config.getClient({ chainId })
39
- return Actions.nonce.getNonce(client, rest)
40
- }
41
-
42
- export namespace getNonce {
43
- export type Parameters<config extends Config> = ChainIdParameter<config> &
44
- Actions.nonce.getNonce.Parameters
45
-
46
- export type ReturnValue = Actions.nonce.getNonce.ReturnValue
47
-
48
- export function queryKey<config extends Config>(
49
- parameters: PartialBy<Parameters<config>, 'account' | 'nonceKey'>,
50
- ) {
51
- return ['getNonce', parameters] as const
52
- }
53
-
54
- export type QueryKey<config extends Config> = ReturnType<
55
- typeof queryKey<config>
56
- >
57
-
58
- export function queryOptions<config extends Config, selectData = ReturnValue>(
59
- config: Config,
60
- parameters: queryOptions.Parameters<config, selectData>,
61
- ): queryOptions.ReturnValue<config, selectData> {
62
- const { query, ...rest } = parameters
63
- return {
64
- ...query,
65
- queryKey: queryKey(rest),
66
- async queryFn({ queryKey }) {
67
- const [, { account, nonceKey, ...parameters }] = queryKey
68
- if (!account) throw new Error('account is required.')
69
- if (nonceKey === undefined) throw new Error('nonceKey is required.')
70
- return await getNonce(config, { account, nonceKey, ...parameters })
71
- },
72
- }
73
- }
74
-
75
- export declare namespace queryOptions {
76
- export type Parameters<
77
- config extends Config,
78
- selectData = getNonce.ReturnValue,
79
- > = PartialBy<getNonce.Parameters<config>, 'account' | 'nonceKey'> & {
80
- query?:
81
- | Omit<ReturnValue<config, selectData>, 'queryKey' | 'queryFn'>
82
- | undefined
83
- }
84
-
85
- export type ReturnValue<
86
- config extends Config,
87
- selectData = getNonce.ReturnValue,
88
- > = RequiredBy<
89
- Query.QueryOptions<
90
- getNonce.ReturnValue,
91
- Query.DefaultError,
92
- selectData,
93
- getNonce.QueryKey<config>
94
- >,
95
- 'queryKey' | 'queryFn'
96
- >
97
- }
98
- }
99
-
100
- /**
101
- * Watches for nonce incremented events.
102
- *
103
- * @example
104
- * ```ts
105
- * import { createConfig, http } from '@wagmi/core'
106
- * import { tempo } from 'viem/chains'
107
- * import { Actions } from 'tempo.ts/wagmi'
108
- *
109
- * const config = createConfig({
110
- * chains: [tempoTestnet],
111
- * transports: {
112
- * [tempo.id]: http(),
113
- * },
114
- * })
115
- *
116
- * const unwatch = Actions.nonce.watchNonceIncremented(config, {
117
- * onNonceIncremented: (args, log) => {
118
- * console.log('Nonce incremented:', args)
119
- * },
120
- * })
121
- * ```
122
- *
123
- * @param config - Config.
124
- * @param parameters - Parameters.
125
- * @returns A function to unsubscribe from the event.
126
- */
127
- export function watchNonceIncremented<config extends Config>(
128
- config: config,
129
- parameters: watchNonceIncremented.Parameters<config>,
130
- ): () => void {
131
- const { chainId, ...rest } = parameters
132
- const client = config.getClient({ chainId })
133
- return Actions.nonce.watchNonceIncremented(client, rest)
134
- }
135
-
136
- export declare namespace watchNonceIncremented {
137
- export type Parameters<config extends Config> = ChainIdParameter<config> &
138
- Actions.nonce.watchNonceIncremented.Parameters
139
- }