starknet 4.18.0 → 4.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # [4.19.0](https://github.com/0xs34n/starknet.js/compare/v4.18.0...v4.19.0) (2023-01-09)
2
+
3
+ ### Bug Fixes
4
+
5
+ - merge develop into feat/add_estimate_fee_bulk ([88e76af](https://github.com/0xs34n/starknet.js/commit/88e76af68dd711b3f277c0a6d4f1935710aba4d7))
6
+ - update getEstimateFeeBulk function ([4b22c82](https://github.com/0xs34n/starknet.js/commit/4b22c8212f4586b37dc7c8ddfad77955e44b1b12))
7
+ - update types & add separate responseParser for estimateFeeBulk ([52110b2](https://github.com/0xs34n/starknet.js/commit/52110b289e3dfbbe449cf195709b2714f295a70d))
8
+
9
+ ### Features
10
+
11
+ - add function estimateInvokeFeeBulk ([e716a18](https://github.com/0xs34n/starknet.js/commit/e716a1882f3ac37d17eae72a51cd3c4fc4649bcb))
12
+ - update estimateFeeBulk ([5ee94f7](https://github.com/0xs34n/starknet.js/commit/5ee94f78af681690905e1ead1de711e3a43c0774))
13
+ - update estimateFeeBulk function & doc ([ce20139](https://github.com/0xs34n/starknet.js/commit/ce201394142a19c4810a1e44cb3f601b815a11fe))
14
+ - update sequencer api ([a12f99e](https://github.com/0xs34n/starknet.js/commit/a12f99ea6e93fb5d44d4d07f7fa8cc2d997db91a))
15
+
1
16
  # [4.18.0](https://github.com/0xs34n/starknet.js/compare/v4.17.1...v4.18.0) (2022-12-23)
2
17
 
3
18
  ### Bug Fixes
package/dist/index.d.ts CHANGED
@@ -741,6 +741,32 @@ declare type InvocationsDetails = {
741
741
  declare type InvocationsDetailsWithNonce = InvocationsDetails & {
742
742
  nonce: BigNumberish;
743
743
  };
744
+ declare type TransactionBulk = Array<({
745
+ type: 'DECLARE';
746
+ } & {
747
+ payload: DeclareContractPayload;
748
+ }) | ({
749
+ type: 'DEPLOY';
750
+ } & {
751
+ payload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[];
752
+ }) | ({
753
+ type: 'DEPLOY_ACCOUNT';
754
+ } & {
755
+ payload: DeployAccountContractPayload;
756
+ }) | ({
757
+ type: 'INVOKE_FUNCTION';
758
+ } & {
759
+ payload: AllowArray<Call>;
760
+ })>;
761
+ declare type InvocationBulk = Array<(({
762
+ type: 'DECLARE';
763
+ } & DeclareContractTransaction) | ({
764
+ type: 'DEPLOY_ACCOUNT';
765
+ } & DeployAccountContractTransaction) | ({
766
+ type: 'INVOKE_FUNCTION';
767
+ } & Invocation)) & InvocationsDetailsWithNonce & {
768
+ blockIdentifier: BlockNumber | BigNumberish;
769
+ }>;
744
770
  declare type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_L1' | 'REJECTED';
745
771
  declare type TransactionStatus = 'TRANSACTION_RECEIVED';
746
772
  declare type TransactionType = 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION' | 'DEPLOY_ACCOUNT';
@@ -1042,6 +1068,7 @@ declare type EstimateFeeAction = {
1042
1068
  type: 'DEPLOY';
1043
1069
  payload: UniversalDeployerContractPayload;
1044
1070
  };
1071
+ declare type EstimateFeeResponseBulk = Array<EstimateFeeResponse>;
1045
1072
 
1046
1073
  interface EstimateFee extends EstimateFeeResponse {
1047
1074
  suggestedMaxFee: BN__default;
@@ -1261,6 +1288,7 @@ declare namespace Sequencer {
1261
1288
  fee_estimation: Sequencer.EstimateFeeResponse;
1262
1289
  };
1263
1290
  type SimulateTransaction = Omit<InvokeFunctionTransaction, 'max_fee' | 'entry_point_type'>;
1291
+ type EstimateFeeRequestBulk = AllowArray<InvokeEstimateFee | DeclareEstimateFee | DeployEstimateFee | DeployAccountEstimateFee>;
1264
1292
  type EstimateFeeResponse = {
1265
1293
  overall_fee: number;
1266
1294
  gas_price: number;
@@ -1270,6 +1298,7 @@ declare namespace Sequencer {
1270
1298
  amount: BN__default;
1271
1299
  unit: string;
1272
1300
  };
1301
+ type EstimateFeeResponseBulk = AllowArray<EstimateFeeResponse>;
1273
1302
  type Endpoints = {
1274
1303
  get_contract_addresses: {
1275
1304
  QUERY: never;
@@ -1397,6 +1426,13 @@ declare namespace Sequencer {
1397
1426
  REQUEST: SimulateTransaction;
1398
1427
  RESPONSE: TransactionSimulationResponse;
1399
1428
  };
1429
+ estimate_fee_bulk: {
1430
+ QUERY: {
1431
+ blockIdentifier: BlockIdentifier;
1432
+ };
1433
+ REQUEST: EstimateFeeRequestBulk;
1434
+ RESPONSE: EstimateFeeResponseBulk;
1435
+ };
1400
1436
  };
1401
1437
  }
1402
1438
 
@@ -1581,6 +1617,19 @@ declare abstract class ProviderInterface {
1581
1617
  * @returns the estimated fee
1582
1618
  */
1583
1619
  abstract getDeployAccountEstimateFee(transaction: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
1620
+ /**
1621
+ * Estimates the fee for a list of INVOKE transaction
1622
+ *
1623
+ * @param invocations the array of invocation and invocation details object containing:
1624
+ * - contractAddress - the address of the account
1625
+ * - calldata - (defaults to []) the calldata
1626
+ * - signature - (defaults to []) the signature
1627
+ * - nonce - optional nonce
1628
+ * - version - optional version
1629
+ * @param blockIdentifier - block identifier
1630
+ * @returns the estimated fee
1631
+ */
1632
+ abstract getEstimateFeeBulk(invocations: InvocationBulk, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponseBulk>;
1584
1633
  /**
1585
1634
  * Wait for the transaction to be accepted
1586
1635
  * @param txHash - transaction hash
@@ -1630,6 +1679,7 @@ declare class RpcProvider implements ProviderInterface {
1630
1679
  getInvokeEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
1631
1680
  getDeclareEstimateFee({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
1632
1681
  getDeployAccountEstimateFee({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
1682
+ getEstimateFeeBulk(_invocations: InvocationBulk, _blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponseBulk>;
1633
1683
  declareContract({ contractDefinition, signature, senderAddress }: DeclareContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeclareContractResponse>;
1634
1684
  deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce): Promise<DeployContractResponse>;
1635
1685
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetailsWithNonce): Promise<InvokeFunctionResponse>;
@@ -1714,6 +1764,7 @@ declare class SequencerProvider implements ProviderInterface {
1714
1764
  getInvokeEstimateFee(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
1715
1765
  getDeclareEstimateFee({ senderAddress, contractDefinition, signature }: DeclareContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
1716
1766
  getDeployAccountEstimateFee({ classHash, addressSalt, constructorCalldata, signature }: DeployAccountContractTransaction, details: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
1767
+ getEstimateFeeBulk(invocations: InvocationBulk, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponseBulk>;
1717
1768
  getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<Sequencer.GetCodeResponse>;
1718
1769
  waitForTransaction(txHash: BigNumberish, retryInterval?: number, successStates?: string[]): Promise<GetTransactionReceiptResponse>;
1719
1770
  /**
@@ -1758,6 +1809,7 @@ declare class Provider implements ProviderInterface {
1758
1809
  getClassByHash(classHash: string): Promise<ContractClass>;
1759
1810
  getEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier: BlockIdentifier): Promise<EstimateFeeResponse>;
1760
1811
  getInvokeEstimateFee(invocationWithTxType: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponse>;
1812
+ getEstimateFeeBulk(invocations: InvocationBulk, blockIdentifier?: BlockIdentifier): Promise<EstimateFeeResponseBulk>;
1761
1813
  getNonceForAddress(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
1762
1814
  getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
1763
1815
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
@@ -2049,6 +2101,17 @@ declare abstract class AccountInterface extends ProviderInterface {
2049
2101
  * - optional maxFee
2050
2102
  */
2051
2103
  abstract estimateDeployFee(deployContractPayload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[], transactionsDetail?: InvocationsDetails): Promise<EstimateFeeResponse>;
2104
+ /**
2105
+ * Estimate Fee for executing a list of transactions on starknet
2106
+ * Contract must be deployed for fee estimation to be possible
2107
+ *
2108
+ * @param transactions array of transaction object containing :
2109
+ * - type - the type of transaction : 'DECLARE' | 'DEPLOY' | 'INVOKE_FUNCTION' | 'DEPLOY_ACCOUNT'
2110
+ * - payload - the payload of the transaction
2111
+ *
2112
+ * @returns response from estimate_fee
2113
+ */
2114
+ abstract estimateFeeBulk(transactions: TransactionBulk, estimateFeeDetails?: EstimateFeeDetails): Promise<EstimateFeeResponseBulk>;
2052
2115
  /**
2053
2116
  * Invoke execute function in account contract
2054
2117
  *
@@ -2228,6 +2291,8 @@ declare class Account extends Provider implements AccountInterface {
2228
2291
  estimateDeclareFee({ classHash, contract }: DeclareContractPayload, { blockIdentifier, nonce: providedNonce }?: EstimateFeeDetails): Promise<EstimateFee>;
2229
2292
  estimateAccountDeployFee({ classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress, }: DeployAccountContractPayload, { blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
2230
2293
  estimateDeployFee(payload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[], transactionsDetail?: InvocationsDetails | undefined): Promise<EstimateFee>;
2294
+ estimateFeeBulk(transactions: TransactionBulk, { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFeeResponseBulk>;
2295
+ buildInvocation(call: Array<Call>, signerDetails: InvocationsSignerDetails): Promise<Invocation>;
2231
2296
  execute(calls: AllowArray<Call>, abis?: Abi[] | undefined, transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
2232
2297
  declare({ classHash, contract }: DeclareContractPayload, transactionsDetail?: InvocationsDetails): Promise<DeclareContractResponse>;
2233
2298
  deploy(payload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[], details?: InvocationsDetails | undefined): Promise<MultiDeployContractResponse>;
@@ -2239,6 +2304,9 @@ declare class Account extends Provider implements AccountInterface {
2239
2304
  verifyMessageHash(hash: BigNumberish, signature: Signature): Promise<boolean>;
2240
2305
  verifyMessage(typedData: TypedData, signature: Signature): Promise<boolean>;
2241
2306
  getSuggestedMaxFee({ type, payload }: EstimateFeeAction, details: EstimateFeeDetails): Promise<string>;
2307
+ buildDeclarePayload({ classHash, contract }: DeclareContractPayload, { nonce, chainId, version, walletAddress, maxFee }: InvocationsSignerDetails): Promise<DeclareContractTransaction>;
2308
+ buildAccountDeployPayload({ classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress, }: DeployAccountContractPayload, { nonce, chainId, version, maxFee }: InvocationsSignerDetails): Promise<DeployAccountContractTransaction>;
2309
+ buildUDCContractPayload(payload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[]): Call[];
2242
2310
  }
2243
2311
 
2244
2312
  declare type CallOptions = {
@@ -2698,4 +2766,4 @@ declare function validateChecksumAddress(address: string): boolean;
2698
2766
  declare function isUrl(s?: string): boolean;
2699
2767
  declare function buildUrl(baseUrl: string, defaultPath: string, urlOrPath?: string): string;
2700
2768
 
2701
- export { Abi, AbiEntry, Account, AccountInterface, AllowArray, Args, AsyncContractFunction, BlockNumber, BlockTag, Call, CallContractResponse, CallDetails, CallL1Handler, CallOptions, Calldata, CommonTransactionReceiptResponse, CommonTransactionResponse, CompiledContract, CompressedCompiledContract, CompressedProgram, Contract, ContractClass, ContractEntryPoint, ContractFactory, ContractFunction, ContractInterface, DeclareContractPayload, DeclareContractResponse, DeclareContractTransaction, DeclareDeployContractPayload, DeclareDeployUDCResponse, DeclareSignerDetails, DeclareTransactionReceiptResponse, DeclareTransactionResponse, DeployAccountContractPayload, DeployAccountContractTransaction, DeployAccountSignerDetails, DeployContractPayload, DeployContractResponse, DeployContractUDCResponse, EntryPointType, EntryPointsByType, EstimateFee, EstimateFeeAction, EstimateFeeDetails, EstimateFeeResponse, Event, ExecutionResources, FunctionAbi, FunctionInvocation, GatewayError, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionReceiptResponse, GetTransactionResponse, GetTransactionStatusResponse, HttpError, Invocation, InvocationsDetails, InvocationsDetailsWithNonce, InvocationsSignerDetails, InvokeFunctionResponse, InvokeTransactionReceiptResponse, InvokeTransactionResponse, KeyPair, MessageToL1, MessageToL2, MultiDeployContractResponse, Overrides, ParsedStruct, Program, Provider, ProviderInterface, ProviderOptions, RPC, RawArgs, RawCalldata, Result, RpcProvider, RpcProviderOptions, Sequencer, SequencerProvider, SequencerProviderOptions, Signature, Signer, SignerInterface, Status, Struct, StructAbi, TransactionStatus, TransactionTraceResponse, TransactionType, UniversalDeployerContractPayload, addAddressPadding, buildUrl, constants, defaultProvider, ellipticCurve as ec, encode, getChecksumAddress, hash, isUrl, json, merkle, number, shortString, stark, transaction, index as typedData, uint256, validateAndParseAddress, validateChecksumAddress };
2769
+ export { Abi, AbiEntry, Account, AccountInterface, AllowArray, Args, AsyncContractFunction, BlockNumber, BlockTag, Call, CallContractResponse, CallDetails, CallL1Handler, CallOptions, Calldata, CommonTransactionReceiptResponse, CommonTransactionResponse, CompiledContract, CompressedCompiledContract, CompressedProgram, Contract, ContractClass, ContractEntryPoint, ContractFactory, ContractFunction, ContractInterface, DeclareContractPayload, DeclareContractResponse, DeclareContractTransaction, DeclareDeployContractPayload, DeclareDeployUDCResponse, DeclareSignerDetails, DeclareTransactionReceiptResponse, DeclareTransactionResponse, DeployAccountContractPayload, DeployAccountContractTransaction, DeployAccountSignerDetails, DeployContractPayload, DeployContractResponse, DeployContractUDCResponse, EntryPointType, EntryPointsByType, EstimateFee, EstimateFeeAction, EstimateFeeDetails, EstimateFeeResponse, EstimateFeeResponseBulk, Event, ExecutionResources, FunctionAbi, FunctionInvocation, GatewayError, GetBlockResponse, GetCodeResponse, GetContractAddressesResponse, GetTransactionReceiptResponse, GetTransactionResponse, GetTransactionStatusResponse, HttpError, Invocation, InvocationBulk, InvocationsDetails, InvocationsDetailsWithNonce, InvocationsSignerDetails, InvokeFunctionResponse, InvokeTransactionReceiptResponse, InvokeTransactionResponse, KeyPair, MessageToL1, MessageToL2, MultiDeployContractResponse, Overrides, ParsedStruct, Program, Provider, ProviderInterface, ProviderOptions, RPC, RawArgs, RawCalldata, Result, RpcProvider, RpcProviderOptions, Sequencer, SequencerProvider, SequencerProviderOptions, Signature, Signer, SignerInterface, Status, Struct, StructAbi, TransactionBulk, TransactionStatus, TransactionTraceResponse, TransactionType, UniversalDeployerContractPayload, addAddressPadding, buildUrl, constants, defaultProvider, ellipticCurve as ec, encode, getChecksumAddress, hash, isUrl, json, merkle, number, shortString, stark, transaction, index as typedData, uint256, validateAndParseAddress, validateChecksumAddress };
@@ -20754,6 +20754,9 @@ var starknet = (() => {
20754
20754
  block_id
20755
20755
  }).then(this.responseParser.parseFeeEstimateResponse);
20756
20756
  }
20757
+ async getEstimateFeeBulk(_invocations, _blockIdentifier = this.blockIdentifier) {
20758
+ throw new Error("RPC does not implement getInvokeEstimateFeeBulk function");
20759
+ }
20757
20760
  async declareContract({ contractDefinition, signature, senderAddress }, details) {
20758
20761
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
20759
20762
  declare_transaction: {
@@ -20935,6 +20938,27 @@ var starknet = (() => {
20935
20938
  overall_fee: toBN(res.amount)
20936
20939
  };
20937
20940
  }
20941
+ parseFeeEstimateBulkResponse(res) {
20942
+ return [].concat(res).map((item) => {
20943
+ if ("overall_fee" in item) {
20944
+ let gasInfo = {};
20945
+ try {
20946
+ gasInfo = {
20947
+ gas_consumed: toBN(item.gas_usage),
20948
+ gas_price: toBN(item.gas_price)
20949
+ };
20950
+ } catch {
20951
+ }
20952
+ return {
20953
+ overall_fee: toBN(item.overall_fee),
20954
+ ...gasInfo
20955
+ };
20956
+ }
20957
+ return {
20958
+ overall_fee: toBN(item.amount)
20959
+ };
20960
+ });
20961
+ }
20938
20962
  parseCallContractResponse(res) {
20939
20963
  return {
20940
20964
  result: res.result
@@ -21119,6 +21143,7 @@ var starknet = (() => {
21119
21143
  "call_contract",
21120
21144
  "estimate_fee",
21121
21145
  "estimate_message_fee",
21146
+ "estimate_fee_bulk",
21122
21147
  "simulate_transaction"
21123
21148
  ];
21124
21149
  return postMethodEndpoints.includes(endpoint) ? "POST" : "GET";
@@ -21321,6 +21346,42 @@ var starknet = (() => {
21321
21346
  }
21322
21347
  ).then(this.responseParser.parseFeeEstimateResponse);
21323
21348
  }
21349
+ async getEstimateFeeBulk(invocations, blockIdentifier = this.blockIdentifier) {
21350
+ const params = invocations.map((invocation) => {
21351
+ let res;
21352
+ if (invocation.type === "INVOKE_FUNCTION") {
21353
+ res = {
21354
+ type: invocation.type,
21355
+ contract_address: invocation.contractAddress,
21356
+ calldata: invocation.calldata ?? []
21357
+ };
21358
+ } else if (invocation.type === "DECLARE") {
21359
+ res = {
21360
+ type: invocation.type,
21361
+ sender_address: invocation.senderAddress,
21362
+ contract_class: invocation.contractDefinition
21363
+ };
21364
+ } else {
21365
+ res = {
21366
+ type: invocation.type,
21367
+ class_hash: toHex(toBN(invocation.classHash)),
21368
+ constructor_calldata: bigNumberishArrayToDecimalStringArray(
21369
+ invocation.constructorCalldata || []
21370
+ ),
21371
+ contract_address_salt: toHex(toBN(invocation.addressSalt || 0))
21372
+ };
21373
+ }
21374
+ return {
21375
+ ...res,
21376
+ signature: bigNumberishArrayToDecimalStringArray(invocation.signature || []),
21377
+ version: toHex(toBN((invocation == null ? void 0 : invocation.version) || 1)),
21378
+ nonce: toHex(toBN(invocation.nonce))
21379
+ };
21380
+ });
21381
+ return this.fetchEndpoint("estimate_fee_bulk", { blockIdentifier }, params).then(
21382
+ this.responseParser.parseFeeEstimateBulkResponse
21383
+ );
21384
+ }
21324
21385
  async getCode(contractAddress, blockIdentifier = this.blockIdentifier) {
21325
21386
  return this.fetchEndpoint("get_code", { contractAddress, blockIdentifier });
21326
21387
  }
@@ -21423,6 +21484,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21423
21484
  blockIdentifier
21424
21485
  );
21425
21486
  }
21487
+ async getEstimateFeeBulk(invocations, blockIdentifier) {
21488
+ return this.provider.getEstimateFeeBulk(invocations, blockIdentifier);
21489
+ }
21426
21490
  async getNonceForAddress(contractAddress, blockIdentifier) {
21427
21491
  return this.provider.getNonceForAddress(contractAddress, blockIdentifier);
21428
21492
  }
@@ -22477,10 +22541,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22477
22541
  version: version3,
22478
22542
  chainId
22479
22543
  };
22480
- const signature = await this.signer.signTransaction(transactions, signerDetails);
22481
- const calldata = fromCallsToExecuteCalldata(transactions);
22544
+ const invocation = await this.buildInvocation(transactions, signerDetails);
22482
22545
  const response = await super.getInvokeEstimateFee(
22483
- { contractAddress: this.address, calldata, signature },
22546
+ { ...invocation },
22484
22547
  { version: version3, nonce },
22485
22548
  blockIdentifier
22486
22549
  );
@@ -22494,17 +22557,12 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22494
22557
  const nonce = toBN(providedNonce ?? await this.getNonce());
22495
22558
  const version3 = toBN(feeTransactionVersion);
22496
22559
  const chainId = await this.getChainId();
22497
- const contractDefinition = parseContract(contract);
22498
- const signature = await this.signer.signDeclareTransaction({
22499
- classHash,
22500
- senderAddress: this.address,
22501
- chainId,
22502
- maxFee: ZERO,
22503
- version: version3,
22504
- nonce
22505
- });
22560
+ const payload = await this.buildDeclarePayload(
22561
+ { classHash, contract },
22562
+ { nonce, chainId, version: version3, walletAddress: this.address, maxFee: ZERO }
22563
+ );
22506
22564
  const response = await super.getDeclareEstimateFee(
22507
- { senderAddress: this.address, signature, contractDefinition },
22565
+ { ...payload },
22508
22566
  { version: version3, nonce },
22509
22567
  blockIdentifier
22510
22568
  );
@@ -22523,19 +22581,12 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22523
22581
  const nonce = "0x0";
22524
22582
  const version3 = toBN(feeTransactionVersion);
22525
22583
  const chainId = await this.getChainId();
22526
- const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
22527
- const signature = await this.signer.signDeployAccountTransaction({
22528
- classHash,
22529
- contractAddress,
22530
- chainId,
22531
- maxFee: ZERO,
22532
- version: version3,
22533
- nonce,
22534
- addressSalt,
22535
- constructorCalldata
22536
- });
22584
+ const payload = await this.buildAccountDeployPayload(
22585
+ { classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress },
22586
+ { nonce, chainId, version: version3, walletAddress: this.address, maxFee: ZERO }
22587
+ );
22537
22588
  const response = await super.getDeployAccountEstimateFee(
22538
- { classHash, addressSalt, constructorCalldata, signature },
22589
+ { ...payload },
22539
22590
  { version: version3, nonce },
22540
22591
  blockIdentifier
22541
22592
  );
@@ -22546,27 +22597,85 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22546
22597
  };
22547
22598
  }
22548
22599
  async estimateDeployFee(payload, transactionsDetail) {
22549
- const calls = [].concat(payload).map((it) => {
22550
- const {
22551
- classHash,
22552
- salt = "0",
22553
- unique = true,
22554
- constructorCalldata = []
22555
- } = it;
22556
- const compiledConstructorCallData = compileCalldata(constructorCalldata);
22600
+ const calls = this.buildUDCContractPayload(payload);
22601
+ return this.estimateInvokeFee(calls, transactionsDetail);
22602
+ }
22603
+ async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier } = {}) {
22604
+ const nonce = toBN(providedNonce ?? await this.getNonce());
22605
+ const version3 = toBN(feeTransactionVersion);
22606
+ const chainId = await this.getChainId();
22607
+ const params = await Promise.all(
22608
+ [].concat(transactions).map(async (transaction, index) => {
22609
+ const signerDetails = {
22610
+ walletAddress: this.address,
22611
+ nonce: toBN(Number(nonce) + index),
22612
+ maxFee: ZERO,
22613
+ version: version3,
22614
+ chainId
22615
+ };
22616
+ const txPayload = transaction.payload;
22617
+ let res;
22618
+ if (typeof transaction === "object" && transaction.type === "INVOKE_FUNCTION") {
22619
+ const invocation = await this.buildInvocation(
22620
+ Array.isArray(txPayload) ? txPayload : [txPayload],
22621
+ signerDetails
22622
+ );
22623
+ res = {
22624
+ type: "INVOKE_FUNCTION",
22625
+ ...invocation,
22626
+ version: version3,
22627
+ nonce: toBN(Number(nonce) + index),
22628
+ blockIdentifier
22629
+ };
22630
+ } else if (typeof transaction === "object" && transaction.type === "DECLARE") {
22631
+ const declareContractPayload = await this.buildDeclarePayload(txPayload, signerDetails);
22632
+ res = {
22633
+ type: "DECLARE",
22634
+ ...declareContractPayload,
22635
+ version: version3,
22636
+ nonce: toBN(Number(nonce) + index),
22637
+ blockIdentifier
22638
+ };
22639
+ } else if (typeof transaction === "object" && transaction.type === "DEPLOY_ACCOUNT") {
22640
+ const payload = await this.buildAccountDeployPayload(txPayload, signerDetails);
22641
+ res = {
22642
+ type: "DEPLOY_ACCOUNT",
22643
+ ...payload,
22644
+ version: version3,
22645
+ nonce,
22646
+ blockIdentifier
22647
+ };
22648
+ } else if (typeof transaction === "object" && transaction.type === "DEPLOY") {
22649
+ const calls = this.buildUDCContractPayload(txPayload);
22650
+ const invocation = await this.buildInvocation(calls, signerDetails);
22651
+ res = {
22652
+ type: "INVOKE_FUNCTION",
22653
+ ...invocation,
22654
+ version: version3,
22655
+ nonce: toBN(Number(nonce) + index),
22656
+ blockIdentifier
22657
+ };
22658
+ }
22659
+ return res;
22660
+ })
22661
+ );
22662
+ const response = await super.getEstimateFeeBulk(params, blockIdentifier);
22663
+ return [].concat(response).map((elem) => {
22664
+ const suggestedMaxFee = estimatedFeeToMaxFee(elem.overall_fee);
22557
22665
  return {
22558
- contractAddress: UDC.ADDRESS,
22559
- entrypoint: UDC.ENTRYPOINT,
22560
- calldata: [
22561
- classHash,
22562
- salt,
22563
- toCairoBool(unique),
22564
- compiledConstructorCallData.length,
22565
- ...compiledConstructorCallData
22566
- ]
22666
+ ...elem,
22667
+ suggestedMaxFee
22567
22668
  };
22568
22669
  });
22569
- return this.estimateInvokeFee(calls, transactionsDetail);
22670
+ }
22671
+ async buildInvocation(call, signerDetails) {
22672
+ const calldata = fromCallsToExecuteCalldata(call);
22673
+ const signature = await this.signer.signTransaction(call, signerDetails);
22674
+ return {
22675
+ contractAddress: this.address,
22676
+ calldata,
22677
+ signature
22678
+ };
22570
22679
  }
22571
22680
  async execute(calls, abis = void 0, transactionsDetail = {}) {
22572
22681
  const transactions = Array.isArray(calls) ? calls : [calls];
@@ -22755,6 +22864,69 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22755
22864
  }
22756
22865
  return feeEstimate.suggestedMaxFee.toString();
22757
22866
  }
22867
+ async buildDeclarePayload({ classHash, contract }, { nonce, chainId, version: version3, walletAddress, maxFee }) {
22868
+ const contractDefinition = parseContract(contract);
22869
+ const signature = await this.signer.signDeclareTransaction({
22870
+ classHash,
22871
+ senderAddress: walletAddress,
22872
+ chainId,
22873
+ maxFee,
22874
+ version: version3,
22875
+ nonce
22876
+ });
22877
+ return {
22878
+ senderAddress: walletAddress,
22879
+ signature,
22880
+ contractDefinition
22881
+ };
22882
+ }
22883
+ async buildAccountDeployPayload({
22884
+ classHash,
22885
+ addressSalt = 0,
22886
+ constructorCalldata = [],
22887
+ contractAddress: providedContractAddress
22888
+ }, { nonce, chainId, version: version3, maxFee }) {
22889
+ const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
22890
+ const signature = await this.signer.signDeployAccountTransaction({
22891
+ classHash,
22892
+ contractAddress,
22893
+ chainId,
22894
+ maxFee,
22895
+ version: version3,
22896
+ nonce,
22897
+ addressSalt,
22898
+ constructorCalldata
22899
+ });
22900
+ return {
22901
+ classHash,
22902
+ addressSalt,
22903
+ constructorCalldata,
22904
+ signature
22905
+ };
22906
+ }
22907
+ buildUDCContractPayload(payload) {
22908
+ const calls = [].concat(payload).map((it) => {
22909
+ const {
22910
+ classHash,
22911
+ salt = "0",
22912
+ unique = true,
22913
+ constructorCalldata = []
22914
+ } = it;
22915
+ const compiledConstructorCallData = compileCalldata(constructorCalldata);
22916
+ return {
22917
+ contractAddress: UDC.ADDRESS,
22918
+ entrypoint: UDC.ENTRYPOINT,
22919
+ calldata: [
22920
+ classHash,
22921
+ salt,
22922
+ toCairoBool(unique),
22923
+ compiledConstructorCallData.length,
22924
+ ...compiledConstructorCallData
22925
+ ]
22926
+ };
22927
+ });
22928
+ return calls;
22929
+ }
22758
22930
  };
22759
22931
 
22760
22932
  // src/account/interface.ts