diff --git a/src/contract/default.ts b/src/contract/default.ts index 221d2c448..f9102ba84 100644 --- a/src/contract/default.ts +++ b/src/contract/default.ts @@ -5,6 +5,7 @@ import { ProviderInterface, defaultProvider } from '../provider'; import { Abi, AbiEvents, + AbiStruct, ArgsOrCalldata, ArgsOrCalldataWithOptions, AsyncContractFunction, @@ -21,7 +22,6 @@ import { ParsedEvents, RawArgs, Result, - AbiStruct, ValidateType, } from '../types'; import assert from '../utils/assert'; @@ -29,8 +29,8 @@ import { CallData, cairo } from '../utils/calldata'; import { createAbiParser } from '../utils/calldata/parser'; import { getAbiEvents, parseEvents as parseRawEvents } from '../utils/events/index'; import { cleanHex } from '../utils/num'; -import { ContractInterface } from './interface'; import type { GetTransactionReceiptResponse } from '../utils/transactionReceipt'; +import { ContractInterface } from './interface'; export type TypedContractV2 = AbiWanTypedContract & Contract; @@ -70,7 +70,7 @@ function buildCall(contract: Contract, functionAbi: FunctionAbi): AsyncContractF * Adds invoke methods to the contract */ function buildInvoke(contract: Contract, functionAbi: FunctionAbi): AsyncContractFunction { - return async function (...args: Array): Promise { + return async function (...args: ArgsOrCalldataWithOptions): Promise { const params = splitArgsAndOptions(args); return contract.invoke(functionAbi.name, params.args, { parseRequest: true, diff --git a/src/types/contract.ts b/src/types/contract.ts index 01dacf9b0..8624df75d 100644 --- a/src/types/contract.ts +++ b/src/types/contract.ts @@ -21,8 +21,37 @@ export type Result = | boolean | CairoEnum; -export type ArgsOrCalldata = RawArgsArray | [Calldata] | Calldata; -export type ArgsOrCalldataWithOptions = ArgsOrCalldata & ContractOptions; +// export type ArgsOrCalldata = RawArgsArray | [Calldata] | Calldata; +// export type ArgsOrCalldataWithOptions = ArgsOrCalldata & ContractOptions; + +// RawParamsOrCalldata as args +export type ArgsOrCalldata = + // params like (va,vb,vc,vd...) as args is [va,vb,vc,vd...] + // params like (x) where x = {a:va,b:vb,c:vc...} as args is [x] + // params like (x) where x = [va,vb,vc...] as args is [[x]] + | RawArgsArray // recursive definition cover all this cases + // [calldata] is [['0x','0x'...]] + | [Calldata] + // calldata is ['0x','0x'...] + | Calldata; + +// RawParamsOrCalldata where each can have an option +export type ArgsOrCalldataWithOptions = + // params like (va,vb,vc,vd..., option) as args is [va,vb,vc,vd..., option] + // params like (x, option) where x = {a:va,b:vb,c:vc...} as args is [x, option] + // params like (x, option) where x = [va,vb,vc...] as args is [[x], option] + // recursive definition cover all this cases + | [...RawArgsArray] + | [...RawArgsArray, ContractOptions] + // used when called compile that return array of calldata + // (calldata, options) as args is [['0x','0x'...], options] + | [Calldata] + | [Calldata, ContractOptions] + // used when separate params compilations + // (c,a,l,l,d,a,t,a, options) as args is ['0x','0x'..., options] + | [...Calldata] + | [...Calldata, ContractOptions]; + export type ContractOptions = { blockIdentifier?: BlockIdentifier; parseRequest?: boolean;