UNPKG

@celo/explorer

Version:
87 lines 3.44 kB
/** * Sourcify (https://sourcify.dev/) helpers for querying * contract metadata when it's available. * * @example * Get the ABI of an arbitrary contract. * ```ts * const metadata = fetchMetadata('42220', '0xF27c7D717B4b7CaD2833a61cb9CA7B61021f9F73') * if (metadata.abi !== null) { * // do something with it. * } */ import { ABIDefinition, AbiInput, AbiItem, Address, Connection } from '@celo/connect'; import { ContractMapping } from './base'; /** ABI input that may have tuple components (runtime ABI data from Solidity) */ export type AbiInputWithComponents = AbiInput & { components?: readonly AbiInputWithComponents[]; }; export declare function formatAbiInputType(input: AbiInputWithComponents): string; /** * MetadataResponse interface for the `metadata.json` file that the sourcify repo returns. * All fields are optional because we don't really _know_ what we get from the API, thus * we need to enforce the structure at runtime. */ export interface MetadataResponse { output?: { abi?: AbiItem[]; }; settings?: { compilationTarget?: Record<string, string>; }; } /** * Wrapper class for a metadata.json response from sourcify. * Because the response's true structure is unknown this wrapper implements * light runtime verification. */ export declare class Metadata { abi: AbiItem[] | null; contractName: string | null; fnMapping: Map<string, ABIDefinition>; private address; constructor(_connection: Connection, address: Address, response: any); set response(value: MetadataResponse); /** * Turn the ABI into a mapping of function selectors to ABI items. */ toContractMapping(): ContractMapping; /** * Find the AbiItem for a given function selector * @param selector the 4-byte selector of the function call * @returns an AbiItem if found or null */ abiForSelector(selector: string): AbiItem | null; /** * Find the AbiItem for methods that match the provided method name. * The function can return more than one AbiItem if the query string * provided doesn't contain arguments as there can be multiple * definitions with different arguments. * @param method name of the method to lookup * @returns and array of AbiItems matching the query */ abiForMethod(query: string): AbiItem[]; } /** * Fetch the contract metadata from Sourcify and instantiate a Metadata wrapper * class around it. Uses the Sourcify v2 API (the v1 repo API has been sunset). * @param connection @celo/connect instance * @param contract the address of the contract to query * @param strict only allow exact matches https://docs.sourcify.dev/docs/exact-match-vs-match/ * @returns Metadata or null */ export declare function fetchMetadata(connection: Connection, contract: Address, strict?: boolean): Promise<Metadata | null>; /** * Use heuristics to determine if the contract can be a proxy * and extract the implementation. * Available scenarios: * - _getImplementation() exists * - getImplementation() exists * - _implementation() exists * - implementation() exists * @param connection @celo/connect instance * @param contract the address of the contract to query * @returns the implementation address or null */ export declare function tryGetProxyImplementation(connection: Connection, contract: Address): Promise<Address | undefined>; //# sourceMappingURL=sourcify.d.ts.map