voltaire-effect 0.2.23 → 0.2.25
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/dist/KZGService-B7PJerOb.d.ts +146 -0
- package/dist/ProviderService-BZ5pqDrD.d.ts +319 -0
- package/dist/{X25519Test-DGsk1V9o.d.ts → X25519Test-D5Q-5fL9.d.ts} +4 -143
- package/dist/crypto/index.d.ts +5 -6
- package/dist/crypto/index.js +227 -201
- package/dist/{index-IgkEHjBe.d.ts → index-BCOuszKZ.d.ts} +17634 -11962
- package/dist/index.d.ts +3195 -976
- package/dist/index.js +6994 -4679
- package/dist/native/index.d.ts +25 -16
- package/dist/native/index.js +7020 -4705
- package/dist/primitives/index.d.ts +14 -8
- package/dist/primitives/index.js +4060 -2539
- package/dist/services/index.d.ts +9054 -30
- package/dist/services/index.js +1592 -1331
- package/package.json +2 -2
- package/src/crypto/ERC6492/ERC6492.test.ts +32 -14
- package/src/crypto/ERC6492/verifySignature.ts +4 -5
- package/src/crypto/Keccak256/Keccak256.test.ts +42 -1
- package/src/crypto/Keccak256/hashSync.ts +53 -0
- package/src/crypto/Keccak256/index.ts +2 -0
- package/src/index.ts +7 -2
- package/src/primitives/Abi/decode.test.ts +38 -0
- package/src/primitives/Abi/decode.ts +67 -0
- package/src/primitives/Abi/decodeData.test.ts +37 -0
- package/src/primitives/Abi/decodeData.ts +77 -0
- package/src/primitives/Abi/decodeLog.test.ts +32 -0
- package/src/primitives/Abi/decodeLog.ts +81 -0
- package/src/primitives/Abi/decodeWrappedError.test.ts +41 -0
- package/src/primitives/Abi/decodeWrappedError.ts +68 -0
- package/src/primitives/Abi/encode.test.ts +43 -0
- package/src/primitives/Abi/encode.ts +67 -0
- package/src/primitives/Abi/encodePacked.test.ts +35 -0
- package/src/primitives/Abi/encodePacked.ts +62 -0
- package/src/primitives/Abi/encodeWrappedError.test.ts +21 -0
- package/src/primitives/Abi/encodeWrappedError.ts +64 -0
- package/src/primitives/Abi/findSelectorCollisions.test.ts +50 -0
- package/src/primitives/Abi/findSelectorCollisions.ts +83 -0
- package/src/primitives/Abi/index.ts +33 -7
- package/src/primitives/Abi/parseLogs.test.ts +37 -0
- package/src/primitives/Abi/parseLogs.ts +62 -0
- package/src/primitives/AccessList/AccessList.test.ts +229 -0
- package/src/primitives/AccessList/AccessListTypeSchema.ts +16 -0
- package/src/primitives/AccessList/addressCount.ts +21 -0
- package/src/primitives/AccessList/assertValid.ts +37 -0
- package/src/primitives/AccessList/create.ts +19 -0
- package/src/primitives/AccessList/deduplicate.ts +23 -0
- package/src/primitives/AccessList/from.ts +39 -0
- package/src/primitives/AccessList/fromBytes.ts +36 -0
- package/src/primitives/AccessList/gasCost.ts +22 -0
- package/src/primitives/AccessList/gasSavings.ts +26 -0
- package/src/primitives/AccessList/hasSavings.ts +23 -0
- package/src/primitives/AccessList/includesAddress.ts +25 -0
- package/src/primitives/AccessList/includesStorageKey.ts +28 -0
- package/src/primitives/AccessList/index.ts +99 -19
- package/src/primitives/AccessList/is.ts +23 -0
- package/src/primitives/AccessList/isEmpty.ts +23 -0
- package/src/primitives/AccessList/isItem.ts +22 -0
- package/src/primitives/AccessList/keysFor.ts +29 -0
- package/src/primitives/AccessList/merge.ts +24 -0
- package/src/primitives/AccessList/storageKeyCount.ts +21 -0
- package/src/primitives/AccessList/toBytes.ts +23 -0
- package/src/primitives/AccessList/withAddress.ts +27 -0
- package/src/primitives/AccessList/withStorageKey.ts +30 -0
- package/src/primitives/Address/Address.test.ts +146 -0
- package/src/primitives/Address/assert.ts +51 -0
- package/src/primitives/Address/calculateCreate2Address.ts +33 -0
- package/src/primitives/Address/calculateCreateAddress.ts +30 -0
- package/src/primitives/Address/deduplicateAddresses.ts +20 -0
- package/src/primitives/Address/from.ts +41 -0
- package/src/primitives/Address/fromAbiEncoded.ts +35 -0
- package/src/primitives/Address/fromBase64.ts +25 -0
- package/src/primitives/Address/fromBytes.ts +25 -0
- package/src/primitives/Address/fromHex.ts +31 -0
- package/src/primitives/Address/fromNumber.ts +25 -0
- package/src/primitives/Address/fromPrivateKey.ts +25 -0
- package/src/primitives/Address/fromPublicKey.ts +56 -0
- package/src/primitives/Address/index.ts +99 -35
- package/src/primitives/Address/is.ts +20 -0
- package/src/primitives/Address/isAddress.ts +22 -0
- package/src/primitives/Address/sortAddresses.ts +19 -0
- package/src/primitives/Address/toChecksummed.ts +32 -0
- package/src/primitives/Address/toHex.ts +18 -0
- package/src/primitives/Address/zero.ts +18 -0
- package/src/primitives/Base64/Base64.test.ts +75 -0
- package/src/primitives/Base64/convert.ts +37 -0
- package/src/primitives/Base64/decode.ts +59 -0
- package/src/primitives/Base64/encode.ts +42 -0
- package/src/primitives/Base64/from.ts +39 -0
- package/src/primitives/Base64/index.ts +81 -1
- package/src/primitives/Base64/size.ts +16 -0
- package/src/primitives/Base64/validation.ts +16 -0
- package/src/primitives/Blob/Blob.test.ts +292 -0
- package/src/primitives/Blob/calculateGas.ts +30 -0
- package/src/primitives/Blob/estimateBlobCount.ts +30 -0
- package/src/primitives/Blob/from.ts +38 -0
- package/src/primitives/Blob/fromData.ts +36 -0
- package/src/primitives/Blob/index.ts +99 -12
- package/src/primitives/Blob/isValidVersion.ts +27 -0
- package/src/primitives/Blob/joinData.ts +43 -0
- package/src/primitives/Blob/splitData.ts +36 -0
- package/src/primitives/Blob/toCommitment.ts +43 -0
- package/src/primitives/Blob/toProof.ts +50 -0
- package/src/primitives/Blob/toVersionedHash.ts +35 -0
- package/src/primitives/Blob/verify.ts +49 -0
- package/src/primitives/Blob/verifyBatch.ts +119 -0
- package/src/primitives/BloomFilter/BloomFilter.test.ts +138 -0
- package/src/primitives/BloomFilter/add.ts +23 -0
- package/src/primitives/BloomFilter/combine.ts +21 -0
- package/src/primitives/BloomFilter/contains.ts +26 -0
- package/src/primitives/BloomFilter/create.ts +35 -0
- package/src/primitives/BloomFilter/density.ts +22 -0
- package/src/primitives/BloomFilter/expectedFalsePositiveRate.ts +25 -0
- package/src/primitives/BloomFilter/fromHex.ts +37 -0
- package/src/primitives/BloomFilter/hash.ts +43 -0
- package/src/primitives/BloomFilter/index.ts +59 -37
- package/src/primitives/BloomFilter/isEmpty.ts +22 -0
- package/src/primitives/BloomFilter/merge.ts +24 -0
- package/src/primitives/BloomFilter/toHex.ts +22 -0
- package/src/primitives/Bytecode/analyze.ts +58 -0
- package/src/primitives/Bytecode/detectFusions.ts +10 -0
- package/src/primitives/Bytecode/equals.ts +10 -0
- package/src/primitives/Bytecode/extractRuntime.ts +12 -0
- package/src/primitives/Bytecode/format.ts +16 -0
- package/src/primitives/Bytecode/from.ts +16 -0
- package/src/primitives/Bytecode/fromHex.ts +14 -0
- package/src/primitives/Bytecode/getBlock.ts +12 -0
- package/src/primitives/Bytecode/getNextPc.ts +12 -0
- package/src/primitives/Bytecode/getPushSize.ts +8 -0
- package/src/primitives/Bytecode/hasMetadata.ts +10 -0
- package/src/primitives/Bytecode/hash.ts +9 -0
- package/src/primitives/Bytecode/index.ts +103 -13
- package/src/primitives/Bytecode/isPush.ts +8 -0
- package/src/primitives/Bytecode/isTerminator.ts +8 -0
- package/src/primitives/Bytecode/isValidJumpDest.ts +12 -0
- package/src/primitives/Bytecode/parseInstructions.ts +10 -0
- package/src/primitives/Bytecode/prettyPrint.ts +12 -0
- package/src/primitives/Bytecode/scan.ts +20 -0
- package/src/primitives/Bytecode/size.ts +9 -0
- package/src/primitives/Bytecode/stripMetadata.ts +10 -0
- package/src/primitives/Bytecode/toAbi.ts +10 -0
- package/src/primitives/Bytecode/toHex.ts +10 -0
- package/src/primitives/Bytecode/types.ts +23 -0
- package/src/primitives/Bytecode/validate.ts +9 -0
- package/src/primitives/ContractSignature/ContractSignature.test.ts +1 -13
- package/src/primitives/ContractSignature/verifySignature.ts +88 -62
- package/src/primitives/Ens/Ens.test.ts +71 -0
- package/src/primitives/Ens/convert.ts +13 -0
- package/src/primitives/Ens/from.ts +32 -0
- package/src/primitives/Ens/hash.ts +46 -0
- package/src/primitives/Ens/index.ts +86 -4
- package/src/primitives/Ens/normalize.ts +45 -0
- package/src/primitives/Ens/validation.ts +38 -0
- package/src/primitives/EventLog/accessors.ts +32 -0
- package/src/primitives/EventLog/clone.ts +17 -0
- package/src/primitives/EventLog/create.ts +46 -0
- package/src/primitives/EventLog/filtering.ts +48 -0
- package/src/primitives/EventLog/index.ts +96 -6
- package/src/primitives/EventLog/status.ts +17 -0
- package/src/primitives/EventLog/toRpc.ts +49 -0
- package/src/primitives/Hardfork/HardforkSchema.ts +3 -3
- package/src/primitives/Hardfork/allIds.ts +13 -0
- package/src/primitives/Hardfork/allNames.ts +13 -0
- package/src/primitives/Hardfork/compare.ts +17 -0
- package/src/primitives/Hardfork/comparisons.ts +45 -0
- package/src/primitives/Hardfork/equals.ts +17 -0
- package/src/primitives/Hardfork/features.ts +61 -0
- package/src/primitives/Hardfork/fromString.ts +16 -0
- package/src/primitives/Hardfork/index.ts +128 -18
- package/src/primitives/Hardfork/isValidName.ts +14 -0
- package/src/primitives/Hardfork/minMax.ts +23 -0
- package/src/primitives/Hardfork/range.ts +19 -0
- package/src/primitives/Hardfork/toString.ts +16 -0
- package/src/primitives/Hash/Hash.test.ts +104 -0
- package/src/primitives/Hash/from.ts +47 -0
- package/src/primitives/Hash/fromBytes.ts +46 -0
- package/src/primitives/Hash/fromHex.ts +44 -0
- package/src/primitives/Hash/index.ts +45 -8
- package/src/primitives/Hash/isHash.ts +31 -0
- package/src/primitives/Hash/toHex.ts +29 -0
- package/src/primitives/Hex/Hex.test.ts +327 -153
- package/src/primitives/Hex/assertSize.ts +41 -0
- package/src/primitives/Hex/concat.ts +37 -0
- package/src/primitives/Hex/from.ts +38 -0
- package/src/primitives/Hex/fromBigInt.ts +40 -0
- package/src/primitives/Hex/fromBoolean.ts +29 -0
- package/src/primitives/Hex/fromNumber.ts +41 -0
- package/src/primitives/Hex/fromString.ts +28 -0
- package/src/primitives/Hex/index.ts +68 -37
- package/src/primitives/Hex/pad.ts +40 -0
- package/src/primitives/Hex/padRight.ts +39 -0
- package/src/primitives/Hex/size.ts +29 -0
- package/src/primitives/Hex/slice.ts +42 -0
- package/src/primitives/Hex/toBigInt.ts +27 -0
- package/src/primitives/Hex/toBoolean.ts +38 -0
- package/src/primitives/Hex/toNumber.ts +37 -0
- package/src/primitives/Hex/toStringHex.ts +39 -0
- package/src/primitives/Hex/trim.ts +27 -0
- package/src/primitives/Hex/validate.ts +37 -0
- package/src/primitives/Hex/xor.ts +39 -0
- package/src/primitives/Opcode/OpcodeSchema.ts +1 -1
- package/src/primitives/Opcode/disassemble.ts +15 -0
- package/src/primitives/Opcode/dupPosition.ts +15 -0
- package/src/primitives/Opcode/format.ts +15 -0
- package/src/primitives/Opcode/getters.ts +54 -0
- package/src/primitives/Opcode/index.ts +301 -11
- package/src/primitives/Opcode/info.ts +18 -0
- package/src/primitives/Opcode/jumpDests.ts +15 -0
- package/src/primitives/Opcode/logTopics.ts +15 -0
- package/src/primitives/Opcode/name.ts +15 -0
- package/src/primitives/Opcode/parse.ts +15 -0
- package/src/primitives/Opcode/predicates.ts +72 -0
- package/src/primitives/Opcode/pushBytes.ts +15 -0
- package/src/primitives/Opcode/pushOpcode.ts +15 -0
- package/src/primitives/Opcode/swapPosition.ts +15 -0
- package/src/primitives/Rlp/decodeBatch.ts +46 -0
- package/src/primitives/Rlp/decodeObject.ts +46 -0
- package/src/primitives/Rlp/decodeValue.ts +51 -0
- package/src/primitives/Rlp/encodeBatch.ts +50 -0
- package/src/primitives/Rlp/encodeObject.ts +48 -0
- package/src/primitives/Rlp/encodeVariadic.ts +49 -0
- package/src/primitives/Rlp/equals.ts +22 -0
- package/src/primitives/Rlp/from.ts +44 -0
- package/src/primitives/Rlp/fromJSON.ts +45 -0
- package/src/primitives/Rlp/getEncodedLength.ts +47 -0
- package/src/primitives/Rlp/getLength.ts +44 -0
- package/src/primitives/Rlp/index.ts +67 -14
- package/src/primitives/Rlp/isBytesData.ts +21 -0
- package/src/primitives/Rlp/isCanonical.ts +32 -0
- package/src/primitives/Rlp/isData.ts +21 -0
- package/src/primitives/Rlp/isList.ts +46 -0
- package/src/primitives/Rlp/isListData.ts +21 -0
- package/src/primitives/Rlp/isString.ts +46 -0
- package/src/primitives/Rlp/toJSON.ts +20 -0
- package/src/primitives/Rlp/toRaw.ts +31 -0
- package/src/primitives/Signature/Signature.test.ts +217 -0
- package/src/primitives/Signature/from.ts +38 -0
- package/src/primitives/Signature/fromBytes.ts +31 -0
- package/src/primitives/Signature/fromCompact.ts +33 -0
- package/src/primitives/Signature/fromDER.ts +35 -0
- package/src/primitives/Signature/fromEd25519.ts +24 -0
- package/src/primitives/Signature/fromHex.ts +29 -0
- package/src/primitives/Signature/fromP256.ts +25 -0
- package/src/primitives/Signature/fromRpc.ts +38 -0
- package/src/primitives/Signature/fromSecp256k1.ts +29 -0
- package/src/primitives/Signature/fromTuple.ts +33 -0
- package/src/primitives/Signature/getR.ts +24 -0
- package/src/primitives/Signature/getS.ts +24 -0
- package/src/primitives/Signature/getV.ts +24 -0
- package/src/primitives/Signature/index.ts +61 -11
- package/src/primitives/Signature/toDER.ts +24 -0
- package/src/primitives/Signature/toHex.ts +24 -0
- package/src/primitives/Signature/toRpc.ts +35 -0
- package/src/primitives/Signature/toTuple.ts +29 -0
- package/src/primitives/Signature/verify.ts +31 -0
- package/src/primitives/Siwe/create.ts +56 -0
- package/src/primitives/Siwe/hash.ts +27 -0
- package/src/primitives/Siwe/index.ts +57 -21
- package/src/primitives/Siwe/parse.ts +24 -0
- package/src/primitives/Siwe/verify.ts +47 -0
- package/src/primitives/Transaction/Transaction.test.ts +309 -0
- package/src/primitives/Transaction/index.ts +467 -2
- package/src/primitives/Uint/Uint.test.ts +200 -0
- package/src/primitives/Uint/dividedBy.ts +34 -0
- package/src/primitives/Uint/from.ts +35 -0
- package/src/primitives/Uint/fromAbiEncoded.ts +29 -0
- package/src/primitives/Uint/fromBigInt.ts +30 -0
- package/src/primitives/Uint/fromBytes.ts +32 -0
- package/src/primitives/Uint/fromHex.ts +32 -0
- package/src/primitives/Uint/fromNumber.ts +30 -0
- package/src/primitives/Uint/index.ts +90 -45
- package/src/primitives/Uint/isUint256.ts +25 -0
- package/src/primitives/Uint/isValid.ts +25 -0
- package/src/primitives/Uint/modulo.ts +34 -0
- package/src/primitives/Uint/toHex.ts +31 -0
- package/src/primitives/Uint/tryFrom.ts +30 -0
- package/src/services/Contract/Contract.test.ts +46 -41
- package/src/services/Contract/Contract.ts +25 -29
- package/src/services/Contract/ContractTypes.ts +6 -3
- package/src/services/Contract/estimateGas.test.ts +21 -9
- package/src/services/Contract/estimateGas.ts +21 -23
- package/src/services/Debug/Debug.ts +1 -1
- package/src/services/Debug/DebugService.ts +1 -1
- package/src/services/FeeEstimator/DefaultFeeEstimator.ts +10 -6
- package/src/services/FeeEstimator/FeeEstimator.test.ts +68 -62
- package/src/services/Multicall/BalanceResolver.ts +1 -1
- package/src/services/Multicall/GetBalance.ts +1 -1
- package/src/services/Multicall/Multicall.ts +1 -1
- package/src/services/NonceManager/DefaultNonceManager.ts +4 -7
- package/src/services/NonceManager/NonceManager.test.ts +20 -33
- package/src/services/Provider/Provider.test.ts +155 -349
- package/src/services/Provider/Provider.ts +14 -1180
- package/src/services/Provider/ProviderService.ts +14 -1199
- package/src/services/Provider/actions/multicall.test.ts +29 -39
- package/src/services/Provider/actions/multicall.ts +2 -2
- package/src/services/Provider/actions/readContract.test.ts +45 -50
- package/src/services/Provider/actions/readContract.ts +2 -6
- package/src/services/Provider/actions/simulateContract.test.ts +55 -232
- package/src/services/Provider/actions/simulateContract.ts +2 -3
- package/src/services/Provider/ens/getEnsAddress.ts +11 -14
- package/src/services/Provider/ens/getEnsName.ts +15 -18
- package/src/services/Provider/ens/getEnsResolver.ts +11 -14
- package/src/services/Provider/ens/getEnsText.ts +15 -18
- package/src/services/Provider/functions/backfillBlocks.ts +97 -0
- package/src/services/Provider/functions/call.ts +45 -0
- package/src/services/Provider/functions/createAccessList.ts +61 -0
- package/src/services/Provider/functions/createBlockFilter.ts +41 -0
- package/src/services/Provider/functions/createEventFilter.ts +43 -0
- package/src/services/Provider/functions/createPendingTransactionFilter.ts +41 -0
- package/src/services/Provider/functions/estimateGas.ts +52 -0
- package/src/services/Provider/functions/getAccounts.ts +40 -0
- package/src/services/Provider/functions/getBalance.ts +50 -0
- package/src/services/Provider/functions/getBlobBaseFee.ts +46 -0
- package/src/services/Provider/functions/getBlock.ts +95 -0
- package/src/services/Provider/functions/getBlockNumber.ts +51 -0
- package/src/services/Provider/functions/getBlockReceipts.ts +78 -0
- package/src/services/Provider/functions/getBlockTransactionCount.ts +86 -0
- package/src/services/Provider/functions/getChainId.ts +46 -0
- package/src/services/Provider/functions/getCode.ts +43 -0
- package/src/services/Provider/functions/getCoinbase.ts +40 -0
- package/src/services/Provider/functions/getFeeHistory.ts +85 -0
- package/src/services/Provider/functions/getFilterChanges.ts +42 -0
- package/src/services/Provider/functions/getFilterLogs.ts +44 -0
- package/src/services/Provider/functions/getGasPrice.ts +46 -0
- package/src/services/Provider/functions/getHashrate.ts +46 -0
- package/src/services/Provider/functions/getLogs.ts +45 -0
- package/src/services/Provider/functions/getMaxPriorityFeePerGas.ts +46 -0
- package/src/services/Provider/functions/getMining.ts +40 -0
- package/src/services/Provider/functions/getProof.ts +52 -0
- package/src/services/Provider/functions/getProtocolVersion.ts +40 -0
- package/src/services/Provider/functions/getStorageAt.ts +52 -0
- package/src/services/Provider/functions/getSyncing.ts +56 -0
- package/src/services/Provider/functions/getTransaction.ts +57 -0
- package/src/services/Provider/functions/getTransactionByBlockHashAndIndex.ts +73 -0
- package/src/services/Provider/functions/getTransactionByBlockNumberAndIndex.ts +86 -0
- package/src/services/Provider/functions/getTransactionConfirmations.ts +70 -0
- package/src/services/Provider/functions/getTransactionCount.ts +50 -0
- package/src/services/Provider/functions/getTransactionReceipt.ts +57 -0
- package/src/services/Provider/functions/getUncle.ts +97 -0
- package/src/services/Provider/functions/getUncleCount.ts +86 -0
- package/src/services/Provider/functions/index.ts +73 -0
- package/src/services/Provider/functions/netVersion.ts +40 -0
- package/src/services/Provider/functions/sendRawTransaction.ts +40 -0
- package/src/services/Provider/functions/sendTransaction.ts +48 -0
- package/src/services/Provider/functions/sign.ts +50 -0
- package/src/services/Provider/functions/signTransaction.ts +52 -0
- package/src/services/Provider/functions/simulateV1.ts +95 -0
- package/src/services/Provider/functions/simulateV2.ts +51 -0
- package/src/services/Provider/functions/subscribe.ts +49 -0
- package/src/services/Provider/functions/uninstallFilter.ts +40 -0
- package/src/services/Provider/functions/unsubscribe.ts +41 -0
- package/src/services/Provider/functions/waitForTransactionReceipt.ts +168 -0
- package/src/services/Provider/functions/watchBlocks.ts +98 -0
- package/src/services/Provider/index.ts +29 -178
- package/src/services/Provider/types.ts +780 -0
- package/src/services/Provider/utils.ts +204 -0
- package/src/services/RawProvider/ForkProviderTransport.ts +2 -3
- package/src/services/RawProvider/HttpProviderTransport.ts +3 -3
- package/src/services/RawProvider/InMemoryProviderTransport.ts +3 -3
- package/src/services/RawProvider/WebSocketProviderTransport.ts +3 -3
- package/src/services/Signer/Signer.test.ts +211 -187
- package/src/services/Signer/Signer.ts +26 -16
- package/src/services/Signer/actions/deployContract.test.ts +125 -105
- package/src/services/Signer/actions/deployContract.ts +3 -2
- package/src/services/Signer/actions/prepareAuthorization.test.ts +47 -48
- package/src/services/Signer/actions/prepareAuthorization.ts +3 -3
- package/src/services/Signer/actions/signAuthorization.test.ts +39 -45
- package/src/services/Signer/actions/signAuthorization.ts +3 -3
- package/src/services/Signer/actions/writeContract.test.ts +41 -57
- package/src/services/Transport/FallbackTransport.ts +3 -3
- package/src/services/Transport/HttpTransport.ts +3 -3
- package/src/services/Transport/config.ts +7 -7
- package/src/services/Transport/index.ts +3 -4
- package/src/services/errors.test.ts +3 -8
- package/src/services/index.ts +8 -90
- package/src/services/presets/index.ts +9 -10
- package/src/services/presets/presets.test.ts +14 -29
- package/src/standards/ERC165.test.ts +19 -20
- package/src/standards/ERC165.ts +9 -11
- package/src/type-exports.test.ts +37 -0
- package/dist/AccountService-BetXokad.d.ts +0 -1717
- package/dist/RpcResolver-BpvqybjD.d.ts +0 -6439
- package/src/services/Provider/Account.ts +0 -33
- package/src/services/Provider/AccountService.ts +0 -84
- package/src/services/Provider/Blocks.ts +0 -32
- package/src/services/Provider/BlocksService.ts +0 -73
- package/src/services/Provider/Events.ts +0 -33
- package/src/services/Provider/EventsService.ts +0 -71
- package/src/services/Provider/Network.ts +0 -41
- package/src/services/Provider/NetworkService.ts +0 -114
- package/src/services/Provider/Simulation.ts +0 -34
- package/src/services/Provider/SimulationService.ts +0 -161
- package/src/services/Provider/Streaming.ts +0 -30
- package/src/services/Provider/StreamingService.ts +0 -58
- package/src/services/Provider/Transaction.ts +0 -39
- package/src/services/Provider/TransactionService.ts +0 -83
- package/src/services/Provider/filters.ts +0 -91
- package/src/services/Provider/getBlobBaseFee.ts +0 -170
|
@@ -3,1191 +3,25 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module Provider
|
|
5
5
|
* @since 0.0.1
|
|
6
|
-
*
|
|
7
|
-
* @description
|
|
8
|
-
* Provides the live implementation layer for ProviderService. This layer
|
|
9
|
-
* translates the high-level ProviderService methods into JSON-RPC calls
|
|
10
|
-
* via the TransportService.
|
|
11
|
-
*
|
|
12
|
-
* The layer requires a TransportService to be provided (HttpTransport,
|
|
13
|
-
* WebSocketTransport, BrowserTransport, or TestTransport).
|
|
14
|
-
*
|
|
15
|
-
* @see {@link ProviderService} - The service interface
|
|
16
|
-
* @see {@link TransportService} - Required dependency
|
|
17
|
-
* @see {@link HttpTransport} - Common transport for RPC calls
|
|
18
6
|
*/
|
|
19
7
|
|
|
20
|
-
import {
|
|
21
|
-
type BackfillOptions,
|
|
22
|
-
type BlockInclude,
|
|
23
|
-
type BlockStreamEvent,
|
|
24
|
-
type BlocksEvent,
|
|
25
|
-
BlockStream as CoreBlockStream,
|
|
26
|
-
type WatchOptions,
|
|
27
|
-
} from "@tevm/voltaire/block";
|
|
28
|
-
import type { HexType } from "@tevm/voltaire/Hex";
|
|
29
|
-
import * as Duration from "effect/Duration";
|
|
30
8
|
import * as Effect from "effect/Effect";
|
|
31
9
|
import * as Layer from "effect/Layer";
|
|
32
|
-
import * as Runtime from "effect/Runtime";
|
|
33
|
-
import * as Schedule from "effect/Schedule";
|
|
34
|
-
import * as Stream from "effect/Stream";
|
|
35
|
-
import { TransportError } from "../Transport/TransportError.js";
|
|
36
10
|
import { TransportService } from "../Transport/TransportService.js";
|
|
37
|
-
import {
|
|
38
|
-
import type { SyncingStatus, WorkResult } from "./NetworkService.js";
|
|
39
|
-
import {
|
|
40
|
-
type AccessListInput,
|
|
41
|
-
type AccessListType,
|
|
42
|
-
type AddressInput,
|
|
43
|
-
type BackfillBlocksError,
|
|
44
|
-
type BlockOverrides,
|
|
45
|
-
type BlockTag,
|
|
46
|
-
type BlockType,
|
|
47
|
-
type CallRequest,
|
|
48
|
-
type EventFilter,
|
|
49
|
-
type FeeHistoryType,
|
|
50
|
-
type FilterChanges,
|
|
51
|
-
type FilterId,
|
|
52
|
-
type GetBlockArgs,
|
|
53
|
-
type GetBlockReceiptsArgs,
|
|
54
|
-
type GetUncleArgs,
|
|
55
|
-
type GetUncleCountArgs,
|
|
56
|
-
type HashInput,
|
|
57
|
-
type LogFilter,
|
|
58
|
-
type LogType,
|
|
59
|
-
type ProofType,
|
|
60
|
-
ProviderConfirmationsPendingError,
|
|
61
|
-
ProviderNotFoundError,
|
|
62
|
-
ProviderReceiptPendingError,
|
|
63
|
-
ProviderResponseError,
|
|
64
|
-
ProviderService,
|
|
65
|
-
ProviderStreamError,
|
|
66
|
-
ProviderTimeoutError,
|
|
67
|
-
ProviderValidationError,
|
|
68
|
-
type ReceiptType,
|
|
69
|
-
type RpcTransactionRequest,
|
|
70
|
-
type StateOverride,
|
|
71
|
-
type TransactionIndexInput,
|
|
72
|
-
type TransactionType,
|
|
73
|
-
type UncleBlockType,
|
|
74
|
-
type WatchBlocksError,
|
|
75
|
-
} from "./ProviderService.js";
|
|
76
|
-
import type {
|
|
77
|
-
SimulateV1Payload,
|
|
78
|
-
SimulateV1Result,
|
|
79
|
-
SimulateV2Payload,
|
|
80
|
-
SimulateV2Result,
|
|
81
|
-
} from "./SimulationService.js";
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Converts a Uint8Array to hex string.
|
|
85
|
-
*/
|
|
86
|
-
const bytesToHex = (bytes: Uint8Array): `0x${string}` => {
|
|
87
|
-
let hex = "0x";
|
|
88
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
89
|
-
hex += bytes[i].toString(16).padStart(2, "0");
|
|
90
|
-
}
|
|
91
|
-
return hex as `0x${string}`;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Converts AddressInput to hex string for RPC calls.
|
|
96
|
-
* Handles both branded AddressType (Uint8Array) and plain hex strings.
|
|
97
|
-
*/
|
|
98
|
-
const toAddressHex = (input: AddressInput): `0x${string}` => {
|
|
99
|
-
if (typeof input === "string") return input as `0x${string}`;
|
|
100
|
-
return bytesToHex(input) as `0x${string}`;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Converts HashInput to hex string for RPC calls.
|
|
105
|
-
* Handles both branded HashType (Uint8Array) and plain hex strings.
|
|
106
|
-
*/
|
|
107
|
-
const toHashHex = (input: HashInput): `0x${string}` => {
|
|
108
|
-
if (typeof input === "string") return input as `0x${string}`;
|
|
109
|
-
return bytesToHex(input) as `0x${string}`;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Parses a hex quantity into bigint with consistent provider error handling.
|
|
114
|
-
*/
|
|
115
|
-
const parseHexToBigInt = (input: {
|
|
116
|
-
method: string;
|
|
117
|
-
response: string;
|
|
118
|
-
params?: unknown[];
|
|
119
|
-
}) =>
|
|
120
|
-
Effect.try({
|
|
121
|
-
try: () => BigInt(input.response),
|
|
122
|
-
catch: (error) =>
|
|
123
|
-
new ProviderResponseError(
|
|
124
|
-
input,
|
|
125
|
-
`Invalid hex response from RPC: ${input.response}`,
|
|
126
|
-
{ cause: error instanceof Error ? error : undefined },
|
|
127
|
-
),
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
type LogFilterParams = {
|
|
131
|
-
address?: AddressInput | AddressInput[];
|
|
132
|
-
topics?: (HashInput | HashInput[] | null)[];
|
|
133
|
-
fromBlock?: BlockTag;
|
|
134
|
-
toBlock?: BlockTag;
|
|
135
|
-
blockHash?: HashInput;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
type RpcLogFilterParams = {
|
|
139
|
-
address?: `0x${string}` | `0x${string}`[];
|
|
140
|
-
topics?: (string | string[] | null)[];
|
|
141
|
-
fromBlock?: BlockTag;
|
|
142
|
-
toBlock?: BlockTag;
|
|
143
|
-
blockHash?: `0x${string}`;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Formats log filter parameters for JSON-RPC submission.
|
|
148
|
-
*/
|
|
149
|
-
const formatLogFilterParams = (filter: LogFilterParams): RpcLogFilterParams => {
|
|
150
|
-
const params: RpcLogFilterParams = {};
|
|
151
|
-
if (filter.address) {
|
|
152
|
-
params.address = Array.isArray(filter.address)
|
|
153
|
-
? filter.address.map(toAddressHex)
|
|
154
|
-
: toAddressHex(filter.address);
|
|
155
|
-
}
|
|
156
|
-
if (filter.topics) {
|
|
157
|
-
params.topics = filter.topics.map((topic) => {
|
|
158
|
-
if (topic === null) return null;
|
|
159
|
-
if (Array.isArray(topic)) return topic.map(toHashHex);
|
|
160
|
-
return toHashHex(topic);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
if (filter.fromBlock !== undefined) params.fromBlock = filter.fromBlock;
|
|
164
|
-
if (filter.toBlock !== undefined) params.toBlock = filter.toBlock;
|
|
165
|
-
if (filter.blockHash !== undefined) {
|
|
166
|
-
params.blockHash = toHashHex(filter.blockHash) as `0x${string}`;
|
|
167
|
-
}
|
|
168
|
-
return params;
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* RPC call object for eth_call, eth_estimateGas, etc.
|
|
173
|
-
* All values are hex-encoded strings per JSON-RPC spec.
|
|
174
|
-
*/
|
|
175
|
-
type RpcCallObject = {
|
|
176
|
-
from?: `0x${string}`;
|
|
177
|
-
to?: `0x${string}`;
|
|
178
|
-
data?: `0x${string}`;
|
|
179
|
-
value?: `0x${string}`;
|
|
180
|
-
gas?: `0x${string}`;
|
|
181
|
-
gasPrice?: `0x${string}`;
|
|
182
|
-
maxFeePerGas?: `0x${string}`;
|
|
183
|
-
maxPriorityFeePerGas?: `0x${string}`;
|
|
184
|
-
nonce?: `0x${string}`;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
type RpcAccessList = Array<{
|
|
188
|
-
address: `0x${string}`;
|
|
189
|
-
storageKeys: Array<`0x${string}`>;
|
|
190
|
-
}>;
|
|
191
|
-
|
|
192
|
-
type RpcTransactionObject = RpcCallObject & {
|
|
193
|
-
to?: `0x${string}` | null;
|
|
194
|
-
accessList?: RpcAccessList;
|
|
195
|
-
chainId?: `0x${string}`;
|
|
196
|
-
type?: `0x${string}`;
|
|
197
|
-
maxFeePerBlobGas?: `0x${string}`;
|
|
198
|
-
blobVersionedHashes?: readonly `0x${string}`[];
|
|
199
|
-
};
|
|
11
|
+
import { ProviderService } from "./ProviderService.js";
|
|
200
12
|
|
|
201
13
|
/**
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* Converts bigint values to hex strings and filters out undefined fields
|
|
206
|
-
* to create a valid JSON-RPC call object.
|
|
207
|
-
*
|
|
208
|
-
* @param tx - The call request to format
|
|
209
|
-
* @returns Formatted object with hex-encoded values
|
|
210
|
-
*
|
|
211
|
-
* @internal
|
|
14
|
+
* Live implementation layer for ProviderService.
|
|
15
|
+
* Provides the minimal request method that all free functions use.
|
|
16
|
+
* Requires TransportService to be provided.
|
|
212
17
|
*/
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const formatAccessList = (accessList: AccessListInput): RpcAccessList =>
|
|
224
|
-
accessList.map((entry) => ({
|
|
225
|
-
address: toAddressHex(entry.address),
|
|
226
|
-
storageKeys: entry.storageKeys,
|
|
227
|
-
}));
|
|
228
|
-
|
|
229
|
-
const formatTransactionRequest = (
|
|
230
|
-
tx: RpcTransactionRequest,
|
|
231
|
-
): RpcTransactionObject => {
|
|
232
|
-
const formatted: RpcTransactionObject = {};
|
|
233
|
-
formatted.from = toAddressHex(tx.from);
|
|
234
|
-
if (tx.to !== undefined) {
|
|
235
|
-
if (tx.to !== null) {
|
|
236
|
-
formatted.to = toAddressHex(tx.to);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (tx.data) formatted.data = tx.data;
|
|
240
|
-
if (tx.value !== undefined) formatted.value = `0x${tx.value.toString(16)}`;
|
|
241
|
-
if (tx.gas !== undefined) formatted.gas = `0x${tx.gas.toString(16)}`;
|
|
242
|
-
if (tx.gasPrice !== undefined) {
|
|
243
|
-
formatted.gasPrice = `0x${tx.gasPrice.toString(16)}`;
|
|
244
|
-
}
|
|
245
|
-
if (tx.maxFeePerGas !== undefined) {
|
|
246
|
-
formatted.maxFeePerGas = `0x${tx.maxFeePerGas.toString(16)}`;
|
|
247
|
-
}
|
|
248
|
-
if (tx.maxPriorityFeePerGas !== undefined) {
|
|
249
|
-
formatted.maxPriorityFeePerGas = `0x${tx.maxPriorityFeePerGas.toString(16)}`;
|
|
250
|
-
}
|
|
251
|
-
if (tx.nonce !== undefined) {
|
|
252
|
-
formatted.nonce = `0x${tx.nonce.toString(16)}`;
|
|
253
|
-
}
|
|
254
|
-
if (tx.accessList !== undefined) {
|
|
255
|
-
formatted.accessList = formatAccessList(tx.accessList);
|
|
256
|
-
}
|
|
257
|
-
if (tx.chainId !== undefined) {
|
|
258
|
-
formatted.chainId = `0x${tx.chainId.toString(16)}`;
|
|
259
|
-
}
|
|
260
|
-
if (tx.type !== undefined) {
|
|
261
|
-
formatted.type = `0x${tx.type.toString(16)}`;
|
|
262
|
-
}
|
|
263
|
-
if (tx.maxFeePerBlobGas !== undefined) {
|
|
264
|
-
formatted.maxFeePerBlobGas = `0x${tx.maxFeePerBlobGas.toString(16)}`;
|
|
265
|
-
}
|
|
266
|
-
if (tx.blobVersionedHashes !== undefined) {
|
|
267
|
-
formatted.blobVersionedHashes = tx.blobVersionedHashes;
|
|
268
|
-
}
|
|
269
|
-
return formatted;
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
const toIndexHex = (index: TransactionIndexInput): `0x${string}` => {
|
|
273
|
-
if (typeof index === "string") return index as `0x${string}`;
|
|
274
|
-
const value = typeof index === "number" ? BigInt(index) : index;
|
|
275
|
-
return `0x${value.toString(16)}` as `0x${string}`;
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
const formatSimulateV1Payload = (payload: SimulateV1Payload) => ({
|
|
279
|
-
...payload,
|
|
280
|
-
blockStateCalls: payload.blockStateCalls.map((block) => ({
|
|
281
|
-
...block,
|
|
282
|
-
blockOverrides: block.blockOverrides
|
|
283
|
-
? formatBlockOverrides(block.blockOverrides)
|
|
284
|
-
: undefined,
|
|
285
|
-
stateOverrides: block.stateOverrides
|
|
286
|
-
? formatStateOverride(block.stateOverrides)
|
|
287
|
-
: undefined,
|
|
288
|
-
calls: block.calls.map(formatCallRequest),
|
|
289
|
-
})),
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* RPC state override object for eth_call.
|
|
294
|
-
*/
|
|
295
|
-
type RpcAccountStateOverride = {
|
|
296
|
-
balance?: `0x${string}`;
|
|
297
|
-
nonce?: `0x${string}`;
|
|
298
|
-
code?: `0x${string}`;
|
|
299
|
-
state?: Record<`0x${string}`, `0x${string}`>;
|
|
300
|
-
stateDiff?: Record<`0x${string}`, `0x${string}`>;
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
type RpcStateOverride = Record<`0x${string}`, RpcAccountStateOverride>;
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Formats a StateOverride for JSON-RPC submission.
|
|
307
|
-
*
|
|
308
|
-
* @description
|
|
309
|
-
* Converts bigint values to hex strings for balance and nonce.
|
|
310
|
-
*
|
|
311
|
-
* @param stateOverride - The state override to format
|
|
312
|
-
* @returns Formatted object with hex-encoded values
|
|
313
|
-
*
|
|
314
|
-
* @internal
|
|
315
|
-
*/
|
|
316
|
-
const formatStateOverride = (
|
|
317
|
-
stateOverride: StateOverride,
|
|
318
|
-
): RpcStateOverride => {
|
|
319
|
-
const result: RpcStateOverride = {};
|
|
320
|
-
for (const [address, override] of Object.entries(stateOverride)) {
|
|
321
|
-
const formattedOverride: RpcAccountStateOverride = {};
|
|
322
|
-
if (override.balance !== undefined) {
|
|
323
|
-
formattedOverride.balance = `0x${override.balance.toString(16)}`;
|
|
324
|
-
}
|
|
325
|
-
if (override.nonce !== undefined) {
|
|
326
|
-
formattedOverride.nonce = `0x${override.nonce.toString(16)}`;
|
|
327
|
-
}
|
|
328
|
-
if (override.code !== undefined) {
|
|
329
|
-
formattedOverride.code = override.code;
|
|
330
|
-
}
|
|
331
|
-
if (override.state !== undefined) {
|
|
332
|
-
formattedOverride.state = override.state;
|
|
333
|
-
}
|
|
334
|
-
if (override.stateDiff !== undefined) {
|
|
335
|
-
formattedOverride.stateDiff = override.stateDiff;
|
|
336
|
-
}
|
|
337
|
-
result[address as `0x${string}`] = formattedOverride;
|
|
338
|
-
}
|
|
339
|
-
return result;
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* RPC block overrides object for eth_call.
|
|
344
|
-
*/
|
|
345
|
-
type RpcBlockOverrides = {
|
|
346
|
-
number?: `0x${string}`;
|
|
347
|
-
difficulty?: `0x${string}`;
|
|
348
|
-
time?: `0x${string}`;
|
|
349
|
-
gasLimit?: `0x${string}`;
|
|
350
|
-
coinbase?: `0x${string}`;
|
|
351
|
-
random?: `0x${string}`;
|
|
352
|
-
baseFee?: `0x${string}`;
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Formats BlockOverrides for JSON-RPC submission.
|
|
357
|
-
*
|
|
358
|
-
* @param blockOverrides - The block overrides to format
|
|
359
|
-
* @returns Formatted object with hex-encoded values
|
|
360
|
-
*
|
|
361
|
-
* @internal
|
|
362
|
-
*/
|
|
363
|
-
const formatBlockOverrides = (
|
|
364
|
-
blockOverrides: BlockOverrides,
|
|
365
|
-
): RpcBlockOverrides => {
|
|
366
|
-
const result: RpcBlockOverrides = {};
|
|
367
|
-
if (blockOverrides.number !== undefined) {
|
|
368
|
-
result.number = `0x${blockOverrides.number.toString(16)}`;
|
|
369
|
-
}
|
|
370
|
-
if (blockOverrides.difficulty !== undefined) {
|
|
371
|
-
result.difficulty = `0x${blockOverrides.difficulty.toString(16)}`;
|
|
372
|
-
}
|
|
373
|
-
if (blockOverrides.time !== undefined) {
|
|
374
|
-
result.time = `0x${blockOverrides.time.toString(16)}`;
|
|
375
|
-
}
|
|
376
|
-
if (blockOverrides.gasLimit !== undefined) {
|
|
377
|
-
result.gasLimit = `0x${blockOverrides.gasLimit.toString(16)}`;
|
|
378
|
-
}
|
|
379
|
-
if (blockOverrides.coinbase !== undefined) {
|
|
380
|
-
result.coinbase = toAddressHex(blockOverrides.coinbase) as `0x${string}`;
|
|
381
|
-
}
|
|
382
|
-
if (blockOverrides.random !== undefined) {
|
|
383
|
-
result.random = toHashHex(blockOverrides.random) as `0x${string}`;
|
|
384
|
-
}
|
|
385
|
-
if (blockOverrides.baseFee !== undefined) {
|
|
386
|
-
result.baseFee = `0x${blockOverrides.baseFee.toString(16)}`;
|
|
387
|
-
}
|
|
388
|
-
return result;
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Live implementation of the provider layer.
|
|
393
|
-
*
|
|
394
|
-
* @description
|
|
395
|
-
* Provides a concrete implementation of ProviderService that translates
|
|
396
|
-
* method calls to JSON-RPC requests via TransportService.
|
|
397
|
-
*
|
|
398
|
-
* This layer:
|
|
399
|
-
* - Converts method parameters to JSON-RPC format
|
|
400
|
-
* - Handles response parsing (hex to bigint, etc.)
|
|
401
|
-
* - Surfaces TransportError and provider-specific errors
|
|
402
|
-
*
|
|
403
|
-
* Requires TransportService in context.
|
|
404
|
-
*
|
|
405
|
-
* @since 0.0.1
|
|
406
|
-
*
|
|
407
|
-
* @example Basic usage
|
|
408
|
-
* ```typescript
|
|
409
|
-
* import { Effect } from 'effect'
|
|
410
|
-
* import { Provider, ProviderService, HttpTransport } from 'voltaire-effect'
|
|
411
|
-
*
|
|
412
|
-
* const program = Effect.gen(function* () {
|
|
413
|
-
* const provider = yield* ProviderService
|
|
414
|
-
* const blockNum = yield* provider.getBlockNumber()
|
|
415
|
-
* return blockNum
|
|
416
|
-
* }).pipe(
|
|
417
|
-
* Effect.provide(Provider),
|
|
418
|
-
* Effect.provide(HttpTransport('https://mainnet.infura.io/v3/YOUR_KEY'))
|
|
419
|
-
* )
|
|
420
|
-
*
|
|
421
|
-
* await Effect.runPromise(program)
|
|
422
|
-
* ```
|
|
423
|
-
*
|
|
424
|
-
* @example Composing with other layers
|
|
425
|
-
* ```typescript
|
|
426
|
-
* import { Effect, Layer } from 'effect'
|
|
427
|
-
* import {
|
|
428
|
-
* Provider,
|
|
429
|
-
* ProviderService,
|
|
430
|
-
* HttpTransport
|
|
431
|
-
* } from 'voltaire-effect'
|
|
432
|
-
*
|
|
433
|
-
* // Create a composed layer for reuse
|
|
434
|
-
* const MainnetProvider = Provider.pipe(
|
|
435
|
-
* Layer.provide(HttpTransport('https://mainnet.infura.io/v3/YOUR_KEY'))
|
|
436
|
-
* )
|
|
437
|
-
*
|
|
438
|
-
* const program = Effect.gen(function* () {
|
|
439
|
-
* const provider = yield* ProviderService
|
|
440
|
-
* return yield* provider.getBlockNumber()
|
|
441
|
-
* }).pipe(Effect.provide(MainnetProvider))
|
|
442
|
-
* ```
|
|
443
|
-
*
|
|
444
|
-
* @example Testing with TestTransport
|
|
445
|
-
* ```typescript
|
|
446
|
-
* import { Effect } from 'effect'
|
|
447
|
-
* import { Provider, ProviderService, TestTransport } from 'voltaire-effect'
|
|
448
|
-
*
|
|
449
|
-
* const testTransport = TestTransport({
|
|
450
|
-
* 'eth_blockNumber': '0x1234',
|
|
451
|
-
* 'eth_chainId': '0x1'
|
|
452
|
-
* })
|
|
453
|
-
*
|
|
454
|
-
* const program = Effect.gen(function* () {
|
|
455
|
-
* const provider = yield* ProviderService
|
|
456
|
-
* return yield* provider.getBlockNumber()
|
|
457
|
-
* }).pipe(
|
|
458
|
-
* Effect.provide(Provider),
|
|
459
|
-
* Effect.provide(testTransport)
|
|
460
|
-
* )
|
|
461
|
-
*
|
|
462
|
-
* const result = await Effect.runPromise(program)
|
|
463
|
-
* expect(result).toBe(0x1234n)
|
|
464
|
-
* ```
|
|
465
|
-
*
|
|
466
|
-
* @see {@link ProviderService} - The service interface
|
|
467
|
-
* @see {@link TransportService} - Required transport dependency
|
|
468
|
-
* @see {@link HttpTransport} - HTTP transport implementation
|
|
469
|
-
* @see {@link TestTransport} - Mock transport for testing
|
|
470
|
-
*/
|
|
471
|
-
export const Provider: Layer.Layer<ProviderService, never, TransportService> =
|
|
472
|
-
Layer.effect(
|
|
473
|
-
ProviderService,
|
|
474
|
-
Effect.gen(function* () {
|
|
475
|
-
const transport = yield* TransportService;
|
|
476
|
-
|
|
477
|
-
const request = <T>(method: string, params?: unknown[]) =>
|
|
478
|
-
transport.request<T>(method, params).pipe(
|
|
479
|
-
Effect.mapError(
|
|
480
|
-
(error) =>
|
|
481
|
-
new TransportError(error.input, error.message, {
|
|
482
|
-
cause: error,
|
|
483
|
-
context: { method, params },
|
|
484
|
-
}),
|
|
485
|
-
),
|
|
486
|
-
);
|
|
487
|
-
|
|
488
|
-
return {
|
|
489
|
-
getBlockNumber: () =>
|
|
490
|
-
request<string>("eth_blockNumber").pipe(
|
|
491
|
-
Effect.flatMap((hex) =>
|
|
492
|
-
parseHexToBigInt({ method: "eth_blockNumber", response: hex }),
|
|
493
|
-
),
|
|
494
|
-
),
|
|
495
|
-
|
|
496
|
-
getBlock: (args?: GetBlockArgs) => {
|
|
497
|
-
const method = args?.blockHash
|
|
498
|
-
? "eth_getBlockByHash"
|
|
499
|
-
: "eth_getBlockByNumber";
|
|
500
|
-
let blockId: string;
|
|
501
|
-
if (args?.blockHash) {
|
|
502
|
-
blockId = toHashHex(args.blockHash);
|
|
503
|
-
} else if (args?.blockNumber !== undefined) {
|
|
504
|
-
blockId = `0x${args.blockNumber.toString(16)}`;
|
|
505
|
-
} else {
|
|
506
|
-
blockId = args?.blockTag ?? "latest";
|
|
507
|
-
}
|
|
508
|
-
const params = [blockId, args?.includeTransactions ?? false];
|
|
509
|
-
return request<BlockType | null>(method, params).pipe(
|
|
510
|
-
Effect.flatMap((block) =>
|
|
511
|
-
block
|
|
512
|
-
? Effect.succeed(block)
|
|
513
|
-
: Effect.fail(
|
|
514
|
-
new ProviderNotFoundError(
|
|
515
|
-
{ method, params, args },
|
|
516
|
-
"Block not found",
|
|
517
|
-
{ resource: "block" },
|
|
518
|
-
),
|
|
519
|
-
),
|
|
520
|
-
),
|
|
521
|
-
);
|
|
522
|
-
},
|
|
523
|
-
|
|
524
|
-
getBlockReceipts: (args?: GetBlockReceiptsArgs) => {
|
|
525
|
-
const method = "eth_getBlockReceipts";
|
|
526
|
-
let blockId: string;
|
|
527
|
-
if (args?.blockHash) {
|
|
528
|
-
blockId = toHashHex(args.blockHash);
|
|
529
|
-
} else if (args?.blockNumber !== undefined) {
|
|
530
|
-
blockId = `0x${args.blockNumber.toString(16)}`;
|
|
531
|
-
} else {
|
|
532
|
-
blockId = args?.blockTag ?? "latest";
|
|
533
|
-
}
|
|
534
|
-
const params = [blockId];
|
|
535
|
-
return request<ReceiptType[] | null>(method, params).pipe(
|
|
536
|
-
Effect.flatMap((receipts) =>
|
|
537
|
-
receipts
|
|
538
|
-
? Effect.succeed(receipts)
|
|
539
|
-
: Effect.fail(
|
|
540
|
-
new ProviderNotFoundError(
|
|
541
|
-
{ method, params, args },
|
|
542
|
-
"Block receipts not found",
|
|
543
|
-
{ resource: "blockReceipts" },
|
|
544
|
-
),
|
|
545
|
-
),
|
|
546
|
-
),
|
|
547
|
-
);
|
|
548
|
-
},
|
|
549
|
-
|
|
550
|
-
getBlockTransactionCount: (args) => {
|
|
551
|
-
const method = args.blockHash
|
|
552
|
-
? "eth_getBlockTransactionCountByHash"
|
|
553
|
-
: "eth_getBlockTransactionCountByNumber";
|
|
554
|
-
const params = args.blockHash
|
|
555
|
-
? [toHashHex(args.blockHash)]
|
|
556
|
-
: [args.blockTag ?? "latest"];
|
|
557
|
-
return request<string>(method, params).pipe(
|
|
558
|
-
Effect.flatMap((hex) =>
|
|
559
|
-
parseHexToBigInt({ method, params, response: hex }),
|
|
560
|
-
),
|
|
561
|
-
);
|
|
562
|
-
},
|
|
563
|
-
|
|
564
|
-
getBalance: (address: AddressInput, blockTag: BlockTag = "latest") =>
|
|
565
|
-
request<string>("eth_getBalance", [
|
|
566
|
-
toAddressHex(address),
|
|
567
|
-
blockTag,
|
|
568
|
-
]).pipe(
|
|
569
|
-
Effect.flatMap((hex) =>
|
|
570
|
-
parseHexToBigInt({
|
|
571
|
-
method: "eth_getBalance",
|
|
572
|
-
params: [toAddressHex(address), blockTag],
|
|
573
|
-
response: hex,
|
|
574
|
-
}),
|
|
575
|
-
),
|
|
576
|
-
),
|
|
577
|
-
|
|
578
|
-
getTransactionCount: (
|
|
579
|
-
address: AddressInput,
|
|
580
|
-
blockTag: BlockTag = "latest",
|
|
581
|
-
) =>
|
|
582
|
-
request<string>("eth_getTransactionCount", [
|
|
583
|
-
toAddressHex(address),
|
|
584
|
-
blockTag,
|
|
585
|
-
]).pipe(
|
|
586
|
-
Effect.flatMap((hex) =>
|
|
587
|
-
parseHexToBigInt({
|
|
588
|
-
method: "eth_getTransactionCount",
|
|
589
|
-
params: [toAddressHex(address), blockTag],
|
|
590
|
-
response: hex,
|
|
591
|
-
}),
|
|
592
|
-
),
|
|
593
|
-
),
|
|
594
|
-
|
|
595
|
-
getCode: (address: AddressInput, blockTag: BlockTag = "latest") =>
|
|
596
|
-
request<`0x${string}`>("eth_getCode", [
|
|
597
|
-
toAddressHex(address),
|
|
598
|
-
blockTag,
|
|
599
|
-
]),
|
|
600
|
-
|
|
601
|
-
getStorageAt: (
|
|
602
|
-
address: AddressInput,
|
|
603
|
-
slot: HashInput,
|
|
604
|
-
blockTag: BlockTag = "latest",
|
|
605
|
-
) =>
|
|
606
|
-
request<`0x${string}`>("eth_getStorageAt", [
|
|
607
|
-
toAddressHex(address),
|
|
608
|
-
toHashHex(slot),
|
|
609
|
-
blockTag,
|
|
610
|
-
]),
|
|
611
|
-
|
|
612
|
-
getTransaction: (hash: HashInput) =>
|
|
613
|
-
request<TransactionType | null>("eth_getTransactionByHash", [
|
|
614
|
-
toHashHex(hash),
|
|
615
|
-
]).pipe(
|
|
616
|
-
Effect.flatMap((tx) =>
|
|
617
|
-
tx
|
|
618
|
-
? Effect.succeed(tx)
|
|
619
|
-
: Effect.fail(
|
|
620
|
-
new ProviderNotFoundError(
|
|
621
|
-
{ hash },
|
|
622
|
-
"Transaction not found",
|
|
623
|
-
{ resource: "transaction" },
|
|
624
|
-
),
|
|
625
|
-
),
|
|
626
|
-
),
|
|
627
|
-
),
|
|
628
|
-
|
|
629
|
-
getTransactionByBlockHashAndIndex: (
|
|
630
|
-
blockHash: HashInput,
|
|
631
|
-
index: TransactionIndexInput,
|
|
632
|
-
) =>
|
|
633
|
-
request<TransactionType | null>(
|
|
634
|
-
"eth_getTransactionByBlockHashAndIndex",
|
|
635
|
-
[toHashHex(blockHash), toIndexHex(index)],
|
|
636
|
-
).pipe(
|
|
637
|
-
Effect.flatMap((tx) =>
|
|
638
|
-
tx
|
|
639
|
-
? Effect.succeed(tx)
|
|
640
|
-
: Effect.fail(
|
|
641
|
-
new ProviderNotFoundError(
|
|
642
|
-
{ blockHash, index },
|
|
643
|
-
"Transaction not found",
|
|
644
|
-
{ resource: "transaction" },
|
|
645
|
-
),
|
|
646
|
-
),
|
|
647
|
-
),
|
|
648
|
-
),
|
|
649
|
-
|
|
650
|
-
getTransactionByBlockNumberAndIndex: (
|
|
651
|
-
blockTag: BlockTag | bigint,
|
|
652
|
-
index: TransactionIndexInput,
|
|
653
|
-
) => {
|
|
654
|
-
const blockRef =
|
|
655
|
-
typeof blockTag === "bigint"
|
|
656
|
-
? (`0x${blockTag.toString(16)}` as const)
|
|
657
|
-
: blockTag;
|
|
658
|
-
return request<TransactionType | null>(
|
|
659
|
-
"eth_getTransactionByBlockNumberAndIndex",
|
|
660
|
-
[blockRef, toIndexHex(index)],
|
|
661
|
-
).pipe(
|
|
662
|
-
Effect.flatMap((tx) =>
|
|
663
|
-
tx
|
|
664
|
-
? Effect.succeed(tx)
|
|
665
|
-
: Effect.fail(
|
|
666
|
-
new ProviderNotFoundError(
|
|
667
|
-
{ blockTag, index },
|
|
668
|
-
"Transaction not found",
|
|
669
|
-
{ resource: "transaction" },
|
|
670
|
-
),
|
|
671
|
-
),
|
|
672
|
-
),
|
|
673
|
-
);
|
|
674
|
-
},
|
|
675
|
-
|
|
676
|
-
getTransactionReceipt: (hash: HashInput) =>
|
|
677
|
-
request<ReceiptType | null>("eth_getTransactionReceipt", [
|
|
678
|
-
toHashHex(hash),
|
|
679
|
-
]).pipe(
|
|
680
|
-
Effect.flatMap((receipt) =>
|
|
681
|
-
receipt
|
|
682
|
-
? Effect.succeed(receipt)
|
|
683
|
-
: Effect.fail(
|
|
684
|
-
new ProviderNotFoundError(
|
|
685
|
-
{ hash },
|
|
686
|
-
"Transaction receipt not found (pending or unknown)",
|
|
687
|
-
{ resource: "receipt" },
|
|
688
|
-
),
|
|
689
|
-
),
|
|
690
|
-
),
|
|
691
|
-
),
|
|
692
|
-
|
|
693
|
-
waitForTransactionReceipt: (
|
|
694
|
-
hash: HashInput,
|
|
695
|
-
opts?: {
|
|
696
|
-
confirmations?: number;
|
|
697
|
-
timeout?: number;
|
|
698
|
-
pollingInterval?: number;
|
|
699
|
-
},
|
|
700
|
-
) =>
|
|
701
|
-
Effect.gen(function* () {
|
|
702
|
-
const confirmations = opts?.confirmations ?? 1;
|
|
703
|
-
const pollingInterval = opts?.pollingInterval ?? 1000;
|
|
704
|
-
if (confirmations < 1) {
|
|
705
|
-
return yield* Effect.fail(
|
|
706
|
-
new ProviderValidationError(
|
|
707
|
-
{ hash, confirmations },
|
|
708
|
-
"Confirmations must be at least 1",
|
|
709
|
-
),
|
|
710
|
-
);
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
const timeout = opts?.timeout ?? 60000;
|
|
714
|
-
const hashHex = toHashHex(hash);
|
|
715
|
-
|
|
716
|
-
const pollReceipt = request<ReceiptType | null>(
|
|
717
|
-
"eth_getTransactionReceipt",
|
|
718
|
-
[hashHex],
|
|
719
|
-
).pipe(
|
|
720
|
-
Effect.flatMap((receipt) =>
|
|
721
|
-
receipt
|
|
722
|
-
? Effect.succeed(receipt)
|
|
723
|
-
: Effect.fail(
|
|
724
|
-
new ProviderReceiptPendingError(
|
|
725
|
-
{ hash },
|
|
726
|
-
"Transaction pending",
|
|
727
|
-
),
|
|
728
|
-
),
|
|
729
|
-
),
|
|
730
|
-
);
|
|
731
|
-
|
|
732
|
-
const receipt = yield* pollReceipt.pipe(
|
|
733
|
-
Effect.retry(
|
|
734
|
-
Schedule.spaced(Duration.millis(pollingInterval)).pipe(
|
|
735
|
-
Schedule.intersect(
|
|
736
|
-
Schedule.recurUpTo(Duration.millis(timeout)),
|
|
737
|
-
),
|
|
738
|
-
Schedule.whileInput(
|
|
739
|
-
(e) =>
|
|
740
|
-
(e as ProviderReceiptPendingError)._tag ===
|
|
741
|
-
"ProviderReceiptPendingError",
|
|
742
|
-
),
|
|
743
|
-
),
|
|
744
|
-
),
|
|
745
|
-
Effect.timeoutFail({
|
|
746
|
-
duration: Duration.millis(timeout),
|
|
747
|
-
onTimeout: () =>
|
|
748
|
-
new ProviderTimeoutError(
|
|
749
|
-
{ hash, timeout },
|
|
750
|
-
"Timeout waiting for transaction receipt",
|
|
751
|
-
{ timeoutMs: timeout },
|
|
752
|
-
),
|
|
753
|
-
}),
|
|
754
|
-
);
|
|
755
|
-
|
|
756
|
-
if (confirmations <= 1) {
|
|
757
|
-
return receipt;
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
const receiptBlockNumber = yield* parseHexToBigInt({
|
|
761
|
-
method: "eth_getTransactionReceipt",
|
|
762
|
-
params: [hashHex],
|
|
763
|
-
response: receipt.blockNumber,
|
|
764
|
-
});
|
|
765
|
-
const targetBlock = receiptBlockNumber + BigInt(confirmations - 1);
|
|
766
|
-
|
|
767
|
-
const pollConfirmations = Effect.gen(function* () {
|
|
768
|
-
const currentBlockHex = yield* request<string>("eth_blockNumber");
|
|
769
|
-
const currentBlock = yield* parseHexToBigInt({
|
|
770
|
-
method: "eth_blockNumber",
|
|
771
|
-
response: currentBlockHex,
|
|
772
|
-
});
|
|
773
|
-
if (currentBlock >= targetBlock) {
|
|
774
|
-
return receipt;
|
|
775
|
-
}
|
|
776
|
-
return yield* Effect.fail(
|
|
777
|
-
new ProviderConfirmationsPendingError(
|
|
778
|
-
{ hash, currentBlock, targetBlock },
|
|
779
|
-
"Waiting for confirmations",
|
|
780
|
-
),
|
|
781
|
-
);
|
|
782
|
-
});
|
|
783
|
-
|
|
784
|
-
return yield* pollConfirmations.pipe(
|
|
785
|
-
Effect.retry(
|
|
786
|
-
Schedule.spaced(Duration.millis(pollingInterval)).pipe(
|
|
787
|
-
Schedule.intersect(
|
|
788
|
-
Schedule.recurUpTo(Duration.millis(timeout)),
|
|
789
|
-
),
|
|
790
|
-
Schedule.whileInput(
|
|
791
|
-
(e) =>
|
|
792
|
-
(e as ProviderConfirmationsPendingError)._tag ===
|
|
793
|
-
"ProviderConfirmationsPendingError",
|
|
794
|
-
),
|
|
795
|
-
),
|
|
796
|
-
),
|
|
797
|
-
Effect.timeoutFail({
|
|
798
|
-
duration: Duration.millis(timeout),
|
|
799
|
-
onTimeout: () =>
|
|
800
|
-
new ProviderTimeoutError(
|
|
801
|
-
{ hash, timeout },
|
|
802
|
-
"Timeout waiting for confirmations",
|
|
803
|
-
{ timeoutMs: timeout },
|
|
804
|
-
),
|
|
805
|
-
}),
|
|
806
|
-
);
|
|
807
|
-
}),
|
|
808
|
-
|
|
809
|
-
call: (
|
|
810
|
-
tx: CallRequest,
|
|
811
|
-
blockTag: BlockTag = "latest",
|
|
812
|
-
stateOverride?: StateOverride,
|
|
813
|
-
blockOverrides?: BlockOverrides,
|
|
814
|
-
) => {
|
|
815
|
-
const params: unknown[] = [formatCallRequest(tx), blockTag];
|
|
816
|
-
if (stateOverride !== undefined) {
|
|
817
|
-
params.push(formatStateOverride(stateOverride));
|
|
818
|
-
}
|
|
819
|
-
if (blockOverrides !== undefined) {
|
|
820
|
-
// Ensure stateOverride slot is filled when blockOverrides present
|
|
821
|
-
if (stateOverride === undefined) {
|
|
822
|
-
params.push({});
|
|
823
|
-
}
|
|
824
|
-
params.push(formatBlockOverrides(blockOverrides));
|
|
825
|
-
}
|
|
826
|
-
return request<`0x${string}`>("eth_call", params);
|
|
827
|
-
},
|
|
828
|
-
|
|
829
|
-
estimateGas: (
|
|
830
|
-
tx: CallRequest,
|
|
831
|
-
blockTag: BlockTag = "latest",
|
|
832
|
-
stateOverride?: StateOverride,
|
|
833
|
-
) => {
|
|
834
|
-
const params: unknown[] = [formatCallRequest(tx), blockTag];
|
|
835
|
-
if (stateOverride !== undefined) {
|
|
836
|
-
params.push(formatStateOverride(stateOverride));
|
|
837
|
-
}
|
|
838
|
-
return request<string>("eth_estimateGas", params).pipe(
|
|
839
|
-
Effect.flatMap((hex) =>
|
|
840
|
-
parseHexToBigInt({
|
|
841
|
-
method: "eth_estimateGas",
|
|
842
|
-
params,
|
|
843
|
-
response: hex,
|
|
844
|
-
}),
|
|
845
|
-
),
|
|
846
|
-
);
|
|
847
|
-
},
|
|
848
|
-
|
|
849
|
-
createAccessList: (tx: CallRequest) =>
|
|
850
|
-
request<AccessListType>("eth_createAccessList", [
|
|
851
|
-
formatCallRequest(tx),
|
|
852
|
-
]),
|
|
853
|
-
|
|
854
|
-
simulateV1: (
|
|
855
|
-
payload: SimulateV1Payload,
|
|
856
|
-
blockTag: BlockTag = "latest",
|
|
857
|
-
) =>
|
|
858
|
-
request<SimulateV1Result>("eth_simulateV1", [
|
|
859
|
-
formatSimulateV1Payload(payload),
|
|
860
|
-
blockTag,
|
|
861
|
-
]),
|
|
862
|
-
|
|
863
|
-
simulateV2: <TResult = SimulateV2Result>(
|
|
864
|
-
payload: SimulateV2Payload,
|
|
865
|
-
blockTag?: BlockTag,
|
|
866
|
-
) => {
|
|
867
|
-
const params =
|
|
868
|
-
blockTag === undefined ? [payload] : [payload, blockTag];
|
|
869
|
-
return request<TResult>("eth_simulateV2", params);
|
|
870
|
-
},
|
|
871
|
-
|
|
872
|
-
getLogs: (filter: LogFilter) => {
|
|
873
|
-
const params = formatLogFilterParams(filter);
|
|
874
|
-
return request<LogType[]>("eth_getLogs", [params]);
|
|
875
|
-
},
|
|
876
|
-
createEventFilter: (filter: EventFilter = {}) => {
|
|
877
|
-
const params = formatLogFilterParams(filter);
|
|
878
|
-
return request<FilterId>("eth_newFilter", [params]);
|
|
879
|
-
},
|
|
880
|
-
createBlockFilter: () => request<FilterId>("eth_newBlockFilter"),
|
|
881
|
-
createPendingTransactionFilter: () =>
|
|
882
|
-
request<FilterId>("eth_newPendingTransactionFilter"),
|
|
883
|
-
getFilterChanges: (filterId: FilterId) =>
|
|
884
|
-
request<FilterChanges>("eth_getFilterChanges", [filterId]),
|
|
885
|
-
getFilterLogs: (filterId: FilterId) =>
|
|
886
|
-
request<LogType[]>("eth_getFilterLogs", [filterId]),
|
|
887
|
-
uninstallFilter: (filterId: FilterId) =>
|
|
888
|
-
request<boolean>("eth_uninstallFilter", [filterId]),
|
|
889
|
-
|
|
890
|
-
getChainId: () =>
|
|
891
|
-
request<string>("eth_chainId").pipe(
|
|
892
|
-
Effect.flatMap((hex) =>
|
|
893
|
-
parseHexToBigInt({ method: "eth_chainId", response: hex }).pipe(
|
|
894
|
-
Effect.flatMap((value) => {
|
|
895
|
-
if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
896
|
-
return Effect.fail(
|
|
897
|
-
new ProviderValidationError(
|
|
898
|
-
{ method: "eth_chainId", value },
|
|
899
|
-
`Chain ID ${value} exceeds safe integer range`,
|
|
900
|
-
),
|
|
901
|
-
);
|
|
902
|
-
}
|
|
903
|
-
return Effect.succeed(Number(value));
|
|
904
|
-
}),
|
|
905
|
-
),
|
|
906
|
-
),
|
|
907
|
-
),
|
|
908
|
-
|
|
909
|
-
getGasPrice: () =>
|
|
910
|
-
request<string>("eth_gasPrice").pipe(
|
|
911
|
-
Effect.flatMap((hex) =>
|
|
912
|
-
parseHexToBigInt({ method: "eth_gasPrice", response: hex }),
|
|
913
|
-
),
|
|
914
|
-
),
|
|
915
|
-
|
|
916
|
-
getMaxPriorityFeePerGas: () =>
|
|
917
|
-
request<string>("eth_maxPriorityFeePerGas").pipe(
|
|
918
|
-
Effect.flatMap((hex) =>
|
|
919
|
-
parseHexToBigInt({
|
|
920
|
-
method: "eth_maxPriorityFeePerGas",
|
|
921
|
-
response: hex,
|
|
922
|
-
}),
|
|
923
|
-
),
|
|
924
|
-
),
|
|
925
|
-
|
|
926
|
-
getFeeHistory: (
|
|
927
|
-
blockCount: number,
|
|
928
|
-
newestBlock: BlockTag,
|
|
929
|
-
rewardPercentiles: number[],
|
|
930
|
-
) =>
|
|
931
|
-
Effect.gen(function* () {
|
|
932
|
-
if (!Number.isInteger(blockCount) || blockCount < 1) {
|
|
933
|
-
return yield* Effect.fail(
|
|
934
|
-
new ProviderValidationError(
|
|
935
|
-
{ blockCount },
|
|
936
|
-
"blockCount must be a positive integer",
|
|
937
|
-
),
|
|
938
|
-
);
|
|
939
|
-
}
|
|
940
|
-
for (const p of rewardPercentiles) {
|
|
941
|
-
if (p < 0 || p > 100) {
|
|
942
|
-
return yield* Effect.fail(
|
|
943
|
-
new ProviderValidationError(
|
|
944
|
-
{ rewardPercentiles },
|
|
945
|
-
"rewardPercentiles values must be between 0 and 100",
|
|
946
|
-
),
|
|
947
|
-
);
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
for (let i = 1; i < rewardPercentiles.length; i++) {
|
|
951
|
-
if (rewardPercentiles[i] < rewardPercentiles[i - 1]) {
|
|
952
|
-
return yield* Effect.fail(
|
|
953
|
-
new ProviderValidationError(
|
|
954
|
-
{ rewardPercentiles },
|
|
955
|
-
"rewardPercentiles should be sorted in ascending order",
|
|
956
|
-
),
|
|
957
|
-
);
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
return yield* request<FeeHistoryType>("eth_feeHistory", [
|
|
961
|
-
`0x${blockCount.toString(16)}`,
|
|
962
|
-
newestBlock,
|
|
963
|
-
rewardPercentiles,
|
|
964
|
-
]);
|
|
965
|
-
}),
|
|
966
|
-
|
|
967
|
-
getSyncing: () => request<SyncingStatus>("eth_syncing"),
|
|
968
|
-
|
|
969
|
-
getAccounts: () => request<`0x${string}`[]>("eth_accounts"),
|
|
970
|
-
|
|
971
|
-
getCoinbase: () => request<`0x${string}`>("eth_coinbase"),
|
|
972
|
-
|
|
973
|
-
netVersion: () => request<string>("net_version"),
|
|
974
|
-
|
|
975
|
-
getProtocolVersion: () => request<string>("eth_protocolVersion"),
|
|
976
|
-
|
|
977
|
-
getMining: () => request<boolean>("eth_mining"),
|
|
978
|
-
|
|
979
|
-
getHashrate: () =>
|
|
980
|
-
request<string>("eth_hashrate").pipe(
|
|
981
|
-
Effect.flatMap((hex) =>
|
|
982
|
-
parseHexToBigInt({ method: "eth_hashrate", response: hex }),
|
|
983
|
-
),
|
|
984
|
-
),
|
|
985
|
-
|
|
986
|
-
getWork: () => request<WorkResult>("eth_getWork"),
|
|
987
|
-
|
|
988
|
-
submitWork: (
|
|
989
|
-
nonce: `0x${string}`,
|
|
990
|
-
powHash: `0x${string}`,
|
|
991
|
-
mixDigest: `0x${string}`,
|
|
992
|
-
) => request<boolean>("eth_submitWork", [nonce, powHash, mixDigest]),
|
|
993
|
-
|
|
994
|
-
submitHashrate: (hashrate: `0x${string}`, id: `0x${string}`) =>
|
|
995
|
-
request<boolean>("eth_submitHashrate", [hashrate, id]),
|
|
996
|
-
|
|
997
|
-
watchBlocks: <TInclude extends BlockInclude = "header">(
|
|
998
|
-
options?: WatchOptions<TInclude>,
|
|
999
|
-
): Stream.Stream<BlockStreamEvent<TInclude>, WatchBlocksError> =>
|
|
1000
|
-
Stream.unwrap(
|
|
1001
|
-
Effect.gen(function* () {
|
|
1002
|
-
const runtime = yield* Effect.runtime<never>();
|
|
1003
|
-
const provider = {
|
|
1004
|
-
request: async ({
|
|
1005
|
-
method,
|
|
1006
|
-
params,
|
|
1007
|
-
}: {
|
|
1008
|
-
method: string;
|
|
1009
|
-
params?: unknown[];
|
|
1010
|
-
}) =>
|
|
1011
|
-
Runtime.runPromise(runtime)(
|
|
1012
|
-
transport.request(method, params),
|
|
1013
|
-
),
|
|
1014
|
-
on: () => {},
|
|
1015
|
-
removeListener: () => {},
|
|
1016
|
-
};
|
|
1017
|
-
const coreStream = CoreBlockStream({ provider: provider as any });
|
|
1018
|
-
const cleanup = () => {
|
|
1019
|
-
(coreStream as unknown as { destroy?: () => void }).destroy?.();
|
|
1020
|
-
};
|
|
1021
|
-
return Stream.acquireRelease(
|
|
1022
|
-
Effect.sync(() => coreStream.watch(options)),
|
|
1023
|
-
() => Effect.sync(cleanup),
|
|
1024
|
-
).pipe(
|
|
1025
|
-
Stream.flatMap((generator) =>
|
|
1026
|
-
Stream.fromAsyncIterable(
|
|
1027
|
-
{ [Symbol.asyncIterator]: () => generator },
|
|
1028
|
-
(error) =>
|
|
1029
|
-
error instanceof TransportError
|
|
1030
|
-
? error
|
|
1031
|
-
: new ProviderStreamError(
|
|
1032
|
-
{ method: "watchBlocks", options },
|
|
1033
|
-
error instanceof Error
|
|
1034
|
-
? error.message
|
|
1035
|
-
: "BlockStream error",
|
|
1036
|
-
{ cause: error instanceof Error ? error : undefined },
|
|
1037
|
-
),
|
|
1038
|
-
),
|
|
1039
|
-
),
|
|
1040
|
-
);
|
|
1041
|
-
}),
|
|
1042
|
-
),
|
|
1043
|
-
|
|
1044
|
-
backfillBlocks: <TInclude extends BlockInclude = "header">(
|
|
1045
|
-
options: BackfillOptions<TInclude>,
|
|
1046
|
-
): Stream.Stream<BlocksEvent<TInclude>, BackfillBlocksError> =>
|
|
1047
|
-
Stream.unwrap(
|
|
1048
|
-
Effect.gen(function* () {
|
|
1049
|
-
const runtime = yield* Effect.runtime<never>();
|
|
1050
|
-
const provider = {
|
|
1051
|
-
request: async ({
|
|
1052
|
-
method,
|
|
1053
|
-
params,
|
|
1054
|
-
}: {
|
|
1055
|
-
method: string;
|
|
1056
|
-
params?: unknown[];
|
|
1057
|
-
}) =>
|
|
1058
|
-
Runtime.runPromise(runtime)(
|
|
1059
|
-
transport.request(method, params),
|
|
1060
|
-
),
|
|
1061
|
-
on: () => {},
|
|
1062
|
-
removeListener: () => {},
|
|
1063
|
-
};
|
|
1064
|
-
const coreStream = CoreBlockStream({ provider: provider as any });
|
|
1065
|
-
const cleanup = () => {
|
|
1066
|
-
(coreStream as unknown as { destroy?: () => void }).destroy?.();
|
|
1067
|
-
};
|
|
1068
|
-
return Stream.acquireRelease(
|
|
1069
|
-
Effect.sync(() => coreStream.backfill(options)),
|
|
1070
|
-
() => Effect.sync(cleanup),
|
|
1071
|
-
).pipe(
|
|
1072
|
-
Stream.flatMap((generator) =>
|
|
1073
|
-
Stream.fromAsyncIterable(
|
|
1074
|
-
{ [Symbol.asyncIterator]: () => generator },
|
|
1075
|
-
(error) =>
|
|
1076
|
-
error instanceof TransportError
|
|
1077
|
-
? error
|
|
1078
|
-
: new ProviderStreamError(
|
|
1079
|
-
{ method: "backfillBlocks", options },
|
|
1080
|
-
error instanceof Error
|
|
1081
|
-
? error.message
|
|
1082
|
-
: "BlockStream error",
|
|
1083
|
-
{ cause: error instanceof Error ? error : undefined },
|
|
1084
|
-
),
|
|
1085
|
-
),
|
|
1086
|
-
),
|
|
1087
|
-
);
|
|
1088
|
-
}),
|
|
1089
|
-
),
|
|
1090
|
-
|
|
1091
|
-
subscribe: (subscription: string, params: readonly unknown[] = []) =>
|
|
1092
|
-
request<`0x${string}`>("eth_subscribe", [subscription, ...params]),
|
|
1093
|
-
|
|
1094
|
-
unsubscribe: (subscriptionId: `0x${string}`) =>
|
|
1095
|
-
request<boolean>("eth_unsubscribe", [subscriptionId]),
|
|
1096
|
-
|
|
1097
|
-
sendRawTransaction: (signedTx: HexType | `0x${string}`) =>
|
|
1098
|
-
request<`0x${string}`>("eth_sendRawTransaction", [signedTx]),
|
|
1099
|
-
|
|
1100
|
-
sendTransaction: (tx: RpcTransactionRequest) =>
|
|
1101
|
-
request<`0x${string}`>("eth_sendTransaction", [
|
|
1102
|
-
formatTransactionRequest(tx),
|
|
1103
|
-
]),
|
|
1104
|
-
|
|
1105
|
-
sign: (address: AddressInput, message: HexType | `0x${string}`) =>
|
|
1106
|
-
request<`0x${string}`>("eth_sign", [toAddressHex(address), message]),
|
|
1107
|
-
|
|
1108
|
-
signTransaction: (tx: RpcTransactionRequest) =>
|
|
1109
|
-
request<unknown>("eth_signTransaction", [
|
|
1110
|
-
formatTransactionRequest(tx),
|
|
1111
|
-
]),
|
|
1112
|
-
|
|
1113
|
-
getUncle: (args: GetUncleArgs, uncleIndex: `0x${string}`) => {
|
|
1114
|
-
const method = args.blockHash
|
|
1115
|
-
? "eth_getUncleByBlockHashAndIndex"
|
|
1116
|
-
: "eth_getUncleByBlockNumberAndIndex";
|
|
1117
|
-
const params = args.blockHash
|
|
1118
|
-
? [toHashHex(args.blockHash), uncleIndex]
|
|
1119
|
-
: [args.blockTag ?? "latest", uncleIndex];
|
|
1120
|
-
return request<UncleBlockType | null>(method, params).pipe(
|
|
1121
|
-
Effect.flatMap((uncle) =>
|
|
1122
|
-
uncle
|
|
1123
|
-
? Effect.succeed(uncle)
|
|
1124
|
-
: Effect.fail(
|
|
1125
|
-
new ProviderNotFoundError(
|
|
1126
|
-
{ args, method, params },
|
|
1127
|
-
"Uncle block not found",
|
|
1128
|
-
{ resource: "uncle" },
|
|
1129
|
-
),
|
|
1130
|
-
),
|
|
1131
|
-
),
|
|
1132
|
-
);
|
|
1133
|
-
},
|
|
1134
|
-
|
|
1135
|
-
getUncleCount: (args: GetUncleCountArgs) => {
|
|
1136
|
-
const method = args.blockHash
|
|
1137
|
-
? "eth_getUncleCountByBlockHash"
|
|
1138
|
-
: "eth_getUncleCountByBlockNumber";
|
|
1139
|
-
const params = args.blockHash
|
|
1140
|
-
? [toHashHex(args.blockHash)]
|
|
1141
|
-
: [args.blockTag ?? "latest"];
|
|
1142
|
-
return request<string>(method, params).pipe(
|
|
1143
|
-
Effect.flatMap((hex) =>
|
|
1144
|
-
parseHexToBigInt({ method, params, response: hex }),
|
|
1145
|
-
),
|
|
1146
|
-
);
|
|
1147
|
-
},
|
|
1148
|
-
|
|
1149
|
-
getProof: (
|
|
1150
|
-
address: AddressInput,
|
|
1151
|
-
storageKeys: HashInput[],
|
|
1152
|
-
blockTag: BlockTag = "latest",
|
|
1153
|
-
) =>
|
|
1154
|
-
request<ProofType>("eth_getProof", [
|
|
1155
|
-
toAddressHex(address),
|
|
1156
|
-
storageKeys.map((key) =>
|
|
1157
|
-
typeof key === "string" ? key : toHashHex(key),
|
|
1158
|
-
),
|
|
1159
|
-
blockTag,
|
|
1160
|
-
]),
|
|
1161
|
-
|
|
1162
|
-
getBlobBaseFee: () =>
|
|
1163
|
-
getBlobBaseFeeEffect().pipe(
|
|
1164
|
-
Effect.provideService(TransportService, transport),
|
|
1165
|
-
),
|
|
1166
|
-
|
|
1167
|
-
getTransactionConfirmations: (hash: HashInput) =>
|
|
1168
|
-
Effect.gen(function* () {
|
|
1169
|
-
const receipt = yield* request<ReceiptType | null>(
|
|
1170
|
-
"eth_getTransactionReceipt",
|
|
1171
|
-
[toHashHex(hash)],
|
|
1172
|
-
);
|
|
1173
|
-
if (!receipt) {
|
|
1174
|
-
return 0n;
|
|
1175
|
-
}
|
|
1176
|
-
const currentBlock = yield* request<string>("eth_blockNumber");
|
|
1177
|
-
const receiptBlock = yield* parseHexToBigInt({
|
|
1178
|
-
method: "eth_getTransactionReceipt",
|
|
1179
|
-
params: [toHashHex(hash)],
|
|
1180
|
-
response: receipt.blockNumber,
|
|
1181
|
-
});
|
|
1182
|
-
const current = yield* parseHexToBigInt({
|
|
1183
|
-
method: "eth_blockNumber",
|
|
1184
|
-
response: currentBlock,
|
|
1185
|
-
});
|
|
1186
|
-
if (current < receiptBlock) {
|
|
1187
|
-
return 0n;
|
|
1188
|
-
}
|
|
1189
|
-
return current - receiptBlock + 1n;
|
|
1190
|
-
}),
|
|
1191
|
-
};
|
|
1192
|
-
}),
|
|
1193
|
-
);
|
|
18
|
+
export const Provider = Layer.effect(
|
|
19
|
+
ProviderService,
|
|
20
|
+
Effect.gen(function* () {
|
|
21
|
+
const transport = yield* TransportService;
|
|
22
|
+
return {
|
|
23
|
+
request: <T>(method: string, params?: unknown[]) =>
|
|
24
|
+
transport.request<T>(method, params),
|
|
25
|
+
};
|
|
26
|
+
}),
|
|
27
|
+
);
|