starknet 5.8.0 → 5.9.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
@@ -114,9 +114,12 @@ var RPC;
114
114
  })(TransactionType2 = RPC2.TransactionType || (RPC2.TransactionType = {}));
115
115
  })(RPC || (RPC = {}));
116
116
 
117
- // src/utils/fetchPonyfill.ts
118
- var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
119
- var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || import_isomorphic_fetch.default;
117
+ // src/utils/assert.ts
118
+ function assert(condition, message) {
119
+ if (!condition) {
120
+ throw new Error(message || "Assertion failure");
121
+ }
122
+ }
120
123
 
121
124
  // src/utils/hash.ts
122
125
  var hash_exports = {};
@@ -2342,15 +2345,6 @@ __export(num_exports, {
2342
2345
  toHexString: () => toHexString
2343
2346
  });
2344
2347
  var import_utils = require("@noble/curves/abstract/utils");
2345
-
2346
- // src/utils/assert.ts
2347
- function assert(condition, message) {
2348
- if (!condition) {
2349
- throw new Error(message || "Assertion failure");
2350
- }
2351
- }
2352
-
2353
- // src/utils/num.ts
2354
2348
  function isHex(hex) {
2355
2349
  return /^0x[0-9a-f]*$/i.test(hex);
2356
2350
  }
@@ -2814,185 +2808,6 @@ function computeContractClassHash(contract) {
2814
2808
  return computeLegacyContractClassHash(compiledContract);
2815
2809
  }
2816
2810
 
