starknet 5.10.2 → 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) {
@@ -2779,8 +2925,8 @@ function parseResponseValue(responseIterator, element, structs) {
2779
2925
  if (isTypeTuple(element.type)) {
2780
2926
  const memberTypes = extractTupleMemberTypes(element.type);
2781
2927
  return memberTypes.reduce((acc, it, idx) => {
2782
- const name = (it == null ? void 0 : it.name) ? it.name : idx;
2783
- 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;
2784
2930
  const el = { name, type };
2785
2931
  acc[name] = parseResponseValue(responseIterator, el, structs);
2786
2932
  return acc;
@@ -2988,6 +3134,12 @@ var CallData = class {
2988
3134
  this.abi = abi;
2989
3135
  this.structs = CallData.getAbiStruct(abi);
2990
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
+ */
2991
3143
  validate(type, method, args = []) {
2992
3144
  if (type !== "DEPLOY") {
2993
3145
  const invocableFunctionNames = this.abi.filter((abi) => {
@@ -3012,14 +3164,41 @@ var CallData = class {
3012
3164
  }
3013
3165
  validateFields(abiMethod, args, this.structs);
3014
3166
  }
3015
- 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
+ }
3016
3191
  const argsIterator = args[Symbol.iterator]();
3017
- const { inputs } = this.abi.find((abi) => abi.name === method);
3018
- return inputs.reduce(
3192
+ return abiMethod.inputs.reduce(
3019
3193
  (acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
3020
3194
  []
3021
3195
  );
3022
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
+ */
3023
3202
  static compile(rawArgs) {
3024
3203
  const createTree = (obj) => {
3025
3204
  const getEntries = (o, prefix = "") => {
@@ -3054,6 +3233,12 @@ var CallData = class {
3054
3233
  });
3055
3234
  return callTreeArray;
3056
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
+ */
3057
3242
  parse(method, response) {
3058
3243
  const { outputs } = this.abi.find((abi) => abi.name === method);
3059
3244
  const responseIterator = response.flat()[Symbol.iterator]();
@@ -3067,13 +3252,30 @@ var CallData = class {
3067
3252
  }, {});
3068
3253
  return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
3069
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
+ */
3070
3262
  format(method, response, format) {
3071
3263
  const parsed = this.parse(method, response);
3072
3264
  return formatter(parsed, format);
3073
3265
  }
3266
+ /**
3267
+ * Helper to calculate inputs from abi
3268
+ * @param inputs AbiEntry
3269
+ * @returns number
3270
+ */
3074
3271
  static abiInputsLength(inputs) {
3075
3272
  return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
3076
3273
  }
3274
+ /**
3275
+ * Helper to extract structs from abi
3276
+ * @param abi Abi
3277
+ * @returns AbiStructs - structs from abi
3278
+ */
3077
3279
  static getAbiStruct(abi) {
3078
3280
  return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
3079
3281
  (acc, abiEntry) => ({
@@ -3083,9 +3285,19 @@ var CallData = class {
3083
3285
  {}
3084
3286
  );
3085
3287
  }
3288
+ /**
3289
+ * Helper: Compile HexCalldata | RawCalldata | RawArgs
3290
+ * @param rawCalldata HexCalldata | RawCalldata | RawArgs
3291
+ * @returns Calldata
3292
+ */
3086
3293
  static toCalldata(rawCalldata = []) {
3087
3294
  return CallData.compile(rawCalldata);
3088
3295
  }
3296
+ /**
3297
+ * Helper: Convert raw to HexCalldata
3298
+ * @param raw HexCalldata | RawCalldata | RawArgs
3299
+ * @returns HexCalldata
3300
+ */
3089
3301
  static toHex(raw = []) {
3090
3302
  const calldata = CallData.compile(raw);
3091
3303
  return calldata.map((it) => toHex(it));
@@ -3094,7 +3306,9 @@ var CallData = class {
3094
3306
 
3095
3307
  // src/utils/fetchPonyfill.ts
3096
3308
  var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
3097
- 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;
3098
3312
 
3099
3313
  // src/utils/hash.ts
3100
3314
  var hash_exports = {};
@@ -3448,6 +3662,7 @@ function parseContract(contract) {
3448
3662
  if (!isSierra(contract)) {
3449
3663
  return {
3450
3664
  ...parsedContract,
3665
+ // TODO: Why do we gzip program object?
3451
3666
  ..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
3452
3667
  };
3453
3668
  }
@@ -3700,6 +3915,7 @@ var Block = class {
3700
3915
  this.tag = "pending";
3701
3916
  }
3702
3917
  }
3918
+ // TODO: fix any
3703
3919
  get queryIdentifier() {
3704
3920
  if (this.number !== null) {
3705
3921
  return `blockNumber=${this.number}`;
@@ -3709,6 +3925,7 @@ var Block = class {
3709
3925
  }
3710
3926
  return `blockNumber=${this.tag}`;
3711
3927
  }
3928
+ // TODO: fix any
3712
3929
  get identifier() {
3713
3930
  if (this.number !== null) {
3714
3931
  return { block_number: this.number };
@@ -3756,17 +3973,17 @@ var RpcProvider = class {
3756
3973
  }
3757
3974
  }
3758
3975
  async fetchEndpoint(method, params) {
3759
- var _a;
3760
3976
  try {
3761
3977
  const rawResult = await this.fetch(method, params);
3762
3978
  const { error, result } = await rawResult.json();
3763
3979
  this.errorHandler(error);
3764
3980
  return result;
3765
3981
  } catch (error) {
3766
- this.errorHandler((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data);
3982
+ this.errorHandler(error?.response?.data);
3767
3983
  throw error;
3768
3984
  }
3769
3985
  }
3986
+ // Methods from Interface
3770
3987
  async getChainId() {
3771
3988
  this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
3772
3989
  return this.chainId;
@@ -3820,6 +4037,7 @@ var RpcProvider = class {
3820
4037
  block_id
3821
4038
  });
3822
4039
  }
4040
+ // Methods from Interface
3823
4041
  async getTransaction(txHash) {
3824
4042
  return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
3825
4043
  }
@@ -3861,9 +4079,9 @@ var RpcProvider = class {
3861
4079
  sender_address: invocation.contractAddress,
3862
4080
  calldata: CallData.toHex(invocation.calldata),
3863
4081
  signature: signatureToHexArray(invocation.signature),
3864
- version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 0),
4082
+ version: toHex(invocationDetails?.version || 0),
3865
4083
  nonce: toHex(invocationDetails.nonce),
3866
- max_fee: toHex((invocationDetails == null ? void 0 : invocationDetails.maxFee) || 0)
4084
+ max_fee: toHex(invocationDetails?.maxFee || 0)
3867
4085
  },
3868
4086
  block_id
3869
4087
  }).then(this.responseParser.parseFeeEstimateResponse);
@@ -3878,12 +4096,13 @@ var RpcProvider = class {
3878
4096
  program: contractDefinition.program,
3879
4097
  entry_points_by_type: contractDefinition.entry_points_by_type,
3880
4098
  abi: contractDefinition.abi
4099
+ // rpc 2.0
3881
4100
  },
3882
4101
  sender_address: senderAddress,
3883
4102
  signature: signatureToHexArray(signature),
3884
- version: toHex((details == null ? void 0 : details.version) || 0),
4103
+ version: toHex(details?.version || 0),
3885
4104
  nonce: toHex(details.nonce),
3886
- max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
4105
+ max_fee: toHex(details?.maxFee || 0)
3887
4106
  },
3888
4107
  block_id
3889
4108
  }).then(this.responseParser.parseFeeEstimateResponse);
@@ -3899,9 +4118,9 @@ var RpcProvider = class {
3899
4118
  class_hash: toHex(classHash),
3900
4119
  contract_address_salt: toHex(addressSalt || 0),
3901
4120
  signature: signatureToHexArray(signature),
3902
- version: toHex((details == null ? void 0 : details.version) || 0),
4121
+ version: toHex(details?.version || 0),
3903
4122
  nonce: toHex(details.nonce),
3904
- max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
4123
+ max_fee: toHex(details?.maxFee || 0)
3905
4124
  },
3906
4125
  block_id
3907
4126
  }).then(this.responseParser.parseFeeEstimateResponse);
@@ -3909,6 +4128,7 @@ var RpcProvider = class {
3909
4128
  async getEstimateFeeBulk(_invocations, _blockIdentifier = this.blockIdentifier) {
3910
4129
  throw new Error("RPC does not implement getInvokeEstimateFeeBulk function");
3911
4130
  }
4131
+ // TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
3912
4132
  async declareContract({ contractDefinition, signature, senderAddress }, details) {
3913
4133
  if ("program" in contractDefinition) {
3914
4134
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
@@ -3917,6 +4137,7 @@ var RpcProvider = class {
3917
4137
  program: contractDefinition.program,
3918
4138
  entry_points_by_type: contractDefinition.entry_points_by_type,
3919
4139
  abi: contractDefinition.abi
4140
+ // rpc 2.0
3920
4141
  },
3921
4142
  type: RPC.TransactionType.DECLARE,
3922
4143
  version: "0x1",
@@ -3956,6 +4177,7 @@ var RpcProvider = class {
3956
4177
  }
3957
4178
  });
3958
4179
  }
4180
+ // Methods from Interface
3959
4181
  async callContract(call, blockIdentifier = this.blockIdentifier) {
3960
4182
  const block_id = new Block(blockIdentifier).identifier;
3961
4183
  const result = await this.fetchEndpoint("starknet_call", {
@@ -3979,8 +4201,8 @@ var RpcProvider = class {
3979
4201
  let { retries } = this;
3980
4202
  let onchain = false;
3981
4203
  let txReceipt = {};
3982
- const retryInterval = (options == null ? void 0 : options.retryInterval) ?? 8e3;
3983
- const successStates = (options == null ? void 0 : options.successStates) ?? [
4204
+ const retryInterval = options?.retryInterval ?? 8e3;
4205
+ const successStates = options?.successStates ?? [
3984
4206
  "ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
3985
4207
  "ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
3986
4208
  "PENDING" /* PENDING */
@@ -4014,16 +4236,41 @@ var RpcProvider = class {
4014
4236
  await wait(retryInterval);
4015
4237
  return txReceipt;
4016
4238
  }
4239
+ /**
4240
+ * Gets the transaction count from a block.
4241
+ *
4242
+ *
4243
+ * @param blockIdentifier
4244
+ * @returns Number of transactions
4245
+ */
4017
4246
  async getTransactionCount(blockIdentifier = this.blockIdentifier) {
4018
4247
  const block_id = new Block(blockIdentifier).identifier;
4019
4248
  return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
4020
4249
  }
4250
+ /**
4251
+ * Gets the latest block number
4252
+ *
4253
+ *
4254
+ * @returns Number of the latest block
4255
+ */
4021
4256
  async getBlockNumber() {
4022
4257
  return this.fetchEndpoint("starknet_blockNumber");
4023
4258
  }
4259
+ /**
4260
+ * Gets syncing status of the node
4261
+ *
4262
+ *
4263
+ * @returns Object with the stats data
4264
+ */
4024
4265
  async getSyncingStats() {
4025
4266
  return this.fetchEndpoint("starknet_syncing");
4026
4267
  }
4268
+ /**
4269
+ * Gets all the events filtered
4270
+ *
4271
+ *
4272
+ * @returns events and the pagination of the events
4273
+ */
4027
4274
  async getEvents(eventFilter) {
4028
4275
  return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
4029
4276
  }
@@ -4074,6 +4321,7 @@ var SequencerAPIResponseParser = class extends ResponseParser {
4074
4321
  transaction_hash: res.transaction_hash,
4075
4322
  status: res.status,
4076
4323
  messages_sent: res.l2_to_l1_messages,
4324
+ // TODO: parse
4077
4325
  events: res.events,
4078
4326
  ..."block_hash" in res && { block_hash: res.block_hash },
4079
4327
  ..."block_number" in res && { block_number: res.block_number },
@@ -4081,6 +4329,7 @@ var SequencerAPIResponseParser = class extends ResponseParser {
4081
4329
  ..."transaction_index" in res && { transaction_index: res.transaction_index },
4082
4330
  ..."execution_resources" in res && { execution_resources: res.execution_resources },
4083
4331
  ..."l1_to_l2_consumed_message" in res && {
4332
+ // eslint-disable-next-line @typescript-eslint/dot-notation
4084
4333
  l1_to_l2_consumed_message: res["l1_to_l2_consumed_message"]
4085
4334
  },
4086
4335
  ..."transaction_failure_reason" in res && {
@@ -4192,6 +4441,7 @@ var SequencerAPIResponseParser = class extends ResponseParser {
4192
4441
  }
4193
4442
  };
4194
4443
  }
4444
+ // TODO: Define response as new type as it diff from ContractClass
4195
4445
  parseSierraContractClassResponse(res) {
4196
4446
  return {
4197
4447
  ...res,
@@ -4253,9 +4503,9 @@ var SequencerProvider = class {
4253
4503
  );
4254
4504
  this.gatewayUrl = buildUrl(this.baseUrl, "gateway", optionsOrProvider.gatewayUrl);
4255
4505
  }
4256
- this.chainId = (optionsOrProvider == null ? void 0 : optionsOrProvider.chainId) ?? SequencerProvider.getChainIdFromBaseUrl(this.baseUrl);
4506
+ this.chainId = optionsOrProvider?.chainId ?? SequencerProvider.getChainIdFromBaseUrl(this.baseUrl);
4257
4507
  this.headers = optionsOrProvider.headers;
4258
- this.blockIdentifier = (optionsOrProvider == null ? void 0 : optionsOrProvider.blockIdentifier) || defaultOptions2.blockIdentifier;
4508
+ this.blockIdentifier = optionsOrProvider?.blockIdentifier || defaultOptions2.blockIdentifier;
4259
4509
  }
4260
4510
  static getNetworkFromName(name) {
4261
4511
  switch (name) {
@@ -4321,6 +4571,7 @@ var SequencerProvider = class {
4321
4571
  }
4322
4572
  return this.headers;
4323
4573
  }
4574
+ // typesafe fetch
4324
4575
  async fetchEndpoint(endpoint, ...[query, request]) {
4325
4576
  const baseUrl = this.getFetchUrl(endpoint);
4326
4577
  const method = this.getFetchMethod(endpoint);
@@ -4333,9 +4584,9 @@ var SequencerProvider = class {
4333
4584
  }
4334
4585
  async fetch(endpoint, options) {
4335
4586
  const url = buildUrl(this.baseUrl, "", endpoint);
4336
- const method = (options == null ? void 0 : options.method) ?? "GET";
4587
+ const method = options?.method ?? "GET";
4337
4588
  const headers = this.getHeaders(method);
4338
- const body = stringify2(options == null ? void 0 : options.body);
4589
+ const body = stringify2(options?.body);
4339
4590
  try {
4340
4591
  const response = await fetchPonyfill_default(url, {
4341
4592
  method,
@@ -4352,7 +4603,7 @@ var SequencerProvider = class {
4352
4603
  }
4353
4604
  throw new GatewayError(responseBody.message, responseBody.code);
4354
4605
  }
4355
- const parseChoice = (options == null ? void 0 : options.parseAlwaysAsBigInt) ? parseAlwaysAsBig : parse2;
4606
+ const parseChoice = options?.parseAlwaysAsBigInt ? parseAlwaysAsBig : parse2;
4356
4607
  return parseChoice(textResponse);
4357
4608
  } catch (error) {
4358
4609
  if (error instanceof Error && !(error instanceof LibraryError))
@@ -4368,6 +4619,9 @@ var SequencerProvider = class {
4368
4619
  "call_contract",
4369
4620
  { blockIdentifier },
4370
4621
  {
4622
+ // TODO - determine best choice once both are fully supported in devnet
4623
+ // signature: [],
4624
+ // sender_address: contractAddress,
4371
4625
  contract_address: contractAddress,
4372
4626
  entry_point_selector: getSelectorFromName(entryPointSelector),
4373
4627
  calldata: CallData.compile(calldata)
@@ -4486,7 +4740,7 @@ var SequencerProvider = class {
4486
4740
  sender_address: invocation.contractAddress,
4487
4741
  calldata: CallData.compile(invocation.calldata ?? []),
4488
4742
  signature: signatureToDecimalArray(invocation.signature),
4489
- version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
4743
+ version: toHex(invocationDetails?.version || 1),
4490
4744
  nonce: toHex(invocationDetails.nonce)
4491
4745
  }
4492
4746
  ).then(this.responseParser.parseFeeEstimateResponse);
@@ -4501,7 +4755,7 @@ var SequencerProvider = class {
4501
4755
  sender_address: senderAddress,
4502
4756
  contract_class: contractDefinition,
4503
4757
  signature: signatureToDecimalArray(signature),
4504
- version: toHex((details == null ? void 0 : details.version) || toBigInt(feeTransactionVersion)),
4758
+ version: toHex(details?.version || toBigInt(feeTransactionVersion)),
4505
4759
  nonce: toHex(details.nonce)
4506
4760
  }
4507
4761
  ).then(this.responseParser.parseFeeEstimateResponse);
@@ -4530,7 +4784,7 @@ var SequencerProvider = class {
4530
4784
  constructor_calldata: CallData.compile(constructorCalldata || []),
4531
4785
  contract_address_salt: toHex(addressSalt || 0),
4532
4786
  signature: signatureToDecimalArray(signature),
4533
- version: toHex((details == null ? void 0 : details.version) || 0),
4787
+ version: toHex(details?.version || 0),
4534
4788
  nonce: toHex(details.nonce)
4535
4789
  }
4536
4790
  ).then(this.responseParser.parseFeeEstimateResponse);
@@ -4561,7 +4815,7 @@ var SequencerProvider = class {
4561
4815
  return {
4562
4816
  ...res,
4563
4817
  signature: bigNumberishArrayToDecimalStringArray(formatSignature(invocation.signature)),
4564
- version: toHex(toBigInt((invocation == null ? void 0 : invocation.version) || 1)),
4818
+ version: toHex(toBigInt(invocation?.version || 1)),
4565
4819
  nonce: toHex(toBigInt(invocation.nonce))
4566
4820
  };
4567
4821
  });
@@ -4576,8 +4830,8 @@ var SequencerProvider = class {
4576
4830
  const errorStates = ["REJECTED" /* REJECTED */, "NOT_RECEIVED" /* NOT_RECEIVED */];
4577
4831
  let onchain = false;
4578
4832
  let res;
4579
- const retryInterval = (options == null ? void 0 : options.retryInterval) ?? 8e3;
4580
- const successStates = (options == null ? void 0 : options.successStates) ?? [
4833
+ const retryInterval = options?.retryInterval ?? 8e3;
4834
+ const successStates = options?.successStates ?? [
4581
4835
  "ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
4582
4836
  "ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
4583
4837
  "PENDING" /* PENDING */
@@ -4598,13 +4852,33 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
4598
4852
  const txReceipt = await this.getTransactionReceipt(txHash);
4599
4853
  return txReceipt;
4600
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
+ */
4601
4863
  async getTransactionStatus(txHash) {
4602
4864
  const txHashHex = toHex(txHash);
4603
4865
  return this.fetchEndpoint("get_transaction_status", { transactionHash: txHashHex });
4604
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
+ */
4605
4873
  async getContractAddresses() {
4606
4874
  return this.fetchEndpoint("get_contract_addresses");
4607
4875
  }
4876
+ /**
4877
+ * Gets the transaction trace from a tx id.
4878
+ *
4879
+ * @param txHash
4880
+ * @returns the transaction trace
4881
+ */
4608
4882
  async getTransactionTrace(txHash) {
4609
4883
  const txHashHex = toHex(txHash);
4610
4884
  return this.fetchEndpoint("get_transaction_trace", { transactionHash: txHashHex });
@@ -4627,9 +4901,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
4627
4901
  sender_address: invocation.contractAddress,
4628
4902
  calldata: CallData.compile(invocation.calldata ?? []),
4629
4903
  signature: signatureToDecimalArray(invocation.signature),
4630
- version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
4904
+ version: toHex(invocationDetails?.version || 1),
4631
4905
  nonce: toHex(invocationDetails.nonce),
4632
- max_fee: toHex((invocationDetails == null ? void 0 : invocationDetails.maxFee) || 0)
4906
+ max_fee: toHex(invocationDetails?.maxFee || 0)
4633
4907
  }
4634
4908
  ).then(this.responseParser.parseFeeSimulateTransactionResponse);
4635
4909
  }
@@ -4639,6 +4913,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
4639
4913
  this.responseParser.parseGetStateUpdateResponse
4640
4914
  );
4641
4915
  }
4916
+ // consider adding an optional trace retrieval parameter to the getBlock method
4642
4917
  async getBlockTraces(blockIdentifier = this.blockIdentifier) {
4643
4918
  const args = new Block(blockIdentifier).sequencerIdentifier;
4644
4919
  return this.fetchEndpoint("get_block_traces", { ...args });
@@ -4823,6 +5098,13 @@ function getCalldata(args, callback) {
4823
5098
  return callback();
4824
5099
  }
4825
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
+ */
4826
5108
  constructor(abi, address, providerOrAccount = defaultProvider) {
4827
5109
  this.address = address && address.toLowerCase();
4828
5110
  this.providerOrAccount = providerOrAccount;
@@ -4985,6 +5267,13 @@ var ContractFactory = class {
4985
5267
  this.classHash = classHash;
4986
5268
  this.CallData = new CallData(abi);
4987
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
+ */
4988
5277
  async deploy(...args) {
4989
5278
  const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
4990
5279
  const constructorCalldata = getCalldata(param, () => {
@@ -5011,13 +5300,26 @@ var ContractFactory = class {
5011
5300
  contractInstance.deployTransactionHash = transaction_hash;
5012
5301
  return contractInstance;
5013
5302
  }
5303
+ /**
5304
+ * Attaches to new Account
5305
+ *
5306
+ * @param account - new Provider or Account to attach to
5307
+ * @returns ContractFactory
5308
+ */
5014
5309
  connect(account) {
5015
5310
  this.account = account;
5016
5311
  return this;
5017
5312
  }
5313
+ /**
5314
+ * Attaches current abi and account to the new address
5315
+ *
5316
+ * @param address - Contract address
5317
+ * @returns Contract
5318
+ */
5018
5319
  attach(address) {
5019
5320
  return new Contract(this.abi, address, this.account);
5020
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
5021
5323
  };
5022
5324
 
5023
5325
  // src/signer/interface.ts
@@ -5596,6 +5898,14 @@ var Account = class extends Provider {
5596
5898
  }
5597
5899
  );
5598
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
+ */
5599
5909
  async declareIfNot(payload, transactionsDetail = {}) {
5600
5910
  const declareContractPayload = extractContractHashes(payload);
5601
5911
  try {
@@ -5776,6 +6086,9 @@ var Account = class extends Provider {
5776
6086
  }
5777
6087
  return feeEstimate.suggestedMaxFee;
5778
6088
  }
6089
+ /**
6090
+ * will be renamed to buildDeclareContractTransaction
6091
+ */
5779
6092
  async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
5780
6093
  const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
5781
6094
  const contractDefinition = parseContract(contract);