viem 2.57.13 → 2.57.15
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 +60 -0
- package/_cjs/account-abstraction/utils/formatters/userOperationReceipt.js +2 -0
- package/_cjs/account-abstraction/utils/formatters/userOperationReceipt.js.map +1 -1
- package/_cjs/actions/public/estimateGas.js +5 -2
- package/_cjs/actions/public/estimateGas.js.map +1 -1
- package/_cjs/actions/public/fillTransaction.js +2 -0
- package/_cjs/actions/public/fillTransaction.js.map +1 -1
- package/_cjs/actions/public/getFilterChanges.js +1 -0
- package/_cjs/actions/public/getFilterChanges.js.map +1 -1
- package/_cjs/actions/public/getFilterLogs.js +1 -0
- package/_cjs/actions/public/getFilterLogs.js.map +1 -1
- package/_cjs/actions/public/watchBlockNumber.js +3 -1
- package/_cjs/actions/public/watchBlockNumber.js.map +1 -1
- package/_cjs/actions/public/watchBlocks.js +20 -8
- package/_cjs/actions/public/watchBlocks.js.map +1 -1
- package/_cjs/actions/public/watchContractEvent.js +10 -3
- package/_cjs/actions/public/watchContractEvent.js.map +1 -1
- package/_cjs/actions/public/watchEvent.js +5 -0
- package/_cjs/actions/public/watchEvent.js.map +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js +3 -2
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/actions/wallet/sendTransaction.js +4 -2
- package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/_cjs/actions/wallet/sendTransactionSync.js +48 -7
- package/_cjs/actions/wallet/sendTransactionSync.js.map +1 -1
- package/_cjs/chains/definitions/hashKeyChain.js +4 -4
- package/_cjs/chains/definitions/hashKeyChain.js.map +1 -1
- package/_cjs/chains/definitions/hashkeyChainTestnet.js +4 -4
- package/_cjs/chains/definitions/hashkeyChainTestnet.js.map +1 -1
- package/_cjs/chains/definitions/turkchain.js +26 -0
- package/_cjs/chains/definitions/turkchain.js.map +1 -0
- package/_cjs/chains/definitions/zksync.js +1 -1
- package/_cjs/chains/definitions/zksync.js.map +1 -1
- package/_cjs/chains/index.js +4 -2
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/createClient.js.map +1 -1
- package/_cjs/clients/transports/fallback.js +5 -0
- package/_cjs/clients/transports/fallback.js.map +1 -1
- package/_cjs/errors/node.js +10 -4
- package/_cjs/errors/node.js.map +1 -1
- package/_cjs/errors/typedData.js +4 -2
- package/_cjs/errors/typedData.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +5 -4
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/Account.js +85 -12
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/Formatters.js +4 -1
- package/_cjs/tempo/Formatters.js.map +1 -1
- package/_cjs/tempo/Relay.js +5 -0
- package/_cjs/tempo/Relay.js.map +1 -1
- package/_cjs/tempo/Transaction.js +2 -1
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +10 -13
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/internal/relay/autoSwap.js +200 -0
- package/_cjs/tempo/internal/relay/autoSwap.js.map +1 -0
- package/_cjs/tempo/internal/relay/error.js +5 -1
- package/_cjs/tempo/internal/relay/error.js.map +1 -1
- package/_cjs/tempo/internal/relay/feePayer.js +18 -5
- package/_cjs/tempo/internal/relay/feePayer.js.map +1 -1
- package/_cjs/tempo/internal/relay/feeToken.js +14 -1
- package/_cjs/tempo/internal/relay/feeToken.js.map +1 -1
- package/_cjs/tempo/internal/relay/simulate.js +57 -15
- package/_cjs/tempo/internal/relay/simulate.js.map +1 -1
- package/_cjs/utils/abi/decodeEventLog.js +57 -7
- package/_cjs/utils/abi/decodeEventLog.js.map +1 -1
- package/_cjs/utils/abi/getAbiItem.js +27 -6
- package/_cjs/utils/abi/getAbiItem.js.map +1 -1
- package/_cjs/utils/abi/parseEventLogs.js +27 -4
- package/_cjs/utils/abi/parseEventLogs.js.map +1 -1
- package/_cjs/utils/authorization/recoverAuthorizationAddress.js +9 -2
- package/_cjs/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
- package/_cjs/utils/authorization/verifyAuthorization.js +14 -4
- package/_cjs/utils/authorization/verifyAuthorization.js.map +1 -1
- package/_cjs/utils/ccip.js +134 -28
- package/_cjs/utils/ccip.js.map +1 -1
- package/_cjs/utils/ccipTunnel.js +5 -1
- package/_cjs/utils/ccipTunnel.js.map +1 -1
- package/_cjs/utils/ens/localBatchGatewayRequest.js +55 -5
- package/_cjs/utils/ens/localBatchGatewayRequest.js.map +1 -1
- package/_cjs/utils/internal/http.js +79 -0
- package/_cjs/utils/internal/http.js.map +1 -0
- package/_cjs/utils/nonceManager.js.map +1 -1
- package/_cjs/utils/rpc/http.js +3 -73
- package/_cjs/utils/rpc/http.js.map +1 -1
- package/_cjs/utils/transaction/assertRequest.js +2 -2
- package/_cjs/utils/transaction/assertRequest.js.map +1 -1
- package/_cjs/utils/transaction/assertTransaction.js +2 -2
- package/_cjs/utils/transaction/assertTransaction.js.map +1 -1
- package/_cjs/utils/transaction/parseTransaction.js +21 -7
- package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
- package/_cjs/utils/typedData.js +19 -6
- package/_cjs/utils/typedData.js.map +1 -1
- package/_esm/account-abstraction/utils/formatters/userOperationReceipt.js +2 -0
- package/_esm/account-abstraction/utils/formatters/userOperationReceipt.js.map +1 -1
- package/_esm/actions/public/estimateGas.js +10 -5
- package/_esm/actions/public/estimateGas.js.map +1 -1
- package/_esm/actions/public/fillTransaction.js +2 -0
- package/_esm/actions/public/fillTransaction.js.map +1 -1
- package/_esm/actions/public/getFilterChanges.js +1 -0
- package/_esm/actions/public/getFilterChanges.js.map +1 -1
- package/_esm/actions/public/getFilterLogs.js +1 -0
- package/_esm/actions/public/getFilterLogs.js.map +1 -1
- package/_esm/actions/public/watchBlockNumber.js +5 -1
- package/_esm/actions/public/watchBlockNumber.js.map +1 -1
- package/_esm/actions/public/watchBlocks.js +28 -8
- package/_esm/actions/public/watchBlocks.js.map +1 -1
- package/_esm/actions/public/watchContractEvent.js +15 -5
- package/_esm/actions/public/watchContractEvent.js.map +1 -1
- package/_esm/actions/public/watchEvent.js +11 -2
- package/_esm/actions/public/watchEvent.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js +3 -2
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/actions/wallet/sendTransaction.js +6 -2
- package/_esm/actions/wallet/sendTransaction.js.map +1 -1
- package/_esm/actions/wallet/sendTransactionSync.js +59 -8
- package/_esm/actions/wallet/sendTransactionSync.js.map +1 -1
- package/_esm/chains/definitions/hashKeyChain.js +4 -4
- package/_esm/chains/definitions/hashKeyChain.js.map +1 -1
- package/_esm/chains/definitions/hashkeyChainTestnet.js +4 -4
- package/_esm/chains/definitions/hashkeyChainTestnet.js.map +1 -1
- package/_esm/chains/definitions/turkchain.js +23 -0
- package/_esm/chains/definitions/turkchain.js.map +1 -0
- package/_esm/chains/definitions/zksync.js +1 -1
- package/_esm/chains/definitions/zksync.js.map +1 -1
- package/_esm/chains/index.js +1 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/createClient.js.map +1 -1
- package/_esm/clients/transports/fallback.js +8 -0
- package/_esm/clients/transports/fallback.js.map +1 -1
- package/_esm/errors/node.js +10 -4
- package/_esm/errors/node.js.map +1 -1
- package/_esm/errors/typedData.js +5 -2
- package/_esm/errors/typedData.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/tempo/Account.js +122 -11
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/Formatters.js +5 -2
- package/_esm/tempo/Formatters.js.map +1 -1
- package/_esm/tempo/Relay.js +20 -0
- package/_esm/tempo/Relay.js.map +1 -1
- package/_esm/tempo/Transaction.js +2 -0
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/chainConfig.js +20 -14
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/internal/relay/autoSwap.js +218 -0
- package/_esm/tempo/internal/relay/autoSwap.js.map +1 -0
- package/_esm/tempo/internal/relay/error.js +6 -2
- package/_esm/tempo/internal/relay/error.js.map +1 -1
- package/_esm/tempo/internal/relay/feePayer.js +24 -7
- package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
- package/_esm/tempo/internal/relay/feeToken.js +17 -3
- package/_esm/tempo/internal/relay/feeToken.js.map +1 -1
- package/_esm/tempo/internal/relay/simulate.js +68 -17
- package/_esm/tempo/internal/relay/simulate.js.map +1 -1
- package/_esm/utils/abi/decodeEventLog.js +69 -7
- package/_esm/utils/abi/decodeEventLog.js.map +1 -1
- package/_esm/utils/abi/getAbiItem.js +34 -6
- package/_esm/utils/abi/getAbiItem.js.map +1 -1
- package/_esm/utils/abi/parseEventLogs.js +43 -10
- package/_esm/utils/abi/parseEventLogs.js.map +1 -1
- package/_esm/utils/authorization/recoverAuthorizationAddress.js +11 -2
- package/_esm/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
- package/_esm/utils/authorization/verifyAuthorization.js +15 -4
- package/_esm/utils/authorization/verifyAuthorization.js.map +1 -1
- package/_esm/utils/ccip.js +163 -31
- package/_esm/utils/ccip.js.map +1 -1
- package/_esm/utils/ccipTunnel.js +5 -1
- package/_esm/utils/ccipTunnel.js.map +1 -1
- package/_esm/utils/ens/localBatchGatewayRequest.js +69 -4
- package/_esm/utils/ens/localBatchGatewayRequest.js.map +1 -1
- package/_esm/utils/internal/http.js +83 -0
- package/_esm/utils/internal/http.js.map +1 -0
- package/_esm/utils/nonceManager.js.map +1 -1
- package/_esm/utils/rpc/http.js +1 -75
- package/_esm/utils/rpc/http.js.map +1 -1
- package/_esm/utils/transaction/assertRequest.js +2 -2
- package/_esm/utils/transaction/assertRequest.js.map +1 -1
- package/_esm/utils/transaction/assertTransaction.js +2 -2
- package/_esm/utils/transaction/assertTransaction.js.map +1 -1
- package/_esm/utils/transaction/parseTransaction.js +24 -7
- package/_esm/utils/transaction/parseTransaction.js.map +1 -1
- package/_esm/utils/typedData.js +25 -8
- package/_esm/utils/typedData.js.map +1 -1
- package/_types/account-abstraction/utils/formatters/userOperationReceipt.d.ts.map +1 -1
- package/_types/actions/public/estimateGas.d.ts.map +1 -1
- package/_types/actions/public/fillTransaction.d.ts.map +1 -1
- package/_types/actions/public/getFilterChanges.d.ts.map +1 -1
- package/_types/actions/public/getFilterLogs.d.ts.map +1 -1
- package/_types/actions/public/watchBlockNumber.d.ts +6 -2
- package/_types/actions/public/watchBlockNumber.d.ts.map +1 -1
- package/_types/actions/public/watchBlocks.d.ts +7 -2
- package/_types/actions/public/watchBlocks.d.ts.map +1 -1
- package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/_types/actions/public/watchEvent.d.ts.map +1 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransactionSync.d.ts.map +1 -1
- package/_types/chains/definitions/hashKeyChain.d.ts +4 -4
- package/_types/chains/definitions/hashkeyChainTestnet.d.ts +4 -4
- package/_types/chains/definitions/turkchain.d.ts +53 -0
- package/_types/chains/definitions/turkchain.d.ts.map +1 -0
- package/_types/chains/definitions/zksync.d.ts +1 -1
- package/_types/chains/index.d.ts +1 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/createClient.d.ts +6 -0
- package/_types/clients/createClient.d.ts.map +1 -1
- package/_types/clients/transports/fallback.d.ts.map +1 -1
- package/_types/errors/node.d.ts.map +1 -1
- package/_types/errors/typedData.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +1 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/tempo/Account.d.ts +78 -5
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Capabilities.d.ts +32 -2
- package/_types/tempo/Capabilities.d.ts.map +1 -1
- package/_types/tempo/Relay.d.ts +27 -1
- package/_types/tempo/Relay.d.ts.map +1 -1
- package/_types/tempo/Transaction.d.ts +2 -0
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/actions/accessKey.d.ts +2 -2
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/internal/relay/autoSwap.d.ts +3 -0
- package/_types/tempo/internal/relay/autoSwap.d.ts.map +1 -0
- package/_types/tempo/internal/relay/error.d.ts.map +1 -1
- package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -1
- package/_types/tempo/internal/relay/feeToken.d.ts.map +1 -1
- package/_types/tempo/internal/relay/simulate.d.ts +4 -0
- package/_types/tempo/internal/relay/simulate.d.ts.map +1 -1
- package/_types/tempo/internal/relay/utils.d.ts +8 -8
- package/_types/utils/abi/decodeEventLog.d.ts +13 -1
- package/_types/utils/abi/decodeEventLog.d.ts.map +1 -1
- package/_types/utils/abi/getAbiItem.d.ts.map +1 -1
- package/_types/utils/abi/parseEventLogs.d.ts.map +1 -1
- package/_types/utils/authorization/recoverAuthorizationAddress.d.ts +2 -1
- package/_types/utils/authorization/recoverAuthorizationAddress.d.ts.map +1 -1
- package/_types/utils/authorization/verifyAuthorization.d.ts.map +1 -1
- package/_types/utils/ccip.d.ts +24 -4
- package/_types/utils/ccip.d.ts.map +1 -1
- package/_types/utils/ccipTunnel.d.ts.map +1 -1
- package/_types/utils/ens/localBatchGatewayRequest.d.ts +26 -0
- package/_types/utils/ens/localBatchGatewayRequest.d.ts.map +1 -1
- package/_types/utils/internal/http.d.ts +16 -0
- package/_types/utils/internal/http.d.ts.map +1 -0
- package/_types/utils/nonceManager.d.ts +15 -1
- package/_types/utils/nonceManager.d.ts.map +1 -1
- package/_types/utils/rpc/http.d.ts.map +1 -1
- package/_types/utils/transaction/parseTransaction.d.ts.map +1 -1
- package/_types/utils/typedData.d.ts.map +1 -1
- package/account-abstraction/utils/formatters/userOperationReceipt.ts +1 -0
- package/actions/public/estimateGas.ts +12 -5
- package/actions/public/fillTransaction.ts +2 -0
- package/actions/public/getFilterChanges.ts +1 -0
- package/actions/public/getFilterLogs.ts +1 -0
- package/actions/public/watchBlockNumber.ts +11 -2
- package/actions/public/watchBlocks.ts +46 -14
- package/actions/public/watchContractEvent.ts +22 -4
- package/actions/public/watchEvent.ts +17 -1
- package/actions/wallet/prepareTransactionRequest.ts +6 -2
- package/actions/wallet/sendTransaction.ts +9 -3
- package/actions/wallet/sendTransactionSync.ts +74 -12
- package/chains/definitions/hashKeyChain.ts +4 -4
- package/chains/definitions/hashkeyChainTestnet.ts +4 -4
- package/chains/definitions/turkchain.ts +23 -0
- package/chains/definitions/zksync.ts +1 -1
- package/chains/index.ts +1 -0
- package/clients/createClient.ts +6 -0
- package/clients/transports/fallback.ts +11 -0
- package/errors/node.ts +11 -5
- package/errors/typedData.ts +5 -2
- package/errors/version.ts +1 -1
- package/index.ts +2 -0
- package/package.json +1 -1
- package/tempo/Account.ts +203 -17
- package/tempo/Capabilities.ts +34 -2
- package/tempo/Formatters.ts +5 -5
- package/tempo/Relay.ts +32 -1
- package/tempo/Transaction.ts +3 -0
- package/tempo/actions/accessKey.ts +2 -2
- package/tempo/chainConfig.ts +22 -14
- package/tempo/internal/relay/autoSwap.ts +263 -0
- package/tempo/internal/relay/error.ts +7 -2
- package/tempo/internal/relay/feePayer.ts +30 -7
- package/tempo/internal/relay/feeToken.ts +21 -3
- package/tempo/internal/relay/simulate.ts +106 -19
- package/utils/abi/decodeEventLog.ts +97 -10
- package/utils/abi/getAbiItem.ts +35 -5
- package/utils/abi/parseEventLogs.ts +48 -11
- package/utils/authorization/recoverAuthorizationAddress.ts +18 -2
- package/utils/authorization/verifyAuthorization.ts +12 -7
- package/utils/ccip.ts +199 -33
- package/utils/ccipTunnel.ts +5 -1
- package/utils/ens/localBatchGatewayRequest.ts +82 -4
- package/utils/internal/http.ts +92 -0
- package/utils/nonceManager.ts +16 -1
- package/utils/rpc/http.ts +1 -83
- package/utils/transaction/assertRequest.ts +2 -2
- package/utils/transaction/assertTransaction.ts +2 -2
- package/utils/transaction/parseTransaction.ts +32 -7
- package/utils/typedData.ts +31 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Abi, AbiParameter } from 'abitype'
|
|
1
|
+
import type { Abi, AbiEvent, AbiParameter } from 'abitype'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
AbiDecodingDataSizeTooSmallError,
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
DecodeLogTopicsMismatch,
|
|
13
13
|
type DecodeLogTopicsMismatchErrorType,
|
|
14
14
|
} from '../../errors/abi.js'
|
|
15
|
+
import { BaseError } from '../../errors/base.js'
|
|
15
16
|
import { PositionOutOfBoundsError } from '../../errors/cursor.js'
|
|
16
17
|
import type { ErrorType } from '../../errors/utils.js'
|
|
17
18
|
import type {
|
|
@@ -84,6 +85,7 @@ export type DecodeEventLogReturnType<
|
|
|
84
85
|
|
|
85
86
|
export type DecodeEventLogErrorType =
|
|
86
87
|
| AbiDecodingDataSizeTooSmallErrorType
|
|
88
|
+
| AbiEventAmbiguityErrorType
|
|
87
89
|
| AbiEventSignatureEmptyTopicsErrorType
|
|
88
90
|
| AbiEventSignatureNotFoundErrorType
|
|
89
91
|
| DecodeAbiParametersErrorType
|
|
@@ -107,23 +109,81 @@ export function decodeEventLog<
|
|
|
107
109
|
const {
|
|
108
110
|
abi,
|
|
109
111
|
data,
|
|
112
|
+
eventName,
|
|
110
113
|
strict: strict_,
|
|
111
114
|
topics,
|
|
112
115
|
} = parameters as DecodeEventLogParameters
|
|
113
116
|
|
|
114
117
|
const strict = strict_ ?? true
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const abiItem = abi.find(
|
|
119
|
-
(x) =>
|
|
120
|
-
x.type === 'event' &&
|
|
121
|
-
signature === toEventSelector(formatAbiItem(x) as EventDefinition),
|
|
118
|
+
const events = abi.filter(
|
|
119
|
+
(item): item is AbiEvent => item.type === 'event' && 'name' in item,
|
|
122
120
|
)
|
|
121
|
+
// Anonymous events omit the signature topic, so `topics[0]` is an indexed
|
|
122
|
+
// argument. A signature match still wins when the log has one.
|
|
123
|
+
const signature = topics[0]
|
|
124
|
+
const bySelector = signature
|
|
125
|
+
? events.find(
|
|
126
|
+
(item) =>
|
|
127
|
+
!item.anonymous &&
|
|
128
|
+
signature === toEventSelector(formatAbiItem(item) as EventDefinition),
|
|
129
|
+
)
|
|
130
|
+
: undefined
|
|
131
|
+
const candidates = bySelector
|
|
132
|
+
? [bySelector]
|
|
133
|
+
: anonymousCandidates(events, topics.length, eventName)
|
|
123
134
|
|
|
124
|
-
if (
|
|
135
|
+
if (candidates.length > 1)
|
|
136
|
+
throw new AbiEventAmbiguityError(candidates.map((item) => item.name))
|
|
137
|
+
const abiItem = candidates[0]
|
|
138
|
+
if (!abiItem) {
|
|
139
|
+
if (!signature) throw new AbiEventSignatureEmptyTopicsError({ docsPath })
|
|
125
140
|
throw new AbiEventSignatureNotFoundError(signature, { docsPath })
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return decodeMatchedEventLog({
|
|
144
|
+
abiItem,
|
|
145
|
+
argTopics: abiItem.anonymous ? topics : topics.slice(1),
|
|
146
|
+
data,
|
|
147
|
+
strict,
|
|
148
|
+
}) as DecodeEventLogReturnType<abi, eventName, topics, data, strict>
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function anonymousCandidates(
|
|
152
|
+
events: readonly AbiEvent[],
|
|
153
|
+
topicCount: number,
|
|
154
|
+
eventName: string | undefined,
|
|
155
|
+
) {
|
|
156
|
+
// Nothing in a log identifies an anonymous event, so any log with the same
|
|
157
|
+
// topic count fits it. Anonymous events are only considered when requested:
|
|
158
|
+
// `eventName` names one, or every event in the ABI is anonymous. Otherwise a
|
|
159
|
+
// log from another contract is decoded as the anonymous event.
|
|
160
|
+
const requested = (() => {
|
|
161
|
+
if (eventName) return events.filter((item) => item.name === eventName)
|
|
162
|
+
if (events.every((item) => item.anonymous)) return events
|
|
163
|
+
return []
|
|
164
|
+
})()
|
|
165
|
+
// `eventName` does not skip the arity check, or a same-name overload with
|
|
166
|
+
// extra topics is guessed.
|
|
167
|
+
return requested.filter(
|
|
168
|
+
(item) => item.anonymous && indexedCount(item) === topicCount,
|
|
169
|
+
)
|
|
170
|
+
}
|
|
126
171
|
|
|
172
|
+
function indexedCount(item: AbiEvent) {
|
|
173
|
+
return item.inputs?.filter((input) => input.indexed).length ?? 0
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function decodeMatchedEventLog({
|
|
177
|
+
abiItem,
|
|
178
|
+
argTopics,
|
|
179
|
+
data,
|
|
180
|
+
strict,
|
|
181
|
+
}: {
|
|
182
|
+
abiItem: AbiEvent
|
|
183
|
+
argTopics: readonly Hex[]
|
|
184
|
+
data: Hex | undefined
|
|
185
|
+
strict: boolean
|
|
186
|
+
}): DecodeEventLogReturnType {
|
|
127
187
|
const { name, inputs } = abiItem
|
|
128
188
|
const isUnnamed = inputs?.some((x) => !('name' in x && x.name))
|
|
129
189
|
|
|
@@ -216,7 +276,7 @@ export function decodeEventLog<
|
|
|
216
276
|
return {
|
|
217
277
|
eventName: name,
|
|
218
278
|
args: Object.values(args).length > 0 ? args : undefined,
|
|
219
|
-
} as
|
|
279
|
+
} as DecodeEventLogReturnType
|
|
220
280
|
}
|
|
221
281
|
|
|
222
282
|
function decodeTopic({ param, value }: { param: AbiParameter; value: Hex }) {
|
|
@@ -230,3 +290,30 @@ function decodeTopic({ param, value }: { param: AbiParameter; value: Hex }) {
|
|
|
230
290
|
const decodedArg = decodeAbiParameters([param], value) || []
|
|
231
291
|
return decodedArg[0]
|
|
232
292
|
}
|
|
293
|
+
|
|
294
|
+
/** Error type thrown when an anonymous event log matches more than one event. */
|
|
295
|
+
export type AbiEventAmbiguityErrorType = AbiEventAmbiguityError & {
|
|
296
|
+
name: 'AbiEventAmbiguityError'
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Thrown by {@link decodeEventLog} when an anonymous event log fits more than
|
|
300
|
+
* one requested anonymous event with the same number of indexed inputs.
|
|
301
|
+
*/
|
|
302
|
+
export class AbiEventAmbiguityError extends BaseError {
|
|
303
|
+
constructor(eventNames: readonly string[]) {
|
|
304
|
+
// `eventName` cannot choose between overloads that share a name, so those
|
|
305
|
+
// need an ABI narrowed to one event.
|
|
306
|
+
const distinct = new Set(eventNames).size === eventNames.length
|
|
307
|
+
super('Ambiguous anonymous event log.', {
|
|
308
|
+
docsPath,
|
|
309
|
+
metaMessages: [
|
|
310
|
+
`Matched ${eventNames.map((name) => `\`${name}\``).join(', ')}.`,
|
|
311
|
+
'These events take the same number of indexed topics.',
|
|
312
|
+
distinct
|
|
313
|
+
? 'Pass `eventName` to choose one.'
|
|
314
|
+
: 'Pass an `abi` that holds only the event to decode.',
|
|
315
|
+
],
|
|
316
|
+
name: 'AbiEventAmbiguityError',
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
}
|
package/utils/abi/getAbiItem.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type { Hex } from '../../types/misc.js'
|
|
|
16
16
|
import type { UnionEvaluate } from '../../types/utils.js'
|
|
17
17
|
import { type IsHexErrorType, isHex } from '../../utils/data/isHex.js'
|
|
18
18
|
import { type IsAddressErrorType, isAddress } from '../address/isAddress.js'
|
|
19
|
+
import { size } from '../data/size.js'
|
|
19
20
|
import { toEventSelector } from '../hash/toEventSelector.js'
|
|
20
21
|
import {
|
|
21
22
|
type ToFunctionSelectorErrorType,
|
|
@@ -188,13 +189,30 @@ export function isArgOfType(arg: unknown, abiParameter: AbiParameter): boolean {
|
|
|
188
189
|
/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(
|
|
189
190
|
abiParameterType,
|
|
190
191
|
)
|
|
191
|
-
)
|
|
192
|
-
|
|
192
|
+
) {
|
|
193
|
+
if (typeof arg !== 'bigint' && typeof arg !== 'number') return false
|
|
194
|
+
if (typeof arg === 'number' && !Number.isInteger(arg)) return false
|
|
195
|
+
|
|
196
|
+
const signed = abiParameterType.startsWith('int')
|
|
197
|
+
const bits = Number.parseInt(
|
|
198
|
+
abiParameterType.replace(/^u?int/, '') || '256',
|
|
199
|
+
10,
|
|
200
|
+
)
|
|
201
|
+
const max = 2n ** (BigInt(bits) - (signed ? 1n : 0n)) - 1n
|
|
202
|
+
const min = signed ? -max - 1n : 0n
|
|
203
|
+
return arg >= min && arg <= max
|
|
204
|
+
}
|
|
193
205
|
|
|
194
206
|
// `bytes<M>`: binary type of `M` bytes, `0 < M <= 32`
|
|
195
207
|
// https://regexr.com/6va55
|
|
196
|
-
if (/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(abiParameterType))
|
|
197
|
-
|
|
208
|
+
if (/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(abiParameterType)) {
|
|
209
|
+
if (typeof arg !== 'string' && !(arg instanceof Uint8Array))
|
|
210
|
+
return false
|
|
211
|
+
const bytes = abiParameterType.slice(5)
|
|
212
|
+
if (!bytes) return true
|
|
213
|
+
if (typeof arg === 'string' && !isHex(arg)) return false
|
|
214
|
+
return size(arg) === Number.parseInt(bytes, 10)
|
|
215
|
+
}
|
|
198
216
|
|
|
199
217
|
// fixed-length (`<type>[M]`) and dynamic (`<type>[]`) arrays
|
|
200
218
|
const arrayComponents = getArrayComponents(abiParameterType)
|
|
@@ -253,6 +271,15 @@ export function getAmbiguousTypes(
|
|
|
253
271
|
[(args[parameterIndex] as readonly unknown[] | undefined)?.[0]],
|
|
254
272
|
)
|
|
255
273
|
if (types) return types
|
|
274
|
+
// Same element type, different array shape: `uint256[]` and `uint256[2]`
|
|
275
|
+
// both accept `[1n, 1n]`, but one is dynamic and the other is static.
|
|
276
|
+
// Skip this when the element types differ. `string[]` vs `address[]`
|
|
277
|
+
// stays unambiguous for a non-address string.
|
|
278
|
+
if (
|
|
279
|
+
sourceArray[1] === targetArray[1] &&
|
|
280
|
+
sourceParameter.type !== targetParameter.type
|
|
281
|
+
)
|
|
282
|
+
return [sourceParameter.type, targetParameter.type]
|
|
256
283
|
continue
|
|
257
284
|
}
|
|
258
285
|
|
|
@@ -260,8 +287,8 @@ export function getAmbiguousTypes(
|
|
|
260
287
|
const value = args[parameterIndex]
|
|
261
288
|
|
|
262
289
|
const ambiguous = (() => {
|
|
263
|
-
if (types.includes('address') && types.includes('bytes20')) return true
|
|
264
290
|
// An `undefined` value comes from an empty array, which matches both types.
|
|
291
|
+
// This stays above the catch-all: a non-address string is not ambiguous.
|
|
265
292
|
if (
|
|
266
293
|
types.includes('address') &&
|
|
267
294
|
(types.includes('string') || types.includes('bytes'))
|
|
@@ -269,6 +296,9 @@ export function getAmbiguousTypes(
|
|
|
269
296
|
return (
|
|
270
297
|
value === undefined || isAddress(value as Address, { strict: false })
|
|
271
298
|
)
|
|
299
|
+
// Distinct types that both matched cannot be distinguished at runtime
|
|
300
|
+
// (e.g. `bytes` vs `bytes32`, `uint256` vs `int256`, `address` vs `bytes20`).
|
|
301
|
+
if (sourceParameter.type !== targetParameter.type) return true
|
|
272
302
|
return false
|
|
273
303
|
})()
|
|
274
304
|
|
|
@@ -117,6 +117,20 @@ export function parseEventLogs<
|
|
|
117
117
|
selector: toEventSelector(abiItem),
|
|
118
118
|
}))
|
|
119
119
|
|
|
120
|
+
// Nothing in a log identifies an anonymous event, so any log with the same
|
|
121
|
+
// topic count fits it. Anonymous events are only considered when requested:
|
|
122
|
+
// `eventName` names one, or every event in the ABI is anonymous. Otherwise a
|
|
123
|
+
// log from another contract in the same receipt is decoded as the anonymous
|
|
124
|
+
// event.
|
|
125
|
+
const anonymousTopics = (() => {
|
|
126
|
+
if (eventName)
|
|
127
|
+
return abiTopics.filter(
|
|
128
|
+
(item) => item.abi.anonymous && eventName.includes(item.abi.name),
|
|
129
|
+
)
|
|
130
|
+
if (abiTopics.every((item) => item.abi.anonymous)) return abiTopics
|
|
131
|
+
return []
|
|
132
|
+
})()
|
|
133
|
+
|
|
120
134
|
return logs
|
|
121
135
|
.map((log) => {
|
|
122
136
|
// Normalize RpcLog (hex-encoded quantities) to Log (bigint/number).
|
|
@@ -125,12 +139,29 @@ export function parseEventLogs<
|
|
|
125
139
|
const formattedLog =
|
|
126
140
|
typeof log.blockNumber === 'string' ? formatLog(log as RpcLog) : log
|
|
127
141
|
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
142
|
+
// Non-anonymous events share a signature topic. Several events can share
|
|
143
|
+
// that selector and differ in indexed parameters (ERC-20 vs ERC-721
|
|
144
|
+
// `Transfer`). Check that against the whole ABI before `eventName`, so
|
|
145
|
+
// an anonymous event never claims a log whose signature is known.
|
|
146
|
+
const bySelector = abiTopics.filter(
|
|
147
|
+
(item) =>
|
|
148
|
+
!item.abi.anonymous && formattedLog.topics[0] === item.selector,
|
|
133
149
|
)
|
|
150
|
+
const abiItems = (() => {
|
|
151
|
+
if (bySelector.length > 0) {
|
|
152
|
+
if (!eventName) return bySelector
|
|
153
|
+
return bySelector.filter((item) => eventName.includes(item.abi.name))
|
|
154
|
+
}
|
|
155
|
+
// A dynamic ABI value can decode as a static type without throwing, so
|
|
156
|
+
// several anonymous events of the same arity are not guessed.
|
|
157
|
+
const anonymous = anonymousTopics.filter(
|
|
158
|
+
(item) =>
|
|
159
|
+
(item.abi.inputs?.filter((input) => input.indexed).length ?? 0) ===
|
|
160
|
+
formattedLog.topics.length,
|
|
161
|
+
)
|
|
162
|
+
if (anonymous.length === 1) return anonymous
|
|
163
|
+
return []
|
|
164
|
+
})()
|
|
134
165
|
if (abiItems.length === 0) return null
|
|
135
166
|
|
|
136
167
|
// Try each matching ABI item until one successfully decodes.
|
|
@@ -152,9 +183,12 @@ export function parseEventLogs<
|
|
|
152
183
|
}
|
|
153
184
|
|
|
154
185
|
// If strict decoding failed for all, and we're in non-strict mode,
|
|
155
|
-
// fall back to the first
|
|
186
|
+
// fall back to the first signature match. An anonymous candidate that
|
|
187
|
+
// failed to decode is not identified, so it is left out.
|
|
156
188
|
if (!event && !strict) {
|
|
157
|
-
|
|
189
|
+
const fallback = abiItems[0]
|
|
190
|
+
if (!fallback || fallback.abi.anonymous) return null
|
|
191
|
+
abiItem = fallback
|
|
158
192
|
try {
|
|
159
193
|
event = decodeEventLog({
|
|
160
194
|
data: formattedLog.data,
|
|
@@ -180,6 +214,7 @@ export function parseEventLogs<
|
|
|
180
214
|
// Check that the decoded event args match the provided args.
|
|
181
215
|
if (
|
|
182
216
|
!includesArgs({
|
|
217
|
+
anonymous: abiItem.abi.anonymous,
|
|
183
218
|
args: event.args,
|
|
184
219
|
inputs: abiItem.abi.inputs,
|
|
185
220
|
matchArgs: args,
|
|
@@ -198,21 +233,23 @@ export function parseEventLogs<
|
|
|
198
233
|
}
|
|
199
234
|
|
|
200
235
|
function includesArgs(parameters: {
|
|
236
|
+
anonymous?: boolean | undefined
|
|
201
237
|
args: unknown
|
|
202
238
|
inputs: AbiEvent['inputs']
|
|
203
239
|
matchArgs: unknown
|
|
204
240
|
topics: Log['topics']
|
|
205
241
|
}) {
|
|
206
|
-
const { args, inputs, matchArgs, topics } = parameters
|
|
242
|
+
const { anonymous, args, inputs, matchArgs, topics } = parameters
|
|
207
243
|
|
|
208
244
|
if (!matchArgs) return true
|
|
209
245
|
if (!args) return false
|
|
210
246
|
|
|
211
|
-
// Topics hold the signature, then indexed inputs in order.
|
|
212
|
-
// decoding reads indexed inputs without
|
|
247
|
+
// Topics hold the signature, then indexed inputs in order. Anonymous events
|
|
248
|
+
// have no signature topic. Non-strict decoding reads indexed inputs without
|
|
249
|
+
// a topic from data.
|
|
213
250
|
const topicInputs = inputs
|
|
214
251
|
.filter((input) => input.indexed)
|
|
215
|
-
.slice(0, topics.length - 1)
|
|
252
|
+
.slice(0, anonymous ? topics.length : topics.length - 1)
|
|
216
253
|
|
|
217
254
|
function isEqual(input: AbiEventParameter, value: unknown, arg: unknown) {
|
|
218
255
|
try {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { Address } from 'abitype'
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
InvalidYParityError,
|
|
5
|
+
type InvalidYParityErrorType,
|
|
6
|
+
} from '../../errors/transaction.js'
|
|
3
7
|
import type { ErrorType } from '../../errors/utils.js'
|
|
4
8
|
import type {
|
|
5
9
|
Authorization,
|
|
@@ -47,6 +51,7 @@ export type RecoverAuthorizationAddressReturnType = Address
|
|
|
47
51
|
|
|
48
52
|
export type RecoverAuthorizationAddressErrorType =
|
|
49
53
|
| HashAuthorizationErrorType
|
|
54
|
+
| InvalidYParityErrorType
|
|
50
55
|
| RecoverAddressErrorType
|
|
51
56
|
| ErrorType
|
|
52
57
|
|
|
@@ -57,10 +62,21 @@ export async function recoverAuthorizationAddress<
|
|
|
57
62
|
>(
|
|
58
63
|
parameters: RecoverAuthorizationAddressParameters<authorization>,
|
|
59
64
|
): Promise<RecoverAuthorizationAddressReturnType> {
|
|
60
|
-
const { authorization
|
|
65
|
+
const { authorization } = parameters
|
|
66
|
+
const signature = (parameters.signature ?? authorization) as Signature
|
|
67
|
+
|
|
68
|
+
// EIP-7702 recovers the authority with `y_parity` as the raw recovery id, so a
|
|
69
|
+
// tuple with any other `yParity` (such as 27 or 28) has no authority.
|
|
70
|
+
if (
|
|
71
|
+
typeof signature === 'object' &&
|
|
72
|
+
typeof signature.yParity === 'number' &&
|
|
73
|
+
signature.yParity !== 0 &&
|
|
74
|
+
signature.yParity !== 1
|
|
75
|
+
)
|
|
76
|
+
throw new InvalidYParityError({ yParity: BigInt(signature.yParity) })
|
|
61
77
|
|
|
62
78
|
return recoverAddress({
|
|
63
79
|
hash: hashAuthorization(authorization as AuthorizationRequest),
|
|
64
|
-
signature
|
|
80
|
+
signature,
|
|
65
81
|
})
|
|
66
82
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Address } from 'abitype'
|
|
2
2
|
|
|
3
|
+
import { InvalidYParityError } from '../../errors/transaction.js'
|
|
3
4
|
import type { ErrorType } from '../../errors/utils.js'
|
|
4
5
|
import { type GetAddressErrorType, getAddress } from '../address/getAddress.js'
|
|
5
6
|
import {
|
|
@@ -39,11 +40,15 @@ export async function verifyAuthorization({
|
|
|
39
40
|
authorization,
|
|
40
41
|
signature,
|
|
41
42
|
}: VerifyAuthorizationParameters): Promise<VerifyAuthorizationReturnType> {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
const recovered = await (async () => {
|
|
44
|
+
try {
|
|
45
|
+
return await recoverAuthorizationAddress({ authorization, signature })
|
|
46
|
+
} catch (error) {
|
|
47
|
+
// A `yParity` other than 0 or 1 has no authority under EIP-7702.
|
|
48
|
+
if (error instanceof InvalidYParityError) return undefined
|
|
49
|
+
throw error
|
|
50
|
+
}
|
|
51
|
+
})()
|
|
52
|
+
if (!recovered) return false
|
|
53
|
+
return isAddressEqual(getAddress(address), recovered)
|
|
49
54
|
}
|