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.js CHANGED
@@ -2716,6 +2716,9 @@ var Block = class {
2716
2716
  set identifier(_identifier) {
2717
2717
  this.setIdentifier(_identifier);
2718
2718
  }
2719
+ get sequencerIdentifier() {
2720
+ return this.hash !== null ? { blockHash: this.hash } : { blockNumber: this.number ?? this.tag };
2721
+ }
2719
2722
  };
2720
2723
 
2721
2724
  // src/provider/rpc.ts
@@ -3008,6 +3011,9 @@ var RpcProvider = class {
3008
3011
  async getEvents(eventFilter) {
3009
3012
  return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
3010
3013
  }
3014
+ async getSimulateTransaction(_invocation, _invocationDetails, _blockIdentifier) {
3015
+ throw new Error("RPC does not implement simulateTransaction function");
3016
+ }
3011
3017
  };
3012
3018
 
3013
3019
  // src/provider/sequencer.ts
@@ -3101,6 +3107,31 @@ var SequencerAPIResponseParser = class extends ResponseParser {
3101
3107
  };
3102
3108
  });
3103
3109
  }
3110
+ parseFeeSimulateTransactionResponse(res) {
3111
+ if ("overall_fee" in res.fee_estimation) {
3112
+ let gasInfo = {};
3113
+ try {
3114
+ gasInfo = {
3115
+ gas_consumed: toBN(res.fee_estimation.gas_usage),
3116
+ gas_price: toBN(res.fee_estimation.gas_price)
3117
+ };
3118
+ } catch {
3119
+ }
3120
+ return {
3121
+ trace: res.trace,
3122
+ fee_estimation: {
3123
+ ...gasInfo,
3124
+ overall_fee: toBN(res.fee_estimation.overall_fee)
3125
+ }
3126
+ };
3127
+ }
3128
+ return {
3129
+ trace: res.trace,
3130
+ fee_estimation: {
3131
+ overall_fee: toBN(res.fee_estimation.amount)
3132
+ }
3133
+ };
3134
+ }
3104
3135
  parseCallContractResponse(res) {
3105
3136
  return {
3106
3137
  result: res.result
@@ -3123,6 +3154,29 @@ var SequencerAPIResponseParser = class extends ResponseParser {
3123
3154
  class_hash: res.class_hash
3124
3155
  };
3125
3156
  }
3157
+ parseGetStateUpdateResponse(res) {
3158
+ const nonces = [].concat(res.state_diff.nonces).map(({ contract_address, nonce }) => {
3159
+ return {
3160
+ contract_address,
3161
+ nonce
3162
+ };
3163
+ });
3164
+ const storage_diffs = [].concat(res.state_diff.storage_diffs).map(({ address, storage_entries }) => {
3165
+ return {
3166
+ address,
3167
+ storage_entries
3168
+ };
3169
+ });
3170
+ return {
3171
+ ...res,
3172
+ state_diff: {
3173
+ storage_diffs,
3174
+ declared_contract_hashes: res.state_diff.declared_contract_hashes,
3175
+ deployed_contracts: res.state_diff.deployed_contracts,
3176
+ nonces
3177
+ }
3178
+ };
3179
+ }
3126
3180
  };
3127
3181
 
3128
3182
  // src/utils/url.ts
@@ -3502,7 +3556,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
3502
3556
  };
3503
3557
  return this.fetchEndpoint("estimate_message_fee", { blockIdentifier }, validCallL1Handler);
3504
3558
  }
3505
- async simulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
3559
+ async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
3506
3560
  return this.fetchEndpoint(
3507
3561
  "simulate_transaction",
3508
3562
  { blockIdentifier },
@@ -3514,6 +3568,12 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
3514
3568
  version: toHex(toBN((invocationDetails == null ? void 0 : invocationDetails.version) || 1)),
3515
3569
  nonce: toHex(toBN(invocationDetails.nonce))
3516
3570
  }
3571
+ ).then(this.responseParser.parseFeeSimulateTransactionResponse);
3572
+ }
3573
+ async getStateUpdate(blockIdentifier = this.blockIdentifier) {
3574
+ const args = new Block(blockIdentifier).sequencerIdentifier;
3575
+ return this.fetchEndpoint("get_state_update", { ...args }).then(
3576
+ this.responseParser.parseGetStateUpdateResponse
3517
3577
  );
3518
3578
  }
3519
3579
  };
@@ -3600,6 +3660,12 @@ var Provider = class {
3600
3660
  async waitForTransaction(txHash, retryInterval, successStates) {
3601
3661
  return this.provider.waitForTransaction(txHash, retryInterval, successStates);
3602
3662
  }
3663
+ async getSimulateTransaction(invocation, invocationDetails, blockIdentifier) {
3664
+ return this.provider.getSimulateTransaction(invocation, invocationDetails, blockIdentifier);
3665
+ }
3666
+ async getStateUpdate(blockIdentifier) {
3667
+ return this.provider.getStateUpdate(blockIdentifier);
3668
+ }
3603
3669
  };
3604
3670
 
3605
3671
  // src/provider/interface.ts
@@ -5004,6 +5070,33 @@ var Account = class extends Provider {
5004
5070
  });
5005
5071
  return calls;
5006
5072
  }
5073
+ async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier } = {}) {
5074
+ const transactions = Array.isArray(calls) ? calls : [calls];
5075
+ const nonce = toBN(providedNonce ?? await this.getNonce());
5076
+ const version = toBN(feeTransactionVersion);
5077
+ const chainId = await this.getChainId();
5078
+ const signerDetails = {
5079
+ walletAddress: this.address,
5080
+ nonce,
5081
+ maxFee: ZERO,
5082
+ version,
5083
+ chainId
5084
+ };
5085
+ const invocation = await this.buildInvocation(transactions, signerDetails);
5086
+ const response = await super.getSimulateTransaction(
5087
+ invocation,
5088
+ { version, nonce },
5089
+ blockIdentifier
5090
+ );
5091
+ const suggestedMaxFee = estimatedFeeToMaxFee(response.fee_estimation.overall_fee);
5092
+ return {
5093
+ ...response,
5094
+ fee_estimation: {
5095
+ ...response.fee_estimation,
5096
+ suggestedMaxFee
5097
+ }
5098
+ };
5099
+ }
5007
5100
  };
5008
5101
 
5009
5102
  // src/account/interface.ts