starknet 5.3.0 → 5.4.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
@@ -2444,24 +2444,22 @@ import * as weierstrass from "@noble/curves/abstract/weierstrass";
2444
2444
  // src/utils/json.ts
2445
2445
  var json_exports = {};
2446
2446
  __export(json_exports, {
2447
- default: () => json_default,
2448
- parse: () => parse,
2447
+ parse: () => parse2,
2449
2448
  parseAlwaysAsBig: () => parseAlwaysAsBig,
2450
- stringify: () => stringify,
2449
+ stringify: () => stringify2,
2451
2450
  stringifyAlwaysAsBig: () => stringifyAlwaysAsBig
2452
2451
  });
2453
- import Json from "json-bigint";
2454
- var json = (alwaysParseAsBig) => {
2455
- return Json({
2456
- alwaysParseAsBig,
2457
- useNativeBigInt: true,
2458
- protoAction: "preserve",
2459
- constructorAction: "preserve"
2460
- });
2452
+ import * as json from "lossless-json";
2453
+ var parseIntAsNumberOrBigInt = (x) => {
2454
+ if (!json.isInteger(x))
2455
+ return parseFloat(x);
2456
+ const v = parseInt(x, 10);
2457
+ return Number.isSafeInteger(v) ? v : BigInt(x);
2461
2458
  };
2462
- var { parse, stringify } = json(false);
2463
- var { parse: parseAlwaysAsBig, stringify: stringifyAlwaysAsBig } = json(true);
2464
- var json_default = { parse, stringify };
2459
+ var parse2 = (x) => json.parse(String(x), null, parseIntAsNumberOrBigInt);
2460
+ var parseAlwaysAsBig = (x) => json.parse(String(x), null, json.parseNumberAndBigInt);
2461
+ var stringify2 = (...p) => json.stringify(...p);
2462
+ var stringifyAlwaysAsBig = stringify2;
2465
2463
 
2466
2464
  // src/utils/hash.ts
2467
2465
  import * as poseidon from "@noble/curves/abstract/poseidon";
@@ -2595,11 +2593,11 @@ function formatSpaces(json2) {
2595
2593
  function computeHintedClassHash(compiledContract) {
2596
2594
  const { abi, program } = compiledContract;
2597
2595
  const contractClass = { abi, program };
2598
- const serializedJson = formatSpaces(stringify(contractClass, nullSkipReplacer));
2596
+ const serializedJson = formatSpaces(stringify2(contractClass, nullSkipReplacer));
2599
2597
  return addHexPrefix(starkCurve.keccak(utf8ToArray(serializedJson)).toString(16));
2600
2598
  }
2601
2599
  function computeLegacyContractClassHash(contract) {
2602
- const compiledContract = typeof contract === "string" ? parse(contract) : contract;
2600
+ const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
2603
2601
  const apiVersion = toHex(API_VERSION);
2604
2602
  const externalEntryPointsHash = computeHashOnElements(
2605
2603
  compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
@@ -2662,7 +2660,7 @@ function hashEntryPointSierra(data) {
2662
2660
  return poseidonHashMany(base);
2663
2661
  }
2664
2662
  function hashAbi(sierra) {
2665
- const indentString = formatSpaces(stringify(sierra.abi, null));
2663
+ const indentString = formatSpaces(stringify2(sierra.abi, null));
2666
2664
  return BigInt(addHexPrefix(starkCurve.keccak(utf8ToArray(indentString)).toString(16)));
2667
2665
  }
2668
2666
  function computeSierraContractClassHash(sierra) {
@@ -2685,7 +2683,7 @@ function computeSierraContractClassHash(sierra) {
2685
2683
  );
2686
2684
  }
2687
2685
  function computeContractClassHash(contract) {
2688
- const compiledContract = typeof contract === "string" ? parse(contract) : contract;
2686
+ const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
2689
2687
  if ("sierra_program" in compiledContract) {
2690
2688
  return computeSierraContractClassHash(compiledContract);
2691
2689
  }
@@ -2693,7 +2691,6 @@ function computeContractClassHash(contract) {
2693
2691
  }
2694
2692
 
2695
2693
  // src/utils/contract.ts
2696
- import { parse as parse2 } from "json-bigint";
2697
2694
  function isSierra(contract) {
2698
2695
  const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
2699
2696
  return "sierra_program" in compiledContract;
@@ -2731,7 +2728,7 @@ __export(stark_exports, {
2731
2728
  import { Signature, getStarkKey, utils } from "micro-starknet";
2732
2729
  import { gzip } from "pako";
2733
2730
  function compressProgram(jsonProgram) {
2734
- const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify(jsonProgram);
2731
+ const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
2735
2732
  const compressedProgram = gzip(stringified);
2736
2733
  return btoaUniversal(compressedProgram);
2737
2734
  }
@@ -2801,13 +2798,13 @@ function parseCalldata(calldata = []) {
2801
2798
  function createSierraContractClass(contract) {
2802
2799
  const result = { ...contract };
2803
2800
  delete result.sierra_program_debug_info;
2804
- result.abi = formatSpaces(stringify(contract.abi));
2805
- result.sierra_program = formatSpaces(stringify(contract.sierra_program));
2801
+ result.abi = formatSpaces(stringify2(contract.abi));
2802
+ result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
2806
2803
  result.sierra_program = compressProgram(result.sierra_program);
2807
2804
  return result;
2808
2805
  }
2809
2806
  function parseContract(contract) {
2810
- const parsedContract = typeof contract === "string" ? parse(contract) : contract;
2807
+ const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
2811
2808
  if (!isSierra(contract)) {
2812
2809
  return {
2813
2810
  ...parsedContract,
@@ -2857,7 +2854,7 @@ var RPCResponseParser = class {
2857
2854
  };
2858
2855
 
2859
2856
  // src/provider/errors.ts
2860
- import { CustomError } from "ts-custom-error";
2857
+ import { CustomError } from "ts-custom-error/dist/custom-error";
2861
2858
  var LibraryError = class extends CustomError {
2862
2859
  };
2863
2860
  var GatewayError = class extends LibraryError {
@@ -3079,7 +3076,7 @@ var RpcProvider = class {
3079
3076
  fetch(method, params) {
3080
3077
  return fetchPonyfill_default(this.nodeUrl, {
3081
3078
  method: "POST",
3082
- body: stringify({ method, jsonrpc: "2.0", params, id: 0 }),
3079
+ body: stringify2({ method, jsonrpc: "2.0", params, id: 0 }),
3083
3080
  headers: this.headers
3084
3081
  });
3085
3082
  }
@@ -3666,20 +3663,20 @@ var SequencerProvider = class {
3666
3663
  try {
3667
3664
  const response = await fetchPonyfill_default(url, {
3668
3665
  method,
3669
- body: stringify(options == null ? void 0 : options.body),
3666
+ body: stringify2(options == null ? void 0 : options.body),
3670
3667
  headers
3671
3668
  });
3672
3669
  const textResponse = await response.text();
3673
3670
  if (!response.ok) {
3674
3671
  let responseBody;
3675
3672
  try {
3676
- responseBody = parse(textResponse);
3673
+ responseBody = parse2(textResponse);
3677
3674
  } catch {
3678
3675
  throw new HttpError(response.statusText, response.status);
3679
3676
  }
3680
3677
  throw new GatewayError(responseBody.message, responseBody.code);
3681
3678
  }
3682
- const parseChoice = (options == null ? void 0 : options.parseAlwaysAsBigInt) ? parseAlwaysAsBig : parse;
3679
+ const parseChoice = (options == null ? void 0 : options.parseAlwaysAsBigInt) ? parseAlwaysAsBig : parse2;
3683
3680
  return parseChoice(textResponse);
3684
3681
  } catch (error) {
3685
3682
  if (error instanceof Error && !(error instanceof LibraryError))
@@ -4748,7 +4745,10 @@ var transaction_exports = {};
4748
4745
  __export(transaction_exports, {
4749
4746
  fromCallsToExecuteCalldata: () => fromCallsToExecuteCalldata,
4750
4747
  fromCallsToExecuteCalldataWithNonce: () => fromCallsToExecuteCalldataWithNonce,
4751
- transformCallsToMulticallArrays: () => transformCallsToMulticallArrays
4748
+ fromCallsToExecuteCalldata_cairo1: () => fromCallsToExecuteCalldata_cairo1,
4749
+ getExecuteCalldata: () => getExecuteCalldata,
4750
+ transformCallsToMulticallArrays: () => transformCallsToMulticallArrays,
4751
+ transformCallsToMulticallArrays_cairo1: () => transformCallsToMulticallArrays_cairo1
4752
4752
  });
4753
4753
  var transformCallsToMulticallArrays = (calls) => {
4754
4754
  const callArray = [];
@@ -4782,6 +4782,27 @@ var fromCallsToExecuteCalldata = (calls) => {
4782
4782
  var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
4783
4783
  return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
4784
4784
  };
4785
+ var transformCallsToMulticallArrays_cairo1 = (calls) => {
4786
+ const callArray = calls.map((call) => ({
4787
+ to: toBigInt(call.contractAddress).toString(10),
4788
+ selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
4789
+ calldata: bigNumberishArrayToDecimalStringArray(call.calldata || [])
4790
+ }));
4791
+ return callArray;
4792
+ };
4793
+ var fromCallsToExecuteCalldata_cairo1 = (calls) => {
4794
+ const callArray = transformCallsToMulticallArrays_cairo1(calls);
4795
+ return [
4796
+ callArray.length.toString(),
4797
+ ...callArray.map(({ to, selector, calldata }) => [to, selector, calldata.length.toString(), ...calldata]).flat()
4798
+ ];
4799
+ };
4800
+ var getExecuteCalldata = (calls, cairoVersion = "0") => {
4801
+ if (cairoVersion === "1") {
4802
+ return fromCallsToExecuteCalldata_cairo1(calls);
4803
+ }
4804
+ return fromCallsToExecuteCalldata(calls);
4805
+ };
4785
4806
 
4786
4807
  // src/utils/typedData/index.ts
4787
4808
  var typedData_exports = {};
@@ -5008,7 +5029,7 @@ var Signer = class {
5008
5029
  if (abis && abis.length !== transactions.length) {
5009
5030
  throw new Error("ABI must be provided for each transaction or no transaction");
5010
5031
  }
5011
- const calldata = fromCallsToExecuteCalldata(transactions);
5032
+ const calldata = getExecuteCalldata(transactions, transactionsDetail.cairoVersion);
5012
5033
  const msgHash = calculateTransactionHash(
5013
5034
  transactionsDetail.walletAddress,
5014
5035
  transactionsDetail.version,
@@ -5099,7 +5120,7 @@ var Account = class extends Provider {
5099
5120
  async estimateFee(calls, estimateFeeDetails) {
5100
5121
  return this.estimateInvokeFee(calls, estimateFeeDetails);
5101
5122
  }
5102
- async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier, skipValidate } = {}) {
5123
+ async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier, skipValidate, cairoVersion } = {}) {
5103
5124
  const transactions = Array.isArray(calls) ? calls : [calls];
5104
5125
  const nonce = toBigInt(providedNonce ?? await this.getNonce());
5105
5126
  const version = toBigInt(feeTransactionVersion);
@@ -5109,7 +5130,8 @@ var Account = class extends Provider {
5109
5130
  nonce,
5110
5131
  maxFee: ZERO,
5111
5132
  version,
5112
- chainId
5133
+ chainId,
5134
+ cairoVersion: cairoVersion ?? "0"
5113
5135
  };
5114
5136
  const invocation = await this.buildInvocation(transactions, signerDetails);
5115
5137
  const response = await super.getInvokeEstimateFee(
@@ -5124,13 +5146,20 @@ var Account = class extends Provider {
5124
5146
  suggestedMaxFee
5125
5147
  };
5126
5148
  }
5127
- async estimateDeclareFee({ contract, classHash: providedClassHash, casm, compiledClassHash }, { blockIdentifier, nonce: providedNonce, skipValidate } = {}) {
5149
+ async estimateDeclareFee({ contract, classHash: providedClassHash, casm, compiledClassHash }, { blockIdentifier, nonce: providedNonce, skipValidate, cairoVersion } = {}) {
5128
5150
  const nonce = toBigInt(providedNonce ?? await this.getNonce());
5129
5151
  const version = !isSierra(contract) ? toBigInt(feeTransactionVersion) : transactionVersion_2;
5130
5152
  const chainId = await this.getChainId();
5131
5153
  const declareContractTransaction = await this.buildDeclarePayload(
5132
5154
  { classHash: providedClassHash, contract, casm, compiledClassHash },
5133
- { nonce, chainId, version, walletAddress: this.address, maxFee: ZERO }
5155
+ {
5156
+ nonce,
5157
+ chainId,
5158
+ version,
5159
+ walletAddress: this.address,
5160
+ maxFee: ZERO,
5161
+ cairoVersion: cairoVersion ?? "0"
5162
+ }
5134
5163
  );
5135
5164
  const response = await super.getDeclareEstimateFee(
5136
5165
  declareContractTransaction,
@@ -5149,13 +5178,20 @@ var Account = class extends Provider {
5149
5178
  addressSalt = 0,
5150
5179
  constructorCalldata = [],
5151
5180
  contractAddress: providedContractAddress
5152
- }, { blockIdentifier, skipValidate } = {}) {
5181
+ }, { blockIdentifier, skipValidate, cairoVersion } = {}) {
5153
5182
  const version = toBigInt(feeTransactionVersion);
5154
5183
  const nonce = ZERO;
5155
5184
  const chainId = await this.getChainId();
5156
5185
  const payload = await this.buildAccountDeployPayload(
5157
5186
  { classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress },
5158
- { nonce, chainId, version, walletAddress: this.address, maxFee: ZERO }
5187
+ {
5188
+ nonce,
5189
+ chainId,
5190
+ version,
5191
+ walletAddress: this.address,
5192
+ maxFee: ZERO,
5193
+ cairoVersion: cairoVersion ?? "0"
5194
+ }
5159
5195
  );
5160
5196
  const response = await super.getDeployAccountEstimateFee(
5161
5197
  { ...payload },
@@ -5173,7 +5209,7 @@ var Account = class extends Provider {
5173
5209
  const calls = this.buildUDCContractPayload(payload);
5174
5210
  return this.estimateInvokeFee(calls, transactionsDetail);
5175
5211
  }
5176
- async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier } = {}) {
5212
+ async estimateFeeBulk(transactions, { nonce: providedNonce, blockIdentifier, cairoVersion } = {}) {
5177
5213
  const nonce = toBigInt(providedNonce ?? await this.getNonce());
5178
5214
  const version = toBigInt(feeTransactionVersion);
5179
5215
  const chainId = await this.getChainId();
@@ -5184,7 +5220,8 @@ var Account = class extends Provider {
5184
5220
  nonce: toBigInt(Number(nonce) + index),
5185
5221
  maxFee: ZERO,
5186
5222
  version,
5187
- chainId
5223
+ chainId,
5224
+ cairoVersion: cairoVersion ?? "0"
5188
5225
  };
5189
5226
  const txPayload = transaction.payload;
5190
5227
  let res;
@@ -5242,7 +5279,7 @@ var Account = class extends Provider {
5242
5279
  });
5243
5280
  }
5244
5281
  async buildInvocation(call, signerDetails) {
5245
- const calldata = fromCallsToExecuteCalldata(call);
5282
+ const calldata = getExecuteCalldata(call, signerDetails.cairoVersion);
5246
5283
  const signature = await this.signer.signTransaction(call, signerDetails);
5247
5284
  return {
5248
5285
  contractAddress: this.address,
@@ -5259,15 +5296,17 @@ var Account = class extends Provider {
5259
5296
  );
5260
5297
  const version = toBigInt(transactionVersion);
5261
5298
  const chainId = await this.getChainId();
5299
+ const cairoVersion = transactionsDetail.cairoVersion ?? "0";
5262
5300
  const signerDetails = {
5263
5301
  walletAddress: this.address,
5264
5302
  nonce,
5265
5303
  maxFee,
5266
5304
  version,
5267
- chainId
5305
+ chainId,
5306
+ cairoVersion
5268
5307
  };
5269
5308
  const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
5270
- const calldata = fromCallsToExecuteCalldata(transactions);
5309
+ const calldata = getExecuteCalldata(transactions, cairoVersion);
5271
5310
  return this.invokeFunction(
5272
5311
  { contractAddress: this.address, calldata, signature },
5273
5312
  {
@@ -5292,7 +5331,8 @@ var Account = class extends Provider {
5292
5331
  details.chainId = await this.getChainId();
5293
5332
  const declareContractTransaction = await this.buildDeclarePayload(declareContractPayload, {
5294
5333
  ...details,
5295
- walletAddress: this.address
5334
+ walletAddress: this.address,
5335
+ cairoVersion: transactionsDetail.cairoVersion ?? "0"
5296
5336
  });
5297
5337
  return this.declareContract(declareContractTransaction, details);
5298
5338
  }
@@ -5433,7 +5473,7 @@ var Account = class extends Provider {
5433
5473
  feeEstimate = { suggestedMaxFee: ZERO, overall_fee: ZERO };
5434
5474
  break;
5435
5475
  }
5436
- return feeEstimate.suggestedMaxFee.toString();
5476
+ return feeEstimate.suggestedMaxFee;
5437
5477
  }
5438
5478
  async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
5439
5479
  const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
@@ -5501,7 +5541,7 @@ var Account = class extends Provider {
5501
5541
  });
5502
5542
  return calls;
5503
5543
  }
5504
- async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate } = {}) {
5544
+ async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate, cairoVersion } = {}) {
5505
5545
  const transactions = Array.isArray(calls) ? calls : [calls];
5506
5546
  const nonce = toBigInt(providedNonce ?? await this.getNonce());
5507
5547
  const version = toBigInt(feeTransactionVersion);
@@ -5511,7 +5551,8 @@ var Account = class extends Provider {
5511
5551
  nonce,
5512
5552
  maxFee: ZERO,
5513
5553
  version,
5514
- chainId
5554
+ chainId,
5555
+ cairoVersion: cairoVersion ?? "0"
5515
5556
  };
5516
5557
  const invocation = await this.buildInvocation(transactions, signerDetails);
5517
5558
  const response = await super.getSimulateTransaction(