starknet 5.8.0 → 5.9.1

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
@@ -43,9 +43,12 @@ var RPC;
43
43
  })(TransactionType2 = RPC2.TransactionType || (RPC2.TransactionType = {}));
44
44
  })(RPC || (RPC = {}));
45
45
 
46
- // src/utils/fetchPonyfill.ts
47
- import isomorphicFetch from "isomorphic-fetch";
48
- var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || isomorphicFetch;
46
+ // src/utils/assert.ts
47
+ function assert(condition, message) {
48
+ if (!condition) {
49
+ throw new Error(message || "Assertion failure");
50
+ }
51
+ }
49
52
 
50
53
  // src/utils/hash.ts
51
54
  var hash_exports = {};
@@ -2271,15 +2274,6 @@ __export(num_exports, {
2271
2274
  toHexString: () => toHexString
2272
2275
  });
2273
2276
  import { hexToBytes as hexToBytesNoble } from "@noble/curves/abstract/utils";
2274
-
2275
- // src/utils/assert.ts
2276
- function assert(condition, message) {
2277
- if (!condition) {
2278
- throw new Error(message || "Assertion failure");
2279
- }
2280
- }
2281
-
2282
- // src/utils/num.ts
2283
2277
  function isHex(hex) {
2284
2278
  return /^0x[0-9a-f]*$/i.test(hex);
2285
2279
  }
@@ -2743,185 +2737,6 @@ function computeContractClassHash(contract) {
2743
2737
  return computeLegacyContractClassHash(compiledContract);
2744
2738
  }
2745
2739
 
