@@ -26,6 +26,7 @@ import {
2626 KeyPair ,
2727 MultiDeployContractResponse ,
2828 Signature ,
29+ TransactionBulk ,
2930 UniversalDeployerContractPayload ,
3031} from '../types' ;
3132import { parseUDCEvent } from '../utils/events' ;
@@ -150,59 +151,6 @@ export class Account extends Provider implements AccountInterface {
150151 } ;
151152 }
152153
153- public async estimateInvokeFeeBulk (
154- calls : Array < AllowArray < Call > > ,
155- { nonce : providedNonce , blockIdentifier } : EstimateFeeDetails = { }
156- ) : Promise < EstimateFee > {
157- let nonce = toBN ( providedNonce ?? ( await this . getNonce ( ) ) ) ;
158- const version = toBN ( feeTransactionVersion ) ;
159- const chainId = await this . getChainId ( ) ;
160-
161- const invocations : any = await Promise . all (
162- [ ] . concat ( calls as [ ] ) . map ( async ( call ) => {
163- const transactions = Array . isArray ( call ) ? call : [ call ] ;
164- const signerDetails : InvocationsSignerDetails = {
165- walletAddress : this . address ,
166- nonce,
167- maxFee : ZERO ,
168- version,
169- chainId,
170- } ;
171- const invocation = await this . buildInvocation ( transactions , signerDetails ) ;
172- const res = {
173- ...invocation ,
174- version,
175- nonce,
176- blockIdentifier,
177- } ;
178- nonce = toBN ( Number ( nonce ) + 1 ) ;
179- return res ;
180- } )
181- ) ;
182-
183- const response = await super . getInvokeEstimateFeeBulk ( invocations , blockIdentifier ) ;
184- const suggestedMaxFee = estimatedFeeToMaxFee ( response . overall_fee ) ;
185-
186- return {
187- ...response ,
188- suggestedMaxFee,
189- } ;
190- }
191-
192- private async buildInvocation (
193- call : Array < Call > ,
194- signerDetails : InvocationsSignerDetails
195- ) : Promise < Invocation > {
196- const calldata = fromCallsToExecuteCalldata ( call ) ;
197- const signature = await this . signer . signTransaction ( call , signerDetails ) ;
198-
199- return {
200- contractAddress : this . address ,
201- calldata,
202- signature,
203- } ;
204- }
205-
206154 public async estimateDeclareFee (
207155 { classHash, contract } : DeclareContractPayload ,
208156 { blockIdentifier, nonce : providedNonce } : EstimateFeeDetails = { }
@@ -303,6 +251,160 @@ export class Account extends Provider implements AccountInterface {
303251 return this . estimateInvokeFee ( calls , transactionsDetail ) ;
304252 }
305253
254+ public async estimateFeeBulk (
255+ calls : Array < TransactionBulk > ,
256+ { nonce : providedNonce , blockIdentifier } : EstimateFeeDetails = { }
257+ ) : Promise < EstimateFee > {
258+ const nonce = toBN ( providedNonce ?? ( await this . getNonce ( ) ) ) ;
259+ const version = toBN ( feeTransactionVersion ) ;
260+ const chainId = await this . getChainId ( ) ;
261+
262+ const invocations : any = await Promise . all (
263+ [ ] . concat ( calls as [ ] ) . map ( async ( transaction : any , index : number ) => {
264+ const signerDetails : InvocationsSignerDetails = {
265+ walletAddress : this . address ,
266+ nonce : toBN ( Number ( nonce ) + index ) ,
267+ maxFee : ZERO ,
268+ version,
269+ chainId,
270+ } ;
271+
272+ let res ;
273+ if (
274+ typeof transaction === 'object' &&
275+ transaction . type === 'INVOKE_FUNCTION' &&
276+ 'entrypoint' in transaction &&
277+ 'contractAddress' in transaction &&
278+ 'calldata' in transaction
279+ ) {
280+ const transactions : any = Array . isArray ( transaction ) ? transaction : [ transaction ] ;
281+ const invocation = await this . buildInvocation ( transactions , signerDetails ) ;
282+ res = {
283+ type : 'INVOKE_FUNCTION' ,
284+ ...invocation ,
285+ version,
286+ nonce : toBN ( Number ( nonce ) + index ) ,
287+ blockIdentifier,
288+ } ;
289+ } else if (
290+ typeof transaction === 'object' &&
291+ transaction . type === 'DECLARE' &&
292+ 'contract' in transaction &&
293+ 'classHash' in transaction
294+ ) {
295+ const contractDefinition = parseContract ( transaction . contract ) ;
296+ const signature = await this . signer . signDeclareTransaction ( {
297+ classHash : transaction . classHash ,
298+ senderAddress : this . address ,
299+ chainId,
300+ maxFee : ZERO ,
301+ version,
302+ nonce : toBN ( Number ( nonce ) + index ) ,
303+ } ) ;
304+ res = {
305+ type : 'DECLARE' ,
306+ senderAddress : this . address ,
307+ signature,
308+ contractDefinition,
309+ version,
310+ nonce : toBN ( Number ( nonce ) + index ) ,
311+ blockIdentifier,
312+ } ;
313+ } else if (
314+ typeof transaction === 'object' &&
315+ transaction . type === 'DEPLOY_ACCOUNT' &&
316+ 'classHash' in transaction
317+ ) {
318+ const contractAddress =
319+ transaction . contractAddress ??
320+ calculateContractAddressFromHash (
321+ transaction . addressSalt || 0 ,
322+ transaction . classHash ,
323+ transaction . constructorCalldata || [ ] ,
324+ 0
325+ ) ;
326+
327+ const signature = await this . signer . signDeployAccountTransaction ( {
328+ classHash : transaction . classHash ,
329+ contractAddress,
330+ chainId,
331+ maxFee : ZERO ,
332+ version,
333+ nonce : toBN ( Number ( nonce ) + index ) ,
334+ addressSalt : transaction . addressSalt || 0 ,
335+ constructorCalldata : transaction . constructorCalldata || [ ] ,
336+ } ) ;
337+
338+ res = {
339+ type : 'DEPLOY_ACCOUNT' ,
340+ classHash : transaction . classHash ,
341+ addressSalt : transaction . addressSalt || 0 ,
342+ constructorCalldata : transaction . constructorCalldata || [ ] ,
343+ signature,
344+ version,
345+ nonce,
346+ blockIdentifier,
347+ } ;
348+ } else if (
349+ typeof transaction === 'object' &&
350+ transaction . type === 'DEPLOY' &&
351+ 'classHash' in transaction
352+ ) {
353+ const {
354+ classHash,
355+ salt = '0' ,
356+ unique = true ,
357+ constructorCalldata = [ ] ,
358+ } = transaction as UniversalDeployerContractPayload ;
359+ const compiledConstructorCallData = compileCalldata ( constructorCalldata ) ;
360+ const call = {
361+ contractAddress : UDC . ADDRESS ,
362+ entrypoint : UDC . ENTRYPOINT ,
363+ calldata : [
364+ classHash ,
365+ salt ,
366+ toCairoBool ( unique ) ,
367+ compiledConstructorCallData . length ,
368+ ...compiledConstructorCallData ,
369+ ] ,
370+ } ;
371+ const transactions : any = Array . isArray ( call ) ? call : [ call ] ;
372+ const invocation = await this . buildInvocation ( transactions , signerDetails ) ;
373+ res = {
374+ type : 'INVOKE_FUNCTION' ,
375+ ...invocation ,
376+ version,
377+ nonce : toBN ( Number ( nonce ) + index ) ,
378+ blockIdentifier,
379+ } ;
380+ }
381+ return res ;
382+ } )
383+ ) ;
384+
385+ const response = await super . getEstimateFeeBulk ( invocations , blockIdentifier ) ;
386+ const suggestedMaxFee = estimatedFeeToMaxFee ( response . overall_fee ) ;
387+
388+ return {
389+ ...response ,
390+ suggestedMaxFee,
391+ } ;
392+ }
393+
394+ private async buildInvocation (
395+ call : Array < Call > ,
396+ signerDetails : InvocationsSignerDetails
397+ ) : Promise < Invocation > {
398+ const calldata = fromCallsToExecuteCalldata ( call ) ;
399+ const signature = await this . signer . signTransaction ( call , signerDetails ) ;
400+
401+ return {
402+ contractAddress : this . address ,
403+ calldata,
404+ signature,
405+ } ;
406+ }
407+
306408 public async execute (
307409 calls : AllowArray < Call > ,
308410 abis : Abi [ ] | undefined = undefined ,
0 commit comments