diff --git a/src/account/default.ts b/src/account/default.ts index b46723e5b..8dc43f1b3 100644 --- a/src/account/default.ts +++ b/src/account/default.ts @@ -6,6 +6,7 @@ import { Signer, SignerInterface } from '../signer'; import { Abi, AllowArray, + CairoVersion, Call, DeclareAndDeployContractPayload, DeclareContractPayload, @@ -59,10 +60,13 @@ export class Account extends Provider implements AccountInterface { public address: string; + public cairoVersion: CairoVersion; + constructor( providerOrOptions: ProviderOptions | ProviderInterface, address: string, - pkOrSigner: Uint8Array | string | SignerInterface + pkOrSigner: Uint8Array | string | SignerInterface, + cairoVersion: CairoVersion = '0' ) { super(providerOrOptions); this.address = address.toLowerCase(); @@ -70,6 +74,8 @@ export class Account extends Provider implements AccountInterface { typeof pkOrSigner === 'string' || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner; + + this.cairoVersion = cairoVersion; } public async getNonce(blockIdentifier?: BlockIdentifier): Promise { @@ -85,7 +91,7 @@ export class Account extends Provider implements AccountInterface { public async estimateInvokeFee( calls: AllowArray, - { nonce: providedNonce, blockIdentifier, skipValidate, cairoVersion }: EstimateFeeDetails = {} + { nonce: providedNonce, blockIdentifier, skipValidate }: EstimateFeeDetails = {} ): Promise { const transactions = Array.isArray(calls) ? calls : [calls]; const nonce = toBigInt(providedNonce ?? (await this.getNonce())); @@ -98,7 +104,7 @@ export class Account extends Provider implements AccountInterface { maxFee: ZERO, version, chainId, - cairoVersion: cairoVersion ?? '0', + cairoVersion: this.cairoVersion, }; const invocation = await this.buildInvocation(transactions, signerDetails); @@ -119,7 +125,7 @@ export class Account extends Provider implements AccountInterface { public async estimateDeclareFee( { contract, classHash: providedClassHash, casm, compiledClassHash }: DeclareContractPayload, - { blockIdentifier, nonce: providedNonce, skipValidate, cairoVersion }: EstimateFeeDetails = {} + { blockIdentifier, nonce: providedNonce, skipValidate }: EstimateFeeDetails = {} ): Promise { const nonce = toBigInt(providedNonce ?? (await this.getNonce())); const version = !isSierra(contract) ? toBigInt(feeTransactionVersion) : transactionVersion_2; @@ -133,7 +139,7 @@ export class Account extends Provider implements AccountInterface { version, walletAddress: this.address, maxFee: ZERO, - cairoVersion: cairoVersion ?? '0', + cairoVersion: this.cairoVersion, } ); @@ -158,7 +164,7 @@ export class Account extends Provider implements AccountInterface { constructorCalldata = [], contractAddress: providedContractAddress, }: DeployAccountContractPayload, - { blockIdentifier, skipValidate, cairoVersion }: EstimateFeeDetails = {} + { blockIdentifier, skipValidate }: EstimateFeeDetails = {} ): Promise { const version = toBigInt(feeTransactionVersion); const nonce = ZERO; // DEPLOY_ACCOUNT transaction will have a nonce zero as it is the first transaction in the account @@ -172,7 +178,7 @@ export class Account extends Provider implements AccountInterface { version, walletAddress: this.address, maxFee: ZERO, - cairoVersion: cairoVersion ?? '0', + cairoVersion: this.cairoVersion, } ); @@ -200,7 +206,7 @@ export class Account extends Provider implements AccountInterface { public async estimateFeeBulk( transactions: TransactionBulk, - { nonce: providedNonce, blockIdentifier, cairoVersion }: EstimateFeeDetails = {} + { nonce: providedNonce, blockIdentifier }: EstimateFeeDetails = {} ): Promise { const nonce = toBigInt(providedNonce ?? (await this.getNonce())); const version = toBigInt(feeTransactionVersion); @@ -214,7 +220,7 @@ export class Account extends Provider implements AccountInterface { maxFee: ZERO, version, chainId, - cairoVersion: cairoVersion ?? '0', + cairoVersion: this.cairoVersion, }; const txPayload = transaction.payload; @@ -280,7 +286,7 @@ export class Account extends Provider implements AccountInterface { call: Array, signerDetails: InvocationsSignerDetails ): Promise { - const calldata = getExecuteCalldata(call, signerDetails.cairoVersion); + const calldata = getExecuteCalldata(call, this.cairoVersion); const signature = await this.signer.signTransaction(call, signerDetails); return { @@ -306,20 +312,18 @@ export class Account extends Provider implements AccountInterface { const version = toBigInt(transactionVersion); const chainId = await this.getChainId(); - const cairoVersion = transactionsDetail.cairoVersion ?? '0'; - const signerDetails: InvocationsSignerDetails = { walletAddress: this.address, nonce, maxFee, version, chainId, - cairoVersion, + cairoVersion: this.cairoVersion, }; const signature = await this.signer.signTransaction(transactions, signerDetails, abis); - const calldata = getExecuteCalldata(transactions, cairoVersion); + const calldata = getExecuteCalldata(transactions, this.cairoVersion); return this.invokeFunction( { contractAddress: this.address, calldata, signature }, @@ -354,7 +358,7 @@ export class Account extends Provider implements AccountInterface { const declareContractTransaction = await this.buildDeclarePayload(declareContractPayload, { ...details, walletAddress: this.address, - cairoVersion: transactionsDetail.cairoVersion ?? '0', // This can be removed as declare doesn't depend on cairo version. Kept here because of the type mismatch + cairoVersion: this.cairoVersion, }); return this.declareContract(declareContractTransaction, details); @@ -629,7 +633,7 @@ export class Account extends Provider implements AccountInterface { public async simulateTransaction( calls: AllowArray, - { nonce: providedNonce, blockIdentifier, skipValidate, cairoVersion }: EstimateFeeDetails = {} + { nonce: providedNonce, blockIdentifier, skipValidate }: EstimateFeeDetails = {} ): Promise { const transactions = Array.isArray(calls) ? calls : [calls]; const nonce = toBigInt(providedNonce ?? (await this.getNonce())); @@ -642,7 +646,7 @@ export class Account extends Provider implements AccountInterface { maxFee: ZERO, version, chainId, - cairoVersion: cairoVersion ?? '0', + cairoVersion: this.cairoVersion, }; const invocation = await this.buildInvocation(transactions, signerDetails); diff --git a/src/account/interface.ts b/src/account/interface.ts index a6a390c17..78e9dbfd0 100644 --- a/src/account/interface.ts +++ b/src/account/interface.ts @@ -4,6 +4,7 @@ import { SignerInterface } from '../signer'; import { Abi, AllowArray, + CairoVersion, Call, DeclareAndDeployContractPayload, DeclareContractPayload, @@ -33,6 +34,8 @@ export abstract class AccountInterface extends ProviderInterface { public abstract signer: SignerInterface; + public abstract cairoVersion: CairoVersion; + /** * Estimate Fee for executing an INVOKE transaction on starknet * diff --git a/src/types/account.ts b/src/types/account.ts index 6997d6676..62b345ba6 100644 --- a/src/types/account.ts +++ b/src/types/account.ts @@ -1,6 +1,5 @@ import { BlockIdentifier } from '../provider/utils'; import { BigNumberish } from '../utils/num'; -import { CairoVersion } from './lib'; import { DeclareTransactionReceiptResponse, EstimateFeeResponse, @@ -17,7 +16,6 @@ export interface EstimateFeeDetails { nonce?: BigNumberish; blockIdentifier?: BlockIdentifier; skipValidate?: boolean; - cairoVersion?: CairoVersion; } export interface DeployContractResponse { diff --git a/src/types/lib/index.ts b/src/types/lib/index.ts index 685ccddbc..94827879c 100644 --- a/src/types/lib/index.ts +++ b/src/types/lib/index.ts @@ -84,7 +84,6 @@ export type InvocationsDetails = { nonce?: BigNumberish; maxFee?: BigNumberish; version?: BigNumberish; - cairoVersion?: CairoVersion; }; /** diff --git a/src/types/signer.ts b/src/types/signer.ts index 16f9504cf..7da2a3b6f 100644 --- a/src/types/signer.ts +++ b/src/types/signer.ts @@ -1,10 +1,11 @@ import { StarknetChainId } from '../constants'; import { BigNumberish } from '../utils/num'; -import { DeployAccountContractPayload, InvocationsDetails } from './lib'; +import { CairoVersion, DeployAccountContractPayload, InvocationsDetails } from './lib'; export interface InvocationsSignerDetails extends Required { walletAddress: string; chainId: StarknetChainId; + cairoVersion: CairoVersion; } export interface DeclareSignerDetails { @@ -18,7 +19,7 @@ export interface DeclareSignerDetails { } export type DeployAccountSignerDetails = Required & - Omit, 'cairoVersion'> & { + Required & { contractAddress: BigNumberish; chainId: StarknetChainId; };