2746
- // src/utils/contract.ts
2747
- function isSierra(contract) {
2748
- const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
2749
- return "sierra_program" in compiledContract;
2750
- }
2751
- function extractContractHashes(payload) {
2752
- const response = { ...payload };
2753
- if (isSierra(payload.contract)) {
2754
- if (!payload.compiledClassHash && payload.casm) {
2755
- response.compiledClassHash = computeCompiledClassHash(payload.casm);
2756
- }
2757
- if (!response.compiledClassHash)
2758
- throw new Error(
2759
- "Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
2760
- );
2761
- }
2762
- response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
2763
- if (!response.classHash)
2764
- throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
2765
- return response;
2766
- }
2767
-
2768
- // src/utils/stark.ts
2769
- var stark_exports = {};
2770
- __export(stark_exports, {
2771
- compressProgram: () => compressProgram,
2772
- estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
2773
- formatSignature: () => formatSignature,
2774
- makeAddress: () => makeAddress,
2775
- randomAddress: () => randomAddress,
2776
- signatureToDecimalArray: () => signatureToDecimalArray,
2777
- signatureToHexArray: () => signatureToHexArray
2778
- });
2779
- import { getStarkKey, utils } from "micro-starknet";
2780
- import { gzip } from "pako";
2781
- function compressProgram(jsonProgram) {
2782
- const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
2783
- const compressedProgram = gzip(stringified);
2784
- return btoaUniversal(compressedProgram);
2785
- }
2786
- function randomAddress() {
2787
- const randomKeyPair = utils.randomPrivateKey();
2788
- return getStarkKey(randomKeyPair);
2789
- }
2790
- function makeAddress(input) {
2791
- return addHexPrefix(input).toLowerCase();
2792
- }
2793
- function formatSignature(sig) {
2794
- if (!sig)
2795
- throw Error("formatSignature: provided signature is undefined");
2796
- if (Array.isArray(sig)) {
2797
- return sig.map((it) => toHex(it));
2798
- }
2799
- try {
2800
- const { r, s } = sig;
2801
- return [toHex(r), toHex(s)];
2802
- } catch (e) {
2803
- throw new Error("Signature need to be weierstrass.SignatureType or an array for custom");
2804
- }
2805
- }
2806
- function signatureToDecimalArray(sig) {
2807
- return bigNumberishArrayToDecimalStringArray(formatSignature(sig));
2808
- }
2809
- function signatureToHexArray(sig) {
2810
- return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
2811
- }
2812
- function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
2813
- const overHeadPercent = Math.round((1 + overhead) * 100);
2814
- return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
2815
- }
2816
-
2817
- // src/utils/provider.ts
2818
- function wait(delay) {
2819
- return new Promise((res) => {
2820
- setTimeout(res, delay);
2821
- });
2822
- }
2823
- function parseCalldata(calldata = []) {
2824
- return calldata.map((data) => {
2825
- if (typeof data === "string" && isHex(data)) {
2826
- return data;
2827
- }
2828
- return toHex(data);
2829
- });
2830
- }
2831
- function createSierraContractClass(contract) {
2832
- const result = { ...contract };
2833
- delete result.sierra_program_debug_info;
2834
- result.abi = formatSpaces(stringify2(contract.abi));
2835
- result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
2836
- result.sierra_program = compressProgram(result.sierra_program);
2837
- return result;
2838
- }
2839
- function parseContract(contract) {
2840
- const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
2841
- if (!isSierra(contract)) {
2842
- return {
2843
- ...parsedContract,
2844
- ..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
2845
- };
2846
- }
2847
- return createSierraContractClass(parsedContract);
2848
- }
2849
-
2850
- // src/utils/responseParser/rpc.ts
2851
- var RPCResponseParser = class {
2852
- parseGetBlockResponse(res) {
2853
- return {
2854
- timestamp: res.timestamp,
2855
- block_hash: res.block_hash,
2856
- block_number: res.block_number,
2857
- new_root: res.new_root,
2858
- parent_hash: res.parent_hash,
2859
- status: res.status,
2860
- transactions: res.transactions
2861
- };
2862
- }
2863
- parseGetTransactionResponse(res) {
2864
- return {
2865
- calldata: res.calldata || [],
2866
- contract_address: res.contract_address,
2867
- sender_address: res.contract_address,
2868
- max_fee: res.max_fee,
2869
- nonce: res.nonce,
2870
- signature: res.signature || [],
2871
- transaction_hash: res.transaction_hash,
2872
- version: res.version
2873
- };
2874
- }
2875
- parseFeeEstimateResponse(res) {
2876
- return {
2877
- overall_fee: toBigInt(res.overall_fee),
2878
- gas_consumed: toBigInt(res.gas_consumed),
2879
- gas_price: toBigInt(res.gas_price)
2880
- };
2881
- }
2882
- parseCallContractResponse(res) {
2883
- return {
2884
- result: res
2885
- };
2886
- }
2887
- };
2888
-
2889
- // src/provider/errors.ts
2890
- function fixStack(target, fn = target.constructor) {
2891
- const { captureStackTrace } = Error;
2892
- captureStackTrace && captureStackTrace(target, fn);
2893
- }
2894
- function fixProto(target, prototype) {
2895
- const { setPrototypeOf } = Object;
2896
- setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
2897
- }
2898
- var CustomError = class extends Error {
2899
- constructor(message) {
2900
- super(message);
2901
- Object.defineProperty(this, "name", {
2902
- value: new.target.name,
2903
- enumerable: false,
2904
- configurable: true
2905
- });
2906
- fixProto(this, new.target.prototype);
2907
- fixStack(this);
2908
- }
2909
- };
2910
- var LibraryError = class extends CustomError {
2911
- };
2912
- var GatewayError = class extends LibraryError {
2913
- constructor(message, errorCode) {
2914
- super(message);
2915
- this.errorCode = errorCode;
2916
- }
2917
- };
2918
- var HttpError = class extends LibraryError {
2919
- constructor(message, errorCode) {
2920
- super(message);
2921
- this.errorCode = errorCode;
2922
- }
2923
- };
2924
-
2925
2740
  // src/utils/calldata/formatter.ts
