Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@delvtech/evm-client

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@delvtech/evm-client - npm Package Compare versions

Comparing version
0.3.0
to
0.3.1
+2
dist/chunk-OWBXSX3M.js
import{a as f,b as s}from"./chunk-HB4JKCEF.js";import{a as u}from"./chunk-FJROFRBN.js";import{c as T}from"./chunk-EXKUPYHD.js";T();T();var x=100;function C({contract:e,cache:r=f({max:x}),namespace:i}){let t=Object.getPrototypeOf(e),n=Object.create(t);return Object.assign(n,e,{cache:r,async read(a,o,c){return l({cache:r,key:s([i,"read",{address:e.address,functionName:a,args:o,options:c}]),callback:()=>e.read(a,o,c)})},deleteRead(a,o,c){let b=s([i,"read",{address:e.address,functionName:a,args:o,options:c}]);r.delete(b)},async getEvents(a,o){return l({cache:r,key:s([i,"getEvents",{address:e.address,eventName:a,options:o}]),callback:()=>e.getEvents(a,o)})},clearCache(){r.clear()}})}async function l({cache:e,key:r,callback:i}){let t=e.get(r);return t||(t=await i(),e.set(r,t),t)}T();function E({contract:e,cache:r,namespace:i}){if(h(e))return e;let t=Object.getPrototypeOf(e),n=Object.create(t);return Object.assign(n,C({contract:e,cache:r,namespace:i}))}function h(e){return"clearCache"in e}T();T();function d({abi:e,type:r,name:i}){let t=e.find(n=>n.type===r&&(r==="constructor"||n.name===i));if(!t)throw new u({type:r,name:i});return t}function P({abi:e,type:r,name:i,kind:t,values:n}){let m=d({abi:e,type:r,name:i}),a=[];if(t in m&&(a=m[t]),a.length<=1)return n[0];let o=n||[],c={};return a.forEach(({name:b},A)=>{b?c[b]=o[A]:c[A]=o[A]}),c}T();function R({abi:e,type:r,name:i,kind:t,values:n}){let m=d({abi:e,type:r,name:i}),a=[];t in m&&(a=m[t]);let o=n||[],c={};return a.forEach(({name:b},A)=>{b?c[b]=o[A]:c[A]=o[A]}),c}T();function I({abi:e,type:r,name:i,kind:t,value:n}){let m=d({abi:e,type:r,name:i}),a=[];if(t in m&&(a=m[t]),!a.length)return[];let o=n&&typeof n=="object"?n:{},c=[];return a.forEach(({name:b},A)=>{c.push(o[b||A])}),c}export{C as a,E as b,d as c,P as d,R as e,I as f};
//# sourceMappingURL=chunk-OWBXSX3M.js.map
{"version":3,"sources":["../src/exports/contract.ts","../src/contract/factories/createCachedReadContract.ts","../src/contract/factories/createCachedReadWriteContract.ts","../src/contract/utils/arrayToFriendly.ts","../src/contract/utils/getAbiEntry.ts","../src/contract/utils/arrayToObject.ts","../src/contract/utils/objectToArray.ts"],"sourcesContent":["// Factories\nexport {\n createCachedReadContract,\n type CreateCachedReadContractOptions,\n} from 'src/contract/factories/createCachedReadContract';\nexport {\n createCachedReadWriteContract,\n type CreateCachedReadWriteContractOptions,\n} from 'src/contract/factories/createCachedReadWriteContract';\n\n// Types\nexport type {\n AbiArrayType,\n AbiEntry,\n AbiEntryName,\n AbiFriendlyType,\n AbiObjectType,\n AbiParameters,\n} from 'src/contract/types/AbiEntry';\nexport type {\n CachedReadContract,\n CachedReadWriteContract,\n} from 'src/contract/types/CachedContract';\nexport type {\n ContractDecodeFunctionDataArgs,\n ContractEncodeFunctionDataArgs,\n ContractGetEventsArgs,\n ContractGetEventsOptions,\n ContractReadArgs,\n ContractReadOptions,\n ContractWriteArgs,\n ContractWriteOptions,\n ReadContract,\n ReadWriteContract,\n} from 'src/contract/types/Contract';\nexport type {\n Event,\n EventArgs,\n EventFilter,\n EventName,\n} from 'src/contract/types/Event';\nexport type {\n DecodedFunctionData,\n FunctionArgs,\n FunctionName,\n FunctionReturn,\n} from 'src/contract/types/Function';\n\n// Utils\nexport { arrayToFriendly } from 'src/contract/utils/arrayToFriendly';\nexport { arrayToObject } from 'src/contract/utils/arrayToObject';\nexport { getAbiEntry } from 'src/contract/utils/getAbiEntry';\nexport { objectToArray } from 'src/contract/utils/objectToArray';\n","import { Abi } from 'abitype';\nimport { createLruSimpleCache } from 'src/cache/factories/createLruSimpleCache';\nimport { SimpleCache, SimpleCacheKey } from 'src/cache/types/SimpleCache';\nimport { createSimpleCacheKey } from 'src/cache/utils/createSimpleCacheKey';\nimport { CachedReadContract } from 'src/contract/types/CachedContract';\nimport { ReadContract } from 'src/contract/types/Contract';\n\n// TODO: Figure out a good default cache size\nconst DEFAULT_CACHE_SIZE = 100;\n\nexport interface CreateCachedReadContractOptions<TAbi extends Abi = Abi> {\n contract: ReadContract<TAbi>;\n cache?: SimpleCache;\n /**\n * A namespace to distinguish this instance from others in the cache by\n * prefixing all cache keys.\n */\n namespace?: string;\n}\n\n/**\n * A wrapped Ethereum contract reader that provides caching capabilities. Useful\n * for reducing the number of actual reads from a contract by caching and\n * reusing previous read results.\n *\n * @example\n * const cachedContract = new CachedReadContract({ contract: myContract });\n * const result1 = await cachedContract.read(\"functionName\", args);\n * const result2 = await cachedContract.read(\"functionName\", args); // Fetched from cache\n */\nexport function createCachedReadContract<TAbi extends Abi = Abi>({\n contract,\n cache = createLruSimpleCache({ max: DEFAULT_CACHE_SIZE }),\n namespace,\n}: CreateCachedReadContractOptions<TAbi>): CachedReadContract<TAbi> {\n // Because this is part of the public API, we won't know if the original\n // contract is a plain object or a class instance, so we use Object.create to\n // preserve the original contract's prototype chain when extending, ensuring\n // the new contract includes all the original contract's methods and\n // instanceof checks will still work.\n const contractPrototype = Object.getPrototypeOf(contract);\n const newContract = Object.create(contractPrototype);\n\n const overrides: Partial<CachedReadContract<TAbi>> = {\n cache,\n\n /**\n * Reads data from the contract. First checks the cache, and if not present,\n * fetches from the contract and then caches the result.\n */\n async read(functionName, args, options) {\n return getOrSet({\n cache,\n key: createSimpleCacheKey([\n namespace,\n 'read',\n {\n address: contract.address,\n functionName,\n args,\n options,\n },\n ]),\n\n callback: () => contract.read(functionName, args, options),\n });\n },\n\n /**\n * Deletes a specific read from the cache.\n *\n * @example\n * const cachedContract = new CachedReadContract({ contract: myContract });\n * const result1 = await cachedContract.read(\"functionName\", args);\n * const result2 = await cachedContract.read(\"functionName\", args); // Fetched from cache\n *\n * cachedContract.deleteRead(\"functionName\", args);\n * const result3 = await cachedContract.read(\"functionName\", args); // Fetched from contract\n */\n deleteRead(functionName, args, options) {\n const key = createSimpleCacheKey([\n namespace,\n 'read',\n {\n address: contract.address,\n functionName,\n args,\n options,\n },\n ]);\n\n cache.delete(key);\n },\n\n /**\n * Gets events from the contract. First checks the cache, and if not present,\n * fetches from the contract and then caches the result.\n */\n async getEvents(eventName, options) {\n return getOrSet({\n cache,\n key: createSimpleCacheKey([\n namespace,\n 'getEvents',\n {\n address: contract.address,\n eventName,\n options,\n },\n ]),\n callback: () => contract.getEvents(eventName, options),\n });\n },\n\n /**\n * Clears the entire cache.\n */\n clearCache() {\n cache.clear();\n },\n };\n\n return Object.assign(newContract, contract, overrides);\n}\n\nasync function getOrSet<TValue>({\n cache,\n key,\n callback,\n}: {\n cache: SimpleCache;\n key: SimpleCacheKey;\n callback: () => Promise<TValue> | TValue;\n}): Promise<TValue> {\n let value = cache.get(key);\n if (value) {\n return value;\n }\n\n value = await callback();\n cache.set(key, value);\n\n return value;\n}\n","import { Abi } from 'abitype';\nimport {\n CreateCachedReadContractOptions,\n createCachedReadContract,\n} from 'src/contract/factories/createCachedReadContract';\nimport { CachedReadWriteContract } from 'src/contract/types/CachedContract';\nimport { ReadWriteContract } from 'src/contract/types/Contract';\n\nexport interface CreateCachedReadWriteContractOptions<TAbi extends Abi = Abi>\n extends CreateCachedReadContractOptions<TAbi> {\n contract: ReadWriteContract<TAbi>;\n}\n\n/**\n * Provides a cached wrapper around an Ethereum writable contract. This class is\n * useful for both reading (with caching) and writing to a contract. It extends\n * the functionality provided by CachedReadContract by adding write\n * capabilities.\n */\nexport function createCachedReadWriteContract<TAbi extends Abi = Abi>({\n contract,\n cache,\n namespace,\n}: CreateCachedReadWriteContractOptions<TAbi>): CachedReadWriteContract<TAbi> {\n // Avoid double-caching if given a contract that already has a cache.\n if (isCached(contract)) {\n return contract;\n }\n // Because this is part of the public API, we won't know if the original\n // contract is a plain object or a class instance, so we use Object.create to\n // preserve the original contract's prototype chain when extending, ensuring\n // the new contract includes all the original contract's methods and\n // instanceof checks will still work.\n const contractPrototype = Object.getPrototypeOf(contract);\n const newContract = Object.create(contractPrototype);\n return Object.assign(\n newContract,\n createCachedReadContract({ contract, cache, namespace }),\n );\n}\n\nfunction isCached<TAbi extends Abi>(\n contract: ReadWriteContract<TAbi>,\n): contract is CachedReadWriteContract<TAbi> {\n return 'clearCache' in contract;\n}\n","import { Abi, AbiItemType, AbiParameter, AbiParameterKind } from 'abitype';\nimport {\n AbiArrayType,\n AbiEntryName,\n AbiFriendlyType,\n} from 'src/contract/types/AbiEntry';\nimport { getAbiEntry } from 'src/contract/utils/getAbiEntry';\n\n/**\n * Converts an array of input or output values into an\n * {@linkcode AbiFriendlyType}, ensuring the values are properly identified\n * based on their index.\n *\n * @example\n * const abi = [\n * {\n * type: \"function\",\n * name: \"transfer\",\n * inputs: [\n * { name: \"to\", type: \"address\" },\n * { name: \"value\", type: \"uint256\" },\n * ],\n * outputs: [{ name: \"\", type: \"bool\" }],\n * stateMutability: \"nonpayable\",\n * },\n * {\n * type: \"event\",\n * name: \"Approval\",\n * inputs: [\n * { indexed: true, name: \"owner\", type: \"address\" },\n * { indexed: true, name: \"spender\", type: \"address\" },\n * { indexed: false, name: \"value\", type: \"uint256\" },\n * ],\n * },\n * ] as const;\n *\n * const parsedArgs = arrayToFriendly({\n * abi,\n * type: \"function\",\n * name: \"transfer\",\n * kind: \"inputs\",\n * values: [\"0x123\", 123n],\n * }); // -> { to: \"0x123\", value: 123n }\n *\n * const parsedReturn = arrayToFriendly({\n * abi,\n * type: \"function\",\n * name: \"transfer\",\n * kind: \"outputs\",\n * values: [true],\n * }); // -> true\n *\n * const parsedFilter = arrayToFriendly({\n * abi,\n * type: \"event\",\n * name: \"Approval\",\n * kind: \"inputs\",\n * values: [undefined, \"0x123\", undefined],\n * }); // -> { owner: undefined, spender: \"0x123\", value: undefined }\n */\nexport function arrayToFriendly<\n TAbi extends Abi,\n TItemType extends AbiItemType,\n TName extends AbiEntryName<TAbi, TItemType>,\n TParameterKind extends AbiParameterKind,\n>({\n abi,\n type,\n name,\n kind,\n values,\n}: {\n abi: TAbi;\n name: TName;\n values?: Abi extends TAbi\n ? readonly unknown[] // <- fallback for unknown ABI type\n : Partial<AbiArrayType<TAbi, TItemType, TName, TParameterKind>>;\n kind: TParameterKind;\n type: TItemType;\n}): AbiFriendlyType<TAbi, TItemType, TName, TParameterKind> {\n const abiEntry = getAbiEntry({ abi, type, name });\n\n let parameters: AbiParameter[] = [];\n if (kind in abiEntry) {\n parameters = (abiEntry as any)[kind];\n }\n\n // Single or no parameters\n if (parameters.length <= 1) {\n return (values as any[])[0];\n }\n\n const valuesArray = values || [];\n\n const friendlyValue: Record<string, any> = {};\n parameters.forEach(({ name }, i) => {\n if (name) {\n friendlyValue[name] = valuesArray[i];\n } else {\n friendlyValue[i] = valuesArray[i];\n }\n });\n\n return friendlyValue as any;\n}\n","import { Abi, AbiItemType } from 'abitype';\nimport { AbiEntry, AbiEntryName } from 'src/contract/types/AbiEntry';\nimport { AbiEntryNotFoundError } from 'src/errors/AbiEntryNotFound';\n\n/**\n * Get an entry from an ABI by type and name.\n * @throws If the entry is not found in the ABI.\n */\nexport function getAbiEntry<\n TAbi extends Abi,\n TItemType extends AbiItemType,\n TName extends AbiEntryName<TAbi, TItemType>,\n>({\n abi,\n type,\n name,\n}: {\n abi: TAbi;\n type: TItemType;\n name?: TName;\n}): AbiEntry<TAbi, TItemType, TName> {\n const abiItem = abi.find(\n (item) =>\n item.type === type &&\n (type === 'constructor' || (item as any).name === name),\n ) as AbiEntry<TAbi, TItemType, TName> | undefined;\n\n if (!abiItem) {\n throw new AbiEntryNotFoundError({ type, name });\n }\n\n return abiItem;\n}\n","import { Abi, AbiItemType, AbiParameter, AbiParameterKind } from 'abitype';\nimport {\n AbiArrayType,\n AbiEntryName,\n AbiObjectType,\n} from 'src/contract/types/AbiEntry';\nimport { getAbiEntry } from 'src/contract/utils/getAbiEntry';\n\n/**\n * Converts an array of input or output values into an object typ, ensuring the\n * values are properly identified based on their index.\n *\n * @example\n * const abi = [\n * {\n * type: \"function\",\n * name: \"transfer\",\n * inputs: [\n * { name: \"to\", type: \"address\" },\n * { name: \"value\", type: \"uint256\" },\n * ],\n * outputs: [{ name: \"\", type: \"bool\" }],\n * stateMutability: \"nonpayable\",\n * },\n * {\n * type: \"event\",\n * name: \"Approval\",\n * inputs: [\n * { indexed: true, name: \"owner\", type: \"address\" },\n * { indexed: true, name: \"spender\", type: \"address\" },\n * { indexed: false, name: \"value\", type: \"uint256\" },\n * ],\n * },\n * ] as const;\n *\n * const parsedArgs = arrayToObject({\n * abi,\n * type: \"function\",\n * name: \"transfer\",\n * kind: \"inputs\",\n * values: [\"0x123\", 123n],\n * }); // -> { to: \"0x123\", value: 123n }\n *\n * const parsedFilter = arrayToObject({\n * abi,\n * type: \"event\",\n * name: \"Approval\",\n * kind: \"inputs\",\n * values: [undefined, \"0x123\", undefined],\n * }); // -> { owner: undefined, spender: \"0x123\", value: undefined }\n */\nexport function arrayToObject<\n TAbi extends Abi,\n TItemType extends AbiItemType,\n TName extends AbiEntryName<TAbi, TItemType>,\n TParameterKind extends AbiParameterKind,\n>({\n abi,\n type,\n name,\n kind,\n values,\n}: {\n abi: TAbi;\n name: TName;\n values?: Abi extends TAbi\n ? readonly unknown[] // <- fallback for unknown ABI type\n : Partial<AbiArrayType<TAbi, TItemType, TName, TParameterKind>>;\n kind: TParameterKind;\n type: TItemType;\n}): AbiObjectType<TAbi, TItemType, TName, TParameterKind> {\n const abiEntry = getAbiEntry({ abi, type, name });\n\n let parameters: AbiParameter[] = [];\n if (kind in abiEntry) {\n parameters = (abiEntry as any)[kind];\n }\n\n const valuesArray = values || [];\n\n const valuesObject: Record<string, any> = {};\n parameters.forEach(({ name }, i) => {\n if (name) {\n valuesObject[name] = valuesArray[i];\n } else {\n valuesObject[i] = valuesArray[i];\n }\n });\n\n return valuesObject as any;\n}\n","import { Abi, AbiItemType, AbiParameter, AbiParameterKind } from 'abitype';\nimport {\n AbiArrayType,\n AbiEntryName,\n AbiObjectType,\n} from 'src/contract/types/AbiEntry';\nimport { getAbiEntry } from 'src/contract/utils/getAbiEntry';\n\n/**\n * Converts an object into an array of input or output values, ensuring the the\n * correct number and order of values are present.\n *\n * @example\n * const abi = [\n * {\n * type: \"function\",\n * name: \"transfer\",\n * inputs: [\n * { name: \"to\", type: \"address\" },\n * { name: \"value\", type: \"uint256\" },\n * ],\n * outputs: [{ name: \"\", type: \"bool\" }],\n * stateMutability: \"nonpayable\",\n * },\n * {\n * type: \"event\",\n * name: \"Approval\",\n * inputs: [\n * { indexed: true, name: \"owner\", type: \"address\" },\n * { indexed: true, name: \"spender\", type: \"address\" },\n * { indexed: false, name: \"value\", type: \"uint256\" },\n * ],\n * },\n * ] as const;\n *\n * const preppedArgs = objectToArray({\n * abi,\n * type: \"function\",\n * name: \"transfer\",\n * kind: \"inputs\",\n * value: { value: 123n, to: \"0x123\" },\n * }); // -> [\"0x123\", 123n]\n *\n * const preppedFilter = objectToArray({\n * abi,\n * type: \"event\",\n * name: \"Approval\",\n * kind: \"inputs\",\n * value: { spender: \"0x123\" },\n * }); // -> [undefined, \"0x123\", undefined]\n */\nexport function objectToArray<\n TAbi extends Abi,\n TItemType extends AbiItemType,\n TName extends AbiEntryName<TAbi, TItemType>,\n TParameterKind extends AbiParameterKind,\n TValue extends AbiObjectType<TAbi, TItemType, TName, TParameterKind>,\n>({\n abi,\n type,\n name,\n kind,\n value,\n}: {\n abi: TAbi;\n name: TName;\n kind: TParameterKind;\n type: TItemType;\n value?: Abi extends TAbi ? Record<string, unknown> : TValue;\n}): AbiArrayType<TAbi, TItemType, TName, TParameterKind> {\n const abiEntry = getAbiEntry({ abi, type, name });\n\n let parameters: AbiParameter[] = [];\n if (kind in abiEntry) {\n parameters = (abiEntry as any)[kind];\n }\n\n // No parameters\n if (!parameters.length) {\n return [] as AbiArrayType<TAbi, TItemType, TName, TParameterKind>;\n }\n\n const valueObject: Record<string, unknown> =\n value && typeof value === 'object' ? value : {};\n\n const array: unknown[] = [];\n parameters.forEach(({ name }, i) => {\n array.push(valueObject[name || i]);\n });\n\n return array as AbiArrayType<TAbi, TItemType, TName, TParameterKind>;\n}\n"],"mappings":"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","names":["init_esm_shims","init_esm_shims","DEFAULT_CACHE_SIZE","createCachedReadContract","contract","cache","createLruSimpleCache","namespace","contractPrototype","newContract","functionName","args","options","getOrSet","createSimpleCacheKey","key","eventName","callback","value","init_esm_shims","createCachedReadWriteContract","contract","cache","namespace","isCached","contractPrototype","newContract","createCachedReadContract","init_esm_shims","init_esm_shims","getAbiEntry","abi","type","name","abiItem","item","AbiEntryNotFoundError","arrayToFriendly","abi","type","name","kind","values","abiEntry","getAbiEntry","parameters","valuesArray","friendlyValue","i","init_esm_shims","arrayToObject","abi","type","name","kind","values","abiEntry","getAbiEntry","parameters","valuesArray","valuesObject","i","init_esm_shims","objectToArray","abi","type","name","kind","value","abiEntry","getAbiEntry","parameters","valueObject","array","i"]}
import { Abi, AbiItemType, AbiStateMutability, AbiParameterKind, AbiParameter, AbiParametersToPrimitiveTypes, AbiParameterToPrimitiveType } from 'abitype';
import { a as BlockTag } from './Block-D7itLNye.js';
type EmptyObject = Record<string, never>;
/**
* Combines members of an intersection into a readable type.
* @see https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg
*/
type Prettify<T> = {
[K in keyof T]: T[K];
} & unknown;
type NamedAbiParameter = AbiParameter & {
name: string;
};
/**
* Get a union of possible names for an abi item type.
*
* @example
* type Erc20EventNames = AbiEntryName<Erc20Abi, "event">;
* // -> "Approval" | "Transfer"
*/
type AbiEntryName<TAbi extends Abi, TItemType extends AbiItemType = AbiItemType> = Extract<TAbi[number], {
type: TItemType;
name?: string;
}>['name'];
/**
* Get the ABI entry for a specific type, name, and state mutability.
*
* @example
* type ApproveEntry = AbiEntry<Erc20Abi, "function", "approve">;
* // ->
* // {
* // type: "function";
* // name: "approve";
* // inputs: [{ name: "spender", type: "address" }, { name: "value", type: "uint256" }];
* // outputs: [{ name: "", type: "bool" }];
* // stateMutability: "nonpayable";
* // }
*/
type AbiEntry<TAbi extends Abi, TItemType extends AbiItemType = AbiItemType, TName extends AbiEntryName<TAbi, TItemType> = AbiEntryName<TAbi, TItemType>, TStateMutability extends AbiStateMutability = AbiStateMutability> = Extract<TAbi[number], {
type: TItemType;
name?: TName;
stateMutability?: TStateMutability;
}>;
/**
* Get the parameters for a specific ABI entry.
*
* @example
* type ApproveParameters = AbiParameters<Erc20Abi, "function", "approve", "inputs">;
* // -> [{ name: "spender", type: "address" }, { name: "value", type: "uint256" }]
*/
type AbiParameters<TAbi extends Abi = Abi, TItemType extends AbiItemType = AbiItemType, TName extends AbiEntryName<TAbi, TItemType> = AbiEntryName<TAbi, TItemType>, TParameterKind extends AbiParameterKind = AbiParameterKind> = AbiEntry<TAbi, TItemType, TName> extends infer TAbiEntry ? TParameterKind extends keyof TAbiEntry ? TAbiEntry[TParameterKind] : [] : [];
/**
* Add default names to any ABI parameters that are missing a name. The default
* name is the index of the parameter.
*/
type WithDefaultNames<TParameters extends readonly AbiParameter[]> = {
[K in keyof TParameters]: TParameters[K] extends infer TParameter extends AbiParameter ? TParameter extends NamedAbiParameter ? TParameter : TParameter & {
name: `${K}`;
} : never;
};
/**
* Convert an array or tuple of named abi parameters to an object type with the
* parameter names as keys and their primitive types as values. If a parameter
* has no name, it's index is used as the key.
*/
type NamedParametersToObject<TParameters extends readonly NamedAbiParameter[], TParameterKind extends AbiParameterKind = AbiParameterKind> = Prettify<{
[TName in Exclude<TParameters[number]['name'], ''>]: AbiParameterToPrimitiveType<Extract<TParameters[number], {
name: TName;
}>, TParameterKind>;
} & (TParameters extends readonly [NamedAbiParameter, ...NamedAbiParameter[]] ? {
[K in keyof TParameters as TParameters[K] extends NamedAbiParameter ? TParameters[K]['name'] extends '' ? Exclude<K, number> : never : never]: TParameters[K] extends NamedAbiParameter ? AbiParameterToPrimitiveType<TParameters[K], TParameterKind> : never;
} : Extract<TParameters[number], {
name: '';
}> extends never ? unknown : {
[index: number]: AbiParameterToPrimitiveType<Extract<TParameters[number], {
name: '';
}>, 'inputs'>;
})>;
/**
* Convert an array or tuple of abi parameters to an object type.
*
* @example
* type ApproveArgs = AbiParametersToObject<[
* { name: "spender", type: "address" },
* { name: "value", type: "uint256" }
* ]>; // -> { spender: `${string}`, value: bigint }
*/
type AbiParametersToObject<TParameters extends readonly AbiParameter[], TParameterKind extends AbiParameterKind = AbiParameterKind> = TParameters extends readonly [] ? EmptyObject : TParameters extends NamedAbiParameter[] ? NamedParametersToObject<TParameters, TParameterKind> : NamedParametersToObject<WithDefaultNames<TParameters>, TParameterKind>;
/**
* Get an array of primitive types for any ABI parameters.
*
* @example
* type ApproveInput = AbiArrayType<Erc20Abi, "function", "approve", "inputs">;
* // -> [`${string}`, bigint]
*
* type BalanceOutput = AbiArrayType<Erc20Abi, "function", "balanceOf", "outputs">;
* // -> [bigint]
*/
type AbiArrayType<TAbi extends Abi, TItemType extends AbiItemType = AbiItemType, TName extends AbiEntryName<TAbi, TItemType> = AbiEntryName<TAbi, TItemType>, TParameterKind extends AbiParameterKind = AbiParameterKind> = AbiParameters<TAbi, TItemType, TName, TParameterKind> extends infer TParameters ? TParameters extends readonly AbiParameter[] ? AbiParametersToPrimitiveTypes<TParameters> : [] : [];
/**
* Get an object of primitive types for any ABI parameters.
*
* @example
* type ApproveArgs = AbiObjectType<Erc20Abi, "function", "approve", "inputs">;
* // -> { spender: `${string}`, value: bigint }
*
* type Balance = AbiObjectType<Erc20Abi, "function", "balanceOf", "outputs">;
* // -> { balance: bigint }
*/
type AbiObjectType<TAbi extends Abi, TItemType extends AbiItemType = AbiItemType, TName extends AbiEntryName<TAbi, TItemType> = AbiEntryName<TAbi, TItemType>, TParameterKind extends AbiParameterKind = AbiParameterKind> = AbiParametersToObject<AbiParameters<TAbi, TItemType, TName, TParameterKind>>;
/**
* Get a user-friendly primitive type for any ABI parameters, which is
* determined by the number of parameters:
* - __Single parameter:__ the primitive type of the parameter.
* - __Multiple parameters:__ an object with the parameter names as keys and the
* their primitive types as values. If a parameter has no name, it's index is
* used as the key.
* - __No parameters:__ `undefined`.
*
* @example
* type ApproveArgs = AbiFriendlyType<Erc20Abi, "function", "approve", "inputs">;
* // -> { spender: `${string}`, value: bigint }
*
* type Balance = AbiFriendlyType<Erc20Abi, "function", "balanceOf", "outputs">;
* // -> bigint
*
* type DecimalArgs = AbiFriendlyType<Erc20Abi, "function", "decimals", "inputs">;
* // -> undefined
*/
type AbiFriendlyType<TAbi extends Abi, TItemType extends AbiItemType = AbiItemType, TName extends AbiEntryName<TAbi, TItemType> = AbiEntryName<TAbi, TItemType>, TParameterKind extends AbiParameterKind = AbiParameterKind, TStateMutability extends AbiStateMutability = AbiStateMutability> = AbiEntry<TAbi, TItemType, TName, TStateMutability> extends infer TAbiEntry ? TParameterKind extends keyof TAbiEntry & AbiParameterKind ? TAbiEntry[TParameterKind] extends readonly [AbiParameter] ? AbiParameterToPrimitiveType<TAbiEntry[TParameterKind][0], TParameterKind> : TAbiEntry[TParameterKind] extends readonly [
AbiParameter,
...AbiParameter[]
] ? AbiParametersToObject<TAbiEntry[TParameterKind], TParameterKind> : undefined : undefined : undefined;
/**
* Get a union of event names from an abi
*/
type EventName<TAbi extends Abi> = AbiEntry<TAbi, 'event'>['name'];
/**
* Get a union of named input parameters for an event from an abi
*/
type NamedEventInput<TAbi extends Abi, TEventName extends EventName<TAbi>> = Extract<AbiParameters<TAbi, 'event', TEventName, 'inputs'>[number], NamedAbiParameter>;
/**
* Get an object type for an event's arguments from an abi.
*/
type EventArgs<TAbi extends Abi, TEventName extends EventName<TAbi>> = AbiObjectType<TAbi, 'event', TEventName, 'inputs'>;
/**
* Get a union of indexed input objects for an event from an abi
*/
type IndexedEventInput<TAbi extends Abi, TEventName extends EventName<TAbi>> = Extract<NamedEventInput<TAbi, TEventName>, {
indexed: true;
}>;
/**
* Get an object type for an event's indexed fields from an abi
*/
type EventFilter<TAbi extends Abi, TEventName extends EventName<TAbi>> = Partial<AbiParametersToObject<IndexedEventInput<TAbi, TEventName>[], 'inputs'>>;
/**
* A strongly typed event object based on an abi
*/
interface Event<TAbi extends Abi, TEventName extends EventName<TAbi> = EventName<TAbi>> {
eventName: TEventName;
args: EventArgs<TAbi, TEventName>;
data?: `0x${string}`;
blockNumber?: bigint;
transactionHash?: `0x${string}`;
}
/**
* Get a union of function names from an abi
*/
type FunctionName<TAbi extends Abi, TAbiStateMutability extends AbiStateMutability = AbiStateMutability> = Extract<TAbi[number], {
type: 'function';
stateMutability: TAbiStateMutability;
}>['name'];
/**
* Get an object type for an abi function's arguments.
*/
type FunctionArgs<TAbi extends Abi, TFunctionName extends FunctionName<TAbi> = FunctionName<TAbi>> = AbiObjectType<TAbi, 'function', TFunctionName, 'inputs'>;
/**
* Get a user-friendly return type for an abi function, which is determined by
* it's outputs:
* - __Single output:__ the type of the single output.
* - __Multiple outputs:__ an object with the output names as keys and the
* output types as values.
* - __No outputs:__ `undefined`.
*/
type FunctionReturn<TAbi extends Abi, TFunctionName extends FunctionName<TAbi>> = AbiFriendlyType<TAbi, 'function', TFunctionName, 'outputs'>;
/**
* Get an object representing decoded function or constructor data from an ABI.
*/
type DecodedFunctionData<TAbi extends Abi, TFunctionName extends FunctionName<TAbi>> = {
[K in TFunctionName]: {
args: FunctionArgs<TAbi, K>;
functionName: K;
};
}[TFunctionName];
/**
* Interface representing a readable contract with specified ABI. Provides type
* safe methods to read and simulate write operations on the contract.
*/
interface ReadContract<TAbi extends Abi = Abi> {
abi: TAbi;
address: `0x${string}`;
/**
* Reads a specified function from the contract.
*/
read<TFunctionName extends FunctionName<TAbi, 'pure' | 'view'>>(...args: ContractReadArgs<TAbi, TFunctionName>): Promise<FunctionReturn<TAbi, TFunctionName>>;
/**
* Simulates a write operation on a specified function of the contract.
*/
simulateWrite<TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>>(...args: ContractWriteArgs<TAbi, TFunctionName>): Promise<FunctionReturn<TAbi, TFunctionName>>;
/**
* Retrieves specified events from the contract.
*/
getEvents<TEventName extends EventName<TAbi>>(...args: ContractGetEventsArgs<TAbi, TEventName>): Promise<Event<TAbi, TEventName>[]>;
/**
* Encodes a function call into calldata.
*/
encodeFunctionData<TFunctionName extends FunctionName<TAbi>>(...args: ContractEncodeFunctionDataArgs<TAbi, TFunctionName>): `0x${string}`;
/**
* Decodes a string of function calldata into it's arguments and function
* name.
*/
decodeFunctionData<TFunctionName extends FunctionName<TAbi> = FunctionName<TAbi>>(...args: ContractDecodeFunctionDataArgs): DecodedFunctionData<TAbi, TFunctionName>;
}
/**
* Interface representing a writable contract with specified ABI.
* Extends IReadContract to also include write operations.
*/
interface ReadWriteContract<TAbi extends Abi = Abi> extends ReadContract<TAbi> {
/**
* Get the address of the signer for this contract.
*/
getSignerAddress(): Promise<`0x${string}`>;
/**
* Writes to a specified function on the contract.
* @returns The transaction hash of the submitted transaction.
*/
write<TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>>(...args: ContractWriteArgs<TAbi, TFunctionName>): Promise<`0x${string}`>;
}
type ContractReadOptions = {
blockNumber?: bigint;
blockTag?: never;
} | {
blockNumber?: never;
/**
* @default 'latest'
*/
blockTag?: BlockTag;
};
type ContractReadArgs<TAbi extends Abi, TFunctionName extends FunctionName<TAbi>> = FunctionArgs<TAbi, TFunctionName> extends EmptyObject ? [
functionName: TFunctionName,
args?: FunctionArgs<TAbi, TFunctionName>,
options?: ContractReadOptions
] : [
functionName: TFunctionName,
args: FunctionArgs<TAbi, TFunctionName>,
options?: ContractReadOptions
];
interface ContractGetEventsOptions<TAbi extends Abi, TEventName extends EventName<TAbi> = EventName<TAbi>> {
filter?: EventFilter<TAbi, TEventName>;
fromBlock?: bigint | BlockTag;
toBlock?: bigint | BlockTag;
}
type ContractGetEventsArgs<TAbi extends Abi, TEventName extends EventName<TAbi>> = [
eventName: TEventName,
options?: ContractGetEventsOptions<TAbi, TEventName>
];
interface ContractWriteOptions {
type?: `0x${string}`;
nonce?: bigint;
to?: `0x${string}`;
from?: `0x${string}`;
/**
* Gas limit
*/
gas?: bigint;
value?: bigint;
input?: `0x${string}`;
/**
* The gas price willing to be paid by the sender in wei
*/
gasPrice?: bigint;
/**
* Maximum fee per gas the sender is willing to pay to miners in wei
*/
maxPriorityFeePerGas?: bigint;
/**
* The maximum total fee per gas the sender is willing to pay (includes the
* network / base fee and miner / priority fee) in wei
*/
maxFeePerGas?: bigint;
/**
* EIP-2930 access list
*/
accessList?: {
address: `0x${string}`;
storageKeys: `0x${string}`[];
}[];
/**
* Chain ID that this transaction is valid on.
*/
chainId?: bigint;
}
type ContractWriteArgs<TAbi extends Abi, TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>> = FunctionArgs<TAbi, TFunctionName> extends EmptyObject ? [
functionName: TFunctionName,
args?: FunctionArgs<TAbi, TFunctionName>,
options?: ContractWriteOptions
] : [
functionName: TFunctionName,
args: FunctionArgs<TAbi, TFunctionName>,
options?: ContractWriteOptions
];
type ContractEncodeFunctionDataArgs<TAbi extends Abi, TFunctionName extends FunctionName<TAbi>> = FunctionArgs<TAbi, TFunctionName> extends EmptyObject ? [functionName: TFunctionName, args?: FunctionArgs<TAbi, TFunctionName>] : [functionName: TFunctionName, args: FunctionArgs<TAbi, TFunctionName>];
type ContractDecodeFunctionDataArgs = [data: `0x${string}`];
export type { AbiArrayType as A, ContractDecodeFunctionDataArgs as C, DecodedFunctionData as D, Event as E, FunctionArgs as F, ReadContract as R, AbiEntry as a, AbiEntryName as b, AbiFriendlyType as c, AbiObjectType as d, AbiParameters as e, ContractEncodeFunctionDataArgs as f, ContractGetEventsArgs as g, ContractGetEventsOptions as h, ContractReadArgs as i, ContractReadOptions as j, ContractWriteArgs as k, ContractWriteOptions as l, ReadWriteContract as m, EventArgs as n, EventFilter as o, EventName as p, FunctionName as q, FunctionReturn as r };
+4
-4
import { Abi, AbiItemType, AbiParameterKind } from 'abitype';
import { S as SimpleCache } from './SimpleCache-zKWlOPyg.js';
import { R as ReadContract, q as FunctionName, i as ContractReadArgs, m as ReadWriteContract, b as AbiEntryName, A as AbiArrayType, c as AbiFriendlyType, d as AbiObjectType, a as AbiEntry } from './Contract-C2u5sI2x.js';
export { e as AbiParameters, C as ContractDecodeFunctionDataArgs, f as ContractEncodeFunctionDataArgs, g as ContractGetEventsArgs, h as ContractGetEventsOptions, j as ContractReadOptions, k as ContractWriteArgs, l as ContractWriteOptions, D as DecodedFunctionData, E as Event, n as EventArgs, o as EventFilter, p as EventName, F as FunctionArgs, r as FunctionReturn } from './Contract-C2u5sI2x.js';
import { R as ReadContract, q as FunctionName, i as ContractReadArgs, m as ReadWriteContract, b as AbiEntryName, A as AbiArrayType, c as AbiFriendlyType, d as AbiObjectType, a as AbiEntry } from './Contract-BIGb9LmL.js';
export { e as AbiParameters, C as ContractDecodeFunctionDataArgs, f as ContractEncodeFunctionDataArgs, g as ContractGetEventsArgs, h as ContractGetEventsOptions, j as ContractReadOptions, k as ContractWriteArgs, l as ContractWriteOptions, D as DecodedFunctionData, E as Event, n as EventArgs, o as EventFilter, p as EventName, F as FunctionArgs, r as FunctionReturn } from './Contract-BIGb9LmL.js';
import './Block-D7itLNye.js';

