starknet 5.10.1 → 5.11.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
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -2523,7 +2527,9 @@ var uint256 = (it) => {
2523
2527
  if (!isUint256(bn))
2524
2528
  throw new Error("Number is too large");
2525
2529
  return {
2530
+ // eslint-disable-next-line no-bitwise
2526
2531
  low: (bn & UINT_128_MAX).toString(10),
2532
+ // eslint-disable-next-line no-bitwise
2527
2533
  high: (bn >> 128n).toString(10)
2528
2534
  };
2529
2535
  };
@@ -2659,7 +2665,11 @@ function extractCairo0Tuple(type) {
2659
2665
  }
2660
2666
  function extractCairo1Tuple(type) {
2661
2667
  const cleanType = type.replace(/\s/g, "").slice(1, -1);
2662
- return cleanType.split(",");
2668
+ const { subTuple, result } = parseSubTuple(cleanType);
2669
+ const recomposed = result.split(",").map((it) => {
2670
+ return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
2671
+ });
2672
+ return recomposed;
2663
2673
  }
2664
2674
  function extractTupleMemberTypes(type) {
2665
2675
  if (isCairo1Type(type)) {
@@ -2668,6 +2678,142 @@ function extractTupleMemberTypes(type) {
2668
2678
  return extractCairo0Tuple(type);
2669
2679
  }
2670
2680
 
2681
+ // src/utils/calldata/propertyOrder.ts
2682
+ function errorU256(key) {
2683
+ return Error(
2684
+ `Your object includes the property : ${key}, containing an Uint256 object without the 'low' and 'high' keys.`
2685
+ );
2686
+ }
2687
+ function orderPropsByAbi(unorderedObject, abiOfObject, structs) {
2688
+ const orderStruct = (unorderedObject2, abiObject) => {
2689
+ const orderedObject2 = abiObject.reduce((orderedObject, abiParam) => {
2690
+ const setProperty = (value) => Object.defineProperty(orderedObject, abiParam.name, {
2691
+ enumerable: true,
2692
+ value: value ?? unorderedObject2[abiParam.name]
2693
+ });
2694
+ if (unorderedObject2[abiParam.name] === "undefined") {
2695
+ if (isCairo1Type(abiParam.type) || !isLen(abiParam.name)) {
2696
+ throw Error(`Your object needs a property with key : ${abiParam.name} .`);
2697
+ }
2698
+ }
2699
+ switch (true) {
2700
+ case isTypeStruct(abiParam.type, structs):
2701
+ setProperty(
2702
+ orderStruct(
2703
+ unorderedObject2[abiParam.name],
2704
+ structs[abiParam.type].members
2705
+ )
2706
+ );
2707
+ break;
2708
+ case isTypeUint256(abiParam.type): {
2709
+ const u256 = unorderedObject2[abiParam.name];
2710
+ if (typeof u256 !== "object") {
2711
+ setProperty();
2712
+ break;
2713
+ }
2714
+ if (!("low" in u256 && "high" in u256)) {
2715
+ throw errorU256(abiParam.name);
2716
+ }
2717
+ setProperty({ low: u256.low, high: u256.high });
2718
+ break;
2719
+ }
2720
+ case isTypeTuple(abiParam.type):
2721
+ setProperty(orderTuple(unorderedObject2[abiParam.name], abiParam));
2722
+ break;
2723
+ case isTypeArray(abiParam.type):
2724
+ setProperty(orderArray(unorderedObject2[abiParam.name], abiParam));
2725
+ break;
2726
+ case (!isCairo1Type(abiParam.type) && isLen(abiParam.name)):
2727
+ break;
2728
+ default:
2729
+ setProperty();
2730
+ }
2731
+ return orderedObject;
2732
+ }, {});
2733
+ return orderedObject2;
2734
+ };
2735
+ function orderArray(myArray, abiParam) {
2736
+ const typeInArray = getArrayType(abiParam.type);
2737
+ if (typeof myArray === "string") {
2738
+ return myArray;
2739
+ }
2740
+ switch (true) {
2741
+ case typeInArray in structs:
2742
+ return myArray.map((myObj) => orderStruct(myObj, structs[typeInArray].members));
2743
+ case typeInArray === "core::integer::u256":
2744
+ return myArray.map((u256) => {
2745
+ if (typeof u256 !== "object") {
2746
+ return u256;
2747
+ }
2748
+ if (!("low" in u256 && "high" in u256)) {
2749
+ throw errorU256(abiParam.name);
2750
+ }
2751
+ return { low: u256.low, high: u256.high };
2752
+ });
2753
+ case isTypeTuple(typeInArray):
2754
+ return myArray.map((myElem) => orderTuple(myElem, { name: "0", type: typeInArray }));
2755
+ case isTypeArray(typeInArray):
2756
+ return myArray.map((myElem) => orderArray(myElem, { name: "0", type: typeInArray }));
2757
+ default:
2758
+ return myArray;
2759
+ }
2760
+ }
2761
+ function orderTuple(unorderedObject2, abiParam) {
2762
+ const typeList = extractTupleMemberTypes(abiParam.type);
2763
+ const orderedObject2 = typeList.reduce((orderedObject, abiTypeCairoX, index) => {
2764
+ const myObjKeys = Object.keys(unorderedObject2);
2765
+ const setProperty = (value) => Object.defineProperty(orderedObject, index.toString(), {
2766
+ enumerable: true,
2767
+ value: value ?? unorderedObject2[myObjKeys[index]]
2768
+ });
2769
+ const abiType = abiTypeCairoX?.type ? abiTypeCairoX.type : abiTypeCairoX;
2770
+ switch (true) {
2771
+ case isTypeStruct(abiType, structs):
2772
+ setProperty(
2773
+ orderStruct(
2774
+ unorderedObject2[myObjKeys[index]],
2775
+ structs[abiType].members
2776
+ )
2777
+ );
2778
+ break;
2779
+ case isTypeUint256(abiType): {
2780
+ const u256 = unorderedObject2[myObjKeys[index]];
2781
+ if (typeof u256 !== "object") {
2782
+ setProperty();
2783
+ break;
2784
+ }
2785
+ if (!("low" in u256 && "high" in u256)) {
2786
+ throw errorU256(abiParam.name);
2787
+ }
2788
+ setProperty({ low: u256.low, high: u256.high });
2789
+ break;
2790
+ }
2791
+ case isTypeTuple(abiType):
2792
+ setProperty(
2793
+ orderTuple(unorderedObject2[myObjKeys[index]], {
2794
+ name: "0",
2795
+ type: abiType
2796
+ })
2797
+ );
2798
+ break;
2799
+ case isTypeArray(abiType):
2800
+ setProperty(
2801
+ orderArray(unorderedObject2[myObjKeys[index]], {
2802
+ name: "0",
2803
+ type: abiType
2804
+ })
2805
+ );
2806
+ break;
2807
+ default:
2808
+ setProperty();
2809
+ }
2810
+ return orderedObject;
2811
+ }, {});
2812
+ return orderedObject2;
2813
+ }
2814
+ return orderStruct(unorderedObject, abiOfObject);
2815
+ }
2816
+
2671
2817
  // src/utils/calldata/requestParser.ts
2672
2818
  function parseBaseTypes(type, val) {
2673
2819
  switch (true) {
@@ -2721,6 +2867,14 @@ function parseCalldataValue(element, type, structs) {
2721
2867
  return acc.concat(parsedData);
2722
2868
  }, []);
2723
2869
  }
2870
+ if (isTypeUint256(type)) {
2871
+ if (typeof element === "object") {
2872
+ const { low, high } = element;
2873
+ return [felt(low), felt(high)];
2874
+ }
2875
+ const el_uint256 = uint256(element);
2876
+ return [felt(el_uint256.low), felt(el_uint256.high)];
2877
+ }
2724
2878
  if (typeof element === "object") {
2725
2879
  throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
2726
2880
  }
@@ -2738,14 +2892,8 @@ function parseCalldataField(argsIterator, input, structs) {
2738
2892
  value = splitLongString(value);
2739
2893
  }
2740
2894
  return parseCalldataValue(value, input.type, structs);
2741
- case (isTypeStruct(type, structs) || isTypeTuple(type)):
2895
+ case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
2742
2896
  return parseCalldataValue(value, type, structs);
2743
- case isTypeUint256(type):
2744
- if (typeof value === "object") {
2745
- return [felt(value.low), felt(value.high)];
2746
- }
2747
- const el_uint256 = uint256(value);
2748
- return [felt(el_uint256.low), felt(el_uint256.high)];
2749
2897
  default:
2750
2898
  return parseBaseTypes(type, value);
2751
2899
  }
@@ -2777,8 +2925,8 @@ function parseResponseValue(responseIterator, element, structs) {
2777
2925
  if (isTypeTuple(element.type)) {
2778
2926
  const memberTypes = extractTupleMemberTypes(element.type);
2779
2927
  return memberTypes.reduce((acc, it, idx) => {
2780
- const name = (it == null ? void 0 : it.name) ? it.name : idx;
2781
- const type = (it == null ? void 0 : it.type) ? it.type : it;
2928
+ const name = it?.name ? it.name : idx;
2929
+ const type = it?.type ? it.type : it;
2782
2930
  const el = { name, type };
2783
2931
  acc[name] = parseResponseValue(responseIterator, el, structs);
2784
2932
  return acc;
@@ -2986,6 +3134,12 @@ var CallData = class {
2986
3134
  this.abi = abi;
2987
3135
  this.structs = CallData.getAbiStruct(abi);
2988
3136
  }
3137
+ /**
3138
+ * Validate arguments passed to the method as corresponding to the ones in the abi
3139
+ * @param type string - type of the method
3140
+ * @param method string - name of the method
3141
+ * @param args ArgsOrCalldata - arguments that are passed to the method
3142
+ */
2989
3143
  validate(type, method, args = []) {
2990
3144
  if (type !== "DEPLOY") {
2991
3145
  const invocableFunctionNames = this.abi.filter((abi) => {
@@ -3010,14 +3164,41 @@ var CallData = class {
3010
3164
  }
3011
3165
  validateFields(abiMethod, args, this.structs);
3012
3166
  }
3013
- compile(method, args) {
3167
+ /**
3168
+ * Compile contract callData with abi
3169
+ * Parse the calldata by using input fields from the abi for that method
3170
+ * @param method string - method name
3171
+ * @param args RawArgs - arguments passed to the method. Can be an array of arguments (in the order of abi definition), or an object constructed in conformity with abi (in this case, the parameter can be in a wrong order).
3172
+ * @return Calldata - parsed arguments in format that contract is expecting
3173
+ * @example
3174
+ * ```typescript
3175
+ * const calldata = myCallData.compile("constructor",["0x34a",[1,3n]]);
3176
+ * ```
3177
+ * ```typescript
3178
+ * const calldata2 = myCallData.compile("constructor",{list:[1,3n],balance:"0x34"}); // wrong order is valid
3179
+ * ```
3180
+ */
3181
+ compile(method, argsCalldata) {
3182
+ const abiMethod = this.abi.find((abi) => abi.name === method);
3183
+ let args;
3184
+ if (Array.isArray(argsCalldata)) {
3185
+ args = argsCalldata;
3186
+ } else {
3187
+ const orderedObject = orderPropsByAbi(argsCalldata, abiMethod.inputs, this.structs);
3188
+ args = Object.values(orderedObject);
3189
+ validateFields(abiMethod, args, this.structs);
3190
+ }
3014
3191
  const argsIterator = args[Symbol.iterator]();
3015
- const { inputs } = this.abi.find((abi) => abi.name === method);
3016
- return inputs.reduce(
3192
+ return abiMethod.inputs.reduce(
3017
3193
  (acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
3018
3194
  []
3019
3195
  );
3020
3196
  }
3197
+ /**
3198
+ * Compile contract callData without abi
3199
+ * @param rawArgs RawArgs representing cairo method arguments or string array of compiled data
3200
+ * @returns Calldata
3201
+ */
3021
3202
  static compile(rawArgs) {
3022
3203
  const createTree = (obj) => {
3023
3204
  const getEntries = (o, prefix = "") => {
@@ -3052,6 +3233,12 @@ var CallData = class {
3052
3233
  });
3053
3234
  return callTreeArray;
3054
3235
  }
3236
+ /**
3237
+ * Parse elements of the response array and structuring them into response object
3238
+ * @param method string - method name
3239
+ * @param response string[] - response from the method
3240
+ * @return Result - parsed response corresponding to the abi
3241
+ */
3055
3242
  parse(method, response) {
3056
3243
  const { outputs } = this.abi.find((abi) => abi.name === method);
3057
3244
  const responseIterator = response.flat()[Symbol.iterator]();
@@ -3065,13 +3252,30 @@ var CallData = class {
3065
3252
  }, {});
3066
3253
  return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
3067
3254
  }
3255
+ /**
3256
+ * Format cairo method response data to native js values based on provided format schema
3257
+ * @param method string - cairo method name
3258
+ * @param response string[] - cairo method response
3259
+ * @param format object - formatter object schema
3260
+ * @returns Result - parsed and formatted response object
3261
+ */
3068
3262
  format(method, response, format) {
3069
3263
  const parsed = this.parse(method, response);
3070
3264
  return formatter(parsed, format);
3071
3265
  }
3266
+ /**
3267
+ * Helper to calculate inputs from abi
3268
+ * @param inputs AbiEntry
3269
+ * @returns number
3270
+ */
3072
3271
  static abiInputsLength(inputs) {
3073
3272
  return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
3074
3273
  }
3274
+ /**
3275
+ * Helper to extract structs from abi
3276
+ * @param abi Abi
3277
+ * @returns AbiStructs - structs from abi
3278
+ */
3075
3279
  static getAbiStruct(abi) {
3076
3280
  return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
3077
3281
  (acc, abiEntry) => ({
@@ -3081,9 +3285,19 @@ var CallData = class {
3081
3285
  {}
3082
3286
  );
3083
3287
  }
3288
+ /**
3289
+ * Helper: Compile HexCalldata | RawCalldata | RawArgs
3290
+ * @param rawCalldata HexCalldata | RawCalldata | RawArgs
3291
+ * @returns Calldata
3292
+ */
3084
3293
  static toCalldata(rawCalldata = []) {
3085
3294
  return CallData.compile(rawCalldata);
3086
3295
  }
3296
+ /**
3297
+ * Helper: Convert raw to HexCalldata
3298
+ * @param raw HexCalldata | RawCalldata | RawArgs
3299
+ * @returns HexCalldata
3300
+ */
3087
3301
  static toHex(raw = []) {
3088
3302
  const calldata = CallData.compile(raw);
3089
3303
  return calldata.map((it) => toHex(it));
@@ -3092,7 +3306,9 @@ var CallData = class {
3092
3306
 
3093
3307
  // src/utils/fetchPonyfill.ts
3094
3308
  var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
3095
- var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || import_isomorphic_fetch.default;
3309
+ var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || // use buildin fetch in browser if available
3310
+ typeof global !== "undefined" && global.fetch || // use buildin fetch in node, react-native and service worker if available
3311
+ import_isomorphic_fetch.default;
3096
3312
 
3097
3313
  // src/utils/hash.ts
3098
3314
  var hash_exports = {};
@@ -3446,6 +3662,7 @@ function parseContract(contract) {
3446
3662
  if (!isSierra(contract)) {
3447
3663
  return {
3448
3664
  ...parsedContract,
3665
+ // TODO: Why do we gzip program object?
3449
3666
  ..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
3450
3667
  };
3451
3668
  }
@@ -3698,6 +3915,7 @@ var Block = class {
3698
3915
  this.tag = "pending";
3699
3916
  }
3700
3917
  }
3918
+ // TODO: fix any
3701
3919
  get queryIdentifier() {
3702
3920
  if (this.number !== null) {
3703
3921
  return `blockNumber=${this.number}`;
@@ -3707,6 +3925,7 @@ var Block = class {
3707
3925
  }
3708
3926
  return `blockNumber=${this.tag}`;
3709
3927
  }
3928
+ // TODO: fix any
3710
3929
  get identifier() {
3711
3930
  if (this.number !== null) {
3712
3931
  return { block_number: this.number };
@@ -3754,17 +3973,17 @@ var RpcProvider = class {
3754
3973
  }
3755
3974
  }
3756
3975
  async fetchEndpoint(method, params) {
3757
- var _a;
3758
3976
  try {
3759
3977
  const rawResult = await this.fetch(method, params);
3760
3978
  const { error, result } = await rawResult.json();
3761
3979
  this.errorHandler(error);
3762
3980
  return result;
3763
3981
  } catch (error) {
3764
- this.errorHandler((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data);
3982
+ this.errorHandler(error?.response?.data);
3765
3983
  throw error;
3766
3984
  }
3767
3985
  }
3986
+ // Methods from Interface
3768
3987
  async getChainId() {
3769
3988
  this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
3770
3989
  return this.chainId;
@@ -3818,6 +4037,7 @@ var RpcProvider = class {
3818
4037
  block_id
3819
4038
  });
3820
4039
  }
4040
+ // Methods from Interface
3821
4041
  async getTransaction(txHash) {
3822
4042
  return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
3823
4043
  }
@@ -3859,9 +4079,9 @@ var RpcProvider = class {
3859
4079
  sender_address: invocation.contractAddress,
3860
4080
  calldata: CallData.toHex(invocation.calldata),
3861
4081
  signature: signatureToHexArray(invocation.signature),
3862
- version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 0),
4082
+ version: toHex(invocationDetails?.version || 0),
3863
4083
  nonce: toHex(invocationDetails.nonce),
3864
- max_fee: toHex((invocationDetails == null ? void 0 : invocationDetails.maxFee) || 0)
4084
+ max_fee: toHex(invocationDetails?.maxFee || 0)
3865
4085
  },
3866
4086
  block_id
3867
4087
  }).then(this.responseParser.parseFeeEstimateResponse);
@@ -3876,12 +4096,13 @@ var RpcProvider = class {
3876
4096
  program: contractDefinition.program,
3877
4097
  entry_points_by_type: contractDefinition.entry_points_by_type,
3878
4098
  abi: contractDefinition.abi
4099
+ // rpc 2.0
3879
4100
  },
3880
4101
  sender_address: senderAddress,
3881
4102
  signature: signatureToHexArray(signature),
3882
- version: toHex((details == null ? void 0 : details.version) || 0),
4103
+ version: toHex(details?.version || 0),
3883
4104
  nonce: toHex(details.nonce),
3884
- max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
4105
+ max_fee: toHex(details?.maxFee || 0)
3885
4106
  },
3886
4107
  block_id
3887
4108
  }).then(this.responseParser.parseFeeEstimateResponse);
@@ -3897,9 +4118,9 @@ var RpcProvider = class {
3897
4118
  class_hash: toHex(classHash),
3898
4119
  contract_address_salt: toHex(addressSalt || 0),
3899
4120
  signature: signatureToHexArray(signature),
3900
- version: toHex((details == null ? void 0 : details.version) || 0),
4121
+ version: toHex(details?.version || 0),
3901
4122
  nonce: toHex(details.nonce),
3902
- max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
4123
+ max_fee: toHex(details?.maxFee || 0)
3903
4124
  },
3904
4125
  block_id
3905
4126
  }).then(this.responseParser.parseFeeEstimateResponse);
@@ -3907,6 +4128,7 @@ var RpcProvider = class {
3907
4128
  async getEstimateFeeBulk(_invocations, _blockIdentifier = this.blockIdentifier) {
3908
4129
  throw new Error("RPC does not implement getInvokeEstimateFeeBulk function");
3909
4130
  }
4131
+ // TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
3910
4132
  async declareContract({ contractDefinition, signature, senderAddress }, details) {
3911
4133
  if ("program" in contractDefinition) {
3912
4134
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
@@ -3915,6 +4137,7 @@ var RpcProvider = class {
3915
4137
  program: contractDefinition.program,
3916
4138
  entry_points_by_type: contractDefinition.entry_points_by_type,
3917
4139
  abi: contractDefinition.abi
4140
+ // rpc 2.0
3918
4141
  },
3919
4142
  type: RPC.TransactionType.DECLARE,
3920
4143
  version: "0x1",
@@ -3954,6 +4177,7 @@ var RpcProvider = class {
3954
4177
  }
3955
4178
  });
3956
4179
  }
4180
+ // Methods from Interface
3957
4181
  async callContract(call, blockIdentifier = this.blockIdentifier) {
3958
4182
  const block_id = new Block(blockIdentifier).identifier;
3959
4183
  const result = await this.fetchEndpoint("starknet_call", {
@@ -3977,8 +4201,8 @@ var RpcProvider = class {
3977
4201
  let { retries } = this;
3978
4202
  let onchain = false;
3979
4203
  let txReceipt = {};
3980
- const retryInterval = (options == null ? void 0 : options.retryInterval) ?? 8e3;
3981
- const successStates = (options == null ? void 0 : options.successStates) ?? [
4204
+ const retryInterval = options?.retryInterval ?? 8e3;
4205
+ const successStates = options?.successStates ?? [
3982
4206
  "ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
3983
4207
  "ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
3984
4208
  "PENDING" /* PENDING */
@@ -4012,16 +4236,41 @@ var RpcProvider = class {
4012
4236
  await wait(retryInterval);
4013
4237
  return txReceipt;
4014
4238
  }
4239
+ /**
4240
+ * Gets the transaction count from a block.
4241
+ *
4242
+ *
4243
+ * @param blockIdentifier
4244
+ * @returns Number of transactions
4245
+ */
4015
4246
  async getTransactionCount(blockIdentifier = this.blockIdentifier) {
4016
4247
  const block_id = new Block(blockIdentifier).identifier;
4017
4248
  return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
4018
4249
  }
4250
+ /**
4251
+ * Gets the latest block number
4252
+ *
4253
+ *
4254
+ * @returns Number of the latest block
4255
+ */
4019
4256
  async getBlockNumber() {
4020
4257
  return this.fetchEndpoint("starknet_blockNumber");
4021
4258
  }
4259
+ /**
4260
+ * Gets syncing status of the node
4261
+ *
4262
+ *
4263
+ * @returns Object with the stats data
4264
+ */
4022
4265
  async getSyncingStats() {
4023
4266
  return this.fetchEndpoint("starknet_syncing");
4024
4267
  }
4268
+ /**
4269
+ * Gets all the events filtered
4270
+ *
4271
+ *
4272
+ * @returns events and the pagination of the events
4273
+ */
4025
4274
  async getEvents(eventFilter) {
4026
4275
  return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
4027
4276
  }
@@ -4072,6 +4321,7 @@ var SequencerAPIResponseParser = class extends ResponseParser {
4072
4321
  transaction_hash: res.transaction_hash,
4073
4322
  status: res.status,
4074
4323
  messages_sent: res.l2_to_l1_messages,
4324
+ // TODO: parse
4075
4325
  events: res.events,
4076
4326
  ..."block_hash" in res && { block_hash: res.block_hash },
4077
4327
  ..."block_number" in res && { block_number: res.block_number },
@@ -4079,6 +4329,7 @@ var SequencerAPIResponseParser = class extends ResponseParser {
4079
4329
  ..."transaction_index" in res && { transaction_index: res.transaction_index },
4080
4330
  ..."execution_resources" in res && { execution_resources: res.execution_resources },
4081
4331
  ..."l1_to_l2_consumed_message" in res && {
4332
+ // eslint-disable-next-line @typescript-eslint/dot-notation
4082
4333
  l1_to_l2_consumed_message: res["l1_to_l2_consumed_message"]
4083
4334
  },
4084
4335
  ..."transaction_failure_reason" in res && {
@@ -4190,6 +4441,7 @@ var SequencerAPIResponseParser = class extends ResponseParser {
4190
4441
  }
4191
4442
  };
4192
4443
  }
4444
+ // TODO: Define response as new type as it diff from ContractClass
4193
4445
  parseSierraContractClassResponse(res) {
4194
4446
  return {
4195
4447
  ...res,
@@ -4251,9 +4503,9 @@ var SequencerProvider = class {
4251
4503
  );
4252
4504
  this.gatewayUrl = buildUrl(this.baseUrl, "gateway", optionsOrProvider.gatewayUrl);
4253
4505
  }
4254
- this.chainId = (optionsOrProvider == null ? void 0 : optionsOrProvider.chainId) ?? SequencerProvider.getChainIdFromBaseUrl(this.baseUrl);
4506
+ this.chainId = optionsOrProvider?.chainId ?? SequencerProvider.getChainIdFromBaseUrl(this.baseUrl);
4255
4507
  this.headers = optionsOrProvider.headers;
4256
- this.blockIdentifier = (optionsOrProvider == null ? void 0 : optionsOrProvider.blockIdentifier) || defaultOptions2.blockIdentifier;
4508
+ this.blockIdentifier = optionsOrProvider?.blockIdentifier || defaultOptions2.blockIdentifier;
4257
4509
  }
4258
4510
  static getNetworkFromName(name) {
4259
4511
  switch (name) {
@@ -4319,6 +4571,7 @@ var SequencerProvider = class {
4319
4571
  }
4320
4572
  return this.headers;
4321
4573
  }
4574
+ // typesafe fetch
4322
4575
  async fetchEndpoint(endpoint, ...[query, request]) {
4323
4576
  const baseUrl = this.getFetchUrl(endpoint);
4324
4577
  const method = this.getFetchMethod(endpoint);
@@ -4331,9 +4584,9 @@ var SequencerProvider = class {
4331
4584
  }
4332
4585
  async fetch(endpoint, options) {
4333
4586
  const url = buildUrl(this.baseUrl, "", endpoint);
4334
- const method = (options == null ? void 0 : options.method) ?? "GET";
4587
+ const method = options?.method ?? "GET";
4335
4588
  const headers = this.getHeaders(method);
4336
- const body = stringify2(options == null ? void 0 : options.body);
4589
+ const body = stringify2(options?.body);
4337
4590
  try {
4338
4591
  const response = await fetchPonyfill_default(url, {
4339
4592
  method,
@@ -4350,7 +4603,7 @@ var SequencerProvider = class {
4350
4603
  }
4351
4604
  throw new GatewayError(responseBody.message, responseBody.code);
4352
4605
  }
4353
- const parseChoice = (options == null ? void 0 : options.parseAlwaysAsBigInt) ? parseAlwaysAsBig : parse2;
4606
+ const parseChoice = options?.parseAlwaysAsBigInt ? parseAlwaysAsBig : parse2;
4354
4607
  return parseChoice(textResponse);
4355
4608
  } catch (error) {
4356
4609
  if (error instanceof Error && !(error instanceof LibraryError))
@@ -4366,6 +4619,9 @@ var SequencerProvider = class {
4366
4619
  "call_contract",
4367
4620
  { blockIdentifier },
4368
4621
  {
4622
+ // TODO - determine best choice once both are fully supported in devnet
4623
+ // signature: [],
4624
+ // sender_address: contractAddress,
4369
4625
  contract_address: contractAddress,
4370
4626
  entry_point_selector: getSelectorFromName(entryPointSelector),
4371
4627
  calldata: CallData.compile(calldata)
@@ -4484,7 +4740,7 @@ var SequencerProvider = class {
4484
4740
  sender_address: invocation.contractAddress,
4485
4741
  calldata: CallData.compile(invocation.calldata ?? []),
4486
4742
  signature: signatureToDecimalArray(invocation.signature),
4487
- version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
4743
+ version: toHex(invocationDetails?.version || 1),
4488
4744
  nonce: toHex(invocationDetails.nonce)
4489
4745
  }
4490
4746
  ).then(this.responseParser.parseFeeEstimateResponse);
@@ -4499,7 +4755,7 @@ var SequencerProvider = class {
4499
4755
  sender_address: senderAddress,
4500
4756
  contract_class: contractDefinition,
4501
4757
  signature: signatureToDecimalArray(signature),
4502
- version: toHex((details == null ? void 0 : details.version) || toBigInt(feeTransactionVersion)),
4758
+ version: toHex(details?.version || toBigInt(feeTransactionVersion)),
4503
4759
  nonce: toHex(details.nonce)
4504
4760
  }
4505
4761
  ).then(this.responseParser.parseFeeEstimateResponse);
@@ -4528,7 +4784,7 @@ var SequencerProvider = class {
4528
4784
  constructor_calldata: CallData.compile(constructorCalldata || []),
4529
4785
  contract_address_salt: toHex(addressSalt || 0),
4530
4786
  signature: signatureToDecimalArray(signature),
4531
- version: toHex((details == null ? void 0 : details.version) || 0),
4787
+ version: toHex(details?.version || 0),
4532
4788
  nonce: toHex(details.nonce)
4533
4789
  }
4534
4790
  ).then(this.responseParser.parseFeeEstimateResponse);
@@ -4559,7 +4815,7 @@ var SequencerProvider = class {
4559
4815
  return {
4560
4816
  ...res,
4561
4817
  signature: bigNumberishArrayToDecimalStringArray(formatSignature(invocation.signature)),
4562
- version: toHex(toBigInt((invocation == null ? void 0 : invocation.version) || 1)),
4818
+ version: toHex(toBigInt(invocation?.version || 1)),
4563
4819
  nonce: toHex(toBigInt(invocation.nonce))
4564
4820
  };
4565
4821
  });
@@ -4574,8 +4830,8 @@ var SequencerProvider = class {
4574
4830
  const errorStates = ["REJECTED" /* REJECTED */, "NOT_RECEIVED" /* NOT_RECEIVED */];
4575
4831
  let onchain = false;
4576
4832
  let res;
4577
- const retryInterval = (options == null ? void 0 : options.retryInterval) ?? 8e3;
4578
- const successStates = (options == null ? void 0 : options.successStates) ?? [
4833
+ const retryInterval = options?.retryInterval ?? 8e3;
4834
+ const successStates = options?.successStates ?? [
4579
4835
  "ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
4580
4836
  "ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
4581
4837
  "PENDING" /* PENDING */
@@ -4596,13 +4852,33 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
4596
4852
  const txReceipt = await this.getTransactionReceipt(txHash);
4597
4853
  return txReceipt;
4598
4854
  }
4855
+ /**
4856
+ * Gets the status of a transaction.
4857
+ *
4858
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
4859
+ *
4860
+ * @param txHash
4861
+ * @returns the transaction status object \{ block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN \}
4862
+ */
4599
4863
  async getTransactionStatus(txHash) {
4600
4864
  const txHashHex = toHex(txHash);
4601
4865
  return this.fetchEndpoint("get_transaction_status", { transactionHash: txHashHex });
4602
4866
  }
4867
+ /**
4868
+ * Gets the smart contract address on the goerli testnet.
4869
+ *
4870
+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
4871
+ * @returns starknet smart contract addresses
4872
+ */
4603
4873
  async getContractAddresses() {
4604
4874
  return this.fetchEndpoint("get_contract_addresses");
4605
4875
  }
4876
+ /**
4877
+ * Gets the transaction trace from a tx id.
4878
+ *
4879
+ * @param txHash
4880
+ * @returns the transaction trace
4881
+ */
4606
4882
  async getTransactionTrace(txHash) {
4607
4883
  const txHashHex = toHex(txHash);
4608
4884
  return this.fetchEndpoint("get_transaction_trace", { transactionHash: txHashHex });
@@ -4625,9 +4901,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
4625
4901
  sender_address: invocation.contractAddress,
4626
4902
  calldata: CallData.compile(invocation.calldata ?? []),
4627
4903
  signature: signatureToDecimalArray(invocation.signature),
4628
- version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
4904
+ version: toHex(invocationDetails?.version || 1),
4629
4905
  nonce: toHex(invocationDetails.nonce),
4630
- max_fee: toHex((invocationDetails == null ? void 0 : invocationDetails.maxFee) || 0)
4906
+ max_fee: toHex(invocationDetails?.maxFee || 0)
4631
4907
  }
4632
4908
  ).then(this.responseParser.parseFeeSimulateTransactionResponse);
4633
4909
  }
@@ -4637,6 +4913,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
4637
4913
  this.responseParser.parseGetStateUpdateResponse
4638
4914
  );
4639
4915
  }
4916
+ // consider adding an optional trace retrieval parameter to the getBlock method
4640
4917
  async getBlockTraces(blockIdentifier = this.blockIdentifier) {
4641
4918
  const args = new Block(blockIdentifier).sequencerIdentifier;
4642
4919
  return this.fetchEndpoint("get_block_traces", { ...args });
@@ -4821,6 +5098,13 @@ function getCalldata(args, callback) {
4821
5098
  return callback();
4822
5099
  }
4823
5100
  var Contract = class {
5101
+ /**
5102
+ * Contract class to handle contract methods
5103
+ *
5104
+ * @param abi - Abi of the contract object
5105
+ * @param address (optional) - address to connect to
5106
+ * @param providerOrAccount (optional) - Provider or Account to attach to
5107
+ */
4824
5108
  constructor(abi, address, providerOrAccount = defaultProvider) {
4825
5109
  this.address = address && address.toLowerCase();
4826
5110
  this.providerOrAccount = providerOrAccount;
@@ -4983,6 +5267,13 @@ var ContractFactory = class {
4983
5267
  this.classHash = classHash;
4984
5268
  this.CallData = new CallData(abi);
4985
5269
  }
5270
+ /**
5271
+ * Deploys contract and returns new instance of the Contract
5272
+ *
5273
+ * @param args - Array of the constructor arguments for deployment
5274
+ * @param options (optional) Object - parseRequest, parseResponse, addressSalt
5275
+ * @returns deployed Contract
5276
+ */
4986
5277
  async deploy(...args) {
4987
5278
  const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
4988
5279
  const constructorCalldata = getCalldata(param, () => {
@@ -5009,13 +5300,26 @@ var ContractFactory = class {
5009
5300
  contractInstance.deployTransactionHash = transaction_hash;
5010
5301
  return contractInstance;
5011
5302
  }
5303
+ /**
5304
+ * Attaches to new Account
5305
+ *
5306
+ * @param account - new Provider or Account to attach to
5307
+ * @returns ContractFactory
5308
+ */
5012
5309
  connect(account) {
5013
5310
  this.account = account;
5014
5311
  return this;
5015
5312
  }
5313
+ /**
5314
+ * Attaches current abi and account to the new address
5315
+ *
5316
+ * @param address - Contract address
5317
+ * @returns Contract
5318
+ */
5016
5319
  attach(address) {
5017
5320
  return new Contract(this.abi, address, this.account);
5018
5321
  }
5322
+ // ethers.js' getDeployTransaction cant be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
5019
5323
  };
5020
5324
 
5021
5325
  // src/signer/interface.ts
@@ -5594,6 +5898,14 @@ var Account = class extends Provider {
5594
5898
  }
5595
5899
  );
5596
5900
  }
5901
+ /**
5902
+ * First check if contract is already declared, if not declare it
5903
+ * If contract already declared returned transaction_hash is ''.
5904
+ * Method will pass even if contract is already declared
5905
+ * @param payload DeclareContractPayload
5906
+ * @param transactionsDetail (optional) InvocationsDetails = \{\}
5907
+ * @returns DeclareContractResponse
5908
+ */
5597
5909
  async declareIfNot(payload, transactionsDetail = {}) {
5598
5910
  const declareContractPayload = extractContractHashes(payload);
5599
5911
  try {
@@ -5774,6 +6086,9 @@ var Account = class extends Provider {
5774
6086
  }
5775
6087
  return feeEstimate.suggestedMaxFee;
5776
6088
  }
6089
+ /**
6090
+ * will be renamed to buildDeclareContractTransaction
6091
+ */
5777
6092
  async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
5778
6093
  const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
5779
6094
  const contractDefinition = parseContract(contract);