@delvtech/evm-client
Advanced tools
| import{a as l,b as p}from"./chunk-EAEQRHOF.js";import{a as u}from"./chunk-FJROFRBN.js";import{c as m}from"./chunk-EXKUPYHD.js";m();m();import E from"lodash.ismatch";var R=100;function f({contract:e,cache:t=l({max:R}),namespace:i}){let r=Object.getPrototypeOf(e),o=Object.create(r);return Object.assign(o,e,{cache:t,async read(a,n,c){return x({cache:t,key:p([i,"read",{address:e.address,functionName:a,args:n,options:c}]),callback:()=>e.read(a,n,c)})},deleteRead(a,n,c){let T=p([i,"read",{address:e.address,functionName:a,args:n,options:c}]);t.delete(T)},deleteReadsMatching(...a){let[n,c,T]=a,b=p([i,"read",{address:e.address,functionName:n,args:c,options:T}]);for(let[C]of t.entries)typeof C=="object"&&E(C,b)&&t.delete(C)},async getEvents(a,n){return x({cache:t,key:p([i,"getEvents",{address:e.address,eventName:a,options:n}]),callback:()=>e.getEvents(a,n)})},clearCache(){t.clear()}})}async function x({cache:e,key:t,callback:i}){let r=e.get(t);return r||(r=await i(),e.set(t,r),r)}m();function P({contract:e,cache:t,namespace:i}){if(h(e))return e;let r=Object.getPrototypeOf(e),o=Object.create(r);return Object.assign(o,f({contract:e,cache:t,namespace:i}))}function h(e){return"clearCache"in e}m();m();function A({abi:e,type:t,name:i}){let r=e.find(o=>o.type===t&&(t==="constructor"||o.name===i));if(!r)throw new u({type:t,name:i});return r}function I({abi:e,type:t,name:i,kind:r,values:o}){let d=A({abi:e,type:t,name:i}),a=[];if(r in d&&(a=d[r]),a.length<=1)return o[0];let n=o||[],c={};return a.forEach(({name:T},b)=>{T?c[T]=n[b]:c[b]=n[b]}),c}m();function g({abi:e,type:t,name:i,kind:r,values:o}){let d=A({abi:e,type:t,name:i}),a=[];r in d&&(a=d[r]);let n=o||[],c={};return a.forEach(({name:T},b)=>{T?c[T]=n[b]:c[b]=n[b]}),c}m();function N({abi:e,type:t,name:i,kind:r,value:o}){let d=A({abi:e,type:t,name:i}),a=[];if(r in d&&(a=d[r]),!a.length)return[];let n=o&&typeof o=="object"?o:{};return a.map(({name:T},b)=>n[T||b])}export{f as a,P as b,A as c,I as d,g as e,N as f}; | ||
| //# sourceMappingURL=chunk-CH66YOZT.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 isMatch from 'lodash.ismatch';\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 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 deleteReadsMatching(...args) {\n const [functionName, functionArgs, options] = args;\n\n const sourceKey = createSimpleCacheKey([\n namespace,\n 'read',\n {\n address: contract.address,\n functionName,\n args: functionArgs,\n options,\n },\n ]);\n\n for (const [key] of cache.entries) {\n if (\n typeof key === 'object' &&\n isMatch(key, sourceKey as SimpleCacheKey[])\n ) {\n cache.delete(key);\n }\n }\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 = parameters.map(({ name }, i) => valueObject[name || i]);\n\n return array as AbiArrayType<TAbi, TItemType, TName, TParameterKind>;\n}\n"],"mappings":"+HAAAA,ICAAC,IACA,OAAOC,MAAa,iBAQpB,IAAMC,EAAqB,IAsBpB,SAASC,EAAiD,CAC/D,SAAAC,EACA,MAAAC,EAAQC,EAAqB,CAAE,IAAKJ,CAAmB,CAAC,EACxD,UAAAK,CACF,EAAoE,CAMlE,IAAMC,EAAoB,OAAO,eAAeJ,CAAQ,EAClDK,EAAc,OAAO,OAAOD,CAAiB,EAwGnD,OAAO,OAAO,OAAOC,EAAaL,EAtGmB,CACnD,MAAAC,EAMA,MAAM,KAAKK,EAAcC,EAAMC,EAAS,CACtC,OAAOC,EAAS,CACd,MAAAR,EACA,IAAKS,EAAqB,CACxBP,EACA,OACA,CACE,QAASH,EAAS,QAClB,aAAAM,EACA,KAAAC,EACA,QAAAC,CACF,CACF,CAAC,EACD,SAAU,IAAMR,EAAS,KAAKM,EAAcC,EAAMC,CAAO,CAC3D,CAAC,CACH,EAaA,WAAWF,EAAcC,EAAMC,EAAS,CACtC,IAAMG,EAAMD,EAAqB,CAC/BP,EACA,OACA,CACE,QAASH,EAAS,QAClB,aAAAM,EACA,KAAAC,EACA,QAAAC,CACF,CACF,CAAC,EAEDP,EAAM,OAAOU,CAAG,CAClB,EAEA,uBAAuBJ,EAAM,CAC3B,GAAM,CAACD,EAAcM,EAAcJ,CAAO,EAAID,EAExCM,EAAYH,EAAqB,CACrCP,EACA,OACA,CACE,QAASH,EAAS,QA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EAA6B,CAAC,EAMlC,GALIJ,KAAQE,IACVE,EAAcF,EAAiBF,CAAI,GAIjC,CAACI,EAAW,OACd,MAAO,CAAC,EAGV,IAAMC,EACJJ,GAAS,OAAOA,GAAU,SAAWA,EAAQ,CAAC,EAIhD,OAFcG,EAAW,IAAI,CAAC,CAAE,KAAAL,CAAK,EAAGO,IAAMD,EAAYN,GAAQO,CAAC,CAAC,CAGtE","names":["init_esm_shims","init_esm_shims","isMatch","DEFAULT_CACHE_SIZE","createCachedReadContract","contract","cache","createLruSimpleCache","namespace","contractPrototype","newContract","functionName","args","options","getOrSet","createSimpleCacheKey","key","functionArgs","sourceKey","isMatch","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","i"]} |
| import{a as v,b as O,c as f}from"./chunk-EXKUPYHD.js";var b=v((C,g)=>{"use strict";f();g.exports=function(n,r){r||(r={}),typeof r=="function"&&(r={cmp:r});var u=typeof r.cycles=="boolean"?r.cycles:!1,t=r.cmp&&function(a){return function(e){return function(i,c){var y={key:i,value:e[i]},o={key:c,value:e[c]};return a(y,o)}}}(r.cmp),l=[];return function a(e){if(e&&e.toJSON&&typeof e.toJSON=="function"&&(e=e.toJSON()),e!==void 0){if(typeof e=="number")return isFinite(e)?""+e:"null";if(typeof e!="object")return JSON.stringify(e);var i,c;if(Array.isArray(e)){for(c="[",i=0;i<e.length;i++)i&&(c+=","),c+=a(e[i])||"null";return c+"]"}if(e===null)return"null";if(l.indexOf(e)!==-1){if(u)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var y=l.push(e)-1,o=Object.keys(e).sort(t&&t(e));for(c="",i=0;i<o.length;i++){var m=o[i],p=a(e[m]);p&&(c&&(c+=","),c+=JSON.stringify(m)+":"+p)}return l.splice(y,1),"{"+c+"}"}}(n)}});f();var s=O(b(),1);import{LRUCache as T}from"lru-cache";function V(n){let r=new T(n);function*u(t){for(let[l,a]of t)yield[JSON.parse(l),a]}return{get entries(){return u(r.entries())},get(t){return r.get((0,s.default)(t))},set(t,l){r.set((0,s.default)(t),l)},delete(t){return r.delete((0,s.default)(t))},clear(){r.clear()},find(t){return r.find((l,a)=>t(l,JSON.parse(a)))}}}f();function N(n){switch(typeof n){case"string":case"number":case"boolean":return n;case"object":{if(Array.isArray(n))return n.map(u=>u==null?null:N(u));let r={};for(let u of Object.keys(n).sort()){let t=n[u];t!=null&&(r[u]=N(t))}return r}default:try{return n.toString()}catch{throw new Error(`Unable to process cache key value: ${String(n)}`)}}}export{V as a,N as b}; | ||
| //# sourceMappingURL=chunk-EAEQRHOF.js.map |
| {"version":3,"sources":["../../../node_modules/fast-json-stable-stringify/index.js","../src/cache/factories/createLruSimpleCache.ts","../src/cache/utils/createSimpleCacheKey.ts"],"sourcesContent":["'use strict';\n\nmodule.exports = function (data, opts) {\n if (!opts) opts = {};\n if (typeof opts === 'function') opts = { cmp: opts };\n var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;\n\n var cmp = opts.cmp && (function (f) {\n return function (node) {\n return function (a, b) {\n var aobj = { key: a, value: node[a] };\n var bobj = { key: b, value: node[b] };\n return f(aobj, bobj);\n };\n };\n })(opts.cmp);\n\n var seen = [];\n return (function stringify (node) {\n if (node && node.toJSON && typeof node.toJSON === 'function') {\n node = node.toJSON();\n }\n\n if (node === undefined) return;\n if (typeof node == 'number') return isFinite(node) ? '' + node : 'null';\n if (typeof node !== 'object') return JSON.stringify(node);\n\n var i, out;\n if (Array.isArray(node)) {\n out = '[';\n for (i = 0; i < node.length; i++) {\n if (i) out += ',';\n out += stringify(node[i]) || 'null';\n }\n return out + ']';\n }\n\n if (node === null) return 'null';\n\n if (seen.indexOf(node) !== -1) {\n if (cycles) return JSON.stringify('__cycle__');\n throw new TypeError('Converting circular structure to JSON');\n }\n\n var seenIndex = seen.push(node) - 1;\n var keys = Object.keys(node).sort(cmp && cmp(node));\n out = '';\n for (i = 0; i < keys.length; i++) {\n var key = keys[i];\n var value = stringify(node[key]);\n\n if (!value) continue;\n if (out) out += ',';\n out += JSON.stringify(key) + ':' + value;\n }\n seen.splice(seenIndex, 1);\n return '{' + out + '}';\n })(data);\n};\n","import stringify from 'fast-json-stable-stringify';\nimport { LRUCache } from 'lru-cache';\nimport { SimpleCache, SimpleCacheKey } from 'src/cache/types/SimpleCache';\n\n/**\n * An LRU (Least Recently Used) implementation of the `SimpleCache` interface.\n * This class wraps around the\n * [lru-cache](https://www.npmjs.com/package/lru-cache) library to provide LRU\n * caching capabilities conforming to the `SimpleCache` interface.\n *\n * @template TValue - The type of value to be stored in the cache.\n * @template TKey - The type of key used to access values in the cache.\n * @hidden\n */\nexport function createLruSimpleCache<\n TValue extends NonNullable<unknown> = NonNullable<unknown>,\n TKey extends SimpleCacheKey = SimpleCacheKey,\n>(options: LRUCache.Options<string, TValue, void>): SimpleCache<TValue, TKey> {\n const cache = new LRUCache(options);\n\n function* entriesGenerator(\n originalGenerator: Generator<[TKey, TValue]>,\n ): Generator<[TKey, TValue]> {\n for (const [key, value] of originalGenerator) {\n // Modify the entry here before yielding it\n const modifiedEntry = [JSON.parse(key as string), value];\n yield modifiedEntry as [TKey, TValue];\n }\n }\n\n return {\n get entries() {\n // Keys need to be returned in the same format as they were given to the cache\n return entriesGenerator(cache.entries() as Generator<[TKey, TValue]>);\n },\n\n get(key) {\n return cache.get(stringify(key));\n },\n\n set(key, value) {\n cache.set(stringify(key), value);\n },\n\n delete(key) {\n return cache.delete(stringify(key));\n },\n\n clear() {\n cache.clear();\n },\n\n find(predicate) {\n return cache.find((value, key) => predicate(value, JSON.parse(key)));\n },\n };\n}\n","import { SimpleCacheKey } from 'src/cache/types/SimpleCache';\n\ntype DefinedValue = NonNullable<\n Record<string, any> | string | number | boolean | symbol\n>;\n\n/**\n * Converts a given raw key into a `SimpleCacheKey``.\n *\n * The method ensures that any given raw key, regardless of its structure, is\n * converted into a format suitable for consistent cache key referencing.\n *\n * - For scalar (string, number, boolean), it returns them directly.\n * - For arrays, it recursively processes each element.\n * - For objects, it sorts the keys and then recursively processes each value,\n * ensuring consistent key generation.\n * - For other types, it attempts to convert the raw key to a string.\n *\n * @param rawKey - The raw input to be converted into a cache key.\n * @returns A standardized cache key suitable for consistent referencing within\n * the cache.\n */\nexport function createSimpleCacheKey(rawKey: DefinedValue): SimpleCacheKey {\n switch (typeof rawKey) {\n case 'string':\n case 'number':\n case 'boolean':\n return rawKey;\n\n case 'object': {\n if (Array.isArray(rawKey)) {\n return rawKey.map((value) =>\n // undefined or null values are converted to null to follow the\n // precedent set by JSON.stringify\n value === undefined || value === null\n ? null\n : createSimpleCacheKey(value),\n );\n }\n\n const processedObject: Record<string, SimpleCacheKey> = {};\n\n // sort keys to ensure consistent key generation\n for (const key of Object.keys(rawKey).sort()) {\n const value = rawKey[key];\n\n // ignore properties with undefined or null values\n if (value !== undefined && value !== null) {\n processedObject[key] = createSimpleCacheKey(value);\n }\n }\n\n return processedObject;\n }\n\n default:\n try {\n return rawKey.toString();\n } catch (err) {\n throw new Error(`Unable to process cache key value: ${String(rawKey)}`);\n }\n }\n}\n"],"mappings":"sDAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,cAAAC,IAEAD,EAAO,QAAU,SAAUE,EAAMC,EAAM,CAC9BA,IAAMA,EAAO,CAAC,GACf,OAAOA,GAAS,aAAYA,EAAO,CAAE,IAAKA,CAAK,GACnD,IAAIC,EAAU,OAAOD,EAAK,QAAW,UAAaA,EAAK,OAAS,GAE5DE,EAAMF,EAAK,KAAQ,SAAUG,EAAG,CAChC,OAAO,SAAUC,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AAOF,EAAO,SAAS,CACzB,MAAc,CACZ,MAAM,IAAI,MAAM,sCAAsC,OAAOA,CAAM,CAAC,EAAE,CACxE,CACJ,CACF","names":["require_fast_json_stable_stringify","__commonJSMin","exports","module","init_esm_shims","data","opts","cycles","cmp","f","node","a","b","aobj","bobj","seen","stringify","out","seenIndex","keys","key","value","init_esm_shims","import_fast_json_stable_stringify","LRUCache","createLruSimpleCache","options","cache","entriesGenerator","originalGenerator","key","value","stringify","predicate","init_esm_shims","createSimpleCacheKey","rawKey","value","processedObject","key"]} |
| 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 | ||
| * ```ts | ||
| * 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 | ||
| * ```ts | ||
| * 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 | ||
| * ```ts | ||
| * 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. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * type Parameters = WithDefaultNames<[{ name: "spender", type: "address" }, { type: "uint256" }]>; | ||
| * // -> [{ name: "spender", type: "address" }, { name: "1", type: "uint256" }] | ||
| * ``` | ||
| */ | ||
| 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 an empty name, it's index is used as the key. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * type Parameters = NamedParametersToObject<[{ name: "spender", type: "address" }, { name: "", type: "uint256" }]>; | ||
| * // -> { spender: `${string}`, "1": bigint } | ||
| * ``` | ||
| */ | ||
| 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 | ||
| * ```ts | ||
| * type ApproveArgs = AbiParametersToObject<[ | ||
| * { name: "spender", type: "address" }, | ||
| * { name: "value", type: "uint256" } | ||
| * ]>; | ||
| * // -> { spender: `0x${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 | ||
| * ```ts | ||
| * type ApproveInput = AbiArrayType<Erc20Abi, "function", "approve", "inputs">; | ||
| * // -> [`0x${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 | ||
| * ```ts | ||
| * type ApproveArgs = AbiObjectType<Erc20Abi, "function", "approve", "inputs">; | ||
| * // -> { spender: `0x${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 | ||
| * ```ts | ||
| * 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 }; |
+6
-4
@@ -20,12 +20,14 @@ import { LRUCache } from 'lru-cache'; | ||
| * | ||
| * The method ensures that any given raw key, regardless of its structure, | ||
| * is converted into a format suitable for consistent cache key referencing. | ||
| * The method ensures that any given raw key, regardless of its structure, is | ||
| * converted into a format suitable for consistent cache key referencing. | ||
| * | ||
| * - For scalar (string, number, boolean), it returns them directly. | ||
| * - For arrays, it recursively processes each element. | ||
| * - For objects, it sorts the keys and then recursively processes each value, ensuring consistent key generation. | ||
| * - For objects, it sorts the keys and then recursively processes each value, | ||
| * ensuring consistent key generation. | ||
| * - For other types, it attempts to convert the raw key to a string. | ||
| * | ||
| * @param rawKey - The raw input to be converted into a cache key. | ||
| * @returns A standardized cache key suitable for consistent referencing within the cache. | ||
| * @returns A standardized cache key suitable for consistent referencing within | ||
| * the cache. | ||
| */ | ||
@@ -32,0 +34,0 @@ declare function createSimpleCacheKey(rawKey: DefinedValue): SimpleCacheKey; |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import"./chunk-MWVTNBAN.js";import{a,b}from"./chunk-VOITYMJ3.js";import"./chunk-EXKUPYHD.js";export{a as createLruSimpleCache,b as createSimpleCacheKey}; | ||
| import"./chunk-MWVTNBAN.js";import{a,b}from"./chunk-EAEQRHOF.js";import"./chunk-EXKUPYHD.js";export{a as createLruSimpleCache,b as createSimpleCacheKey}; | ||
| //# sourceMappingURL=cache.js.map |
| 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-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 { 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-BnkTtZqI.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-BnkTtZqI.js'; | ||
| import './Block-D7itLNye.js'; | ||
@@ -12,6 +12,7 @@ | ||
| deleteRead<TFunctionName extends FunctionName<TAbi>>(...[functionName, args, options]: ContractReadArgs<TAbi, TFunctionName>): void; | ||
| deleteReadMatch<TFunctionName extends FunctionName<TAbi>>(...[functionName, args, options]: DeepPartial<ContractReadArgs<TAbi, TFunctionName>>): void; | ||
| deleteReadsMatching<TFunctionName extends FunctionName<TAbi>>(...[functionName, args, options]: DeepPartial<ContractReadArgs<TAbi, TFunctionName>>): void; | ||
| } | ||
| interface CachedReadWriteContract<TAbi extends Abi = Abi> extends CachedReadContract<TAbi>, ReadWriteContract<TAbi> { | ||
| } | ||
| /** Recursively make all properties in T partial. */ | ||
| type DeepPartial<T> = Partial<{ | ||
@@ -18,0 +19,0 @@ [K in keyof T]: DeepPartial<T[K]>; |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import{a,b,c,d,e,f}from"./chunk-FCP4QSIX.js";import"./chunk-VOITYMJ3.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-CH66YOZT.js";import"./chunk-EAEQRHOF.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 |
+1
-1
| 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-BIGb9LmL.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-BnkTtZqI.js'; | ||
| export { AbiEntryNotFoundError } from './errors.js'; | ||
@@ -6,0 +6,0 @@ export { B as Block, a as BlockTag } from './Block-D7itLNye.js'; |
+1
-1
@@ -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-FCP4QSIX.js";import{a as r,b as e}from"./chunk-VOITYMJ3.js";import"./chunk-3DBCK3WJ.js";import{a as p}from"./chunk-FJROFRBN.js";import"./chunk-MDTXOUYA.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-CH66YOZT.js";import{a as r,b as e}from"./chunk-EAEQRHOF.js";import"./chunk-3DBCK3WJ.js";import{a as p}from"./chunk-FJROFRBN.js";import"./chunk-MDTXOUYA.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 |
@@ -65,2 +65,6 @@ import { B as Block, a as BlockTag } from './Block-D7itLNye.js'; | ||
| /** | ||
| * Get the chain ID of the network. | ||
| */ | ||
| getChainId(): Promise<number>; | ||
| /** | ||
| * Get a transaction from a transaction hash. | ||
@@ -67,0 +71,0 @@ */ |
+4
-1
| 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-BIGb9LmL.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-BnkTtZqI.js'; | ||
| import { B as Block } from './Block-D7itLNye.js'; | ||
@@ -165,2 +165,3 @@ import { Network, NetworkGetBalanceArgs, NetworkGetBlockArgs, NetworkGetTransactionArgs, Transaction, NetworkWaitForTransactionArgs, TransactionReceipt } from './network.js'; | ||
| protected getBlockStub: SinonStub<[NetworkGetBlockArgs?], Promise<Block | undefined>> | undefined; | ||
| protected getChainIdStub: SinonStub<[], Promise<number>> | undefined; | ||
| protected getTransactionStub: SinonStub<[NetworkGetTransactionArgs?], Promise<Transaction | undefined>> | undefined; | ||
@@ -175,2 +176,3 @@ stubGetBalance({ args, value, }: { | ||
| }): void; | ||
| stubGetChainId(id: number): void; | ||
| stubGetTransaction({ args, value, }: { | ||
@@ -182,2 +184,3 @@ args?: NetworkGetTransactionArgs; | ||
| getBlock(...args: NetworkGetBlockArgs): Promise<Block | undefined>; | ||
| getChainId(): Promise<number>; | ||
| getTransaction(...args: NetworkGetTransactionArgs): Promise<Transaction | undefined>; | ||
@@ -184,0 +187,0 @@ waitForTransaction(...[hash, { timeout }]: NetworkWaitForTransactionArgs): Promise<TransactionReceipt | undefined>; |
+6
-5
@@ -1,9 +0,10 @@ | ||
| import{c as o}from"./chunk-EXKUPYHD.js";o();o();import N from"fast-safe-stringify";import{stub as b}from"sinon";var s=class{abi;address="0x0000000000000000000000000000000000000000";readStubMap=new Map;eventsStubMap=new Map;simulateWriteStubMap=new Map;constructor(t=[]){this.abi=t}async read(...[t,n,e]){let i=this.getReadStub(t);if(!i)throw new Error(`Called read for ${t} on a stubbed contract without a return value. The function must be stubbed first: | ||
| import{c as o}from"./chunk-EXKUPYHD.js";o();o();import N from"fast-safe-stringify";import{stub as d}from"sinon";var s=class{abi;address="0x0000000000000000000000000000000000000000";readStubMap=new Map;eventsStubMap=new Map;simulateWriteStubMap=new Map;constructor(t=[]){this.abi=t}async read(...[t,n,e]){let i=this.getReadStub(t);if(!i)throw new Error(`Called read for ${t} on a stubbed contract without a return value. The function must be stubbed first: | ||
| contract.stubRead("${t}", value)`);return i(n,e)}async simulateWrite(...[t,n,e]){let i=this.getSimulateWriteStub(t);if(!i)throw new Error(`Called simulateWrite for ${t} on a stubbed contract without a return value. The function must be stubbed first: | ||
| contract.stubWrite("${t}", value)`);return i(n,e)}async getEvents(...[t,n]){let e=this.getEventsStub(t,n);if(!e)throw new Error(`Called getEvents for ${t} on a stubbed contract without a return value. The function must be stubbed first: | ||
| contract.stubEvents("${t}", value)`);return e(n)}stubRead({functionName:t,args:n,value:e,options:i}){let r=this.readStubMap.get(t);if(r||(r=b(),this.readStubMap.set(t,r)),n||i){r.withArgs(n,i).resolves(e);return}r.resolves(e)}stubSimulateWrite(t,n){let e=this.simulateWriteStubMap.get(t);e||(e=b(),this.simulateWriteStubMap.set(t,e)),e.resolves(n)}stubEvents(t,n,e){let i=l({eventName:t,args:n});this.eventsStubMap.has(i)?this.getEventsStub(t,n).resolves(e):this.eventsStubMap.set(i,b().resolves(e))}getReadStub(t){return this.readStubMap.get(t)}getSimulateWriteStub(t){return this.simulateWriteStubMap.get(t)}getEventsStub(t,n){let e=l({eventName:t,args:n});return this.eventsStubMap.get(e)}decodeFunctionData(...t){throw new Error("Method not implemented.")}encodeFunctionData(...t){throw new Error("Method not implemented.")}};function l(a){function t(n,e){return typeof e=="bigint"?e.toString():e}return N.stableStringify(a,t)}o();import{stub as p}from"sinon";o();var A="0xBob";var T=class extends s{writeStubMap=new Map;getSignerAddress=p().resolves(A);async write(...[t,n,e]){let i=this.getWriteStub(t);if(!i)throw new Error(`Called write for ${t} on a stubbed contract without a return value. The function must be stubbed first: | ||
| contract.stubWrite("${t}", value)`);return i(n,e)}stubWrite(t,n){let e=this.writeStubMap.get(t);e||(e=p(),this.writeStubMap.set(t,e)),e.resolves(n)}getWriteStub(t){return this.writeStubMap.get(t)}};o();import{stub as m}from"sinon";var d=class{getBalanceStub;getBlockStub;getTransactionStub;stubGetBalance({args:t,value:n}){if(this.getBalanceStub||(this.getBalanceStub=m()),t){this.getBalanceStub.withArgs(t).resolves(n);return}this.getBalanceStub.resolves(n)}stubGetBlock({args:t,value:n}){if(this.getBlockStub||(this.getBlockStub=m()),t){this.getBlockStub.withArgs(t).resolves(n);return}this.getBlockStub.resolves(n)}stubGetTransaction({args:t,value:n}){if(this.getTransactionStub||(this.getTransactionStub=m()),t){this.getTransactionStub.withArgs(t).resolves(n);return}this.getTransactionStub.resolves(n)}getBalance(...t){if(!this.getBalanceStub)throw new Error(`The getBalance function must be stubbed first: | ||
| contract.stubEvents("${t}", value)`);return e(n)}stubRead({functionName:t,args:n,value:e,options:i}){let r=this.readStubMap.get(t);if(r||(r=d(),this.readStubMap.set(t,r)),n||i){r.withArgs(n,i).resolves(e);return}r.resolves(e)}stubSimulateWrite(t,n){let e=this.simulateWriteStubMap.get(t);e||(e=d(),this.simulateWriteStubMap.set(t,e)),e.resolves(n)}stubEvents(t,n,e){let i=l({eventName:t,args:n});this.eventsStubMap.has(i)?this.getEventsStub(t,n).resolves(e):this.eventsStubMap.set(i,d().resolves(e))}getReadStub(t){return this.readStubMap.get(t)}getSimulateWriteStub(t){return this.simulateWriteStubMap.get(t)}getEventsStub(t,n){let e=l({eventName:t,args:n});return this.eventsStubMap.get(e)}decodeFunctionData(...t){throw new Error("Method not implemented.")}encodeFunctionData(...t){throw new Error("Method not implemented.")}};function l(a){function t(n,e){return typeof e=="bigint"?e.toString():e}return N.stableStringify(a,t)}o();import{stub as g}from"sinon";o();var A="0xBob";var m=class extends s{writeStubMap=new Map;getSignerAddress=g().resolves(A);async write(...[t,n,e]){let i=this.getWriteStub(t);if(!i)throw new Error(`Called write for ${t} on a stubbed contract without a return value. The function must be stubbed first: | ||
| contract.stubWrite("${t}", value)`);return i(n,e)}stubWrite(t,n){let e=this.writeStubMap.get(t);e||(e=g(),this.writeStubMap.set(t,e)),e.resolves(n)}getWriteStub(t){return this.writeStubMap.get(t)}};o();import{stub as c}from"sinon";var T=class{getBalanceStub;getBlockStub;getChainIdStub;getTransactionStub;stubGetBalance({args:t,value:n}){if(this.getBalanceStub||(this.getBalanceStub=c()),t){this.getBalanceStub.withArgs(t).resolves(n);return}this.getBalanceStub.resolves(n)}stubGetBlock({args:t,value:n}){if(this.getBlockStub||(this.getBlockStub=c()),t){this.getBlockStub.withArgs(t).resolves(n);return}this.getBlockStub.resolves(n)}stubGetChainId(t){this.getChainIdStub||(this.getChainIdStub=c()),this.getChainIdStub.resolves(t)}stubGetTransaction({args:t,value:n}){if(this.getTransactionStub||(this.getTransactionStub=c()),t){this.getTransactionStub.withArgs(t).resolves(n);return}this.getTransactionStub.resolves(n)}getBalance(...t){if(!this.getBalanceStub)throw new Error(`The getBalance function must be stubbed first: | ||
| contract.stubGetBalance()`);return this.getBalanceStub(t)}getBlock(...t){if(!this.getBlockStub)throw new Error(`The getBlock function must be stubbed first: | ||
| contract.stubGetBlock()`);return this.getBlockStub(t)}getTransaction(...t){if(!this.getTransactionStub)throw new Error(`The getTransaction function must be stubbed first: | ||
| contract.stubGetTransaction()`);return this.getTransactionStub(t)}async waitForTransaction(...[t,{timeout:n=6e4}={}]){return new Promise(async e=>{let i;if(i=await this.getTransactionStub?.([t]).catch(),i)return e(g(i));let r=0,S=setInterval(async()=>{r+=1e3,i=await this.getTransactionStub?.([t]).catch(),(i||r>=n)&&(clearInterval(S),e(g(i)))},1e3)})}};function g(a){return a?{blockHash:a.blockHash,blockNumber:a.blockNumber,from:a.from,to:a.to,transactionIndex:a.transactionIndex,cumulativeGasUsed:0n,effectiveGasPrice:0n,transactionHash:a.hash,gasUsed:0n,logsBloom:"0x",status:"success"}:void 0}export{d as NetworkStub,s as ReadContractStub,T as ReadWriteContractStub}; | ||
| contract.stubGetBlock()`);return this.getBlockStub(t)}getChainId(){if(!this.getChainIdStub)throw new Error(`The getChainId function must be stubbed first: | ||
| contract.stubGetChainId()`);return this.getChainIdStub()}getTransaction(...t){if(!this.getTransactionStub)throw new Error(`The getTransaction function must be stubbed first: | ||
| contract.stubGetTransaction()`);return this.getTransactionStub(t)}async waitForTransaction(...[t,{timeout:n=6e4}={}]){return new Promise(async e=>{let i;if(i=await this.getTransactionStub?.([t]).catch(),i)return e(S(i));let r=0,p=setInterval(async()=>{r+=1e3,i=await this.getTransactionStub?.([t]).catch(),(i||r>=n)&&(clearInterval(p),e(S(i)))},1e3)})}};function S(a){return a?{blockHash:a.blockHash,blockNumber:a.blockNumber,from:a.from,to:a.to,transactionIndex:a.transactionIndex,cumulativeGasUsed:0n,effectiveGasPrice:0n,transactionHash:a.hash,gasUsed:0n,logsBloom:"0x",status:"success"}:void 0}export{T as NetworkStub,s as ReadContractStub,m as ReadWriteContractStub}; | ||
| //# sourceMappingURL=stubs.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/exports/stubs.ts","../src/contract/stubs/ReadContractStub.ts","../src/contract/stubs/ReadWriteContractStub.ts","../src/base/testing/accounts.ts","../src/network/stubs/NetworkStub.ts"],"sourcesContent":["// Contract\nexport { ReadContractStub } from 'src/contract/stubs/ReadContractStub';\nexport { ReadWriteContractStub } from 'src/contract/stubs/ReadWriteContractStub';\n\n// Network\nexport { NetworkStub } from 'src/network/stubs/NetworkStub';\n","import { Abi } from 'abitype';\nimport stringify from 'fast-safe-stringify';\nimport { SinonStub, stub } from 'sinon';\nimport {\n ContractDecodeFunctionDataArgs,\n ContractEncodeFunctionDataArgs,\n ContractGetEventsArgs,\n ContractGetEventsOptions,\n ContractReadArgs,\n ContractReadOptions,\n ContractWriteArgs,\n ContractWriteOptions,\n ReadContract,\n} from 'src/contract/types/Contract';\nimport { Event, EventName } from 'src/contract/types/Event';\nimport {\n DecodedFunctionData,\n FunctionArgs,\n FunctionName,\n FunctionReturn,\n} from 'src/contract/types/Function';\n\n/**\n * A mock implementation of a `ReadContract` designed to facilitate unit\n * testing. The `ReadContractStub` provides a way to stub out specific\n * contract read, write, and event-fetching behaviors, allowing tests to focus\n * on the business logic of the SDK.\n *\n * @example\n * const contract = new ReadContractStub(ERC20ABI);\n * contract.stubRead(\"baseToken\", \"0x123abc\");\n *\n * const value = await contract.read(\"baseToken\", []); // \"0x123abc\"\n *\n */\nexport class ReadContractStub<TAbi extends Abi = Abi>\n implements ReadContract<TAbi>\n{\n abi;\n address = '0x0000000000000000000000000000000000000000' as const;\n\n // Maps to store stubs for different contract methods based on their name.\n protected readStubMap = new Map<\n FunctionName<TAbi>,\n ReadStub<TAbi, FunctionName<TAbi>>\n >();\n protected eventsStubMap = new Map<\n EventName<TAbi>,\n EventsStub<TAbi, EventName<TAbi>>\n >();\n protected simulateWriteStubMap = new Map<\n FunctionName<TAbi, 'nonpayable' | 'payable'>,\n SimulateWriteStub<TAbi, FunctionName<TAbi, 'nonpayable' | 'payable'>>\n >();\n\n constructor(abi: TAbi = [] as any) {\n this.abi = abi;\n }\n\n /**\n * Simulates a contract read operation for a given function. If the function\n * is not previously stubbed using `stubRead`, an error will be thrown.\n */\n async read<TFunctionName extends FunctionName<TAbi>>(\n ...[functionName, args, options]: ContractReadArgs<TAbi, TFunctionName>\n ): Promise<FunctionReturn<TAbi, TFunctionName>> {\n const stub = this.getReadStub(functionName);\n if (!stub) {\n throw new Error(\n `Called read for ${functionName} on a stubbed contract without a return value. The function must be stubbed first:\\n\\tcontract.stubRead(\"${functionName}\", value)`,\n );\n }\n return stub(args, options);\n }\n\n /**\n * Simulates a contract write operation for a given function. If the function\n * is not previously stubbed using `stubWrite`, an error will be thrown.\n */\n async simulateWrite<\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n >(\n ...[functionName, args, options]: ContractWriteArgs<TAbi, TFunctionName>\n ): Promise<FunctionReturn<TAbi, TFunctionName>> {\n const stub = this.getSimulateWriteStub(functionName);\n if (!stub) {\n throw new Error(\n `Called simulateWrite for ${functionName} on a stubbed contract without a return value. The function must be stubbed first:\\n\\tcontract.stubWrite(\"${functionName}\", value)`,\n );\n }\n return stub(args, options);\n }\n\n /**\n * Simulates fetching events for a given event name from the contract. If the\n * event name is not previously stubbed using `stubEvents`, an error will be\n * thrown.\n */\n async getEvents<TEventName extends EventName<TAbi>>(\n ...[eventName, options]: ContractGetEventsArgs<TAbi, TEventName>\n ): Promise<Event<TAbi, TEventName>[]> {\n const stub = this.getEventsStub(eventName, options);\n if (!stub) {\n throw new Error(\n `Called getEvents for ${eventName} on a stubbed contract without a return value. The function must be stubbed first:\\n\\tcontract.stubEvents(\"${eventName}\", value)`,\n );\n }\n return stub(options);\n }\n\n /**\n * Stubs the return value for a given function when `read` is called with that\n * function name. This method overrides any previously stubbed values for the\n * same function.\n */\n stubRead<TFunctionName extends FunctionName<TAbi>>({\n functionName,\n args,\n value,\n options,\n }: {\n functionName: TFunctionName;\n args?: FunctionArgs<TAbi, TFunctionName>;\n value: FunctionReturn<TAbi, TFunctionName>;\n options?: ContractReadOptions;\n }): void {\n let readStub = this.readStubMap.get(functionName);\n if (!readStub) {\n readStub = stub();\n this.readStubMap.set(functionName, readStub);\n }\n\n // Account for dynamic args if provided\n if (args || options) {\n // The stub returned from the map doesn't have a strong FunctionName type\n // so we have to cast to avoid contravariance errors with the args.\n (readStub as ReadStub<TAbi, TFunctionName>)\n .withArgs(args, options)\n .resolves(value);\n return;\n }\n\n readStub.resolves(value);\n }\n\n /**\n * Stubs the return value for a given function when `simulateWrite` is called\n * with that function name. This method overrides any previously stubbed\n * values for the same function.\n *\n * *Note: The stub doesn't account for dynamic values based on provided\n * arguments/options.*\n */\n stubSimulateWrite<\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n >(\n functionName: TFunctionName,\n value: FunctionReturn<TAbi, TFunctionName>,\n ): void {\n let simulateWriteStub = this.simulateWriteStubMap.get(functionName);\n if (!simulateWriteStub) {\n simulateWriteStub = stub();\n this.simulateWriteStubMap.set(functionName, simulateWriteStub);\n }\n simulateWriteStub.resolves(value);\n }\n\n /**\n * Stubs the return value for a given event name when `getEvents` is called\n * with that event name. This method overrides any previously stubbed values\n * for the same event.\n */\n stubEvents<TEventName extends EventName<TAbi>>(\n eventName: TEventName,\n args: ContractGetEventsOptions<TAbi, TEventName> | undefined,\n value: Event<TAbi, TEventName>[],\n ): void {\n const stubKey = stableStringify({ eventName, args });\n if (this.eventsStubMap.has(stubKey)) {\n this.getEventsStub(eventName, args)!.resolves(value as any);\n } else {\n this.eventsStubMap.set(stubKey, stub().resolves(value) as any);\n }\n }\n\n /**\n * Retrieves the stub associated with a read function name.\n * Useful for assertions in testing, such as checking call counts.\n */\n getReadStub<TFunctionName extends FunctionName<TAbi>>(\n functionName: TFunctionName,\n ): ReadStub<TAbi, TFunctionName> | undefined {\n return this.readStubMap.get(functionName) as\n | ReadStub<TAbi, TFunctionName>\n | undefined;\n }\n\n /**\n * Retrieves the stub associated with a write function name.\n * Useful for assertions in testing, such as checking call counts.\n */\n getSimulateWriteStub<\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n >(\n functionName: TFunctionName,\n ): SimulateWriteStub<TAbi, TFunctionName> | undefined {\n return this.simulateWriteStubMap.get(functionName) as\n | SimulateWriteStub<TAbi, TFunctionName>\n | undefined;\n }\n\n /**\n * Retrieves the stub associated with an event name.\n * Useful for assertions in testing, such as checking call counts.\n */\n getEventsStub<TEventName extends EventName<TAbi>>(\n eventName: TEventName,\n args?: ContractGetEventsOptions<TAbi, TEventName> | undefined,\n ): EventsStub<TAbi, TEventName> | undefined {\n const stubKey = stableStringify({ eventName, args });\n return this.eventsStubMap.get(stubKey) as\n | EventsStub<TAbi, TEventName>\n | undefined;\n }\n\n // TODO:\n decodeFunctionData<\n TFunctionName extends FunctionName<TAbi> = FunctionName<TAbi>,\n >(\n ...args: ContractDecodeFunctionDataArgs\n ): DecodedFunctionData<TAbi, TFunctionName> {\n throw new Error('Method not implemented.');\n }\n\n // TODO:\n encodeFunctionData<\n TFunctionName extends FunctionName<TAbi> = FunctionName<TAbi>,\n >(\n ...args: ContractEncodeFunctionDataArgs<TAbi, TFunctionName>\n ): `0x${string}` {\n throw new Error('Method not implemented.');\n }\n}\n\n/**\n * Type representing a stub for the \"read\" function of a contract.\n */\ntype ReadStub<\n TAbi extends Abi,\n TFunctionName extends FunctionName<TAbi>,\n> = SinonStub<\n [args?: FunctionArgs<TAbi, TFunctionName>, options?: ContractReadOptions],\n Promise<FunctionReturn<TAbi, TFunctionName>>\n>;\n\n/**\n * Type representing a stub for the \"getEvents\" function of a contract.\n */\ntype EventsStub<\n TAbi extends Abi,\n TEventName extends EventName<TAbi>,\n> = SinonStub<\n [options?: ContractGetEventsOptions<TAbi, TEventName>],\n Promise<Event<TAbi, TEventName>[]>\n>;\n\n/**\n * Type representing a stub for the \"write\" and \"simulateWrite\" functions of a\n * contract.\n */\ntype SimulateWriteStub<\n TAbi extends Abi,\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n> = SinonStub<\n [\n args?: FunctionArgs<TAbi, TFunctionName> | undefined,\n options?: ContractWriteOptions,\n ],\n Promise<FunctionReturn<TAbi, TFunctionName>>\n>;\n\nfunction stableStringify(obj: Record<any, any>) {\n // simple non-recursive stringify replacer for bigints\n function replacer(_: any, v: any) {\n return typeof v === 'bigint' ? v.toString() : v;\n }\n\n return stringify.stableStringify(obj, replacer);\n}\n","import { Abi } from 'abitype';\nimport { SinonStub, stub } from 'sinon';\nimport { BOB } from 'src/base/testing/accounts';\nimport { ReadContractStub } from 'src/contract/stubs/ReadContractStub';\nimport {\n ContractWriteArgs,\n ContractWriteOptions,\n ReadWriteContract,\n} from 'src/contract/types/Contract';\nimport { FunctionArgs, FunctionName } from 'src/contract/types/Function';\n\n/**\n * A mock implementation of a writable Ethereum contract designed for unit\n * testing purposes. The `ReadWriteContractStub` extends the functionalities of\n * `ReadContractStub` and provides capabilities to stub out specific\n * contract write behaviors. This makes it a valuable tool when testing\n * scenarios that involve contract writing operations, without actually\n * interacting with a real Ethereum contract.\n *\n * @example\n * const contract = new ReadWriteContractStub(ERC20ABI);\n * contract.stubWrite(\"addLiquidity\", 100n);\n *\n * const result = await contract.write(\"addLiquidity\", []); // 100n\n * @extends {ReadContractStub<TAbi>}\n * @implements {ReadWriteContract<TAbi>}\n */\nexport class ReadWriteContractStub<TAbi extends Abi = Abi>\n extends ReadContractStub<TAbi>\n implements ReadWriteContract<TAbi>\n{\n protected writeStubMap = new Map<\n FunctionName<TAbi, 'nonpayable' | 'payable'>,\n WriteStub<TAbi, FunctionName<TAbi, 'nonpayable' | 'payable'>>\n >();\n\n getSignerAddress = stub().resolves(BOB);\n\n /**\n * Simulates a contract write operation for a given function. If the function\n * is not previously stubbed using `stubWrite` from the parent class, an error\n * will be thrown.\n */\n async write<\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n >(\n ...[functionName, args, options]: ContractWriteArgs<TAbi, TFunctionName>\n ): Promise<`0x${string}`> {\n const stub = this.getWriteStub(functionName);\n if (!stub) {\n throw new Error(\n `Called write for ${functionName} on a stubbed contract without a return value. The function must be stubbed first:\\n\\tcontract.stubWrite(\"${functionName}\", value)`,\n );\n }\n return stub(args, options);\n }\n\n /**\n * Stubs the return value for a given function when `simulateWrite` is called\n * with that function name. This method overrides any previously stubbed\n * values for the same function.\n *\n * *Note: The stub doesn't account for dynamic values based on provided\n * arguments/options.*\n */\n stubWrite<TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>>(\n functionName: TFunctionName,\n value: `0x${string}`,\n ): void {\n let writeStub = this.writeStubMap.get(functionName);\n if (!writeStub) {\n writeStub = stub();\n this.writeStubMap.set(functionName, writeStub);\n }\n writeStub.resolves(value);\n }\n\n /**\n * Retrieves the stub associated with a write function name.\n * Useful for assertions in testing, such as checking call counts.\n */\n getWriteStub<\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n >(functionName: TFunctionName): WriteStub<TAbi, TFunctionName> | undefined {\n return this.writeStubMap.get(functionName) as WriteStub<\n TAbi,\n TFunctionName\n >;\n }\n}\n\n/**\n * Type representing a stub for the \"write\" and \"simulateWrite\" functions of a\n * contract.\n */\ntype WriteStub<\n TAbi extends Abi,\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n> = SinonStub<\n [args?: FunctionArgs<TAbi, TFunctionName>, options?: ContractWriteOptions],\n `0x${string}`\n>;\n","export const BOB = '0xBob';\nexport const ALICE = '0xAlice';\nexport const NANCY = '0xNancy';\n","import { SinonStub, stub } from 'sinon';\nimport { Block } from 'src/network/types/Block';\nimport {\n Network,\n NetworkGetBalanceArgs,\n NetworkGetBlockArgs,\n NetworkGetTransactionArgs,\n NetworkWaitForTransactionArgs,\n} from 'src/network/types/Network';\nimport { Transaction, TransactionReceipt } from 'src/network/types/Transaction';\n\n/**\n * A mock implementation of a `Network` designed to facilitate unit\n * testing.\n */\nexport class NetworkStub implements Network {\n protected getBalanceStub:\n | SinonStub<[NetworkGetBalanceArgs?], Promise<bigint>>\n | undefined;\n protected getBlockStub:\n | SinonStub<[NetworkGetBlockArgs?], Promise<Block | undefined>>\n | undefined;\n protected getTransactionStub:\n | SinonStub<[NetworkGetTransactionArgs?], Promise<Transaction | undefined>>\n | undefined;\n\n stubGetBalance({\n args,\n value,\n }: {\n args?: NetworkGetBalanceArgs | undefined;\n value: bigint;\n }): void {\n if (!this.getBalanceStub) {\n this.getBalanceStub = stub();\n }\n\n // Account for dynamic args if provided\n if (args) {\n this.getBalanceStub.withArgs(args).resolves(value);\n return;\n }\n\n this.getBalanceStub.resolves(value);\n }\n\n stubGetBlock({\n args,\n value,\n }: {\n args?: NetworkGetBlockArgs | undefined;\n value: Block | undefined;\n }): void {\n if (!this.getBlockStub) {\n this.getBlockStub = stub();\n }\n\n // Account for dynamic args if provided\n if (args) {\n this.getBlockStub.withArgs(args).resolves(value);\n return;\n }\n\n this.getBlockStub.resolves(value);\n }\n\n stubGetTransaction({\n args,\n value,\n }: {\n args?: NetworkGetTransactionArgs;\n value: Transaction | undefined;\n }): void {\n if (!this.getTransactionStub) {\n this.getTransactionStub = stub();\n }\n\n // Account for dynamic args if provided\n if (args) {\n this.getTransactionStub.withArgs(args).resolves(value);\n return;\n }\n\n this.getTransactionStub.resolves(value);\n }\n\n getBalance(...args: NetworkGetBalanceArgs): Promise<bigint> {\n if (!this.getBalanceStub) {\n throw new Error(\n `The getBalance function must be stubbed first:\\n\\tcontract.stubGetBalance()`,\n );\n }\n return this.getBalanceStub(args);\n }\n\n getBlock(...args: NetworkGetBlockArgs): Promise<Block | undefined> {\n if (!this.getBlockStub) {\n throw new Error(\n `The getBlock function must be stubbed first:\\n\\tcontract.stubGetBlock()`,\n );\n }\n return this.getBlockStub(args);\n }\n\n getTransaction(\n ...args: NetworkGetTransactionArgs\n ): Promise<Transaction | undefined> {\n if (!this.getTransactionStub) {\n throw new Error(\n `The getTransaction function must be stubbed first:\\n\\tcontract.stubGetTransaction()`,\n );\n }\n return this.getTransactionStub(args);\n }\n\n async waitForTransaction(\n ...[hash, { timeout = 60_000 } = {}]: NetworkWaitForTransactionArgs\n ): Promise<TransactionReceipt | undefined> {\n return new Promise(async (resolve) => {\n let transaction: Transaction | undefined;\n\n transaction = await this.getTransactionStub?.([hash]).catch();\n\n if (transaction) {\n return resolve(transactionToReceipt(transaction));\n }\n\n // Poll for the transaction until it's found or the timeout is reached\n let waitedTime = 0;\n const interval = setInterval(async () => {\n waitedTime += 1000;\n transaction = await this.getTransactionStub?.([hash]).catch();\n if (transaction || waitedTime >= timeout) {\n clearInterval(interval);\n resolve(transactionToReceipt(transaction));\n }\n }, 1000);\n });\n }\n}\n\nexport function transactionToReceipt(\n transaction: Transaction | undefined,\n): TransactionReceipt | undefined {\n return transaction\n ? {\n blockHash: transaction.blockHash!,\n blockNumber: transaction.blockNumber!,\n from: transaction.from!,\n to: transaction.to!,\n transactionIndex: transaction.transactionIndex!,\n cumulativeGasUsed: 0n,\n effectiveGasPrice: 0n,\n transactionHash: transaction.hash!,\n gasUsed: 0n,\n logsBloom: '0x',\n status: 'success',\n }\n : undefined;\n}\n"],"mappings":"wCAAAA,ICAAC,IACA,OAAOC,MAAe,sBACtB,OAAoB,QAAAC,MAAY,QAiCzB,IAAMC,EAAN,KAEP,CACE,IACA,QAAU,6CAGA,YAAc,IAAI,IAIlB,cAAgB,IAAI,IAIpB,qBAAuB,IAAI,IAKrC,YAAYC,EAAY,CAAC,EAAU,CACjC,KAAK,IAAMA,CACb,CAMA,MAAM,QACD,CAACC,EAAcC,EAAMC,CAAO,EACe,CAC9C,IAAML,EAAO,KAAK,YAAYG,CAAY,EAC1C,GAAI,CAACH,EACH,MAAM,IAAI,MACR,mBAAmBG,CAAY;AAAA,sBAA4GA,CAAY,WACzJ,EAEF,OAAOH,EAAKI,EAAMC,CAAO,CAC3B,CAMA,MAAM,iBAGD,CAACF,EAAcC,EAAMC,CAAO,EACe,CAC9C,IAAML,EAAO,KAAK,qBAAqBG,CAAY,EACnD,GAAI,CAACH,EACH,MAAM,IAAI,MACR,4BAA4BG,CAAY;AAAA,uBAA6GA,CAAY,WACnK,EAEF,OAAOH,EAAKI,EAAMC,CAAO,CAC3B,CAOA,MAAM,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YACzB,KAAMA,EAAY,KAClB,GAAIA,EAAY,GAChB,iBAAkBA,EAAY,iBAC9B,kBAAmB,GACnB,kBAAmB,GACnB,gBAAiBA,EAAY,KAC7B,QAAS,GACT,UAAW,KACX,OAAQ,SACV,EACA,MACN","names":["init_esm_shims","init_esm_shims","stringify","stub","ReadContractStub","abi","functionName","args","options","eventName","value","readStub","simulateWriteStub","stubKey","stableStringify","obj","replacer","_","v","init_esm_shims","stub","init_esm_shims","BOB","ReadWriteContractStub","ReadContractStub","stub","BOB","functionName","args","options","value","writeStub","init_esm_shims","stub","NetworkStub","args","value","hash","timeout","resolve","transaction","transactionToReceipt","waitedTime","interval"]} | ||
| {"version":3,"sources":["../src/exports/stubs.ts","../src/contract/stubs/ReadContractStub.ts","../src/contract/stubs/ReadWriteContractStub.ts","../src/base/testing/accounts.ts","../src/network/stubs/NetworkStub.ts"],"sourcesContent":["// Contract\nexport { ReadContractStub } from 'src/contract/stubs/ReadContractStub';\nexport { ReadWriteContractStub } from 'src/contract/stubs/ReadWriteContractStub';\n\n// Network\nexport { NetworkStub } from 'src/network/stubs/NetworkStub';\n","import { Abi } from 'abitype';\nimport stringify from 'fast-safe-stringify';\nimport { SinonStub, stub } from 'sinon';\nimport {\n ContractDecodeFunctionDataArgs,\n ContractEncodeFunctionDataArgs,\n ContractGetEventsArgs,\n ContractGetEventsOptions,\n ContractReadArgs,\n ContractReadOptions,\n ContractWriteArgs,\n ContractWriteOptions,\n ReadContract,\n} from 'src/contract/types/Contract';\nimport { Event, EventName } from 'src/contract/types/Event';\nimport {\n DecodedFunctionData,\n FunctionArgs,\n FunctionName,\n FunctionReturn,\n} from 'src/contract/types/Function';\n\n/**\n * A mock implementation of a `ReadContract` designed to facilitate unit\n * testing. The `ReadContractStub` provides a way to stub out specific\n * contract read, write, and event-fetching behaviors, allowing tests to focus\n * on the business logic of the SDK.\n *\n * @example\n * const contract = new ReadContractStub(ERC20ABI);\n * contract.stubRead(\"baseToken\", \"0x123abc\");\n *\n * const value = await contract.read(\"baseToken\", []); // \"0x123abc\"\n *\n */\nexport class ReadContractStub<TAbi extends Abi = Abi>\n implements ReadContract<TAbi>\n{\n abi;\n address = '0x0000000000000000000000000000000000000000' as const;\n\n // Maps to store stubs for different contract methods based on their name.\n protected readStubMap = new Map<\n FunctionName<TAbi>,\n ReadStub<TAbi, FunctionName<TAbi>>\n >();\n protected eventsStubMap = new Map<\n EventName<TAbi>,\n EventsStub<TAbi, EventName<TAbi>>\n >();\n protected simulateWriteStubMap = new Map<\n FunctionName<TAbi, 'nonpayable' | 'payable'>,\n SimulateWriteStub<TAbi, FunctionName<TAbi, 'nonpayable' | 'payable'>>\n >();\n\n constructor(abi: TAbi = [] as any) {\n this.abi = abi;\n }\n\n /**\n * Simulates a contract read operation for a given function. If the function\n * is not previously stubbed using `stubRead`, an error will be thrown.\n */\n async read<TFunctionName extends FunctionName<TAbi>>(\n ...[functionName, args, options]: ContractReadArgs<TAbi, TFunctionName>\n ): Promise<FunctionReturn<TAbi, TFunctionName>> {\n const stub = this.getReadStub(functionName);\n if (!stub) {\n throw new Error(\n `Called read for ${functionName} on a stubbed contract without a return value. The function must be stubbed first:\\n\\tcontract.stubRead(\"${functionName}\", value)`,\n );\n }\n return stub(args, options);\n }\n\n /**\n * Simulates a contract write operation for a given function. If the function\n * is not previously stubbed using `stubWrite`, an error will be thrown.\n */\n async simulateWrite<\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n >(\n ...[functionName, args, options]: ContractWriteArgs<TAbi, TFunctionName>\n ): Promise<FunctionReturn<TAbi, TFunctionName>> {\n const stub = this.getSimulateWriteStub(functionName);\n if (!stub) {\n throw new Error(\n `Called simulateWrite for ${functionName} on a stubbed contract without a return value. The function must be stubbed first:\\n\\tcontract.stubWrite(\"${functionName}\", value)`,\n );\n }\n return stub(args, options);\n }\n\n /**\n * Simulates fetching events for a given event name from the contract. If the\n * event name is not previously stubbed using `stubEvents`, an error will be\n * thrown.\n */\n async getEvents<TEventName extends EventName<TAbi>>(\n ...[eventName, options]: ContractGetEventsArgs<TAbi, TEventName>\n ): Promise<Event<TAbi, TEventName>[]> {\n const stub = this.getEventsStub(eventName, options);\n if (!stub) {\n throw new Error(\n `Called getEvents for ${eventName} on a stubbed contract without a return value. The function must be stubbed first:\\n\\tcontract.stubEvents(\"${eventName}\", value)`,\n );\n }\n return stub(options);\n }\n\n /**\n * Stubs the return value for a given function when `read` is called with that\n * function name. This method overrides any previously stubbed values for the\n * same function.\n */\n stubRead<TFunctionName extends FunctionName<TAbi>>({\n functionName,\n args,\n value,\n options,\n }: {\n functionName: TFunctionName;\n args?: FunctionArgs<TAbi, TFunctionName>;\n value: FunctionReturn<TAbi, TFunctionName>;\n options?: ContractReadOptions;\n }): void {\n let readStub = this.readStubMap.get(functionName);\n if (!readStub) {\n readStub = stub();\n this.readStubMap.set(functionName, readStub);\n }\n\n // Account for dynamic args if provided\n if (args || options) {\n // The stub returned from the map doesn't have a strong FunctionName type\n // so we have to cast to avoid contravariance errors with the args.\n (readStub as ReadStub<TAbi, TFunctionName>)\n .withArgs(args, options)\n .resolves(value);\n return;\n }\n\n readStub.resolves(value);\n }\n\n /**\n * Stubs the return value for a given function when `simulateWrite` is called\n * with that function name. This method overrides any previously stubbed\n * values for the same function.\n *\n * *Note: The stub doesn't account for dynamic values based on provided\n * arguments/options.*\n */\n stubSimulateWrite<\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n >(\n functionName: TFunctionName,\n value: FunctionReturn<TAbi, TFunctionName>,\n ): void {\n let simulateWriteStub = this.simulateWriteStubMap.get(functionName);\n if (!simulateWriteStub) {\n simulateWriteStub = stub();\n this.simulateWriteStubMap.set(functionName, simulateWriteStub);\n }\n simulateWriteStub.resolves(value);\n }\n\n /**\n * Stubs the return value for a given event name when `getEvents` is called\n * with that event name. This method overrides any previously stubbed values\n * for the same event.\n */\n stubEvents<TEventName extends EventName<TAbi>>(\n eventName: TEventName,\n args: ContractGetEventsOptions<TAbi, TEventName> | undefined,\n value: Event<TAbi, TEventName>[],\n ): void {\n const stubKey = stableStringify({ eventName, args });\n if (this.eventsStubMap.has(stubKey)) {\n this.getEventsStub(eventName, args)!.resolves(value as any);\n } else {\n this.eventsStubMap.set(stubKey, stub().resolves(value) as any);\n }\n }\n\n /**\n * Retrieves the stub associated with a read function name.\n * Useful for assertions in testing, such as checking call counts.\n */\n getReadStub<TFunctionName extends FunctionName<TAbi>>(\n functionName: TFunctionName,\n ): ReadStub<TAbi, TFunctionName> | undefined {\n return this.readStubMap.get(functionName) as\n | ReadStub<TAbi, TFunctionName>\n | undefined;\n }\n\n /**\n * Retrieves the stub associated with a write function name.\n * Useful for assertions in testing, such as checking call counts.\n */\n getSimulateWriteStub<\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n >(\n functionName: TFunctionName,\n ): SimulateWriteStub<TAbi, TFunctionName> | undefined {\n return this.simulateWriteStubMap.get(functionName) as\n | SimulateWriteStub<TAbi, TFunctionName>\n | undefined;\n }\n\n /**\n * Retrieves the stub associated with an event name.\n * Useful for assertions in testing, such as checking call counts.\n */\n getEventsStub<TEventName extends EventName<TAbi>>(\n eventName: TEventName,\n args?: ContractGetEventsOptions<TAbi, TEventName> | undefined,\n ): EventsStub<TAbi, TEventName> | undefined {\n const stubKey = stableStringify({ eventName, args });\n return this.eventsStubMap.get(stubKey) as\n | EventsStub<TAbi, TEventName>\n | undefined;\n }\n\n // TODO:\n decodeFunctionData<\n TFunctionName extends FunctionName<TAbi> = FunctionName<TAbi>,\n >(\n ...args: ContractDecodeFunctionDataArgs\n ): DecodedFunctionData<TAbi, TFunctionName> {\n throw new Error('Method not implemented.');\n }\n\n // TODO:\n encodeFunctionData<\n TFunctionName extends FunctionName<TAbi> = FunctionName<TAbi>,\n >(\n ...args: ContractEncodeFunctionDataArgs<TAbi, TFunctionName>\n ): `0x${string}` {\n throw new Error('Method not implemented.');\n }\n}\n\n/**\n * Type representing a stub for the \"read\" function of a contract.\n */\ntype ReadStub<\n TAbi extends Abi,\n TFunctionName extends FunctionName<TAbi>,\n> = SinonStub<\n [args?: FunctionArgs<TAbi, TFunctionName>, options?: ContractReadOptions],\n Promise<FunctionReturn<TAbi, TFunctionName>>\n>;\n\n/**\n * Type representing a stub for the \"getEvents\" function of a contract.\n */\ntype EventsStub<\n TAbi extends Abi,\n TEventName extends EventName<TAbi>,\n> = SinonStub<\n [options?: ContractGetEventsOptions<TAbi, TEventName>],\n Promise<Event<TAbi, TEventName>[]>\n>;\n\n/**\n * Type representing a stub for the \"write\" and \"simulateWrite\" functions of a\n * contract.\n */\ntype SimulateWriteStub<\n TAbi extends Abi,\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n> = SinonStub<\n [\n args?: FunctionArgs<TAbi, TFunctionName> | undefined,\n options?: ContractWriteOptions,\n ],\n Promise<FunctionReturn<TAbi, TFunctionName>>\n>;\n\nfunction stableStringify(obj: Record<any, any>) {\n // simple non-recursive stringify replacer for bigints\n function replacer(_: any, v: any) {\n return typeof v === 'bigint' ? v.toString() : v;\n }\n\n return stringify.stableStringify(obj, replacer);\n}\n","import { Abi } from 'abitype';\nimport { SinonStub, stub } from 'sinon';\nimport { BOB } from 'src/base/testing/accounts';\nimport { ReadContractStub } from 'src/contract/stubs/ReadContractStub';\nimport {\n ContractWriteArgs,\n ContractWriteOptions,\n ReadWriteContract,\n} from 'src/contract/types/Contract';\nimport { FunctionArgs, FunctionName } from 'src/contract/types/Function';\n\n/**\n * A mock implementation of a writable Ethereum contract designed for unit\n * testing purposes. The `ReadWriteContractStub` extends the functionalities of\n * `ReadContractStub` and provides capabilities to stub out specific\n * contract write behaviors. This makes it a valuable tool when testing\n * scenarios that involve contract writing operations, without actually\n * interacting with a real Ethereum contract.\n *\n * @example\n * const contract = new ReadWriteContractStub(ERC20ABI);\n * contract.stubWrite(\"addLiquidity\", 100n);\n *\n * const result = await contract.write(\"addLiquidity\", []); // 100n\n * @extends {ReadContractStub<TAbi>}\n * @implements {ReadWriteContract<TAbi>}\n */\nexport class ReadWriteContractStub<TAbi extends Abi = Abi>\n extends ReadContractStub<TAbi>\n implements ReadWriteContract<TAbi>\n{\n protected writeStubMap = new Map<\n FunctionName<TAbi, 'nonpayable' | 'payable'>,\n WriteStub<TAbi, FunctionName<TAbi, 'nonpayable' | 'payable'>>\n >();\n\n getSignerAddress = stub().resolves(BOB);\n\n /**\n * Simulates a contract write operation for a given function. If the function\n * is not previously stubbed using `stubWrite` from the parent class, an error\n * will be thrown.\n */\n async write<\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n >(\n ...[functionName, args, options]: ContractWriteArgs<TAbi, TFunctionName>\n ): Promise<`0x${string}`> {\n const stub = this.getWriteStub(functionName);\n if (!stub) {\n throw new Error(\n `Called write for ${functionName} on a stubbed contract without a return value. The function must be stubbed first:\\n\\tcontract.stubWrite(\"${functionName}\", value)`,\n );\n }\n return stub(args, options);\n }\n\n /**\n * Stubs the return value for a given function when `simulateWrite` is called\n * with that function name. This method overrides any previously stubbed\n * values for the same function.\n *\n * *Note: The stub doesn't account for dynamic values based on provided\n * arguments/options.*\n */\n stubWrite<TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>>(\n functionName: TFunctionName,\n value: `0x${string}`,\n ): void {\n let writeStub = this.writeStubMap.get(functionName);\n if (!writeStub) {\n writeStub = stub();\n this.writeStubMap.set(functionName, writeStub);\n }\n writeStub.resolves(value);\n }\n\n /**\n * Retrieves the stub associated with a write function name.\n * Useful for assertions in testing, such as checking call counts.\n */\n getWriteStub<\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n >(functionName: TFunctionName): WriteStub<TAbi, TFunctionName> | undefined {\n return this.writeStubMap.get(functionName) as WriteStub<\n TAbi,\n TFunctionName\n >;\n }\n}\n\n/**\n * Type representing a stub for the \"write\" and \"simulateWrite\" functions of a\n * contract.\n */\ntype WriteStub<\n TAbi extends Abi,\n TFunctionName extends FunctionName<TAbi, 'nonpayable' | 'payable'>,\n> = SinonStub<\n [args?: FunctionArgs<TAbi, TFunctionName>, options?: ContractWriteOptions],\n `0x${string}`\n>;\n","export const BOB = '0xBob';\nexport const ALICE = '0xAlice';\nexport const NANCY = '0xNancy';\n","import { SinonStub, stub } from 'sinon';\nimport { Block } from 'src/network/types/Block';\nimport {\n Network,\n NetworkGetBalanceArgs,\n NetworkGetBlockArgs,\n NetworkGetTransactionArgs,\n NetworkWaitForTransactionArgs,\n} from 'src/network/types/Network';\nimport { Transaction, TransactionReceipt } from 'src/network/types/Transaction';\n\n/**\n * A mock implementation of a `Network` designed to facilitate unit\n * testing.\n */\nexport class NetworkStub implements Network {\n protected getBalanceStub:\n | SinonStub<[NetworkGetBalanceArgs?], Promise<bigint>>\n | undefined;\n protected getBlockStub:\n | SinonStub<[NetworkGetBlockArgs?], Promise<Block | undefined>>\n | undefined;\n protected getChainIdStub: SinonStub<[], Promise<number>> | undefined;\n protected getTransactionStub:\n | SinonStub<[NetworkGetTransactionArgs?], Promise<Transaction | undefined>>\n | undefined;\n\n stubGetBalance({\n args,\n value,\n }: {\n args?: NetworkGetBalanceArgs | undefined;\n value: bigint;\n }): void {\n if (!this.getBalanceStub) {\n this.getBalanceStub = stub();\n }\n\n // Account for dynamic args if provided\n if (args) {\n this.getBalanceStub.withArgs(args).resolves(value);\n return;\n }\n\n this.getBalanceStub.resolves(value);\n }\n\n stubGetBlock({\n args,\n value,\n }: {\n args?: NetworkGetBlockArgs | undefined;\n value: Block | undefined;\n }): void {\n if (!this.getBlockStub) {\n this.getBlockStub = stub();\n }\n\n // Account for dynamic args if provided\n if (args) {\n this.getBlockStub.withArgs(args).resolves(value);\n return;\n }\n\n this.getBlockStub.resolves(value);\n }\n\n stubGetChainId(id: number): void {\n if (!this.getChainIdStub) {\n this.getChainIdStub = stub();\n }\n\n this.getChainIdStub.resolves(id);\n }\n\n stubGetTransaction({\n args,\n value,\n }: {\n args?: NetworkGetTransactionArgs;\n value: Transaction | undefined;\n }): void {\n if (!this.getTransactionStub) {\n this.getTransactionStub = stub();\n }\n\n // Account for dynamic args if provided\n if (args) {\n this.getTransactionStub.withArgs(args).resolves(value);\n return;\n }\n\n this.getTransactionStub.resolves(value);\n }\n\n getBalance(...args: NetworkGetBalanceArgs): Promise<bigint> {\n if (!this.getBalanceStub) {\n throw new Error(\n `The getBalance function must be stubbed first:\\n\\tcontract.stubGetBalance()`,\n );\n }\n return this.getBalanceStub(args);\n }\n\n getBlock(...args: NetworkGetBlockArgs): Promise<Block | undefined> {\n if (!this.getBlockStub) {\n throw new Error(\n `The getBlock function must be stubbed first:\\n\\tcontract.stubGetBlock()`,\n );\n }\n return this.getBlockStub(args);\n }\n\n getChainId(): Promise<number> {\n if (!this.getChainIdStub) {\n throw new Error(\n `The getChainId function must be stubbed first:\\n\\tcontract.stubGetChainId()`,\n );\n }\n return this.getChainIdStub();\n }\n\n getTransaction(\n ...args: NetworkGetTransactionArgs\n ): Promise<Transaction | undefined> {\n if (!this.getTransactionStub) {\n throw new Error(\n `The getTransaction function must be stubbed first:\\n\\tcontract.stubGetTransaction()`,\n );\n }\n return this.getTransactionStub(args);\n }\n\n async waitForTransaction(\n ...[hash, { timeout = 60_000 } = {}]: NetworkWaitForTransactionArgs\n ): Promise<TransactionReceipt | undefined> {\n return new Promise(async (resolve) => {\n let transaction: Transaction | undefined;\n\n transaction = await this.getTransactionStub?.([hash]).catch();\n\n if (transaction) {\n return resolve(transactionToReceipt(transaction));\n }\n\n // Poll for the transaction until it's found or the timeout is reached\n let waitedTime = 0;\n const interval = setInterval(async () => {\n waitedTime += 1000;\n transaction = await this.getTransactionStub?.([hash]).catch();\n if (transaction || waitedTime >= timeout) {\n clearInterval(interval);\n resolve(transactionToReceipt(transaction));\n }\n }, 1000);\n });\n }\n}\n\nexport function transactionToReceipt(\n transaction: Transaction | undefined,\n): TransactionReceipt | undefined {\n return transaction\n ? {\n blockHash: transaction.blockHash!,\n blockNumber: transaction.blockNumber!,\n from: transaction.from!,\n to: transaction.to!,\n transactionIndex: transaction.transactionIndex!,\n cumulativeGasUsed: 0n,\n effectiveGasPrice: 0n,\n transactionHash: transaction.hash!,\n gasUsed: 0n,\n logsBloom: '0x',\n status: 'success',\n }\n : undefined;\n}\n"],"mappings":"wCAAAA,ICAAC,IACA,OAAOC,MAAe,sBACtB,OAAoB,QAAAC,MAAY,QAiCzB,IAAMC,EAAN,KAEP,CACE,IACA,QAAU,6CAGA,YAAc,IAAI,IAIlB,cAAgB,IAAI,IAIpB,qBAAuB,IAAI,IAKrC,YAAYC,EAAY,CAAC,EAAU,CACjC,KAAK,IAAMA,CACb,CAMA,MAAM,QACD,CAACC,EAAcC,EAAMC,CAAO,EACe,CAC9C,IAAML,EAAO,KAAK,YAAYG,CAAY,EAC1C,GAAI,CAACH,EACH,MAAM,IAAI,MACR,mBAAmBG,CAAY;AAAA,sBAA4GA,CAAY,WACzJ,EAEF,OAAOH,EAAKI,EAAMC,CAAO,CAC3B,CAMA,MAAM,iBAGD,CAACF,EAAcC,EAAMC,CAAO,EACe,CAC9C,IAAML,EAAO,KAAK,qBAAqBG,CAAY,EACnD,GAAI,CAACH,EACH,MAAM,IAAI,MACR,4BAA4BG,CAAY;AAAA,uBAA6GA,CAAY,WACnK,EAEF,OAAOH,EAAKI,EAAMC,CAAO,CAC3B,CAOA,MAAM,aACD,CAACC,EAAWD,CAAO,EACc,CACpC,IAAML,EAAO,KAAK,cAAcM,EAAWD,CAAO,EAClD,GAAI,CAACL,EACH,MAAM,IAAI,MACR,wBAAwBM,CAAS;AAAA,wBAA8GA,CAAS,WAC1J,EAEF,OAAON,EAAKK,CAAO,CACrB,CAOA,SAAmD,CACjD,aAAAF,EACA,KAAAC,EACA,MAAAG,EACA,QAAAF,CACF,EAKS,CACP,IAAIG,EAAW,KAAK,YAAY,IAAIL,CAAY,EAOhD,GANKK,IACHA,EAAWR,EAAK,EAChB,KAAK,YAAY,IAAIG,EAAcK,CAAQ,GAIzCJ,GAAQC,EAAS,CAGlBG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Stub","abi","functionName","args","options","eventName","value","readStub","simulateWriteStub","stubKey","stableStringify","obj","replacer","_","v","init_esm_shims","stub","init_esm_shims","BOB","ReadWriteContractStub","ReadContractStub","stub","BOB","functionName","args","options","value","writeStub","init_esm_shims","stub","NetworkStub","args","value","id","hash","timeout","resolve","transaction","transactionToReceipt","waitedTime","interval"]} |
+1
-1
| { | ||
| "name": "@delvtech/evm-client", | ||
| "version": "0.4.2", | ||
| "version": "0.5.0", | ||
| "license": "MIT", | ||
@@ -5,0 +5,0 @@ "type": "module", |
| import{a as u,b as p}from"./chunk-VOITYMJ3.js";import{a as l}from"./chunk-FJROFRBN.js";import{c as m}from"./chunk-EXKUPYHD.js";m();m();import E from"lodash.ismatch";var h=100;function f({contract:e,cache:t=u({max:h}),namespace:i}){let r=Object.getPrototypeOf(e),c=Object.create(r);return Object.assign(c,e,{cache:t,async read(a,n,o){return x({cache:t,key:p([i,"read",{address:e.address,functionName:a,args:n,options:o}]),callback:()=>e.read(a,n,o)})},deleteRead(a,n,o){let T=p([i,"read",{address:e.address,functionName:a,args:n,options:o}]);t.delete(T)},deleteReadMatch(...a){let[n,o,T]=a,b=p([i,"read",{address:e.address,functionName:n,args:o,options:T}]);for(let[C]of t.entries)typeof C=="object"&&E(C,b)&&t.delete(C)},async getEvents(a,n){return x({cache:t,key:p([i,"getEvents",{address:e.address,eventName:a,options:n}]),callback:()=>e.getEvents(a,n)})},clearCache(){t.clear()}})}async function x({cache:e,key:t,callback:i}){let r=e.get(t);return r||(r=await i(),e.set(t,r),r)}m();function R({contract:e,cache:t,namespace:i}){if(P(e))return e;let r=Object.getPrototypeOf(e),c=Object.create(r);return Object.assign(c,f({contract:e,cache:t,namespace:i}))}function P(e){return"clearCache"in e}m();m();function A({abi:e,type:t,name:i}){let r=e.find(c=>c.type===t&&(t==="constructor"||c.name===i));if(!r)throw new l({type:t,name:i});return r}function I({abi:e,type:t,name:i,kind:r,values:c}){let d=A({abi:e,type:t,name:i}),a=[];if(r in d&&(a=d[r]),a.length<=1)return c[0];let n=c||[],o={};return a.forEach(({name:T},b)=>{T?o[T]=n[b]:o[b]=n[b]}),o}m();function g({abi:e,type:t,name:i,kind:r,values:c}){let d=A({abi:e,type:t,name:i}),a=[];r in d&&(a=d[r]);let n=c||[],o={};return a.forEach(({name:T},b)=>{T?o[T]=n[b]:o[b]=n[b]}),o}m();function N({abi:e,type:t,name:i,kind:r,value:c}){let d=A({abi:e,type:t,name:i}),a=[];if(r in d&&(a=d[r]),!a.length)return[];let n=c&&typeof c=="object"?c:{},o=[];return a.forEach(({name:T},b)=>{o.push(n[T||b])}),o}export{f as a,R as b,A as c,I as d,g as e,N as f}; | ||
| //# sourceMappingURL=chunk-FCP4QSIX.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 isMatch from 'lodash.ismatch';\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 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 deleteReadMatch(...args) {\n const [functionName, functionArgs, options] = args;\n\n const sourceKey = createSimpleCacheKey([\n namespace,\n 'read',\n {\n address: contract.address,\n functionName,\n args: functionArgs,\n options,\n },\n ]);\n\n for (const [key] of cache.entries) {\n if (\n typeof key === 'object' &&\n isMatch(key, sourceKey as SimpleCacheKey[])\n ) {\n cache.delete(key);\n }\n }\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":"+HAAAA,ICAAC,IACA,OAAOC,MAAa,iBAQpB,IAAMC,EAAqB,IAsBpB,SAASC,EAAiD,CAC/D,SAAAC,EACA,MAAAC,EAAQC,EAAqB,CAAE,IAAKJ,CAAmB,CAAC,EACxD,UAAAK,CACF,EAAoE,CAMlE,IAAMC,EAAoB,OAAO,eAAeJ,CAAQ,EAClDK,EAAc,OAAO,OAAOD,CAAiB,EAwGnD,OAAO,OAAO,OAAOC,EAAaL,EAtGmB,CACnD,MAAAC,EAMA,MAAM,KAAKK,EAAcC,EAAMC,EAAS,CACtC,OAAOC,EAAS,CACd,MAAAR,EACA,IAAKS,EAAqB,CACxBP,EACA,OACA,CACE,QAASH,EAAS,QAClB,aAAAM,EACA,KAAAC,EACA,QAAAC,CACF,CACF,CAAC,EACD,SAAU,IAAMR,EAAS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,EAAW,QAAQ,CAAC,CAAE,KAAAL,CAAK,EAAGQ,IAAM,CAC9BR,EACFO,EAAaP,CAAI,EAAIM,EAAYE,CAAC,EAElCD,EAAaC,CAAC,EAAIF,EAAYE,CAAC,CAEnC,CAAC,EAEMD,CACT,CC1FAE,IAmDO,SAASC,EAMd,CACA,IAAAC,EACA,KAAAC,EACA,KAAAC,EACA,KAAAC,EACA,MAAAC,CACF,EAMyD,CACvD,IAAMC,EAAWC,EAAY,CAAE,IAAAN,EAAK,KAAAC,EAAM,KAAAC,CAAK,CAAC,EAE5CK,EAA6B,CAAC,EAMlC,GALIJ,KAAQE,IACVE,EAAcF,EAAiBF,CAAI,GAIjC,CAACI,EAAW,OACd,MAAO,CAAC,EAGV,IAAMC,EACJJ,GAAS,OAAOA,GAAU,SAAWA,EAAQ,CAAC,EAE1CK,EAAmB,CAAC,EAC1B,OAAAF,EAAW,QAAQ,CAAC,CAAE,KAAAL,CAAK,EAAGQ,IAAM,CAClCD,EAAM,KAAKD,EAAYN,GAAQQ,CAAC,CAAC,CACnC,CAAC,EAEMD,CACT","names":["init_esm_shims","init_esm_shims","isMatch","DEFAULT_CACHE_SIZE","createCachedReadContract","contract","cache","createLruSimpleCache","namespace","contractPrototype","newContract","functionName","args","options","getOrSet","createSimpleCacheKey","key","functionArgs","sourceKey","isMatch","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{a as v,b as O,c as f}from"./chunk-EXKUPYHD.js";var b=v((C,g)=>{"use strict";f();g.exports=function(n,r){r||(r={}),typeof r=="function"&&(r={cmp:r});var u=typeof r.cycles=="boolean"?r.cycles:!1,t=r.cmp&&function(a){return function(e){return function(i,c){var y={key:i,value:e[i]},o={key:c,value:e[c]};return a(y,o)}}}(r.cmp),l=[];return function a(e){if(e&&e.toJSON&&typeof e.toJSON=="function"&&(e=e.toJSON()),e!==void 0){if(typeof e=="number")return isFinite(e)?""+e:"null";if(typeof e!="object")return JSON.stringify(e);var i,c;if(Array.isArray(e)){for(c="[",i=0;i<e.length;i++)i&&(c+=","),c+=a(e[i])||"null";return c+"]"}if(e===null)return"null";if(l.indexOf(e)!==-1){if(u)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var y=l.push(e)-1,o=Object.keys(e).sort(t&&t(e));for(c="",i=0;i<o.length;i++){var m=o[i],p=a(e[m]);p&&(c&&(c+=","),c+=JSON.stringify(m)+":"+p)}return l.splice(y,1),"{"+c+"}"}}(n)}});f();var s=O(b(),1);import{LRUCache as T}from"lru-cache";function V(n){let r=new T(n);function*u(t){for(let[l,a]of t)yield[JSON.parse(l),a]}return{get entries(){return u(r.entries())},get(t){return r.get((0,s.default)(t))},set(t,l){r.set((0,s.default)(t),l)},delete(t){return r.delete((0,s.default)(t))},clear(){r.clear()},find(t){return r.find((l,a)=>t(l,JSON.parse(a)))}}}f();function N(n){switch(typeof n){case"string":case"number":case"boolean":return n;case"object":{if(Array.isArray(n))return n.map(u=>u==null?null:N(u));let r={};for(let u of Object.keys(n).sort()){let t=n[u];t!=null&&(r[u]=N(t))}return r}default:try{return n.toString()}catch{throw new Error(`Unable to process cache key value: ${String(n)}`)}}}export{V as a,N as b}; | ||
| //# sourceMappingURL=chunk-VOITYMJ3.js.map |
| {"version":3,"sources":["../../../node_modules/fast-json-stable-stringify/index.js","../src/cache/factories/createLruSimpleCache.ts","../src/cache/utils/createSimpleCacheKey.ts"],"sourcesContent":["'use strict';\n\nmodule.exports = function (data, opts) {\n if (!opts) opts = {};\n if (typeof opts === 'function') opts = { cmp: opts };\n var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;\n\n var cmp = opts.cmp && (function (f) {\n return function (node) {\n return function (a, b) {\n var aobj = { key: a, value: node[a] };\n var bobj = { key: b, value: node[b] };\n return f(aobj, bobj);\n };\n };\n })(opts.cmp);\n\n var seen = [];\n return (function stringify (node) {\n if (node && node.toJSON && typeof node.toJSON === 'function') {\n node = node.toJSON();\n }\n\n if (node === undefined) return;\n if (typeof node == 'number') return isFinite(node) ? '' + node : 'null';\n if (typeof node !== 'object') return JSON.stringify(node);\n\n var i, out;\n if (Array.isArray(node)) {\n out = '[';\n for (i = 0; i < node.length; i++) {\n if (i) out += ',';\n out += stringify(node[i]) || 'null';\n }\n return out + ']';\n }\n\n if (node === null) return 'null';\n\n if (seen.indexOf(node) !== -1) {\n if (cycles) return JSON.stringify('__cycle__');\n throw new TypeError('Converting circular structure to JSON');\n }\n\n var seenIndex = seen.push(node) - 1;\n var keys = Object.keys(node).sort(cmp && cmp(node));\n out = '';\n for (i = 0; i < keys.length; i++) {\n var key = keys[i];\n var value = stringify(node[key]);\n\n if (!value) continue;\n if (out) out += ',';\n out += JSON.stringify(key) + ':' + value;\n }\n seen.splice(seenIndex, 1);\n return '{' + out + '}';\n })(data);\n};\n","import stringify from 'fast-json-stable-stringify';\nimport { LRUCache } from 'lru-cache';\nimport { SimpleCache, SimpleCacheKey } from 'src/cache/types/SimpleCache';\n\n/**\n * An LRU (Least Recently Used) implementation of the `SimpleCache` interface.\n * This class wraps around the\n * [lru-cache](https://www.npmjs.com/package/lru-cache) library to provide LRU\n * caching capabilities conforming to the `SimpleCache` interface.\n *\n * @template TValue - The type of value to be stored in the cache.\n * @template TKey - The type of key used to access values in the cache.\n * @hidden\n */\nexport function createLruSimpleCache<\n TValue extends NonNullable<unknown> = NonNullable<unknown>,\n TKey extends SimpleCacheKey = SimpleCacheKey,\n>(options: LRUCache.Options<string, TValue, void>): SimpleCache<TValue, TKey> {\n const cache = new LRUCache(options);\n\n function* entriesGenerator(\n originalGenerator: Generator<[TKey, TValue]>,\n ): Generator<[TKey, TValue]> {\n for (const [key, value] of originalGenerator) {\n // Modify the entry here before yielding it\n const modifiedEntry = [JSON.parse(key as string), value];\n yield modifiedEntry as [TKey, TValue];\n }\n }\n\n return {\n get entries() {\n // Keys need to be returned in the same format as they were given to the cache\n return entriesGenerator(cache.entries() as Generator<[TKey, TValue]>);\n },\n\n get(key) {\n return cache.get(stringify(key));\n },\n\n set(key, value) {\n cache.set(stringify(key), value);\n },\n\n delete(key) {\n return cache.delete(stringify(key));\n },\n\n clear() {\n cache.clear();\n },\n\n find(predicate) {\n return cache.find((value, key) => predicate(value, JSON.parse(key)));\n },\n };\n}\n","import { SimpleCacheKey } from 'src/cache/types/SimpleCache';\n\ntype DefinedValue = NonNullable<\n Record<string, any> | string | number | boolean | symbol\n>;\n\n/**\n * Converts a given raw key into a `SimpleCacheKey``.\n *\n * The method ensures that any given raw key, regardless of its structure,\n * is converted into a format suitable for consistent cache key referencing.\n *\n * - For scalar (string, number, boolean), it returns them directly.\n * - For arrays, it recursively processes each element.\n * - For objects, it sorts the keys and then recursively processes each value, ensuring consistent key generation.\n * - For other types, it attempts to convert the raw key to a string.\n *\n * @param rawKey - The raw input to be converted into a cache key.\n * @returns A standardized cache key suitable for consistent referencing within the cache.\n */\nexport function createSimpleCacheKey(rawKey: DefinedValue): SimpleCacheKey {\n switch (typeof rawKey) {\n case 'string':\n case 'number':\n case 'boolean':\n return rawKey;\n\n case 'object': {\n if (Array.isArray(rawKey)) {\n return rawKey.map((value) =>\n // undefined or null values are converted to null to follow the\n // precedent set by JSON.stringify\n value === undefined || value === null\n ? null\n : createSimpleCacheKey(value),\n );\n }\n\n const processedObject: Record<string, SimpleCacheKey> = {};\n\n // sort keys to ensure consistent key generation\n for (const key of Object.keys(rawKey).sort()) {\n const value = rawKey[key];\n\n // ignore properties with undefined or null values\n if (value !== undefined && value !== null) {\n processedObject[key] = createSimpleCacheKey(value);\n }\n }\n\n return processedObject;\n }\n\n default:\n try {\n return rawKey.toString();\n } catch (err) {\n throw new Error(`Unable to process cache key value: ${String(rawKey)}`);\n }\n }\n}\n"],"mappings":"sDAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,cAAAC,IAEAD,EAAO,QAAU,SAAUE,EAAMC,EAAM,CAC9BA,IAAMA,EAAO,CAAC,GACf,OAAOA,GAAS,aAAYA,EAAO,CAAE,IAAKA,CAAK,GACnD,IAAIC,EAAU,OAAOD,EAAK,QAAW,UAAaA,EAAK,OAAS,GAE5DE,EAAMF,EAAK,KAAQ,SAAUG,EAAG,CAChC,OAAO,SAAUC,EAAM,CACnB,OAAO,SAAUC,EAAGC,EAAG,CACnB,IAAIC,EAAO,CAAE,IAAKF,EAAG,MAAOD,EAAKC,CAAC,CAAE,EAChCG,EAAO,CAAE,IAAKF,EAAG,MAAOF,EAAKE,CAAC,CAAE,EACpC,OAAOH,EAAEI,EAAMC,CAAI,CACvB,CACJ,CACJ,EAAGR,EAAK,GAAG,EAEPS,EAAO,CAAC,EACZ,OAAQ,SAASC,EAAWN,EAAM,CAK9B,GAJIA,GAAQA,EAAK,QAAU,OAAOA,EAAK,QAAW,aAC9CA,EAAOA,EAAK,OAAO,GAGnBA,IAAS,OACb,IAAI,OAAOA,GAAQ,SAAU,OAAO,SAASA,CAAI,EAAI,GAAKA,EAAO,OACjE,GAAI,OAAOA,GAAS,SAAU,OAAO,KAAK,UAAUA,CAAI,EAExD,IAAI,EAAGO,EACP,GAAI,MAAM,QAAQP,CAAI,EAAG,CAErB,IADAO,EAAM,IACD,EAAI,EAAG,EAAIP,EAAK,OAAQ,IACrB,IAAGO,GAAO,KACdA,GAAOD,EAAUN,EAAK,CAAC,CAAC,GAAK,OAEjC,OAAOO,EAAM,GACjB,CAEA,GAAIP,IAAS,KAAM,MAAO,OAE1B,GAAIK,EAAK,QAAQL,CAAI,IAAM,GAAI,CAC3B,GAAIH,EAAQ,OAAO,KAAK,UAA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OAAQ,OAAOA,EAAQ,CACrB,IAAK,SACL,IAAK,SACL,IAAK,UACH,OAAOA,EAET,IAAK,SAAU,CACb,GAAI,MAAM,QAAQA,CAAM,EACtB,OAAOA,EAAO,IAAKC,GAGMA,GAAU,KAC7B,KACAF,EAAqBE,CAAK,CAChC,EAGF,IAAMC,EAAkD,CAAC,EAGzD,QAAWC,KAAO,OAAO,KAAKH,CAAM,EAAE,KAAK,EAAG,CAC5C,IAAMC,EAAQD,EAAOG,CAAG,EAGGF,GAAU,OACnCC,EAAgBC,CAAG,EAAIJ,EAAqBE,CAAK,EAErD,CAEA,OAAOC,CACT,CAEA,QACE,GAAI,CACF,OAAOF,EAAO,SAAS,CACzB,MAAc,CACZ,MAAM,IAAI,MAAM,sCAAsC,OAAOA,CAAM,CAAC,EAAE,CACxE,CACJ,CACF","names":["require_fast_json_stable_stringify","__commonJSMin","exports","module","init_esm_shims","data","opts","cycles","cmp","f","node","a","b","aobj","bobj","seen","stringify","out","seenIndex","keys","key","value","init_esm_shims","import_fast_json_stable_stringify","LRUCache","createLruSimpleCache","options","cache","entriesGenerator","originalGenerator","key","value","stringify","predicate","init_esm_shims","createSimpleCacheKey","rawKey","value","processedObject","key"]} |
| 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 }; |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
116534
1.44%1011
3.91%