2926
2741
  var guard = {
2927
2742
  isBN: (data, type, key) => {
@@ -3039,6 +2854,15 @@ function extractTupleMemberTypes(type) {
3039
2854
  }
3040
2855
 
3041
2856
  // src/utils/calldata/requestParser.ts
2857
+ function parseBaseTypes(type, val) {
2858
+ switch (true) {
2859
+ case isTypeUint256(type):
2860
+ const el_uint256 = uint256(val);
2861
+ return [felt(el_uint256.low), felt(el_uint256.high)];
2862
+ default:
2863
+ return felt(val);
2864
+ }
2865
+ }
3042
2866
  function parseTuple(element, typeStr) {
3043
2867
  const memberTypes = extractTupleMemberTypes(typeStr);
3044
2868
  const elements = Object.values(element);
@@ -3063,10 +2887,6 @@ function parseCalldataValue(element, type, structs) {
3063
2887
  if (Array.isArray(element)) {
3064
2888
  throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
3065
2889
  }
3066
- if (isTypeUint256(type)) {
3067
- const el_uint256 = uint256(element);
3068
- return [felt(el_uint256.low), felt(el_uint256.high)];
3069
- }
3070
2890
  if (structs[type] && structs[type].members.length) {
3071
2891
  const { members } = structs[type];
3072
2892
  const subElement = element;
@@ -3084,7 +2904,7 @@ function parseCalldataValue(element, type, structs) {
3084
2904
  if (typeof element === "object") {
3085
2905
  throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
3086
2906
  }
3087
- return felt(element);
2907
+ return parseBaseTypes(type, element);
3088
2908
  }
3089
2909
  function parseCalldataField(argsIterator, input, structs) {
3090
2910
  const { name, type } = input;
@@ -3101,25 +2921,42 @@ function parseCalldataField(argsIterator, input, structs) {
3101
2921
  result.push(felt(value.length));
3102
2922
  const arrayType = getArrayType(input.type);
3103
2923
  return value.reduce((acc, el) => {
3104
- if (isTypeFelt(arrayType) || isTypeUint(arrayType) || isTypeContractAddress(arrayType)) {
3105
- acc.push(felt(el));
3106
- } else if (isTypeBool(arrayType) && typeof el === "boolean") {
3107
- acc.push(el.toString());
3108
- } else {
2924
+ if (isTypeStruct(arrayType, structs) || isTypeTuple(arrayType) || isTypeArray(arrayType)) {
3109
2925
  acc.push(...parseCalldataValue(el, arrayType, structs));
2926
+ } else {
2927
+ return acc.concat(parseBaseTypes(arrayType, el));
3110
2928
  }
3111
2929
  return acc;
3112
2930
  }, result);
3113
- case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
2931
+ case (isTypeStruct(type, structs) || isTypeTuple(type)):
3114
2932
  return parseCalldataValue(value, type, structs);
3115
- case isTypeBool(type):
3116
- return `${+value}`;
2933
+ case isTypeUint256(type):
2934
+ if (typeof value === "object") {
2935
+ return [felt(value.low), felt(value.high)];
2936
+ }
2937
+ const el_uint256 = uint256(value);
2938
+ return [felt(el_uint256.low), felt(el_uint256.high)];
3117
2939
  default:
3118
- return felt(value);
2940
+ return parseBaseTypes(type, value);
3119
2941
  }
3120
2942
  }
3121
2943
 
3122
2944
  // src/utils/calldata/responseParser.ts
2945
+ function parseBaseTypes2(type, it) {
2946
+ let temp;
2947
+ switch (true) {
2948
+ case isTypeBool(type):
2949
+ temp = it.next().value;
2950
+ return Boolean(BigInt(temp));
2951
+ case isTypeUint256(type):
2952
+ const low = it.next().value;
2953
+ const high = it.next().value;
2954
+ return uint256ToBN({ low, high });
2955
+ default:
2956
+ temp = it.next().value;
2957
+ return BigInt(temp);
2958
+ }
2959
+ }
3123
2960
  function parseResponseStruct(responseIterator, type, structs) {
3124
2961
  if (type in structs && structs[type]) {
3125
2962
  return structs[type].members.reduce((acc, el) => {
@@ -3136,8 +2973,7 @@ function parseResponseStruct(responseIterator, type, structs) {
3136
2973
  return acc;
3137
2974
  }, {});
3138
2975
  }
3139
- const temp = responseIterator.next().value;
3140
- return BigInt(temp);
2976
+ return parseBaseTypes2(type, responseIterator);
3141
2977
  }
3142
2978
  function responseParser(responseIterator, output, structs, parsedResult) {
3143
2979
  const { name, type } = output;
@@ -3146,21 +2982,13 @@ function responseParser(responseIterator, output, structs, parsedResult) {
3146
2982
  case isLen(name):
3147
2983
  temp = responseIterator.next().value;
3148
2984
  return BigInt(temp);
3149
- case isTypeBool(type):
3150
- temp = responseIterator.next().value;
3151
- return Boolean(BigInt(temp));
3152
- case isTypeUint256(type):
3153
- const low = responseIterator.next().value;
3154
- const high = responseIterator.next().value;
3155
- return uint256ToBN({ low, high });
3156
2985
  case isTypeArray(type):
3157
2986
  const parsedDataArr = [];
3158
2987
  if (isCairo1Type(type)) {
3159
- responseIterator.next();
3160
- let it = responseIterator.next();
3161
- while (!it.done) {
3162
- parsedDataArr.push(BigInt(it.value));
3163
- it = responseIterator.next();
2988
+ const arrayType = getArrayType(type);
2989
+ const len = BigInt(responseIterator.next().value);
2990
+ while (parsedDataArr.length < len) {
2991
+ parsedDataArr.push(parseResponseStruct(responseIterator, arrayType, structs));
3164
2992
  }
3165
2993
  return parsedDataArr;
3166
2994
  }
@@ -3176,8 +3004,7 @@ function responseParser(responseIterator, output, structs, parsedResult) {
3176
3004
  case (type in structs || isTypeTuple(type)):
3177
3005
  return parseResponseStruct(responseIterator, type, structs);
3178
3006
  default:
3179
- temp = responseIterator.next().value;
3180
- return BigInt(temp);
3007
+ return parseBaseTypes2(type, responseIterator);
3181
3008
  }
3182
3009
  }
3183
3010
 
@@ -3196,10 +3023,10 @@ var validateUint = (parameter, input) => {
3196
3023
  );
3197
3024
  }
3198
3025
  assert(
3199
- typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
3200
- `Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt)`
3026
+ typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint" || typeof parameter === "object" && "low" in parameter && "high" in parameter,
3027
+ `Validate: arg ${input.name} of cairo ZORG type ${input.type} should be type (String, Number or BigInt)`
3201
3028
  );
3202
- const param = toBigInt(parameter);
3029
+ const param = typeof parameter === "object" ? uint256ToBN(parameter) : toBigInt(parameter);
3203
3030
  switch (input.type) {
3204
3031
  case "core::integer::u8" /* u8 */:
3205
3032
  assert(
@@ -3375,6 +3202,8 @@ var CallData = class {
3375
3202
  let value = v;
3376
3203
  if (isLongText(value))
3377
3204
  value = splitLongString(value);
3205
+ if (k === "entrypoint")
3206
+ value = getSelectorFromName(value);
3378
3207
  const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
3379
3208
  if (isBigInt(value))
3380
3209
  return [[`${prefix}${kk}`, felt(value)]];
@@ -3428,6 +3257,188 @@ var CallData = class {
3428
3257
  {}
3429
3258
  );
3430
3259
  }
3260
+ static toCalldata(rawCalldata = []) {
3261
+ return CallData.compile(rawCalldata);
3262
+ }
3263
+ static toHex(rawCalldata = []) {
3264
+ const calldata = CallData.compile(rawCalldata);
3265
+ return calldata.map((it) => toHex(it));
3266
+ }
3267
+ };
3268
+
3269
+ // src/utils/fetchPonyfill.ts
3270
+ import isomorphicFetch from "isomorphic-fetch";
3271
+ var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || isomorphicFetch;
3272
+
3273
+ // src/utils/contract.ts
3274
+ function isSierra(contract) {
3275
+ const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
3276
+ return "sierra_program" in compiledContract;
3277
+ }
3278
+ function extractContractHashes(payload) {
3279
+ const response = { ...payload };
3280
+ if (isSierra(payload.contract)) {
3281
+ if (!payload.compiledClassHash && payload.casm) {
3282
+ response.compiledClassHash = computeCompiledClassHash(payload.casm);
3283
+ }
3284
+ if (!response.compiledClassHash)
3285
+ throw new Error(
3286
+ "Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
3287
+ );
3288
+ }
3289
+ response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
3290
+ if (!response.classHash)
3291
+ throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
3292
+ return response;
3293
+ }
3294
+
3295
+ // src/utils/stark.ts
3296
+ var stark_exports = {};
3297
+ __export(stark_exports, {
3298
+ compressProgram: () => compressProgram,
3299
+ estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
3300
+ formatSignature: () => formatSignature,
3301
+ makeAddress: () => makeAddress,
3302
+ randomAddress: () => randomAddress,
3303
+ signatureToDecimalArray: () => signatureToDecimalArray,
3304
+ signatureToHexArray: () => signatureToHexArray
3305
+ });
3306
+ import { getStarkKey, utils } from "micro-starknet";
3307
+ import { gzip } from "pako";
3308
+ function compressProgram(jsonProgram) {
3309
+ const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
3310
+ const compressedProgram = gzip(stringified);
3311
+ return btoaUniversal(compressedProgram);
3312
+ }
3313
+ function randomAddress() {
3314
+ const randomKeyPair = utils.randomPrivateKey();
3315
+ return getStarkKey(randomKeyPair);
3316
+ }
3317
+ function makeAddress(input) {
3318
+ return addHexPrefix(input).toLowerCase();
3319
+ }
3320
+ function formatSignature(sig) {
3321
+ if (!sig)
3322
+ throw Error("formatSignature: provided signature is undefined");
3323
+ if (Array.isArray(sig)) {
3324
+ return sig.map((it) => toHex(it));
3325
+ }
3326
+ try {
3327
+ const { r, s } = sig;
3328
+ return [toHex(r), toHex(s)];
3329
+ } catch (e) {
3330
+ throw new Error("Signature need to be weierstrass.SignatureType or an array for custom");
3331
+ }
3332
+ }
3333
+ function signatureToDecimalArray(sig) {
3334
+ return bigNumberishArrayToDecimalStringArray(formatSignature(sig));
3335
+ }
3336
+ function signatureToHexArray(sig) {
3337
+ return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
3338
+ }
3339
+ function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
3340
+ const overHeadPercent = Math.round((1 + overhead) * 100);
3341
+ return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
3342
+ }
3343
+
3344
+ // src/utils/provider.ts
3345
+ function wait(delay) {
3346
+ return new Promise((res) => {
3347
+ setTimeout(res, delay);
3348
+ });
3349
+ }
3350
+ function createSierraContractClass(contract) {
3351
+ const result = { ...contract };
3352
+ delete result.sierra_program_debug_info;
3353
+ result.abi = formatSpaces(stringify2(contract.abi));
3354
+ result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
3355
+ result.sierra_program = compressProgram(result.sierra_program);
3356
+ return result;
3357
+ }
3358
+ function parseContract(contract) {
3359
+ const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
3360
+ if (!isSierra(contract)) {
3361
+ return {
3362
+ ...parsedContract,
3363
+ ..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
3364
+ };
3365
+ }
3366
+ return createSierraContractClass(parsedContract);
3367
+ }
3368
+
3369
+ // src/utils/responseParser/rpc.ts
3370
+ var RPCResponseParser = class {
3371
+ parseGetBlockResponse(res) {
3372
+ return {
3373
+ timestamp: res.timestamp,
3374
+ block_hash: res.block_hash,
3375
+ block_number: res.block_number,
3376
+ new_root: res.new_root,
3377
+ parent_hash: res.parent_hash,
3378
+ status: res.status,
3379
+ transactions: res.transactions
3380
+ };
3381
+ }
3382
+ parseGetTransactionResponse(res) {
3383
+ return {
3384
+ calldata: res.calldata || [],
3385
+ contract_address: res.contract_address,
3386
+ sender_address: res.contract_address,
3387
+ max_fee: res.max_fee,
3388
+ nonce: res.nonce,
3389
+ signature: res.signature || [],
3390
+ transaction_hash: res.transaction_hash,
3391
+ version: res.version
3392
+ };
3393
+ }
3394
+ parseFeeEstimateResponse(res) {
3395
+ return {
3396
+ overall_fee: toBigInt(res.overall_fee),
3397
+ gas_consumed: toBigInt(res.gas_consumed),
3398
+ gas_price: toBigInt(res.gas_price)
3399
+ };
3400
+ }
3401
+ parseCallContractResponse(res) {
3402
+ return {
3403
+ result: res
3404
+ };
3405
+ }
3406
+ };
3407
+
3408
+ // src/provider/errors.ts
3409
+ function fixStack(target, fn = target.constructor) {
3410
+ const { captureStackTrace } = Error;
3411
+ captureStackTrace && captureStackTrace(target, fn);
3412
+ }
3413
+ function fixProto(target, prototype) {
3414
+ const { setPrototypeOf } = Object;
3415
+ setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
3416
+ }
3417
+ var CustomError = class extends Error {
3418
+ constructor(message) {
3419
+ super(message);
3420
+ Object.defineProperty(this, "name", {
3421
+ value: new.target.name,
3422
+ enumerable: false,
3423
+ configurable: true
3424
+ });
3425
+ fixProto(this, new.target.prototype);
3426
+ fixStack(this);
3427
+ }
3428
+ };
3429
+ var LibraryError = class extends CustomError {
3430
+ };
3431
+ var GatewayError = class extends LibraryError {
3432
+ constructor(message, errorCode) {
3433
+ super(message);
3434
+ this.errorCode = errorCode;
3435
+ }
3436
+ };
3437
+ var HttpError = class extends LibraryError {
3438
+ constructor(message, errorCode) {
3439
+ super(message);
3440
+ this.errorCode = errorCode;
3441
+ }
3431
3442
  };
3432
3443
 
3433
3444
  // src/utils/starknetId.ts
@@ -3760,7 +3771,7 @@ var RpcProvider = class {
3760
3771
  request: {
3761
3772
  type: RPC.TransactionType.INVOKE,
3762
3773
  sender_address: invocation.contractAddress,
3763
- calldata: parseCalldata(invocation.calldata),
3774
+ calldata: CallData.toHex(invocation.calldata),
3764
3775
  signature: signatureToHexArray(invocation.signature),
3765
3776
  version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 0),
3766
3777
  nonce: toHex(invocationDetails.nonce),
@@ -3848,7 +3859,7 @@ var RpcProvider = class {
3848
3859
  return this.fetchEndpoint("starknet_addInvokeTransaction", {
3849
3860
  invoke_transaction: {
3850
3861
  sender_address: functionInvocation.contractAddress,
3851
- calldata: parseCalldata(functionInvocation.calldata),
3862
+ calldata: CallData.toHex(functionInvocation.calldata),
3852
3863
  type: RPC.TransactionType.INVOKE,
3853
3864
  max_fee: toHex(details.maxFee || 0),
3854
3865
  version: "0x1",
@@ -3863,7 +3874,7 @@ var RpcProvider = class {
3863
3874
  request: {
3864
3875
  contract_address: call.contractAddress,
3865
3876
  entry_point_selector: getSelectorFromName(call.entrypoint),
3866
- calldata: parseCalldata(call.calldata)
3877
+ calldata: CallData.toHex(call.calldata)
3867
3878
  },
3868
3879
  block_id
3869
3880
  });
@@ -4333,7 +4344,7 @@ var SequencerProvider = class {
4333
4344
  return this.fetchEndpoint("add_transaction", void 0, {
4334
4345
  type: "INVOKE_FUNCTION" /* INVOKE */,
4335
4346
  sender_address: functionInvocation.contractAddress,
4336
- calldata: bigNumberishArrayToDecimalStringArray(functionInvocation.calldata ?? []),
4347
+ calldata: CallData.compile(functionInvocation.calldata ?? []),
4337
4348
  signature: signatureToDecimalArray(functionInvocation.signature),
4338
4349
  nonce: toHex(details.nonce),
4339
4350
  max_fee: toHex(details.maxFee || 0),
@@ -4344,7 +4355,7 @@ var SequencerProvider = class {
4344
4355
  return this.fetchEndpoint("add_transaction", void 0, {
4345
4356
  type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
4346
4357
  contract_address_salt: addressSalt ?? randomAddress(),
4347
- constructor_calldata: bigNumberishArrayToDecimalStringArray(constructorCalldata ?? []),
4358
+ constructor_calldata: CallData.compile(constructorCalldata ?? []),
4348
4359
  class_hash: toHex(classHash),
4349
4360
  max_fee: toHex(details.maxFee || 0),
4350
4361
  version: toHex(details.version || 0),
@@ -4428,7 +4439,7 @@ var SequencerProvider = class {
4428
4439
  {
4429
4440
  type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
4430
4441
  class_hash: toHex(classHash),
4431
- constructor_calldata: bigNumberishArrayToDecimalStringArray(constructorCalldata || []),
4442
+ constructor_calldata: CallData.compile(constructorCalldata || []),
4432
4443
  contract_address_salt: toHex(addressSalt || 0),
4433
4444
  signature: signatureToDecimalArray(signature),
4434
4445
  version: toHex((details == null ? void 0 : details.version) || 0),
@@ -4455,9 +4466,7 @@ var SequencerProvider = class {
4455
4466
  res = {
4456
4467
  type: invocation.type,
4457
4468
  class_hash: toHex(toBigInt(invocation.classHash)),
4458
- constructor_calldata: bigNumberishArrayToDecimalStringArray(
4459
- invocation.constructorCalldata || []
4460
- ),
4469
+ constructor_calldata: CallData.compile(invocation.constructorCalldata || []),
4461
4470
  contract_address_salt: toHex(toBigInt(invocation.addressSalt || 0))
4462
4471
  };
4463
4472
  }
@@ -4952,19 +4961,13 @@ var transformCallsToMulticallArrays = (calls) => {
4952
4961
  });
4953
4962
  return {
4954
4963
  callArray,
4955
- calldata: bigNumberishArrayToDecimalStringArray(calldata)
4964
+ calldata: CallData.compile({ calldata })
4956
4965
  };
4957
4966
  };
4958
4967
  var fromCallsToExecuteCalldata = (calls) => {
4959
4968
  const { callArray, calldata } = transformCallsToMulticallArrays(calls);
4960
- return [
4961
- callArray.length.toString(),
4962
- ...callArray.map(
4963
- ({ to, selector, data_offset, data_len }) => [to, selector, data_offset, data_len]
4964
- ).flat(),
4965
- calldata.length.toString(),
4966
- ...calldata
4967
- ];
4969
+ const compiledCalls = CallData.compile({ callArray });
4970
+ return [...compiledCalls, ...calldata];
4968
4971
  };
4969
4972
  var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
4970
4973
  return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
@@ -4973,20 +4976,16 @@ var transformCallsToMulticallArrays_cairo1 = (calls) => {
4973
4976
  const callArray = calls.map((call) => ({
4974
4977
  to: toBigInt(call.contractAddress).toString(10),
4975
4978
  selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
4976
- calldata: bigNumberishArrayToDecimalStringArray(call.calldata || [])
4979
+ calldata: CallData.compile(call.calldata || [])
4977
4980
  }));
4978
4981
  return callArray;
4979
4982
  };
4980
4983
  var fromCallsToExecuteCalldata_cairo1 = (calls) => {
4981
- const callArray = transformCallsToMulticallArrays_cairo1(calls);
4982
- return [
4983
- callArray.length.toString(),
4984
- ...callArray.map(({ to, selector, calldata }) => [to, selector, calldata.length.toString(), ...calldata]).flat()
4985
- ];
4984
+ return CallData.compile({ calls });
4986
4985
  };
4987
4986
  var getExecuteCalldata = (calls, cairoVersion = "0") => {
4988
4987
  if (cairoVersion === "1") {
4989
- return fromCallsToExecuteCalldata_cairo1(calls);
4988
+ return CallData.compile({ calls });
4990
4989
  }
4991
4990
  return fromCallsToExecuteCalldata(calls);
4992
4991
  };
@@ -5592,7 +5591,8 @@ var Account = class extends Provider {
5592
5591
  const version = toBigInt(transactionVersion);
5593
5592
  const nonce = ZERO;
5594
5593
  const chainId = await this.getChainId();
5595
- const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
5594
+ const compiledCalldata = CallData.compile(constructorCalldata);
5595
+ const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
5596
5596
  const maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
5597
5597
  {
5598
5598
  type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
@@ -5690,7 +5690,8 @@ var Account = class extends Provider {
5690
5690
  constructorCalldata = [],
5691
5691
  contractAddress: providedContractAddress
5692
5692
  }, { nonce, chainId, version, maxFee }) {
5693
- const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
5693
+ const compiledCalldata = CallData.compile(constructorCalldata);
5694
+ const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
5694
5695
  const signature = await this.signer.signDeployAccountTransaction({
5695
5696
  classHash,
5696
5697
  contractAddress,