starknet 4.19.2 → 4.20.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/dist/index.mjs CHANGED
@@ -2658,6 +2658,9 @@ var Block = class {
2658
2658
  set identifier(_identifier) {
2659
2659
  this.setIdentifier(_identifier);
2660
2660
  }
2661
+ get sequencerIdentifier() {
2662
+ return this.hash !== null ? { blockHash: this.hash } : { blockNumber: this.number ?? this.tag };
2663
+ }
2661
2664
  };
2662
2665
 
2663
2666
  // src/provider/rpc.ts
@@ -2950,6 +2953,9 @@ var RpcProvider = class {
2950
2953
  async getEvents(eventFilter) {
2951
2954
  return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
2952
2955
  }
2956
+ async getSimulateTransaction(_invocation, _invocationDetails, _blockIdentifier) {
2957
+ throw new Error("RPC does not implement simulateTransaction function");
2958
+ }
2953
2959
  };
2954
2960
 
2955
2961
  // src/provider/sequencer.ts
@@ -3043,6 +3049,31 @@ var SequencerAPIResponseParser = class extends ResponseParser {
3043
3049
  };
3044
3050
  });
3045
3051
  }
3052
+ parseFeeSimulateTransactionResponse(res) {
3053
+ if ("overall_fee" in res.fee_estimation) {
3054
+ let gasInfo = {};
3055
+ try {
3056
+ gasInfo = {
3057
+ gas_consumed: toBN(res.fee_estimation.gas_usage),
3058
+ gas_price: toBN(res.fee_estimation.gas_price)
3059
+ };
3060
+ } catch {
3061
+ }
3062
+ return {
3063
+ trace: res.trace,
3064
+ fee_estimation: {
3065
+ ...gasInfo,
3066
+ overall_fee: toBN(res.fee_estimation.overall_fee)
3067
+ }
3068
+ };
3069
+ }
3070
+ return {
3071
+ trace: res.trace,
3072
+ fee_estimation: {
3073
+ overall_fee: toBN(res.fee_estimation.amount)
3074
+ }
3075
+ };
3076
+ }
3046
3077
  parseCallContractResponse(res) {
3047
3078
  return {
3048
3079
  result: res.result
@@ -3065,6 +3096,29 @@ var SequencerAPIResponseParser = class extends ResponseParser {
3065
3096
  class_hash: res.class_hash
3066
3097
  };
3067
3098
  }
3099
+ parseGetStateUpdateResponse(res) {
3100
+ const nonces = [].concat(res.state_diff.nonces).map(({ contract_address, nonce }) => {
3101
+ return {
3102
+ contract_address,
3103
+ nonce
3104
+ };
3105
+ });
3106
+ const storage_diffs = [].concat(res.state_diff.storage_diffs).map(({ address, storage_entries }) => {
3107
+ return {
3108
+ address,
3109
+ storage_entries
3110
+ };
3111
+ });
3112
+ return {
3113
+ ...res,
3114
+ state_diff: {
3115
+ storage_diffs,
3116
+ declared_contract_hashes: res.state_diff.declared_contract_hashes,
3117
+ deployed_contracts: res.state_diff.deployed_contracts,
3118
+ nonces
3119
+ }
3120
+ };
3121
+ }
3068
3122
  };
3069
3123
 
3070
3124
  // src/utils/url.ts
@@ -3444,7 +3498,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
3444
3498
  };
3445
3499
  return this.fetchEndpoint("estimate_message_fee", { blockIdentifier }, validCallL1Handler);
3446
3500
  }
3447
- async simulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
3501
+ async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
3448
3502
  return this.fetchEndpoint(
3449
3503
  "simulate_transaction",
3450
3504
  { blockIdentifier },
@@ -3456,6 +3510,12 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
3456
3510
  version: toHex(toBN((invocationDetails == null ? void 0 : invocationDetails.version) || 1)),
3457
3511
  nonce: toHex(toBN(invocationDetails.nonce))
3458
3512
  }
3513
+ ).then(this.responseParser.parseFeeSimulateTransactionResponse);
3514
+ }
3515
+ async getStateUpdate(blockIdentifier = this.blockIdentifier) {
3516
+ const args = new Block(blockIdentifier).sequencerIdentifier;
3517
+ return this.fetchEndpoint("get_state_update", { ...args }).then(
3518
+ this.responseParser.parseGetStateUpdateResponse
3459
3519
  );
3460
3520
  }
3461
3521
  };
@@ -3542,6 +3602,12 @@ var Provider = class {
3542
3602
  async waitForTransaction(txHash, retryInterval, successStates) {
3543
3603
  return this.provider.waitForTransaction(txHash, retryInterval, successStates);
3544
3604
  }
3605
+ async getSimulateTransaction(invocation, invocationDetails, blockIdentifier) {
3606
+ return this.provider.getSimulateTransaction(invocation, invocationDetails, blockIdentifier);
3607
+ }
3608
+ async getStateUpdate(blockIdentifier) {
3609
+ return this.provider.getStateUpdate(blockIdentifier);
3610
+ }
3545
3611
  };
3546
3612
 
3547
3613
  // src/provider/interface.ts
@@ -4946,6 +5012,33 @@ var Account = class extends Provider {
4946
5012
  });
4947
5013
  return calls;
4948
5014
  }
5015
+ async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier } = {}) {
5016
+ const transactions = Array.isArray(calls) ? calls : [calls];
5017
+ const nonce = toBN(providedNonce ?? await this.getNonce());
5018
+ const version = toBN(feeTransactionVersion);
5019
+ const chainId = await this.getChainId();
5020
+ const signerDetails = {
5021
+ walletAddress: this.address,
5022
+ nonce,
5023
+ maxFee: ZERO,
5024
+ version,
5025
+ chainId
5026
+ };
5027
+ const invocation = await this.buildInvocation(transactions, signerDetails);
5028
+ const response = await super.getSimulateTransaction(
5029
+ invocation,
5030
+ { version, nonce },
5031
+ blockIdentifier
5032
+ );
5033
+ const suggestedMaxFee = estimatedFeeToMaxFee(response.fee_estimation.overall_fee);
5034
+ return {
5035
+ ...response,
5036
+ fee_estimation: {
5037
+ ...response.fee_estimation,
5038
+ suggestedMaxFee
5039
+ }
5040
+ };
5041
+ }
4949
5042
  };
4950
5043
 
4951
5044
  // src/account/interface.ts