viem 1.5.4 → 1.6.2
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/chains/utils/package.json +5 -0
- package/dist/cjs/accounts/index.js +5 -1
- package/dist/cjs/accounts/index.js.map +1 -1
- package/dist/cjs/accounts/utils/privateKeyToAddress.js +12 -0
- package/dist/cjs/accounts/utils/privateKeyToAddress.js.map +1 -0
- package/dist/cjs/accounts/utils/signTransaction.js.map +1 -1
- package/dist/cjs/actions/getContract.js.map +1 -1
- package/dist/cjs/actions/public/estimateGas.js +3 -1
- package/dist/cjs/actions/public/estimateGas.js.map +1 -1
- package/dist/cjs/actions/public/multicall.js +2 -3
- package/dist/cjs/actions/public/multicall.js.map +1 -1
- package/dist/cjs/actions/public/watchContractEvent.js +134 -67
- package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
- package/dist/cjs/actions/public/watchEvent.js +136 -62
- package/dist/cjs/actions/public/watchEvent.js.map +1 -1
- package/dist/cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/cjs/actions/wallet/writeContract.js.map +1 -1
- package/dist/cjs/chains/{formatters/celo.js → celo/formatters.js} +1 -1
- package/dist/cjs/chains/celo/formatters.js.map +1 -0
- package/dist/cjs/chains/{serializers/celo.js → celo/serializers.js} +1 -1
- package/dist/cjs/chains/celo/serializers.js.map +1 -0
- package/dist/cjs/{types/formatter.js → chains/celo/types.js} +1 -1
- package/dist/cjs/chains/celo/types.js.map +1 -0
- package/dist/cjs/chains/index.js +32 -16
- package/dist/cjs/chains/index.js.map +1 -1
- package/dist/cjs/chains/optimism/fees.js +7 -0
- package/dist/cjs/chains/optimism/fees.js.map +1 -0
- package/dist/cjs/chains/{formatters/optimism.js → optimism/formatters.js} +13 -1
- package/dist/cjs/chains/optimism/formatters.js.map +1 -0
- package/dist/cjs/{types/serializer.js → chains/optimism/types.js} +1 -1
- package/dist/cjs/chains/optimism/types.js.map +1 -0
- package/dist/cjs/chains/utils.js +11 -0
- package/dist/cjs/chains/utils.js.map +1 -0
- package/dist/cjs/clients/decorators/public.js.map +1 -1
- package/dist/cjs/constants/number.js +96 -96
- package/dist/cjs/constants/number.js.map +1 -1
- package/dist/cjs/errors/node.js +1 -1
- package/dist/cjs/errors/node.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/abi/decodeAbiParameters.js.map +1 -1
- package/dist/cjs/utils/abi/decodeDeployData.js.map +1 -1
- package/dist/cjs/utils/abi/decodeErrorResult.js.map +1 -1
- package/dist/cjs/utils/abi/decodeFunctionResult.js.map +1 -1
- package/dist/cjs/utils/abi/encodeAbiParameters.js.map +1 -1
- package/dist/cjs/utils/abi/encodeDeployData.js.map +1 -1
- package/dist/cjs/utils/abi/encodeEventTopics.js.map +1 -1
- package/dist/cjs/utils/abi/encodePacked.js.map +1 -1
- package/dist/cjs/utils/chain.js +5 -3
- package/dist/cjs/utils/chain.js.map +1 -1
- package/dist/cjs/utils/formatters/block.js.map +1 -1
- package/dist/cjs/utils/formatters/extract.js.map +1 -1
- package/dist/cjs/utils/formatters/formatter.js.map +1 -1
- package/dist/cjs/utils/formatters/transaction.js.map +1 -1
- package/dist/cjs/utils/formatters/transactionReceipt.js.map +1 -1
- package/dist/cjs/utils/formatters/transactionRequest.js.map +1 -1
- package/dist/cjs/utils/poll.js +1 -1
- package/dist/cjs/utils/poll.js.map +1 -1
- package/dist/cjs/utils/transaction/prepareRequest.js +15 -6
- package/dist/cjs/utils/transaction/prepareRequest.js.map +1 -1
- package/dist/cjs/utils/typedData.js +2 -2
- package/dist/cjs/utils/typedData.js.map +1 -1
- package/dist/esm/accounts/index.js +2 -0
- package/dist/esm/accounts/index.js.map +1 -1
- package/dist/esm/accounts/utils/privateKeyToAddress.js +15 -0
- package/dist/esm/accounts/utils/privateKeyToAddress.js.map +1 -0
- package/dist/esm/accounts/utils/signTransaction.js.map +1 -1
- package/dist/esm/actions/getContract.js.map +1 -1
- package/dist/esm/actions/public/estimateGas.js +4 -2
- package/dist/esm/actions/public/estimateGas.js.map +1 -1
- package/dist/esm/actions/public/multicall.js +2 -4
- package/dist/esm/actions/public/multicall.js.map +1 -1
- package/dist/esm/actions/public/watchContractEvent.js +145 -76
- package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
- package/dist/esm/actions/public/watchEvent.js +146 -70
- package/dist/esm/actions/public/watchEvent.js.map +1 -1
- package/dist/esm/actions/wallet/sendTransaction.js +1 -1
- package/dist/esm/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/esm/actions/wallet/writeContract.js.map +1 -1
- package/dist/esm/chains/{formatters/celo.js → celo/formatters.js} +2 -2
- package/dist/esm/chains/celo/formatters.js.map +1 -0
- package/dist/esm/chains/{serializers/celo.js → celo/serializers.js} +1 -1
- package/dist/esm/chains/celo/serializers.js.map +1 -0
- package/dist/esm/chains/celo/types.js +2 -0
- package/dist/esm/chains/celo/types.js.map +1 -0
- package/dist/esm/chains/index.js +23 -7
- package/dist/esm/chains/index.js.map +1 -1
- package/dist/esm/chains/optimism/fees.js +4 -0
- package/dist/esm/chains/optimism/fees.js.map +1 -0
- package/dist/esm/chains/{formatters/optimism.js → optimism/formatters.js} +15 -2
- package/dist/esm/chains/optimism/formatters.js.map +1 -0
- package/dist/esm/chains/optimism/types.js +2 -0
- package/dist/esm/chains/optimism/types.js.map +1 -0
- package/dist/esm/chains/utils.js +4 -0
- package/dist/esm/chains/utils.js.map +1 -0
- package/dist/esm/clients/decorators/public.js.map +1 -1
- package/dist/esm/constants/number.js +96 -96
- package/dist/esm/constants/number.js.map +1 -1
- package/dist/esm/errors/node.js +1 -1
- package/dist/esm/errors/node.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/abi/decodeAbiParameters.js.map +1 -1
- package/dist/esm/utils/abi/decodeDeployData.js.map +1 -1
- package/dist/esm/utils/abi/decodeErrorResult.js.map +1 -1
- package/dist/esm/utils/abi/decodeFunctionResult.js.map +1 -1
- package/dist/esm/utils/abi/encodeAbiParameters.js.map +1 -1
- package/dist/esm/utils/abi/encodeDeployData.js.map +1 -1
- package/dist/esm/utils/abi/encodeEventTopics.js.map +1 -1
- package/dist/esm/utils/abi/encodePacked.js.map +1 -1
- package/dist/esm/utils/chain.js +5 -3
- package/dist/esm/utils/chain.js.map +1 -1
- package/dist/esm/utils/formatters/block.js.map +1 -1
- package/dist/esm/utils/formatters/extract.js.map +1 -1
- package/dist/esm/utils/formatters/formatter.js.map +1 -1
- package/dist/esm/utils/formatters/transaction.js.map +1 -1
- package/dist/esm/utils/formatters/transactionReceipt.js.map +1 -1
- package/dist/esm/utils/formatters/transactionRequest.js.map +1 -1
- package/dist/esm/utils/poll.js +1 -1
- package/dist/esm/utils/poll.js.map +1 -1
- package/dist/esm/utils/transaction/prepareRequest.js +14 -5
- package/dist/esm/utils/transaction/prepareRequest.js.map +1 -1
- package/dist/esm/utils/typedData.js +2 -2
- package/dist/esm/utils/typedData.js.map +1 -1
- package/dist/types/accounts/index.d.ts +2 -0
- package/dist/types/accounts/index.d.ts.map +1 -1
- package/dist/types/accounts/types.d.ts +1 -1
- package/dist/types/accounts/types.d.ts.map +1 -1
- package/dist/types/accounts/utils/privateKeyToAddress.d.ts +11 -0
- package/dist/types/accounts/utils/privateKeyToAddress.d.ts.map +1 -0
- package/dist/types/accounts/utils/signTransaction.d.ts +2 -2
- package/dist/types/accounts/utils/signTransaction.d.ts.map +1 -1
- package/dist/types/accounts/utils/signTypedData.d.ts +1 -1
- package/dist/types/accounts/utils/signTypedData.d.ts.map +1 -1
- package/dist/types/actions/getContract.d.ts +5 -5
- package/dist/types/actions/getContract.d.ts.map +1 -1
- package/dist/types/actions/public/createContractEventFilter.d.ts +3 -3
- package/dist/types/actions/public/createContractEventFilter.d.ts.map +1 -1
- package/dist/types/actions/public/createEventFilter.d.ts +5 -5
- package/dist/types/actions/public/createEventFilter.d.ts.map +1 -1
- package/dist/types/actions/public/estimateContractGas.d.ts +1 -1
- package/dist/types/actions/public/estimateContractGas.d.ts.map +1 -1
- package/dist/types/actions/public/estimateGas.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterChanges.d.ts +1 -1
- package/dist/types/actions/public/getFilterChanges.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterLogs.d.ts +1 -1
- package/dist/types/actions/public/getFilterLogs.d.ts.map +1 -1
- package/dist/types/actions/public/getLogs.d.ts +4 -4
- package/dist/types/actions/public/getLogs.d.ts.map +1 -1
- package/dist/types/actions/public/getTransactionReceipt.d.ts +1 -1
- package/dist/types/actions/public/getTransactionReceipt.d.ts.map +1 -1
- package/dist/types/actions/public/multicall.d.ts +1 -1
- package/dist/types/actions/public/multicall.d.ts.map +1 -1
- package/dist/types/actions/public/readContract.d.ts +1 -1
- package/dist/types/actions/public/readContract.d.ts.map +1 -1
- package/dist/types/actions/public/simulateContract.d.ts +3 -3
- package/dist/types/actions/public/simulateContract.d.ts.map +1 -1
- package/dist/types/actions/public/watchContractEvent.d.ts +34 -8
- package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/dist/types/actions/public/watchEvent.d.ts +35 -12
- package/dist/types/actions/public/watchEvent.d.ts.map +1 -1
- package/dist/types/actions/wallet/deployContract.d.ts +4 -4
- package/dist/types/actions/wallet/deployContract.d.ts.map +1 -1
- package/dist/types/actions/wallet/sendTransaction.d.ts +2 -2
- package/dist/types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/dist/types/actions/wallet/signTypedData.d.ts +1 -1
- package/dist/types/actions/wallet/signTypedData.d.ts.map +1 -1
- package/dist/types/actions/wallet/writeContract.d.ts +4 -2
- package/dist/types/actions/wallet/writeContract.d.ts.map +1 -1
- package/dist/types/chains/{formatters/celo.d.ts → celo/formatters.d.ts} +26 -85
- package/dist/types/chains/celo/formatters.d.ts.map +1 -0
- package/dist/types/chains/{serializers/celo.d.ts → celo/serializers.d.ts} +4 -4
- package/dist/types/chains/celo/serializers.d.ts.map +1 -0
- package/dist/types/chains/celo/types.d.ts +60 -0
- package/dist/types/chains/celo/types.d.ts.map +1 -0
- package/dist/types/chains/index.d.ts +2681 -2790
- package/dist/types/chains/index.d.ts.map +1 -1
- package/dist/types/chains/optimism/fees.d.ts +4 -0
- package/dist/types/chains/optimism/fees.d.ts.map +1 -0
- package/dist/types/chains/{formatters/optimism.d.ts → optimism/formatters.d.ts} +77 -54
- package/dist/types/chains/optimism/formatters.d.ts.map +1 -0
- package/dist/types/chains/optimism/types.d.ts +53 -0
- package/dist/types/chains/optimism/types.d.ts.map +1 -0
- package/dist/types/chains/utils.d.ts +6 -0
- package/dist/types/chains/utils.d.ts.map +1 -0
- package/dist/types/clients/decorators/public.d.ts +10 -10
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/clients/decorators/wallet.d.ts +3 -3
- package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
- package/dist/types/constants/number.d.ts.map +1 -1
- package/dist/types/errors/node.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +14 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/chain.d.ts +52 -8
- package/dist/types/types/chain.d.ts.map +1 -1
- package/dist/types/types/multicall.d.ts +8 -8
- package/dist/types/types/multicall.d.ts.map +1 -1
- package/dist/types/types/rpc.d.ts +1 -1
- package/dist/types/types/rpc.d.ts.map +1 -1
- package/dist/types/types/typedData.d.ts +3 -3
- package/dist/types/types/typedData.d.ts.map +1 -1
- package/dist/types/types/utils.d.ts +10 -0
- package/dist/types/types/utils.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeAbiParameters.d.ts +2 -2
- package/dist/types/utils/abi/decodeAbiParameters.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeDeployData.d.ts +3 -3
- package/dist/types/utils/abi/decodeDeployData.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeErrorResult.d.ts +3 -3
- package/dist/types/utils/abi/decodeErrorResult.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeEventLog.d.ts +3 -3
- package/dist/types/utils/abi/decodeEventLog.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeFunctionResult.d.ts +4 -4
- package/dist/types/utils/abi/decodeFunctionResult.d.ts.map +1 -1
- package/dist/types/utils/abi/encodeAbiParameters.d.ts +2 -2
- package/dist/types/utils/abi/encodeAbiParameters.d.ts.map +1 -1
- package/dist/types/utils/abi/encodeDeployData.d.ts +3 -3
- package/dist/types/utils/abi/encodeDeployData.d.ts.map +1 -1
- package/dist/types/utils/abi/encodeErrorResult.d.ts +4 -4
- package/dist/types/utils/abi/encodeErrorResult.d.ts.map +1 -1
- package/dist/types/utils/abi/encodeEventTopics.d.ts +4 -4
- package/dist/types/utils/abi/encodeEventTopics.d.ts.map +1 -1
- package/dist/types/utils/abi/encodeFunctionData.d.ts +4 -4
- package/dist/types/utils/abi/encodeFunctionData.d.ts.map +1 -1
- package/dist/types/utils/abi/encodeFunctionResult.d.ts +4 -4
- package/dist/types/utils/abi/encodeFunctionResult.d.ts.map +1 -1
- package/dist/types/utils/abi/encodePacked.d.ts +3 -3
- package/dist/types/utils/abi/encodePacked.d.ts.map +1 -1
- package/dist/types/utils/abi/getAbiItem.d.ts +3 -3
- package/dist/types/utils/abi/getAbiItem.d.ts.map +1 -1
- package/dist/types/utils/chain.d.ts +3 -6
- package/dist/types/utils/chain.d.ts.map +1 -1
- package/dist/types/utils/formatters/block.d.ts +7 -3
- package/dist/types/utils/formatters/block.d.ts.map +1 -1
- package/dist/types/utils/formatters/extract.d.ts +2 -2
- package/dist/types/utils/formatters/extract.d.ts.map +1 -1
- package/dist/types/utils/formatters/formatter.d.ts +1 -1
- package/dist/types/utils/formatters/transaction.d.ts +8 -4
- package/dist/types/utils/formatters/transaction.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionReceipt.d.ts +3 -4
- package/dist/types/utils/formatters/transactionReceipt.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionRequest.d.ts +4 -5
- package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
- package/dist/types/utils/signature/hashTypedData.d.ts +1 -1
- package/dist/types/utils/signature/hashTypedData.d.ts.map +1 -1
- package/dist/types/utils/signature/recoverTypedDataAddress.d.ts +1 -1
- package/dist/types/utils/signature/recoverTypedDataAddress.d.ts.map +1 -1
- package/dist/types/utils/signature/verifyTypedData.d.ts +1 -1
- package/dist/types/utils/signature/verifyTypedData.d.ts.map +1 -1
- package/dist/types/utils/transaction/prepareRequest.d.ts +6 -11
- package/dist/types/utils/transaction/prepareRequest.d.ts.map +1 -1
- package/dist/types/utils/typedData.d.ts +1 -1
- package/dist/types/utils/typedData.d.ts.map +1 -1
- package/package.json +9 -3
- package/src/accounts/index.ts +6 -0
- package/src/accounts/types.ts +1 -1
- package/src/accounts/utils/privateKeyToAddress.ts +20 -0
- package/src/accounts/utils/signTransaction.ts +2 -2
- package/src/accounts/utils/signTypedData.ts +1 -1
- package/src/actions/getContract.ts +6 -5
- package/src/actions/public/createContractEventFilter.ts +3 -3
- package/src/actions/public/createEventFilter.ts +6 -6
- package/src/actions/public/estimateContractGas.ts +1 -1
- package/src/actions/public/estimateGas.ts +11 -2
- package/src/actions/public/getFilterChanges.ts +1 -1
- package/src/actions/public/getFilterLogs.ts +1 -1
- package/src/actions/public/getLogs.ts +5 -5
- package/src/actions/public/multicall.ts +9 -8
- package/src/actions/public/readContract.ts +1 -1
- package/src/actions/public/simulateContract.ts +3 -3
- package/src/actions/public/watchContractEvent.ts +204 -90
- package/src/actions/public/watchEvent.ts +232 -111
- package/src/actions/wallet/deployContract.ts +4 -4
- package/src/actions/wallet/sendTransaction.ts +9 -6
- package/src/actions/wallet/signTypedData.ts +1 -1
- package/src/actions/wallet/writeContract.ts +12 -8
- package/src/chains/{formatters/celo.ts → celo/formatters.ts} +29 -48
- package/src/chains/{serializers/celo.ts → celo/serializers.ts} +5 -5
- package/src/chains/celo/types.ts +111 -0
- package/src/chains/index.ts +23 -7
- package/src/chains/optimism/fees.ts +5 -0
- package/src/chains/optimism/formatters.ts +74 -0
- package/src/chains/optimism/types.ts +102 -0
- package/src/chains/utils.ts +41 -0
- package/src/clients/decorators/public.ts +16 -16
- package/src/clients/decorators/wallet.ts +3 -3
- package/src/constants/number.ts +96 -96
- package/src/errors/node.ts +2 -1
- package/src/errors/version.ts +1 -1
- package/src/index.ts +25 -8
- package/src/types/chain.ts +91 -14
- package/src/types/multicall.ts +14 -11
- package/src/types/rpc.ts +2 -6
- package/src/types/typedData.ts +2 -3
- package/src/types/utils.ts +11 -0
- package/src/utils/abi/decodeAbiParameters.ts +7 -8
- package/src/utils/abi/decodeDeployData.ts +3 -3
- package/src/utils/abi/decodeErrorResult.ts +3 -8
- package/src/utils/abi/decodeEventLog.ts +3 -3
- package/src/utils/abi/decodeFunctionResult.ts +4 -6
- package/src/utils/abi/encodeAbiParameters.ts +8 -9
- package/src/utils/abi/encodeDeployData.ts +3 -3
- package/src/utils/abi/encodeErrorResult.ts +4 -4
- package/src/utils/abi/encodeEventTopics.ts +4 -9
- package/src/utils/abi/encodeFunctionData.ts +4 -4
- package/src/utils/abi/encodeFunctionResult.ts +4 -4
- package/src/utils/abi/encodePacked.ts +6 -8
- package/src/utils/abi/getAbiItem.ts +3 -3
- package/src/utils/chain.ts +21 -10
- package/src/utils/formatters/block.ts +8 -6
- package/src/utils/formatters/extract.ts +2 -2
- package/src/utils/formatters/formatter.ts +2 -2
- package/src/utils/formatters/transaction.ts +8 -6
- package/src/utils/formatters/transactionReceipt.ts +9 -3
- package/src/utils/formatters/transactionRequest.ts +9 -3
- package/src/utils/poll.ts +1 -1
- package/src/utils/signature/hashTypedData.ts +1 -1
- package/src/utils/signature/recoverTypedDataAddress.ts +1 -1
- package/src/utils/signature/verifyTypedData.ts +1 -1
- package/src/utils/transaction/prepareRequest.ts +48 -22
- package/src/utils/typedData.ts +2 -3
- package/dist/cjs/chains/formatters/celo.js.map +0 -1
- package/dist/cjs/chains/formatters/optimism.js.map +0 -1
- package/dist/cjs/chains/serializers/celo.js.map +0 -1
- package/dist/cjs/types/formatter.js.map +0 -1
- package/dist/cjs/types/serializer.js.map +0 -1
- package/dist/esm/chains/formatters/celo.js.map +0 -1
- package/dist/esm/chains/formatters/optimism.js.map +0 -1
- package/dist/esm/chains/serializers/celo.js.map +0 -1
- package/dist/esm/types/formatter.js +0 -2
- package/dist/esm/types/formatter.js.map +0 -1
- package/dist/esm/types/serializer.js +0 -2
- package/dist/esm/types/serializer.js.map +0 -1
- package/dist/types/chains/formatters/celo.d.ts.map +0 -1
- package/dist/types/chains/formatters/optimism.d.ts.map +0 -1
- package/dist/types/chains/serializers/celo.d.ts.map +0 -1
- package/dist/types/types/formatter.d.ts +0 -17
- package/dist/types/types/formatter.d.ts.map +0 -1
- package/dist/types/types/serializer.d.ts +0 -7
- package/dist/types/types/serializer.d.ts.map +0 -1
- package/src/chains/formatters/optimism.ts +0 -91
- package/src/types/formatter.ts +0 -42
- package/src/types/serializer.ts +0 -19
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Abi, Address
|
1
|
+
import type { Abi, Address } from 'abitype'
|
2
2
|
|
3
3
|
import type { Client } from '../../clients/createClient.js'
|
4
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
@@ -28,7 +28,7 @@ export type CreateContractEventFilterParameters<
|
|
28
28
|
TToBlock extends BlockNumber | BlockTag | undefined = undefined,
|
29
29
|
> = {
|
30
30
|
address?: Address | Address[]
|
31
|
-
abi:
|
31
|
+
abi: TAbi
|
32
32
|
eventName?: InferEventName<TAbi, TEventName>
|
33
33
|
fromBlock?: TFromBlock | BlockNumber | BlockTag
|
34
34
|
/**
|
@@ -87,7 +87,7 @@ export type CreateContractEventFilterReturnType<
|
|
87
87
|
*/
|
88
88
|
export async function createContractEventFilter<
|
89
89
|
TChain extends Chain | undefined,
|
90
|
-
TAbi extends Abi | readonly unknown[],
|
90
|
+
const TAbi extends Abi | readonly unknown[],
|
91
91
|
TEventName extends string | undefined,
|
92
92
|
TArgs extends MaybeExtractEventArgsFromAbi<TAbi, TEventName> | undefined,
|
93
93
|
TStrict extends boolean | undefined = undefined,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { AbiEvent, Address
|
1
|
+
import type { AbiEvent, Address } from 'abitype'
|
2
2
|
|
3
3
|
import type { Client } from '../../clients/createClient.js'
|
4
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
@@ -44,7 +44,7 @@ export type CreateEventFilterParameters<
|
|
44
44
|
args:
|
45
45
|
| TEventFilterArgs
|
46
46
|
| (_Args extends TEventFilterArgs ? _Args : never)
|
47
|
-
event:
|
47
|
+
event: TAbiEvent
|
48
48
|
events?: never
|
49
49
|
/**
|
50
50
|
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
@@ -54,7 +54,7 @@ export type CreateEventFilterParameters<
|
|
54
54
|
}
|
55
55
|
| {
|
56
56
|
args?: never
|
57
|
-
event?:
|
57
|
+
event?: TAbiEvent
|
58
58
|
events?: never
|
59
59
|
/**
|
60
60
|
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
@@ -65,7 +65,7 @@ export type CreateEventFilterParameters<
|
|
65
65
|
| {
|
66
66
|
args?: never
|
67
67
|
event?: never
|
68
|
-
events:
|
68
|
+
events: TAbiEvents
|
69
69
|
/**
|
70
70
|
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
71
71
|
* @default false
|
@@ -127,8 +127,8 @@ export type CreateEventFilterReturnType<
|
|
127
127
|
*/
|
128
128
|
export async function createEventFilter<
|
129
129
|
TChain extends Chain | undefined,
|
130
|
-
TAbiEvent extends AbiEvent | undefined = undefined,
|
131
|
-
TAbiEvents extends
|
130
|
+
const TAbiEvent extends AbiEvent | undefined = undefined,
|
131
|
+
const TAbiEvents extends
|
132
132
|
| readonly AbiEvent[]
|
133
133
|
| readonly unknown[]
|
134
134
|
| undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
|
@@ -60,7 +60,7 @@ export type EstimateContractGasReturnType = bigint
|
|
60
60
|
* })
|
61
61
|
*/
|
62
62
|
export async function estimateContractGas<
|
63
|
-
TAbi extends Abi | readonly unknown[],
|
63
|
+
const TAbi extends Abi | readonly unknown[],
|
64
64
|
TFunctionName extends string,
|
65
65
|
TChain extends Chain | undefined,
|
66
66
|
TAccount extends Account | undefined = undefined,
|
@@ -20,7 +20,10 @@ import {
|
|
20
20
|
type AssertRequestParameters,
|
21
21
|
assertRequest,
|
22
22
|
} from '../../utils/transaction/assertRequest.js'
|
23
|
-
import {
|
23
|
+
import {
|
24
|
+
type PrepareRequestParameters,
|
25
|
+
prepareRequest,
|
26
|
+
} from '../../utils/transaction/prepareRequest.js'
|
24
27
|
|
25
28
|
export type FormattedEstimateGas<
|
26
29
|
TChain extends Chain | undefined = Chain | undefined,
|
@@ -102,7 +105,13 @@ export async function estimateGas<
|
|
102
105
|
to,
|
103
106
|
value,
|
104
107
|
...rest
|
105
|
-
} =
|
108
|
+
} =
|
109
|
+
account.type === 'local'
|
110
|
+
? ((await prepareRequest(
|
111
|
+
client,
|
112
|
+
args as PrepareRequestParameters,
|
113
|
+
)) as EstimateGasParameters)
|
114
|
+
: args
|
106
115
|
|
107
116
|
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : undefined
|
108
117
|
const block = blockNumberHex || blockTag
|
@@ -138,7 +138,7 @@ export async function getFilterChanges<
|
|
138
138
|
TTransport extends Transport,
|
139
139
|
TChain extends Chain | undefined,
|
140
140
|
TFilterType extends FilterType,
|
141
|
-
TAbi extends Abi | readonly unknown[] | undefined,
|
141
|
+
const TAbi extends Abi | readonly unknown[] | undefined,
|
142
142
|
TEventName extends string | undefined,
|
143
143
|
TStrict extends boolean | undefined = undefined,
|
144
144
|
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
|
@@ -67,7 +67,7 @@ export type GetFilterLogsReturnType<
|
|
67
67
|
*/
|
68
68
|
export async function getFilterLogs<
|
69
69
|
TChain extends Chain | undefined,
|
70
|
-
TAbi extends Abi | readonly unknown[] | undefined,
|
70
|
+
const TAbi extends Abi | readonly unknown[] | undefined,
|
71
71
|
TEventName extends string | undefined,
|
72
72
|
TStrict extends boolean | undefined = undefined,
|
73
73
|
TFromBlock extends BlockNumber | BlockTag | undefined = undefined,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Abi, AbiEvent, Address
|
1
|
+
import type { Abi, AbiEvent, Address } from 'abitype'
|
2
2
|
|
3
3
|
import type { Client } from '../../clients/createClient.js'
|
4
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
@@ -38,7 +38,7 @@ export type GetLogsParameters<
|
|
38
38
|
address?: Address | Address[]
|
39
39
|
} & (
|
40
40
|
| {
|
41
|
-
event:
|
41
|
+
event: TAbiEvent
|
42
42
|
events?: never
|
43
43
|
args?: MaybeExtractEventArgsFromAbi<TAbiEvents, _EventName>
|
44
44
|
/**
|
@@ -49,7 +49,7 @@ export type GetLogsParameters<
|
|
49
49
|
}
|
50
50
|
| {
|
51
51
|
event?: never
|
52
|
-
events:
|
52
|
+
events: TAbiEvents
|
53
53
|
args?: never
|
54
54
|
/**
|
55
55
|
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
@@ -119,8 +119,8 @@ export type GetLogsReturnType<
|
|
119
119
|
*/
|
120
120
|
export async function getLogs<
|
121
121
|
TChain extends Chain | undefined,
|
122
|
-
TAbiEvent extends AbiEvent | undefined = undefined,
|
123
|
-
TAbiEvents extends
|
122
|
+
const TAbiEvent extends AbiEvent | undefined = undefined,
|
123
|
+
const TAbiEvents extends
|
124
124
|
| readonly AbiEvent[]
|
125
125
|
| readonly unknown[]
|
126
126
|
| undefined = TAbiEvent extends AbiEvent ? [TAbiEvent] : undefined,
|
@@ -80,8 +80,8 @@ export type MulticallReturnType<
|
|
80
80
|
* // [{ result: 424122n, status: 'success' }, { result: 1000000n, status: 'success' }]
|
81
81
|
*/
|
82
82
|
export async function multicall<
|
83
|
-
TChain extends Chain | undefined,
|
84
83
|
TContracts extends ContractFunctionConfig[],
|
84
|
+
TChain extends Chain | undefined,
|
85
85
|
TAllowFailure extends boolean = true,
|
86
86
|
>(
|
87
87
|
client: Client<Transport, TChain>,
|
@@ -92,7 +92,7 @@ export async function multicall<
|
|
92
92
|
batchSize: batchSize_,
|
93
93
|
blockNumber,
|
94
94
|
blockTag,
|
95
|
-
contracts
|
95
|
+
contracts,
|
96
96
|
multicallAddress: multicallAddress_,
|
97
97
|
} = args
|
98
98
|
|
@@ -102,9 +102,6 @@ export async function multicall<
|
|
102
102
|
client.batch.multicall.batchSize) ||
|
103
103
|
1_024)
|
104
104
|
|
105
|
-
// Fix type cast from `Narrow` in type definition.
|
106
|
-
const contracts = contracts_ as readonly [...MulticallContracts<TContracts>]
|
107
|
-
|
108
105
|
let multicallAddress = multicallAddress_
|
109
106
|
if (!multicallAddress) {
|
110
107
|
if (!client.chain)
|
@@ -129,7 +126,9 @@ export async function multicall<
|
|
129
126
|
let currentChunk = 0
|
130
127
|
let currentChunkSize = 0
|
131
128
|
for (let i = 0; i < contracts.length; i++) {
|
132
|
-
const { abi, address, args, functionName } = contracts[
|
129
|
+
const { abi, address, args, functionName } = contracts[
|
130
|
+
i
|
131
|
+
] as ContractFunctionConfig
|
133
132
|
try {
|
134
133
|
const callData = encodeFunctionData({
|
135
134
|
abi,
|
@@ -188,7 +187,9 @@ export async function multicall<
|
|
188
187
|
return results.flat().map(({ returnData, success }, i) => {
|
189
188
|
const calls = chunkedCalls.flat()
|
190
189
|
const { callData } = calls[i]
|
191
|
-
const { abi, address, functionName, args } = contracts[
|
190
|
+
const { abi, address, functionName, args } = contracts[
|
191
|
+
i
|
192
|
+
] as ContractFunctionConfig
|
192
193
|
try {
|
193
194
|
if (callData === '0x') throw new AbiDecodingZeroDataError()
|
194
195
|
if (!success) throw new RawContractError({ data: returnData })
|
@@ -196,7 +197,7 @@ export async function multicall<
|
|
196
197
|
abi,
|
197
198
|
args,
|
198
199
|
data: returnData,
|
199
|
-
functionName
|
200
|
+
functionName,
|
200
201
|
})
|
201
202
|
return allowFailure ? { result, status: 'success' } : result
|
202
203
|
} catch (err) {
|
@@ -64,7 +64,7 @@ export type ReadContractReturnType<
|
|
64
64
|
*/
|
65
65
|
export async function readContract<
|
66
66
|
TChain extends Chain | undefined,
|
67
|
-
TAbi extends Abi | readonly unknown[],
|
67
|
+
const TAbi extends Abi | readonly unknown[],
|
68
68
|
TFunctionName extends string,
|
69
69
|
>(
|
70
70
|
client: Client<Transport, TChain>,
|
@@ -29,7 +29,7 @@ export type SimulateContractParameters<
|
|
29
29
|
TAbi extends Abi | readonly unknown[] = Abi,
|
30
30
|
TFunctionName extends string = any,
|
31
31
|
TChain extends Chain | undefined = Chain | undefined,
|
32
|
-
TChainOverride extends Chain | undefined = undefined,
|
32
|
+
TChainOverride extends Chain | undefined = Chain | undefined,
|
33
33
|
> = {
|
34
34
|
chain?: TChainOverride
|
35
35
|
/** Data to append to the end of the calldata. Useful for adding a ["domain" tag](https://opensea.notion.site/opensea/Seaport-Order-Attributions-ec2d69bf455041a5baa490941aad307f). */
|
@@ -51,7 +51,7 @@ export type SimulateContractReturnType<
|
|
51
51
|
TAbi extends Abi | readonly unknown[] = Abi,
|
52
52
|
TFunctionName extends string = string,
|
53
53
|
TChain extends Chain | undefined = Chain | undefined,
|
54
|
-
TChainOverride extends Chain | undefined = undefined,
|
54
|
+
TChainOverride extends Chain | undefined = Chain | undefined,
|
55
55
|
> = {
|
56
56
|
result: ContractFunctionResult<TAbi, TFunctionName>
|
57
57
|
request: UnionOmit<
|
@@ -102,7 +102,7 @@ export type SimulateContractReturnType<
|
|
102
102
|
*/
|
103
103
|
export async function simulateContract<
|
104
104
|
TChain extends Chain | undefined,
|
105
|
-
TAbi extends Abi | readonly unknown[],
|
105
|
+
const TAbi extends Abi | readonly unknown[],
|
106
106
|
TFunctionName extends string,
|
107
107
|
TChainOverride extends Chain | undefined,
|
108
108
|
>(
|
@@ -1,11 +1,14 @@
|
|
1
|
-
import type { Abi, AbiEvent, Address, ExtractAbiEvent
|
1
|
+
import type { Abi, AbiEvent, Address, ExtractAbiEvent } from 'abitype'
|
2
2
|
|
3
3
|
import type { Client } from '../../clients/createClient.js'
|
4
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
5
|
+
import type { EncodeEventTopicsParameters, LogTopic } from '../../index.js'
|
5
6
|
import type { Chain } from '../../types/chain.js'
|
6
7
|
import type { GetEventArgs, InferEventName } from '../../types/contract.js'
|
7
8
|
import type { Filter } from '../../types/filter.js'
|
8
9
|
import type { Log } from '../../types/log.js'
|
10
|
+
import type { GetTransportConfig } from '../../types/transport.js'
|
11
|
+
|
9
12
|
import {
|
10
13
|
type GetAbiItemParameters,
|
11
14
|
getAbiItem,
|
@@ -14,7 +17,14 @@ import { observe } from '../../utils/observe.js'
|
|
14
17
|
import { poll } from '../../utils/poll.js'
|
15
18
|
import { stringify } from '../../utils/stringify.js'
|
16
19
|
|
17
|
-
import {
|
20
|
+
import { DecodeLogDataMismatch } from '../../errors/abi.js'
|
21
|
+
import {
|
22
|
+
DecodeLogTopicsMismatch,
|
23
|
+
InvalidInputRpcError,
|
24
|
+
decodeEventLog,
|
25
|
+
encodeEventTopics,
|
26
|
+
formatLog,
|
27
|
+
} from '../../index.js'
|
18
28
|
import {
|
19
29
|
type CreateContractEventFilterParameters,
|
20
30
|
createContractEventFilter,
|
@@ -24,6 +34,19 @@ import { getFilterChanges } from './getFilterChanges.js'
|
|
24
34
|
import { getLogs } from './getLogs.js'
|
25
35
|
import { uninstallFilter } from './uninstallFilter.js'
|
26
36
|
|
37
|
+
type PollOptions = {
|
38
|
+
/**
|
39
|
+
* Whether or not the transaction hashes should be batched on each invocation.
|
40
|
+
* @default true
|
41
|
+
*/
|
42
|
+
batch?: boolean
|
43
|
+
/**
|
44
|
+
* Polling frequency (in ms). Defaults to Client's pollingInterval config.
|
45
|
+
* @default client.pollingInterval
|
46
|
+
*/
|
47
|
+
pollingInterval?: number
|
48
|
+
}
|
49
|
+
|
27
50
|
export type WatchContractEventOnLogsParameter<
|
28
51
|
TAbi extends Abi | readonly unknown[] = readonly unknown[],
|
29
52
|
TEventName extends string = string,
|
@@ -45,24 +68,40 @@ export type WatchContractEventParameters<
|
|
45
68
|
/** The address of the contract. */
|
46
69
|
address?: Address | Address[]
|
47
70
|
/** Contract ABI. */
|
48
|
-
abi:
|
71
|
+
abi: TAbi
|
49
72
|
args?: GetEventArgs<TAbi, TEventName>
|
50
|
-
/** Whether or not the event logs should be batched on each invocation. */
|
51
|
-
batch?: boolean
|
52
73
|
/** Contract event. */
|
53
74
|
eventName?: InferEventName<TAbi, TEventName>
|
54
75
|
/** The callback to call when an error occurred when trying to get for a new block. */
|
55
76
|
onError?: (error: Error) => void
|
56
77
|
/** The callback to call when new event logs are received. */
|
57
78
|
onLogs: WatchContractEventOnLogsFn<TAbi, TEventName, TStrict>
|
58
|
-
/** Polling frequency (in ms). Defaults to Client's pollingInterval config. */
|
59
|
-
pollingInterval?: number
|
60
79
|
/**
|
61
80
|
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
62
81
|
* @default false
|
63
82
|
*/
|
64
83
|
strict?: TStrict
|
65
|
-
}
|
84
|
+
} & (GetTransportConfig<Transport>['type'] extends 'webSocket'
|
85
|
+
?
|
86
|
+
| {
|
87
|
+
batch?: never
|
88
|
+
/**
|
89
|
+
* Whether or not the WebSocket Transport should poll the JSON-RPC, rather than using `eth_subscribe`.
|
90
|
+
* @default false
|
91
|
+
*/
|
92
|
+
poll?: false
|
93
|
+
pollingInterval?: never
|
94
|
+
}
|
95
|
+
| (PollOptions & {
|
96
|
+
/**
|
97
|
+
* Whether or not the WebSocket Transport should poll the JSON-RPC, rather than using `eth_subscribe`.
|
98
|
+
* @default true
|
99
|
+
*/
|
100
|
+
poll?: true
|
101
|
+
})
|
102
|
+
: PollOptions & {
|
103
|
+
poll?: true
|
104
|
+
})
|
66
105
|
|
67
106
|
export type WatchContractEventReturnType = () => void
|
68
107
|
|
@@ -98,7 +137,7 @@ export type WatchContractEventReturnType = () => void
|
|
98
137
|
*/
|
99
138
|
export function watchContractEvent<
|
100
139
|
TChain extends Chain | undefined,
|
101
|
-
TAbi extends Abi | readonly unknown[],
|
140
|
+
const TAbi extends Abi | readonly unknown[],
|
102
141
|
TEventName extends string,
|
103
142
|
TStrict extends boolean | undefined = undefined,
|
104
143
|
>(
|
@@ -111,96 +150,171 @@ export function watchContractEvent<
|
|
111
150
|
eventName,
|
112
151
|
onError,
|
113
152
|
onLogs,
|
153
|
+
poll: poll_,
|
114
154
|
pollingInterval = client.pollingInterval,
|
115
155
|
strict: strict_,
|
116
156
|
}: WatchContractEventParameters<TAbi, TEventName, TStrict>,
|
117
157
|
): WatchContractEventReturnType {
|
118
|
-
const
|
119
|
-
'
|
120
|
-
address,
|
121
|
-
args,
|
122
|
-
batch,
|
123
|
-
client.uid,
|
124
|
-
eventName,
|
125
|
-
pollingInterval,
|
126
|
-
])
|
127
|
-
const strict = strict_ ?? false
|
128
|
-
|
129
|
-
return observe(observerId, { onLogs, onError }, (emit) => {
|
130
|
-
let previousBlockNumber: bigint
|
131
|
-
let filter: Filter<'event', TAbi, TEventName> | undefined
|
132
|
-
let initialized = false
|
133
|
-
|
134
|
-
const unwatch = poll(
|
135
|
-
async () => {
|
136
|
-
if (!initialized) {
|
137
|
-
try {
|
138
|
-
filter = (await createContractEventFilter(client, {
|
139
|
-
abi,
|
140
|
-
address,
|
141
|
-
args,
|
142
|
-
eventName,
|
143
|
-
strict,
|
144
|
-
} as unknown as CreateContractEventFilterParameters)) as Filter<
|
145
|
-
'event',
|
146
|
-
TAbi,
|
147
|
-
TEventName
|
148
|
-
>
|
149
|
-
} catch {}
|
150
|
-
initialized = true
|
151
|
-
return
|
152
|
-
}
|
158
|
+
const enablePolling =
|
159
|
+
typeof poll_ !== 'undefined' ? poll_ : client.transport.type !== 'webSocket'
|
153
160
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
161
|
+
const pollContractEvent = () => {
|
162
|
+
const observerId = stringify([
|
163
|
+
'watchContractEvent',
|
164
|
+
address,
|
165
|
+
args,
|
166
|
+
batch,
|
167
|
+
client.uid,
|
168
|
+
eventName,
|
169
|
+
pollingInterval,
|
170
|
+
])
|
171
|
+
const strict = strict_ ?? false
|
172
|
+
|
173
|
+
return observe(observerId, { onLogs, onError }, (emit) => {
|
174
|
+
let previousBlockNumber: bigint
|
175
|
+
let filter: Filter<'event', TAbi, TEventName> | undefined
|
176
|
+
let initialized = false
|
177
|
+
|
178
|
+
const unwatch = poll(
|
179
|
+
async () => {
|
180
|
+
if (!initialized) {
|
181
|
+
try {
|
182
|
+
filter = (await createContractEventFilter(client, {
|
183
|
+
abi,
|
170
184
|
address,
|
171
185
|
args,
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
186
|
+
eventName,
|
187
|
+
strict,
|
188
|
+
} as unknown as CreateContractEventFilterParameters)) as Filter<
|
189
|
+
'event',
|
190
|
+
TAbi,
|
191
|
+
TEventName
|
192
|
+
>
|
193
|
+
} catch {}
|
194
|
+
initialized = true
|
195
|
+
return
|
196
|
+
}
|
197
|
+
|
198
|
+
try {
|
199
|
+
let logs: Log[]
|
200
|
+
if (filter) {
|
201
|
+
logs = await getFilterChanges(client, { filter })
|
179
202
|
} else {
|
180
|
-
|
203
|
+
// If the filter doesn't exist, we will fall back to use `getLogs`.
|
204
|
+
// The fall back exists because some RPC Providers do not support filters.
|
205
|
+
|
206
|
+
// Fetch the block number to use for `getLogs`.
|
207
|
+
const blockNumber = await getBlockNumber(client)
|
208
|
+
|
209
|
+
// If the block number has changed, we will need to fetch the logs.
|
210
|
+
// If the block number doesn't exist, we are yet to reach the first poll interval,
|
211
|
+
// so do not emit any logs.
|
212
|
+
if (previousBlockNumber && previousBlockNumber !== blockNumber) {
|
213
|
+
logs = await getLogs(client, {
|
214
|
+
address,
|
215
|
+
args,
|
216
|
+
fromBlock: previousBlockNumber + 1n,
|
217
|
+
toBlock: blockNumber,
|
218
|
+
event: getAbiItem({
|
219
|
+
abi,
|
220
|
+
name: eventName,
|
221
|
+
} as unknown as GetAbiItemParameters) as AbiEvent,
|
222
|
+
})
|
223
|
+
} else {
|
224
|
+
logs = []
|
225
|
+
}
|
226
|
+
previousBlockNumber = blockNumber
|
181
227
|
}
|
182
|
-
|
228
|
+
|
229
|
+
if (logs.length === 0) return
|
230
|
+
if (batch) emit.onLogs(logs as any)
|
231
|
+
else logs.forEach((log) => emit.onLogs([log] as any))
|
232
|
+
} catch (err) {
|
233
|
+
// If a filter has been set and gets uninstalled, providers will throw an InvalidInput error.
|
234
|
+
// Reinitalize the filter when this occurs
|
235
|
+
if (filter && err instanceof InvalidInputRpcError)
|
236
|
+
initialized = false
|
237
|
+
emit.onError?.(err as Error)
|
183
238
|
}
|
239
|
+
},
|
240
|
+
{
|
241
|
+
emitOnBegin: true,
|
242
|
+
interval: pollingInterval,
|
243
|
+
},
|
244
|
+
)
|
184
245
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
246
|
+
return async () => {
|
247
|
+
if (filter) await uninstallFilter(client, { filter })
|
248
|
+
unwatch()
|
249
|
+
}
|
250
|
+
})
|
251
|
+
}
|
252
|
+
|
253
|
+
const subscribeContractEvent = () => {
|
254
|
+
let active = true
|
255
|
+
let unsubscribe = () => (active = false)
|
256
|
+
;(async () => {
|
257
|
+
try {
|
258
|
+
const topics: LogTopic[] = eventName
|
259
|
+
? encodeEventTopics({
|
260
|
+
abi: abi,
|
261
|
+
eventName: eventName,
|
262
|
+
args,
|
263
|
+
} as EncodeEventTopicsParameters)
|
264
|
+
: []
|
265
|
+
|
266
|
+
const { unsubscribe: unsubscribe_ } = await client.transport.subscribe({
|
267
|
+
params: ['logs', { address, topics }],
|
268
|
+
onData(data: any) {
|
269
|
+
if (!active) return
|
270
|
+
const log = data.result
|
271
|
+
try {
|
272
|
+
const { eventName, args } = decodeEventLog({
|
273
|
+
abi: abi,
|
274
|
+
data: log.data,
|
275
|
+
topics: log.topics as any,
|
276
|
+
strict: strict_,
|
277
|
+
})
|
278
|
+
const formatted = formatLog(log, {
|
279
|
+
args,
|
280
|
+
eventName: eventName as string,
|
281
|
+
})
|
282
|
+
onLogs([formatted] as any)
|
283
|
+
} catch (err) {
|
284
|
+
let eventName
|
285
|
+
let isUnnamed
|
286
|
+
if (
|
287
|
+
err instanceof DecodeLogDataMismatch ||
|
288
|
+
err instanceof DecodeLogTopicsMismatch
|
289
|
+
) {
|
290
|
+
// If strict mode is on, and log data/topics do not match event definition, skip.
|
291
|
+
if (strict_) return
|
292
|
+
eventName = err.abiItem.name
|
293
|
+
isUnnamed = err.abiItem.inputs?.some(
|
294
|
+
(x) => !('name' in x && x.name),
|
295
|
+
)
|
296
|
+
}
|
297
|
+
|
298
|
+
// Set args to empty if there is an error decoding (e.g. indexed/non-indexed params mismatch).
|
299
|
+
const formatted = formatLog(log, {
|
300
|
+
args: isUnnamed ? [] : {},
|
301
|
+
eventName,
|
302
|
+
})
|
303
|
+
onLogs([formatted] as any)
|
304
|
+
}
|
305
|
+
},
|
306
|
+
onError(error: Error) {
|
307
|
+
onError?.(error)
|
308
|
+
},
|
309
|
+
})
|
310
|
+
unsubscribe = unsubscribe_
|
311
|
+
if (!active) unsubscribe()
|
312
|
+
} catch (err) {
|
313
|
+
onError?.(err as Error)
|
314
|
+
}
|
315
|
+
})()
|
316
|
+
return unsubscribe
|
317
|
+
}
|
318
|
+
|
319
|
+
return enablePolling ? pollContractEvent() : subscribeContractEvent()
|
206
320
|
}
|