2817
- // src/utils/contract.ts
2818
- function isSierra(contract) {
2819
- const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
2820
- return "sierra_program" in compiledContract;
2821
- }
2822
- function extractContractHashes(payload) {
2823
- const response = { ...payload };
2824
- if (isSierra(payload.contract)) {
2825
- if (!payload.compiledClassHash && payload.casm) {
2826
- response.compiledClassHash = computeCompiledClassHash(payload.casm);
2827
- }
2828
- if (!response.compiledClassHash)
2829
- throw new Error(
2830
- "Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
2831
- );
2832
- }
2833
- response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
2834
- if (!response.classHash)
2835
- throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
2836
- return response;
2837
- }
2838
-
2839
- // src/utils/stark.ts
2840
- var stark_exports = {};
2841
- __export(stark_exports, {
2842
- compressProgram: () => compressProgram,
2843
- estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
2844
- formatSignature: () => formatSignature,
2845
- makeAddress: () => makeAddress,
2846
- randomAddress: () => randomAddress,
2847
- signatureToDecimalArray: () => signatureToDecimalArray,
2848
- signatureToHexArray: () => signatureToHexArray
2849
- });
2850
- var import_micro_starknet2 = require("micro-starknet");
2851
- var import_pako = require("pako");
2852
- function compressProgram(jsonProgram) {
2853
- const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
2854
- const compressedProgram = (0, import_pako.gzip)(stringified);
2855
- return btoaUniversal(compressedProgram);
2856
- }
2857
- function randomAddress() {
2858
- const randomKeyPair = import_micro_starknet2.utils.randomPrivateKey();
2859
- return (0, import_micro_starknet2.getStarkKey)(randomKeyPair);
2860
- }
2861
- function makeAddress(input) {
2862
- return addHexPrefix(input).toLowerCase();
2863
- }
2864
- function formatSignature(sig) {
2865
- if (!sig)
2866
- throw Error("formatSignature: provided signature is undefined");
2867
- if (Array.isArray(sig)) {
2868
- return sig.map((it) => toHex(it));
2869
- }
2870
- try {
2871
- const { r, s } = sig;
2872
- return [toHex(r), toHex(s)];
2873
- } catch (e) {
2874
- throw new Error("Signature need to be weierstrass.SignatureType or an array for custom");
2875
- }
2876
- }
2877
- function signatureToDecimalArray(sig) {
2878
- return bigNumberishArrayToDecimalStringArray(formatSignature(sig));
2879
- }
2880
- function signatureToHexArray(sig) {
2881
- return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
2882
- }
2883
- function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
2884
- const overHeadPercent = Math.round((1 + overhead) * 100);
2885
- return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
2886
- }
2887
-
2888
- // src/utils/provider.ts
2889
- function wait(delay) {
2890
- return new Promise((res) => {
2891
- setTimeout(res, delay);
2892
- });
2893
- }
2894
- function parseCalldata(calldata = []) {
2895
- return calldata.map((data) => {
2896
- if (typeof data === "string" && isHex(data)) {
2897
- return data;
2898
- }
2899
- return toHex(data);
2900
- });
2901
- }
2902
- function createSierraContractClass(contract) {
2903
- const result = { ...contract };
2904
- delete result.sierra_program_debug_info;
2905
- result.abi = formatSpaces(stringify2(contract.abi));
2906
- result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
2907
- result.sierra_program = compressProgram(result.sierra_program);
2908
- return result;
2909
- }
2910
- function parseContract(contract) {
2911
- const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
2912
- if (!isSierra(contract)) {
2913
- return {
2914
- ...parsedContract,
2915
- ..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
2916
- };
2917
- }
2918
- return createSierraContractClass(parsedContract);
2919
- }
2920
-
2921
- // src/utils/responseParser/rpc.ts
2922
- var RPCResponseParser = class {
2923
- parseGetBlockResponse(res) {
2924
- return {
2925
- timestamp: res.timestamp,
2926
- block_hash: res.block_hash,
2927
- block_number: res.block_number,
2928
- new_root: res.new_root,
2929
- parent_hash: res.parent_hash,
2930
- status: res.status,
2931
- transactions: res.transactions
2932
- };
2933
- }
2934
- parseGetTransactionResponse(res) {
2935
- return {
2936
- calldata: res.calldata || [],
2937
- contract_address: res.contract_address,
2938
- sender_address: res.contract_address,
2939
- max_fee: res.max_fee,
2940
- nonce: res.nonce,
2941
- signature: res.signature || [],
2942
- transaction_hash: res.transaction_hash,
2943
- version: res.version
2944
- };
2945
- }
2946
- parseFeeEstimateResponse(res) {
2947
- return {
2948
- overall_fee: toBigInt(res.overall_fee),
2949
- gas_consumed: toBigInt(res.gas_consumed),
2950
- gas_price: toBigInt(res.gas_price)
2951
- };
2952
- }
2953
- parseCallContractResponse(res) {
2954
- return {
2955
- result: res
2956
- };
2957
- }
2958
- };
2959
-
2960
- // src/provider/errors.ts
2961
- function fixStack(target, fn = target.constructor) {
2962
- const { captureStackTrace } = Error;
2963
- captureStackTrace && captureStackTrace(target, fn);
2964
- }
2965
- function fixProto(target, prototype) {
2966
- const { setPrototypeOf } = Object;
2967
- setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
2968
- }
2969
- var CustomError = class extends Error {
2970
- constructor(message) {
2971
- super(message);
2972
- Object.defineProperty(this, "name", {
2973
- value: new.target.name,
2974
- enumerable: false,
2975
- configurable: true
2976
- });
2977
- fixProto(this, new.target.prototype);
2978
- fixStack(this);
2979
- }
2980
- };
2981
- var LibraryError = class extends CustomError {
2982
- };
2983
- var GatewayError = class extends LibraryError {
2984
- constructor(message, errorCode) {
2985
- super(message);
2986
- this.errorCode = errorCode;
2987
- }
2988
- };
2989
- var HttpError = class extends LibraryError {
2990
- constructor(message, errorCode) {
2991
- super(message);
2992
- this.errorCode = errorCode;
2993
- }
2994
- };
2995
-
2996
2811
  // src/utils/calldata/formatter.ts
