diff --git a/src/actions/index.ts b/src/actions/index.ts index 1708890e52..16309b811e 100644 --- a/src/actions/index.ts +++ b/src/actions/index.ts @@ -182,6 +182,10 @@ export { type ReadContractReturnType, readContract, } from './public/readContract.js' +export { + type GetAddressesReturnType, + getAddresses, +} from './wallet/getAddresses.js' export { type GetPermissionsReturnType, getPermissions, diff --git a/src/actions/public/simulateContract.test-d.ts b/src/actions/public/simulateContract.test-d.ts index e6d9b042a8..43d0c4e175 100644 --- a/src/actions/public/simulateContract.test-d.ts +++ b/src/actions/public/simulateContract.test-d.ts @@ -1,5 +1,5 @@ import { parseAbi } from 'abitype' -import { assertType, test } from 'vitest' +import { assertType, expectTypeOf, test } from 'vitest' import { wagmiContractConfig } from '../../_test/abis.js' import { publicClient } from '../../_test/utils.js' @@ -123,6 +123,9 @@ test('overloads', async () => { functionName: 'foo', }) assertType(res1.result) + expectTypeOf(res1.request.abi).toEqualTypeOf( + parseAbi(['function foo() returns (int8)']), + ) const res2 = await simulateContract(publicClient, { address: '0x', @@ -131,6 +134,9 @@ test('overloads', async () => { args: ['0x'], }) assertType(res2.result) + expectTypeOf(res2.request.abi).toEqualTypeOf( + parseAbi(['function foo(address) returns (string)']), + ) const res3 = await simulateContract(publicClient, { address: '0x', @@ -142,4 +148,9 @@ test('overloads', async () => { foo: `0x${string}` bar: `0x${string}` }>(res3.result) + expectTypeOf(res3.request.abi).toEqualTypeOf( + parseAbi([ + 'function foo(address, address) returns ((address foo, address bar))', + ]), + ) }) diff --git a/src/actions/public/simulateContract.ts b/src/actions/public/simulateContract.ts index 701fbb6951..5806c3ebae 100644 --- a/src/actions/public/simulateContract.ts +++ b/src/actions/public/simulateContract.ts @@ -10,10 +10,11 @@ import type { ContractFunctionName, ContractFunctionParameters, ContractFunctionReturnType, + ExtractAbiFunctionForArgs, GetValue, } from '../../types/contract.js' import type { Hex } from '../../types/misc.js' -import type { UnionOmit } from '../../types/utils.js' +import type { Prettify, UnionEvaluate, UnionOmit } from '../../types/utils.js' import { decodeFunctionResult } from '../../utils/abi/decodeFunctionResult.js' import { encodeFunctionData } from '../../utils/abi/encodeFunctionData.js' import { getContractError } from '../../utils/errors/getContractError.js' @@ -69,32 +70,45 @@ export type SimulateContractReturnType< > = ContractFunctionArgs, chain extends Chain | undefined = Chain | undefined, chainOverride extends Chain | undefined = Chain | undefined, + /// + minimizedAbi extends Abi = readonly [ + ExtractAbiFunctionForArgs< + abi extends Abi ? abi : Abi, + 'nonpayable' | 'payable', + functionName, + args + >, + ], > = { result: ContractFunctionReturnType< - abi, + minimizedAbi, 'nonpayable' | 'payable', functionName, args > - request: UnionOmit< - WriteContractParameters< - abi, - functionName, - args, - chain, - undefined, - chainOverride - >, - 'chain' | 'functionName' - > & { - chain: chainOverride - functionName: functionName - } & ContractFunctionParameters< - abi, - 'nonpayable' | 'payable', - functionName, - args - > + request: Prettify< + UnionEvaluate< + UnionOmit< + WriteContractParameters< + minimizedAbi, + functionName, + args, + chain, + undefined, + chainOverride + >, + 'abi' | 'args' | 'chain' | 'functionName' + > + > & + ContractFunctionParameters< + minimizedAbi, + 'nonpayable' | 'payable', + functionName, + args + > & { + chain: chainOverride + } + > } /** @@ -170,10 +184,14 @@ export async function simulateContract< functionName, data: data || '0x', }) + const minimizedAbi = abi.filter( + (abiItem) => + 'name' in abiItem && abiItem.name === parameters.functionName, + ) return { result, request: { - abi, + abi: minimizedAbi, address, args, dataSuffix, diff --git a/src/index.ts b/src/index.ts index 182767d394..1c463461c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,8 +6,6 @@ export { type AbiParameterKind, type AbiParameterToPrimitiveType, type Address, - type ExtractAbiFunction, - type ExtractAbiFunctionNames, type Narrow, type ParseAbi, type ParseAbiItem, @@ -561,6 +559,7 @@ export { SizeExceedsPaddingSizeError } from './errors/data.js' export { UrlRequiredError } from './errors/transport.js' export type { AbiItem, + ExtractAbiFunctionForArgs, ContractErrorArgs, ContractErrorName, ContractEventArgs,