@@ -212,10 +212,10 @@

*/
declare function objectToArray<TAbi extends Abi, TItemType extends AbiItemType, TName extends AbiEntryName<TAbi, TItemType>, TParameterKind extends AbiParameterKind>({ abi, type, name, kind, value, }: {
declare function objectToArray<TAbi extends Abi, TItemType extends AbiItemType, TName extends AbiEntryName<TAbi, TItemType>, TParameterKind extends AbiParameterKind, TValue extends AbiObjectType<TAbi, TItemType, TName, TParameterKind>>({ abi, type, name, kind, value, }: {
abi: TAbi;
name: TName;
value?: Abi extends TAbi ? Record<string, unknown> : Partial<AbiObjectType<TAbi, TItemType, TName, TParameterKind>>;
kind: TParameterKind;
type: TItemType;
value?: Abi extends TAbi ? Record<string, unknown> : TValue;
}): AbiArrayType<TAbi, TItemType, TName, TParameterKind>;
export { AbiArrayType, AbiEntry, AbiEntryName, AbiFriendlyType, AbiObjectType, type CachedReadContract, type CachedReadWriteContract, ContractReadArgs, type CreateCachedReadContractOptions, type CreateCachedReadWriteContractOptions, FunctionName, ReadContract, ReadWriteContract, arrayToFriendly, arrayToObject, createCachedReadContract, createCachedReadWriteContract, getAbiEntry, objectToArray };

@@ -1,2 +0,2 @@

import{a,b,c,d,e,f}from"./chunk-FI3KYCOV.js";import"./chunk-HB4JKCEF.js";import"./chunk-FJROFRBN.js";import"./chunk-EXKUPYHD.js";export{d as arrayToFriendly,e as arrayToObject,a as createCachedReadContract,b as createCachedReadWriteContract,c as getAbiEntry,f as objectToArray};
import{a,b,c,d,e,f}from"./chunk-OWBXSX3M.js";import"./chunk-HB4JKCEF.js";import"./chunk-FJROFRBN.js";import"./chunk-EXKUPYHD.js";export{d as arrayToFriendly,e as arrayToObject,a as createCachedReadContract,b as createCachedReadWriteContract,c as getAbiEntry,f as objectToArray};
//# sourceMappingURL=contract.js.map
export { createLruSimpleCache, createSimpleCacheKey } from './cache.js';
export { S as SimpleCache, a as SimpleCacheKey } from './SimpleCache-zKWlOPyg.js';
export { CachedReadContract, CachedReadWriteContract, CreateCachedReadContractOptions, CreateCachedReadWriteContractOptions, arrayToFriendly, arrayToObject, createCachedReadContract, createCachedReadWriteContract, getAbiEntry, objectToArray } from './contract.js';
export { A as AbiArrayType, a as AbiEntry, b as AbiEntryName, c as AbiFriendlyType, d as AbiObjectType, e as AbiParameters, C as ContractDecodeFunctionDataArgs, f as ContractEncodeFunctionDataArgs, g as ContractGetEventsArgs, h as ContractGetEventsOptions, i as ContractReadArgs, j as ContractReadOptions, k as ContractWriteArgs, l as ContractWriteOptions, D as DecodedFunctionData, E as Event, n as EventArgs, o as EventFilter, p as EventName, F as FunctionArgs, q as FunctionName, r as FunctionReturn, R as ReadContract, m as ReadWriteContract } from './Contract-C2u5sI2x.js';
export { A as AbiArrayType, a as AbiEntry, b as AbiEntryName, c as AbiFriendlyType, d as AbiObjectType, e as AbiParameters, C as ContractDecodeFunctionDataArgs, f as ContractEncodeFunctionDataArgs, g as ContractGetEventsArgs, h as ContractGetEventsOptions, i as ContractReadArgs, j as ContractReadOptions, k as ContractWriteArgs, l as ContractWriteOptions, D as DecodedFunctionData, E as Event, n as EventArgs, o as EventFilter, p as EventName, F as FunctionArgs, q as FunctionName, r as FunctionReturn, R as ReadContract, m as ReadWriteContract } from './Contract-BIGb9LmL.js';
export { AbiEntryNotFoundError } from './errors.js';

@@ -6,0 +6,0 @@ export { B as Block, a as BlockTag } from './Block-D7itLNye.js';

@@ -1,2 +0,2 @@

import"./chunk-MWVTNBAN.js";import{a as f,b as m,c as t,d as x,e as a,f as b}from"./chunk-FI3KYCOV.js";import{a as r,b as e}from"./chunk-HB4JKCEF.js";import"./chunk-3DBCK3WJ.js";import{a as p}from"./chunk-FJROFRBN.js";import"./chunk-SXCIO5B6.js";import{c as o}from"./chunk-EXKUPYHD.js";o();export{p as AbiEntryNotFoundError,x as arrayToFriendly,a as arrayToObject,f as createCachedReadContract,m as createCachedReadWriteContract,r as createLruSimpleCache,e as createSimpleCacheKey,t as getAbiEntry,b as objectToArray};
import"./chunk-MWVTNBAN.js";import{a as f,b as m,c as t,d as x,e as a,f as b}from"./chunk-OWBXSX3M.js";import{a as r,b as e}from"./chunk-HB4JKCEF.js";import"./chunk-3DBCK3WJ.js";import{a as p}from"./chunk-FJROFRBN.js";import"./chunk-SXCIO5B6.js";import{c as o}from"./chunk-EXKUPYHD.js";o();export{p as AbiEntryNotFoundError,x as arrayToFriendly,a as arrayToObject,f as createCachedReadContract,m as createCachedReadWriteContract,r as createLruSimpleCache,e as createSimpleCacheKey,t as getAbiEntry,b as objectToArray};
//# sourceMappingURL=index.js.map
import { Abi } from 'abitype';
import { SinonStub } from 'sinon';
import { R as ReadContract, q as FunctionName, p as EventName, i as ContractReadArgs, r as FunctionReturn, k as ContractWriteArgs, g as ContractGetEventsArgs, E as Event, F as FunctionArgs, j as ContractReadOptions, h as ContractGetEventsOptions, C as ContractDecodeFunctionDataArgs, D as DecodedFunctionData, f as ContractEncodeFunctionDataArgs, l as ContractWriteOptions, m as ReadWriteContract } from './Contract-C2u5sI2x.js';
import { R as ReadContract, q as FunctionName, p as EventName, i as ContractReadArgs, r as FunctionReturn, k as ContractWriteArgs, g as ContractGetEventsArgs, E as Event, F as FunctionArgs, j as ContractReadOptions, h as ContractGetEventsOptions, C as ContractDecodeFunctionDataArgs, D as DecodedFunctionData, f as ContractEncodeFunctionDataArgs, l as ContractWriteOptions, m as ReadWriteContract } from './Contract-BIGb9LmL.js';
import { B as Block } from './Block-D7itLNye.js';

@@ -5,0 +5,0 @@ import { N as Network, a as NetworkGetBalanceArgs, b as NetworkGetBlockArgs, d as NetworkGetTransactionArgs, T as Transaction, e as NetworkWaitForTransactionArgs, g as TransactionReceipt } from './network-Do1HtQIB.js';

{
"name": "@delvtech/evm-client",
"version": "0.3.0",
"version": "0.3.1",
"license": "MIT",

@@ -5,0 +5,0 @@ "type": "module",

import{a as f,b as s}from"./chunk-HB4JKCEF.js";import{a as l}from"./chunk-FJROFRBN.js";import{c as m}from"./chunk-EXKUPYHD.js";m();m();var x=100;function C({contract:e,cache:r=f({max:x}),namespace:i}){let t=Object.getPrototypeOf(e),n=Object.create(t);return Object.assign(n,e,{cache:r,async read(a,o,c){return u({cache:r,key:s([i,"read",{address:e.address,functionName:a,args:o,options:c}]),callback:()=>e.read(a,o,c)})},deleteRead(a,o,c){let b=s([i,"read",{address:e.address,functionName:a,args:o,options:c}]);r.delete(b)},async getEvents(a,o){return u({cache:r,key:s([i,"getEvents",{address:e.address,eventName:a,options:o}]),callback:()=>e.getEvents(a,o)})},clearCache(){r.clear()}})}async function u({cache:e,key:r,callback:i}){let t=e.get(r);return t||(t=await i(),e.set(r,t),t)}m();function E({contract:e,cache:r,namespace:i}){if(P(e))return e;let t=Object.getPrototypeOf(e),n=Object.create(t);return Object.assign(n,C({contract:e,cache:r,namespace:i}))}function P(e){return"clearCache"in e}m();m();function d({abi:e,type:r,name:i}){let t=e.find(n=>n.type===r&&(r==="constructor"||n.name===i));if(!t)throw new l({type:r,name:i});return t}function h({abi:e,type:r,name:i,kind:t,values:n}){let T=d({abi:e,type:r,name:i}),a=[];if(t in T&&(a=T[t]),a.length<=1)return n[0];let o=n||[],c={};return a.forEach(({name:b},A)=>{b?c[b]=o[A]:c[A]=o[A]}),c}m();function R({abi:e,type:r,name:i,kind:t,values:n}){let T=d({abi:e,type:r,name:i}),a=[];t in T&&(a=T[t]);let o=n||[],c={};return a.forEach(({name:b},A)=>{b?c[b]=o[A]:c[A]=o[A]}),c}m();function I({abi:e,type:r,name:i,kind:t,value:n}){let T=d({abi:e,type:r,name:i}),a=[];if(t in T&&(a=T[t]),!a.length)return[];let o=n&&typeof n=="object"?n:{},c=[];return a.forEach(({name:b},A)=>{c.push(o[b||A])}),c}export{C as a,E as b,d as c,h as d,R as e,I as f};
//# sourceMappingURL=chunk-FI3KYCOV.js.map
{"version":3,"sources":["../src/exports/contract.ts","../src/contract/factories/createCachedReadContract.ts","../src/contract/factories/createCachedReadWriteContract.ts","../src/contract/utils/arrayToFriendly.ts","../src/contract/utils/getAbiEntry.ts","../src/contract/utils/arrayToObject.ts","../src/contract/utils/objectToArray.ts"],"sourcesContent":["// Factories\nexport {\n createCachedReadContract,\n type CreateCachedReadContractOptions,\n} from 'src/contract/factories/createCachedReadContract';\nexport {\n createCachedReadWriteContract,\n type CreateCachedReadWriteContractOptions,\n} from 'src/contract/factories/createCachedReadWriteContract';\n\n// Types\nexport type {\n AbiArrayType,\n AbiEntry,\n AbiEntryName,\n AbiFriendlyType,\n AbiObjectType,\n AbiParameters,\n} from 'src/contract/types/AbiEntry';\nexport type {\n CachedReadContract,\n CachedReadWriteContract,\n} from 'src/contract/types/CachedContract';\nexport type {\n ContractDecodeFunctionDataArgs,\n ContractEncodeFunctionDataArgs,\n ContractGetEventsArgs,\n ContractGetEventsOptions,\n ContractReadArgs,\n ContractReadOptions,\n ContractWriteArgs,\n ContractWriteOptions,\n ReadContract,\n ReadWriteContract,\n} from 'src/contract/types/Contract';\nexport type {\n Event,\n EventArgs,\n EventFilter,\n EventName,\n} from 'src/contract/types/Event';\nexport type {\n DecodedFunctionData,\n FunctionArgs,\n FunctionName,\n FunctionReturn,\n} from 'src/contract/types/Function';\n\n// Utils\nexport { arrayToFriendly } from 'src/contract/utils/arrayToFriendly';\nexport { arrayToObject } from 'src/contract/utils/arrayToObject';\nexport { getAbiEntry } from 'src/contract/utils/getAbiEntry';\nexport { objectToArray } from 'src/contract/utils/objectToArray';\n","import { Abi } from 'abitype';\nimport { createLruSimpleCache } from 'src/cache/factories/createLruSimpleCache';\nimport { SimpleCache, SimpleCacheKey } from 'src/cache/types/SimpleCache';\nimport { createSimpleCacheKey } from 'src/cache/utils/createSimpleCacheKey';\nimport { CachedReadContract } from 'src/contract/types/CachedContract';\nimport { ReadContract } from 'src/contract/types/Contract';\n\n// TODO: Figure out a good default cache size\nconst DEFAULT_CACHE_SIZE = 100;\n\nexport interface CreateCachedReadContractOptions<TAbi extends Abi = Abi> {\n contract: ReadContract<TAbi>;\n cache?: SimpleCache;\n /**\n * A namespace to distinguish this instance from others in the cache by\n * prefixing all cache keys.\n */\n namespace?: string;\n}\n\n/**\n * A wrapped Ethereum contract reader that provides caching capabilities. Useful\n * for reducing the number of actual reads from a contract by caching and\n * reusing previous read results.\n *\n * @example\n * const cachedContract = new CachedReadContract({ contract: myContract });\n * const result1 = await cachedContract.read(\"functionName\", args);\n * const result2 = await cachedContract.read(\"functionName\", args); // Fetched from cache\n */\nexport function createCachedReadContract<TAbi extends Abi = Abi>({\n contract,\n cache = createLruSimpleCache({ max: DEFAULT_CACHE_SIZE }),\n namespace,\n}: CreateCachedReadContractOptions<TAbi>): CachedReadContract<TAbi> {\n // Because this is part of the public API, we won't know if the original\n // contract is a plain object or a class instance, so we use Object.create to\n // preserve the original contract's prototype chain when extending, ensuring\n // the new contract includes all the original contract's methods and\n // instanceof checks will still work.\n const contractPrototype = Object.getPrototypeOf(contract);\n const newContract = Object.create(contractPrototype);\n\n const overrides: Partial<CachedReadContract<TAbi>> = {\n cache,\n\n /**\n * Reads data from the contract. First checks the cache, and if not present,\n * fetches from the contract and then caches the result.\n */\n async read(functionName, args, options) {\n return getOrSet({\n cache,\n key: createSimpleCacheKey([\n namespace,\n 'read',\n {\n address: contract.address,\n functionName,\n args,\n options,\n },\n ]),\n\n callback: () => contract.read(functionName, args, options),\n });\n },\n\n /**\n * Deletes a specific read from the cache.\n *\n * @example\n * const cachedContract = new CachedReadContract({ contract: myContract });\n * const result1 = await cachedContract.read(\"functionName\", args);\n * const result2 = await cachedContract.read(\"functionName\", args); // Fetched from cache\n *\n * cachedContract.deleteRead(\"functionName\", args);\n * const result3 = await cachedContract.read(\"functionName\", args); // Fetched from contract\n */\n deleteRead(functionName, args, options) {\n const key = createSimpleCacheKey([\n namespace,\n 'read',\n {\n address: contract.address,\n functionName,\n args,\n options,\n },\n ]);\n\n cache.delete(key);\n },\n\n /**\n * Gets events from the contract. First checks the cache, and if not present,\n * fetches from the contract and then caches the result.\n */\n async getEvents(eventName, options) {\n return getOrSet({\n cache,\n key: createSimpleCacheKey([\n namespace,\n 'getEvents',\n {\n address: contract.address,\n eventName,\n options,\n },\n ]),\n callback: () => contract.getEvents(eventName, options),\n });\n },\n\n /**\n * Clears the entire cache.\n */\n clearCache() {\n cache.clear();\n },\n };\n\n return Object.assign(newContract, contract, overrides);\n}\n\nasync function getOrSet<TValue>({\n cache,\n key,\n callback,\n}: {\n cache: SimpleCache;\n key: SimpleCacheKey;\n callback: () => Promise<TValue> | TValue;\n}): Promise<TValue> {\n let value = cache.get(key);\n if (value) {\n return value;\n }\n\n value = await callback();\n cache.set(key, value);\n\n return value;\n}\n","import { Abi } from 'abitype';\nimport {\n CreateCachedReadContractOptions,\n createCachedReadContract,\n} from 'src/contract/factories/createCachedReadContract';\nimport { CachedReadWriteContract } from 'src/contract/types/CachedContract';\nimport { ReadWriteContract } from 'src/contract/types/Contract';\n\nexport interface CreateCachedReadWriteContractOptions<TAbi extends Abi = Abi>\n extends CreateCachedReadContractOptions<TAbi> {\n contract: ReadWriteContract<TAbi>;\n}\n\n/**\n * Provides a cached wrapper around an Ethereum writable contract. This class is\n * useful for both reading (with caching) and writing to a contract. It extends\n * the functionality provided by CachedReadContract by adding write\n * capabilities.\n */\nexport function createCachedReadWriteContract<TAbi extends Abi = Abi>({\n contract,\n cache,\n namespace,\n}: CreateCachedReadWriteContractOptions<TAbi>): CachedReadWriteContract<TAbi> {\n // Avoid double-caching if given a contract that already has a cache.\n if (isCached(contract)) {\n return contract;\n }\n // Because this is part of the public API, we won't know if the original\n // contract is a plain object or a class instance, so we use Object.create to\n // preserve the original contract's prototype chain when extending, ensuring\n // the new contract includes all the original contract's methods and\n // instanceof checks will still work.\n const contractPrototype = Object.getPrototypeOf(contract);\n const newContract = Object.create(contractPrototype);\n return Object.assign(\n newContract,\n createCachedReadContract({ contract, cache, namespace }),\n );\n}\n\nfunction isCached<TAbi extends Abi>(\n contract: ReadWriteContract<TAbi>,\n): contract is CachedReadWriteContract<TAbi> {\n return 'clearCache' in contract;\n}\n","import { Abi, AbiItemType, AbiParameter, AbiParameterKind } from 'abitype';\nimport {\n AbiArrayType,\n AbiEntryName,\n AbiFriendlyType,\n} from 'src/contract/types/AbiEntry';\nimport { getAbiEntry } from 'src/contract/utils/getAbiEntry';\n\n/**\n * Converts an array of input or output values into an\n * {@linkcode AbiFriendlyType}, ensuring the values are properly identified\n * based on their index.\n *\n * @example\n * const abi = [\n * {\n * type: \"function\",\n * name: \"transfer\",\n * inputs: [\n * { name: \"to\", type: \"address\" },\n * { name: \"value\", type: \"uint256\" },\n * ],\n * outputs: [{ name: \"\", type: \"bool\" }],\n * stateMutability: \"nonpayable\",\n * },\n * {\n * type: \"event\",\n * name: \"Approval\",\n * inputs: [\n * { indexed: true, name: \"owner\", type: \"address\" },\n * { indexed: true, name: \"spender\", type: \"address\" },\n * { indexed: false, name: \"value\", type: \"uint256\" },\n * ],\n * },\n * ] as const;\n *\n * const parsedArgs = arrayToFriendly({\n * abi,\n * type: \"function\",\n * name: \"transfer\",\n * kind: \"inputs\",\n * values: [\"0x123\", 123n],\n * }); // -> { to: \"0x123\", value: 123n }\n *\n * const parsedReturn = arrayToFriendly({\n * abi,\n * type: \"function\",\n * name: \"transfer\",\n * kind: \"outputs\",\n * values: [true],\n * }); // -> true\n *\n * const parsedFilter = arrayToFriendly({\n * abi,\n * type: \"event\",\n * name: \"Approval\",\n * kind: \"inputs\",\n * values: [undefined, \"0x123\", undefined],\n * }); // -> { owner: undefined, spender: \"0x123\", value: undefined }\n */\nexport function arrayToFriendly<\n TAbi extends Abi,\n TItemType extends AbiItemType,\n TName extends AbiEntryName<TAbi, TItemType>,\n TParameterKind extends AbiParameterKind,\n>({\n abi,\n type,\n name,\n kind,\n values,\n}: {\n abi: TAbi;\n name: TName;\n values?: Abi extends TAbi\n ? readonly unknown[] // <- fallback for unknown ABI type\n : Partial<AbiArrayType<TAbi, TItemType, TName, TParameterKind>>;\n kind: TParameterKind;\n type: TItemType;\n}): AbiFriendlyType<TAbi, TItemType, TName, TParameterKind> {\n const abiEntry = getAbiEntry({ abi, type, name });\n\n let parameters: AbiParameter[] = [];\n if (kind in abiEntry) {\n parameters = (abiEntry as any)[kind];\n }\n\n // Single or no parameters\n if (parameters.length <= 1) {\n return (values as any[])[0];\n }\n\n const valuesArray = values || [];\n\n const friendlyValue: Record<string, any> = {};\n parameters.forEach(({ name }, i) => {\n if (name) {\n friendlyValue[name] = valuesArray[i];\n } else {\n friendlyValue[i] = valuesArray[i];\n }\n });\n\n return friendlyValue as any;\n}\n","import { Abi, AbiItemType } from 'abitype';\nimport { AbiEntry, AbiEntryName } from 'src/contract/types/AbiEntry';\nimport { AbiEntryNotFoundError } from 'src/errors/AbiEntryNotFound';\n\n/**\n * Get an entry from an ABI by type and name.\n * @throws If the entry is not found in the ABI.\n */\nexport function getAbiEntry<\n TAbi extends Abi,\n TItemType extends AbiItemType,\n TName extends AbiEntryName<TAbi, TItemType>,\n>({\n abi,\n type,\n name,\n}: {\n abi: TAbi;\n type: TItemType;\n name?: TName;\n}): AbiEntry<TAbi, TItemType, TName> {\n const abiItem = abi.find(\n (item) =>\n item.type === type &&\n (type === 'constructor' || (item as any).name === name),\n ) as AbiEntry<TAbi, TItemType, TName> | undefined;\n\n if (!abiItem) {\n throw new AbiEntryNotFoundError({ type, name });\n }\n\n return abiItem;\n}\n","import { Abi, AbiItemType, AbiParameter, AbiParameterKind } from 'abitype';\nimport {\n AbiArrayType,\n AbiEntryName,\n AbiObjectType,\n} from 'src/contract/types/AbiEntry';\nimport { getAbiEntry } from 'src/contract/utils/getAbiEntry';\n\n/**\n * Converts an array of input or output values into an object typ, ensuring the\n * values are properly identified based on their index.\n *\n * @example\n * const abi = [\n * {\n * type: \"function\",\n * name: \"transfer\",\n * inputs: [\n * { name: \"to\", type: \"address\" },\n * { name: \"value\", type: \"uint256\" },\n * ],\n * outputs: [{ name: \"\", type: \"bool\" }],\n * stateMutability: \"nonpayable\",\n * },\n * {\n * type: \"event\",\n * name: \"Approval\",\n * inputs: [\n * { indexed: true, name: \"owner\", type: \"address\" },\n * { indexed: true, name: \"spender\", type: \"address\" },\n * { indexed: false, name: \"value\", type: \"uint256\" },\n * ],\n * },\n * ] as const;\n *\n * const parsedArgs = arrayToObject({\n * abi,\n * type: \"function\",\n * name: \"transfer\",\n * kind: \"inputs\",\n * values: [\"0x123\", 123n],\n * }); // -> { to: \"0x123\", value: 123n }\n *\n * const parsedFilter = arrayToObject({\n * abi,\n * type: \"event\",\n * name: \"Approval\",\n * kind: \"inputs\",\n * values: [undefined, \"0x123\", undefined],\n * }); // -> { owner: undefined, spender: \"0x123\", value: undefined }\n */\nexport function arrayToObject<\n TAbi extends Abi,\n TItemType extends AbiItemType,\n TName extends AbiEntryName<TAbi, TItemType>,\n TParameterKind extends AbiParameterKind,\n>({\n abi,\n type,\n name,\n kind,\n values,\n}: {\n abi: TAbi;\n name: TName;\n values?: Abi extends TAbi\n ? readonly unknown[] // <- fallback for unknown ABI type\n : Partial<AbiArrayType<TAbi, TItemType, TName, TParameterKind>>;\n kind: TParameterKind;\n type: TItemType;\n}): AbiObjectType<TAbi, TItemType, TName, TParameterKind> {\n const abiEntry = getAbiEntry({ abi, type, name });\n\n let parameters: AbiParameter[] = [];\n if (kind in abiEntry) {\n parameters = (abiEntry as any)[kind];\n }\n\n const valuesArray = values || [];\n\n const valuesObject: Record<string, any> = {};\n parameters.forEach(({ name }, i) => {\n if (name) {\n valuesObject[name] = valuesArray[i];\n } else {\n valuesObject[i] = valuesArray[i];\n }\n });\n\n return valuesObject as any;\n}\n","import { Abi, AbiItemType, AbiParameter, AbiParameterKind } from 'abitype';\nimport {\n AbiArrayType,\n AbiEntryName,\n AbiObjectType,\n} from 'src/contract/types/AbiEntry';\nimport { getAbiEntry } from 'src/contract/utils/getAbiEntry';\n\n/**\n * Converts an object into an array of input or output values, ensuring the the\n * correct number and order of values are present.\n *\n * @example\n * const abi = [\n * {\n * type: \"function\",\n * name: \"transfer\",\n * inputs: [\n * { name: \"to\", type: \"address\" },\n * { name: \"value\", type: \"uint256\" },\n * ],\n * outputs: [{ name: \"\", type: \"bool\" }],\n * stateMutability: \"nonpayable\",\n * },\n * {\n * type: \"event\",\n * name: \"Approval\",\n * inputs: [\n * { indexed: true, name: \"owner\", type: \"address\" },\n * { indexed: true, name: \"spender\", type: \"address\" },\n * { indexed: false, name: \"value\", type: \"uint256\" },\n * ],\n * },\n * ] as const;\n *\n * const preppedArgs = objectToArray({\n * abi,\n * type: \"function\",\n * name: \"transfer\",\n * kind: \"inputs\",\n * value: { value: 123n, to: \"0x123\" },\n * }); // -> [\"0x123\", 123n]\n *\n * const preppedFilter = objectToArray({\n * abi,\n * type: \"event\",\n * name: \"Approval\",\n * kind: \"inputs\",\n * value: { spender: \"0x123\" },\n * }); // -> [undefined, \"0x123\", undefined]\n */\nexport function objectToArray<\n TAbi extends Abi,\n TItemType extends AbiItemType,\n TName extends AbiEntryName<TAbi, TItemType>,\n TParameterKind extends AbiParameterKind,\n>({\n abi,\n type,\n name,\n kind,\n value,\n}: {\n abi: TAbi;\n name: TName;\n value?: Abi extends TAbi\n ? Record<string, unknown> // <- fallback for unknown ABI type\n : Partial<AbiObjectType<TAbi, TItemType, TName, TParameterKind>>;\n kind: TParameterKind;\n type: TItemType;\n}): AbiArrayType<TAbi, TItemType, TName, TParameterKind> {\n const abiEntry = getAbiEntry({ abi, type, name });\n\n let parameters: AbiParameter[] = [];\n if (kind in abiEntry) {\n parameters = (abiEntry as any)[kind];\n }\n\n // No parameters\n if (!parameters.length) {\n return [] as AbiArrayType<TAbi, TItemType, TName, TParameterKind>;\n }\n\n const valueObject: Record<string, unknown> =\n value && typeof value === 'object' ? value : {};\n\n const array: unknown[] = [];\n parameters.forEach(({ name }, i) => {\n array.push(valueObject[name || i]);\n });\n\n return array as AbiArrayType<TAbi, TItemType, TName, TParameterKind>;\n}\n"],"mappings":"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","names":["init_esm_shims","init_esm_shims","DEFAULT_CACHE_SIZE","createCachedReadContract","contract","cache","createLruSimpleCache","namespace","contractPrototype","newContract","functionName","args","options","getOrSet","createSimpleCacheKey","key","eventName","callback","value","init_esm_shims","createCachedReadWriteContract","contract","cache","namespace","isCached","contractPrototype","newContract","createCachedReadContract","init_esm_shims","init_esm_shims","getAbiEntry","abi","type","name","abiItem","item","AbiEntryNotFoundError","arrayToFriendly","abi","type","name","kind","values","abiEntry","getAbiEntry","parameters","valuesArray","friendlyValue","i","init_esm_shims","arrayToObject","abi","type","name","kind","values","abiEntry","getAbiEntry","parameters","valuesArray","valuesObject","i","init_esm_shims","objectToArray","abi","type","name","kind","value","abiEntry","getAbiEntry","parameters","valueObject","array","i"]}
import { Abi, AbiItemType, AbiStateMutability, AbiParameterKind, AbiParameter, AbiParametersToPrimitiveTypes, AbiParameterToPrimitiveType } from 'abitype';
import { a as BlockTag } from './Block-D7itLNye.js';
type EmptyObject = Record<string, never>;
/**
* Combines members of an intersection into a readable type.
* @see https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg
*/
type Prettify<T> = {
[K in keyof T]: T[K];
} & unknown;
type NamedAbiParameter = AbiParameter & {
name: string;
};
/**
* Get a union of possible names for an abi item type.
*
* @example
* type Erc20EventNames = AbiEntryName<Erc20Abi, "event">;
* // -> "Approval" | "Transfer"
*/
type AbiEntryName<TAbi extends Abi, TItemType extends AbiItemType = AbiItemType> = Extract<TAbi[number], {
type: TItemType;
name?: string;
}>['name'];
/**
* Get the ABI entry for a specific type, name, and state mutability.
*
* @example
* type ApproveEntry = AbiEntry<Erc20Abi, "function", "approve">;
* // ->
* // {
* // type: "function";
* // name: "approve";
* // inputs: [{ name: "spender", type: "address" }, { name: "value", type: "uint256" }];
* // outputs: [{ name: "", type: "bool" }];
* // stateMutability: "nonpayable";
* // }
*/
type AbiEntry<TAbi extends Abi, TItemType extends AbiItemType = AbiItemType, TName extends AbiEntryName<TAbi, TItemType> = AbiEntryName<TAbi, TItemType>, TStateMutability extends AbiStateMutability = AbiStateMutability> = Extract<TAbi[number], {
type: TItemType;
name?: TName;
stateMutability?: TStateMutability;
}>;
/**
* Get the parameters for a specific ABI entry.
*
* @example
* type ApproveParameters = AbiParameters<Erc20Abi, "function", "approve", "inputs">;
* // -> [{ name: "spender", type: "address" }, { name: "value", type: "uint256" }]
*/
type AbiParameters<TAbi extends Abi = Abi, TItemType extends AbiItemType = AbiItemType, TName extends AbiEntryName<TAbi, TItemType> = AbiEntryName<TAbi, TItemType>, TParameterKind extends AbiParameterKind = AbiParameterKind> = AbiEntry<TAbi, TItemType, TName> extends infer TAbiEntry ? TParameterKind extends keyof TAbiEntry ? TAbiEntry[TParameterKind] : [] : [];
/**
* Add default names to any ABI parameters that are missing a name. The default
* name is the index of the parameter.
*/
type WithDefaultNames<TParameters extends readonly AbiParameter[]> = {
[K in keyof TParameters]: TParameters[K] extends infer TParameter extends AbiParameter ? TParameter extends NamedAbiParameter ? TParameter : TParameter & {
name: `${K}`;
} : never;
};
/**
* Convert an array or tuple of named abi parameters to an object type with the
* parameter names as keys and their primitive types as values. If a parameter
* has no name, it's index is used as the key.
*/
type NamedParametersToObject<TParameters extends readonly NamedAbiParameter[], TParameterKind extends AbiParameterKind = AbiParameterKind> = Prettify<{
[TName in Exclude<TParameters[number]['name'], ''>]: AbiParameterToPrimitiveType<Extract<TParameters[number], {
name: TName;
}>, TParameterKind>;
} & (TParameters extends readonly [NamedAbiParameter, ...NamedAbiParameter[]] ? {
[K in keyof TParameters as TParameters[K] extends NamedAbiParameter ? TParameters[K]['name'] extends '' ? Exclude<K, number> : never : never]: TParameters[K] extends NamedAbiParameter ? AbiParameterToPrimitiveType<TParameters[K], TParameterKind> : never;
} : Extract<TParameters[number], {
name: '';
}> extends never ? unknown : {
[index: number]: AbiParameterToPrimitiveType<Extract<TParameters[number], {
name: '';
}>, 'inputs'>;
})>;
/**
* Convert an array or tuple of abi parameters to an object type.
*
* @example
* type ApproveArgs = AbiParametersToObject<[
* { name: "spender", type: "address" },
* { name: "value", type: "uint256" }
* ]>; // -> { spender: `${string}`, value: bigint }
*/
type AbiParametersToObject<TParameters extends readonly AbiParameter[], TParameterKind extends AbiParameterKind = AbiParameterKind> = TParameters extends readonly [] ? EmptyObject : TParameters extends NamedAbiParameter[] ? NamedParametersToObject<TParameters, TParameterKind> : NamedParametersToObject<WithDefaultNames<TParameters>, TParameterKind>;
/**
* Get an array of primitive types for any ABI parameters.
*
* @example
* type ApproveInput = AbiArrayType<Erc20Abi, "function", "approve", "inputs">;
* // -> [`${string}`, bigint]
*
* type BalanceOutput = AbiArrayType<Erc20Abi, "function", "balanceOf", "outputs">;
* // -> [bigint]
*/
type AbiArrayType<TAbi extends Abi, TItemType extends AbiItemType = AbiItemType, TName extends AbiEntryName<TAbi, TItemType> = AbiEntryName<TAbi, TItemType>, TParameterKind extends AbiParameterKind = AbiParameterKind> = AbiParameters<TAbi, TItemType, TName, TParameterKind> extends infer TParameters ? TParameters extends readonly AbiParameter[] ? AbiParametersToPrimitiveTypes<TParameters> : [] : [];
/**
* Get an object of primitive types for any ABI parameters.
*
* @example
* type ApproveArgs = AbiObjectType<Erc20Abi, "function", "approve", "inputs">;
* // -> { spender: `${string}`, value: bigint }
*
* type Balance = AbiObjectType<Erc20Abi, "function", "balanceOf", "outputs">;
* // -> { balance: bigint }
*/
type AbiObjectType<TAbi extends Abi, TItemType extends AbiItemType = AbiItemType, TName extends AbiEntryName<TAbi, TItemType> = AbiEntryName<TAbi, TItemType>, TParameterKind extends AbiParameterKind = AbiParameterKind> = AbiParametersToObject<AbiParameters<TAbi, TItemType, TName, TParameterKind>>;
/**
* Get a user-friendly primitive type for any ABI parameters, which is
* determined by the number of parameters:
* - __Single parameter:__ the primitive type of the parameter.
* - __Multiple parameters:__ an object with the parameter names as keys and the
* their primitive types as values. If a parameter has no name, it's index is
* used as the key.
* - __No parameters:__ `undefined`.
*
* @example
* type ApproveArgs = AbiFriendlyType<Erc20Abi, "function", "approve", "inputs">;
* // -> { spender: `${string}`, value: bigint }
*
* type Balance = AbiFriendlyType<Erc20Abi, "function", "balanceOf", "outputs">;
* // -> bigint
*
* type DecimalArgs = AbiFriendlyType<Erc20Abi, "function", "decimals", "inputs">;
* // -> undefined
*/
type AbiFriendlyType<TAbi extends Abi, TItemType extends AbiItemType = AbiItemType, TName extends AbiEntryName<TAbi, TItemType> = AbiEntryName<TAbi, TItemType>, TParameterKind extends AbiParameterKind = AbiParameterKind, TStateMutability extends AbiStateMutability = AbiStateMutability> = AbiEntry<TAbi, TItemType, TName, TStateMutability> extends infer TAbiEntry ? TParameterKind extends keyof TAbiEntry & AbiParameterKind ? TAbiEntry[TParameterKind] extends readonly [AbiParameter] ? AbiParameterToPrimitiveType<TAbiEntry[TParameterKind][0], TParameterKind> : TAbiEntry[TParameterKind] extends readonly [
AbiParameter,
...AbiParameter[]
] ? AbiParametersToObject<TAbiEntry[TParameterKind], TParameterKind> : undefined : undefined : undefined;
/**
* Get a union of event names from an abi
*/
type EventName<TAbi extends Abi> = AbiEntry<TAbi, 'event'>['name'];
/**
* Get a union of named input parameters for an event from an abi
*/
type NamedEventInput<TAbi extends Abi, TEventName extends EventName<TAbi>> = Extract<AbiParameters<TAbi, 'event', TEventName, 'inputs'>, NamedAbiParameter>;
/**
* Get an object type for an event's arguments from an abi.
*/
type EventArgs<TAbi extends Abi, TEventName extends EventName<TAbi>> = AbiObjectType<TAbi, 'event', TEventName, 'inputs'>;
/**
* Get a union of indexed input objects for an event from an abi
*/
type IndexedEventInput<TAbi extends Abi, TEventName extends EventName<TAbi>> = Extract<NamedEventInput<TAbi, TEventName>, {
indexed: true;
}>;
/**
* Get an object type for an event's indexed fields from an abi
*/
type EventFilter<TAbi extends Abi, TEventName extends EventName<TAbi>> = Partial<AbiParametersToObject<IndexedEventInput<TAbi, TEventName>[], 'inputs'>>;
/**
* A strongly typed event object based on an abi
*/
interface Event<TAbi extends Abi, TEventName extends EventName<TAbi> = EventName<TAbi>> {
eventName: TEventName;
args: EventArgs<TAbi, TEventName>;
data?: `0x${string}`;
blockNumber?: bigint;
transactionHash?: `0x${string}`;
}
/**
* Get a union of function names from an abi
*/
type FunctionName<TAbi extends Abi, TAbiStateMutability extends AbiStateMutability = AbiStateMutability> = Extract<TAbi[number], {
type: 'function';
stateMutability: TAbiStateMutability;
}>['name'];
/**
* Get an object type for an abi function's arguments.
*/
type FunctionArgs<TAbi extends Abi, TFunctionName extends FunctionName<TAbi> = FunctionName<TAbi>> = AbiObjectType<TAbi, 'function', TFunctionName, 'inputs'>;
/**
* Get a user-friendly return type for an abi function, which is determined by
* it's outputs:
* - __Single output:__ the type of the single output.
* - __Multiple outputs:__ an object with the output names as keys and the
* output types as values.
* - __No outputs:__ `undefined`.
*/
type FunctionReturn<TAbi extends Abi, TFunctionName extends FunctionName<TAbi>> = AbiFriendlyType<TAbi, 'function', TFunctionName, 'outputs'>;
/**
* Get an object representing decoded function or constructor data from an ABI.
*/
type DecodedFunctionData<TAbi extends Abi, TFunctionName extends FunctionName<TAbi>> = {
[K in TFunctionName]: {
args: FunctionArgs<TAbi, K>;
functionName: K;
};
}[TFunctionName];
/**
* Interface representing a readable contract with specified ABI. Provides type
* safe methods to read and simulate write operations on the contract.
*/
interface ReadContract<TAbi extends Abi = Abi> {
abi: TAbi;
address: `0x${string}`;
/**
* Reads a specified function from the contract.
*/
read<TFunctionName extends FunctionName<TAbi, 'pure' | 'view'>>(...args: ContractReadArgs<TAbi, TFunctionName>): Promise<FunctionReturn<TAbi, TFunctionName>>;
/**
* Simulates a write operation on a specified function of the contract.
*/
simulateWrite<TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>>(...args: ContractWriteArgs<TAbi, TFunctionName>): Promise<FunctionReturn<TAbi, TFunctionName>>;
/**
* Retrieves specified events from the contract.
*/
getEvents<TEventName extends EventName<TAbi>>(...args: ContractGetEventsArgs<TAbi, TEventName>): Promise<Event<TAbi, TEventName>[]>;
/**
* Encodes a function call into calldata.
*/
encodeFunctionData<TFunctionName extends FunctionName<TAbi>>(...args: ContractEncodeFunctionDataArgs<TAbi, TFunctionName>): `0x${string}`;
/**
* Decodes a string of function calldata into it's arguments and function
* name.
*/
decodeFunctionData<TFunctionName extends FunctionName<TAbi> = FunctionName<TAbi>>(...args: ContractDecodeFunctionDataArgs): DecodedFunctionData<TAbi, TFunctionName>;
}
/**
* Interface representing a writable contract with specified ABI.
* Extends IReadContract to also include write operations.
*/
interface ReadWriteContract<TAbi extends Abi = Abi> extends ReadContract<TAbi> {
/**
* Get the address of the signer for this contract.
*/
getSignerAddress(): Promise<`0x${string}`>;
/**
* Writes to a specified function on the contract.
* @returns The transaction hash of the submitted transaction.
*/
write<TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>>(...args: ContractWriteArgs<TAbi, TFunctionName>): Promise<`0x${string}`>;
}
type ContractReadOptions = {
blockNumber?: bigint;
blockTag?: never;
} | {
blockNumber?: never;
/**
* @default 'latest'
*/
blockTag?: BlockTag;
};
type ContractReadArgs<TAbi extends Abi, TFunctionName extends FunctionName<TAbi>> = FunctionArgs<TAbi, TFunctionName> extends EmptyObject ? [
functionName: TFunctionName,
args?: FunctionArgs<TAbi, TFunctionName>,
options?: ContractReadOptions
] : [
functionName: TFunctionName,
args: FunctionArgs<TAbi, TFunctionName>,
options?: ContractReadOptions
];
interface ContractGetEventsOptions<TAbi extends Abi, TEventName extends EventName<TAbi> = EventName<TAbi>> {
filter?: EventFilter<TAbi, TEventName>;
fromBlock?: bigint | BlockTag;
toBlock?: bigint | BlockTag;
}
type ContractGetEventsArgs<TAbi extends Abi, TEventName extends EventName<TAbi>> = [
eventName: TEventName,
options?: ContractGetEventsOptions<TAbi, TEventName>
];
interface ContractWriteOptions {
type?: `0x${string}`;
nonce?: bigint;
to?: `0x${string}`;
from?: `0x${string}`;
/**
* Gas limit
*/
gas?: bigint;
value?: bigint;
input?: `0x${string}`;
/**
* The gas price willing to be paid by the sender in wei
*/
gasPrice?: bigint;
/**
* Maximum fee per gas the sender is willing to pay to miners in wei
*/
maxPriorityFeePerGas?: bigint;
/**
* The maximum total fee per gas the sender is willing to pay (includes the
* network / base fee and miner / priority fee) in wei
*/
maxFeePerGas?: bigint;
/**
* EIP-2930 access list
*/
accessList?: {
address: `0x${string}`;
storageKeys: `0x${string}`[];
}[];
/**
* Chain ID that this transaction is valid on.
*/
chainId?: bigint;
}
type ContractWriteArgs<TAbi extends Abi, TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>> = FunctionArgs<TAbi, TFunctionName> extends EmptyObject ? [
functionName: TFunctionName,
args?: FunctionArgs<TAbi, TFunctionName>,
options?: ContractWriteOptions
] : [
functionName: TFunctionName,
args: FunctionArgs<TAbi, TFunctionName>,
options?: ContractWriteOptions
];
type ContractEncodeFunctionDataArgs<TAbi extends Abi, TFunctionName extends FunctionName<TAbi>> = FunctionArgs<TAbi, TFunctionName> extends EmptyObject ? [functionName: TFunctionName, args?: FunctionArgs<TAbi, TFunctionName>] : [functionName: TFunctionName, args: FunctionArgs<TAbi, TFunctionName>];
type ContractDecodeFunctionDataArgs = [data: `0x${string}`];
export type { AbiArrayType as A, ContractDecodeFunctionDataArgs as C, DecodedFunctionData as D, Event as E, FunctionArgs as F, ReadContract as R, AbiEntry as a, AbiEntryName as b, AbiFriendlyType as c, AbiObjectType as d, AbiParameters as e, ContractEncodeFunctionDataArgs as f, ContractGetEventsArgs as g, ContractGetEventsOptions as h, ContractReadArgs as i, ContractReadOptions as j, ContractWriteArgs as k, ContractWriteOptions as l, ReadWriteContract as m, EventArgs as n, EventFilter as o, EventName as p, FunctionName as q, FunctionReturn as r };