@fuel-ts/account 0.0.0-rc-2037-20240430170043 → 0.0.0-rc-2037-20240501112942

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.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

package/dist/index.js CHANGED
@@ -104,8 +104,8 @@ __export(src_exports, {
104
104
  assets: () => assets,
105
105
  buildBlockExplorerUrl: () => buildBlockExplorerUrl,
106
106
  cacheFor: () => cacheFor,
107
- cacheResources: () => cacheResources,
108
- cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
107
+ cacheRequestInputsResources: () => cacheRequestInputsResources,
108
+ cacheRequestInputsResourcesFromOwner: () => cacheRequestInputsResourcesFromOwner,
109
109
  calculateGasFee: () => calculateGasFee,
110
110
  calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
111
111
  calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
@@ -118,6 +118,7 @@ __export(src_exports, {
118
118
  extractMintedAssetsFromReceipts: () => extractMintedAssetsFromReceipts,
119
119
  extractTxError: () => extractTxError,
120
120
  gasUsedByInputs: () => gasUsedByInputs,
121
+ getAssetAmountInRequestInputs: () => getAssetAmountInRequestInputs,
121
122
  getAssetEth: () => getAssetEth,
122
123
  getAssetFuel: () => getAssetFuel,
123
124
  getAssetNetwork: () => getAssetNetwork,
@@ -193,7 +194,7 @@ module.exports = __toCommonJS(src_exports);
193
194
  var import_address4 = require("@fuel-ts/address");
194
195
  var import_errors16 = require("@fuel-ts/errors");
195
196
  var import_interfaces = require("@fuel-ts/interfaces");
196
- var import_math19 = require("@fuel-ts/math");
197
+ var import_math20 = require("@fuel-ts/math");
197
198
  var import_utils27 = require("@fuel-ts/utils");
198
199
  var import_ramda4 = require("ramda");
199
200
 
@@ -235,7 +236,7 @@ var addAmountToCoinQuantities = (params) => {
235
236
  // src/providers/provider.ts
236
237
  var import_address3 = require("@fuel-ts/address");
237
238
  var import_errors14 = require("@fuel-ts/errors");
238
- var import_math16 = require("@fuel-ts/math");
239
+ var import_math17 = require("@fuel-ts/math");
239
240
  var import_transactions20 = require("@fuel-ts/transactions");
240
241
  var import_utils22 = require("@fuel-ts/utils");
241
242
  var import_versions = require("@fuel-ts/versions");
@@ -1402,7 +1403,7 @@ var import_abi_coder2 = require("@fuel-ts/abi-coder");
1402
1403
  var import_address = require("@fuel-ts/address");
1403
1404
  var import_configs6 = require("@fuel-ts/address/configs");
1404
1405
  var import_crypto = require("@fuel-ts/crypto");
1405
- var import_math7 = require("@fuel-ts/math");
1406
+ var import_math8 = require("@fuel-ts/math");
1406
1407
  var import_transactions7 = require("@fuel-ts/transactions");
1407
1408
  var import_utils9 = require("@fuel-ts/utils");
1408
1409
 
@@ -1774,7 +1775,7 @@ function calculateMetadataGasForTxScript({
1774
1775
  }
1775
1776
  var calculateGasFee = (params) => {
1776
1777
  const { gas, gasPrice, priceFactor, tip } = params;
1777
- return gas.mul(gasPrice).div(priceFactor).add(tip);
1778
+ return gas.mul(gasPrice).div(priceFactor).add((0, import_math5.bn)(tip));
1778
1779
  };
1779
1780
 
1780
1781
  // src/providers/utils/json.ts
@@ -1912,18 +1913,28 @@ var NoWitnessByOwnerError = class extends Error {
1912
1913
  };
1913
1914
 
1914
1915
  // src/providers/transaction-request/helpers.ts
1916
+ var import_math7 = require("@fuel-ts/math");
1915
1917
  var import_transactions6 = require("@fuel-ts/transactions");
1916
1918
  var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
1917
1919
  var isRequestInputMessage = (input) => input.type === import_transactions6.InputType.Message;
1918
1920
  var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
1919
1921
  var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
1920
1922
  var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
1921
- var cacheResources = (resources) => resources.reduce(
1922
- (cache2, resource) => {
1923
- if (isCoin(resource)) {
1924
- cache2.utxos.push(resource.id);
1923
+ var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
1924
+ if (isRequestInputCoin(input) && input.assetId === assetId) {
1925
+ return acc.add(input.amount);
1926
+ }
1927
+ if (isRequestInputMessage(input) && assetId === baseAsset) {
1928
+ return acc.add(input.amount);
1929
+ }
1930
+ return acc;
1931
+ }, (0, import_math7.bn)(0));
1932
+ var cacheRequestInputsResources = (inputs) => inputs.filter(isRequestInputResource).reduce(
1933
+ (cache2, input) => {
1934
+ if (isRequestInputCoin(input)) {
1935
+ cache2.utxos.push(input.id);
1925
1936
  } else {
1926
- cache2.messages.push(resource.nonce);
1937
+ cache2.messages.push(input.nonce);
1927
1938
  }
1928
1939
  return cache2;
1929
1940
  },
@@ -1932,6 +1943,20 @@ var cacheResources = (resources) => resources.reduce(
1932
1943
  messages: []
1933
1944
  }
1934
1945
  );
1946
+ var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
1947
+ (acc, input) => {
1948
+ if (isRequestInputCoin(input) && input.owner === owner.toB256()) {
1949
+ acc.utxos.push(input.id);
1950
+ } else if (isRequestInputMessage(input) && input.recipient === owner.toB256()) {
1951
+ acc.messages.push(input.nonce);
1952
+ }
1953
+ return acc;
1954
+ },
1955
+ {
1956
+ utxos: [],
1957
+ messages: []
1958
+ }
1959
+ );
1935
1960
 
1936
1961
  // src/providers/transaction-request/witness.ts
1937
1962
  var import_utils8 = require("@fuel-ts/utils");
@@ -1973,10 +1998,10 @@ var BaseTransactionRequest = class {
1973
1998
  outputs,
1974
1999
  witnesses
1975
2000
  } = {}) {
1976
- this.tip = (0, import_math7.bn)(tip);
1977
- this.maturity = maturity ?? 0;
1978
- this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
1979
- this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
2001
+ this.tip = tip ? (0, import_math8.bn)(tip) : void 0;
2002
+ this.maturity = maturity && maturity > 0 ? maturity : void 0;
2003
+ this.witnessLimit = (0, import_utils9.isDefined)(witnessLimit) ? (0, import_math8.bn)(witnessLimit) : void 0;
2004
+ this.maxFee = (0, import_math8.bn)(maxFee);
1980
2005
  this.inputs = inputs ?? [];
1981
2006
  this.outputs = outputs ?? [];
1982
2007
  this.witnesses = witnesses ?? [];
@@ -1984,22 +2009,21 @@ var BaseTransactionRequest = class {
1984
2009
  static getPolicyMeta(req) {
1985
2010
  let policyTypes = 0;
1986
2011
  const policies = [];
1987
- if (req.tip) {
2012
+ const { tip, witnessLimit, maturity } = req;
2013
+ if ((0, import_math8.bn)(tip).gt(0)) {
1988
2014
  policyTypes += import_transactions7.PolicyType.Tip;
1989
- policies.push({ data: req.tip, type: import_transactions7.PolicyType.Tip });
2015
+ policies.push({ data: (0, import_math8.bn)(tip), type: import_transactions7.PolicyType.Tip });
1990
2016
  }
1991
- if (req.witnessLimit) {
2017
+ if ((0, import_utils9.isDefined)(witnessLimit) && (0, import_math8.bn)(witnessLimit).gte(0)) {
1992
2018
  policyTypes += import_transactions7.PolicyType.WitnessLimit;
1993
- policies.push({ data: req.witnessLimit, type: import_transactions7.PolicyType.WitnessLimit });
2019
+ policies.push({ data: (0, import_math8.bn)(witnessLimit), type: import_transactions7.PolicyType.WitnessLimit });
1994
2020
  }
1995
- if (req.maturity > 0) {
2021
+ if (maturity && maturity > 0) {
1996
2022
  policyTypes += import_transactions7.PolicyType.Maturity;
1997
- policies.push({ data: req.maturity, type: import_transactions7.PolicyType.Maturity });
1998
- }
1999
- if (req.maxFee) {
2000
- policyTypes += import_transactions7.PolicyType.MaxFee;
2001
- policies.push({ data: req.maxFee, type: import_transactions7.PolicyType.MaxFee });
2023
+ policies.push({ data: maturity, type: import_transactions7.PolicyType.Maturity });
2002
2024
  }
2025
+ policyTypes += import_transactions7.PolicyType.MaxFee;
2026
+ policies.push({ data: req.maxFee, type: import_transactions7.PolicyType.MaxFee });
2003
2027
  return {
2004
2028
  policyTypes,
2005
2029
  policies
@@ -2360,7 +2384,7 @@ var BaseTransactionRequest = class {
2360
2384
  const assetInput = findAssetInput(assetId);
2361
2385
  let usedQuantity = quantity;
2362
2386
  if (assetId === baseAssetId) {
2363
- usedQuantity = (0, import_math7.bn)("1000000000000000000");
2387
+ usedQuantity = (0, import_math8.bn)("1000000000000000000");
2364
2388
  }
2365
2389
  if (assetInput && "assetId" in assetInput) {
2366
2390
  assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
@@ -2372,13 +2396,13 @@ var BaseTransactionRequest = class {
2372
2396
  amount: usedQuantity,
2373
2397
  assetId,
2374
2398
  owner: resourcesOwner || import_address.Address.fromRandom(),
2375
- blockCreated: (0, import_math7.bn)(1),
2376
- txCreatedIdx: (0, import_math7.bn)(1)
2399
+ blockCreated: (0, import_math8.bn)(1),
2400
+ txCreatedIdx: (0, import_math8.bn)(1)
2377
2401
  }
2378
2402
  ]);
2379
2403
  }
2380
2404
  };
2381
- updateAssetInput(baseAssetId, (0, import_math7.bn)(1e11));
2405
+ updateAssetInput(baseAssetId, (0, import_math8.bn)(1e11));
2382
2406
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2383
2407
  }
2384
2408
  /**
@@ -2389,7 +2413,7 @@ var BaseTransactionRequest = class {
2389
2413
  */
2390
2414
  getCoinOutputsQuantities() {
2391
2415
  const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
2392
- amount: (0, import_math7.bn)(amount),
2416
+ amount: (0, import_math8.bn)(amount),
2393
2417
  assetId: assetId.toString()
2394
2418
  }));
2395
2419
  return coinsQuantities;
@@ -2429,7 +2453,7 @@ var BaseTransactionRequest = class {
2429
2453
  default:
2430
2454
  return;
2431
2455
  }
2432
- if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math7.bn)(correspondingInput.predicateGasUsed).gt(0)) {
2456
+ if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math8.bn)(correspondingInput.predicateGasUsed).gt(0)) {
2433
2457
  i.predicate = correspondingInput.predicate;
2434
2458
  i.predicateData = correspondingInput.predicateData;
2435
2459
  i.predicateGasUsed = correspondingInput.predicateGasUsed;
@@ -2449,14 +2473,14 @@ var BaseTransactionRequest = class {
2449
2473
 
2450
2474
  // src/providers/transaction-request/create-transaction-request.ts
2451
2475
  var import_configs8 = require("@fuel-ts/address/configs");
2452
- var import_math9 = require("@fuel-ts/math");
2476
+ var import_math10 = require("@fuel-ts/math");
2453
2477
  var import_transactions9 = require("@fuel-ts/transactions");
2454
2478
  var import_utils13 = require("@fuel-ts/utils");
2455
2479
 
2456
2480
  // src/providers/transaction-request/hash-transaction.ts
2457
2481
  var import_configs7 = require("@fuel-ts/address/configs");
2458
2482
  var import_hasher = require("@fuel-ts/hasher");
2459
- var import_math8 = require("@fuel-ts/math");
2483
+ var import_math9 = require("@fuel-ts/math");
2460
2484
  var import_transactions8 = require("@fuel-ts/transactions");
2461
2485
  var import_utils11 = require("@fuel-ts/utils");
2462
2486
  var import_ramda2 = require("ramda");
@@ -2473,11 +2497,11 @@ function hashTransaction(transactionRequest, chainId) {
2473
2497
  blockHeight: 0,
2474
2498
  txIndex: 0
2475
2499
  };
2476
- inputClone.predicateGasUsed = (0, import_math8.bn)(0);
2500
+ inputClone.predicateGasUsed = (0, import_math9.bn)(0);
2477
2501
  return inputClone;
2478
2502
  }
2479
2503
  case import_transactions8.InputType.Message: {
2480
- inputClone.predicateGasUsed = (0, import_math8.bn)(0);
2504
+ inputClone.predicateGasUsed = (0, import_math9.bn)(0);
2481
2505
  return inputClone;
2482
2506
  }
2483
2507
  case import_transactions8.InputType.Contract: {
@@ -2504,12 +2528,12 @@ function hashTransaction(transactionRequest, chainId) {
2504
2528
  return outputClone;
2505
2529
  }
2506
2530
  case import_transactions8.OutputType.Change: {
2507
- outputClone.amount = (0, import_math8.bn)(0);
2531
+ outputClone.amount = (0, import_math9.bn)(0);
2508
2532
  return outputClone;
2509
2533
  }
2510
2534
  case import_transactions8.OutputType.Variable: {
2511
2535
  outputClone.to = import_configs7.ZeroBytes32;
2512
- outputClone.amount = (0, import_math8.bn)(0);
2536
+ outputClone.amount = (0, import_math9.bn)(0);
2513
2537
  outputClone.assetId = import_configs7.ZeroBytes32;
2514
2538
  return outputClone;
2515
2539
  }
@@ -2587,7 +2611,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2587
2611
  type: import_transactions9.TransactionType.Create,
2588
2612
  ...baseTransaction,
2589
2613
  bytecodeWitnessIndex,
2590
- storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
2614
+ storageSlotsCount: (0, import_math10.bn)(storageSlots.length),
2591
2615
  salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2592
2616
  storageSlots
2593
2617
  };
@@ -2627,7 +2651,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2627
2651
  }
2628
2652
  metadataGas(gasCosts) {
2629
2653
  return calculateMetadataGasForTxCreate({
2630
- contractBytesSize: (0, import_math9.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2654
+ contractBytesSize: (0, import_math10.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2631
2655
  gasCosts,
2632
2656
  stateRootSize: this.storageSlots.length,
2633
2657
  txBytesSize: this.byteSize()
@@ -2639,7 +2663,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2639
2663
  var import_abi_coder3 = require("@fuel-ts/abi-coder");
2640
2664
  var import_address2 = require("@fuel-ts/address");
2641
2665
  var import_configs9 = require("@fuel-ts/address/configs");
2642
- var import_math10 = require("@fuel-ts/math");
2666
+ var import_math11 = require("@fuel-ts/math");
2643
2667
  var import_transactions10 = require("@fuel-ts/transactions");
2644
2668
  var import_utils15 = require("@fuel-ts/utils");
2645
2669
 
@@ -2693,7 +2717,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2693
2717
  */
2694
2718
  constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2695
2719
  super(rest);
2696
- this.gasLimit = (0, import_math10.bn)(gasLimit);
2720
+ this.gasLimit = (0, import_math11.bn)(gasLimit);
2697
2721
  this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
2698
2722
  this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
2699
2723
  this.abis = rest.abis;
@@ -2710,8 +2734,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2710
2734
  type: import_transactions10.TransactionType.Script,
2711
2735
  scriptGasLimit: this.gasLimit,
2712
2736
  ...super.getBaseTransaction(),
2713
- scriptLength: (0, import_math10.bn)(script.length),
2714
- scriptDataLength: (0, import_math10.bn)(scriptData.length),
2737
+ scriptLength: (0, import_math11.bn)(script.length),
2738
+ scriptDataLength: (0, import_math11.bn)(scriptData.length),
2715
2739
  receiptsRoot: import_configs9.ZeroBytes32,
2716
2740
  script: (0, import_utils15.hexlify)(script),
2717
2741
  scriptData: (0, import_utils15.hexlify)(scriptData)
@@ -2861,35 +2885,20 @@ var transactionRequestify = (obj) => {
2861
2885
  }
2862
2886
  }
2863
2887
  };
2864
- var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2865
- (acc, input) => {
2866
- if (input.type === import_transactions11.InputType.Coin && input.owner === owner) {
2867
- acc.utxos.push(input.id);
2868
- }
2869
- if (input.type === import_transactions11.InputType.Message && input.recipient === owner) {
2870
- acc.messages.push(input.nonce);
2871
- }
2872
- return acc;
2873
- },
2874
- {
2875
- utxos: [],
2876
- messages: []
2877
- }
2878
- );
2879
2888
 
2880
2889
  // src/providers/transaction-response/transaction-response.ts
2881
2890
  var import_errors13 = require("@fuel-ts/errors");
2882
- var import_math15 = require("@fuel-ts/math");
2891
+ var import_math16 = require("@fuel-ts/math");
2883
2892
  var import_transactions19 = require("@fuel-ts/transactions");
2884
2893
  var import_utils20 = require("@fuel-ts/utils");
2885
2894
 
2886
2895
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2887
- var import_math14 = require("@fuel-ts/math");
2896
+ var import_math15 = require("@fuel-ts/math");
2888
2897
  var import_transactions17 = require("@fuel-ts/transactions");
2889
2898
  var import_utils18 = require("@fuel-ts/utils");
2890
2899
 
2891
2900
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2892
- var import_math11 = require("@fuel-ts/math");
2901
+ var import_math12 = require("@fuel-ts/math");
2893
2902
  var import_transactions12 = require("@fuel-ts/transactions");
2894
2903
  var import_utils16 = require("@fuel-ts/utils");
2895
2904
  var calculateTransactionFee = (params) => {
@@ -2899,23 +2908,23 @@ var calculateTransactionFee = (params) => {
2899
2908
  tip,
2900
2909
  consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2901
2910
  } = params;
2902
- const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
2903
- const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
2911
+ const gasPerByte = (0, import_math12.bn)(feeParams.gasPerByte);
2912
+ const gasPriceFactor = (0, import_math12.bn)(feeParams.gasPriceFactor);
2904
2913
  const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
2905
2914
  const [transaction] = new import_transactions12.TransactionCoder().decode(transactionBytes, 0);
2906
2915
  if (transaction.type === import_transactions12.TransactionType.Mint) {
2907
2916
  return {
2908
- fee: (0, import_math11.bn)(0),
2909
- minFee: (0, import_math11.bn)(0),
2910
- maxFee: (0, import_math11.bn)(0)
2917
+ fee: (0, import_math12.bn)(0),
2918
+ minFee: (0, import_math12.bn)(0),
2919
+ maxFee: (0, import_math12.bn)(0)
2911
2920
  };
2912
2921
  }
2913
2922
  const { type, witnesses, inputs, policies } = transaction;
2914
- let metadataGas = (0, import_math11.bn)(0);
2915
- let gasLimit = (0, import_math11.bn)(0);
2923
+ let metadataGas = (0, import_math12.bn)(0);
2924
+ let gasLimit = (0, import_math12.bn)(0);
2916
2925
  if (type === import_transactions12.TransactionType.Create) {
2917
2926
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2918
- const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
2927
+ const contractBytesSize = (0, import_math12.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
2919
2928
  metadataGas = calculateMetadataGasForTxCreate({
2920
2929
  contractBytesSize,
2921
2930
  gasCosts,
@@ -2934,7 +2943,7 @@ var calculateTransactionFee = (params) => {
2934
2943
  }
2935
2944
  const minGas = getMinGas({
2936
2945
  gasCosts,
2937
- gasPerByte: (0, import_math11.bn)(gasPerByte),
2946
+ gasPerByte: (0, import_math12.bn)(gasPerByte),
2938
2947
  inputs,
2939
2948
  metadataGas,
2940
2949
  txBytesSize: transactionBytes.length
@@ -2971,12 +2980,12 @@ var calculateTransactionFee = (params) => {
2971
2980
  // src/providers/transaction-summary/operations.ts
2972
2981
  var import_configs10 = require("@fuel-ts/address/configs");
2973
2982
  var import_errors11 = require("@fuel-ts/errors");
2974
- var import_math13 = require("@fuel-ts/math");
2983
+ var import_math14 = require("@fuel-ts/math");
2975
2984
  var import_transactions15 = require("@fuel-ts/transactions");
2976
2985
 
2977
2986
  // src/providers/transaction-summary/call.ts
2978
2987
  var import_abi_coder4 = require("@fuel-ts/abi-coder");
2979
- var import_math12 = require("@fuel-ts/math");
2988
+ var import_math13 = require("@fuel-ts/math");
2980
2989
  var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2981
2990
  const abiInterface = new import_abi_coder4.Interface(abi);
2982
2991
  const callFunctionSelector = receipt.param1.toHex(8);
@@ -2985,7 +2994,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2985
2994
  let encodedArgs;
2986
2995
  if (functionFragment.isInputDataPointer) {
2987
2996
  if (rawPayload) {
2988
- const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder4.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
2997
+ const argsOffset = (0, import_math13.bn)(receipt.param2).sub((0, import_abi_coder4.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
2989
2998
  encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
2990
2999
  }
2991
3000
  } else {
@@ -3185,7 +3194,7 @@ var mergeAssets = (op1, op2) => {
3185
3194
  if (!matchingAsset) {
3186
3195
  return asset1;
3187
3196
  }
3188
- const mergedAmount = (0, import_math13.bn)(asset1.amount).add(matchingAsset.amount);
3197
+ const mergedAmount = (0, import_math14.bn)(asset1.amount).add(matchingAsset.amount);
3189
3198
  return { ...asset1, amount: mergedAmount };
3190
3199
  });
3191
3200
  return mergedAssets.concat(filteredAssets);
@@ -3594,7 +3603,7 @@ function assembleTransactionSummary(params) {
3594
3603
  maxInputs
3595
3604
  });
3596
3605
  const typeName = getTransactionTypeName(transaction.type);
3597
- const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions17.PolicyType.Tip)?.data);
3606
+ const tip = (0, import_math15.bn)(transaction.policies?.find((policy) => policy.type === import_transactions17.PolicyType.Tip)?.data);
3598
3607
  const { fee } = calculateTransactionFee({
3599
3608
  gasPrice,
3600
3609
  rawPayload,
@@ -3661,7 +3670,7 @@ var TransactionResponse = class {
3661
3670
  /** Current provider */
3662
3671
  provider;
3663
3672
  /** Gas used on the transaction */
3664
- gasUsed = (0, import_math15.bn)(0);
3673
+ gasUsed = (0, import_math16.bn)(0);
3665
3674
  /** The graphql Transaction with receipts object. */
3666
3675
  gqlTransaction;
3667
3676
  abis;
@@ -3885,30 +3894,30 @@ var processGqlChain = (chain) => {
3885
3894
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3886
3895
  return {
3887
3896
  name,
3888
- baseChainHeight: (0, import_math16.bn)(daHeight),
3897
+ baseChainHeight: (0, import_math17.bn)(daHeight),
3889
3898
  consensusParameters: {
3890
- contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
3891
- maxInputs: (0, import_math16.bn)(txParams.maxInputs),
3892
- maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
3893
- maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
3894
- maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
3895
- maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
3896
- maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
3897
- maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
3898
- maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
3899
- maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
3900
- maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
3901
- gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
3902
- gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
3903
- maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
3904
- chainId: (0, import_math16.bn)(consensusParameters.chainId),
3899
+ contractMaxSize: (0, import_math17.bn)(contractParams.contractMaxSize),
3900
+ maxInputs: (0, import_math17.bn)(txParams.maxInputs),
3901
+ maxOutputs: (0, import_math17.bn)(txParams.maxOutputs),
3902
+ maxWitnesses: (0, import_math17.bn)(txParams.maxWitnesses),
3903
+ maxGasPerTx: (0, import_math17.bn)(txParams.maxGasPerTx),
3904
+ maxScriptLength: (0, import_math17.bn)(scriptParams.maxScriptLength),
3905
+ maxScriptDataLength: (0, import_math17.bn)(scriptParams.maxScriptDataLength),
3906
+ maxStorageSlots: (0, import_math17.bn)(contractParams.maxStorageSlots),
3907
+ maxPredicateLength: (0, import_math17.bn)(predicateParams.maxPredicateLength),
3908
+ maxPredicateDataLength: (0, import_math17.bn)(predicateParams.maxPredicateDataLength),
3909
+ maxGasPerPredicate: (0, import_math17.bn)(predicateParams.maxGasPerPredicate),
3910
+ gasPriceFactor: (0, import_math17.bn)(feeParams.gasPriceFactor),
3911
+ gasPerByte: (0, import_math17.bn)(feeParams.gasPerByte),
3912
+ maxMessageDataLength: (0, import_math17.bn)(predicateParams.maxMessageDataLength),
3913
+ chainId: (0, import_math17.bn)(consensusParameters.chainId),
3905
3914
  baseAssetId: consensusParameters.baseAssetId,
3906
3915
  gasCosts
3907
3916
  },
3908
3917
  gasCosts,
3909
3918
  latestBlock: {
3910
3919
  id: latestBlock.id,
3911
- height: (0, import_math16.bn)(latestBlock.height),
3920
+ height: (0, import_math17.bn)(latestBlock.height),
3912
3921
  time: latestBlock.header.time,
3913
3922
  transactions: latestBlock.transactions.map((i) => ({
3914
3923
  id: i.id
@@ -4051,7 +4060,18 @@ var _Provider = class {
4051
4060
  createOperations() {
4052
4061
  const fetchFn = _Provider.getFetchFn(this.options);
4053
4062
  const gqlClient = new import_graphql_request.GraphQLClient(this.url, {
4054
- fetch: (url, requestInit) => fetchFn(url, requestInit, this.options)
4063
+ fetch: (url, requestInit) => fetchFn(url, requestInit, this.options),
4064
+ responseMiddleware: (response) => {
4065
+ if ("response" in response) {
4066
+ const graphQlResponse = response.response;
4067
+ if (Array.isArray(graphQlResponse?.errors)) {
4068
+ throw new import_errors14.FuelError(
4069
+ import_errors14.FuelError.CODES.INVALID_REQUEST,
4070
+ graphQlResponse.errors.map((err) => err.message).join("\n\n")
4071
+ );
4072
+ }
4073
+ }
4074
+ }
4055
4075
  });
4056
4076
  const executeQuery = (query, vars) => {
4057
4077
  const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
@@ -4086,7 +4106,7 @@ var _Provider = class {
4086
4106
  */
4087
4107
  async getBlockNumber() {
4088
4108
  const { chain } = await this.operations.getChain();
4089
- return (0, import_math16.bn)(chain.latestBlock.height, 10);
4109
+ return (0, import_math17.bn)(chain.latestBlock.height, 10);
4090
4110
  }
4091
4111
  /**
4092
4112
  * Returns the chain information.
@@ -4096,8 +4116,8 @@ var _Provider = class {
4096
4116
  async fetchNode() {
4097
4117
  const { nodeInfo } = await this.operations.getNodeInfo();
4098
4118
  const processedNodeInfo = {
4099
- maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
4100
- maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
4119
+ maxDepth: (0, import_math17.bn)(nodeInfo.maxDepth),
4120
+ maxTx: (0, import_math17.bn)(nodeInfo.maxTx),
4101
4121
  nodeVersion: nodeInfo.nodeVersion,
4102
4122
  utxoValidation: nodeInfo.utxoValidation,
4103
4123
  vmBacktrace: nodeInfo.vmBacktrace
@@ -4214,7 +4234,7 @@ var _Provider = class {
4214
4234
  async estimatePredicates(transactionRequest) {
4215
4235
  const shouldEstimatePredicates = Boolean(
4216
4236
  transactionRequest.inputs.find(
4217
- (input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math16.BN(input.predicateGasUsed).isZero()
4237
+ (input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math17.BN(input.predicateGasUsed).isZero()
4218
4238
  )
4219
4239
  );
4220
4240
  if (!shouldEstimatePredicates) {
@@ -4229,7 +4249,7 @@ var _Provider = class {
4229
4249
  } = response;
4230
4250
  if (inputs) {
4231
4251
  inputs.forEach((input, index) => {
4232
- if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
4252
+ if ("predicateGasUsed" in input && (0, import_math17.bn)(input.predicateGasUsed).gt(0)) {
4233
4253
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
4234
4254
  }
4235
4255
  });
@@ -4387,12 +4407,12 @@ var _Provider = class {
4387
4407
  gasPrice = await this.estimateGasPrice(10);
4388
4408
  }
4389
4409
  const minFee = calculateGasFee({
4390
- gasPrice: (0, import_math16.bn)(gasPrice),
4410
+ gasPrice: (0, import_math17.bn)(gasPrice),
4391
4411
  gas: minGas,
4392
4412
  priceFactor: gasPriceFactor,
4393
4413
  tip: transactionRequest.tip
4394
4414
  }).add(1);
4395
- let gasLimit = (0, import_math16.bn)(0);
4415
+ let gasLimit = (0, import_math17.bn)(0);
4396
4416
  if (transactionRequest.type === import_transactions20.TransactionType.Script) {
4397
4417
  gasLimit = transactionRequest.gasLimit;
4398
4418
  if (transactionRequest.gasLimit.eq(0)) {
@@ -4405,7 +4425,7 @@ var _Provider = class {
4405
4425
  }
4406
4426
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4407
4427
  const maxFee = calculateGasFee({
4408
- gasPrice: (0, import_math16.bn)(gasPrice),
4428
+ gasPrice: (0, import_math17.bn)(gasPrice),
4409
4429
  gas: maxGas,
4410
4430
  priceFactor: gasPriceFactor,
4411
4431
  tip: transactionRequest.tip
@@ -4468,9 +4488,9 @@ var _Provider = class {
4468
4488
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4469
4489
  const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4470
4490
  txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
4471
- txRequestClone.maxFee = (0, import_math16.bn)(0);
4491
+ txRequestClone.maxFee = (0, import_math17.bn)(0);
4472
4492
  if (isScriptTransaction) {
4473
- txRequestClone.gasLimit = (0, import_math16.bn)(0);
4493
+ txRequestClone.gasLimit = (0, import_math17.bn)(0);
4474
4494
  }
4475
4495
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4476
4496
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
@@ -4489,7 +4509,7 @@ var _Provider = class {
4489
4509
  let receipts = [];
4490
4510
  let missingContractIds = [];
4491
4511
  let outputVariables = 0;
4492
- let gasUsed = (0, import_math16.bn)(0);
4512
+ let gasUsed = (0, import_math17.bn)(0);
4493
4513
  txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4494
4514
  txRequestClone.maxFee = maxFee;
4495
4515
  if (isScriptTransaction) {
@@ -4556,10 +4576,10 @@ var _Provider = class {
4556
4576
  return coins.map((coin) => ({
4557
4577
  id: coin.utxoId,
4558
4578
  assetId: coin.assetId,
4559
- amount: (0, import_math16.bn)(coin.amount),
4579
+ amount: (0, import_math17.bn)(coin.amount),
4560
4580
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4561
- blockCreated: (0, import_math16.bn)(coin.blockCreated),
4562
- txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4581
+ blockCreated: (0, import_math17.bn)(coin.blockCreated),
4582
+ txCreatedIdx: (0, import_math17.bn)(coin.txCreatedIdx)
4563
4583
  }));
4564
4584
  }
4565
4585
  /**
@@ -4596,9 +4616,9 @@ var _Provider = class {
4596
4616
  switch (coin.__typename) {
4597
4617
  case "MessageCoin":
4598
4618
  return {
4599
- amount: (0, import_math16.bn)(coin.amount),
4619
+ amount: (0, import_math17.bn)(coin.amount),
4600
4620
  assetId: coin.assetId,
4601
- daHeight: (0, import_math16.bn)(coin.daHeight),
4621
+ daHeight: (0, import_math17.bn)(coin.daHeight),
4602
4622
  sender: import_address3.Address.fromAddressOrString(coin.sender),
4603
4623
  recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4604
4624
  nonce: coin.nonce
@@ -4606,11 +4626,11 @@ var _Provider = class {
4606
4626
  case "Coin":
4607
4627
  return {
4608
4628
  id: coin.utxoId,
4609
- amount: (0, import_math16.bn)(coin.amount),
4629
+ amount: (0, import_math17.bn)(coin.amount),
4610
4630
  assetId: coin.assetId,
4611
4631
  owner: import_address3.Address.fromAddressOrString(coin.owner),
4612
- blockCreated: (0, import_math16.bn)(coin.blockCreated),
4613
- txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
4632
+ blockCreated: (0, import_math17.bn)(coin.blockCreated),
4633
+ txCreatedIdx: (0, import_math17.bn)(coin.txCreatedIdx)
4614
4634
  };
4615
4635
  default:
4616
4636
  return null;
@@ -4627,13 +4647,13 @@ var _Provider = class {
4627
4647
  async getBlock(idOrHeight) {
4628
4648
  let variables;
4629
4649
  if (typeof idOrHeight === "number") {
4630
- variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
4650
+ variables = { height: (0, import_math17.bn)(idOrHeight).toString(10) };
4631
4651
  } else if (idOrHeight === "latest") {
4632
4652
  variables = { height: (await this.getBlockNumber()).toString(10) };
4633
4653
  } else if (idOrHeight.length === 66) {
4634
4654
  variables = { blockId: idOrHeight };
4635
4655
  } else {
4636
- variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
4656
+ variables = { blockId: (0, import_math17.bn)(idOrHeight).toString(10) };
4637
4657
  }
4638
4658
  const { block } = await this.operations.getBlock(variables);
4639
4659
  if (!block) {
@@ -4641,7 +4661,7 @@ var _Provider = class {
4641
4661
  }
4642
4662
  return {
4643
4663
  id: block.id,
4644
- height: (0, import_math16.bn)(block.height),
4664
+ height: (0, import_math17.bn)(block.height),
4645
4665
  time: block.header.time,
4646
4666
  transactionIds: block.transactions.map((tx) => tx.id)
4647
4667
  };
@@ -4656,7 +4676,7 @@ var _Provider = class {
4656
4676
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4657
4677
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4658
4678
  id: block.id,
4659
- height: (0, import_math16.bn)(block.height),
4679
+ height: (0, import_math17.bn)(block.height),
4660
4680
  time: block.header.time,
4661
4681
  transactionIds: block.transactions.map((tx) => tx.id)
4662
4682
  }));
@@ -4671,7 +4691,7 @@ var _Provider = class {
4671
4691
  async getBlockWithTransactions(idOrHeight) {
4672
4692
  let variables;
4673
4693
  if (typeof idOrHeight === "number") {
4674
- variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
4694
+ variables = { blockHeight: (0, import_math17.bn)(idOrHeight).toString(10) };
4675
4695
  } else if (idOrHeight === "latest") {
4676
4696
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4677
4697
  } else {
@@ -4683,7 +4703,7 @@ var _Provider = class {
4683
4703
  }
4684
4704
  return {
4685
4705
  id: block.id,
4686
- height: (0, import_math16.bn)(block.height, 10),
4706
+ height: (0, import_math17.bn)(block.height, 10),
4687
4707
  time: block.header.time,
4688
4708
  transactionIds: block.transactions.map((tx) => tx.id),
4689
4709
  transactions: block.transactions.map(
@@ -4732,7 +4752,7 @@ var _Provider = class {
4732
4752
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4733
4753
  asset: (0, import_utils22.hexlify)(assetId)
4734
4754
  });
4735
- return (0, import_math16.bn)(contractBalance.amount, 10);
4755
+ return (0, import_math17.bn)(contractBalance.amount, 10);
4736
4756
  }
4737
4757
  /**
4738
4758
  * Returns the balance for the given owner for the given asset ID.
@@ -4746,7 +4766,7 @@ var _Provider = class {
4746
4766
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4747
4767
  assetId: (0, import_utils22.hexlify)(assetId)
4748
4768
  });
4749
- return (0, import_math16.bn)(balance.amount, 10);
4769
+ return (0, import_math17.bn)(balance.amount, 10);
4750
4770
  }
4751
4771
  /**
4752
4772
  * Returns balances for the given owner.
@@ -4764,7 +4784,7 @@ var _Provider = class {
4764
4784
  const balances = result.balances.edges.map((edge) => edge.node);
4765
4785
  return balances.map((balance) => ({
4766
4786
  assetId: balance.assetId,
4767
- amount: (0, import_math16.bn)(balance.amount)
4787
+ amount: (0, import_math17.bn)(balance.amount)
4768
4788
  }));
4769
4789
  }
4770
4790
  /**
@@ -4786,15 +4806,15 @@ var _Provider = class {
4786
4806
  sender: message.sender,
4787
4807
  recipient: message.recipient,
4788
4808
  nonce: message.nonce,
4789
- amount: (0, import_math16.bn)(message.amount),
4809
+ amount: (0, import_math17.bn)(message.amount),
4790
4810
  data: message.data
4791
4811
  }),
4792
4812
  sender: import_address3.Address.fromAddressOrString(message.sender),
4793
4813
  recipient: import_address3.Address.fromAddressOrString(message.recipient),
4794
4814
  nonce: message.nonce,
4795
- amount: (0, import_math16.bn)(message.amount),
4815
+ amount: (0, import_math17.bn)(message.amount),
4796
4816
  data: import_transactions20.InputMessageCoder.decodeData(message.data),
4797
- daHeight: (0, import_math16.bn)(message.daHeight)
4817
+ daHeight: (0, import_math17.bn)(message.daHeight)
4798
4818
  }));
4799
4819
  }
4800
4820
  /**
@@ -4847,23 +4867,23 @@ var _Provider = class {
4847
4867
  } = result.messageProof;
4848
4868
  return {
4849
4869
  messageProof: {
4850
- proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
4870
+ proofIndex: (0, import_math17.bn)(messageProof.proofIndex),
4851
4871
  proofSet: messageProof.proofSet
4852
4872
  },
4853
4873
  blockProof: {
4854
- proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
4874
+ proofIndex: (0, import_math17.bn)(blockProof.proofIndex),
4855
4875
  proofSet: blockProof.proofSet
4856
4876
  },
4857
4877
  messageBlockHeader: {
4858
4878
  id: messageBlockHeader.id,
4859
- daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
4860
- transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
4879
+ daHeight: (0, import_math17.bn)(messageBlockHeader.daHeight),
4880
+ transactionsCount: (0, import_math17.bn)(messageBlockHeader.transactionsCount),
4861
4881
  transactionsRoot: messageBlockHeader.transactionsRoot,
4862
- height: (0, import_math16.bn)(messageBlockHeader.height),
4882
+ height: (0, import_math17.bn)(messageBlockHeader.height),
4863
4883
  prevRoot: messageBlockHeader.prevRoot,
4864
4884
  time: messageBlockHeader.time,
4865
4885
  applicationHash: messageBlockHeader.applicationHash,
4866
- messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
4886
+ messageReceiptCount: (0, import_math17.bn)(messageBlockHeader.messageReceiptCount),
4867
4887
  messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4868
4888
  consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
4869
4889
  eventInboxRoot: messageBlockHeader.eventInboxRoot,
@@ -4871,14 +4891,14 @@ var _Provider = class {
4871
4891
  },
4872
4892
  commitBlockHeader: {
4873
4893
  id: commitBlockHeader.id,
4874
- daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
4875
- transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
4894
+ daHeight: (0, import_math17.bn)(commitBlockHeader.daHeight),
4895
+ transactionsCount: (0, import_math17.bn)(commitBlockHeader.transactionsCount),
4876
4896
  transactionsRoot: commitBlockHeader.transactionsRoot,
4877
- height: (0, import_math16.bn)(commitBlockHeader.height),
4897
+ height: (0, import_math17.bn)(commitBlockHeader.height),
4878
4898
  prevRoot: commitBlockHeader.prevRoot,
4879
4899
  time: commitBlockHeader.time,
4880
4900
  applicationHash: commitBlockHeader.applicationHash,
4881
- messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
4901
+ messageReceiptCount: (0, import_math17.bn)(commitBlockHeader.messageReceiptCount),
4882
4902
  messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4883
4903
  consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
4884
4904
  eventInboxRoot: commitBlockHeader.eventInboxRoot,
@@ -4887,19 +4907,19 @@ var _Provider = class {
4887
4907
  sender: import_address3.Address.fromAddressOrString(sender),
4888
4908
  recipient: import_address3.Address.fromAddressOrString(recipient),
4889
4909
  nonce,
4890
- amount: (0, import_math16.bn)(amount),
4910
+ amount: (0, import_math17.bn)(amount),
4891
4911
  data
4892
4912
  };
4893
4913
  }
4894
4914
  async getLatestGasPrice() {
4895
4915
  const { latestGasPrice } = await this.operations.getLatestGasPrice();
4896
- return (0, import_math16.bn)(latestGasPrice.gasPrice);
4916
+ return (0, import_math17.bn)(latestGasPrice.gasPrice);
4897
4917
  }
4898
4918
  async estimateGasPrice(blockHorizon) {
4899
4919
  const { estimateGasPrice } = await this.operations.estimateGasPrice({
4900
4920
  blockHorizon: String(blockHorizon)
4901
4921
  });
4902
- return (0, import_math16.bn)(estimateGasPrice.gasPrice);
4922
+ return (0, import_math17.bn)(estimateGasPrice.gasPrice);
4903
4923
  }
4904
4924
  /**
4905
4925
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
@@ -4920,10 +4940,10 @@ var _Provider = class {
4920
4940
  */
4921
4941
  async produceBlocks(amount, startTime) {
4922
4942
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4923
- blocksToProduce: (0, import_math16.bn)(amount).toString(10),
4943
+ blocksToProduce: (0, import_math17.bn)(amount).toString(10),
4924
4944
  startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4925
4945
  });
4926
- return (0, import_math16.bn)(latestBlockHeight);
4946
+ return (0, import_math17.bn)(latestBlockHeight);
4927
4947
  }
4928
4948
  // eslint-disable-next-line @typescript-eslint/require-await
4929
4949
  async getTransactionResponse(transactionId) {
@@ -4960,7 +4980,7 @@ __publicField(Provider, "nodeInfoCache", {});
4960
4980
 
4961
4981
  // src/providers/transaction-summary/get-transaction-summary.ts
4962
4982
  var import_errors15 = require("@fuel-ts/errors");
4963
- var import_math17 = require("@fuel-ts/math");
4983
+ var import_math18 = require("@fuel-ts/math");
4964
4984
  var import_transactions21 = require("@fuel-ts/transactions");
4965
4985
  var import_utils25 = require("@fuel-ts/utils");
4966
4986
  async function getTransactionSummary(params) {
@@ -4993,8 +5013,8 @@ async function getTransactionSummary(params) {
4993
5013
  transaction: decodedTransaction,
4994
5014
  transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
4995
5015
  gqlTransactionStatus: gqlTransaction.status,
4996
- gasPerByte: (0, import_math17.bn)(gasPerByte),
4997
- gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
5016
+ gasPerByte: (0, import_math18.bn)(gasPerByte),
5017
+ gasPriceFactor: (0, import_math18.bn)(gasPriceFactor),
4998
5018
  abiMap,
4999
5019
  maxInputs,
5000
5020
  gasCosts,
@@ -5194,13 +5214,13 @@ var assets = [
5194
5214
 
5195
5215
  // src/utils/formatTransferToContractScriptData.ts
5196
5216
  var import_abi_coder6 = require("@fuel-ts/abi-coder");
5197
- var import_math18 = require("@fuel-ts/math");
5217
+ var import_math19 = require("@fuel-ts/math");
5198
5218
  var import_utils26 = require("@fuel-ts/utils");
5199
5219
  var asm = __toESM(require("@fuels/vm-asm"));
5200
5220
  var formatTransferToContractScriptData = (params) => {
5201
5221
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
5202
5222
  const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
5203
- const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
5223
+ const encoded = numberCoder.encode(new import_math19.BN(amountToTransfer).toNumber());
5204
5224
  const scriptData = Uint8Array.from([
5205
5225
  ...(0, import_utils26.arrayify)(hexlifiedContractId),
5206
5226
  ...encoded,
@@ -5229,6 +5249,7 @@ var assembleTransferToContractScript = async (params) => {
5229
5249
  };
5230
5250
 
5231
5251
  // src/account.ts
5252
+ var MAX_FUNDING_ATTEMPTS = 2;
5232
5253
  var Account = class extends import_interfaces.AbstractAccount {
5233
5254
  /**
5234
5255
  * The address associated with the account.
@@ -5386,16 +5407,17 @@ var Account = class extends import_interfaces.AbstractAccount {
5386
5407
  * Adds resources to the transaction enough to fund it.
5387
5408
  *
5388
5409
  * @param request - The transaction request.
5389
- * @param coinQuantities - The coin quantities required to execute the transaction.
5410
+ * @param requiredQuantities - The coin quantities required to execute the transaction.
5390
5411
  * @param fee - The estimated transaction fee.
5391
5412
  * @returns A promise that resolves when the resources are added to the transaction.
5392
5413
  */
5393
5414
  async fund(request, params) {
5394
5415
  const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
5395
5416
  const baseAssetId = this.provider.getBaseAssetId();
5417
+ const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math20.bn)(0);
5396
5418
  const txRequest = request;
5397
5419
  const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5398
- amount: (0, import_math19.bn)(fee),
5420
+ amount: (0, import_math20.bn)(fee),
5399
5421
  assetId: baseAssetId,
5400
5422
  coinQuantities: requiredQuantities
5401
5423
  });
@@ -5403,21 +5425,17 @@ var Account = class extends import_interfaces.AbstractAccount {
5403
5425
  requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
5404
5426
  quantitiesDict[assetId] = {
5405
5427
  required: amount,
5406
- owned: (0, import_math19.bn)(0)
5428
+ owned: (0, import_math20.bn)(0)
5407
5429
  };
5408
5430
  });
5409
- txRequest.inputs.forEach((input) => {
5410
- const isResource = "amount" in input;
5411
- if (!isResource) {
5412
- return;
5413
- }
5414
- const isCoin2 = "owner" in input;
5431
+ request.inputs.filter(isRequestInputResource).forEach((input) => {
5432
+ const isCoin2 = isRequestInputCoin(input);
5415
5433
  const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
5416
5434
  if (quantitiesDict[assetId]) {
5417
5435
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
5418
5436
  }
5419
5437
  });
5420
- const missingQuantities = [];
5438
+ let missingQuantities = [];
5421
5439
  Object.entries(quantitiesDict).forEach(([assetId, { owned, required }]) => {
5422
5440
  if (owned.lt(required)) {
5423
5441
  missingQuantities.push({
@@ -5426,11 +5444,42 @@ var Account = class extends import_interfaces.AbstractAccount {
5426
5444
  });
5427
5445
  }
5428
5446
  });
5429
- const needsToBeFunded = missingQuantities.length;
5430
- if (needsToBeFunded) {
5431
- const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
5432
- const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
5433
- txRequest.addResources(resources);
5447
+ let needsToBeFunded = missingQuantities.length > 0;
5448
+ let fundingAttempts = 0;
5449
+ while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
5450
+ const resources = await this.getResourcesToSpend(
5451
+ missingQuantities,
5452
+ cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
5453
+ );
5454
+ request.addResources(resources);
5455
+ txRequest.shiftPredicateData();
5456
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
5457
+ const requestToReestimate2 = (0, import_ramda4.clone)(txRequest);
5458
+ if (addedSignatures) {
5459
+ Array.from({ length: addedSignatures }).forEach(
5460
+ () => requestToReestimate2.addEmptyWitness()
5461
+ );
5462
+ }
5463
+ const { maxFee: newFee } = await this.provider.estimateTxGasAndFee({
5464
+ transactionRequest: requestToReestimate2
5465
+ });
5466
+ const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
5467
+ request.inputs,
5468
+ baseAssetId,
5469
+ baseAssetId
5470
+ );
5471
+ const totalBaseAssetRequiredWithFee = requiredInBaseAsset.add(newFee);
5472
+ if (totalBaseAssetOnInputs.gt(totalBaseAssetRequiredWithFee)) {
5473
+ needsToBeFunded = false;
5474
+ } else {
5475
+ missingQuantities = [
5476
+ {
5477
+ amount: totalBaseAssetRequiredWithFee.sub(totalBaseAssetOnInputs),
5478
+ assetId: baseAssetId
5479
+ }
5480
+ ];
5481
+ }
5482
+ fundingAttempts += 1;
5434
5483
  }
5435
5484
  txRequest.shiftPredicateData();
5436
5485
  txRequest.updatePredicateGasUsed(estimatedPredicates);
@@ -5481,7 +5530,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5481
5530
  * @returns A promise that resolves to the transaction response.
5482
5531
  */
5483
5532
  async transfer(destination, amount, assetId, txParams = {}) {
5484
- if ((0, import_math19.bn)(amount).lte(0)) {
5533
+ if ((0, import_math20.bn)(amount).lte(0)) {
5485
5534
  throw new import_errors16.FuelError(
5486
5535
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5487
5536
  "Transfer amount must be a positive number."
@@ -5501,7 +5550,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5501
5550
  * @returns A promise that resolves to the transaction response.
5502
5551
  */
5503
5552
  async transferToContract(contractId, amount, assetId, txParams = {}) {
5504
- if ((0, import_math19.bn)(amount).lte(0)) {
5553
+ if ((0, import_math20.bn)(amount).lte(0)) {
5505
5554
  throw new import_errors16.FuelError(
5506
5555
  import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5507
5556
  "Transfer amount must be a positive number."
@@ -5511,7 +5560,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5511
5560
  const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5512
5561
  const { script, scriptData } = await assembleTransferToContractScript({
5513
5562
  hexlifiedContractId: contractAddress.toB256(),
5514
- amountToTransfer: (0, import_math19.bn)(amount),
5563
+ amountToTransfer: (0, import_math20.bn)(amount),
5515
5564
  assetId: assetIdToTransfer
5516
5565
  });
5517
5566
  const request = new ScriptTransactionRequest({
@@ -5522,7 +5571,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5522
5571
  request.addContractInputAndOutput(contractAddress);
5523
5572
  const txCost = await this.provider.getTransactionCost(request, {
5524
5573
  resourcesOwner: this,
5525
- quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetIdToTransfer) }]
5574
+ quantitiesToContract: [{ amount: (0, import_math20.bn)(amount), assetId: String(assetIdToTransfer) }]
5526
5575
  });
5527
5576
  this.validateGasLimitAndMaxFee({
5528
5577
  gasUsed: txCost.gasUsed,
@@ -5548,7 +5597,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5548
5597
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5549
5598
  );
5550
5599
  const amountDataArray = (0, import_utils27.arrayify)(
5551
- "0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
5600
+ "0x".concat((0, import_math20.bn)(amount).toHex().substring(2).padStart(16, "0"))
5552
5601
  );
5553
5602
  const script = new Uint8Array([
5554
5603
  ...(0, import_utils27.arrayify)(withdrawScript.bytes),
@@ -5558,7 +5607,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5558
5607
  const params = { script, ...txParams };
5559
5608
  const baseAssetId = this.provider.getBaseAssetId();
5560
5609
  const request = new ScriptTransactionRequest(params);
5561
- const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: baseAssetId }];
5610
+ const quantitiesToContract = [{ amount: (0, import_math20.bn)(amount), assetId: baseAssetId }];
5562
5611
  const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5563
5612
  this.validateGasLimitAndMaxFee({
5564
5613
  gasUsed: txCost.gasUsed,
@@ -5653,7 +5702,7 @@ var import_utils30 = require("@fuel-ts/utils");
5653
5702
  var import_address5 = require("@fuel-ts/address");
5654
5703
  var import_crypto2 = require("@fuel-ts/crypto");
5655
5704
  var import_hasher2 = require("@fuel-ts/hasher");
5656
- var import_math20 = require("@fuel-ts/math");
5705
+ var import_math21 = require("@fuel-ts/math");
5657
5706
  var import_utils28 = require("@fuel-ts/utils");
5658
5707
  var import_secp256k1 = require("@noble/curves/secp256k1");
5659
5708
  var Signer = class {
@@ -5673,7 +5722,7 @@ var Signer = class {
5673
5722
  privateKey = `0x${privateKey}`;
5674
5723
  }
5675
5724
  }
5676
- const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
5725
+ const privateKeyBytes = (0, import_math21.toBytes)(privateKey, 32);
5677
5726
  this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
5678
5727
  this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5679
5728
  this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
@@ -5691,8 +5740,8 @@ var Signer = class {
5691
5740
  */
5692
5741
  sign(data) {
5693
5742
  const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
5694
- const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
5695
- const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
5743
+ const r = (0, import_math21.toBytes)(`0x${signature.r.toString(16)}`, 32);
5744
+ const s = (0, import_math21.toBytes)(`0x${signature.s.toString(16)}`, 32);
5696
5745
  s[0] |= (signature.recovery || 0) << 7;
5697
5746
  return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
5698
5747
  }
@@ -5964,7 +6013,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5964
6013
  // src/hdwallet/hdwallet.ts
5965
6014
  var import_errors20 = require("@fuel-ts/errors");
5966
6015
  var import_hasher6 = require("@fuel-ts/hasher");
5967
- var import_math21 = require("@fuel-ts/math");
6016
+ var import_math22 = require("@fuel-ts/math");
5968
6017
  var import_utils34 = require("@fuel-ts/utils");
5969
6018
  var import_ethers2 = require("ethers");
5970
6019
 
@@ -8430,13 +8479,13 @@ var HDWallet = class {
8430
8479
  } else {
8431
8480
  data.set((0, import_utils34.arrayify)(this.publicKey));
8432
8481
  }
8433
- data.set((0, import_math21.toBytes)(index, 4), 33);
8482
+ data.set((0, import_math22.toBytes)(index, 4), 33);
8434
8483
  const bytes = (0, import_utils34.arrayify)((0, import_ethers2.computeHmac)("sha512", chainCode, data));
8435
8484
  const IL = bytes.slice(0, 32);
8436
8485
  const IR = bytes.slice(32);
8437
8486
  if (privateKey) {
8438
8487
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
8439
- const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
8488
+ const ki = (0, import_math22.bn)(IL).add(privateKey).mod(N).toBytes(32);
8440
8489
  return new HDWallet({
8441
8490
  privateKey: ki,
8442
8491
  chainCode: IR,
@@ -8482,7 +8531,7 @@ var HDWallet = class {
8482
8531
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8483
8532
  const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
8484
8533
  const parentFingerprint = this.parentFingerprint;
8485
- const index = (0, import_math21.toHex)(this.index, 4);
8534
+ const index = (0, import_math22.toHex)(this.index, 4);
8486
8535
  const chainCode = this.chainCode;
8487
8536
  const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
8488
8537
  const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
@@ -10053,8 +10102,8 @@ __publicField(Fuel, "defaultConfig", {});
10053
10102
  assets,
10054
10103
  buildBlockExplorerUrl,
10055
10104
  cacheFor,
10056
- cacheResources,
10057
- cacheTxInputsFromOwner,
10105
+ cacheRequestInputsResources,
10106
+ cacheRequestInputsResourcesFromOwner,
10058
10107
  calculateGasFee,
10059
10108
  calculateMetadataGasForTxCreate,
10060
10109
  calculateMetadataGasForTxScript,
@@ -10067,6 +10116,7 @@ __publicField(Fuel, "defaultConfig", {});
10067
10116
  extractMintedAssetsFromReceipts,
10068
10117
  extractTxError,
10069
10118
  gasUsedByInputs,
10119
+ getAssetAmountInRequestInputs,
10070
10120
  getAssetEth,
10071
10121
  getAssetFuel,
10072
10122
  getAssetNetwork,