diff --git a/__tests__/account.test.ts b/__tests__/account.test.ts index d9b2d2819..95a06255a 100644 --- a/__tests__/account.test.ts +++ b/__tests__/account.test.ts @@ -7,7 +7,6 @@ import { toBN } from '../src/utils/number'; import { encodeShortString } from '../src/utils/shortString'; import { randomAddress } from '../src/utils/stark'; import { - IS_DEVNET, compiledErc20, compiledTestDapp, erc20ClassHash, @@ -189,7 +188,6 @@ describe('deploy and test Wallet', () => { ], salt, unique: true, // Using true here so as not to clash with normal erc20 deploy in account and provider test - isDevnet: IS_DEVNET, }); await provider.waitForTransaction(deployment.transaction_hash); diff --git a/src/account/default.ts b/src/account/default.ts index ee53bb838..7fe5996dd 100644 --- a/src/account/default.ts +++ b/src/account/default.ts @@ -166,6 +166,38 @@ export class Account extends Provider implements AccountInterface { }; } + public async estimateDeployFee( + { + classHash, + salt, + unique = true, + constructorCalldata = [], + additionalCalls = [], + }: UniversalDeployerContractPayload, + transactionsDetail?: InvocationsDetails | undefined + ): Promise { + const compiledConstructorCallData = compileCalldata(constructorCalldata); + + const callsArray = Array.isArray(additionalCalls) ? additionalCalls : [additionalCalls]; + return this.estimateInvokeFee( + [ + { + contractAddress: UDC.ADDRESS, + entrypoint: UDC.ENTRYPOINT, + calldata: [ + classHash, + salt, + toCairoBool(unique), + compiledConstructorCallData.length, + ...compiledConstructorCallData, + ], + }, + ...callsArray, + ], + transactionsDetail + ); + } + public async execute( calls: AllowArray, abis: Abi[] | undefined = undefined, @@ -243,9 +275,8 @@ export class Account extends Provider implements AccountInterface { salt, unique = true, constructorCalldata = [], - isDevnet = false, + additionalCalls = [], }: UniversalDeployerContractPayload, - additionalCalls: AllowArray = [], // support multicall transactionsDetail: InvocationsDetails = {} ): Promise { const compiledConstructorCallData = compileCalldata(constructorCalldata); @@ -255,7 +286,7 @@ export class Account extends Provider implements AccountInterface { return this.execute( [ { - contractAddress: isDevnet ? UDC.ADDRESS_DEVNET : UDC.ADDRESS, + contractAddress: UDC.ADDRESS, entrypoint: UDC.ENTRYPOINT, calldata: [ classHash, @@ -350,22 +381,26 @@ export class Account extends Provider implements AccountInterface { } public async getSuggestedMaxFee( - estimateFeeAction: EstimateFeeAction, + { type, payload }: EstimateFeeAction, details: EstimateFeeDetails ) { let feeEstimate: EstimateFee; - switch (estimateFeeAction.type) { + switch (type) { case 'INVOKE': - feeEstimate = await this.estimateInvokeFee(estimateFeeAction.payload, details); + feeEstimate = await this.estimateInvokeFee(payload, details); break; case 'DECLARE': - feeEstimate = await this.estimateDeclareFee(estimateFeeAction.payload, details); + feeEstimate = await this.estimateDeclareFee(payload, details); break; case 'DEPLOY_ACCOUNT': - feeEstimate = await this.estimateAccountDeployFee(estimateFeeAction.payload, details); + feeEstimate = await this.estimateAccountDeployFee(payload, details); + break; + + case 'DEPLOY': + feeEstimate = await this.estimateDeployFee(payload, details); break; default: diff --git a/src/account/interface.ts b/src/account/interface.ts index fb92900ca..103446cde 100644 --- a/src/account/interface.ts +++ b/src/account/interface.ts @@ -86,6 +86,27 @@ export abstract class AccountInterface extends ProviderInterface { estimateFeeDetails?: EstimateFeeDetails ): Promise; + /** + * Estimate Fee for executing a UDC DEPLOY transaction on starknet + * This is different from the normal DEPLOY transaction as it goes through the Universal Deployer Contract (UDC) + + * @param deployContractPayload containing + * - classHash: computed class hash of compiled contract + * - salt: address salt + * - unique: bool if true ensure unique salt + * - calldata: constructor calldata + * - additionalCalls - optional additional calls array to support multicall + * + * @param transactionsDetail Invocation Details containing: + * - optional nonce + * - optional version + * - optional maxFee + */ + public abstract estimateDeployFee( + deployContractPayload: UniversalDeployerContractPayload, + transactionsDetail?: InvocationsDetails + ): Promise; + /** * Invoke execute function in account contract * @@ -123,12 +144,15 @@ export abstract class AccountInterface extends ProviderInterface { ): Promise; /** + * Deploys a given compiled contract (json) to starknet using Universal Deployer Contract (UDC) + * This is different from the normal DEPLOY transaction as it goes through the Universal Deployer Contract (UDC) + * * @param deployContractPayload containing * - classHash: computed class hash of compiled contract * - salt: address salt * - unique: bool if true ensure unique salt * - calldata: constructor calldata - * @param additionalCalls - optional additional calls array to support multicall + * - additionalCalls - optional additional calls array to support multicall * @param transactionsDetail Invocation Details containing: * - optional nonce * - optional version @@ -136,7 +160,6 @@ export abstract class AccountInterface extends ProviderInterface { */ public abstract deploy( deployContractPayload: UniversalDeployerContractPayload, - additionalCalls?: AllowArray, transactionsDetail?: InvocationsDetails ): Promise; diff --git a/src/constants.ts b/src/constants.ts index 1cdb2728a..95cc85f58 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -24,7 +24,6 @@ export enum TransactionHashPrefix { export const UDC = { ADDRESS: '0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf', ENTRYPOINT: 'deployContract', - ADDRESS_DEVNET: '0x25fcb74260022bd8ed7e8d542408941826b53345e478b8303d6f31744838a36', }; /** diff --git a/src/types/lib.ts b/src/types/lib.ts index 58f48073b..3d8d4e236 100644 --- a/src/types/lib.ts +++ b/src/types/lib.ts @@ -24,7 +24,7 @@ export type UniversalDeployerContractPayload = { salt: string; unique: boolean; constructorCalldata?: RawArgs; - isDevnet?: boolean; + additionalCalls?: AllowArray; // support multicall }; export type DeployContractPayload = { diff --git a/src/types/provider.ts b/src/types/provider.ts index a87bf2f8f..9da3ecf84 100644 --- a/src/types/provider.ts +++ b/src/types/provider.ts @@ -12,6 +12,7 @@ import { RawCalldata, Signature, Status, + UniversalDeployerContractPayload, } from './lib'; export interface GetBlockResponse { @@ -131,4 +132,8 @@ export type EstimateFeeAction = | { type: 'DEPLOY_ACCOUNT'; payload: DeployAccountContractPayload; + } + | { + type: 'DEPLOY'; + payload: UniversalDeployerContractPayload; };