2997
2812
  var guard = {
2998
2813
  isBN: (data, type, key) => {
@@ -3110,6 +2925,15 @@ function extractTupleMemberTypes(type) {
3110
2925
  }
3111
2926
 
3112
2927
  // src/utils/calldata/requestParser.ts
2928
+ function parseBaseTypes(type, val) {
2929
+ switch (true) {
2930
+ case isTypeUint256(type):
2931
+ const el_uint256 = uint256(val);
2932
+ return [felt(el_uint256.low), felt(el_uint256.high)];
2933
+ default:
2934
+ return felt(val);
2935
+ }
2936
+ }
3113
2937
  function parseTuple(element, typeStr) {
3114
2938
  const memberTypes = extractTupleMemberTypes(typeStr);
3115
2939
  const elements = Object.values(element);
@@ -3134,10 +2958,6 @@ function parseCalldataValue(element, type, structs) {
3134
2958
  if (Array.isArray(element)) {
3135
2959
  throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
3136
2960
  }
3137
- if (isTypeUint256(type)) {
3138
- const el_uint256 = uint256(element);
3139
- return [felt(el_uint256.low), felt(el_uint256.high)];
3140
- }
3141
2961
  if (structs[type] && structs[type].members.length) {
3142
2962
  const { members } = structs[type];
3143
2963
  const subElement = element;
@@ -3155,7 +2975,7 @@ function parseCalldataValue(element, type, structs) {
3155
2975
  if (typeof element === "object") {
3156
2976
  throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
3157
2977
  }
3158
- return felt(element);
2978
+ return parseBaseTypes(type, element);
3159
2979
  }
3160
2980
  function parseCalldataField(argsIterator, input, structs) {
3161
2981
  const { name, type } = input;
@@ -3172,25 +2992,36 @@ function parseCalldataField(argsIterator, input, structs) {
3172
2992
  result.push(felt(value.length));
3173
2993
  const arrayType = getArrayType(input.type);
3174
2994
  return value.reduce((acc, el) => {
3175
- if (isTypeFelt(arrayType) || isTypeUint(arrayType) || isTypeContractAddress(arrayType)) {
3176
- acc.push(felt(el));
3177
- } else if (isTypeBool(arrayType) && typeof el === "boolean") {
3178
- acc.push(el.toString());
3179
- } else {
2995
+ if (isTypeStruct(arrayType, structs) || isTypeTuple(arrayType) || isTypeArray(arrayType)) {
3180
2996
  acc.push(...parseCalldataValue(el, arrayType, structs));
2997
+ } else {
2998
+ return acc.concat(parseBaseTypes(arrayType, el));
3181
2999
  }
3182
3000
  return acc;
3183
3001
  }, result);
3184
- case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
3002
+ case (isTypeStruct(type, structs) || isTypeTuple(type)):
3185
3003
  return parseCalldataValue(value, type, structs);
3186
- case isTypeBool(type):
3187
- return `${+value}`;
3188
3004
  default:
3189
- return felt(value);
3005
+ return parseBaseTypes(type, value);
3190
3006
  }
3191
3007
  }
3192
3008
 
3193
3009
  // src/utils/calldata/responseParser.ts
3010
+ function parseBaseTypes2(type, it) {
3011
+ let temp;
3012
+ switch (true) {
3013
+ case isTypeBool(type):
3014
+ temp = it.next().value;
3015
+ return Boolean(BigInt(temp));
3016
+ case isTypeUint256(type):
3017
+ const low = it.next().value;
3018
+ const high = it.next().value;
3019
+ return uint256ToBN({ low, high });
3020
+ default:
3021
+ temp = it.next().value;
3022
+ return BigInt(temp);
3023
+ }
3024
+ }
3194
3025
  function parseResponseStruct(responseIterator, type, structs) {
3195
3026
  if (type in structs && structs[type]) {
3196
3027
  return structs[type].members.reduce((acc, el) => {
@@ -3207,8 +3038,7 @@ function parseResponseStruct(responseIterator, type, structs) {
3207
3038
  return acc;
3208
3039
  }, {});
3209
3040
  }
3210
- const temp = responseIterator.next().value;
3211
- return BigInt(temp);
3041
+ return parseBaseTypes2(type, responseIterator);
3212
3042
  }
3213
3043
  function responseParser(responseIterator, output, structs, parsedResult) {
3214
3044
  const { name, type } = output;
@@ -3217,21 +3047,13 @@ function responseParser(responseIterator, output, structs, parsedResult) {
3217
3047
  case isLen(name):
3218
3048
  temp = responseIterator.next().value;
3219
3049
  return BigInt(temp);
3220
- case isTypeBool(type):
3221
- temp = responseIterator.next().value;
3222
- return Boolean(BigInt(temp));
3223
- case isTypeUint256(type):
3224
- const low = responseIterator.next().value;
3225
- const high = responseIterator.next().value;
3226
- return uint256ToBN({ low, high });
3227
3050
  case isTypeArray(type):
3228
3051
  const parsedDataArr = [];
3229
3052
  if (isCairo1Type(type)) {
3230
- responseIterator.next();
3231
- let it = responseIterator.next();
3232
- while (!it.done) {
3233
- parsedDataArr.push(BigInt(it.value));
3234
- it = responseIterator.next();
3053
+ const arrayType = getArrayType(type);
3054
+ const len = BigInt(responseIterator.next().value);
3055
+ while (parsedDataArr.length < len) {
3056
+ parsedDataArr.push(parseResponseStruct(responseIterator, arrayType, structs));
3235
3057
  }
3236
3058
  return parsedDataArr;
3237
3059
  }
@@ -3247,8 +3069,7 @@ function responseParser(responseIterator, output, structs, parsedResult) {
3247
3069
  case (type in structs || isTypeTuple(type)):
3248
3070
  return parseResponseStruct(responseIterator, type, structs);
3249
3071
  default:
3250
- temp = responseIterator.next().value;
3251
- return BigInt(temp);
3072
+ return parseBaseTypes2(type, responseIterator);
3252
3073
  }
3253
3074
  }
3254
3075
 
@@ -3446,6 +3267,8 @@ var CallData = class {
3446
3267
  let value = v;
3447
3268
  if (isLongText(value))
3448
3269
  value = splitLongString(value);
3270
+ if (k === "entrypoint")
3271
+ value = getSelectorFromName(value);
3449
3272
  const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
3450
3273
  if (isBigInt(value))
3451
3274
  return [[`${prefix}${kk}`, felt(value)]];
@@ -3499,6 +3322,188 @@ var CallData = class {
3499
3322
  {}
3500
3323
  );
3501
3324
  }
3325
+ static toCalldata(rawCalldata = []) {
3326
+ return CallData.compile(rawCalldata);
3327
+ }
3328
+ static toHex(rawCalldata = []) {
3329
+ const calldata = CallData.compile(rawCalldata);
3330
+ return calldata.map((it) => toHex(it));
3331
+ }
3332
+ };
3333
+
3334
+ // src/utils/fetchPonyfill.ts
3335
+ var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
3336
+ var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || import_isomorphic_fetch.default;
3337
+
3338
+ // src/utils/contract.ts
3339
+ function isSierra(contract) {
3340
+ const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
3341
+ return "sierra_program" in compiledContract;
3342
+ }
3343
+ function extractContractHashes(payload) {
3344
+ const response = { ...payload };
3345
+ if (isSierra(payload.contract)) {
3346
+ if (!payload.compiledClassHash && payload.casm) {
3347
+ response.compiledClassHash = computeCompiledClassHash(payload.casm);
3348
+ }
3349
+ if (!response.compiledClassHash)
3350
+ throw new Error(
3351
+ "Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
3352
+ );
3353
+ }
3354
+ response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
3355
+ if (!response.classHash)
3356
+ throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
3357
+ return response;
3358
+ }
3359
+
3360
+ // src/utils/stark.ts
3361
+ var stark_exports = {};
3362
+ __export(stark_exports, {
3363
+ compressProgram: () => compressProgram,
3364
+ estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
3365
+ formatSignature: () => formatSignature,
3366
+ makeAddress: () => makeAddress,
3367
+ randomAddress: () => randomAddress,
3368
+ signatureToDecimalArray: () => signatureToDecimalArray,
3369
+ signatureToHexArray: () => signatureToHexArray
3370
+ });
3371
+ var import_micro_starknet2 = require("micro-starknet");
3372
+ var import_pako = require("pako");
3373
+ function compressProgram(jsonProgram) {
3374
+ const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
3375
+ const compressedProgram = (0, import_pako.gzip)(stringified);
3376
+ return btoaUniversal(compressedProgram);
3377
+ }
3378
+ function randomAddress() {
3379
+ const randomKeyPair = import_micro_starknet2.utils.randomPrivateKey();
3380
+ return (0, import_micro_starknet2.getStarkKey)(randomKeyPair);
3381
+ }
3382
+ function makeAddress(input) {
3383
+ return addHexPrefix(input).toLowerCase();
3384
+ }
3385
+ function formatSignature(sig) {
3386
+ if (!sig)
3387
+ throw Error("formatSignature: provided signature is undefined");
3388
+ if (Array.isArray(sig)) {
3389
+ return sig.map((it) => toHex(it));
3390
+ }
3391
+ try {
3392
+ const { r, s } = sig;
3393
+ return [toHex(r), toHex(s)];
3394
+ } catch (e) {
3395
+ throw new Error("Signature need to be weierstrass.SignatureType or an array for custom");
3396
+ }
3397
+ }
3398
+ function signatureToDecimalArray(sig) {
3399
+ return bigNumberishArrayToDecimalStringArray(formatSignature(sig));
3400
+ }
3401
+ function signatureToHexArray(sig) {
3402
+ return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
3403
+ }
3404
+ function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
3405
+ const overHeadPercent = Math.round((1 + overhead) * 100);
3406
+ return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
3407
+ }
3408
+
3409
+ // src/utils/provider.ts
3410
+ function wait(delay) {
3411
+ return new Promise((res) => {
3412
+ setTimeout(res, delay);
3413
+ });
3414
+ }
3415
+ function createSierraContractClass(contract) {
3416
+ const result = { ...contract };
3417
+ delete result.sierra_program_debug_info;
3418
+ result.abi = formatSpaces(stringify2(contract.abi));
3419
+ result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
3420
+ result.sierra_program = compressProgram(result.sierra_program);
3421
+ return result;
3422
+ }
3423
+ function parseContract(contract) {
3424
+ const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
3425
+ if (!isSierra(contract)) {
3426
+ return {
3427
+ ...parsedContract,
3428
+ ..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
3429
+ };
3430
+ }
3431
+ return createSierraContractClass(parsedContract);
3432
+ }
3433
+
3434
+ // src/utils/responseParser/rpc.ts
3435
+ var RPCResponseParser = class {
3436
+ parseGetBlockResponse(res) {
3437
+ return {
3438
+ timestamp: res.timestamp,
3439
+ block_hash: res.block_hash,
3440
+ block_number: res.block_number,
3441
+ new_root: res.new_root,
3442
+ parent_hash: res.parent_hash,
3443
+ status: res.status,
3444
+ transactions: res.transactions
3445
+ };
3446
+ }
3447
+ parseGetTransactionResponse(res) {
3448
+ return {
3449
+ calldata: res.calldata || [],
3450
+ contract_address: res.contract_address,
3451
+ sender_address: res.contract_address,
3452
+ max_fee: res.max_fee,
3453
+ nonce: res.nonce,
3454
+ signature: res.signature || [],
3455
+ transaction_hash: res.transaction_hash,
3456
+ version: res.version
3457
+ };
3458
+ }
3459
+ parseFeeEstimateResponse(res) {
3460
+ return {
3461
+ overall_fee: toBigInt(res.overall_fee),
3462
+ gas_consumed: toBigInt(res.gas_consumed),
3463
+ gas_price: toBigInt(res.gas_price)
3464
+ };
3465
+ }
3466
+ parseCallContractResponse(res) {
3467
+ return {
3468
+ result: res
3469
+ };
3470
+ }
3471
+ };
3472
+
3473
+ // src/provider/errors.ts
3474
+ function fixStack(target, fn = target.constructor) {
3475
+ const { captureStackTrace } = Error;
3476
+ captureStackTrace && captureStackTrace(target, fn);
3477
+ }
3478
+ function fixProto(target, prototype) {
3479
+ const { setPrototypeOf } = Object;
3480
+ setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
3481
+ }
3482
+ var CustomError = class extends Error {
3483
+ constructor(message) {
3484
+ super(message);
3485
+ Object.defineProperty(this, "name", {
3486
+ value: new.target.name,
3487
+ enumerable: false,
3488
+ configurable: true
3489
+ });
3490
+ fixProto(this, new.target.prototype);
3491
+ fixStack(this);
3492
+ }
3493
+ };
3494
+ var LibraryError = class extends CustomError {
3495
+ };
3496
+ var GatewayError = class extends LibraryError {
3497
+ constructor(message, errorCode) {
3498
+ super(message);
3499
+ this.errorCode = errorCode;
3500
+ }
3501
+ };
3502
+ var HttpError = class extends LibraryError {
3503
+ constructor(message, errorCode) {
3504
+ super(message);
3505
+ this.errorCode = errorCode;
3506
+ }
3502
3507
  };
3503
3508
 
3504
3509
  // src/utils/starknetId.ts
@@ -3831,7 +3836,7 @@ var RpcProvider = class {
3831
3836
  request: {
3832
3837
  type: RPC.TransactionType.INVOKE,
3833
3838
  sender_address: invocation.contractAddress,
3834
- calldata: parseCalldata(invocation.calldata),
3839
+ calldata: CallData.toHex(invocation.calldata),
3835
3840
  signature: signatureToHexArray(invocation.signature),
3836
3841
  version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 0),
3837
3842
  nonce: toHex(invocationDetails.nonce),
@@ -3919,7 +3924,7 @@ var RpcProvider = class {
3919
3924
  return this.fetchEndpoint("starknet_addInvokeTransaction", {
3920
3925
  invoke_transaction: {
3921
3926
  sender_address: functionInvocation.contractAddress,
3922
- calldata: parseCalldata(functionInvocation.calldata),
3927
+ calldata: CallData.toHex(functionInvocation.calldata),
3923
3928
  type: RPC.TransactionType.INVOKE,
3924
3929
  max_fee: toHex(details.maxFee || 0),
3925
3930
  version: "0x1",
@@ -3934,7 +3939,7 @@ var RpcProvider = class {
3934
3939
  request: {
3935
3940
  contract_address: call.contractAddress,
3936
3941
  entry_point_selector: getSelectorFromName(call.entrypoint),
3937
- calldata: parseCalldata(call.calldata)
3942
+ calldata: CallData.toHex(call.calldata)
3938
3943
  },
3939
3944
  block_id
3940
3945
  });
@@ -4404,7 +4409,7 @@ var SequencerProvider = class {
4404
4409
  return this.fetchEndpoint("add_transaction", void 0, {
4405
4410
  type: "INVOKE_FUNCTION" /* INVOKE */,
4406
4411
  sender_address: functionInvocation.contractAddress,
4407
- calldata: bigNumberishArrayToDecimalStringArray(functionInvocation.calldata ?? []),
4412
+ calldata: CallData.compile(functionInvocation.calldata ?? []),
4408
4413
  signature: signatureToDecimalArray(functionInvocation.signature),
4409
4414
  nonce: toHex(details.nonce),
4410
4415
  max_fee: toHex(details.maxFee || 0),
@@ -4415,7 +4420,7 @@ var SequencerProvider = class {
4415
4420
  return this.fetchEndpoint("add_transaction", void 0, {
4416
4421
  type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
4417
4422
  contract_address_salt: addressSalt ?? randomAddress(),
4418
- constructor_calldata: bigNumberishArrayToDecimalStringArray(constructorCalldata ?? []),
4423
+ constructor_calldata: CallData.compile(constructorCalldata ?? []),
4419
4424
  class_hash: toHex(classHash),
4420
4425
  max_fee: toHex(details.maxFee || 0),
4421
4426
  version: toHex(details.version || 0),
@@ -4499,7 +4504,7 @@ var SequencerProvider = class {
4499
4504
  {
4500
4505
  type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
4501
4506
  class_hash: toHex(classHash),
4502
- constructor_calldata: bigNumberishArrayToDecimalStringArray(constructorCalldata || []),
4507
+ constructor_calldata: CallData.compile(constructorCalldata || []),
4503
4508
  contract_address_salt: toHex(addressSalt || 0),
4504
4509
  signature: signatureToDecimalArray(signature),
4505
4510
  version: toHex((details == null ? void 0 : details.version) || 0),
@@ -4526,9 +4531,7 @@ var SequencerProvider = class {
4526
4531
  res = {
4527
4532
  type: invocation.type,
4528
4533
  class_hash: toHex(toBigInt(invocation.classHash)),
4529
- constructor_calldata: bigNumberishArrayToDecimalStringArray(
4530
- invocation.constructorCalldata || []
4531
- ),
4534
+ constructor_calldata: CallData.compile(invocation.constructorCalldata || []),
4532
4535
  contract_address_salt: toHex(toBigInt(invocation.addressSalt || 0))
4533
4536
  };
4534
4537
  }
@@ -5023,19 +5026,13 @@ var transformCallsToMulticallArrays = (calls) => {
5023
5026
  });
5024
5027
  return {
5025
5028
  callArray,
5026
- calldata: bigNumberishArrayToDecimalStringArray(calldata)
5029
+ calldata: CallData.compile({ calldata })
5027
5030
  };
5028
5031
  };
5029
5032
  var fromCallsToExecuteCalldata = (calls) => {
5030
5033
  const { callArray, calldata } = transformCallsToMulticallArrays(calls);
5031
- return [
5032
- callArray.length.toString(),
5033
- ...callArray.map(
5034
- ({ to, selector, data_offset, data_len }) => [to, selector, data_offset, data_len]
5035
- ).flat(),
5036
- calldata.length.toString(),
5037
- ...calldata
5038
- ];
5034
+ const compiledCalls = CallData.compile({ callArray });
5035
+ return [...compiledCalls, ...calldata];
5039
5036
  };
5040
5037
  var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
5041
5038
  return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
@@ -5044,20 +5041,16 @@ var transformCallsToMulticallArrays_cairo1 = (calls) => {
5044
5041
  const callArray = calls.map((call) => ({
5045
5042
  to: toBigInt(call.contractAddress).toString(10),
5046
5043
  selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
5047
- calldata: bigNumberishArrayToDecimalStringArray(call.calldata || [])
5044
+ calldata: CallData.compile(call.calldata || [])
5048
5045
  }));
5049
5046
  return callArray;
5050
5047
  };
5051
5048
  var fromCallsToExecuteCalldata_cairo1 = (calls) => {
5052
- const callArray = transformCallsToMulticallArrays_cairo1(calls);
5053
- return [
5054
- callArray.length.toString(),
5055
- ...callArray.map(({ to, selector, calldata }) => [to, selector, calldata.length.toString(), ...calldata]).flat()
5056
- ];
5049
+ return CallData.compile({ calls });
5057
5050
  };
5058
5051
  var getExecuteCalldata = (calls, cairoVersion = "0") => {
5059
5052
  if (cairoVersion === "1") {
5060
- return fromCallsToExecuteCalldata_cairo1(calls);
5053
+ return CallData.compile({ calls });
5061
5054
  }
5062
5055
  return fromCallsToExecuteCalldata(calls);
5063
5056
  };
@@ -5663,7 +5656,8 @@ var Account = class extends Provider {
5663
5656
  const version = toBigInt(transactionVersion);
5664
5657
  const nonce = ZERO;
5665
5658
  const chainId = await this.getChainId();
5666
- const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
5659
+ const compiledCalldata = CallData.compile(constructorCalldata);
5660
+ const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
5667
5661
  const maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
5668
5662
  {
5669
5663
  type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
@@ -5761,7 +5755,8 @@ var Account = class extends Provider {
5761
5755
  constructorCalldata = [],
5762
5756
  contractAddress: providedContractAddress
5763
5757
  }, { nonce, chainId, version, maxFee }) {
5764
- const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, constructorCalldata, 0);
5758
+ const compiledCalldata = CallData.compile(constructorCalldata);
5759
+ const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
5765
5760
  const signature = await this.signer.signDeployAccountTransaction({
5766
5761
  classHash,
5767
5762
  contractAddress,