viem 2.57.11 → 2.57.13
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 +62 -0
- package/_cjs/actions/public/fillTransaction.js +6 -3
- package/_cjs/actions/public/fillTransaction.js.map +1 -1
- package/_cjs/actions/public/waitForTransactionReceipt.js +83 -23
- package/_cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/_cjs/actions/public/watchContractEvent.js +58 -29
- package/_cjs/actions/public/watchContractEvent.js.map +1 -1
- package/_cjs/actions/public/watchEvent.js +58 -28
- package/_cjs/actions/public/watchEvent.js.map +1 -1
- package/_cjs/actions/token/approve.js +1 -1
- package/_cjs/actions/token/approve.js.map +1 -1
- package/_cjs/actions/token/getAllowance.js +1 -1
- package/_cjs/actions/token/getAllowance.js.map +1 -1
- package/_cjs/actions/token/getBalance.js +1 -1
- package/_cjs/actions/token/getBalance.js.map +1 -1
- package/_cjs/actions/token/getTotalSupply.js +1 -1
- package/_cjs/actions/token/getTotalSupply.js.map +1 -1
- package/_cjs/actions/token/transfer.js +1 -1
- package/_cjs/actions/token/transfer.js.map +1 -1
- package/_cjs/actions/wallet/sendCalls.js +1 -1
- package/_cjs/actions/wallet/sendCalls.js.map +1 -1
- package/_cjs/chains/definitions/molibra.js +21 -0
- package/_cjs/chains/definitions/molibra.js.map +1 -0
- package/_cjs/chains/definitions/valuechain.js +22 -0
- package/_cjs/chains/definitions/valuechain.js.map +1 -0
- package/_cjs/chains/definitions/valuechainTestnet.js +23 -0
- package/_cjs/chains/definitions/valuechainTestnet.js.map +1 -0
- package/_cjs/chains/index.js +13 -7
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/decorators/public.js.map +1 -1
- package/_cjs/clients/transports/http.js +5 -1
- package/_cjs/clients/transports/http.js.map +1 -1
- package/_cjs/errors/node.js +1 -1
- package/_cjs/errors/node.js.map +1 -1
- package/_cjs/errors/request.js +20 -2
- package/_cjs/errors/request.js.map +1 -1
- package/_cjs/errors/typedData.js +3 -1
- package/_cjs/errors/typedData.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/op-stack/abis.js +52 -0
- package/_cjs/op-stack/abis.js.map +1 -1
- package/_cjs/op-stack/actions/getTimeToFinalize.js +53 -4
- package/_cjs/op-stack/actions/getTimeToFinalize.js.map +1 -1
- package/_cjs/op-stack/actions/getTimeToProve.js +29 -2
- package/_cjs/op-stack/actions/getTimeToProve.js.map +1 -1
- package/_cjs/op-stack/actions/getWithdrawalStatus.js +20 -4
- package/_cjs/op-stack/actions/getWithdrawalStatus.js.map +1 -1
- package/_cjs/op-stack/actions/waitToProve.js +28 -2
- package/_cjs/op-stack/actions/waitToProve.js.map +1 -1
- package/_cjs/op-stack/errors/withdrawal.js +12 -1
- package/_cjs/op-stack/errors/withdrawal.js.map +1 -1
- package/_cjs/tempo/Account.js +6 -9
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/Addresses.js +1 -2
- package/_cjs/tempo/Addresses.js.map +1 -1
- package/_cjs/tempo/Formatters.js +13 -2
- package/_cjs/tempo/Formatters.js.map +1 -1
- package/_cjs/tempo/Relay.js.map +1 -1
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/accounts/Config.js +22 -12
- package/_cjs/tempo/accounts/Config.js.map +1 -1
- package/_cjs/tempo/actions/accessKey.js +8 -8
- package/_cjs/tempo/actions/accessKey.js.map +1 -1
- package/_cjs/tempo/actions/accounts.js +5 -5
- package/_cjs/tempo/actions/accounts.js.map +1 -1
- package/_cjs/tempo/actions/amm.js +4 -4
- package/_cjs/tempo/actions/amm.js.map +1 -1
- package/_cjs/tempo/actions/channel.js +7 -7
- package/_cjs/tempo/actions/channel.js.map +1 -1
- package/_cjs/tempo/actions/dex.js +14 -14
- package/_cjs/tempo/actions/dex.js.map +1 -1
- package/_cjs/tempo/actions/earn/deployment.js +3 -3
- package/_cjs/tempo/actions/earn/deployment.js.map +1 -1
- package/_cjs/tempo/actions/earn.js +6 -6
- package/_cjs/tempo/actions/earn.js.map +1 -1
- package/_cjs/tempo/actions/fee.js +4 -4
- package/_cjs/tempo/actions/fee.js.map +1 -1
- package/_cjs/tempo/actions/nonce.js +1 -1
- package/_cjs/tempo/actions/nonce.js.map +1 -1
- package/_cjs/tempo/actions/policy.js +6 -6
- package/_cjs/tempo/actions/policy.js.map +1 -1
- package/_cjs/tempo/actions/propAmm.js +10 -10
- package/_cjs/tempo/actions/propAmm.js.map +1 -1
- package/_cjs/tempo/actions/receivePolicy.js +6 -6
- package/_cjs/tempo/actions/receivePolicy.js.map +1 -1
- package/_cjs/tempo/actions/reward.js +6 -6
- package/_cjs/tempo/actions/reward.js.map +1 -1
- package/_cjs/tempo/actions/token.js +21 -21
- package/_cjs/tempo/actions/token.js.map +1 -1
- package/_cjs/tempo/actions/validator.js +11 -11
- package/_cjs/tempo/actions/validator.js.map +1 -1
- package/_cjs/tempo/actions/virtualAddress.js +2 -2
- package/_cjs/tempo/actions/virtualAddress.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +11 -4
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/internal/relay/accounts.js +42 -7
- package/_cjs/tempo/internal/relay/accounts.js.map +1 -1
- package/_cjs/tempo/internal/relay/feePayer.js +4 -1
- package/_cjs/tempo/internal/relay/feePayer.js.map +1 -1
- package/_cjs/utils/abi/getAbiItem.js +33 -12
- package/_cjs/utils/abi/getAbiItem.js.map +1 -1
- package/_cjs/utils/abi/parseEventLogs.js +18 -10
- package/_cjs/utils/abi/parseEventLogs.js.map +1 -1
- package/_cjs/utils/authorization/serializeAuthorizationList.js +4 -1
- package/_cjs/utils/authorization/serializeAuthorizationList.js.map +1 -1
- package/_cjs/utils/buildRequest.js +25 -14
- package/_cjs/utils/buildRequest.js.map +1 -1
- package/_cjs/utils/data/isHex.js +3 -1
- package/_cjs/utils/data/isHex.js.map +1 -1
- package/_cjs/utils/hash/normalizeSignature.js +1 -1
- package/_cjs/utils/hash/normalizeSignature.js.map +1 -1
- package/_cjs/utils/rpc/http.js +24 -4
- package/_cjs/utils/rpc/http.js.map +1 -1
- package/_cjs/utils/signature/compactSignatureToSignature.js +3 -2
- package/_cjs/utils/signature/compactSignatureToSignature.js.map +1 -1
- package/_cjs/utils/signature/hashTypedData.js +1 -2
- package/_cjs/utils/signature/hashTypedData.js.map +1 -1
- package/_cjs/utils/signature/signatureToCompactSignature.js +15 -7
- package/_cjs/utils/signature/signatureToCompactSignature.js.map +1 -1
- package/_cjs/utils/siwe/createSiweMessage.js +1 -1
- package/_cjs/utils/siwe/createSiweMessage.js.map +1 -1
- package/_cjs/utils/typedData.js +6 -7
- package/_cjs/utils/typedData.js.map +1 -1
- package/_cjs/utils/wait.js +1 -1
- package/_cjs/utils/wait.js.map +1 -1
- package/_esm/actions/public/fillTransaction.js +8 -3
- package/_esm/actions/public/fillTransaction.js.map +1 -1
- package/_esm/actions/public/waitForTransactionReceipt.js +101 -23
- package/_esm/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/_esm/actions/public/watchContractEvent.js +73 -36
- package/_esm/actions/public/watchContractEvent.js.map +1 -1
- package/_esm/actions/public/watchEvent.js +73 -35
- package/_esm/actions/public/watchEvent.js.map +1 -1
- package/_esm/actions/token/approve.js +1 -1
- package/_esm/actions/token/approve.js.map +1 -1
- package/_esm/actions/token/getAllowance.js +1 -1
- package/_esm/actions/token/getAllowance.js.map +1 -1
- package/_esm/actions/token/getBalance.js +1 -1
- package/_esm/actions/token/getBalance.js.map +1 -1
- package/_esm/actions/token/getTotalSupply.js +1 -1
- package/_esm/actions/token/getTotalSupply.js.map +1 -1
- package/_esm/actions/token/transfer.js +1 -1
- package/_esm/actions/token/transfer.js.map +1 -1
- package/_esm/actions/wallet/sendCalls.js +1 -1
- package/_esm/actions/wallet/sendCalls.js.map +1 -1
- package/_esm/chains/definitions/molibra.js +18 -0
- package/_esm/chains/definitions/molibra.js.map +1 -0
- package/_esm/chains/definitions/valuechain.js +20 -0
- package/_esm/chains/definitions/valuechain.js.map +1 -0
- package/_esm/chains/definitions/valuechainTestnet.js +21 -0
- package/_esm/chains/definitions/valuechainTestnet.js.map +1 -0
- package/_esm/chains/index.js +5 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/decorators/public.js.map +1 -1
- package/_esm/clients/transports/http.js +6 -1
- package/_esm/clients/transports/http.js.map +1 -1
- package/_esm/errors/node.js +1 -1
- package/_esm/errors/node.js.map +1 -1
- package/_esm/errors/request.js +22 -2
- package/_esm/errors/request.js.map +1 -1
- package/_esm/errors/typedData.js +3 -1
- package/_esm/errors/typedData.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/op-stack/abis.js +52 -0
- package/_esm/op-stack/abis.js.map +1 -1
- package/_esm/op-stack/actions/getTimeToFinalize.js +64 -6
- package/_esm/op-stack/actions/getTimeToFinalize.js.map +1 -1
- package/_esm/op-stack/actions/getTimeToProve.js +30 -2
- package/_esm/op-stack/actions/getTimeToProve.js.map +1 -1
- package/_esm/op-stack/actions/getWithdrawalStatus.js +24 -5
- package/_esm/op-stack/actions/getWithdrawalStatus.js.map +1 -1
- package/_esm/op-stack/actions/waitToProve.js +30 -3
- package/_esm/op-stack/actions/waitToProve.js.map +1 -1
- package/_esm/op-stack/errors/withdrawal.js +10 -0
- package/_esm/op-stack/errors/withdrawal.js.map +1 -1
- package/_esm/tempo/Account.js +6 -9
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/Addresses.js +0 -2
- package/_esm/tempo/Addresses.js.map +1 -1
- package/_esm/tempo/Formatters.js +12 -2
- package/_esm/tempo/Formatters.js.map +1 -1
- package/_esm/tempo/Relay.js.map +1 -1
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/accounts/Config.js +28 -16
- package/_esm/tempo/accounts/Config.js.map +1 -1
- package/_esm/tempo/actions/accessKey.js +8 -8
- package/_esm/tempo/actions/accessKey.js.map +1 -1
- package/_esm/tempo/actions/accounts.js +7 -7
- package/_esm/tempo/actions/accounts.js.map +1 -1
- package/_esm/tempo/actions/amm.js +4 -4
- package/_esm/tempo/actions/amm.js.map +1 -1
- package/_esm/tempo/actions/channel.js +7 -7
- package/_esm/tempo/actions/channel.js.map +1 -1
- package/_esm/tempo/actions/dex.js +14 -14
- package/_esm/tempo/actions/dex.js.map +1 -1
- package/_esm/tempo/actions/earn/deployment.js +3 -3
- package/_esm/tempo/actions/earn/deployment.js.map +1 -1
- package/_esm/tempo/actions/earn.js +6 -6
- package/_esm/tempo/actions/earn.js.map +1 -1
- package/_esm/tempo/actions/fee.js +4 -4
- package/_esm/tempo/actions/fee.js.map +1 -1
- package/_esm/tempo/actions/nonce.js +1 -1
- package/_esm/tempo/actions/nonce.js.map +1 -1
- package/_esm/tempo/actions/policy.js +6 -6
- package/_esm/tempo/actions/policy.js.map +1 -1
- package/_esm/tempo/actions/propAmm.js +10 -10
- package/_esm/tempo/actions/propAmm.js.map +1 -1
- package/_esm/tempo/actions/receivePolicy.js +6 -6
- package/_esm/tempo/actions/receivePolicy.js.map +1 -1
- package/_esm/tempo/actions/reward.js +6 -6
- package/_esm/tempo/actions/reward.js.map +1 -1
- package/_esm/tempo/actions/token.js +21 -21
- package/_esm/tempo/actions/token.js.map +1 -1
- package/_esm/tempo/actions/validator.js +11 -11
- package/_esm/tempo/actions/validator.js.map +1 -1
- package/_esm/tempo/actions/virtualAddress.js +2 -2
- package/_esm/tempo/actions/virtualAddress.js.map +1 -1
- package/_esm/tempo/chainConfig.js +13 -4
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/internal/relay/accounts.js +44 -7
- package/_esm/tempo/internal/relay/accounts.js.map +1 -1
- package/_esm/tempo/internal/relay/feePayer.js +4 -1
- package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
- package/_esm/utils/abi/getAbiItem.js +36 -14
- package/_esm/utils/abi/getAbiItem.js.map +1 -1
- package/_esm/utils/abi/parseEventLogs.js +25 -11
- package/_esm/utils/abi/parseEventLogs.js.map +1 -1
- package/_esm/utils/authorization/serializeAuthorizationList.js +7 -1
- package/_esm/utils/authorization/serializeAuthorizationList.js.map +1 -1
- package/_esm/utils/buildRequest.js +29 -15
- package/_esm/utils/buildRequest.js.map +1 -1
- package/_esm/utils/data/isHex.js +3 -1
- package/_esm/utils/data/isHex.js.map +1 -1
- package/_esm/utils/hash/normalizeSignature.js +1 -1
- package/_esm/utils/hash/normalizeSignature.js.map +1 -1
- package/_esm/utils/hash/toSignature.js +1 -1
- package/_esm/utils/hash/toSignatureHash.js +1 -1
- package/_esm/utils/rpc/http.js +29 -7
- package/_esm/utils/rpc/http.js.map +1 -1
- package/_esm/utils/signature/compactSignatureToSignature.js +3 -2
- package/_esm/utils/signature/compactSignatureToSignature.js.map +1 -1
- package/_esm/utils/signature/hashTypedData.js +1 -2
- package/_esm/utils/signature/hashTypedData.js.map +1 -1
- package/_esm/utils/signature/signatureToCompactSignature.js +16 -7
- package/_esm/utils/signature/signatureToCompactSignature.js.map +1 -1
- package/_esm/utils/siwe/createSiweMessage.js +1 -1
- package/_esm/utils/siwe/createSiweMessage.js.map +1 -1
- package/_esm/utils/typedData.js +12 -8
- package/_esm/utils/typedData.js.map +1 -1
- package/_esm/utils/wait.js +2 -1
- package/_esm/utils/wait.js.map +1 -1
- package/_types/actions/getContract.d.ts +1 -1
- package/_types/actions/public/fillTransaction.d.ts.map +1 -1
- package/_types/actions/public/waitForTransactionReceipt.d.ts +31 -1
- package/_types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
- package/_types/actions/public/watchContractEvent.d.ts +1 -1
- package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/_types/actions/public/watchEvent.d.ts +1 -1
- package/_types/actions/public/watchEvent.d.ts.map +1 -1
- package/_types/chains/definitions/molibra.d.ts +52 -0
- package/_types/chains/definitions/molibra.d.ts.map +1 -0
- package/_types/chains/definitions/tempo.d.ts +14 -6
- package/_types/chains/definitions/tempo.d.ts.map +1 -1
- package/_types/chains/definitions/tempoDevnet.d.ts +14 -6
- package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempoLocalnet.d.ts +14 -6
- package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempoModerato.d.ts +14 -6
- package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
- package/_types/chains/definitions/valuechain.d.ts +53 -0
- package/_types/chains/definitions/valuechain.d.ts.map +1 -0
- package/_types/chains/definitions/valuechainTestnet.d.ts +53 -0
- package/_types/chains/definitions/valuechainTestnet.d.ts.map +1 -0
- package/_types/chains/index.d.ts +5 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/decorators/public.d.ts +5 -2
- package/_types/clients/decorators/public.d.ts.map +1 -1
- package/_types/clients/transports/http.d.ts.map +1 -1
- package/_types/errors/node.d.ts.map +1 -1
- package/_types/errors/request.d.ts +7 -1
- package/_types/errors/request.d.ts.map +1 -1
- package/_types/errors/typedData.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/op-stack/abis.d.ts +40 -0
- package/_types/op-stack/abis.d.ts.map +1 -1
- package/_types/op-stack/actions/getTimeToFinalize.d.ts +3 -2
- package/_types/op-stack/actions/getTimeToFinalize.d.ts.map +1 -1
- package/_types/op-stack/actions/getTimeToProve.d.ts +3 -1
- package/_types/op-stack/actions/getTimeToProve.d.ts.map +1 -1
- package/_types/op-stack/actions/getWithdrawalStatus.d.ts +2 -2
- package/_types/op-stack/actions/getWithdrawalStatus.d.ts.map +1 -1
- package/_types/op-stack/actions/waitToProve.d.ts +3 -1
- package/_types/op-stack/actions/waitToProve.d.ts.map +1 -1
- package/_types/op-stack/errors/withdrawal.d.ts +8 -0
- package/_types/op-stack/errors/withdrawal.d.ts.map +1 -1
- package/_types/tempo/Account.d.ts +14 -5
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Addresses.d.ts +0 -2
- package/_types/tempo/Addresses.d.ts.map +1 -1
- package/_types/tempo/Formatters.d.ts +3 -0
- package/_types/tempo/Formatters.d.ts.map +1 -1
- package/_types/tempo/Relay.d.ts +20 -0
- package/_types/tempo/Relay.d.ts.map +1 -1
- package/_types/tempo/Transaction.d.ts +7 -2
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/accounts/Config.d.ts +24 -2
- package/_types/tempo/accounts/Config.d.ts.map +1 -1
- package/_types/tempo/actions/accounts.d.ts +2 -2
- package/_types/tempo/chainConfig.d.ts +8 -3
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/internal/relay/accounts.d.ts.map +1 -1
- package/_types/tempo/internal/relay/feePayer.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/serializeAuthorizationList.d.ts.map +1 -1
- package/_types/utils/buildRequest.d.ts.map +1 -1
- package/_types/utils/data/isHex.d.ts +12 -1
- package/_types/utils/data/isHex.d.ts.map +1 -1
- package/_types/utils/hash/toSignature.d.ts +1 -1
- package/_types/utils/hash/toSignatureHash.d.ts +1 -1
- package/_types/utils/rpc/http.d.ts +2 -2
- package/_types/utils/rpc/http.d.ts.map +1 -1
- package/_types/utils/signature/compactSignatureToSignature.d.ts +2 -1
- package/_types/utils/signature/compactSignatureToSignature.d.ts.map +1 -1
- package/_types/utils/signature/hashTypedData.d.ts.map +1 -1
- package/_types/utils/signature/signatureToCompactSignature.d.ts +2 -1
- package/_types/utils/signature/signatureToCompactSignature.d.ts.map +1 -1
- package/_types/utils/typedData.d.ts.map +1 -1
- package/_types/utils/wait.d.ts.map +1 -1
- package/actions/getContract.ts +1 -1
- package/actions/public/fillTransaction.ts +12 -3
- package/actions/public/waitForTransactionReceipt.ts +164 -33
- package/actions/public/watchContractEvent.ts +82 -39
- package/actions/public/watchEvent.ts +82 -38
- package/actions/wallet/sendCalls.ts +1 -1
- package/chains/definitions/molibra.ts +18 -0
- package/chains/definitions/valuechain.ts +20 -0
- package/chains/definitions/valuechainTestnet.ts +21 -0
- package/chains/index.ts +5 -0
- package/clients/decorators/public.ts +5 -2
- package/clients/transports/http.ts +6 -1
- package/errors/node.ts +1 -1
- package/errors/request.ts +15 -1
- package/errors/typedData.ts +3 -1
- package/errors/version.ts +1 -1
- package/op-stack/abis.ts +52 -0
- package/op-stack/actions/getTimeToFinalize.ts +89 -10
- package/op-stack/actions/getTimeToProve.ts +43 -2
- package/op-stack/actions/getWithdrawalStatus.ts +30 -6
- package/op-stack/actions/waitToProve.ts +45 -3
- package/op-stack/errors/withdrawal.ts +17 -0
- package/package.json +2 -2
- package/tempo/Account.ts +20 -22
- package/tempo/Addresses.ts +0 -3
- package/tempo/Formatters.ts +19 -7
- package/tempo/Relay.ts +26 -0
- package/tempo/Transaction.ts +10 -2
- package/tempo/accounts/Config.ts +40 -25
- package/tempo/actions/accounts.ts +2 -2
- package/tempo/chainConfig.ts +15 -4
- package/tempo/internal/relay/accounts.ts +45 -9
- package/tempo/internal/relay/feePayer.ts +6 -1
- package/utils/abi/getAbiItem.ts +49 -17
- package/utils/abi/parseEventLogs.ts +32 -11
- package/utils/authorization/serializeAuthorizationList.ts +7 -1
- package/utils/buildRequest.ts +29 -14
- package/utils/data/isHex.ts +18 -1
- package/utils/hash/normalizeSignature.ts +1 -1
- package/utils/hash/toSignature.ts +1 -1
- package/utils/hash/toSignatureHash.ts +1 -1
- package/utils/rpc/http.ts +33 -8
- package/utils/signature/compactSignatureToSignature.ts +4 -2
- package/utils/signature/hashTypedData.ts +1 -2
- package/utils/signature/signatureToCompactSignature.ts +13 -8
- package/utils/siwe/createSiweMessage.ts +1 -1
- package/utils/typedData.ts +11 -8
- package/utils/wait.ts +8 -4
package/actions/getContract.ts
CHANGED
|
@@ -327,7 +327,7 @@ export type GetContractReturnType<
|
|
|
327
327
|
*
|
|
328
328
|
* This Action will batch up all the event logs found within the [`pollingInterval`](https://viem.sh/docs/contract/watchContractEvent#pollinginterval-optional), and invoke them via [`onLogs`](https://viem.sh/docs/contract/watchContractEvent#onLogs).
|
|
329
329
|
*
|
|
330
|
-
* `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead.
|
|
330
|
+
* `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead. If `getLogs` fails for a block range, `watchEvent` will retry with smaller block ranges and may call `onLogs` more than once per polling interval.
|
|
331
331
|
*
|
|
332
332
|
* @example
|
|
333
333
|
* import { createPublicClient, getContract, http, parseAbi } from 'viem'
|
|
@@ -202,7 +202,8 @@ export async function fillTransaction<
|
|
|
202
202
|
if (
|
|
203
203
|
hasFeePayerSignature &&
|
|
204
204
|
typeof nonce !== 'undefined' &&
|
|
205
|
-
|
|
205
|
+
// Tempo formats nonces as bigints (TIP-1106 discriminators exceed 2^53).
|
|
206
|
+
BigInt(transaction.nonce) !== BigInt(nonce)
|
|
206
207
|
)
|
|
207
208
|
throw new FeePayerNonceMismatchError({
|
|
208
209
|
filledNonce: transaction.nonce,
|
|
@@ -226,8 +227,16 @@ export async function fillTransaction<
|
|
|
226
227
|
if (transaction.maxPriorityFeePerGas)
|
|
227
228
|
transaction.maxPriorityFeePerGas =
|
|
228
229
|
parameters.maxPriorityFeePerGas ?? transaction.maxPriorityFeePerGas
|
|
229
|
-
if (
|
|
230
|
-
transaction.nonce
|
|
230
|
+
if (
|
|
231
|
+
typeof transaction.nonce !== 'undefined' &&
|
|
232
|
+
typeof parameters.nonce !== 'undefined'
|
|
233
|
+
)
|
|
234
|
+
// Keep the formatter's representation (Tempo formats nonces as bigints).
|
|
235
|
+
transaction.nonce = (
|
|
236
|
+
typeof transaction.nonce === 'bigint'
|
|
237
|
+
? BigInt(parameters.nonce)
|
|
238
|
+
: parameters.nonce
|
|
239
|
+
) as typeof transaction.nonce
|
|
231
240
|
|
|
232
241
|
// Build fee multiplier function.
|
|
233
242
|
const feeMultiplier = await (async () => {
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import type { Address } from 'abitype'
|
|
2
|
+
|
|
1
3
|
import type { Client } from '../../clients/createClient.js'
|
|
2
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
|
3
5
|
import { BlockNotFoundError } from '../../errors/block.js'
|
|
6
|
+
import {
|
|
7
|
+
MethodNotFoundRpcError,
|
|
8
|
+
MethodNotSupportedRpcError,
|
|
9
|
+
} from '../../errors/rpc.js'
|
|
4
10
|
import {
|
|
5
11
|
TransactionNotFoundError,
|
|
6
12
|
TransactionReceiptNotFoundError,
|
|
@@ -9,7 +15,7 @@ import {
|
|
|
9
15
|
} from '../../errors/transaction.js'
|
|
10
16
|
import type { ErrorType } from '../../errors/utils.js'
|
|
11
17
|
import type { Chain } from '../../types/chain.js'
|
|
12
|
-
import type { Hash } from '../../types/misc.js'
|
|
18
|
+
import type { Hash, Hex } from '../../types/misc.js'
|
|
13
19
|
import type { Transaction } from '../../types/transaction.js'
|
|
14
20
|
import { isAddressEqual } from '../../utils/address/isAddressEqual.js'
|
|
15
21
|
import { getAction } from '../../utils/getAction.js'
|
|
@@ -73,6 +79,34 @@ export type WaitForTransactionReceiptParameters<
|
|
|
73
79
|
* @default client.pollingInterval
|
|
74
80
|
*/
|
|
75
81
|
pollingInterval?: number | undefined
|
|
82
|
+
/**
|
|
83
|
+
* The sender and nonce of the transaction, and optionally the fields it was
|
|
84
|
+
* sent with.
|
|
85
|
+
*
|
|
86
|
+
* A node can drop a replaced transaction before the wait first reads it, and
|
|
87
|
+
* `hash` alone does not identify its sender and nonce. With them, the wait
|
|
88
|
+
* looks up the transaction in its nonce slot (`eth_getTransactionBySenderAndNonce`).
|
|
89
|
+
* Without that method, it scans each block from the one it starts on, which
|
|
90
|
+
* misses a replacement mined earlier.
|
|
91
|
+
*
|
|
92
|
+
* `onReplaced` receives these fields, with `hash`, as `replacedTransaction`.
|
|
93
|
+
* Ignored on chains with their own replacement keys (e.g. Tempo nonce lanes),
|
|
94
|
+
* where a sender and nonce do not identify a nonce slot.
|
|
95
|
+
*/
|
|
96
|
+
replacement?:
|
|
97
|
+
| {
|
|
98
|
+
/** The sender of the transaction. */
|
|
99
|
+
from: Address
|
|
100
|
+
/** The calldata of the transaction. Identifies a repriced replacement. */
|
|
101
|
+
input?: Hex | undefined
|
|
102
|
+
/** The nonce of the transaction. */
|
|
103
|
+
nonce: number
|
|
104
|
+
/** The recipient of the transaction. Identifies a repriced replacement. */
|
|
105
|
+
to?: Address | null | undefined
|
|
106
|
+
/** The value of the transaction (in wei). Identifies a repriced replacement. */
|
|
107
|
+
value?: bigint | undefined
|
|
108
|
+
}
|
|
109
|
+
| undefined
|
|
76
110
|
/**
|
|
77
111
|
* Number of times to retry if the transaction or block is not found.
|
|
78
112
|
* @default 6 (exponential backoff)
|
|
@@ -110,6 +144,9 @@ export type WaitForTransactionReceiptErrorType =
|
|
|
110
144
|
* - Calls [`eth_getBlockByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbynumber) and extracts the transactions
|
|
111
145
|
* - Checks if one of the Transactions is a replacement
|
|
112
146
|
* - If so, calls [`eth_getTransactionReceipt`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getTransactionReceipt).
|
|
147
|
+
* - If the Transaction is not found and `replacement` is provided:
|
|
148
|
+
* - Calls `eth_getTransactionBySenderAndNonce` to find the Transaction in its nonce slot
|
|
149
|
+
* - If it is a replacement, calls [`eth_getTransactionReceipt`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getTransactionReceipt).
|
|
113
150
|
*
|
|
114
151
|
* The `waitForTransactionReceipt` action additionally supports Replacement detection (e.g. sped up Transactions).
|
|
115
152
|
*
|
|
@@ -154,6 +191,12 @@ export async function waitForTransactionReceipt<
|
|
|
154
191
|
timeout = 180_000,
|
|
155
192
|
} = parameters
|
|
156
193
|
|
|
194
|
+
// On chains with their own replacement keys, a sender and nonce do not
|
|
195
|
+
// identify a nonce slot.
|
|
196
|
+
const replacement = client.chain?.transactionReplacement?.getKey
|
|
197
|
+
? undefined
|
|
198
|
+
: parameters.replacement
|
|
199
|
+
|
|
157
200
|
const getReplacementKey = (transaction: Transaction) =>
|
|
158
201
|
client.chain?.transactionReplacement?.getKey?.(transaction) ??
|
|
159
202
|
String(transaction.nonce)
|
|
@@ -176,14 +219,16 @@ export async function waitForTransactionReceipt<
|
|
|
176
219
|
checkReplacement,
|
|
177
220
|
confirmations,
|
|
178
221
|
pollingInterval,
|
|
222
|
+
replacement,
|
|
179
223
|
retryCount,
|
|
180
224
|
timeout,
|
|
181
225
|
},
|
|
182
226
|
])
|
|
183
227
|
|
|
184
228
|
let transaction: GetTransactionReturnType<chain> | undefined
|
|
185
|
-
let replacedTransaction: GetTransactionReturnType<chain> | undefined
|
|
186
229
|
let receipt: GetTransactionReceiptReturnType<chain> | undefined
|
|
230
|
+
// A found replacement, kept while `receipt` waits for confirmations.
|
|
231
|
+
let replacementResponse: ReplacementReturnType<chain> | undefined
|
|
187
232
|
let retrying = false
|
|
188
233
|
|
|
189
234
|
let _unobserve: () => void
|
|
@@ -249,7 +294,10 @@ export async function waitForTransactionReceipt<
|
|
|
249
294
|
)
|
|
250
295
|
return
|
|
251
296
|
|
|
252
|
-
done(() =>
|
|
297
|
+
done(() => {
|
|
298
|
+
if (replacementResponse) emit.onReplaced?.(replacementResponse)
|
|
299
|
+
emit.resolve(receipt!)
|
|
300
|
+
})
|
|
253
301
|
return
|
|
254
302
|
}
|
|
255
303
|
|
|
@@ -271,6 +319,10 @@ export async function waitForTransactionReceipt<
|
|
|
271
319
|
{
|
|
272
320
|
delay: retryDelay,
|
|
273
321
|
retryCount,
|
|
322
|
+
// A dropped transaction does not reappear, so a known
|
|
323
|
+
// sender and nonce are looked up without the retries.
|
|
324
|
+
shouldRetry: ({ error }) =>
|
|
325
|
+
!(replacement && error instanceof TransactionNotFoundError),
|
|
274
326
|
},
|
|
275
327
|
)
|
|
276
328
|
retrying = false
|
|
@@ -299,22 +351,104 @@ export async function waitForTransactionReceipt<
|
|
|
299
351
|
err instanceof TransactionNotFoundError ||
|
|
300
352
|
err instanceof TransactionReceiptNotFoundError
|
|
301
353
|
) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
354
|
+
retrying = false
|
|
355
|
+
|
|
356
|
+
// A node that dropped the transaction no longer returns it, so
|
|
357
|
+
// the known fields of it stand in. RPC hashes are lowercase.
|
|
358
|
+
const replaced =
|
|
359
|
+
transaction ??
|
|
360
|
+
(checkReplacement && replacement
|
|
361
|
+
? ({
|
|
362
|
+
...replacement,
|
|
363
|
+
hash: hash.toLowerCase(),
|
|
364
|
+
} as GetTransactionReturnType<chain>)
|
|
365
|
+
: undefined)
|
|
366
|
+
if (!replaced) return
|
|
306
367
|
|
|
307
368
|
// The transaction was seen mined, so it consumed its nonce slot
|
|
308
369
|
// and was not replaced: its receipt is not indexed yet. The
|
|
309
370
|
// transaction is fetched once, so one first seen pending is
|
|
310
371
|
// matched by replacement key instead.
|
|
311
|
-
if (
|
|
312
|
-
retrying = false
|
|
313
|
-
return
|
|
314
|
-
}
|
|
372
|
+
if (replaced.blockNumber) return
|
|
315
373
|
|
|
316
374
|
try {
|
|
317
|
-
|
|
375
|
+
// Look up the transaction in the nonce slot, since the block
|
|
376
|
+
// scan below misses a replacement mined before the wait starts.
|
|
377
|
+
if (!transaction) {
|
|
378
|
+
retrying = true
|
|
379
|
+
const found = (await getAction(
|
|
380
|
+
client,
|
|
381
|
+
getTransaction,
|
|
382
|
+
'getTransaction',
|
|
383
|
+
)({
|
|
384
|
+
nonce: replaced.nonce,
|
|
385
|
+
sender: replaced.from,
|
|
386
|
+
}).catch((error) => {
|
|
387
|
+
// Without the method, only the block scan runs from now
|
|
388
|
+
// on. Other errors retry the lookup on the next block.
|
|
389
|
+
if (
|
|
390
|
+
error instanceof MethodNotFoundRpcError ||
|
|
391
|
+
error instanceof MethodNotSupportedRpcError
|
|
392
|
+
)
|
|
393
|
+
transaction = replaced
|
|
394
|
+
return undefined
|
|
395
|
+
})) as GetTransactionReturnType<chain> | undefined
|
|
396
|
+
retrying = false
|
|
397
|
+
|
|
398
|
+
// The transaction still holds its nonce slot.
|
|
399
|
+
if (
|
|
400
|
+
(found as Transaction | undefined)?.hash.toLowerCase() ===
|
|
401
|
+
replaced.hash
|
|
402
|
+
) {
|
|
403
|
+
transaction = found
|
|
404
|
+
return
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// Another transaction holds the nonce slot, so it replaced
|
|
408
|
+
// this one. A pending replacement has no receipt yet.
|
|
409
|
+
if (found) {
|
|
410
|
+
const replacementReceipt = await getAction(
|
|
411
|
+
client,
|
|
412
|
+
getTransactionReceipt,
|
|
413
|
+
'getTransactionReceipt',
|
|
414
|
+
)({ hash: found.hash }).catch((error) => {
|
|
415
|
+
if (error instanceof TransactionReceiptNotFoundError)
|
|
416
|
+
return undefined
|
|
417
|
+
throw error
|
|
418
|
+
})
|
|
419
|
+
if (!replacementReceipt) return
|
|
420
|
+
|
|
421
|
+
receipt = replacementReceipt
|
|
422
|
+
replacementResponse = {
|
|
423
|
+
reason:
|
|
424
|
+
client.chain?.transactionReplacement?.getReason?.({
|
|
425
|
+
replaced,
|
|
426
|
+
replacement: found,
|
|
427
|
+
}) ??
|
|
428
|
+
getReplacementReason(
|
|
429
|
+
replaced as Transaction,
|
|
430
|
+
found as Transaction,
|
|
431
|
+
),
|
|
432
|
+
replacedTransaction: replaced as Transaction,
|
|
433
|
+
transaction: found as Transaction,
|
|
434
|
+
transactionReceipt: receipt,
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// Check if we have enough confirmations. If not, continue polling.
|
|
438
|
+
if (
|
|
439
|
+
confirmations > 1 &&
|
|
440
|
+
(!receipt.blockNumber ||
|
|
441
|
+
blockNumber - receipt.blockNumber + 1n < confirmations)
|
|
442
|
+
)
|
|
443
|
+
return
|
|
444
|
+
|
|
445
|
+
done(() => {
|
|
446
|
+
emit.onReplaced?.(replacementResponse!)
|
|
447
|
+
emit.resolve(receipt!)
|
|
448
|
+
})
|
|
449
|
+
return
|
|
450
|
+
}
|
|
451
|
+
}
|
|
318
452
|
|
|
319
453
|
// Let's retrieve the transactions from the current block.
|
|
320
454
|
// We need to retry as some RPC Providers may be slow to sync
|
|
@@ -339,15 +473,13 @@ export async function waitForTransactionReceipt<
|
|
|
339
473
|
)
|
|
340
474
|
retrying = false
|
|
341
475
|
|
|
342
|
-
const replacedKey = getReplacementKey(
|
|
343
|
-
replacedTransaction as Transaction,
|
|
344
|
-
)
|
|
476
|
+
const replacedKey = getReplacementKey(replaced as Transaction)
|
|
345
477
|
const replacementTransaction = (
|
|
346
478
|
block.transactions as {} as Transaction[]
|
|
347
479
|
).find(
|
|
348
480
|
(candidate) =>
|
|
349
|
-
isAddressEqual(candidate.from,
|
|
350
|
-
candidate.hash !==
|
|
481
|
+
isAddressEqual(candidate.from, replaced.from) &&
|
|
482
|
+
candidate.hash !== replaced.hash &&
|
|
351
483
|
getReplacementKey(candidate) === replacedKey,
|
|
352
484
|
)
|
|
353
485
|
|
|
@@ -362,6 +494,20 @@ export async function waitForTransactionReceipt<
|
|
|
362
494
|
)({
|
|
363
495
|
hash: replacementTransaction.hash,
|
|
364
496
|
})
|
|
497
|
+
replacementResponse = {
|
|
498
|
+
reason:
|
|
499
|
+
client.chain?.transactionReplacement?.getReason?.({
|
|
500
|
+
replaced,
|
|
501
|
+
replacement: replacementTransaction,
|
|
502
|
+
}) ??
|
|
503
|
+
getReplacementReason(
|
|
504
|
+
replaced as Transaction,
|
|
505
|
+
replacementTransaction,
|
|
506
|
+
),
|
|
507
|
+
replacedTransaction: replaced as Transaction,
|
|
508
|
+
transaction: replacementTransaction,
|
|
509
|
+
transactionReceipt: receipt,
|
|
510
|
+
}
|
|
365
511
|
|
|
366
512
|
// Check if we have enough confirmations. If not, continue polling.
|
|
367
513
|
if (
|
|
@@ -371,23 +517,8 @@ export async function waitForTransactionReceipt<
|
|
|
371
517
|
)
|
|
372
518
|
return
|
|
373
519
|
|
|
374
|
-
const reason =
|
|
375
|
-
client.chain?.transactionReplacement?.getReason?.({
|
|
376
|
-
replaced: replacedTransaction,
|
|
377
|
-
replacement: replacementTransaction,
|
|
378
|
-
}) ??
|
|
379
|
-
getReplacementReason(
|
|
380
|
-
replacedTransaction as Transaction,
|
|
381
|
-
replacementTransaction,
|
|
382
|
-
)
|
|
383
|
-
|
|
384
520
|
done(() => {
|
|
385
|
-
emit.onReplaced?.(
|
|
386
|
-
reason,
|
|
387
|
-
replacedTransaction: replacedTransaction! as any,
|
|
388
|
-
transaction: replacementTransaction,
|
|
389
|
-
transactionReceipt: receipt!,
|
|
390
|
-
})
|
|
521
|
+
emit.onReplaced?.(replacementResponse!)
|
|
391
522
|
emit.resolve(receipt!)
|
|
392
523
|
})
|
|
393
524
|
} catch (err_) {
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
DecodeLogDataMismatch,
|
|
7
7
|
DecodeLogTopicsMismatch,
|
|
8
8
|
} from '../../errors/abi.js'
|
|
9
|
+
import { BaseError } from '../../errors/base.js'
|
|
10
|
+
import { HttpRequestError, RpcRequestError } from '../../errors/request.js'
|
|
9
11
|
import { InvalidInputRpcError } from '../../errors/rpc.js'
|
|
10
12
|
import type { ErrorType } from '../../errors/utils.js'
|
|
11
13
|
import type { BlockNumber } from '../../types/block.js'
|
|
@@ -106,7 +108,7 @@ export type WatchContractEventErrorType =
|
|
|
106
108
|
*
|
|
107
109
|
* This Action will batch up all the event logs found within the [`pollingInterval`](https://viem.sh/docs/contract/watchContractEvent#pollinginterval-optional), and invoke them via [`onLogs`](https://viem.sh/docs/contract/watchContractEvent#onLogs).
|
|
108
110
|
*
|
|
109
|
-
* `watchContractEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchContractEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead.
|
|
111
|
+
* `watchContractEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchContractEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead. If `getLogs` fails for a block range, `watchContractEvent` will retry with smaller block ranges and may call `onLogs` more than once per polling interval.
|
|
110
112
|
*
|
|
111
113
|
* @param client - Client to use
|
|
112
114
|
* @param parameters - {@link WatchContractEventParameters}
|
|
@@ -185,11 +187,34 @@ export function watchContractEvent<
|
|
|
185
187
|
])
|
|
186
188
|
|
|
187
189
|
return observe(observerId, { onLogs, onError }, (emit) => {
|
|
188
|
-
let
|
|
189
|
-
|
|
190
|
+
let active = true
|
|
191
|
+
let previousBlockNumber =
|
|
192
|
+
fromBlock === undefined ? undefined : fromBlock - 1n
|
|
190
193
|
let filter: Filter<'event', abi, eventName> | undefined
|
|
191
194
|
let initialized = false
|
|
192
195
|
|
|
196
|
+
const emitLogs = (logs: Log[]) => {
|
|
197
|
+
if (logs.length === 0) return
|
|
198
|
+
if (batch) emit.onLogs(logs as any)
|
|
199
|
+
else for (const log of logs) emit.onLogs([log] as any)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Fetches the logs of the blocks from `from` to `to`, inclusive.
|
|
203
|
+
const getLogsInRange = (from: bigint, to: bigint) =>
|
|
204
|
+
getAction(
|
|
205
|
+
client,
|
|
206
|
+
getContractEvents,
|
|
207
|
+
'getContractEvents',
|
|
208
|
+
)({
|
|
209
|
+
abi,
|
|
210
|
+
address,
|
|
211
|
+
args,
|
|
212
|
+
eventName,
|
|
213
|
+
fromBlock: from,
|
|
214
|
+
toBlock: to,
|
|
215
|
+
strict,
|
|
216
|
+
} as {} as GetContractEventsParameters)
|
|
217
|
+
|
|
193
218
|
const unwatch = poll(
|
|
194
219
|
async () => {
|
|
195
220
|
if (!initialized) {
|
|
@@ -208,54 +233,55 @@ export function watchContractEvent<
|
|
|
208
233
|
})) as Filter<'event', abi, eventName>
|
|
209
234
|
} catch {}
|
|
210
235
|
initialized = true
|
|
211
|
-
return
|
|
236
|
+
if (filter) return
|
|
212
237
|
}
|
|
213
238
|
|
|
214
239
|
try {
|
|
215
|
-
let logs: Log[]
|
|
216
240
|
if (filter) {
|
|
217
|
-
logs = await getAction(
|
|
241
|
+
const logs = await getAction(
|
|
218
242
|
client,
|
|
219
243
|
getFilterChanges,
|
|
220
244
|
'getFilterChanges',
|
|
221
245
|
)({ filter })
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
246
|
+
emitLogs(logs)
|
|
247
|
+
return
|
|
248
|
+
}
|
|
225
249
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
250
|
+
// If the filter doesn't exist, we will fall back to use `getLogs`.
|
|
251
|
+
// The fall back exists because some RPC Providers do not support filters.
|
|
252
|
+
const blockNumber = await getAction(
|
|
253
|
+
client,
|
|
254
|
+
getBlockNumber,
|
|
255
|
+
'getBlockNumber',
|
|
256
|
+
)({})
|
|
232
257
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
258
|
+
// Without `fromBlock`, start watching from the current block.
|
|
259
|
+
previousBlockNumber ??= blockNumber
|
|
260
|
+
|
|
261
|
+
// RPC Providers limit `eth_getLogs` by block range, log count or response
|
|
262
|
+
// size. `size` is the most blocks to request at once: it starts with all
|
|
263
|
+
// new blocks and halves whenever a request fails.
|
|
264
|
+
let size = blockNumber - previousBlockNumber
|
|
265
|
+
while (previousBlockNumber < blockNumber) {
|
|
266
|
+
const from = previousBlockNumber + 1n
|
|
267
|
+
const end: bigint = previousBlockNumber + size
|
|
268
|
+
const to = end < blockNumber ? end : blockNumber
|
|
269
|
+
|
|
270
|
+
const logs = await getLogsInRange(from, to).catch((error) => {
|
|
271
|
+
// A single block cannot be split, and a smaller range does not
|
|
272
|
+
// help when the RPC Provider is unreachable or rejects the client.
|
|
273
|
+
if (from === to || !isRangeError(error)) throw error
|
|
274
|
+
})
|
|
275
|
+
if (!active) return
|
|
276
|
+
if (!logs) {
|
|
277
|
+
size = (to - from + 1n) / 2n
|
|
278
|
+
continue
|
|
252
279
|
}
|
|
253
|
-
previousBlockNumber = blockNumber
|
|
254
|
-
}
|
|
255
280
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
281
|
+
// Only move past blocks whose logs were fetched, so none are skipped.
|
|
282
|
+
previousBlockNumber = to
|
|
283
|
+
emitLogs(logs)
|
|
284
|
+
}
|
|
259
285
|
} catch (err) {
|
|
260
286
|
// If a filter has been set and gets uninstalled, providers will throw an InvalidInput error.
|
|
261
287
|
// Reinitialize the filter when this occurs
|
|
@@ -271,6 +297,7 @@ export function watchContractEvent<
|
|
|
271
297
|
)
|
|
272
298
|
|
|
273
299
|
return async () => {
|
|
300
|
+
active = false
|
|
274
301
|
if (filter)
|
|
275
302
|
await getAction(
|
|
276
303
|
client,
|
|
@@ -377,3 +404,19 @@ export function watchContractEvent<
|
|
|
377
404
|
|
|
378
405
|
return enablePolling ? pollContractEvent() : subscribeContractEvent()
|
|
379
406
|
}
|
|
407
|
+
|
|
408
|
+
/** Returns whether a failed `eth_getLogs` request may succeed with a smaller block range. */
|
|
409
|
+
function isRangeError(error: unknown) {
|
|
410
|
+
if (!(error instanceof BaseError)) return true
|
|
411
|
+
const cause = error.walk(
|
|
412
|
+
(err) => err instanceof HttpRequestError || err instanceof RpcRequestError,
|
|
413
|
+
) as HttpRequestError | RpcRequestError | null
|
|
414
|
+
if (!cause) return true
|
|
415
|
+
// Rate limited.
|
|
416
|
+
if (cause instanceof RpcRequestError && cause.code === 429) return false
|
|
417
|
+
// Unreachable.
|
|
418
|
+
if (cause instanceof HttpRequestError && cause.status === undefined)
|
|
419
|
+
return false
|
|
420
|
+
// Unauthorized, forbidden or rate limited.
|
|
421
|
+
return cause.status !== 401 && cause.status !== 403 && cause.status !== 429
|
|
422
|
+
}
|