starknet 6.4.2 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -21,7 +21,8 @@ __export(constants_exports, {
21
21
  TRANSACTION_VERSION: () => ETransactionVersion4,
22
22
  TransactionHashPrefix: () => TransactionHashPrefix,
23
23
  UDC: () => UDC,
24
- ZERO: () => ZERO
24
+ ZERO: () => ZERO,
25
+ feeMarginPercentage: () => feeMarginPercentage
25
26
  });
26
27
 
27
28
  // src/types/api/index.ts
@@ -348,6 +349,12 @@ var TransactionHashPrefix = /* @__PURE__ */ ((TransactionHashPrefix2) => {
348
349
  TransactionHashPrefix2["L1_HANDLER"] = "0x6c315f68616e646c6572";
349
350
  return TransactionHashPrefix2;
350
351
  })(TransactionHashPrefix || {});
352
+ var feeMarginPercentage = /* @__PURE__ */ ((feeMarginPercentage2) => {
353
+ feeMarginPercentage2[feeMarginPercentage2["L1_BOUND_MAX_AMOUNT"] = 50] = "L1_BOUND_MAX_AMOUNT";
354
+ feeMarginPercentage2[feeMarginPercentage2["L1_BOUND_MAX_PRICE_PER_UNIT"] = 50] = "L1_BOUND_MAX_PRICE_PER_UNIT";
355
+ feeMarginPercentage2[feeMarginPercentage2["MAX_FEE"] = 50] = "MAX_FEE";
356
+ return feeMarginPercentage2;
357
+ })(feeMarginPercentage || {});
351
358
  var UDC = {
352
359
  ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
353
360
  ENTRYPOINT: "deployContract"
@@ -2837,10 +2844,10 @@ function signatureToDecimalArray(sig) {
2837
2844
  function signatureToHexArray(sig) {
2838
2845
  return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
2839
2846
  }
2840
- function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
2841
- return addPercent(estimatedFee, overhead * 100);
2847
+ function estimatedFeeToMaxFee(estimatedFee, overhead = 50 /* MAX_FEE */) {
2848
+ return addPercent(estimatedFee, overhead);
2842
2849
  }
2843
- function estimateFeeToBounds(estimate, amountOverhead = 10, priceOverhead = 50) {
2850
+ function estimateFeeToBounds(estimate, amountOverhead = 50 /* L1_BOUND_MAX_AMOUNT */, priceOverhead = 50 /* L1_BOUND_MAX_PRICE_PER_UNIT */) {
2844
2851
  if (typeof estimate === "bigint") {
2845
2852
  return {
2846
2853
  l2_gas: { max_amount: "0x0", max_price_per_unit: "0x0" },
@@ -2850,7 +2857,7 @@ function estimateFeeToBounds(estimate, amountOverhead = 10, priceOverhead = 50)
2850
2857
  if (typeof estimate.gas_consumed === "undefined" || typeof estimate.gas_price === "undefined") {
2851
2858
  throw Error("estimateFeeToBounds: estimate is undefined");
2852
2859
  }
2853
- const maxUnits = toHex(addPercent(estimate.gas_consumed, amountOverhead));
2860
+ const maxUnits = estimate.data_gas_consumed !== void 0 && estimate.data_gas_price !== void 0 ? toHex(addPercent(BigInt(estimate.overall_fee) / BigInt(estimate.gas_price), amountOverhead)) : toHex(addPercent(estimate.gas_consumed, amountOverhead));
2854
2861
  const maxUnitPrice = toHex(addPercent(estimate.gas_price, priceOverhead));
2855
2862
  return {
2856
2863
  l2_gas: { max_amount: "0x0", max_price_per_unit: "0x0" },
@@ -4204,6 +4211,20 @@ var RpcChannel2 = class {
4204
4211
 
4205
4212
  // src/utils/responseParser/rpc.ts
4206
4213
  var RPCResponseParser = class {
4214
+ margin;
4215
+ constructor(margin) {
4216
+ this.margin = margin;
4217
+ }
4218
+ estimatedFeeToMaxFee(estimatedFee) {
4219
+ return estimatedFeeToMaxFee(estimatedFee, this.margin?.maxFee);
4220
+ }
4221
+ estimateFeeToBounds(estimate) {
4222
+ return estimateFeeToBounds(
4223
+ estimate,
4224
+ this.margin?.l1BoundMaxAmount,
4225
+ this.margin?.l1BoundMaxPricePerUnit
4226
+ );
4227
+ }
4207
4228
  parseGetBlockResponse(res) {
4208
4229
  return { status: "PENDING", ...res };
4209
4230
  }
@@ -4226,8 +4247,8 @@ var RPCResponseParser = class {
4226
4247
  gas_consumed: toBigInt(val.gas_consumed),
4227
4248
  gas_price: toBigInt(val.gas_price),
4228
4249
  unit: val.unit,
4229
- suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
4230
- resourceBounds: estimateFeeToBounds(val)
4250
+ suggestedMaxFee: this.estimatedFeeToMaxFee(val.overall_fee),
4251
+ resourceBounds: this.estimateFeeToBounds(val)
4231
4252
  };
4232
4253
  }
4233
4254
  parseFeeEstimateBulkResponse(res) {
@@ -4236,16 +4257,16 @@ var RPCResponseParser = class {
4236
4257
  gas_consumed: toBigInt(val.gas_consumed),
4237
4258
  gas_price: toBigInt(val.gas_price),
4238
4259
  unit: val.unit,
4239
- suggestedMaxFee: estimatedFeeToMaxFee(val.overall_fee),
4240
- resourceBounds: estimateFeeToBounds(val)
4260
+ suggestedMaxFee: this.estimatedFeeToMaxFee(val.overall_fee),
4261
+ resourceBounds: this.estimateFeeToBounds(val)
4241
4262
  }));
4242
4263
  }
4243
4264
  parseSimulateTransactionResponse(res) {
4244
4265
  return res.map((it) => {
4245
4266
  return {
4246
4267
  ...it,
4247
- suggestedMaxFee: estimatedFeeToMaxFee(BigInt(it.fee_estimation.overall_fee)),
4248
- resourceBounds: estimateFeeToBounds(it.fee_estimation)
4268
+ suggestedMaxFee: this.estimatedFeeToMaxFee(it.fee_estimation.overall_fee),
4269
+ resourceBounds: this.estimateFeeToBounds(it.fee_estimation)
4249
4270
  };
4250
4271
  });
4251
4272
  }
@@ -4259,13 +4280,15 @@ var RPCResponseParser = class {
4259
4280
 
4260
4281
  // src/provider/rpc.ts
4261
4282
  var RpcProvider = class {
4262
- responseParser = new RPCResponseParser();
4283
+ responseParser;
4263
4284
  channel;
4264
4285
  constructor(optionsOrProvider) {
4265
4286
  if (optionsOrProvider && "channel" in optionsOrProvider) {
4266
4287
  this.channel = optionsOrProvider.channel;
4288
+ this.responseParser = optionsOrProvider.responseParser;
4267
4289
  } else {
4268
4290
  this.channel = new RpcChannel2({ ...optionsOrProvider, waitMode: false });
4291
+ this.responseParser = new RPCResponseParser(optionsOrProvider?.feeMarginPercentage);
4269
4292
  }
4270
4293
  }
4271
4294
  fetch(method, params, id = 0) {
@@ -4358,7 +4381,7 @@ var RpcProvider = class {
4358
4381
  * - skipFeeCharge (default true)<br/>
4359
4382
  */
4360
4383
  async getSimulateTransaction(invocations, options) {
4361
- return this.channel.simulateTransaction(invocations, options).then(this.responseParser.parseSimulateTransactionResponse);
4384
+ return this.channel.simulateTransaction(invocations, options).then((r) => this.responseParser.parseSimulateTransactionResponse(r));
4362
4385
  }
4363
4386
  async waitForTransaction(txHash, options) {
4364
4387
  return this.channel.waitForTransaction(txHash, options);
@@ -4415,7 +4438,7 @@ var RpcProvider = class {
4415
4438
  }
4416
4439
  ],
4417
4440
  { blockIdentifier, skipValidate }
4418
- ).then(this.responseParser.parseFeeEstimateResponse);
4441
+ ).then((r) => this.responseParser.parseFeeEstimateResponse(r));
4419
4442
  }
4420
4443
  async getDeclareEstimateFee(invocation, details, blockIdentifier, skipValidate) {
4421
4444
  return this.channel.getEstimateFee(
@@ -4427,7 +4450,7 @@ var RpcProvider = class {
4427
4450
  }
4428
4451
  ],
4429
4452
  { blockIdentifier, skipValidate }
4430
- ).then(this.responseParser.parseFeeEstimateResponse);
4453
+ ).then((r) => this.responseParser.parseFeeEstimateResponse(r));
4431
4454
  }
4432
4455
  async getDeployAccountEstimateFee(invocation, details, blockIdentifier, skipValidate) {
4433
4456
  return this.channel.getEstimateFee(
@@ -4439,10 +4462,10 @@ var RpcProvider = class {
4439
4462
  }
4440
4463
  ],
4441
4464
  { blockIdentifier, skipValidate }
4442
- ).then(this.responseParser.parseFeeEstimateResponse);
4465
+ ).then((r) => this.responseParser.parseFeeEstimateResponse(r));
4443
4466
  }
4444
4467
  async getEstimateFeeBulk(invocations, options) {
4445
- return this.channel.getEstimateFee(invocations, options).then(this.responseParser.parseFeeEstimateBulkResponse);
4468
+ return this.channel.getEstimateFee(invocations, options).then((r) => this.responseParser.parseFeeEstimateBulkResponse(r));
4446
4469
  }
4447
4470
  async invokeFunction(functionInvocation, details) {
4448
4471
  return this.channel.invoke(functionInvocation, details);