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, ExtractAbiFunctionNames
|
1
|
+
import type { Abi, ExtractAbiFunctionNames } from 'abitype'
|
2
2
|
|
3
3
|
import {
|
4
4
|
AbiFunctionNotFoundError,
|
@@ -25,11 +25,9 @@ export type DecodeFunctionResultParameters<
|
|
25
25
|
functionName?: _FunctionName
|
26
26
|
data: Hex
|
27
27
|
} & (TFunctionName extends string
|
28
|
-
? { abi:
|
28
|
+
? { abi: TAbi } & Partial<GetFunctionArgs<TAbi, TFunctionName>>
|
29
29
|
: _FunctionName extends string
|
30
|
-
? { abi: [
|
31
|
-
GetFunctionArgs<TAbi, _FunctionName>
|
32
|
-
>
|
30
|
+
? { abi: [TAbi[number]] } & Partial<GetFunctionArgs<TAbi, _FunctionName>>
|
33
31
|
: never)
|
34
32
|
|
35
33
|
export type DecodeFunctionResultReturnType<
|
@@ -45,7 +43,7 @@ export type DecodeFunctionResultReturnType<
|
|
45
43
|
: ContractFunctionResult<TAbi, _FunctionName>
|
46
44
|
|
47
45
|
export function decodeFunctionResult<
|
48
|
-
TAbi extends Abi | readonly unknown[],
|
46
|
+
const TAbi extends Abi | readonly unknown[],
|
49
47
|
TFunctionName extends string | undefined = undefined,
|
50
48
|
>({
|
51
49
|
abi,
|
@@ -2,7 +2,6 @@ import type {
|
|
2
2
|
AbiParameter,
|
3
3
|
AbiParameterToPrimitiveType,
|
4
4
|
AbiParametersToPrimitiveTypes,
|
5
|
-
Narrow,
|
6
5
|
} from 'abitype'
|
7
6
|
|
8
7
|
import {
|
@@ -27,9 +26,9 @@ export type EncodeAbiParametersReturnType = Hex
|
|
27
26
|
* @description Encodes a list of primitive values into an ABI-encoded hex value.
|
28
27
|
*/
|
29
28
|
export function encodeAbiParameters<
|
30
|
-
TParams extends readonly AbiParameter[] | readonly unknown[],
|
29
|
+
const TParams extends readonly AbiParameter[] | readonly unknown[],
|
31
30
|
>(
|
32
|
-
params:
|
31
|
+
params: TParams,
|
33
32
|
values: TParams extends readonly AbiParameter[]
|
34
33
|
? AbiParametersToPrimitiveTypes<TParams>
|
35
34
|
: never,
|
@@ -56,11 +55,11 @@ type PreparedParam = { dynamic: boolean; encoded: Hex }
|
|
56
55
|
type TupleAbiParameter = AbiParameter & { components: readonly AbiParameter[] }
|
57
56
|
type Tuple = AbiParameterToPrimitiveType<TupleAbiParameter>
|
58
57
|
|
59
|
-
function prepareParams<TParams extends readonly AbiParameter[]>({
|
58
|
+
function prepareParams<const TParams extends readonly AbiParameter[]>({
|
60
59
|
params,
|
61
60
|
values,
|
62
61
|
}: {
|
63
|
-
params:
|
62
|
+
params: TParams
|
64
63
|
values: AbiParametersToPrimitiveTypes<TParams>
|
65
64
|
}) {
|
66
65
|
const preparedParams: PreparedParam[] = []
|
@@ -70,7 +69,7 @@ function prepareParams<TParams extends readonly AbiParameter[]>({
|
|
70
69
|
return preparedParams
|
71
70
|
}
|
72
71
|
|
73
|
-
function prepareParam<TParam extends AbiParameter>({
|
72
|
+
function prepareParam<const TParam extends AbiParameter>({
|
74
73
|
param,
|
75
74
|
value,
|
76
75
|
}: {
|
@@ -145,7 +144,7 @@ function encodeAddress(value: Hex): PreparedParam {
|
|
145
144
|
return { dynamic: false, encoded: padHex(value.toLowerCase() as Hex) }
|
146
145
|
}
|
147
146
|
|
148
|
-
function encodeArray<TParam extends AbiParameter>(
|
147
|
+
function encodeArray<const TParam extends AbiParameter>(
|
149
148
|
value: AbiParameterToPrimitiveType<TParam>,
|
150
149
|
{
|
151
150
|
length,
|
@@ -190,7 +189,7 @@ function encodeArray<TParam extends AbiParameter>(
|
|
190
189
|
}
|
191
190
|
}
|
192
191
|
|
193
|
-
function encodeBytes<TParam extends AbiParameter>(
|
192
|
+
function encodeBytes<const TParam extends AbiParameter>(
|
194
193
|
value: Hex,
|
195
194
|
{ param }: { param: TParam },
|
196
195
|
): PreparedParam {
|
@@ -256,7 +255,7 @@ function encodeString(value: string): PreparedParam {
|
|
256
255
|
}
|
257
256
|
|
258
257
|
function encodeTuple<
|
259
|
-
TParam extends AbiParameter & { components: readonly AbiParameter[] },
|
258
|
+
const TParam extends AbiParameter & { components: readonly AbiParameter[] },
|
260
259
|
>(
|
261
260
|
value: AbiParameterToPrimitiveType<TParam>,
|
262
261
|
{ param }: { param: TParam },
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Abi
|
1
|
+
import type { Abi } from 'abitype'
|
2
2
|
|
3
3
|
import {
|
4
4
|
AbiConstructorNotFoundError,
|
@@ -15,11 +15,11 @@ const docsPath = '/docs/contract/encodeDeployData'
|
|
15
15
|
export type EncodeDeployDataParameters<
|
16
16
|
TAbi extends Abi | readonly unknown[] = Abi,
|
17
17
|
> = {
|
18
|
-
abi:
|
18
|
+
abi: TAbi
|
19
19
|
bytecode: Hex
|
20
20
|
} & GetConstructorArgs<TAbi>
|
21
21
|
|
22
|
-
export function encodeDeployData<TAbi extends Abi | readonly unknown[]>({
|
22
|
+
export function encodeDeployData<const TAbi extends Abi | readonly unknown[]>({
|
23
23
|
abi,
|
24
24
|
args,
|
25
25
|
bytecode,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Abi
|
1
|
+
import type { Abi } from 'abitype'
|
2
2
|
|
3
3
|
import {
|
4
4
|
AbiErrorInputsNotFoundError,
|
@@ -26,13 +26,13 @@ export type EncodeErrorResultParameters<
|
|
26
26
|
> = {
|
27
27
|
errorName?: _ErrorName
|
28
28
|
} & (TErrorName extends string
|
29
|
-
? { abi:
|
29
|
+
? { abi: TAbi } & GetErrorArgs<TAbi, TErrorName>
|
30
30
|
: _ErrorName extends string
|
31
|
-
? { abi: [
|
31
|
+
? { abi: [TAbi[number]] } & GetErrorArgs<TAbi, _ErrorName>
|
32
32
|
: never)
|
33
33
|
|
34
34
|
export function encodeErrorResult<
|
35
|
-
TAbi extends Abi | readonly unknown[],
|
35
|
+
const TAbi extends Abi | readonly unknown[],
|
36
36
|
TErrorName extends string | undefined = undefined,
|
37
37
|
>({ abi, errorName, args }: EncodeErrorResultParameters<TAbi, TErrorName>) {
|
38
38
|
let abiItem = abi[0] as AbiItem
|
@@ -1,9 +1,4 @@
|
|
1
|
-
import type {
|
2
|
-
Abi,
|
3
|
-
AbiParameter,
|
4
|
-
AbiParameterToPrimitiveType,
|
5
|
-
Narrow,
|
6
|
-
} from 'abitype'
|
1
|
+
import type { Abi, AbiParameter, AbiParameterToPrimitiveType } from 'abitype'
|
7
2
|
|
8
3
|
import { AbiEventNotFoundError } from '../../errors/abi.js'
|
9
4
|
import { FilterTypeNotSupportedError } from '../../errors/log.js'
|
@@ -29,13 +24,13 @@ export type EncodeEventTopicsParameters<
|
|
29
24
|
> = {
|
30
25
|
eventName?: _EventName
|
31
26
|
} & (TEventName extends string
|
32
|
-
? { abi:
|
27
|
+
? { abi: TAbi; args?: GetEventArgs<TAbi, TEventName> }
|
33
28
|
: _EventName extends string
|
34
|
-
? { abi: [
|
29
|
+
? { abi: [TAbi[number]]; args?: GetEventArgs<TAbi, _EventName> }
|
35
30
|
: never)
|
36
31
|
|
37
32
|
export function encodeEventTopics<
|
38
|
-
TAbi extends Abi | readonly unknown[],
|
33
|
+
const TAbi extends Abi | readonly unknown[],
|
39
34
|
TEventName extends string | undefined = undefined,
|
40
35
|
>({ abi, eventName, args }: EncodeEventTopicsParameters<TAbi, TEventName>) {
|
41
36
|
let abiItem = abi[0] as AbiItem
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Abi
|
1
|
+
import type { Abi } from 'abitype'
|
2
2
|
|
3
3
|
import { AbiFunctionNotFoundError } from '../../errors/abi.js'
|
4
4
|
import type {
|
@@ -20,13 +20,13 @@ export type EncodeFunctionDataParameters<
|
|
20
20
|
> = {
|
21
21
|
functionName?: _FunctionName
|
22
22
|
} & (TFunctionName extends string
|
23
|
-
? { abi:
|
23
|
+
? { abi: TAbi } & GetFunctionArgs<TAbi, TFunctionName>
|
24
24
|
: _FunctionName extends string
|
25
|
-
? { abi: [
|
25
|
+
? { abi: [TAbi[number]] } & GetFunctionArgs<TAbi, _FunctionName>
|
26
26
|
: never)
|
27
27
|
|
28
28
|
export function encodeFunctionData<
|
29
|
-
TAbi extends Abi | readonly unknown[],
|
29
|
+
const TAbi extends Abi | readonly unknown[],
|
30
30
|
TFunctionName extends string | undefined = undefined,
|
31
31
|
>({
|
32
32
|
abi,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Abi
|
1
|
+
import type { Abi } from 'abitype'
|
2
2
|
|
3
3
|
import {
|
4
4
|
AbiFunctionNotFoundError,
|
@@ -22,16 +22,16 @@ export type EncodeFunctionResultParameters<
|
|
22
22
|
> = {
|
23
23
|
functionName?: _FunctionName
|
24
24
|
} & (TFunctionName extends string
|
25
|
-
? { abi:
|
25
|
+
? { abi: TAbi; result?: ContractFunctionResult<TAbi, TFunctionName> }
|
26
26
|
: _FunctionName extends string
|
27
27
|
? {
|
28
|
-
abi: [
|
28
|
+
abi: [TAbi[number]]
|
29
29
|
result?: ContractFunctionResult<TAbi, _FunctionName>
|
30
30
|
}
|
31
31
|
: never)
|
32
32
|
|
33
33
|
export function encodeFunctionResult<
|
34
|
-
TAbi extends Abi | readonly unknown[],
|
34
|
+
const TAbi extends Abi | readonly unknown[],
|
35
35
|
TFunctionName extends string | undefined = undefined,
|
36
36
|
>({
|
37
37
|
abi,
|
@@ -2,7 +2,6 @@ import type {
|
|
2
2
|
AbiParameterToPrimitiveType,
|
3
3
|
AbiType,
|
4
4
|
Address,
|
5
|
-
Narrow,
|
6
5
|
SolidityAddress,
|
7
6
|
SolidityArrayWithoutTuple,
|
8
7
|
SolidityBool,
|
@@ -32,18 +31,17 @@ type PackedAbiType =
|
|
32
31
|
| SolidityString
|
33
32
|
| SolidityArrayWithoutTuple
|
34
33
|
|
35
|
-
type EncodePackedValues<
|
34
|
+
type EncodePackedValues<
|
35
|
+
TPackedAbiTypes extends readonly PackedAbiType[] | readonly unknown[],
|
36
|
+
> = {
|
36
37
|
[K in keyof TPackedAbiTypes]: TPackedAbiTypes[K] extends AbiType
|
37
38
|
? AbiParameterToPrimitiveType<{ type: TPackedAbiTypes[K] }>
|
38
39
|
: unknown
|
39
40
|
}
|
40
41
|
|
41
42
|
export function encodePacked<
|
42
|
-
TPackedAbiTypes extends PackedAbiType[] | unknown[],
|
43
|
-
>(
|
44
|
-
types: Narrow<TPackedAbiTypes>,
|
45
|
-
values: EncodePackedValues<TPackedAbiTypes>,
|
46
|
-
): Hex {
|
43
|
+
const TPackedAbiTypes extends readonly PackedAbiType[] | readonly unknown[],
|
44
|
+
>(types: TPackedAbiTypes, values: EncodePackedValues<TPackedAbiTypes>): Hex {
|
47
45
|
if (types.length !== values.length)
|
48
46
|
throw new AbiEncodingLengthMismatchError({
|
49
47
|
expectedLength: types.length as number,
|
@@ -59,7 +57,7 @@ export function encodePacked<
|
|
59
57
|
return concat(data)
|
60
58
|
}
|
61
59
|
|
62
|
-
function encode<TPackedAbiType extends PackedAbiType | unknown>(
|
60
|
+
function encode<const TPackedAbiType extends PackedAbiType | unknown>(
|
63
61
|
type: TPackedAbiType,
|
64
62
|
value: EncodePackedValues<[TPackedAbiType]>[0],
|
65
63
|
isArray = false,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Abi, AbiParameter, Address
|
1
|
+
import type { Abi, AbiParameter, Address } from 'abitype'
|
2
2
|
|
3
3
|
import type { GetFunctionArgs, InferItemName } from '../../types/contract.js'
|
4
4
|
import { isAddress } from '../address/isAddress.js'
|
@@ -7,7 +7,7 @@ export type GetAbiItemParameters<
|
|
7
7
|
TAbi extends Abi | readonly unknown[] = Abi,
|
8
8
|
TItemName extends string = string,
|
9
9
|
> = {
|
10
|
-
abi:
|
10
|
+
abi: TAbi
|
11
11
|
name: InferItemName<TAbi, TItemName>
|
12
12
|
} & Partial<GetFunctionArgs<TAbi, TItemName>>
|
13
13
|
|
@@ -22,7 +22,7 @@ export type GetAbiItemReturnType<
|
|
22
22
|
>
|
23
23
|
|
24
24
|
export function getAbiItem<
|
25
|
-
TAbi extends Abi | readonly unknown[],
|
25
|
+
const TAbi extends Abi | readonly unknown[],
|
26
26
|
TItemName extends string,
|
27
27
|
>({
|
28
28
|
abi,
|
package/src/utils/chain.ts
CHANGED
@@ -3,8 +3,13 @@ import {
|
|
3
3
|
ChainMismatchError,
|
4
4
|
ChainNotFoundError,
|
5
5
|
} from '../errors/chain.js'
|
6
|
-
import type {
|
7
|
-
|
6
|
+
import type {
|
7
|
+
Chain,
|
8
|
+
ChainConfig,
|
9
|
+
ChainContract,
|
10
|
+
ChainFormatters,
|
11
|
+
} from '../types/chain.js'
|
12
|
+
import type { Assign } from '../types/utils.js'
|
8
13
|
|
9
14
|
export type AssertCurrentChainParameters = {
|
10
15
|
chain?: Chain
|
@@ -21,17 +26,23 @@ export function assertCurrentChain({
|
|
21
26
|
}
|
22
27
|
|
23
28
|
export function defineChain<
|
24
|
-
|
25
|
-
|
29
|
+
chain extends Chain,
|
30
|
+
formatters extends ChainFormatters,
|
26
31
|
>(
|
27
|
-
chain:
|
28
|
-
config
|
29
|
-
) {
|
32
|
+
chain: chain,
|
33
|
+
config: ChainConfig<formatters> = {},
|
34
|
+
): Assign<chain, ChainConfig<formatters>> {
|
35
|
+
const {
|
36
|
+
fees = chain.fees,
|
37
|
+
formatters = chain.formatters,
|
38
|
+
serializers = chain.serializers,
|
39
|
+
} = config
|
30
40
|
return {
|
31
41
|
...chain,
|
32
|
-
|
33
|
-
|
34
|
-
|
42
|
+
fees,
|
43
|
+
formatters,
|
44
|
+
serializers,
|
45
|
+
} as unknown as Assign<chain, ChainConfig<formatters>>
|
35
46
|
}
|
36
47
|
|
37
48
|
export function getChainContractAddress({
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { Block, BlockTag } from '../../types/block.js'
|
2
2
|
import type { Chain } from '../../types/chain.js'
|
3
3
|
import type {
|
4
|
-
|
5
|
-
|
6
|
-
} from '../../types/
|
4
|
+
ExtractChainFormatterExclude,
|
5
|
+
ExtractChainFormatterReturnType,
|
6
|
+
} from '../../types/chain.js'
|
7
7
|
import type { Hash } from '../../types/misc.js'
|
8
8
|
import type { RpcBlock } from '../../types/rpc.js'
|
9
9
|
import type { Prettify } from '../../types/utils.js'
|
@@ -14,16 +14,18 @@ import { type FormattedTransaction, formatTransaction } from './transaction.js'
|
|
14
14
|
type BlockPendingDependencies = 'hash' | 'logsBloom' | 'nonce' | 'number'
|
15
15
|
|
16
16
|
export type FormattedBlock<
|
17
|
-
TChain extends Chain | undefined =
|
17
|
+
TChain extends { formatters?: Chain['formatters'] } | undefined =
|
18
|
+
| { formatters?: Chain['formatters'] }
|
19
|
+
| undefined,
|
18
20
|
TIncludeTransactions extends boolean = boolean,
|
19
21
|
TBlockTag extends BlockTag = BlockTag,
|
20
|
-
_FormatterReturnType =
|
22
|
+
_FormatterReturnType = ExtractChainFormatterReturnType<
|
21
23
|
TChain,
|
22
24
|
'block',
|
23
25
|
Block<bigint, TIncludeTransactions>
|
24
26
|
>,
|
25
27
|
_ExcludedPendingDependencies extends string = BlockPendingDependencies &
|
26
|
-
|
28
|
+
ExtractChainFormatterExclude<TChain, 'block'>,
|
27
29
|
_Formatted = Omit<_FormatterReturnType, BlockPendingDependencies> & {
|
28
30
|
[K in _ExcludedPendingDependencies]: never
|
29
31
|
} & Pick<
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import type {
|
1
|
+
import type { ChainFormatter } from '../../types/chain.js'
|
2
2
|
|
3
3
|
/**
|
4
4
|
* @description Picks out the keys from `value` that exist in the formatter.
|
5
5
|
*/
|
6
6
|
export function extract(
|
7
7
|
value: Record<string, unknown>,
|
8
|
-
{ format }: { format?:
|
8
|
+
{ format }: { format?: ChainFormatter['format'] },
|
9
9
|
) {
|
10
10
|
if (!format) return {}
|
11
11
|
const keys = Object.keys(format({}))
|
@@ -17,8 +17,8 @@ export function defineFormatter<TType extends string, TParameters, TReturnType>(
|
|
17
17
|
}) => {
|
18
18
|
return {
|
19
19
|
exclude,
|
20
|
-
format: (args: TParameters
|
21
|
-
const formatted = format(args)
|
20
|
+
format: (args: Assign<TParameters, TOverrideParameters>) => {
|
21
|
+
const formatted = format(args as any)
|
22
22
|
if (exclude) {
|
23
23
|
for (const key of exclude) {
|
24
24
|
delete (formatted as any)[key]
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { BlockTag } from '../../types/block.js'
|
2
2
|
import type { Chain } from '../../types/chain.js'
|
3
3
|
import type {
|
4
|
-
|
5
|
-
|
6
|
-
} from '../../types/
|
4
|
+
ExtractChainFormatterExclude,
|
5
|
+
ExtractChainFormatterReturnType,
|
6
|
+
} from '../../types/chain.js'
|
7
7
|
import type { RpcTransaction } from '../../types/rpc.js'
|
8
8
|
import type { Transaction } from '../../types/transaction.js'
|
9
9
|
import type { UnionOmit } from '../../types/utils.js'
|
@@ -16,15 +16,17 @@ type TransactionPendingDependencies =
|
|
16
16
|
| 'transactionIndex'
|
17
17
|
|
18
18
|
export type FormattedTransaction<
|
19
|
-
TChain extends Chain | undefined =
|
19
|
+
TChain extends { formatters?: Chain['formatters'] } | undefined =
|
20
|
+
| { formatters?: Chain['formatters'] }
|
21
|
+
| undefined,
|
20
22
|
TBlockTag extends BlockTag = BlockTag,
|
21
|
-
_FormatterReturnType =
|
23
|
+
_FormatterReturnType = ExtractChainFormatterReturnType<
|
22
24
|
TChain,
|
23
25
|
'transaction',
|
24
26
|
Transaction
|
25
27
|
>,
|
26
28
|
_ExcludedPendingDependencies extends string = TransactionPendingDependencies &
|
27
|
-
|
29
|
+
ExtractChainFormatterExclude<TChain, 'transaction'>,
|
28
30
|
> = UnionOmit<_FormatterReturnType, TransactionPendingDependencies> & {
|
29
31
|
[K in _ExcludedPendingDependencies]: never
|
30
32
|
} & Pick<
|
@@ -1,5 +1,7 @@
|
|
1
|
-
import type {
|
2
|
-
|
1
|
+
import type {
|
2
|
+
Chain,
|
3
|
+
ExtractChainFormatterReturnType,
|
4
|
+
} from '../../types/chain.js'
|
3
5
|
import type { RpcTransactionReceipt } from '../../types/rpc.js'
|
4
6
|
import type { TransactionReceipt } from '../../types/transaction.js'
|
5
7
|
import { hexToNumber } from '../encoding/fromHex.js'
|
@@ -10,7 +12,11 @@ import { transactionType } from './transaction.js'
|
|
10
12
|
|
11
13
|
export type FormattedTransactionReceipt<
|
12
14
|
TChain extends Chain | undefined = Chain | undefined,
|
13
|
-
> =
|
15
|
+
> = ExtractChainFormatterReturnType<
|
16
|
+
TChain,
|
17
|
+
'transactionReceipt',
|
18
|
+
TransactionReceipt
|
19
|
+
>
|
14
20
|
|
15
21
|
const statuses = {
|
16
22
|
'0x0': 'reverted',
|
@@ -1,5 +1,7 @@
|
|
1
|
-
import type {
|
2
|
-
|
1
|
+
import type {
|
2
|
+
Chain,
|
3
|
+
ExtractChainFormatterParameters,
|
4
|
+
} from '../../types/chain.js'
|
3
5
|
import type { RpcTransactionRequest } from '../../types/rpc.js'
|
4
6
|
import type { TransactionRequest } from '../../types/transaction.js'
|
5
7
|
import { numberToHex } from '../encoding/toHex.js'
|
@@ -7,7 +9,11 @@ import { defineFormatter } from './formatter.js'
|
|
7
9
|
|
8
10
|
export type FormattedTransactionRequest<
|
9
11
|
TChain extends Chain | undefined = Chain | undefined,
|
10
|
-
> =
|
12
|
+
> = ExtractChainFormatterParameters<
|
13
|
+
TChain,
|
14
|
+
'transactionRequest',
|
15
|
+
TransactionRequest
|
16
|
+
>
|
11
17
|
|
12
18
|
export function formatTransactionRequest(
|
13
19
|
transactionRequest: Partial<TransactionRequest>,
|
package/src/utils/poll.ts
CHANGED
@@ -21,7 +21,7 @@ export function poll<TData>(
|
|
21
21
|
const unwatch = () => (active = false)
|
22
22
|
|
23
23
|
const watch = async () => {
|
24
|
-
let data: TData | void
|
24
|
+
let data: TData | void = undefined
|
25
25
|
if (emitOnBegin) data = await fn({ unpoll: unwatch })
|
26
26
|
|
27
27
|
const initialWait = (await initialWaitTime?.(data)) ?? interval
|
@@ -23,7 +23,7 @@ export type HashTypedDataParameters<
|
|
23
23
|
export type HashTypedDataReturnType = Hex
|
24
24
|
|
25
25
|
export function hashTypedData<
|
26
|
-
TTypedData extends TypedData | { [key: string]: unknown },
|
26
|
+
const TTypedData extends TypedData | { [key: string]: unknown },
|
27
27
|
TPrimaryType extends string = string,
|
28
28
|
>({
|
29
29
|
domain: domain_,
|
@@ -15,7 +15,7 @@ export type RecoverTypedDataAddressParameters<
|
|
15
15
|
export type RecoverTypedDataAddressReturnType = Address
|
16
16
|
|
17
17
|
export async function recoverTypedDataAddress<
|
18
|
-
TTypedData extends TypedData | { [key: string]: unknown },
|
18
|
+
const TTypedData extends TypedData | { [key: string]: unknown },
|
19
19
|
TPrimaryType extends string = string,
|
20
20
|
>({
|
21
21
|
domain,
|
@@ -35,7 +35,7 @@ export type VerifyTypedDataReturnType = boolean
|
|
35
35
|
* @returns Whether or not the signature is valid. {@link VerifyTypedDataReturnType}
|
36
36
|
*/
|
37
37
|
export async function verifyTypedData<
|
38
|
-
TTypedData extends TypedData | { [key: string]: unknown },
|
38
|
+
const TTypedData extends TypedData | { [key: string]: unknown },
|
39
39
|
TPrimaryType extends string = string,
|
40
40
|
>({
|
41
41
|
address,
|
@@ -15,24 +15,34 @@ import type { Transport } from '../../clients/transports/createTransport.js'
|
|
15
15
|
import { AccountNotFoundError } from '../../errors/account.js'
|
16
16
|
import { BaseError } from '../../errors/base.js'
|
17
17
|
import type { GetAccountParameter } from '../../types/account.js'
|
18
|
-
import type { Chain } from '../../types/chain.js'
|
19
|
-
|
18
|
+
import type { Chain, GetChain } from '../../types/chain.js'
|
19
|
+
import type { UnionOmit } from '../../types/utils.js'
|
20
|
+
import type { FormattedTransactionRequest } from '../index.js'
|
20
21
|
import { type AssertRequestParameters, assertRequest } from './assertRequest.js'
|
21
22
|
|
22
23
|
export type PrepareRequestParameters<
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
TChain extends Chain | undefined = Chain | undefined,
|
25
|
+
TAccount extends Account | undefined = Account | undefined,
|
26
|
+
TChainOverride extends Chain | undefined = Chain | undefined,
|
27
|
+
> = UnionOmit<
|
28
|
+
FormattedTransactionRequest<
|
29
|
+
TChainOverride extends Chain ? TChainOverride : TChain
|
30
|
+
>,
|
31
|
+
'from'
|
32
|
+
> &
|
33
|
+
GetAccountParameter<TAccount> &
|
34
|
+
GetChain<TChain, TChainOverride>
|
31
35
|
|
32
36
|
export type PrepareRequestReturnType<
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
TChain extends Chain | undefined = Chain | undefined,
|
38
|
+
TAccount extends Account | undefined = Account | undefined,
|
39
|
+
TChainOverride extends Chain | undefined = Chain | undefined,
|
40
|
+
TArgs extends PrepareRequestParameters<
|
41
|
+
TChain,
|
42
|
+
TAccount,
|
43
|
+
TChainOverride
|
44
|
+
> = PrepareRequestParameters<TChain, TAccount, TChainOverride>,
|
45
|
+
> = TArgs & {
|
36
46
|
from: Address
|
37
47
|
gas: SendTransactionParameters['gas']
|
38
48
|
gasPrice?: SendTransactionParameters['gasPrice']
|
@@ -41,18 +51,18 @@ export type PrepareRequestReturnType<
|
|
41
51
|
nonce: SendTransactionParameters['nonce']
|
42
52
|
}
|
43
53
|
|
44
|
-
export const defaultTip = 1_500_000_000n // 1.5 gwei
|
45
|
-
|
46
54
|
export async function prepareRequest<
|
47
55
|
TChain extends Chain | undefined,
|
48
56
|
TAccount extends Account | undefined,
|
49
|
-
|
57
|
+
TChainOverride extends Chain | undefined,
|
58
|
+
TArgs extends PrepareRequestParameters<TChain, TAccount, TChainOverride>,
|
50
59
|
>(
|
51
60
|
client: Client<Transport, TChain, TAccount>,
|
52
|
-
args:
|
53
|
-
): Promise<PrepareRequestReturnType<TAccount,
|
61
|
+
args: TArgs,
|
62
|
+
): Promise<PrepareRequestReturnType<TChain, TAccount, TChainOverride, TArgs>> {
|
54
63
|
const {
|
55
64
|
account: account_,
|
65
|
+
chain = client.chain,
|
56
66
|
gas,
|
57
67
|
gasPrice,
|
58
68
|
maxFeePerGas,
|
@@ -76,22 +86,33 @@ export async function prepareRequest<
|
|
76
86
|
typeof block.baseFeePerGas === 'bigint' &&
|
77
87
|
typeof gasPrice === 'undefined'
|
78
88
|
) {
|
89
|
+
let defaultPriorityFee = 1_500_000_000n // 1.5 gwei
|
90
|
+
if (typeof chain?.fees?.defaultPriorityFee !== 'undefined') {
|
91
|
+
defaultPriorityFee =
|
92
|
+
typeof chain.fees.defaultPriorityFee === 'bigint'
|
93
|
+
? chain.fees.defaultPriorityFee
|
94
|
+
: await chain.fees.defaultPriorityFee({
|
95
|
+
block,
|
96
|
+
request: request as PrepareRequestParameters,
|
97
|
+
})
|
98
|
+
}
|
99
|
+
|
79
100
|
// EIP-1559 fees
|
80
101
|
if (typeof maxFeePerGas === 'undefined') {
|
81
102
|
// Set a buffer of 1.2x on top of the base fee to account for fluctuations.
|
82
|
-
request.maxPriorityFeePerGas = maxPriorityFeePerGas ??
|
103
|
+
request.maxPriorityFeePerGas = maxPriorityFeePerGas ?? defaultPriorityFee
|
83
104
|
request.maxFeePerGas =
|
84
105
|
(block.baseFeePerGas * 120n) / 100n + request.maxPriorityFeePerGas
|
85
106
|
} else {
|
86
107
|
if (
|
87
108
|
typeof maxPriorityFeePerGas === 'undefined' &&
|
88
|
-
maxFeePerGas <
|
109
|
+
maxFeePerGas < defaultPriorityFee
|
89
110
|
)
|
90
111
|
throw new BaseError(
|
91
112
|
'`maxFeePerGas` cannot be less than the default `maxPriorityFeePerGas` (1.5 gwei).',
|
92
113
|
)
|
93
114
|
request.maxFeePerGas = maxFeePerGas
|
94
|
-
request.maxPriorityFeePerGas = maxPriorityFeePerGas ??
|
115
|
+
request.maxPriorityFeePerGas = maxPriorityFeePerGas ?? defaultPriorityFee
|
95
116
|
}
|
96
117
|
} else if (typeof gasPrice === 'undefined') {
|
97
118
|
// Legacy fees
|
@@ -113,5 +134,10 @@ export async function prepareRequest<
|
|
113
134
|
|
114
135
|
assertRequest(request as AssertRequestParameters)
|
115
136
|
|
116
|
-
return request as PrepareRequestReturnType<
|
137
|
+
return request as PrepareRequestReturnType<
|
138
|
+
TChain,
|
139
|
+
TAccount,
|
140
|
+
TChainOverride,
|
141
|
+
TArgs
|
142
|
+
>
|
117
143
|
}
|
package/src/utils/typedData.ts
CHANGED
@@ -11,7 +11,7 @@ import { numberToHex } from './encoding/toHex.js'
|
|
11
11
|
import { bytesRegex, integerRegex } from './regex.js'
|
12
12
|
|
13
13
|
export function validateTypedData<
|
14
|
-
TTypedData extends TypedData | { [key: string]: unknown },
|
14
|
+
const TTypedData extends TypedData | { [key: string]: unknown },
|
15
15
|
TPrimaryType extends string = string,
|
16
16
|
>({
|
17
17
|
domain,
|
@@ -63,8 +63,7 @@ export function validateTypedData<
|
|
63
63
|
}
|
64
64
|
|
65
65
|
// Validate domain types.
|
66
|
-
if (types
|
67
|
-
validateData(types['EIP712Domain'], domain)
|
66
|
+
if (types.EIP712Domain && domain) validateData(types.EIP712Domain, domain)
|
68
67
|
|
69
68
|
if (primaryType !== 'EIP712Domain') {
|
70
69
|
// Validate message types.
|