ox 0.0.1 → 0.1.0
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/Abi/package.json +6 -0
- package/Abi.ts +163 -0
- package/AbiConstructor/package.json +6 -0
- package/AbiConstructor.ts +413 -0
- package/AbiError/package.json +6 -0
- package/AbiError.ts +719 -0
- package/AbiEvent/package.json +6 -0
- package/AbiEvent.ts +1284 -0
- package/AbiFunction/package.json +6 -0
- package/AbiFunction.ts +813 -0
- package/AbiItem/package.json +6 -0
- package/AbiItem.ts +779 -0
- package/AbiParameters/package.json +6 -0
- package/AbiParameters.ts +712 -0
- package/AccessList/package.json +6 -0
- package/AccessList.ts +124 -0
- package/AccountProof/package.json +6 -0
- package/AccountProof.ts +35 -0
- package/Address/package.json +6 -0
- package/Address.ts +359 -0
- package/AesGcm/package.json +6 -0
- package/AesGcm.ts +220 -0
- package/Authorization/package.json +6 -0
- package/Authorization.ts +639 -0
- package/Base58/package.json +6 -0
- package/Base58.ts +180 -0
- package/Base64/package.json +6 -0
- package/Base64.ts +333 -0
- package/Blobs/package.json +6 -0
- package/Blobs.ts +982 -0
- package/Block/package.json +6 -0
- package/Block.ts +317 -0
- package/Bloom/package.json +6 -0
- package/Bloom.ts +80 -0
- package/Bls/package.json +6 -0
- package/Bls.ts +496 -0
- package/BlsPoint/package.json +6 -0
- package/BlsPoint.ts +232 -0
- package/Bytes/package.json +6 -0
- package/Bytes.ts +963 -0
- package/CHANGELOG.md +7 -0
- package/Caches/package.json +6 -0
- package/Caches.ts +21 -0
- package/ContractAddress/package.json +6 -0
- package/ContractAddress.ts +181 -0
- package/Ens/package.json +6 -0
- package/Ens.ts +116 -0
- package/Errors/package.json +6 -0
- package/Errors.ts +95 -0
- package/Fee/package.json +6 -0
- package/Fee.ts +57 -0
- package/Filter/package.json +6 -0
- package/Filter.ts +144 -0
- package/Hash/package.json +6 -0
- package/Hash.ts +210 -0
- package/HdKey/package.json +6 -0
- package/HdKey.ts +175 -0
- package/Hex/package.json +6 -0
- package/Hex.ts +1040 -0
- package/Json/package.json +6 -0
- package/Json.ts +84 -0
- package/Kzg/package.json +6 -0
- package/Kzg.ts +51 -0
- package/LICENSE +21 -0
- package/Log/package.json +6 -0
- package/Log.ts +248 -0
- package/Mnemonic/package.json +6 -0
- package/Mnemonic.ts +249 -0
- package/P256/package.json +6 -0
- package/P256.ts +230 -0
- package/PersonalMessage/package.json +6 -0
- package/PersonalMessage.ts +70 -0
- package/Provider/package.json +6 -0
- package/Provider.ts +354 -0
- package/PublicKey/package.json +6 -0
- package/PublicKey.ts +545 -0
- package/README.md +75 -26
- package/Rlp/package.json +6 -0
- package/Rlp.ts +390 -0
- package/RpcRequest/package.json +6 -0
- package/RpcRequest.ts +192 -0
- package/RpcResponse/package.json +6 -0
- package/RpcResponse.ts +389 -0
- package/RpcSchema/package.json +6 -0
- package/RpcSchema.ts +273 -0
- package/RpcTransport/package.json +6 -0
- package/RpcTransport.ts +198 -0
- package/Secp256k1/package.json +6 -0
- package/Secp256k1.ts +304 -0
- package/Signature/package.json +6 -0
- package/Signature.ts +909 -0
- package/Siwe/package.json +6 -0
- package/Siwe.ts +516 -0
- package/Solidity/package.json +6 -0
- package/Solidity.ts +109 -0
- package/Transaction/package.json +6 -0
- package/Transaction.ts +429 -0
- package/TransactionEnvelope/package.json +6 -0
- package/TransactionEnvelope.ts +205 -0
- package/TransactionEnvelopeEip1559/package.json +6 -0
- package/TransactionEnvelopeEip1559.ts +656 -0
- package/TransactionEnvelopeEip2930/package.json +6 -0
- package/TransactionEnvelopeEip2930.ts +624 -0
- package/TransactionEnvelopeEip4844/package.json +6 -0
- package/TransactionEnvelopeEip4844.ts +764 -0
- package/TransactionEnvelopeEip7702/package.json +6 -0
- package/TransactionEnvelopeEip7702.ts +639 -0
- package/TransactionEnvelopeLegacy/package.json +6 -0
- package/TransactionEnvelopeLegacy.ts +674 -0
- package/TransactionReceipt/package.json +6 -0
- package/TransactionReceipt.ts +341 -0
- package/TransactionRequest/package.json +6 -0
- package/TransactionRequest.ts +151 -0
- package/TypedData/package.json +6 -0
- package/TypedData.ts +931 -0
- package/ValidatorData/package.json +6 -0
- package/ValidatorData.ts +87 -0
- package/Value/package.json +6 -0
- package/Value.ts +242 -0
- package/WebAuthnP256/package.json +6 -0
- package/WebAuthnP256.ts +803 -0
- package/WebCryptoP256/package.json +6 -0
- package/WebCryptoP256.ts +190 -0
- package/Withdrawal/package.json +6 -0
- package/Withdrawal.ts +95 -0
- package/_cjs/Abi.js +17 -0
- package/_cjs/Abi.js.map +1 -0
- package/_cjs/AbiConstructor.js +42 -0
- package/_cjs/AbiConstructor.js.map +1 -0
- package/_cjs/AbiError.js +98 -0
- package/_cjs/AbiError.js.map +1 -0
- package/_cjs/AbiEvent.js +338 -0
- package/_cjs/AbiEvent.js.map +1 -0
- package/_cjs/AbiFunction.js +85 -0
- package/_cjs/AbiFunction.js.map +1 -0
- package/_cjs/AbiItem.js +180 -0
- package/_cjs/AbiItem.js.map +1 -0
- package/_cjs/AbiParameters.js +229 -0
- package/_cjs/AbiParameters.js.map +1 -0
- package/_cjs/AccessList.js +51 -0
- package/_cjs/AccessList.js.map +1 -0
- package/_cjs/AccountProof.js +3 -0
- package/_cjs/AccountProof.js.map +1 -0
- package/_cjs/Address.js +121 -0
- package/_cjs/Address.js.map +1 -0
- package/_cjs/AesGcm.js +55 -0
- package/_cjs/AesGcm.js.map +1 -0
- package/_cjs/Authorization.js +99 -0
- package/_cjs/Authorization.js.map +1 -0
- package/_cjs/Base58.js +52 -0
- package/_cjs/Base58.js.map +1 -0
- package/_cjs/Base64.js +76 -0
- package/_cjs/Base64.js.map +1 -0
- package/_cjs/Blobs.js +255 -0
- package/_cjs/Blobs.js.map +1 -0
- package/_cjs/Block.js +87 -0
- package/_cjs/Block.js.map +1 -0
- package/_cjs/Bloom.js +23 -0
- package/_cjs/Bloom.js.map +1 -0
- package/_cjs/Bls.js +79 -0
- package/_cjs/Bls.js.map +1 -0
- package/_cjs/BlsPoint.js +32 -0
- package/_cjs/BlsPoint.js.map +1 -0
- package/_cjs/Bytes.js +279 -0
- package/_cjs/Bytes.js.map +1 -0
- package/_cjs/Caches.js +14 -0
- package/_cjs/Caches.js.map +1 -0
- package/_cjs/ContractAddress.js +39 -0
- package/_cjs/ContractAddress.js.map +1 -0
- package/_cjs/Ens.js +37 -0
- package/_cjs/Ens.js.map +1 -0
- package/_cjs/Errors.js +99 -0
- package/_cjs/Errors.js.map +1 -0
- package/_cjs/Fee.js +3 -0
- package/_cjs/Fee.js.map +1 -0
- package/_cjs/Filter.js +43 -0
- package/_cjs/Filter.js.map +1 -0
- package/_cjs/Hash.js +40 -0
- package/_cjs/Hash.js.map +1 -0
- package/_cjs/HdKey.js +30 -0
- package/_cjs/HdKey.js.map +1 -0
- package/_cjs/Hex.js +324 -0
- package/_cjs/Hex.js.map +1 -0
- package/_cjs/Json.js +25 -0
- package/_cjs/Json.js.map +1 -0
- package/_cjs/Kzg.js +14 -0
- package/_cjs/Kzg.js.map +1 -0
- package/_cjs/Log.js +35 -0
- package/_cjs/Log.js.map +1 -0
- package/_cjs/Mnemonic.js +56 -0
- package/_cjs/Mnemonic.js.map +1 -0
- package/_cjs/P256.js +52 -0
- package/_cjs/P256.js.map +1 -0
- package/_cjs/PersonalMessage.js +16 -0
- package/_cjs/PersonalMessage.js.map +1 -0
- package/_cjs/Provider.js +90 -0
- package/_cjs/Provider.js.map +1 -0
- package/_cjs/PublicKey.js +192 -0
- package/_cjs/PublicKey.js.map +1 -0
- package/_cjs/Rlp.js +179 -0
- package/_cjs/Rlp.js.map +1 -0
- package/_cjs/RpcRequest.js +27 -0
- package/_cjs/RpcRequest.js.map +1 -0
- package/_cjs/RpcResponse.js +368 -0
- package/_cjs/RpcResponse.js.map +1 -0
- package/_cjs/RpcSchema.js +7 -0
- package/_cjs/RpcSchema.js.map +1 -0
- package/_cjs/RpcTransport.js +95 -0
- package/_cjs/RpcTransport.js.map +1 -0
- package/_cjs/Secp256k1.js +57 -0
- package/_cjs/Secp256k1.js.map +1 -0
- package/_cjs/Signature.js +305 -0
- package/_cjs/Signature.js.map +1 -0
- package/_cjs/Siwe.js +231 -0
- package/_cjs/Siwe.js.map +1 -0
- package/_cjs/Solidity.js +104 -0
- package/_cjs/Solidity.js.map +1 -0
- package/_cjs/Transaction.js +106 -0
- package/_cjs/Transaction.js.map +1 -0
- package/_cjs/TransactionEnvelope.js +80 -0
- package/_cjs/TransactionEnvelope.js.map +1 -0
- package/_cjs/TransactionEnvelopeEip1559.js +182 -0
- package/_cjs/TransactionEnvelopeEip1559.js.map +1 -0
- package/_cjs/TransactionEnvelopeEip2930.js +166 -0
- package/_cjs/TransactionEnvelopeEip2930.js.map +1 -0
- package/_cjs/TransactionEnvelopeEip4844.js +224 -0
- package/_cjs/TransactionEnvelopeEip4844.js.map +1 -0
- package/_cjs/TransactionEnvelopeEip7702.js +156 -0
- package/_cjs/TransactionEnvelopeEip7702.js.map +1 -0
- package/_cjs/TransactionEnvelopeLegacy.js +221 -0
- package/_cjs/TransactionEnvelopeLegacy.js.map +1 -0
- package/_cjs/TransactionReceipt.js +76 -0
- package/_cjs/TransactionReceipt.js.map +1 -0
- package/_cjs/TransactionRequest.js +51 -0
- package/_cjs/TransactionRequest.js.map +1 -0
- package/_cjs/TypedData.js +318 -0
- package/_cjs/TypedData.js.map +1 -0
- package/_cjs/ValidatorData.js +16 -0
- package/_cjs/ValidatorData.js.map +1 -0
- package/_cjs/Value.js +96 -0
- package/_cjs/Value.js.map +1 -0
- package/_cjs/WebAuthnP256.js +245 -0
- package/_cjs/WebAuthnP256.js.map +1 -0
- package/_cjs/WebCryptoP256.js +46 -0
- package/_cjs/WebCryptoP256.js.map +1 -0
- package/_cjs/Withdrawal.js +24 -0
- package/_cjs/Withdrawal.js.map +1 -0
- package/_cjs/index.js +66 -0
- package/_cjs/index.js.map +1 -0
- package/_cjs/internal/abi.js +11 -0
- package/_cjs/internal/abi.js.map +1 -0
- package/_cjs/internal/abiConstructor.js +3 -0
- package/_cjs/internal/abiConstructor.js.map +1 -0
- package/_cjs/internal/abiError.js +3 -0
- package/_cjs/internal/abiError.js.map +1 -0
- package/_cjs/internal/abiEvent.js +3 -0
- package/_cjs/internal/abiEvent.js.map +1 -0
- package/_cjs/internal/abiFunction.js +3 -0
- package/_cjs/internal/abiFunction.js.map +1 -0
- package/_cjs/internal/abiItem.js +110 -0
- package/_cjs/internal/abiItem.js.map +1 -0
- package/_cjs/internal/abiParameters.js +376 -0
- package/_cjs/internal/abiParameters.js.map +1 -0
- package/_cjs/internal/base58.js +89 -0
- package/_cjs/internal/base58.js.map +1 -0
- package/_cjs/internal/bytes.js +88 -0
- package/_cjs/internal/bytes.js.map +1 -0
- package/_cjs/internal/cursor.js +210 -0
- package/_cjs/internal/cursor.js.map +1 -0
- package/_cjs/internal/ens.js +43 -0
- package/_cjs/internal/ens.js.map +1 -0
- package/_cjs/internal/errors.js +28 -0
- package/_cjs/internal/errors.js.map +1 -0
- package/_cjs/internal/hdKey.js +19 -0
- package/_cjs/internal/hdKey.js.map +1 -0
- package/_cjs/internal/hex.js +66 -0
- package/_cjs/internal/hex.js.map +1 -0
- package/_cjs/internal/lru.js +34 -0
- package/_cjs/internal/lru.js.map +1 -0
- package/_cjs/internal/mnemonic/wordlists.js +24 -0
- package/_cjs/internal/mnemonic/wordlists.js.map +1 -0
- package/_cjs/internal/promise.js +49 -0
- package/_cjs/internal/promise.js.map +1 -0
- package/_cjs/internal/register.js +3 -0
- package/_cjs/internal/register.js.map +1 -0
- package/_cjs/internal/rpcSchema.js +3 -0
- package/_cjs/internal/rpcSchema.js.map +1 -0
- package/_cjs/internal/rpcSchemas/eth.js +3 -0
- package/_cjs/internal/rpcSchemas/eth.js.map +1 -0
- package/_cjs/internal/rpcSchemas/wallet.js +3 -0
- package/_cjs/internal/rpcSchemas/wallet.js.map +1 -0
- package/_cjs/internal/rpcTransport.js +19 -0
- package/_cjs/internal/rpcTransport.js.map +1 -0
- package/_cjs/internal/types.js +3 -0
- package/_cjs/internal/types.js.map +1 -0
- package/_cjs/internal/uid.js +17 -0
- package/_cjs/internal/uid.js.map +1 -0
- package/_cjs/internal/webauthn.js +28 -0
- package/_cjs/internal/webauthn.js.map +1 -0
- package/_cjs/package.json +1 -0
- package/_cjs/trusted-setups/Paths.js +6 -0
- package/_cjs/trusted-setups/Paths.js.map +1 -0
- package/_cjs/trusted-setups/index.js +5 -0
- package/_cjs/trusted-setups/index.js.map +1 -0
- package/_cjs/trusted-setups/internal/paths.js +11 -0
- package/_cjs/trusted-setups/internal/paths.js.map +1 -0
- package/_cjs/version.js +5 -0
- package/_cjs/version.js.map +1 -0
- package/_cjs/window/index.js +3 -0
- package/_cjs/window/index.js.map +1 -0
- package/_esm/Abi.js +19 -0
- package/_esm/Abi.js.map +1 -0
- package/_esm/AbiConstructor.js +102 -0
- package/_esm/AbiConstructor.js.map +1 -0
- package/_esm/AbiError.js +364 -0
- package/_esm/AbiError.js.map +1 -0
- package/_esm/AbiEvent.js +1038 -0
- package/_esm/AbiEvent.js.map +1 -0
- package/_esm/AbiFunction.js +549 -0
- package/_esm/AbiFunction.js.map +1 -0
- package/_esm/AbiItem.js +574 -0
- package/_esm/AbiItem.js.map +1 -0
- package/_esm/AbiParameters.js +543 -0
- package/_esm/AbiParameters.js.map +1 -0
- package/_esm/AccessList.js +105 -0
- package/_esm/AccessList.js.map +1 -0
- package/_esm/AccountProof.js +2 -0
- package/_esm/AccountProof.js.map +1 -0
- package/_esm/Address.js +268 -0
- package/_esm/Address.js.map +1 -0
- package/_esm/AesGcm.js +124 -0
- package/_esm/AesGcm.js.map +1 -0
- package/_esm/Authorization.js +441 -0
- package/_esm/Authorization.js.map +1 -0
- package/_esm/Base58.js +142 -0
- package/_esm/Base58.js.map +1 -0
- package/_esm/Base64.js +236 -0
- package/_esm/Base64.js.map +1 -0
- package/_esm/Blobs.js +624 -0
- package/_esm/Blobs.js.map +1 -0
- package/_esm/Block.js +177 -0
- package/_esm/Block.js.map +1 -0
- package/_esm/Bloom.js +57 -0
- package/_esm/Bloom.js.map +1 -0
- package/_esm/Bls.js +141 -0
- package/_esm/Bls.js.map +1 -0
- package/_esm/BlsPoint.js +59 -0
- package/_esm/BlsPoint.js.map +1 -0
- package/_esm/Bytes.js +719 -0
- package/_esm/Bytes.js.map +1 -0
- package/_esm/Caches.js +19 -0
- package/_esm/Caches.js.map +1 -0
- package/_esm/ContractAddress.js +110 -0
- package/_esm/ContractAddress.js.map +1 -0
- package/_esm/Ens.js +84 -0
- package/_esm/Ens.js.map +1 -0
- package/_esm/Errors.js +105 -0
- package/_esm/Errors.js.map +1 -0
- package/_esm/Fee.js +2 -0
- package/_esm/Fee.js.map +1 -0
- package/_esm/Filter.js +100 -0
- package/_esm/Filter.js.map +1 -0
- package/_esm/Hash.js +126 -0
- package/_esm/Hash.js.map +1 -0
- package/_esm/HdKey.js +107 -0
- package/_esm/HdKey.js.map +1 -0
- package/_esm/Hex.js +763 -0
- package/_esm/Hex.js.map +1 -0
- package/_esm/Json.js +62 -0
- package/_esm/Json.js.map +1 -0
- package/_esm/Kzg.js +30 -0
- package/_esm/Kzg.js.map +1 -0
- package/_esm/Log.js +181 -0
- package/_esm/Log.js.map +1 -0
- package/_esm/Mnemonic.js +154 -0
- package/_esm/Mnemonic.js.map +1 -0
- package/_esm/P256.js +131 -0
- package/_esm/P256.js.map +1 -0
- package/_esm/PersonalMessage.js +46 -0
- package/_esm/PersonalMessage.js.map +1 -0
- package/_esm/Provider.js +122 -0
- package/_esm/Provider.js.map +1 -0
- package/_esm/PublicKey.js +395 -0
- package/_esm/PublicKey.js.map +1 -0
- package/_esm/Rlp.js +267 -0
- package/_esm/Rlp.js.map +1 -0
- package/_esm/RpcRequest.js +131 -0
- package/_esm/RpcRequest.js.map +1 -0
- package/_esm/RpcResponse.js +457 -0
- package/_esm/RpcResponse.js.map +1 -0
- package/_esm/RpcSchema.js +46 -0
- package/_esm/RpcSchema.js.map +1 -0
- package/_esm/RpcTransport.js +110 -0
- package/_esm/RpcTransport.js.map +1 -0
- package/_esm/Secp256k1.js +173 -0
- package/_esm/Secp256k1.js.map +1 -0
- package/_esm/Signature.js +696 -0
- package/_esm/Signature.js.map +1 -0
- package/_esm/Siwe.js +374 -0
- package/_esm/Siwe.js.map +1 -0
- package/_esm/Solidity.js +104 -0
- package/_esm/Solidity.js.map +1 -0
- package/_esm/Transaction.js +176 -0
- package/_esm/Transaction.js.map +1 -0
- package/_esm/TransactionEnvelope.js +139 -0
- package/_esm/TransactionEnvelope.js.map +1 -0
- package/_esm/TransactionEnvelopeEip1559.js +455 -0
- package/_esm/TransactionEnvelopeEip1559.js.map +1 -0
- package/_esm/TransactionEnvelopeEip2930.js +439 -0
- package/_esm/TransactionEnvelopeEip2930.js.map +1 -0
- package/_esm/TransactionEnvelopeEip4844.js +542 -0
- package/_esm/TransactionEnvelopeEip4844.js.map +1 -0
- package/_esm/TransactionEnvelopeEip7702.js +442 -0
- package/_esm/TransactionEnvelopeEip7702.js.map +1 -0
- package/_esm/TransactionEnvelopeLegacy.js +495 -0
- package/_esm/TransactionEnvelopeLegacy.js.map +1 -0
- package/_esm/TransactionReceipt.js +229 -0
- package/_esm/TransactionReceipt.js.map +1 -0
- package/_esm/TransactionRequest.js +89 -0
- package/_esm/TransactionRequest.js.map +1 -0
- package/_esm/TypedData.js +635 -0
- package/_esm/TypedData.js.map +1 -0
- package/_esm/ValidatorData.js +52 -0
- package/_esm/ValidatorData.js.map +1 -0
- package/_esm/Value.js +196 -0
- package/_esm/Value.js.map +1 -0
- package/_esm/WebAuthnP256.js +471 -0
- package/_esm/WebAuthnP256.js.map +1 -0
- package/_esm/WebCryptoP256.js +116 -0
- package/_esm/WebCryptoP256.js.map +1 -0
- package/_esm/Withdrawal.js +72 -0
- package/_esm/Withdrawal.js.map +1 -0
- package/_esm/index.js +3366 -0
- package/_esm/index.js.map +1 -0
- package/_esm/internal/abi.js +9 -0
- package/_esm/internal/abi.js.map +1 -0
- package/_esm/internal/abiConstructor.js +2 -0
- package/_esm/internal/abiConstructor.js.map +1 -0
- package/_esm/internal/abiError.js +2 -0
- package/_esm/internal/abiError.js.map +1 -0
- package/_esm/internal/abiEvent.js +2 -0
- package/_esm/internal/abiEvent.js.map +1 -0
- package/_esm/internal/abiFunction.js +2 -0
- package/_esm/internal/abiFunction.js.map +1 -0
- package/_esm/internal/abiItem.js +122 -0
- package/_esm/internal/abiItem.js.map +1 -0
- package/_esm/internal/abiParameters.js +419 -0
- package/_esm/internal/abiParameters.js.map +1 -0
- package/_esm/internal/base58.js +91 -0
- package/_esm/internal/base58.js.map +1 -0
- package/_esm/internal/bytes.js +86 -0
- package/_esm/internal/bytes.js.map +1 -0
- package/_esm/internal/cursor.js +207 -0
- package/_esm/internal/cursor.js.map +1 -0
- package/_esm/internal/ens.js +47 -0
- package/_esm/internal/ens.js.map +1 -0
- package/_esm/internal/errors.js +26 -0
- package/_esm/internal/errors.js.map +1 -0
- package/_esm/internal/hdKey.js +17 -0
- package/_esm/internal/hdKey.js.map +1 -0
- package/_esm/internal/hex.js +64 -0
- package/_esm/internal/hex.js.map +1 -0
- package/_esm/internal/lru.js +36 -0
- package/_esm/internal/lru.js.map +1 -0
- package/_esm/internal/mnemonic/wordlists.js +11 -0
- package/_esm/internal/mnemonic/wordlists.js.map +1 -0
- package/_esm/internal/promise.js +52 -0
- package/_esm/internal/promise.js.map +1 -0
- package/_esm/internal/register.js +2 -0
- package/_esm/internal/register.js.map +1 -0
- package/_esm/internal/rpcSchema.js +2 -0
- package/_esm/internal/rpcSchema.js.map +1 -0
- package/_esm/internal/rpcSchemas/eth.js +2 -0
- package/_esm/internal/rpcSchemas/eth.js.map +1 -0
- package/_esm/internal/rpcSchemas/wallet.js +2 -0
- package/_esm/internal/rpcSchemas/wallet.js.map +1 -0
- package/_esm/internal/rpcTransport.js +20 -0
- package/_esm/internal/rpcTransport.js.map +1 -0
- package/_esm/internal/types.js +2 -0
- package/_esm/internal/types.js.map +1 -0
- package/_esm/internal/uid.js +15 -0
- package/_esm/internal/uid.js.map +1 -0
- package/_esm/internal/webauthn.js +35 -0
- package/_esm/internal/webauthn.js.map +1 -0
- package/_esm/package.json +1 -0
- package/_esm/trusted-setups/Paths.js +3 -0
- package/_esm/trusted-setups/Paths.js.map +1 -0
- package/_esm/trusted-setups/index.js +2 -0
- package/_esm/trusted-setups/index.js.map +1 -0
- package/_esm/trusted-setups/internal/paths.js +12 -0
- package/_esm/trusted-setups/internal/paths.js.map +1 -0
- package/_esm/version.js +3 -0
- package/_esm/version.js.map +1 -0
- package/_esm/window/index.js +2 -0
- package/_esm/window/index.js.map +1 -0
- package/_test/Abi.test-d/package.json +6 -0
- package/_test/AbiConstructor.test-d/package.json +6 -0
- package/_test/AbiError.test-d/package.json +6 -0
- package/_test/AbiEvent.snap-d/package.json +6 -0
- package/_test/AbiEvent.snap-d.ts +329 -0
- package/_test/AbiFunction.snap-d/package.json +6 -0
- package/_test/AbiFunction.snap-d.ts +262 -0
- package/_test/AbiItem.snap-d/package.json +6 -0
- package/_test/AbiItem.snap-d.ts +131 -0
- package/_test/AbiParameters.bench/package.json +6 -0
- package/_test/AbiParameters.snap-d/package.json +6 -0
- package/_test/AbiParameters.snap-d.ts +66 -0
- package/_test/Address.bench/package.json +6 -0
- package/_test/Base58.bench/package.json +6 -0
- package/_test/Hex.bench/package.json +6 -0
- package/_test/Hex.test-d/package.json +6 -0
- package/_test/PublicKey.test-d/package.json +6 -0
- package/_test/Rlp.bench/package.json +6 -0
- package/_test/Rlp.test-d/package.json +6 -0
- package/_test/Signature.snap-d/package.json +6 -0
- package/_test/Signature.snap-d.ts +96 -0
- package/_test/TransactionEnvelopeEip1559.test-d/package.json +6 -0
- package/_test/TransactionEnvelopeEip2930.test-d/package.json +6 -0
- package/_test/TransactionEnvelopeEip4844.test-d/package.json +6 -0
- package/_test/TransactionEnvelopeEip7702.test-d/package.json +6 -0
- package/_test/TransactionEnvelopeLegacy.test-d/package.json +6 -0
- package/_test/TypedData.test-d/package.json +6 -0
- package/_types/Abi.d.ts +137 -0
- package/_types/Abi.d.ts.map +1 -0
- package/_types/AbiConstructor.d.ts +305 -0
- package/_types/AbiConstructor.d.ts.map +1 -0
- package/_types/AbiError.d.ts +522 -0
- package/_types/AbiError.d.ts.map +1 -0
- package/_types/AbiEvent.d.ts +892 -0
- package/_types/AbiEvent.d.ts.map +1 -0
- package/_types/AbiFunction.d.ts +602 -0
- package/_types/AbiFunction.d.ts.map +1 -0
- package/_types/AbiItem.d.ts +544 -0
- package/_types/AbiItem.d.ts.map +1 -0
- package/_types/AbiParameters.d.ts +466 -0
- package/_types/AbiParameters.d.ts.map +1 -0
- package/_types/AccessList.d.ts +83 -0
- package/_types/AccessList.d.ts.map +1 -0
- package/_types/AccountProof.d.ts +32 -0
- package/_types/AccountProof.d.ts.map +1 -0
- package/_types/Address.d.ts +244 -0
- package/_types/Address.d.ts.map +1 -0
- package/_types/AesGcm.d.ts +116 -0
- package/_types/AesGcm.d.ts.map +1 -0
- package/_types/Authorization.d.ts +461 -0
- package/_types/Authorization.d.ts.map +1 -0
- package/_types/Base58.d.ts +131 -0
- package/_types/Base58.d.ts.map +1 -0
- package/_types/Base64.d.ts +244 -0
- package/_types/Base64.d.ts.map +1 -0
- package/_types/Blobs.d.ts +556 -0
- package/_types/Blobs.d.ts.map +1 -0
- package/_types/Block.d.ts +190 -0
- package/_types/Block.d.ts.map +1 -0
- package/_types/Bloom.d.ts +54 -0
- package/_types/Bloom.d.ts.map +1 -0
- package/_types/Bls.d.ts +365 -0
- package/_types/Bls.d.ts.map +1 -0
- package/_types/BlsPoint.d.ts +187 -0
- package/_types/BlsPoint.d.ts.map +1 -0
- package/_types/Bytes.d.ts +674 -0
- package/_types/Bytes.d.ts.map +1 -0
- package/_types/Caches.d.ts +13 -0
- package/_types/Caches.d.ts.map +1 -0
- package/_types/ContractAddress.d.ts +115 -0
- package/_types/ContractAddress.d.ts.map +1 -0
- package/_types/Ens.d.ts +72 -0
- package/_types/Ens.d.ts.map +1 -0
- package/_types/Errors.d.ts +33 -0
- package/_types/Errors.d.ts.map +1 -0
- package/_types/Fee.d.ts +41 -0
- package/_types/Fee.d.ts.map +1 -0
- package/_types/Filter.d.ts +100 -0
- package/_types/Filter.d.ts.map +1 -0
- package/_types/Hash.d.ts +135 -0
- package/_types/Hash.d.ts.map +1 -0
- package/_types/HdKey.d.ts +146 -0
- package/_types/HdKey.d.ts.map +1 -0
- package/_types/Hex.d.ts +711 -0
- package/_types/Hex.d.ts.map +1 -0
- package/_types/Json.d.ts +53 -0
- package/_types/Json.d.ts.map +1 -0
- package/_types/Kzg.d.ts +42 -0
- package/_types/Kzg.d.ts.map +1 -0
- package/_types/Log.d.ts +194 -0
- package/_types/Log.d.ts.map +1 -0
- package/_types/Mnemonic.d.ts +176 -0
- package/_types/Mnemonic.d.ts.map +1 -0
- package/_types/P256.d.ts +207 -0
- package/_types/P256.d.ts.map +1 -0
- package/_types/PersonalMessage.d.ts +49 -0
- package/_types/PersonalMessage.d.ts.map +1 -0
- package/_types/Provider.d.ts +268 -0
- package/_types/Provider.d.ts.map +1 -0
- package/_types/PublicKey.d.ts +327 -0
- package/_types/PublicKey.d.ts.map +1 -0
- package/_types/Rlp.d.ts +153 -0
- package/_types/Rlp.d.ts.map +1 -0
- package/_types/RpcRequest.d.ts +144 -0
- package/_types/RpcRequest.d.ts.map +1 -0
- package/_types/RpcResponse.d.ts +266 -0
- package/_types/RpcResponse.d.ts.map +1 -0
- package/_types/RpcSchema.d.ts +248 -0
- package/_types/RpcSchema.d.ts.map +1 -0
- package/_types/RpcTransport.d.ts +65 -0
- package/_types/RpcTransport.d.ts.map +1 -0
- package/_types/Secp256k1.d.ts +277 -0
- package/_types/Secp256k1.d.ts.map +1 -0
- package/_types/Signature.d.ts +601 -0
- package/_types/Signature.d.ts.map +1 -0
- package/_types/Siwe.d.ts +249 -0
- package/_types/Siwe.d.ts.map +1 -0
- package/_types/Solidity.d.ts +100 -0
- package/_types/Solidity.d.ts.map +1 -0
- package/_types/Transaction.d.ts +235 -0
- package/_types/Transaction.d.ts.map +1 -0
- package/_types/TransactionEnvelope.d.ts +141 -0
- package/_types/TransactionEnvelope.d.ts.map +1 -0
- package/_types/TransactionEnvelopeEip1559.d.ts +367 -0
- package/_types/TransactionEnvelopeEip1559.d.ts.map +1 -0
- package/_types/TransactionEnvelopeEip2930.d.ts +364 -0
- package/_types/TransactionEnvelopeEip2930.d.ts.map +1 -0
- package/_types/TransactionEnvelopeEip4844.d.ts +419 -0
- package/_types/TransactionEnvelopeEip4844.d.ts.map +1 -0
- package/_types/TransactionEnvelopeEip7702.d.ts +377 -0
- package/_types/TransactionEnvelopeEip7702.d.ts.map +1 -0
- package/_types/TransactionEnvelopeLegacy.d.ts +358 -0
- package/_types/TransactionEnvelopeLegacy.d.ts.map +1 -0
- package/_types/TransactionReceipt.d.ts +271 -0
- package/_types/TransactionReceipt.d.ts.map +1 -0
- package/_types/TransactionRequest.d.ts +92 -0
- package/_types/TransactionRequest.d.ts.map +1 -0
- package/_types/TypedData.d.ts +496 -0
- package/_types/TypedData.d.ts.map +1 -0
- package/_types/ValidatorData.d.ts +64 -0
- package/_types/ValidatorData.d.ts.map +1 -0
- package/_types/Value.d.ts +159 -0
- package/_types/Value.d.ts.map +1 -0
- package/_types/WebAuthnP256.d.ts +445 -0
- package/_types/WebAuthnP256.d.ts.map +1 -0
- package/_types/WebCryptoP256.d.ts +119 -0
- package/_types/WebCryptoP256.d.ts.map +1 -0
- package/_types/Withdrawal.d.ts +74 -0
- package/_types/Withdrawal.d.ts.map +1 -0
- package/_types/index.d.ts +3367 -0
- package/_types/index.d.ts.map +1 -0
- package/_types/internal/abi.d.ts +4 -0
- package/_types/internal/abi.d.ts.map +1 -0
- package/_types/internal/abiConstructor.d.ts +11 -0
- package/_types/internal/abiConstructor.d.ts.map +1 -0
- package/_types/internal/abiError.d.ts +11 -0
- package/_types/internal/abiError.d.ts.map +1 -0
- package/_types/internal/abiEvent.d.ts +60 -0
- package/_types/internal/abiEvent.d.ts.map +1 -0
- package/_types/internal/abiFunction.d.ts +11 -0
- package/_types/internal/abiFunction.d.ts.map +1 -0
- package/_types/internal/abiItem.d.ts +100 -0
- package/_types/internal/abiItem.d.ts.map +1 -0
- package/_types/internal/abiParameters.d.ts +169 -0
- package/_types/internal/abiParameters.d.ts.map +1 -0
- package/_types/internal/base58.d.ts +17 -0
- package/_types/internal/base58.d.ts.map +1 -0
- package/_types/internal/bytes.d.ts +52 -0
- package/_types/internal/bytes.d.ts.map +1 -0
- package/_types/internal/cursor.d.ts +70 -0
- package/_types/internal/cursor.d.ts.map +1 -0
- package/_types/internal/ens.d.ts +23 -0
- package/_types/internal/ens.d.ts.map +1 -0
- package/_types/internal/errors.d.ts +7 -0
- package/_types/internal/errors.d.ts.map +1 -0
- package/_types/internal/hdKey.d.ts +10 -0
- package/_types/internal/hdKey.d.ts.map +1 -0
- package/_types/internal/hex.d.ts +39 -0
- package/_types/internal/hex.d.ts.map +1 -0
- package/_types/internal/lru.d.ts +13 -0
- package/_types/internal/lru.d.ts.map +1 -0
- package/_types/internal/mnemonic/wordlists.d.ts +11 -0
- package/_types/internal/mnemonic/wordlists.d.ts.map +1 -0
- package/_types/internal/promise.d.ts +27 -0
- package/_types/internal/promise.d.ts.map +1 -0
- package/_types/internal/register.d.ts +13 -0
- package/_types/internal/register.d.ts.map +1 -0
- package/_types/internal/rpcSchema.d.ts +12 -0
- package/_types/internal/rpcSchema.d.ts.map +1 -0
- package/_types/internal/rpcSchemas/eth.d.ts +718 -0
- package/_types/internal/rpcSchemas/eth.d.ts.map +1 -0
- package/_types/internal/rpcSchemas/wallet.d.ts +416 -0
- package/_types/internal/rpcSchemas/wallet.d.ts.map +1 -0
- package/_types/internal/rpcTransport.d.ts +38 -0
- package/_types/internal/rpcTransport.d.ts.map +1 -0
- package/_types/internal/types.d.ts +284 -0
- package/_types/internal/types.d.ts.map +1 -0
- package/_types/internal/uid.d.ts +3 -0
- package/_types/internal/uid.d.ts.map +1 -0
- package/_types/internal/webauthn.d.ts +127 -0
- package/_types/internal/webauthn.d.ts.map +1 -0
- package/_types/trusted-setups/Paths.d.ts +2 -0
- package/_types/trusted-setups/Paths.d.ts.map +1 -0
- package/_types/trusted-setups/index.d.ts +2 -0
- package/_types/trusted-setups/index.d.ts.map +1 -0
- package/_types/trusted-setups/internal/paths.d.ts +3 -0
- package/_types/trusted-setups/internal/paths.d.ts.map +1 -0
- package/_types/version.d.ts +3 -0
- package/_types/version.d.ts.map +1 -0
- package/_types/window/index.d.ts +7 -0
- package/_types/window/index.d.ts.map +1 -0
- package/index.ts +3427 -0
- package/internal/abi.ts +11 -0
- package/internal/abiConstructor.ts +32 -0
- package/internal/abiError.ts +30 -0
- package/internal/abiEvent.ts +154 -0
- package/internal/abiFunction.ts +32 -0
- package/internal/abiItem.ts +593 -0
- package/internal/abiParameters.ts +741 -0
- package/internal/base58.ts +106 -0
- package/internal/bytes.ts +152 -0
- package/internal/cursor.ts +252 -0
- package/internal/ens.ts +64 -0
- package/internal/errors.ts +26 -0
- package/internal/hdKey.ts +25 -0
- package/internal/hex.ts +123 -0
- package/internal/lru.ts +34 -0
- package/internal/mnemonic/wordlists.ts +10 -0
- package/internal/promise.ts +66 -0
- package/internal/register.ts +15 -0
- package/internal/rpcSchema.ts +20 -0
- package/internal/rpcSchemas/eth.ts +727 -0
- package/internal/rpcSchemas/wallet.ts +428 -0
- package/internal/rpcTransport.ts +74 -0
- package/internal/types.ts +414 -0
- package/internal/uid.ts +15 -0
- package/internal/webauthn.ts +198 -0
- package/package.json +500 -20
- package/trusted-setups/Paths/package.json +6 -0
- package/trusted-setups/Paths.ts +3 -0
- package/trusted-setups/index.ts +1 -0
- package/trusted-setups/internal/paths.ts +13 -0
- package/trusted-setups/internal/setups/mainnet.json +8265 -0
- package/trusted-setups/internal/setups/mainnet.txt +4163 -0
- package/trusted-setups/package.json +6 -0
- package/tsdoc.json +4 -0
- package/version/package.json +6 -0
- package/version.ts +2 -0
- package/window/index.ts +7 -0
- package/window/package.json +6 -0
- package/cl/ansiesc.js +0 -25
- package/cl/deps.js +0 -7
- package/cl/editor.js +0 -141
- package/cl/index.html +0 -19
- package/cl/ox.js +0 -44
- package/cl/socket.io.js +0 -1922
- package/cl/style.css +0 -37
- package/srv/deps.js +0 -88
- package/srv/httpSrv.js +0 -82
- package/srv/ox.js +0 -44
- package/srv/remoteXtermReq.js +0 -70
package/AbiEvent.ts
ADDED
|
@@ -0,0 +1,1284 @@
|
|
|
1
|
+
import * as abitype from 'abitype'
|
|
2
|
+
import type * as Abi from './Abi.js'
|
|
3
|
+
import * as AbiItem from './AbiItem.js'
|
|
4
|
+
import * as AbiParameters from './AbiParameters.js'
|
|
5
|
+
import * as Address from './Address.js'
|
|
6
|
+
import * as Bytes from './Bytes.js'
|
|
7
|
+
import * as Errors from './Errors.js'
|
|
8
|
+
import * as Hash from './Hash.js'
|
|
9
|
+
import * as Hex from './Hex.js'
|
|
10
|
+
import type * as internal from './internal/abiEvent.js'
|
|
11
|
+
import type * as AbiItem_internal from './internal/abiItem.js'
|
|
12
|
+
import * as Cursor from './internal/cursor.js'
|
|
13
|
+
import { prettyPrint } from './internal/errors.js'
|
|
14
|
+
import type { Compute } from './internal/types.js'
|
|
15
|
+
import type { IsNarrowable } from './internal/types.js'
|
|
16
|
+
|
|
17
|
+
/** Root type for an {@link ox#AbiItem.AbiItem} with an `event` type. */
|
|
18
|
+
export type AbiEvent = abitype.AbiEvent & {
|
|
19
|
+
hash?: Hex.Hex | undefined
|
|
20
|
+
overloads?: readonly AbiEvent[] | undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Extracts an {@link ox#AbiEvent.AbiEvent} item from an {@link ox#Abi.Abi}, given a name.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts twoslash
|
|
28
|
+
* import { Abi, AbiEvent } from 'ox'
|
|
29
|
+
*
|
|
30
|
+
* const abi = Abi.from([
|
|
31
|
+
* 'event Foo(string)',
|
|
32
|
+
* 'event Bar(uint256)',
|
|
33
|
+
* ])
|
|
34
|
+
*
|
|
35
|
+
* type Foo = AbiEvent.FromAbi<typeof abi, 'Foo'>
|
|
36
|
+
* // ^?
|
|
37
|
+
*
|
|
38
|
+
*
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
*
|
|
42
|
+
*
|
|
43
|
+
*
|
|
44
|
+
*
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export type FromAbi<
|
|
48
|
+
abi extends Abi.Abi,
|
|
49
|
+
name extends ExtractNames<abi>,
|
|
50
|
+
> = abitype.ExtractAbiEvent<abi, name>
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Extracts the names of all {@link ox#AbiError.AbiError} items in an {@link ox#Abi.Abi}.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts twoslash
|
|
57
|
+
* import { Abi, AbiEvent } from 'ox'
|
|
58
|
+
*
|
|
59
|
+
* const abi = Abi.from([
|
|
60
|
+
* 'event Foo(string)',
|
|
61
|
+
* 'event Bar(uint256)',
|
|
62
|
+
* ])
|
|
63
|
+
*
|
|
64
|
+
* type names = AbiEvent.Name<typeof abi>
|
|
65
|
+
* // ^?
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export type Name<abi extends Abi.Abi | readonly unknown[] = Abi.Abi> =
|
|
69
|
+
abi extends Abi.Abi ? ExtractNames<abi> : string
|
|
70
|
+
|
|
71
|
+
export type ExtractNames<abi extends Abi.Abi> =
|
|
72
|
+
abitype.ExtractAbiEventNames<abi>
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Asserts that the provided arguments match the decoded log arguments.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts twoslash
|
|
79
|
+
* import { AbiEvent } from 'ox'
|
|
80
|
+
*
|
|
81
|
+
* const abiEvent = AbiEvent.from('event Transfer(address indexed from, address indexed to, uint256 value)')
|
|
82
|
+
*
|
|
83
|
+
* const args = AbiEvent.decode(abiEvent, {
|
|
84
|
+
* data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
85
|
+
* topics: [
|
|
86
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
87
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
88
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
89
|
+
* ],
|
|
90
|
+
* })
|
|
91
|
+
*
|
|
92
|
+
* AbiEvent.assertArgs(abiEvent, args, {
|
|
93
|
+
* from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
94
|
+
* to: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
95
|
+
* value: 1n,
|
|
96
|
+
* })
|
|
97
|
+
*
|
|
98
|
+
* // @error: AbiEvent.ArgsMismatchError: Given arguments to not match the arguments decoded from the log.
|
|
99
|
+
* // @error: Event: event Transfer(address indexed from, address indexed to, uint256 value)
|
|
100
|
+
* // @error: Expected Arguments:
|
|
101
|
+
* // @error: from: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac
|
|
102
|
+
* // @error: to: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad
|
|
103
|
+
* // @error: value: 1
|
|
104
|
+
* // @error: Given Arguments:
|
|
105
|
+
* // @error: from: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad
|
|
106
|
+
* // @error: to: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac
|
|
107
|
+
* // @error: value: 1
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @param abiEvent - ABI Event to check.
|
|
111
|
+
* @param args - Decoded arguments.
|
|
112
|
+
* @param matchArgs - The arguments to check.
|
|
113
|
+
*/
|
|
114
|
+
export function assertArgs<const abiEvent extends AbiEvent>(
|
|
115
|
+
abiEvent: abiEvent | AbiEvent,
|
|
116
|
+
args: unknown,
|
|
117
|
+
matchArgs: IsNarrowable<abiEvent, AbiEvent> extends true
|
|
118
|
+
? abiEvent['inputs'] extends readonly []
|
|
119
|
+
? never
|
|
120
|
+
: internal.ParametersToPrimitiveTypes<
|
|
121
|
+
abiEvent['inputs'],
|
|
122
|
+
{ EnableUnion: true; IndexedOnly: false; Required: false }
|
|
123
|
+
>
|
|
124
|
+
: unknown,
|
|
125
|
+
) {
|
|
126
|
+
if (!args || !matchArgs)
|
|
127
|
+
throw new ArgsMismatchError({
|
|
128
|
+
abiEvent,
|
|
129
|
+
expected: args,
|
|
130
|
+
given: matchArgs,
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
function isEqual(
|
|
134
|
+
input: abitype.AbiEventParameter,
|
|
135
|
+
value: unknown,
|
|
136
|
+
arg: unknown,
|
|
137
|
+
) {
|
|
138
|
+
if (input.type === 'address')
|
|
139
|
+
return Address.isEqual(value as Address.Address, arg as Address.Address)
|
|
140
|
+
if (input.type === 'string')
|
|
141
|
+
return Hash.keccak256(Bytes.fromString(value as string)) === arg
|
|
142
|
+
if (input.type === 'bytes') return Hash.keccak256(value as Hex.Hex) === arg
|
|
143
|
+
return value === arg
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (Array.isArray(args) && Array.isArray(matchArgs)) {
|
|
147
|
+
for (const [index, value] of matchArgs.entries()) {
|
|
148
|
+
if (value === null || value === undefined) continue
|
|
149
|
+
const input = abiEvent.inputs[index]
|
|
150
|
+
if (!input)
|
|
151
|
+
throw new InputNotFoundError({
|
|
152
|
+
abiEvent,
|
|
153
|
+
name: `${index}`,
|
|
154
|
+
})
|
|
155
|
+
const value_ = Array.isArray(value) ? value : [value]
|
|
156
|
+
let equal = false
|
|
157
|
+
for (const value of value_) {
|
|
158
|
+
if (isEqual(input, value, args[index])) equal = true
|
|
159
|
+
}
|
|
160
|
+
if (!equal)
|
|
161
|
+
throw new ArgsMismatchError({
|
|
162
|
+
abiEvent,
|
|
163
|
+
expected: args,
|
|
164
|
+
given: matchArgs,
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (
|
|
170
|
+
typeof args === 'object' &&
|
|
171
|
+
!Array.isArray(args) &&
|
|
172
|
+
typeof matchArgs === 'object' &&
|
|
173
|
+
!Array.isArray(matchArgs)
|
|
174
|
+
)
|
|
175
|
+
for (const [key, value] of Object.entries(matchArgs)) {
|
|
176
|
+
if (value === null || value === undefined) continue
|
|
177
|
+
const input = abiEvent.inputs.find((input) => input.name === key)
|
|
178
|
+
if (!input) throw new InputNotFoundError({ abiEvent, name: key })
|
|
179
|
+
const value_ = Array.isArray(value) ? value : [value]
|
|
180
|
+
let equal = false
|
|
181
|
+
for (const value of value_) {
|
|
182
|
+
if (isEqual(input, value, (args as Record<string, unknown>)[key]))
|
|
183
|
+
equal = true
|
|
184
|
+
}
|
|
185
|
+
if (!equal)
|
|
186
|
+
throw new ArgsMismatchError({
|
|
187
|
+
abiEvent,
|
|
188
|
+
expected: args,
|
|
189
|
+
given: matchArgs,
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export declare namespace assertArgs {
|
|
195
|
+
type ErrorType =
|
|
196
|
+
| Address.isEqual.ErrorType
|
|
197
|
+
| Bytes.fromString.ErrorType
|
|
198
|
+
| Hash.keccak256.ErrorType
|
|
199
|
+
| ArgsMismatchError
|
|
200
|
+
| Errors.GlobalErrorType
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
assertArgs.parseError = (error: unknown) =>
|
|
204
|
+
/* v8 ignore next */
|
|
205
|
+
error as assertArgs.ErrorType
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* ABI-Decodes the provided [Log Topics and Data](https://info.etherscan.com/what-is-event-logs/) according to the ABI Event's parameter types (`input`).
|
|
209
|
+
*
|
|
210
|
+
* :::tip
|
|
211
|
+
*
|
|
212
|
+
* This function is typically used to decode an [Event Log](https://info.etherscan.com/what-is-event-logs/) that may be returned from a Log Query (e.g. `eth_getLogs`) or Transaction Receipt.
|
|
213
|
+
*
|
|
214
|
+
* See the [End-to-end Example](#end-to-end).
|
|
215
|
+
*
|
|
216
|
+
* :::
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts twoslash
|
|
220
|
+
* import { AbiEvent } from 'ox'
|
|
221
|
+
*
|
|
222
|
+
* const transfer = AbiEvent.from(
|
|
223
|
+
* 'event Transfer(address indexed from, address indexed to, uint256 value)'
|
|
224
|
+
* )
|
|
225
|
+
*
|
|
226
|
+
* const log = {
|
|
227
|
+
* // ...
|
|
228
|
+
* data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
229
|
+
* topics: [
|
|
230
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
231
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
232
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
233
|
+
* ],
|
|
234
|
+
* } as const
|
|
235
|
+
*
|
|
236
|
+
* const decoded = AbiEvent.decode(transfer, log)
|
|
237
|
+
* // @log: {
|
|
238
|
+
* // @log: from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
239
|
+
* // @log: to: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
240
|
+
* // @log: value: 1n
|
|
241
|
+
* // @log: }
|
|
242
|
+
* ```
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ### End-to-end
|
|
246
|
+
*
|
|
247
|
+
* Below is an end-to-end example of using `AbiEvent.decode` to decode the topics of a `Transfer` event on the [Wagmi Mint Example contract](https://etherscan.io/address/0xfba3912ca04dd458c843e2ee08967fc04f3579c2).
|
|
248
|
+
*
|
|
249
|
+
* ```ts twoslash
|
|
250
|
+
* import 'ox/window'
|
|
251
|
+
* import { AbiEvent, Hex } from 'ox'
|
|
252
|
+
*
|
|
253
|
+
* // 1. Instantiate the `Transfer` ABI Event.
|
|
254
|
+
* const transfer = AbiEvent.from(
|
|
255
|
+
* 'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
256
|
+
* )
|
|
257
|
+
*
|
|
258
|
+
* // 2. Encode the ABI Event into Event Topics.
|
|
259
|
+
* const { topics } = AbiEvent.encode(transfer)
|
|
260
|
+
*
|
|
261
|
+
* // 3. Query for events matching the encoded Topics.
|
|
262
|
+
* const logs = await window.ethereum!.request({
|
|
263
|
+
* method: 'eth_getLogs',
|
|
264
|
+
* params: [
|
|
265
|
+
* {
|
|
266
|
+
* address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
|
|
267
|
+
* fromBlock: Hex.fromNumber(19760235n),
|
|
268
|
+
* toBlock: Hex.fromNumber(19760240n),
|
|
269
|
+
* topics,
|
|
270
|
+
* },
|
|
271
|
+
* ],
|
|
272
|
+
* })
|
|
273
|
+
*
|
|
274
|
+
* // 4. Decode the Log. // [!code focus]
|
|
275
|
+
* const decoded = AbiEvent.decode(transfer, logs[0]!) // [!code focus]
|
|
276
|
+
* // @log: {
|
|
277
|
+
* // @log: from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
278
|
+
* // @log: to: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
279
|
+
* // @log: value: 603n
|
|
280
|
+
* // @log: }
|
|
281
|
+
* ```
|
|
282
|
+
*
|
|
283
|
+
* :::note
|
|
284
|
+
*
|
|
285
|
+
* For simplicity, the above example uses `window.ethereum.request`, but you can use any
|
|
286
|
+
* type of JSON-RPC interface.
|
|
287
|
+
*
|
|
288
|
+
* :::
|
|
289
|
+
*
|
|
290
|
+
* @param abiEvent - The ABI Event to decode.
|
|
291
|
+
* @param log - `topics` & `data` to decode.
|
|
292
|
+
* @returns The decoded event.
|
|
293
|
+
*/
|
|
294
|
+
export function decode<const abiEvent extends AbiEvent>(
|
|
295
|
+
abiEvent: abiEvent | AbiEvent,
|
|
296
|
+
log: decode.Log,
|
|
297
|
+
): decode.ReturnType<abiEvent> {
|
|
298
|
+
const { data, topics } = log
|
|
299
|
+
|
|
300
|
+
const [selector_, ...argTopics] = topics
|
|
301
|
+
|
|
302
|
+
const selector = getSelector(abiEvent)
|
|
303
|
+
if (selector_ !== selector)
|
|
304
|
+
throw new SelectorTopicMismatchError({
|
|
305
|
+
abiEvent,
|
|
306
|
+
actual: selector_,
|
|
307
|
+
expected: selector,
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
const { inputs } = abiEvent
|
|
311
|
+
const isUnnamed = inputs?.every((x) => !('name' in x && x.name))
|
|
312
|
+
|
|
313
|
+
let args: any = isUnnamed ? [] : {}
|
|
314
|
+
|
|
315
|
+
// Decode topics (indexed args).
|
|
316
|
+
const indexedInputs = inputs.filter((x) => 'indexed' in x && x.indexed)
|
|
317
|
+
for (let i = 0; i < indexedInputs.length; i++) {
|
|
318
|
+
const param = indexedInputs[i]!
|
|
319
|
+
const topic = argTopics[i]
|
|
320
|
+
if (!topic)
|
|
321
|
+
throw new TopicsMismatchError({
|
|
322
|
+
abiEvent,
|
|
323
|
+
param: param as abitype.AbiParameter & { indexed: boolean },
|
|
324
|
+
})
|
|
325
|
+
args[isUnnamed ? i : param.name || i] = (() => {
|
|
326
|
+
if (
|
|
327
|
+
param.type === 'string' ||
|
|
328
|
+
param.type === 'bytes' ||
|
|
329
|
+
param.type === 'tuple' ||
|
|
330
|
+
param.type.match(/^(.*)\[(\d+)?\]$/)
|
|
331
|
+
)
|
|
332
|
+
return topic
|
|
333
|
+
const decoded = AbiParameters.decode([param], topic) || []
|
|
334
|
+
return decoded[0]
|
|
335
|
+
})()
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Decode data (non-indexed args).
|
|
339
|
+
const nonIndexedInputs = inputs.filter((x) => !('indexed' in x && x.indexed))
|
|
340
|
+
if (nonIndexedInputs.length > 0) {
|
|
341
|
+
if (data && data !== '0x') {
|
|
342
|
+
try {
|
|
343
|
+
const decodedData = AbiParameters.decode(nonIndexedInputs, data)
|
|
344
|
+
if (decodedData) {
|
|
345
|
+
if (isUnnamed) args = [...args, ...decodedData]
|
|
346
|
+
else {
|
|
347
|
+
for (let i = 0; i < nonIndexedInputs.length; i++) {
|
|
348
|
+
const index = inputs.indexOf(nonIndexedInputs[i]!)
|
|
349
|
+
args[nonIndexedInputs[i]!.name! || index] = decodedData[i]
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
} catch (err) {
|
|
354
|
+
if (
|
|
355
|
+
err instanceof AbiParameters.DataSizeTooSmallError ||
|
|
356
|
+
err instanceof Cursor.PositionOutOfBoundsError
|
|
357
|
+
)
|
|
358
|
+
throw new DataMismatchError({
|
|
359
|
+
abiEvent,
|
|
360
|
+
data: data,
|
|
361
|
+
parameters: nonIndexedInputs,
|
|
362
|
+
size: Hex.size(data),
|
|
363
|
+
})
|
|
364
|
+
throw err
|
|
365
|
+
}
|
|
366
|
+
} else {
|
|
367
|
+
throw new DataMismatchError({
|
|
368
|
+
abiEvent,
|
|
369
|
+
data: '0x',
|
|
370
|
+
parameters: nonIndexedInputs,
|
|
371
|
+
size: 0,
|
|
372
|
+
})
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return Object.values(args).length > 0 ? args : undefined
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export declare namespace decode {
|
|
380
|
+
type Log = {
|
|
381
|
+
data?: Hex.Hex | undefined
|
|
382
|
+
topics: readonly Hex.Hex[]
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
type ReturnType<abiEvent extends AbiEvent = AbiEvent> = IsNarrowable<
|
|
386
|
+
abiEvent,
|
|
387
|
+
AbiEvent
|
|
388
|
+
> extends true
|
|
389
|
+
? abiEvent['inputs'] extends readonly []
|
|
390
|
+
? undefined
|
|
391
|
+
: internal.ParametersToPrimitiveTypes<
|
|
392
|
+
abiEvent['inputs'],
|
|
393
|
+
{ EnableUnion: false; IndexedOnly: false; Required: true }
|
|
394
|
+
>
|
|
395
|
+
: unknown
|
|
396
|
+
|
|
397
|
+
type ErrorType =
|
|
398
|
+
| AbiParameters.decode.ErrorType
|
|
399
|
+
| getSelector.ErrorType
|
|
400
|
+
| DataMismatchError
|
|
401
|
+
| SelectorTopicMismatchError
|
|
402
|
+
| TopicsMismatchError
|
|
403
|
+
| Errors.GlobalErrorType
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
decode.parseError = (error: unknown) =>
|
|
407
|
+
/* v8 ignore next */
|
|
408
|
+
error as decode.ErrorType
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* ABI-encodes the provided event input (`inputs`) into an array of [Event Topics](https://info.etherscan.com/what-is-event-logs/).
|
|
412
|
+
*
|
|
413
|
+
* :::tip
|
|
414
|
+
*
|
|
415
|
+
* This function is typically used to encode event arguments into [Event Topics](https://info.etherscan.com/what-is-event-logs/).
|
|
416
|
+
*
|
|
417
|
+
* See the [End-to-end Example](#end-to-end).
|
|
418
|
+
*
|
|
419
|
+
* :::
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* ```ts twoslash
|
|
423
|
+
* import { AbiEvent } from 'ox'
|
|
424
|
+
*
|
|
425
|
+
* const transfer = AbiEvent.from(
|
|
426
|
+
* 'event Transfer(address indexed from, address indexed to, uint256 value)'
|
|
427
|
+
* )
|
|
428
|
+
*
|
|
429
|
+
* const { topics } = AbiEvent.encode(transfer)
|
|
430
|
+
* // @log: ['0x406dade31f7ae4b5dbc276258c28dde5ae6d5c2773c5745802c493a2360e55e0']
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ### Passing Arguments
|
|
435
|
+
*
|
|
436
|
+
* You can pass `indexed` parameter values to `AbiEvent.encode`.
|
|
437
|
+
*
|
|
438
|
+
* TypeScript types will be inferred from the ABI Event, to guard you from inserting the wrong values.
|
|
439
|
+
*
|
|
440
|
+
* For example, the `Transfer` event below accepts an `address` type for the `from` and `to` attributes.
|
|
441
|
+
*
|
|
442
|
+
* ```ts twoslash
|
|
443
|
+
* import { AbiEvent } from 'ox'
|
|
444
|
+
*
|
|
445
|
+
* const transfer = AbiEvent.from(
|
|
446
|
+
* 'event Transfer(address indexed from, address indexed to, uint256 value)'
|
|
447
|
+
* )
|
|
448
|
+
*
|
|
449
|
+
* const { topics } = AbiEvent.encode(transfer, {
|
|
450
|
+
* from: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', // [!code hl]
|
|
451
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' // [!code hl]
|
|
452
|
+
* })
|
|
453
|
+
* // @log: [
|
|
454
|
+
* // @log: '0x406dade31f7ae4b5dbc276258c28dde5ae6d5c2773c5745802c493a2360e55e0',
|
|
455
|
+
* // @log: '0x00000000000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
|
456
|
+
* // @log: '0x0000000000000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8'
|
|
457
|
+
* // @log: ]
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* @example
|
|
461
|
+
* ### End-to-end
|
|
462
|
+
*
|
|
463
|
+
* Below is an end-to-end example of using `AbiEvent.encode` to encode the topics of a `Transfer` event and query for events matching the encoded topics on the [Wagmi Mint Example contract](https://etherscan.io/address/0xfba3912ca04dd458c843e2ee08967fc04f3579c2).
|
|
464
|
+
*
|
|
465
|
+
* ```ts twoslash
|
|
466
|
+
* import 'ox/window'
|
|
467
|
+
* import { AbiEvent, Hex } from 'ox'
|
|
468
|
+
*
|
|
469
|
+
* // 1. Instantiate the `Transfer` ABI Event.
|
|
470
|
+
* const transfer = AbiEvent.from(
|
|
471
|
+
* 'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
472
|
+
* )
|
|
473
|
+
*
|
|
474
|
+
* // 2. Encode the ABI Event into Event Topics.
|
|
475
|
+
* const { topics } = AbiEvent.encode(transfer)
|
|
476
|
+
*
|
|
477
|
+
* // 3. Query for events matching the encoded Topics.
|
|
478
|
+
* const logs = await window.ethereum!.request({
|
|
479
|
+
* method: 'eth_getLogs',
|
|
480
|
+
* params: [
|
|
481
|
+
* {
|
|
482
|
+
* address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
|
|
483
|
+
* fromBlock: Hex.fromNumber(19760235n),
|
|
484
|
+
* toBlock: Hex.fromNumber(19760240n),
|
|
485
|
+
* topics,
|
|
486
|
+
* },
|
|
487
|
+
* ],
|
|
488
|
+
* })
|
|
489
|
+
* // @log: [
|
|
490
|
+
* // @log: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
|
491
|
+
* // @log: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
492
|
+
* // @log: "0x0000000000000000000000000c04d9e9278ec5e4d424476d3ebec70cb5d648d1",
|
|
493
|
+
* // @log: "0x000000000000000000000000000000000000000000000000000000000000025b",
|
|
494
|
+
* // @log: ]
|
|
495
|
+
* ```
|
|
496
|
+
*
|
|
497
|
+
* :::note
|
|
498
|
+
*
|
|
499
|
+
* For simplicity, the above example uses `window.ethereum.request`, but you can use any
|
|
500
|
+
* type of JSON-RPC interface.
|
|
501
|
+
*
|
|
502
|
+
* :::
|
|
503
|
+
*
|
|
504
|
+
* @param abiEvent - The event to encode.
|
|
505
|
+
* @param args - The arguments to encode.
|
|
506
|
+
* @returns The encoded event topics.
|
|
507
|
+
*/
|
|
508
|
+
export function encode<const abiEvent extends AbiEvent>(
|
|
509
|
+
abiEvent: abiEvent | AbiEvent,
|
|
510
|
+
...[args]: encode.Args<abiEvent>
|
|
511
|
+
): encode.ReturnType {
|
|
512
|
+
let topics: (Hex.Hex | Hex.Hex[] | null)[] = []
|
|
513
|
+
if (args && abiEvent.inputs) {
|
|
514
|
+
const indexedInputs = abiEvent.inputs.filter(
|
|
515
|
+
(param) => 'indexed' in param && param.indexed,
|
|
516
|
+
)
|
|
517
|
+
const args_ = Array.isArray(args)
|
|
518
|
+
? args
|
|
519
|
+
: Object.values(args).length > 0
|
|
520
|
+
? indexedInputs?.map(
|
|
521
|
+
(x: any, i: number) => (args as any)[x.name ?? i],
|
|
522
|
+
) ?? []
|
|
523
|
+
: []
|
|
524
|
+
|
|
525
|
+
if (args_.length > 0) {
|
|
526
|
+
const encode = (param: abitype.AbiParameter, value: unknown) => {
|
|
527
|
+
if (param.type === 'string')
|
|
528
|
+
return Hash.keccak256(Hex.fromString(value as string))
|
|
529
|
+
if (param.type === 'bytes') return Hash.keccak256(value as Hex.Hex)
|
|
530
|
+
if (param.type === 'tuple' || param.type.match(/^(.*)\[(\d+)?\]$/))
|
|
531
|
+
throw new FilterTypeNotSupportedError(param.type)
|
|
532
|
+
return AbiParameters.encode([param], [value])
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
topics =
|
|
536
|
+
indexedInputs?.map((param, i) => {
|
|
537
|
+
if (Array.isArray(args_[i]))
|
|
538
|
+
return args_[i].map((_: any, j: number) =>
|
|
539
|
+
encode(param, args_[i][j]),
|
|
540
|
+
)
|
|
541
|
+
return args_[i] ? encode(param, args_[i]) : null
|
|
542
|
+
}) ?? []
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const selector = (() => {
|
|
547
|
+
if (abiEvent.hash) return abiEvent.hash
|
|
548
|
+
return getSelector(abiEvent)
|
|
549
|
+
})()
|
|
550
|
+
|
|
551
|
+
return { topics: [selector, ...topics] }
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export declare namespace encode {
|
|
555
|
+
type Args<abiEvent extends AbiEvent> = IsNarrowable<
|
|
556
|
+
abiEvent,
|
|
557
|
+
AbiEvent
|
|
558
|
+
> extends true
|
|
559
|
+
? abiEvent['inputs'] extends readonly []
|
|
560
|
+
? []
|
|
561
|
+
: internal.ParametersToPrimitiveTypes<
|
|
562
|
+
abiEvent['inputs']
|
|
563
|
+
> extends infer result
|
|
564
|
+
? result extends readonly []
|
|
565
|
+
? []
|
|
566
|
+
: [result] | []
|
|
567
|
+
: []
|
|
568
|
+
: [readonly unknown[] | Record<string, unknown>] | []
|
|
569
|
+
|
|
570
|
+
type ReturnType = {
|
|
571
|
+
topics: Compute<
|
|
572
|
+
[selector: Hex.Hex, ...(Hex.Hex | readonly Hex.Hex[] | null)[]]
|
|
573
|
+
>
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
type ErrorType =
|
|
577
|
+
| AbiParameters.encode.ErrorType
|
|
578
|
+
| getSelector.ErrorType
|
|
579
|
+
| Hex.fromString.ErrorType
|
|
580
|
+
| Hash.keccak256.ErrorType
|
|
581
|
+
| Errors.GlobalErrorType
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
encode.parseError = (error: unknown) =>
|
|
585
|
+
/* v8 ignore next */
|
|
586
|
+
error as encode.ErrorType
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Formats an {@link ox#AbiEvent.AbiEvent} into a **Human Readable ABI Error**.
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```ts twoslash
|
|
593
|
+
* import { AbiEvent } from 'ox'
|
|
594
|
+
*
|
|
595
|
+
* const formatted = AbiEvent.format({
|
|
596
|
+
* type: 'event',
|
|
597
|
+
* name: 'Transfer',
|
|
598
|
+
* inputs: [
|
|
599
|
+
* { name: 'from', type: 'address', indexed: true },
|
|
600
|
+
* { name: 'to', type: 'address', indexed: true },
|
|
601
|
+
* { name: 'value', type: 'uint256' },
|
|
602
|
+
* ],
|
|
603
|
+
* })
|
|
604
|
+
*
|
|
605
|
+
* formatted
|
|
606
|
+
* // ^?
|
|
607
|
+
*
|
|
608
|
+
*
|
|
609
|
+
* ```
|
|
610
|
+
*
|
|
611
|
+
* @param abiEvent - The ABI Event to format.
|
|
612
|
+
* @returns The formatted ABI Event.
|
|
613
|
+
*/
|
|
614
|
+
export function format<const abiEvent extends AbiEvent>(
|
|
615
|
+
abiEvent: abiEvent | AbiEvent,
|
|
616
|
+
): abitype.FormatAbiItem<abiEvent> {
|
|
617
|
+
return abitype.formatAbiItem(abiEvent) as never
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
export declare namespace format {
|
|
621
|
+
type ErrorType = Errors.GlobalErrorType
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
format.parseError = (error: unknown) =>
|
|
625
|
+
/* v8 ignore next */
|
|
626
|
+
error as format.ErrorType
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Parses an arbitrary **JSON ABI Event** or **Human Readable ABI Event** into a typed {@link ox#AbiEvent.AbiEvent}.
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ### JSON ABIs
|
|
633
|
+
*
|
|
634
|
+
* ```ts twoslash
|
|
635
|
+
* import { AbiEvent } from 'ox'
|
|
636
|
+
*
|
|
637
|
+
* const transfer = AbiEvent.from({
|
|
638
|
+
* name: 'Transfer',
|
|
639
|
+
* type: 'event',
|
|
640
|
+
* inputs: [
|
|
641
|
+
* { name: 'from', type: 'address', indexed: true },
|
|
642
|
+
* { name: 'to', type: 'address', indexed: true },
|
|
643
|
+
* { name: 'value', type: 'uint256' },
|
|
644
|
+
* ],
|
|
645
|
+
* })
|
|
646
|
+
*
|
|
647
|
+
* transfer
|
|
648
|
+
* //^?
|
|
649
|
+
*
|
|
650
|
+
*
|
|
651
|
+
*
|
|
652
|
+
*
|
|
653
|
+
*
|
|
654
|
+
*
|
|
655
|
+
*
|
|
656
|
+
*
|
|
657
|
+
*
|
|
658
|
+
*
|
|
659
|
+
*
|
|
660
|
+
*
|
|
661
|
+
* ```
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* ### Human Readable ABIs
|
|
665
|
+
*
|
|
666
|
+
* A Human Readable ABI can be parsed into a typed ABI object:
|
|
667
|
+
*
|
|
668
|
+
* ```ts twoslash
|
|
669
|
+
* import { AbiEvent } from 'ox'
|
|
670
|
+
*
|
|
671
|
+
* const transfer = AbiEvent.from(
|
|
672
|
+
* 'event Transfer(address indexed from, address indexed to, uint256 value)' // [!code hl]
|
|
673
|
+
* )
|
|
674
|
+
*
|
|
675
|
+
* transfer
|
|
676
|
+
* //^?
|
|
677
|
+
*
|
|
678
|
+
*
|
|
679
|
+
*
|
|
680
|
+
*
|
|
681
|
+
*
|
|
682
|
+
*
|
|
683
|
+
*
|
|
684
|
+
*
|
|
685
|
+
*
|
|
686
|
+
*
|
|
687
|
+
*
|
|
688
|
+
*
|
|
689
|
+
*
|
|
690
|
+
* ```
|
|
691
|
+
*
|
|
692
|
+
* @param abiEvent - The ABI Event to parse.
|
|
693
|
+
* @returns Typed ABI Event.
|
|
694
|
+
*/
|
|
695
|
+
export function from<
|
|
696
|
+
const abiEvent extends AbiEvent | string | readonly string[],
|
|
697
|
+
>(
|
|
698
|
+
abiEvent: (abiEvent | AbiEvent | string | readonly string[]) &
|
|
699
|
+
(
|
|
700
|
+
| (abiEvent extends string ? internal.Signature<abiEvent> : never)
|
|
701
|
+
| (abiEvent extends readonly string[]
|
|
702
|
+
? internal.Signatures<abiEvent>
|
|
703
|
+
: never)
|
|
704
|
+
| AbiEvent
|
|
705
|
+
),
|
|
706
|
+
options: from.Options = {},
|
|
707
|
+
): from.ReturnType<abiEvent> {
|
|
708
|
+
return AbiItem.from(abiEvent as AbiEvent, options) as never
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
export declare namespace from {
|
|
712
|
+
type Options = {
|
|
713
|
+
/**
|
|
714
|
+
* Whether or not to prepare the extracted event (optimization for encoding performance).
|
|
715
|
+
* When `true`, the `hash` property is computed and included in the returned value.
|
|
716
|
+
*
|
|
717
|
+
* @default true
|
|
718
|
+
*/
|
|
719
|
+
prepare?: boolean | undefined
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
type ReturnType<abiEvent extends AbiEvent | string | readonly string[]> =
|
|
723
|
+
AbiItem.from.ReturnType<abiEvent>
|
|
724
|
+
|
|
725
|
+
type ErrorType = AbiItem.from.ErrorType | Errors.GlobalErrorType
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
from.parseEvent = (Event: unknown) =>
|
|
729
|
+
/* v8 ignore next */
|
|
730
|
+
Event as from.ErrorType
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Extracts an {@link ox#AbiEvent.AbiEvent} from an {@link ox#Abi.Abi} given a name and optional arguments.
|
|
734
|
+
*
|
|
735
|
+
* @example
|
|
736
|
+
* ### Extracting by Name
|
|
737
|
+
*
|
|
738
|
+
* ABI Events can be extracted by their name using the `name` option:
|
|
739
|
+
*
|
|
740
|
+
* ```ts twoslash
|
|
741
|
+
* import { Abi, AbiEvent } from 'ox'
|
|
742
|
+
*
|
|
743
|
+
* const abi = Abi.from([
|
|
744
|
+
* 'function foo()',
|
|
745
|
+
* 'event Transfer(address owner, address to, uint256 tokenId)',
|
|
746
|
+
* 'function bar(string a) returns (uint256 x)',
|
|
747
|
+
* ])
|
|
748
|
+
*
|
|
749
|
+
* const item = AbiEvent.fromAbi(abi, 'Transfer') // [!code focus]
|
|
750
|
+
* // ^?
|
|
751
|
+
*
|
|
752
|
+
*
|
|
753
|
+
*
|
|
754
|
+
*
|
|
755
|
+
*
|
|
756
|
+
*
|
|
757
|
+
* ```
|
|
758
|
+
*
|
|
759
|
+
* @example
|
|
760
|
+
* ### Extracting by Selector
|
|
761
|
+
*
|
|
762
|
+
* ABI Events can be extract by their selector when {@link ox#Hex.Hex} is provided to `name`.
|
|
763
|
+
*
|
|
764
|
+
* ```ts twoslash
|
|
765
|
+
* import { Abi, AbiEvent } from 'ox'
|
|
766
|
+
*
|
|
767
|
+
* const abi = Abi.from([
|
|
768
|
+
* 'function foo()',
|
|
769
|
+
* 'event Transfer(address owner, address to, uint256 tokenId)',
|
|
770
|
+
* 'function bar(string a) returns (uint256 x)',
|
|
771
|
+
* ])
|
|
772
|
+
* const item = AbiEvent.fromAbi(abi, '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef') // [!code focus]
|
|
773
|
+
* // ^?
|
|
774
|
+
*
|
|
775
|
+
*
|
|
776
|
+
*
|
|
777
|
+
*
|
|
778
|
+
*
|
|
779
|
+
*
|
|
780
|
+
*
|
|
781
|
+
*
|
|
782
|
+
*
|
|
783
|
+
* ```
|
|
784
|
+
*
|
|
785
|
+
* :::note
|
|
786
|
+
*
|
|
787
|
+
* Extracting via a hex selector is useful when extracting an ABI Event from the first topic of a Log.
|
|
788
|
+
*
|
|
789
|
+
* :::
|
|
790
|
+
*
|
|
791
|
+
* @param abi - The ABI to extract from.
|
|
792
|
+
* @param name - The name (or selector) of the ABI item to extract.
|
|
793
|
+
* @param options - Extraction options.
|
|
794
|
+
* @returns The ABI item.
|
|
795
|
+
*/
|
|
796
|
+
export function fromAbi<
|
|
797
|
+
const abi extends Abi.Abi | readonly unknown[],
|
|
798
|
+
name extends Name<abi>,
|
|
799
|
+
const args extends
|
|
800
|
+
| AbiItem_internal.ExtractArgs<abi, name>
|
|
801
|
+
| undefined = undefined,
|
|
802
|
+
//
|
|
803
|
+
allNames = Name<abi>,
|
|
804
|
+
>(
|
|
805
|
+
abi: abi | Abi.Abi | readonly unknown[],
|
|
806
|
+
name: Hex.Hex | (name extends allNames ? name : never),
|
|
807
|
+
options?: AbiItem.fromAbi.Options<
|
|
808
|
+
abi,
|
|
809
|
+
name,
|
|
810
|
+
args,
|
|
811
|
+
AbiItem_internal.ExtractArgs<abi, name>
|
|
812
|
+
>,
|
|
813
|
+
): AbiItem.fromAbi.ReturnType<abi, name, args, AbiEvent> {
|
|
814
|
+
const item = AbiItem.fromAbi(abi, name, options as any)
|
|
815
|
+
if (item.type !== 'event')
|
|
816
|
+
throw new AbiItem.NotFoundError({ name, type: 'event' })
|
|
817
|
+
return item as never
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
export declare namespace fromAbi {
|
|
821
|
+
type ErrorType = AbiItem.fromAbi.ErrorType | Errors.GlobalErrorType
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
fromAbi.parseError = (error: unknown) =>
|
|
825
|
+
/* v8 ignore next */
|
|
826
|
+
error as fromAbi.ErrorType
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Computes the event selector (hash of event signature) for an {@link ox#AbiEvent.AbiEvent}.
|
|
830
|
+
*
|
|
831
|
+
* @example
|
|
832
|
+
* ```ts twoslash
|
|
833
|
+
* import { AbiEvent } from 'ox'
|
|
834
|
+
*
|
|
835
|
+
* const selector = AbiEvent.getSelector('event Transfer(address indexed from, address indexed to, uint256 value)')
|
|
836
|
+
* // @log: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f556a2'
|
|
837
|
+
* ```
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* ```ts twoslash
|
|
841
|
+
* import { AbiEvent } from 'ox'
|
|
842
|
+
*
|
|
843
|
+
* const selector = AbiEvent.getSelector({
|
|
844
|
+
* name: 'Transfer',
|
|
845
|
+
* type: 'event',
|
|
846
|
+
* inputs: [
|
|
847
|
+
* { name: 'from', type: 'address', indexed: true },
|
|
848
|
+
* { name: 'to', type: 'address', indexed: true },
|
|
849
|
+
* { name: 'value', type: 'uint256' }
|
|
850
|
+
* ]
|
|
851
|
+
* })
|
|
852
|
+
* // @log: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f556a2'
|
|
853
|
+
* ```
|
|
854
|
+
*
|
|
855
|
+
* @param abiItem - The ABI event to compute the selector for.
|
|
856
|
+
* @returns The {@link ox#Hash.(keccak256:function)} hash of the event signature.
|
|
857
|
+
*/
|
|
858
|
+
export function getSelector(abiItem: string | AbiEvent): Hex.Hex {
|
|
859
|
+
return AbiItem.getSignatureHash(abiItem)
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
export declare namespace getSelector {
|
|
863
|
+
type ErrorType = AbiItem.getSignatureHash.ErrorType | Errors.GlobalErrorType
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/* v8 ignore next */
|
|
867
|
+
getSelector.parseError = (error: unknown) => error as getSelector.ErrorType
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* Thrown when the provided arguments do not match the expected arguments.
|
|
871
|
+
*
|
|
872
|
+
* @example
|
|
873
|
+
* ```ts twoslash
|
|
874
|
+
* import { AbiEvent } from 'ox'
|
|
875
|
+
*
|
|
876
|
+
* const abiEvent = AbiEvent.from(
|
|
877
|
+
* 'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
878
|
+
* )
|
|
879
|
+
*
|
|
880
|
+
* const args = AbiEvent.decode(abiEvent, {
|
|
881
|
+
* data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
882
|
+
* topics: [
|
|
883
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
884
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
885
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
886
|
+
* ],
|
|
887
|
+
* })
|
|
888
|
+
*
|
|
889
|
+
* AbiEvent.assertArgs(abiEvent, args, {
|
|
890
|
+
* from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
891
|
+
* to: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
892
|
+
* value: 1n,
|
|
893
|
+
* })
|
|
894
|
+
* // @error: AbiEvent.ArgsMismatchError: Given arguments do not match the expected arguments.
|
|
895
|
+
* // @error: Event: event Transfer(address indexed from, address indexed to, uint256 value)
|
|
896
|
+
* // @error: Expected Arguments:
|
|
897
|
+
* // @error: from: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac
|
|
898
|
+
* // @error: to: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad
|
|
899
|
+
* // @error: value: 1
|
|
900
|
+
* // @error: Given Arguments:
|
|
901
|
+
* // @error: from: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad
|
|
902
|
+
* // @error: to: 0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac
|
|
903
|
+
* // @error: value: 1
|
|
904
|
+
* ```
|
|
905
|
+
*
|
|
906
|
+
* ### Solution
|
|
907
|
+
*
|
|
908
|
+
* The provided arguments need to match the expected arguments.
|
|
909
|
+
*
|
|
910
|
+
* ```ts twoslash
|
|
911
|
+
* // @noErrors
|
|
912
|
+
* import { AbiEvent } from 'ox'
|
|
913
|
+
*
|
|
914
|
+
* const abiEvent = AbiEvent.from(
|
|
915
|
+
* 'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
916
|
+
* )
|
|
917
|
+
*
|
|
918
|
+
* const args = AbiEvent.decode(abiEvent, {
|
|
919
|
+
* data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
920
|
+
* topics: [
|
|
921
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
922
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
923
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
924
|
+
* ],
|
|
925
|
+
* })
|
|
926
|
+
*
|
|
927
|
+
* AbiEvent.assertArgs(abiEvent, args, {
|
|
928
|
+
* from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad', // [!code --]
|
|
929
|
+
* from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac', // [!code ++]
|
|
930
|
+
* to: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac', // [!code --]
|
|
931
|
+
* to: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad', // [!code ++]
|
|
932
|
+
* value: 1n,
|
|
933
|
+
* })
|
|
934
|
+
* ```
|
|
935
|
+
*/
|
|
936
|
+
export class ArgsMismatchError extends Errors.BaseError {
|
|
937
|
+
override readonly name = 'AbiEvent.ArgsMismatchError'
|
|
938
|
+
|
|
939
|
+
constructor({
|
|
940
|
+
abiEvent,
|
|
941
|
+
expected,
|
|
942
|
+
given,
|
|
943
|
+
}: {
|
|
944
|
+
abiEvent: AbiEvent
|
|
945
|
+
expected: unknown
|
|
946
|
+
given: unknown
|
|
947
|
+
}) {
|
|
948
|
+
super('Given arguments do not match the expected arguments.', {
|
|
949
|
+
metaMessages: [
|
|
950
|
+
`Event: ${format(abiEvent)}`,
|
|
951
|
+
`Expected Arguments: ${!expected ? 'None' : ''}`,
|
|
952
|
+
expected ? prettyPrint(expected) : undefined,
|
|
953
|
+
`Given Arguments: ${!given ? 'None' : ''}`,
|
|
954
|
+
given ? prettyPrint(given) : undefined,
|
|
955
|
+
],
|
|
956
|
+
})
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
/**
|
|
961
|
+
* Thrown when no argument was found on the event signature.
|
|
962
|
+
*
|
|
963
|
+
* @example
|
|
964
|
+
* ```ts twoslash
|
|
965
|
+
* // @noErrors
|
|
966
|
+
* import { AbiEvent } from 'ox'
|
|
967
|
+
*
|
|
968
|
+
* const abiEvent = AbiEvent.from(
|
|
969
|
+
* 'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
970
|
+
* )
|
|
971
|
+
*
|
|
972
|
+
* const args = AbiEvent.decode(abiEvent, {
|
|
973
|
+
* data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
974
|
+
* topics: [
|
|
975
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
976
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
977
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
978
|
+
* ],
|
|
979
|
+
* })
|
|
980
|
+
*
|
|
981
|
+
* AbiEvent.assertArgs(abiEvent, args, {
|
|
982
|
+
* a: 'b',
|
|
983
|
+
* from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
984
|
+
* to: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
985
|
+
* value: 1n,
|
|
986
|
+
* })
|
|
987
|
+
* // @error: AbiEvent.InputNotFoundError: Parameter "a" not found on `event Transfer(address indexed from, address indexed to, uint256 value)`.
|
|
988
|
+
* ```
|
|
989
|
+
*
|
|
990
|
+
* ### Solution
|
|
991
|
+
*
|
|
992
|
+
* Ensure the arguments match the event signature.
|
|
993
|
+
*
|
|
994
|
+
* ```ts twoslash
|
|
995
|
+
* // @noErrors
|
|
996
|
+
* import { AbiEvent } from 'ox'
|
|
997
|
+
*
|
|
998
|
+
* const abiEvent = AbiEvent.from(
|
|
999
|
+
* 'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
1000
|
+
* )
|
|
1001
|
+
*
|
|
1002
|
+
* const args = AbiEvent.decode(abiEvent, {
|
|
1003
|
+
* data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1004
|
+
* topics: [
|
|
1005
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
1006
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1007
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
1008
|
+
* ],
|
|
1009
|
+
* })
|
|
1010
|
+
*
|
|
1011
|
+
* AbiEvent.assertArgs(abiEvent, args, {
|
|
1012
|
+
* a: 'b', // [!code --]
|
|
1013
|
+
* from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1014
|
+
* to: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ad',
|
|
1015
|
+
* value: 1n,
|
|
1016
|
+
* })
|
|
1017
|
+
* ```
|
|
1018
|
+
*/
|
|
1019
|
+
export class InputNotFoundError extends Errors.BaseError {
|
|
1020
|
+
override readonly name = 'AbiEvent.InputNotFoundError'
|
|
1021
|
+
|
|
1022
|
+
constructor({
|
|
1023
|
+
abiEvent,
|
|
1024
|
+
name,
|
|
1025
|
+
}: {
|
|
1026
|
+
abiEvent: AbiEvent
|
|
1027
|
+
name: string
|
|
1028
|
+
}) {
|
|
1029
|
+
super(`Parameter "${name}" not found on \`${format(abiEvent)}\`.`)
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* Thrown when the provided data size does not match the expected size from the non-indexed parameters.
|
|
1035
|
+
*
|
|
1036
|
+
* @example
|
|
1037
|
+
* ```ts twoslash
|
|
1038
|
+
* import { AbiEvent } from 'ox'
|
|
1039
|
+
*
|
|
1040
|
+
* const abiEvent = AbiEvent.from(
|
|
1041
|
+
* 'event Transfer(address indexed from, address to, uint256 value)',
|
|
1042
|
+
* // ↑ 32 bytes + ↑ 32 bytes = 64 bytes
|
|
1043
|
+
* )
|
|
1044
|
+
*
|
|
1045
|
+
* const args = AbiEvent.decode(abiEvent, {
|
|
1046
|
+
* data: '0x0000000000000000000000000000000000000000000000000000000023c34600',
|
|
1047
|
+
* // ↑ 32 bytes ❌
|
|
1048
|
+
* topics: [
|
|
1049
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
1050
|
+
* '0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
|
1051
|
+
* ],
|
|
1052
|
+
* })
|
|
1053
|
+
* // @error: AbiEvent.DataMismatchError: Data size of 32 bytes is too small for non-indexed event parameters.
|
|
1054
|
+
* // @error: Non-indexed Parameters: (address to, uint256 value)
|
|
1055
|
+
* // @error: Data: 0x0000000000000000000000000000000000000000000000000000000023c34600 (32 bytes)
|
|
1056
|
+
* ```
|
|
1057
|
+
*
|
|
1058
|
+
* ### Solution
|
|
1059
|
+
*
|
|
1060
|
+
* Ensure that the data size matches the expected size.
|
|
1061
|
+
*
|
|
1062
|
+
* ```ts twoslash
|
|
1063
|
+
* import { AbiEvent } from 'ox'
|
|
1064
|
+
*
|
|
1065
|
+
* const abiEvent = AbiEvent.from(
|
|
1066
|
+
* 'event Transfer(address indexed from, address to, uint256 value)',
|
|
1067
|
+
* // ↑ 32 bytes + ↑ 32 bytes = 64 bytes
|
|
1068
|
+
* )
|
|
1069
|
+
*
|
|
1070
|
+
* const args = AbiEvent.decode(abiEvent, {
|
|
1071
|
+
* data: '0x0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000000000023c34600',
|
|
1072
|
+
* // ↑ 64 bytes ✅
|
|
1073
|
+
* topics: [
|
|
1074
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
1075
|
+
* '0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
|
1076
|
+
* ],
|
|
1077
|
+
* })
|
|
1078
|
+
* ```
|
|
1079
|
+
*/
|
|
1080
|
+
export class DataMismatchError extends Errors.BaseError {
|
|
1081
|
+
override readonly name = 'AbiEvent.DataMismatchError'
|
|
1082
|
+
|
|
1083
|
+
abiEvent: AbiEvent
|
|
1084
|
+
data: Hex.Hex
|
|
1085
|
+
parameters: readonly abitype.AbiParameter[]
|
|
1086
|
+
size: number
|
|
1087
|
+
|
|
1088
|
+
constructor({
|
|
1089
|
+
abiEvent,
|
|
1090
|
+
data,
|
|
1091
|
+
parameters,
|
|
1092
|
+
size,
|
|
1093
|
+
}: {
|
|
1094
|
+
abiEvent: AbiEvent
|
|
1095
|
+
data: Hex.Hex
|
|
1096
|
+
parameters: readonly abitype.AbiParameter[]
|
|
1097
|
+
size: number
|
|
1098
|
+
}) {
|
|
1099
|
+
super(
|
|
1100
|
+
[
|
|
1101
|
+
`Data size of ${size} bytes is too small for non-indexed event parameters.`,
|
|
1102
|
+
].join('\n'),
|
|
1103
|
+
{
|
|
1104
|
+
metaMessages: [
|
|
1105
|
+
`Non-indexed Parameters: (${AbiParameters.format(parameters as any)})`,
|
|
1106
|
+
`Data: ${data} (${size} bytes)`,
|
|
1107
|
+
],
|
|
1108
|
+
},
|
|
1109
|
+
)
|
|
1110
|
+
|
|
1111
|
+
this.abiEvent = abiEvent
|
|
1112
|
+
this.data = data
|
|
1113
|
+
this.parameters = parameters
|
|
1114
|
+
this.size = size
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* Thrown when the provided topics do not match the expected number of topics.
|
|
1120
|
+
*
|
|
1121
|
+
* @example
|
|
1122
|
+
* ```ts twoslash
|
|
1123
|
+
* import { AbiEvent } from 'ox'
|
|
1124
|
+
*
|
|
1125
|
+
* const abiEvent = AbiEvent.from(
|
|
1126
|
+
* 'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
1127
|
+
* )
|
|
1128
|
+
*
|
|
1129
|
+
* const args = AbiEvent.decode(abiEvent, {
|
|
1130
|
+
* data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1131
|
+
* topics: [
|
|
1132
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
1133
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1134
|
+
* ],
|
|
1135
|
+
* })
|
|
1136
|
+
* // @error: AbiEvent.TopicsMismatchError: Expected a topic for indexed event parameter "to" for "event Transfer(address indexed from, address indexed to, uint256 value)".
|
|
1137
|
+
* ```
|
|
1138
|
+
*
|
|
1139
|
+
* ### Solution
|
|
1140
|
+
*
|
|
1141
|
+
* Ensure that the topics match the expected number of topics.
|
|
1142
|
+
*
|
|
1143
|
+
* ```ts twoslash
|
|
1144
|
+
* import { AbiEvent } from 'ox'
|
|
1145
|
+
*
|
|
1146
|
+
* const abiEvent = AbiEvent.from(
|
|
1147
|
+
* 'event Transfer(address indexed from, address indexed to, uint256 value)',
|
|
1148
|
+
* )
|
|
1149
|
+
*
|
|
1150
|
+
* const args = AbiEvent.decode(abiEvent, {
|
|
1151
|
+
* data: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1152
|
+
* topics: [
|
|
1153
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
1154
|
+
* '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
|
|
1155
|
+
* '0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266', // [!code ++]
|
|
1156
|
+
* ],
|
|
1157
|
+
* })
|
|
1158
|
+
* ```
|
|
1159
|
+
*
|
|
1160
|
+
*/
|
|
1161
|
+
export class TopicsMismatchError extends Errors.BaseError {
|
|
1162
|
+
override readonly name = 'AbiEvent.TopicsMismatchError'
|
|
1163
|
+
|
|
1164
|
+
abiEvent: AbiEvent
|
|
1165
|
+
|
|
1166
|
+
constructor({
|
|
1167
|
+
abiEvent,
|
|
1168
|
+
param,
|
|
1169
|
+
}: {
|
|
1170
|
+
abiEvent: AbiEvent
|
|
1171
|
+
param: abitype.AbiParameter & { indexed: boolean }
|
|
1172
|
+
}) {
|
|
1173
|
+
super(
|
|
1174
|
+
[
|
|
1175
|
+
`Expected a topic for indexed event parameter${
|
|
1176
|
+
param.name ? ` "${param.name}"` : ''
|
|
1177
|
+
} for "${format(abiEvent)}".`,
|
|
1178
|
+
].join('\n'),
|
|
1179
|
+
)
|
|
1180
|
+
|
|
1181
|
+
this.abiEvent = abiEvent
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
/**
|
|
1186
|
+
* Thrown when the provided selector does not match the expected selector.
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* ```ts twoslash
|
|
1190
|
+
* import { AbiEvent } from 'ox'
|
|
1191
|
+
*
|
|
1192
|
+
* const transfer = AbiEvent.from(
|
|
1193
|
+
* 'event Transfer(address indexed from, address indexed to, bool sender)',
|
|
1194
|
+
* )
|
|
1195
|
+
*
|
|
1196
|
+
* AbiEvent.decode(transfer, {
|
|
1197
|
+
* topics: [
|
|
1198
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
1199
|
+
* '0x000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045',
|
|
1200
|
+
* '0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
|
1201
|
+
* ],
|
|
1202
|
+
* })
|
|
1203
|
+
* // @error: AbiEvent.SelectorTopicMismatchError: topics[0]="0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" does not match the expected topics[0]="0x3da3cd3cf420c78f8981e7afeefa0eab1f0de0eb56e78ad9ba918ed01c0b402f".
|
|
1204
|
+
* // @error: Event: event Transfer(address indexed from, address indexed to, bool sender)
|
|
1205
|
+
* // @error: Selector: 0x3da3cd3cf420c78f8981e7afeefa0eab1f0de0eb56e78ad9ba918ed01c0b402f
|
|
1206
|
+
* ```
|
|
1207
|
+
*
|
|
1208
|
+
* ### Solution
|
|
1209
|
+
*
|
|
1210
|
+
* Ensure that the provided selector matches the selector of the event signature.
|
|
1211
|
+
*
|
|
1212
|
+
* ```ts twoslash
|
|
1213
|
+
* import { AbiEvent } from 'ox'
|
|
1214
|
+
*
|
|
1215
|
+
* const transfer = AbiEvent.from(
|
|
1216
|
+
* 'event Transfer(address indexed from, address indexed to, bool sender)',
|
|
1217
|
+
* )
|
|
1218
|
+
*
|
|
1219
|
+
* AbiEvent.decode(transfer, {
|
|
1220
|
+
* topics: [
|
|
1221
|
+
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', // [!code --]
|
|
1222
|
+
* '0x3da3cd3cf420c78f8981e7afeefa0eab1f0de0eb56e78ad9ba918ed01c0b402f', // [!code ++]
|
|
1223
|
+
* '0x000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045',
|
|
1224
|
+
* '0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
|
1225
|
+
* ],
|
|
1226
|
+
* })
|
|
1227
|
+
* ```
|
|
1228
|
+
*/
|
|
1229
|
+
export class SelectorTopicMismatchError extends Errors.BaseError {
|
|
1230
|
+
override readonly name = 'AbiEvent.SelectorTopicMismatchError'
|
|
1231
|
+
|
|
1232
|
+
constructor({
|
|
1233
|
+
abiEvent,
|
|
1234
|
+
actual,
|
|
1235
|
+
expected,
|
|
1236
|
+
}: {
|
|
1237
|
+
abiEvent: AbiEvent
|
|
1238
|
+
actual: Hex.Hex | undefined
|
|
1239
|
+
expected: Hex.Hex
|
|
1240
|
+
}) {
|
|
1241
|
+
super(
|
|
1242
|
+
`topics[0]="${actual}" does not match the expected topics[0]="${expected}".`,
|
|
1243
|
+
{
|
|
1244
|
+
metaMessages: [`Event: ${format(abiEvent)}`, `Selector: ${expected}`],
|
|
1245
|
+
},
|
|
1246
|
+
)
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* Thrown when the provided filter type is not supported.
|
|
1252
|
+
*
|
|
1253
|
+
* @example
|
|
1254
|
+
* ```ts twoslash
|
|
1255
|
+
* import { AbiEvent } from 'ox'
|
|
1256
|
+
*
|
|
1257
|
+
* const transfer = AbiEvent.from('event Transfer((string) indexed a, string b)')
|
|
1258
|
+
*
|
|
1259
|
+
* AbiEvent.encode(transfer, {
|
|
1260
|
+
* a: ['hello'],
|
|
1261
|
+
* })
|
|
1262
|
+
* // @error: AbiEvent.FilterTypeNotSupportedError: Filter type "tuple" is not supported.
|
|
1263
|
+
* ```
|
|
1264
|
+
*
|
|
1265
|
+
* ### Solution
|
|
1266
|
+
*
|
|
1267
|
+
* Provide a valid event input type.
|
|
1268
|
+
*
|
|
1269
|
+
* ```ts twoslash
|
|
1270
|
+
* // @noErrors
|
|
1271
|
+
* import { AbiEvent } from 'ox'
|
|
1272
|
+
*
|
|
1273
|
+
* const transfer = AbiEvent.from('event Transfer((string) indexed a, string b)') // [!code --]
|
|
1274
|
+
* const transfer = AbiEvent.from('event Transfer(string indexed a, string b)') // [!code ++]
|
|
1275
|
+
* ```
|
|
1276
|
+
*
|
|
1277
|
+
*
|
|
1278
|
+
*/
|
|
1279
|
+
export class FilterTypeNotSupportedError extends Errors.BaseError {
|
|
1280
|
+
override readonly name = 'AbiEvent.FilterTypeNotSupportedError'
|
|
1281
|
+
constructor(type: string) {
|
|
1282
|
+
super(`Filter type "${type}" is not supported.`)
|
|
1283
|
+
}
|
|
1284
|
+
}
|