viem 2.25.0 → 2.26.0-canary-20250406061806
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 +53 -0
- package/_cjs/errors/version.js +1 -1
- package/_cjs/errors/version.js.map +1 -1
- package/_cjs/experimental/eip5792/actions/getCallsStatus.js +22 -4
- package/_cjs/experimental/eip5792/actions/getCallsStatus.js.map +1 -1
- package/_cjs/experimental/eip5792/actions/getCapabilities.js +4 -7
- package/_cjs/experimental/eip5792/actions/getCapabilities.js.map +1 -1
- package/_cjs/experimental/eip5792/actions/sendCalls.js +7 -2
- package/_cjs/experimental/eip5792/actions/sendCalls.js.map +1 -1
- package/_cjs/experimental/eip5792/actions/waitForCallsStatus.js +10 -8
- package/_cjs/experimental/eip5792/actions/waitForCallsStatus.js.map +1 -1
- package/_cjs/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/errors/version.js.map +1 -1
- package/_esm/experimental/eip5792/actions/getCallsStatus.js +26 -5
- package/_esm/experimental/eip5792/actions/getCallsStatus.js.map +1 -1
- package/_esm/experimental/eip5792/actions/getCapabilities.js +4 -7
- package/_esm/experimental/eip5792/actions/getCapabilities.js.map +1 -1
- package/_esm/experimental/eip5792/actions/sendCalls.js +7 -2
- package/_esm/experimental/eip5792/actions/sendCalls.js.map +1 -1
- package/_esm/experimental/eip5792/actions/waitForCallsStatus.js +10 -8
- package/_esm/experimental/eip5792/actions/waitForCallsStatus.js.map +1 -1
- package/_esm/index.js.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/errors/version.d.ts.map +1 -1
- package/_types/experimental/eip5792/actions/getCallsStatus.d.ts +5 -2
- package/_types/experimental/eip5792/actions/getCallsStatus.d.ts.map +1 -1
- package/_types/experimental/eip5792/actions/getCapabilities.d.ts +4 -4
- package/_types/experimental/eip5792/actions/getCapabilities.d.ts.map +1 -1
- package/_types/experimental/eip5792/actions/sendCalls.d.ts +7 -2
- package/_types/experimental/eip5792/actions/sendCalls.d.ts.map +1 -1
- package/_types/experimental/eip5792/actions/waitForCallsStatus.d.ts +5 -7
- package/_types/experimental/eip5792/actions/waitForCallsStatus.d.ts.map +1 -1
- package/_types/index.d.ts +1 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/types/eip1193.d.ts +18 -6
- package/_types/types/eip1193.d.ts.map +1 -1
- package/errors/version.ts +1 -1
- package/experimental/eip5792/actions/getCallsStatus.ts +46 -7
- package/experimental/eip5792/actions/getCapabilities.ts +22 -14
- package/experimental/eip5792/actions/sendCalls.ts +14 -5
- package/experimental/eip5792/actions/waitForCallsStatus.ts +16 -15
- package/index.ts +1 -0
- package/package.json +1 -1
- package/types/eip1193.ts +26 -6
@@ -27,13 +27,16 @@ export type SendCallsParameters<
|
|
27
27
|
> = {
|
28
28
|
chain?: chainOverride | Chain | undefined
|
29
29
|
calls: Calls<Narrow<calls>>
|
30
|
-
capabilities?:
|
31
|
-
|
32
|
-
|
30
|
+
capabilities?: WalletCapabilities | undefined
|
31
|
+
forceAtomic?: boolean | undefined
|
32
|
+
id?: string | undefined
|
33
33
|
version?: WalletSendCallsParameters[number]['version'] | undefined
|
34
34
|
} & GetAccountParameter<account, Account | Address, true, true>
|
35
35
|
|
36
|
-
export type SendCallsReturnType =
|
36
|
+
export type SendCallsReturnType = {
|
37
|
+
capabilities?: WalletCapabilities | undefined
|
38
|
+
id: string
|
39
|
+
}
|
37
40
|
|
38
41
|
export type SendCallsErrorType = RequestErrorType | ErrorType
|
39
42
|
|
@@ -82,6 +85,8 @@ export async function sendCalls<
|
|
82
85
|
account: account_ = client.account,
|
83
86
|
capabilities,
|
84
87
|
chain = client.chain,
|
88
|
+
forceAtomic = false,
|
89
|
+
id,
|
85
90
|
version = '1.0',
|
86
91
|
} = parameters
|
87
92
|
|
@@ -110,21 +115,25 @@ export async function sendCalls<
|
|
110
115
|
})
|
111
116
|
|
112
117
|
try {
|
113
|
-
|
118
|
+
const response = await client.request(
|
114
119
|
{
|
115
120
|
method: 'wallet_sendCalls',
|
116
121
|
params: [
|
117
122
|
{
|
123
|
+
atomicRequired: forceAtomic,
|
118
124
|
calls,
|
119
125
|
capabilities,
|
120
126
|
chainId: numberToHex(chain!.id),
|
121
127
|
from: account?.address,
|
128
|
+
id,
|
122
129
|
version,
|
123
130
|
},
|
124
131
|
],
|
125
132
|
},
|
126
133
|
{ retryCount: 0 },
|
127
134
|
)
|
135
|
+
if (typeof response === 'string') return { id: response }
|
136
|
+
return response
|
128
137
|
} catch (err) {
|
129
138
|
throw getTransactionError(err as BaseError, {
|
130
139
|
...parameters,
|
@@ -3,14 +3,13 @@ import type { Transport } from '../../../clients/transports/createTransport.js'
|
|
3
3
|
import { BaseError } from '../../../errors/base.js'
|
4
4
|
import type { ErrorType } from '../../../errors/utils.js'
|
5
5
|
import type { Chain } from '../../../types/chain.js'
|
6
|
-
import type { WalletGetCallsStatusReturnType } from '../../../types/eip1193.js'
|
7
|
-
import type { Prettify } from '../../../types/utils.js'
|
8
6
|
import { type ObserveErrorType, observe } from '../../../utils/observe.js'
|
9
7
|
import { type PollErrorType, poll } from '../../../utils/poll.js'
|
10
8
|
import { withResolvers } from '../../../utils/promise/withResolvers.js'
|
11
9
|
import { stringify } from '../../../utils/stringify.js'
|
12
10
|
import {
|
13
11
|
type GetCallsStatusErrorType,
|
12
|
+
type GetCallsStatusReturnType,
|
14
13
|
getCallsStatus,
|
15
14
|
} from './getCallsStatus.js'
|
16
15
|
|
@@ -26,11 +25,11 @@ export type WaitForCallsStatusParameters = {
|
|
26
25
|
*/
|
27
26
|
pollingInterval?: number | undefined
|
28
27
|
/**
|
29
|
-
* The status to wait for.
|
28
|
+
* The status range to wait for.
|
30
29
|
*
|
31
|
-
* @default
|
30
|
+
* @default (status) => status >= 200
|
32
31
|
*/
|
33
|
-
status?:
|
32
|
+
status?: ((parameters: GetCallsStatusReturnType) => boolean) | undefined
|
34
33
|
/**
|
35
34
|
* Optional timeout (in milliseconds) to wait before stopping polling.
|
36
35
|
*
|
@@ -39,9 +38,7 @@ export type WaitForCallsStatusParameters = {
|
|
39
38
|
timeout?: number | undefined
|
40
39
|
}
|
41
40
|
|
42
|
-
export type WaitForCallsStatusReturnType =
|
43
|
-
WalletGetCallsStatusReturnType<bigint, 'success' | 'reverted'>
|
44
|
-
>
|
41
|
+
export type WaitForCallsStatusReturnType = GetCallsStatusReturnType
|
45
42
|
|
46
43
|
export type WaitForCallsStatusErrorType =
|
47
44
|
| ObserveErrorType
|
@@ -79,7 +76,7 @@ export async function waitForCallsStatus<chain extends Chain | undefined>(
|
|
79
76
|
const {
|
80
77
|
id,
|
81
78
|
pollingInterval = client.pollingInterval,
|
82
|
-
status =
|
79
|
+
status = ({ statusCode }) => statusCode >= 200,
|
83
80
|
timeout = 60_000,
|
84
81
|
} = parameters
|
85
82
|
const observerId = stringify(['waitForCallsStatus', client.uid, id])
|
@@ -92,15 +89,19 @@ export async function waitForCallsStatus<chain extends Chain | undefined>(
|
|
92
89
|
const unobserve = observe(observerId, { resolve, reject }, (emit) => {
|
93
90
|
const unpoll = poll(
|
94
91
|
async () => {
|
92
|
+
const done = (fn: () => void) => {
|
93
|
+
clearTimeout(timer)
|
94
|
+
unpoll()
|
95
|
+
fn()
|
96
|
+
unobserve()
|
97
|
+
}
|
98
|
+
|
95
99
|
try {
|
96
100
|
const result = await getCallsStatus(client, { id })
|
97
|
-
if (result
|
98
|
-
emit.resolve(result)
|
101
|
+
if (!status(result)) return
|
102
|
+
done(() => emit.resolve(result))
|
99
103
|
} catch (error) {
|
100
|
-
|
101
|
-
unpoll()
|
102
|
-
emit.reject(error)
|
103
|
-
unobserve()
|
104
|
+
done(() => emit.reject(error))
|
104
105
|
}
|
105
106
|
},
|
106
107
|
{
|
package/index.ts
CHANGED
package/package.json
CHANGED
package/types/eip1193.ts
CHANGED
@@ -186,9 +186,19 @@ export type WalletGrantPermissionsReturnType = {
|
|
186
186
|
| undefined
|
187
187
|
}
|
188
188
|
|
189
|
-
export type WalletGetCallsStatusReturnType<
|
190
|
-
|
191
|
-
|
189
|
+
export type WalletGetCallsStatusReturnType<
|
190
|
+
capabilities extends WalletCapabilities = WalletCapabilities,
|
191
|
+
numberType = Hex,
|
192
|
+
bigintType = Hex,
|
193
|
+
receiptStatus = Hex,
|
194
|
+
> = {
|
195
|
+
atomic: boolean
|
196
|
+
capabilities?: capabilities | WalletCapabilities | undefined
|
197
|
+
chainId: numberType
|
198
|
+
id: string
|
199
|
+
receipts?: WalletCallReceipt<bigintType, receiptStatus>[] | undefined
|
200
|
+
status: number
|
201
|
+
version: string
|
192
202
|
}
|
193
203
|
|
194
204
|
export type WalletPermissionCaveat = {
|
@@ -210,18 +220,28 @@ export type WalletSendCallsParameters<
|
|
210
220
|
quantity extends Quantity | bigint = Quantity,
|
211
221
|
> = [
|
212
222
|
{
|
223
|
+
atomicRequired: boolean
|
213
224
|
calls: readonly {
|
225
|
+
capabilities?: capabilities | WalletCapabilities | undefined
|
214
226
|
to?: Address | undefined
|
215
227
|
data?: Hex | undefined
|
216
228
|
value?: quantity | undefined
|
217
229
|
}[]
|
218
|
-
capabilities?: capabilities | undefined
|
230
|
+
capabilities?: capabilities | WalletCapabilities | undefined
|
219
231
|
chainId?: chainId | undefined
|
232
|
+
id?: string | undefined
|
220
233
|
from?: Address | undefined
|
221
234
|
version: string
|
222
235
|
},
|
223
236
|
]
|
224
237
|
|
238
|
+
export type WalletSendCallsReturnType<
|
239
|
+
capabilities extends WalletCapabilities = WalletCapabilities,
|
240
|
+
> = {
|
241
|
+
capabilities?: capabilities | undefined
|
242
|
+
id: string
|
243
|
+
}
|
244
|
+
|
225
245
|
export type WatchAssetParams = {
|
226
246
|
/** Token type. */
|
227
247
|
type: 'ERC20'
|
@@ -1775,7 +1795,7 @@ export type WalletRpcSchema = [
|
|
1775
1795
|
*/
|
1776
1796
|
{
|
1777
1797
|
Method: 'wallet_getCapabilities'
|
1778
|
-
Parameters?: [Address]
|
1798
|
+
Parameters?: [Address | undefined] | undefined
|
1779
1799
|
ReturnType: Prettify<WalletCapabilitiesRecord>
|
1780
1800
|
},
|
1781
1801
|
/**
|
@@ -1836,7 +1856,7 @@ export type WalletRpcSchema = [
|
|
1836
1856
|
{
|
1837
1857
|
Method: 'wallet_sendCalls'
|
1838
1858
|
Parameters?: WalletSendCallsParameters
|
1839
|
-
ReturnType:
|
1859
|
+
ReturnType: WalletSendCallsReturnType
|
1840
1860
|
},
|
1841
1861
|
/**
|
1842
1862
|
* @description Creates, signs, and sends a new transaction to the network
|