@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.

@@ -26,8 +26,8 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
26
26
  import { Address as Address3 } from "@fuel-ts/address";
27
27
  import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
28
28
  import { AbstractAccount } from "@fuel-ts/interfaces";
29
- import { bn as bn18 } from "@fuel-ts/math";
30
- import { arrayify as arrayify14, isDefined } from "@fuel-ts/utils";
29
+ import { bn as bn19 } from "@fuel-ts/math";
30
+ import { arrayify as arrayify14, isDefined as isDefined2 } from "@fuel-ts/utils";
31
31
  import { clone as clone4 } from "ramda";
32
32
 
33
33
  // src/providers/coin-quantity.ts
@@ -68,9 +68,9 @@ var addAmountToCoinQuantities = (params) => {
68
68
  // src/providers/provider.ts
69
69
  import { Address as Address2 } from "@fuel-ts/address";
70
70
  import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
71
- import { BN, bn as bn16 } from "@fuel-ts/math";
71
+ import { BN, bn as bn17 } from "@fuel-ts/math";
72
72
  import {
73
- InputType as InputType8,
73
+ InputType as InputType7,
74
74
  TransactionType as TransactionType8,
75
75
  InputMessageCoder,
76
76
  TransactionCoder as TransactionCoder5
@@ -1240,7 +1240,7 @@ import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
1240
1240
  import { Address, addressify } from "@fuel-ts/address";
1241
1241
  import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
1242
1242
  import { randomBytes } from "@fuel-ts/crypto";
1243
- import { bn as bn7 } from "@fuel-ts/math";
1243
+ import { bn as bn8 } from "@fuel-ts/math";
1244
1244
  import {
1245
1245
  PolicyType,
1246
1246
  TransactionCoder,
@@ -1248,7 +1248,7 @@ import {
1248
1248
  OutputType as OutputType2,
1249
1249
  TransactionType
1250
1250
  } from "@fuel-ts/transactions";
1251
- import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
1251
+ import { concat, hexlify as hexlify7, isDefined } from "@fuel-ts/utils";
1252
1252
 
1253
1253
  // src/providers/resource.ts
1254
1254
  var isCoin = (resource) => "id" in resource;
@@ -1561,7 +1561,7 @@ function calculateMetadataGasForTxScript({
1561
1561
  }
1562
1562
  var calculateGasFee = (params) => {
1563
1563
  const { gas, gasPrice, priceFactor, tip } = params;
1564
- return gas.mul(gasPrice).div(priceFactor).add(tip);
1564
+ return gas.mul(gasPrice).div(priceFactor).add(bn5(tip));
1565
1565
  };
1566
1566
 
1567
1567
  // src/providers/utils/json.ts
@@ -1695,10 +1695,34 @@ var NoWitnessAtIndexError = class extends Error {
1695
1695
  };
1696
1696
 
1697
1697
  // src/providers/transaction-request/helpers.ts
1698
+ import { bn as bn7 } from "@fuel-ts/math";
1698
1699
  import { InputType as InputType2 } from "@fuel-ts/transactions";
1699
1700
  var isRequestInputCoin = (input) => input.type === InputType2.Coin;
1700
1701
  var isRequestInputMessage = (input) => input.type === InputType2.Message;
1701
1702
  var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
1703
+ var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
1704
+ if (isRequestInputCoin(input) && input.assetId === assetId) {
1705
+ return acc.add(input.amount);
1706
+ }
1707
+ if (isRequestInputMessage(input) && assetId === baseAsset) {
1708
+ return acc.add(input.amount);
1709
+ }
1710
+ return acc;
1711
+ }, bn7(0));
1712
+ var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
1713
+ (acc, input) => {
1714
+ if (isRequestInputCoin(input) && input.owner === owner.toB256()) {
1715
+ acc.utxos.push(input.id);
1716
+ } else if (isRequestInputMessage(input) && input.recipient === owner.toB256()) {
1717
+ acc.messages.push(input.nonce);
1718
+ }
1719
+ return acc;
1720
+ },
1721
+ {
1722
+ utxos: [],
1723
+ messages: []
1724
+ }
1725
+ );
1702
1726
 
1703
1727
  // src/providers/transaction-request/witness.ts
1704
1728
  import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
@@ -1740,10 +1764,10 @@ var BaseTransactionRequest = class {
1740
1764
  outputs,
1741
1765
  witnesses
1742
1766
  } = {}) {
1743
- this.tip = bn7(tip);
1744
- this.maturity = maturity ?? 0;
1745
- this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
1746
- this.maxFee = maxFee ? bn7(maxFee) : void 0;
1767
+ this.tip = tip ? bn8(tip) : void 0;
1768
+ this.maturity = maturity && maturity > 0 ? maturity : void 0;
1769
+ this.witnessLimit = isDefined(witnessLimit) ? bn8(witnessLimit) : void 0;
1770
+ this.maxFee = bn8(maxFee);
1747
1771
  this.inputs = inputs ?? [];
1748
1772
  this.outputs = outputs ?? [];
1749
1773
  this.witnesses = witnesses ?? [];
@@ -1751,22 +1775,21 @@ var BaseTransactionRequest = class {
1751
1775
  static getPolicyMeta(req) {
1752
1776
  let policyTypes = 0;
1753
1777
  const policies = [];
1754
- if (req.tip) {
1778
+ const { tip, witnessLimit, maturity } = req;
1779
+ if (bn8(tip).gt(0)) {
1755
1780
  policyTypes += PolicyType.Tip;
1756
- policies.push({ data: req.tip, type: PolicyType.Tip });
1781
+ policies.push({ data: bn8(tip), type: PolicyType.Tip });
1757
1782
  }
1758
- if (req.witnessLimit) {
1783
+ if (isDefined(witnessLimit) && bn8(witnessLimit).gte(0)) {
1759
1784
  policyTypes += PolicyType.WitnessLimit;
1760
- policies.push({ data: req.witnessLimit, type: PolicyType.WitnessLimit });
1785
+ policies.push({ data: bn8(witnessLimit), type: PolicyType.WitnessLimit });
1761
1786
  }
1762
- if (req.maturity > 0) {
1787
+ if (maturity && maturity > 0) {
1763
1788
  policyTypes += PolicyType.Maturity;
1764
- policies.push({ data: req.maturity, type: PolicyType.Maturity });
1765
- }
1766
- if (req.maxFee) {
1767
- policyTypes += PolicyType.MaxFee;
1768
- policies.push({ data: req.maxFee, type: PolicyType.MaxFee });
1789
+ policies.push({ data: maturity, type: PolicyType.Maturity });
1769
1790
  }
1791
+ policyTypes += PolicyType.MaxFee;
1792
+ policies.push({ data: req.maxFee, type: PolicyType.MaxFee });
1770
1793
  return {
1771
1794
  policyTypes,
1772
1795
  policies
@@ -2127,7 +2150,7 @@ var BaseTransactionRequest = class {
2127
2150
  const assetInput = findAssetInput(assetId);
2128
2151
  let usedQuantity = quantity;
2129
2152
  if (assetId === baseAssetId) {
2130
- usedQuantity = bn7("1000000000000000000");
2153
+ usedQuantity = bn8("1000000000000000000");
2131
2154
  }
2132
2155
  if (assetInput && "assetId" in assetInput) {
2133
2156
  assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
@@ -2139,13 +2162,13 @@ var BaseTransactionRequest = class {
2139
2162
  amount: usedQuantity,
2140
2163
  assetId,
2141
2164
  owner: resourcesOwner || Address.fromRandom(),
2142
- blockCreated: bn7(1),
2143
- txCreatedIdx: bn7(1)
2165
+ blockCreated: bn8(1),
2166
+ txCreatedIdx: bn8(1)
2144
2167
  }
2145
2168
  ]);
2146
2169
  }
2147
2170
  };
2148
- updateAssetInput(baseAssetId, bn7(1e11));
2171
+ updateAssetInput(baseAssetId, bn8(1e11));
2149
2172
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2150
2173
  }
2151
2174
  /**
@@ -2156,7 +2179,7 @@ var BaseTransactionRequest = class {
2156
2179
  */
2157
2180
  getCoinOutputsQuantities() {
2158
2181
  const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
2159
- amount: bn7(amount),
2182
+ amount: bn8(amount),
2160
2183
  assetId: assetId.toString()
2161
2184
  }));
2162
2185
  return coinsQuantities;
@@ -2196,7 +2219,7 @@ var BaseTransactionRequest = class {
2196
2219
  default:
2197
2220
  return;
2198
2221
  }
2199
- if (correspondingInput && "predicateGasUsed" in correspondingInput && bn7(correspondingInput.predicateGasUsed).gt(0)) {
2222
+ if (correspondingInput && "predicateGasUsed" in correspondingInput && bn8(correspondingInput.predicateGasUsed).gt(0)) {
2200
2223
  i.predicate = correspondingInput.predicate;
2201
2224
  i.predicateData = correspondingInput.predicateData;
2202
2225
  i.predicateGasUsed = correspondingInput.predicateGasUsed;
@@ -2216,14 +2239,14 @@ var BaseTransactionRequest = class {
2216
2239
 
2217
2240
  // src/providers/transaction-request/create-transaction-request.ts
2218
2241
  import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
2219
- import { bn as bn9 } from "@fuel-ts/math";
2242
+ import { bn as bn10 } from "@fuel-ts/math";
2220
2243
  import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
2221
2244
  import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
2222
2245
 
2223
2246
  // src/providers/transaction-request/hash-transaction.ts
2224
2247
  import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
2225
2248
  import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
2226
- import { bn as bn8 } from "@fuel-ts/math";
2249
+ import { bn as bn9 } from "@fuel-ts/math";
2227
2250
  import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
2228
2251
  import { concat as concat2 } from "@fuel-ts/utils";
2229
2252
  import { clone as clone2 } from "ramda";
@@ -2240,11 +2263,11 @@ function hashTransaction(transactionRequest, chainId) {
2240
2263
  blockHeight: 0,
2241
2264
  txIndex: 0
2242
2265
  };
2243
- inputClone.predicateGasUsed = bn8(0);
2266
+ inputClone.predicateGasUsed = bn9(0);
2244
2267
  return inputClone;
2245
2268
  }
2246
2269
  case InputType4.Message: {
2247
- inputClone.predicateGasUsed = bn8(0);
2270
+ inputClone.predicateGasUsed = bn9(0);
2248
2271
  return inputClone;
2249
2272
  }
2250
2273
  case InputType4.Contract: {
@@ -2271,12 +2294,12 @@ function hashTransaction(transactionRequest, chainId) {
2271
2294
  return outputClone;
2272
2295
  }
2273
2296
  case OutputType3.Change: {
2274
- outputClone.amount = bn8(0);
2297
+ outputClone.amount = bn9(0);
2275
2298
  return outputClone;
2276
2299
  }
2277
2300
  case OutputType3.Variable: {
2278
2301
  outputClone.to = ZeroBytes325;
2279
- outputClone.amount = bn8(0);
2302
+ outputClone.amount = bn9(0);
2280
2303
  outputClone.assetId = ZeroBytes325;
2281
2304
  return outputClone;
2282
2305
  }
@@ -2354,7 +2377,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2354
2377
  type: TransactionType3.Create,
2355
2378
  ...baseTransaction,
2356
2379
  bytecodeWitnessIndex,
2357
- storageSlotsCount: bn9(storageSlots.length),
2380
+ storageSlotsCount: bn10(storageSlots.length),
2358
2381
  salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
2359
2382
  storageSlots
2360
2383
  };
@@ -2394,7 +2417,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2394
2417
  }
2395
2418
  metadataGas(gasCosts) {
2396
2419
  return calculateMetadataGasForTxCreate({
2397
- contractBytesSize: bn9(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2420
+ contractBytesSize: bn10(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2398
2421
  gasCosts,
2399
2422
  stateRootSize: this.storageSlots.length,
2400
2423
  txBytesSize: this.byteSize()
@@ -2406,7 +2429,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2406
2429
  import { Interface } from "@fuel-ts/abi-coder";
2407
2430
  import { addressify as addressify2 } from "@fuel-ts/address";
2408
2431
  import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
2409
- import { bn as bn10 } from "@fuel-ts/math";
2432
+ import { bn as bn11 } from "@fuel-ts/math";
2410
2433
  import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
2411
2434
  import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
2412
2435
 
@@ -2460,7 +2483,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2460
2483
  */
2461
2484
  constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2462
2485
  super(rest);
2463
- this.gasLimit = bn10(gasLimit);
2486
+ this.gasLimit = bn11(gasLimit);
2464
2487
  this.script = arrayify8(script ?? returnZeroScript.bytes);
2465
2488
  this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
2466
2489
  this.abis = rest.abis;
@@ -2477,8 +2500,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2477
2500
  type: TransactionType4.Script,
2478
2501
  scriptGasLimit: this.gasLimit,
2479
2502
  ...super.getBaseTransaction(),
2480
- scriptLength: bn10(script.length),
2481
- scriptDataLength: bn10(scriptData.length),
2503
+ scriptLength: bn11(script.length),
2504
+ scriptDataLength: bn11(scriptData.length),
2482
2505
  receiptsRoot: ZeroBytes327,
2483
2506
  script: hexlify10(script),
2484
2507
  scriptData: hexlify10(scriptData)
@@ -2610,7 +2633,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2610
2633
 
2611
2634
  // src/providers/transaction-request/utils.ts
2612
2635
  import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
2613
- import { TransactionType as TransactionType5, InputType as InputType6 } from "@fuel-ts/transactions";
2636
+ import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
2614
2637
  var transactionRequestify = (obj) => {
2615
2638
  if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
2616
2639
  return obj;
@@ -2628,35 +2651,20 @@ var transactionRequestify = (obj) => {
2628
2651
  }
2629
2652
  }
2630
2653
  };
2631
- var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
2632
- (acc, input) => {
2633
- if (input.type === InputType6.Coin && input.owner === owner) {
2634
- acc.utxos.push(input.id);
2635
- }
2636
- if (input.type === InputType6.Message && input.recipient === owner) {
2637
- acc.messages.push(input.nonce);
2638
- }
2639
- return acc;
2640
- },
2641
- {
2642
- utxos: [],
2643
- messages: []
2644
- }
2645
- );
2646
2654
 
2647
2655
  // src/providers/transaction-response/transaction-response.ts
2648
2656
  import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
2649
- import { bn as bn15 } from "@fuel-ts/math";
2657
+ import { bn as bn16 } from "@fuel-ts/math";
2650
2658
  import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
2651
2659
  import { arrayify as arrayify10 } from "@fuel-ts/utils";
2652
2660
 
2653
2661
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2654
- import { bn as bn14 } from "@fuel-ts/math";
2662
+ import { bn as bn15 } from "@fuel-ts/math";
2655
2663
  import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
2656
2664
  import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
2657
2665
 
2658
2666
  // src/providers/transaction-summary/calculate-transaction-fee.ts
2659
- import { bn as bn11 } from "@fuel-ts/math";
2667
+ import { bn as bn12 } from "@fuel-ts/math";
2660
2668
  import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
2661
2669
  import { arrayify as arrayify9 } from "@fuel-ts/utils";
2662
2670
  var calculateTransactionFee = (params) => {
@@ -2666,23 +2674,23 @@ var calculateTransactionFee = (params) => {
2666
2674
  tip,
2667
2675
  consensusParameters: { gasCosts, feeParams, maxGasPerTx }
2668
2676
  } = params;
2669
- const gasPerByte = bn11(feeParams.gasPerByte);
2670
- const gasPriceFactor = bn11(feeParams.gasPriceFactor);
2677
+ const gasPerByte = bn12(feeParams.gasPerByte);
2678
+ const gasPriceFactor = bn12(feeParams.gasPriceFactor);
2671
2679
  const transactionBytes = arrayify9(rawPayload);
2672
2680
  const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
2673
2681
  if (transaction.type === TransactionType6.Mint) {
2674
2682
  return {
2675
- fee: bn11(0),
2676
- minFee: bn11(0),
2677
- maxFee: bn11(0)
2683
+ fee: bn12(0),
2684
+ minFee: bn12(0),
2685
+ maxFee: bn12(0)
2678
2686
  };
2679
2687
  }
2680
2688
  const { type, witnesses, inputs, policies } = transaction;
2681
- let metadataGas = bn11(0);
2682
- let gasLimit = bn11(0);
2689
+ let metadataGas = bn12(0);
2690
+ let gasLimit = bn12(0);
2683
2691
  if (type === TransactionType6.Create) {
2684
2692
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2685
- const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
2693
+ const contractBytesSize = bn12(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
2686
2694
  metadataGas = calculateMetadataGasForTxCreate({
2687
2695
  contractBytesSize,
2688
2696
  gasCosts,
@@ -2701,7 +2709,7 @@ var calculateTransactionFee = (params) => {
2701
2709
  }
2702
2710
  const minGas = getMinGas({
2703
2711
  gasCosts,
2704
- gasPerByte: bn11(gasPerByte),
2712
+ gasPerByte: bn12(gasPerByte),
2705
2713
  inputs,
2706
2714
  metadataGas,
2707
2715
  txBytesSize: transactionBytes.length
@@ -2738,12 +2746,12 @@ var calculateTransactionFee = (params) => {
2738
2746
  // src/providers/transaction-summary/operations.ts
2739
2747
  import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
2740
2748
  import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
2741
- import { bn as bn13 } from "@fuel-ts/math";
2749
+ import { bn as bn14 } from "@fuel-ts/math";
2742
2750
  import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
2743
2751
 
2744
2752
  // src/providers/transaction-summary/call.ts
2745
2753
  import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
2746
- import { bn as bn12 } from "@fuel-ts/math";
2754
+ import { bn as bn13 } from "@fuel-ts/math";
2747
2755
  var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2748
2756
  const abiInterface = new Interface2(abi);
2749
2757
  const callFunctionSelector = receipt.param1.toHex(8);
@@ -2752,7 +2760,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2752
2760
  let encodedArgs;
2753
2761
  if (functionFragment.isInputDataPointer) {
2754
2762
  if (rawPayload) {
2755
- const argsOffset = bn12(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
2763
+ const argsOffset = bn13(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
2756
2764
  encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
2757
2765
  }
2758
2766
  } else {
@@ -2787,7 +2795,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
2787
2795
 
2788
2796
  // src/providers/transaction-summary/input.ts
2789
2797
  import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
2790
- import { InputType as InputType7 } from "@fuel-ts/transactions";
2798
+ import { InputType as InputType6 } from "@fuel-ts/transactions";
2791
2799
  function getInputsByTypes(inputs, types) {
2792
2800
  return inputs.filter((i) => types.includes(i.type));
2793
2801
  }
@@ -2795,16 +2803,16 @@ function getInputsByType(inputs, type) {
2795
2803
  return inputs.filter((i) => i.type === type);
2796
2804
  }
2797
2805
  function getInputsCoin(inputs) {
2798
- return getInputsByType(inputs, InputType7.Coin);
2806
+ return getInputsByType(inputs, InputType6.Coin);
2799
2807
  }
2800
2808
  function getInputsMessage(inputs) {
2801
- return getInputsByType(inputs, InputType7.Message);
2809
+ return getInputsByType(inputs, InputType6.Message);
2802
2810
  }
2803
2811
  function getInputsCoinAndMessage(inputs) {
2804
- return getInputsByTypes(inputs, [InputType7.Coin, InputType7.Message]);
2812
+ return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
2805
2813
  }
2806
2814
  function getInputsContract(inputs) {
2807
- return getInputsByType(inputs, InputType7.Contract);
2815
+ return getInputsByType(inputs, InputType6.Contract);
2808
2816
  }
2809
2817
  function getInputFromAssetId(inputs, assetId) {
2810
2818
  const coinInputs = getInputsCoin(inputs);
@@ -2823,7 +2831,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
2823
2831
  if (!contractInput) {
2824
2832
  return void 0;
2825
2833
  }
2826
- if (contractInput.type !== InputType7.Contract) {
2834
+ if (contractInput.type !== InputType6.Contract) {
2827
2835
  throw new FuelError9(
2828
2836
  ErrorCode9.INVALID_TRANSACTION_INPUT,
2829
2837
  `Contract input should be of type 'contract'.`
@@ -2832,10 +2840,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
2832
2840
  return contractInput;
2833
2841
  }
2834
2842
  function getInputAccountAddress(input) {
2835
- if (input.type === InputType7.Coin) {
2843
+ if (input.type === InputType6.Coin) {
2836
2844
  return input.owner.toString();
2837
2845
  }
2838
- if (input.type === InputType7.Message) {
2846
+ if (input.type === InputType6.Message) {
2839
2847
  return input.recipient.toString();
2840
2848
  }
2841
2849
  return "";
@@ -2908,7 +2916,7 @@ var mergeAssets = (op1, op2) => {
2908
2916
  if (!matchingAsset) {
2909
2917
  return asset1;
2910
2918
  }
2911
- const mergedAmount = bn13(asset1.amount).add(matchingAsset.amount);
2919
+ const mergedAmount = bn14(asset1.amount).add(matchingAsset.amount);
2912
2920
  return { ...asset1, amount: mergedAmount };
2913
2921
  });
2914
2922
  return mergedAssets.concat(filteredAssets);
@@ -3314,7 +3322,7 @@ function assembleTransactionSummary(params) {
3314
3322
  maxInputs
3315
3323
  });
3316
3324
  const typeName = getTransactionTypeName(transaction.type);
3317
- const tip = bn14(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
3325
+ const tip = bn15(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
3318
3326
  const { fee } = calculateTransactionFee({
3319
3327
  gasPrice,
3320
3328
  rawPayload,
@@ -3381,7 +3389,7 @@ var TransactionResponse = class {
3381
3389
  /** Current provider */
3382
3390
  provider;
3383
3391
  /** Gas used on the transaction */
3384
- gasUsed = bn15(0);
3392
+ gasUsed = bn16(0);
3385
3393
  /** The graphql Transaction with receipts object. */
3386
3394
  gqlTransaction;
3387
3395
  abis;
@@ -3605,30 +3613,30 @@ var processGqlChain = (chain) => {
3605
3613
  const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
3606
3614
  return {
3607
3615
  name,
3608
- baseChainHeight: bn16(daHeight),
3616
+ baseChainHeight: bn17(daHeight),
3609
3617
  consensusParameters: {
3610
- contractMaxSize: bn16(contractParams.contractMaxSize),
3611
- maxInputs: bn16(txParams.maxInputs),
3612
- maxOutputs: bn16(txParams.maxOutputs),
3613
- maxWitnesses: bn16(txParams.maxWitnesses),
3614
- maxGasPerTx: bn16(txParams.maxGasPerTx),
3615
- maxScriptLength: bn16(scriptParams.maxScriptLength),
3616
- maxScriptDataLength: bn16(scriptParams.maxScriptDataLength),
3617
- maxStorageSlots: bn16(contractParams.maxStorageSlots),
3618
- maxPredicateLength: bn16(predicateParams.maxPredicateLength),
3619
- maxPredicateDataLength: bn16(predicateParams.maxPredicateDataLength),
3620
- maxGasPerPredicate: bn16(predicateParams.maxGasPerPredicate),
3621
- gasPriceFactor: bn16(feeParams.gasPriceFactor),
3622
- gasPerByte: bn16(feeParams.gasPerByte),
3623
- maxMessageDataLength: bn16(predicateParams.maxMessageDataLength),
3624
- chainId: bn16(consensusParameters.chainId),
3618
+ contractMaxSize: bn17(contractParams.contractMaxSize),
3619
+ maxInputs: bn17(txParams.maxInputs),
3620
+ maxOutputs: bn17(txParams.maxOutputs),
3621
+ maxWitnesses: bn17(txParams.maxWitnesses),
3622
+ maxGasPerTx: bn17(txParams.maxGasPerTx),
3623
+ maxScriptLength: bn17(scriptParams.maxScriptLength),
3624
+ maxScriptDataLength: bn17(scriptParams.maxScriptDataLength),
3625
+ maxStorageSlots: bn17(contractParams.maxStorageSlots),
3626
+ maxPredicateLength: bn17(predicateParams.maxPredicateLength),
3627
+ maxPredicateDataLength: bn17(predicateParams.maxPredicateDataLength),
3628
+ maxGasPerPredicate: bn17(predicateParams.maxGasPerPredicate),
3629
+ gasPriceFactor: bn17(feeParams.gasPriceFactor),
3630
+ gasPerByte: bn17(feeParams.gasPerByte),
3631
+ maxMessageDataLength: bn17(predicateParams.maxMessageDataLength),
3632
+ chainId: bn17(consensusParameters.chainId),
3625
3633
  baseAssetId: consensusParameters.baseAssetId,
3626
3634
  gasCosts
3627
3635
  },
3628
3636
  gasCosts,
3629
3637
  latestBlock: {
3630
3638
  id: latestBlock.id,
3631
- height: bn16(latestBlock.height),
3639
+ height: bn17(latestBlock.height),
3632
3640
  time: latestBlock.header.time,
3633
3641
  transactions: latestBlock.transactions.map((i) => ({
3634
3642
  id: i.id
@@ -3771,7 +3779,18 @@ var _Provider = class {
3771
3779
  createOperations() {
3772
3780
  const fetchFn = _Provider.getFetchFn(this.options);
3773
3781
  const gqlClient = new GraphQLClient(this.url, {
3774
- fetch: (url, requestInit) => fetchFn(url, requestInit, this.options)
3782
+ fetch: (url, requestInit) => fetchFn(url, requestInit, this.options),
3783
+ responseMiddleware: (response) => {
3784
+ if ("response" in response) {
3785
+ const graphQlResponse = response.response;
3786
+ if (Array.isArray(graphQlResponse?.errors)) {
3787
+ throw new FuelError13(
3788
+ FuelError13.CODES.INVALID_REQUEST,
3789
+ graphQlResponse.errors.map((err) => err.message).join("\n\n")
3790
+ );
3791
+ }
3792
+ }
3793
+ }
3775
3794
  });
3776
3795
  const executeQuery = (query, vars) => {
3777
3796
  const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
@@ -3806,7 +3825,7 @@ var _Provider = class {
3806
3825
  */
3807
3826
  async getBlockNumber() {
3808
3827
  const { chain } = await this.operations.getChain();
3809
- return bn16(chain.latestBlock.height, 10);
3828
+ return bn17(chain.latestBlock.height, 10);
3810
3829
  }
3811
3830
  /**
3812
3831
  * Returns the chain information.
@@ -3816,8 +3835,8 @@ var _Provider = class {
3816
3835
  async fetchNode() {
3817
3836
  const { nodeInfo } = await this.operations.getNodeInfo();
3818
3837
  const processedNodeInfo = {
3819
- maxDepth: bn16(nodeInfo.maxDepth),
3820
- maxTx: bn16(nodeInfo.maxTx),
3838
+ maxDepth: bn17(nodeInfo.maxDepth),
3839
+ maxTx: bn17(nodeInfo.maxTx),
3821
3840
  nodeVersion: nodeInfo.nodeVersion,
3822
3841
  utxoValidation: nodeInfo.utxoValidation,
3823
3842
  vmBacktrace: nodeInfo.vmBacktrace
@@ -3949,7 +3968,7 @@ var _Provider = class {
3949
3968
  } = response;
3950
3969
  if (inputs) {
3951
3970
  inputs.forEach((input, index) => {
3952
- if ("predicateGasUsed" in input && bn16(input.predicateGasUsed).gt(0)) {
3971
+ if ("predicateGasUsed" in input && bn17(input.predicateGasUsed).gt(0)) {
3953
3972
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
3954
3973
  }
3955
3974
  });
@@ -4107,12 +4126,12 @@ var _Provider = class {
4107
4126
  gasPrice = await this.estimateGasPrice(10);
4108
4127
  }
4109
4128
  const minFee = calculateGasFee({
4110
- gasPrice: bn16(gasPrice),
4129
+ gasPrice: bn17(gasPrice),
4111
4130
  gas: minGas,
4112
4131
  priceFactor: gasPriceFactor,
4113
4132
  tip: transactionRequest.tip
4114
4133
  }).add(1);
4115
- let gasLimit = bn16(0);
4134
+ let gasLimit = bn17(0);
4116
4135
  if (transactionRequest.type === TransactionType8.Script) {
4117
4136
  gasLimit = transactionRequest.gasLimit;
4118
4137
  if (transactionRequest.gasLimit.eq(0)) {
@@ -4125,7 +4144,7 @@ var _Provider = class {
4125
4144
  }
4126
4145
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4127
4146
  const maxFee = calculateGasFee({
4128
- gasPrice: bn16(gasPrice),
4147
+ gasPrice: bn17(gasPrice),
4129
4148
  gas: maxGas,
4130
4149
  priceFactor: gasPriceFactor,
4131
4150
  tip: transactionRequest.tip
@@ -4188,9 +4207,9 @@ var _Provider = class {
4188
4207
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4189
4208
  const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4190
4209
  txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
4191
- txRequestClone.maxFee = bn16(0);
4210
+ txRequestClone.maxFee = bn17(0);
4192
4211
  if (isScriptTransaction) {
4193
- txRequestClone.gasLimit = bn16(0);
4212
+ txRequestClone.gasLimit = bn17(0);
4194
4213
  }
4195
4214
  if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4196
4215
  resourcesOwner.populateTransactionPredicateData(txRequestClone);
@@ -4209,7 +4228,7 @@ var _Provider = class {
4209
4228
  let receipts = [];
4210
4229
  let missingContractIds = [];
4211
4230
  let outputVariables = 0;
4212
- let gasUsed = bn16(0);
4231
+ let gasUsed = bn17(0);
4213
4232
  txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
4214
4233
  txRequestClone.maxFee = maxFee;
4215
4234
  if (isScriptTransaction) {
@@ -4276,10 +4295,10 @@ var _Provider = class {
4276
4295
  return coins.map((coin) => ({
4277
4296
  id: coin.utxoId,
4278
4297
  assetId: coin.assetId,
4279
- amount: bn16(coin.amount),
4298
+ amount: bn17(coin.amount),
4280
4299
  owner: Address2.fromAddressOrString(coin.owner),
4281
- blockCreated: bn16(coin.blockCreated),
4282
- txCreatedIdx: bn16(coin.txCreatedIdx)
4300
+ blockCreated: bn17(coin.blockCreated),
4301
+ txCreatedIdx: bn17(coin.txCreatedIdx)
4283
4302
  }));
4284
4303
  }
4285
4304
  /**
@@ -4316,9 +4335,9 @@ var _Provider = class {
4316
4335
  switch (coin.__typename) {
4317
4336
  case "MessageCoin":
4318
4337
  return {
4319
- amount: bn16(coin.amount),
4338
+ amount: bn17(coin.amount),
4320
4339
  assetId: coin.assetId,
4321
- daHeight: bn16(coin.daHeight),
4340
+ daHeight: bn17(coin.daHeight),
4322
4341
  sender: Address2.fromAddressOrString(coin.sender),
4323
4342
  recipient: Address2.fromAddressOrString(coin.recipient),
4324
4343
  nonce: coin.nonce
@@ -4326,11 +4345,11 @@ var _Provider = class {
4326
4345
  case "Coin":
4327
4346
  return {
4328
4347
  id: coin.utxoId,
4329
- amount: bn16(coin.amount),
4348
+ amount: bn17(coin.amount),
4330
4349
  assetId: coin.assetId,
4331
4350
  owner: Address2.fromAddressOrString(coin.owner),
4332
- blockCreated: bn16(coin.blockCreated),
4333
- txCreatedIdx: bn16(coin.txCreatedIdx)
4351
+ blockCreated: bn17(coin.blockCreated),
4352
+ txCreatedIdx: bn17(coin.txCreatedIdx)
4334
4353
  };
4335
4354
  default:
4336
4355
  return null;
@@ -4347,13 +4366,13 @@ var _Provider = class {
4347
4366
  async getBlock(idOrHeight) {
4348
4367
  let variables;
4349
4368
  if (typeof idOrHeight === "number") {
4350
- variables = { height: bn16(idOrHeight).toString(10) };
4369
+ variables = { height: bn17(idOrHeight).toString(10) };
4351
4370
  } else if (idOrHeight === "latest") {
4352
4371
  variables = { height: (await this.getBlockNumber()).toString(10) };
4353
4372
  } else if (idOrHeight.length === 66) {
4354
4373
  variables = { blockId: idOrHeight };
4355
4374
  } else {
4356
- variables = { blockId: bn16(idOrHeight).toString(10) };
4375
+ variables = { blockId: bn17(idOrHeight).toString(10) };
4357
4376
  }
4358
4377
  const { block } = await this.operations.getBlock(variables);
4359
4378
  if (!block) {
@@ -4361,7 +4380,7 @@ var _Provider = class {
4361
4380
  }
4362
4381
  return {
4363
4382
  id: block.id,
4364
- height: bn16(block.height),
4383
+ height: bn17(block.height),
4365
4384
  time: block.header.time,
4366
4385
  transactionIds: block.transactions.map((tx) => tx.id)
4367
4386
  };
@@ -4376,7 +4395,7 @@ var _Provider = class {
4376
4395
  const { blocks: fetchedData } = await this.operations.getBlocks(params);
4377
4396
  const blocks = fetchedData.edges.map(({ node: block }) => ({
4378
4397
  id: block.id,
4379
- height: bn16(block.height),
4398
+ height: bn17(block.height),
4380
4399
  time: block.header.time,
4381
4400
  transactionIds: block.transactions.map((tx) => tx.id)
4382
4401
  }));
@@ -4391,7 +4410,7 @@ var _Provider = class {
4391
4410
  async getBlockWithTransactions(idOrHeight) {
4392
4411
  let variables;
4393
4412
  if (typeof idOrHeight === "number") {
4394
- variables = { blockHeight: bn16(idOrHeight).toString(10) };
4413
+ variables = { blockHeight: bn17(idOrHeight).toString(10) };
4395
4414
  } else if (idOrHeight === "latest") {
4396
4415
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4397
4416
  } else {
@@ -4403,7 +4422,7 @@ var _Provider = class {
4403
4422
  }
4404
4423
  return {
4405
4424
  id: block.id,
4406
- height: bn16(block.height, 10),
4425
+ height: bn17(block.height, 10),
4407
4426
  time: block.header.time,
4408
4427
  transactionIds: block.transactions.map((tx) => tx.id),
4409
4428
  transactions: block.transactions.map(
@@ -4452,7 +4471,7 @@ var _Provider = class {
4452
4471
  contract: Address2.fromAddressOrString(contractId).toB256(),
4453
4472
  asset: hexlify12(assetId)
4454
4473
  });
4455
- return bn16(contractBalance.amount, 10);
4474
+ return bn17(contractBalance.amount, 10);
4456
4475
  }
4457
4476
  /**
4458
4477
  * Returns the balance for the given owner for the given asset ID.
@@ -4466,7 +4485,7 @@ var _Provider = class {
4466
4485
  owner: Address2.fromAddressOrString(owner).toB256(),
4467
4486
  assetId: hexlify12(assetId)
4468
4487
  });
4469
- return bn16(balance.amount, 10);
4488
+ return bn17(balance.amount, 10);
4470
4489
  }
4471
4490
  /**
4472
4491
  * Returns balances for the given owner.
@@ -4484,7 +4503,7 @@ var _Provider = class {
4484
4503
  const balances = result.balances.edges.map((edge) => edge.node);
4485
4504
  return balances.map((balance) => ({
4486
4505
  assetId: balance.assetId,
4487
- amount: bn16(balance.amount)
4506
+ amount: bn17(balance.amount)
4488
4507
  }));
4489
4508
  }
4490
4509
  /**
@@ -4506,15 +4525,15 @@ var _Provider = class {
4506
4525
  sender: message.sender,
4507
4526
  recipient: message.recipient,
4508
4527
  nonce: message.nonce,
4509
- amount: bn16(message.amount),
4528
+ amount: bn17(message.amount),
4510
4529
  data: message.data
4511
4530
  }),
4512
4531
  sender: Address2.fromAddressOrString(message.sender),
4513
4532
  recipient: Address2.fromAddressOrString(message.recipient),
4514
4533
  nonce: message.nonce,
4515
- amount: bn16(message.amount),
4534
+ amount: bn17(message.amount),
4516
4535
  data: InputMessageCoder.decodeData(message.data),
4517
- daHeight: bn16(message.daHeight)
4536
+ daHeight: bn17(message.daHeight)
4518
4537
  }));
4519
4538
  }
4520
4539
  /**
@@ -4567,23 +4586,23 @@ var _Provider = class {
4567
4586
  } = result.messageProof;
4568
4587
  return {
4569
4588
  messageProof: {
4570
- proofIndex: bn16(messageProof.proofIndex),
4589
+ proofIndex: bn17(messageProof.proofIndex),
4571
4590
  proofSet: messageProof.proofSet
4572
4591
  },
4573
4592
  blockProof: {
4574
- proofIndex: bn16(blockProof.proofIndex),
4593
+ proofIndex: bn17(blockProof.proofIndex),
4575
4594
  proofSet: blockProof.proofSet
4576
4595
  },
4577
4596
  messageBlockHeader: {
4578
4597
  id: messageBlockHeader.id,
4579
- daHeight: bn16(messageBlockHeader.daHeight),
4580
- transactionsCount: bn16(messageBlockHeader.transactionsCount),
4598
+ daHeight: bn17(messageBlockHeader.daHeight),
4599
+ transactionsCount: bn17(messageBlockHeader.transactionsCount),
4581
4600
  transactionsRoot: messageBlockHeader.transactionsRoot,
4582
- height: bn16(messageBlockHeader.height),
4601
+ height: bn17(messageBlockHeader.height),
4583
4602
  prevRoot: messageBlockHeader.prevRoot,
4584
4603
  time: messageBlockHeader.time,
4585
4604
  applicationHash: messageBlockHeader.applicationHash,
4586
- messageReceiptCount: bn16(messageBlockHeader.messageReceiptCount),
4605
+ messageReceiptCount: bn17(messageBlockHeader.messageReceiptCount),
4587
4606
  messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
4588
4607
  consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
4589
4608
  eventInboxRoot: messageBlockHeader.eventInboxRoot,
@@ -4591,14 +4610,14 @@ var _Provider = class {
4591
4610
  },
4592
4611
  commitBlockHeader: {
4593
4612
  id: commitBlockHeader.id,
4594
- daHeight: bn16(commitBlockHeader.daHeight),
4595
- transactionsCount: bn16(commitBlockHeader.transactionsCount),
4613
+ daHeight: bn17(commitBlockHeader.daHeight),
4614
+ transactionsCount: bn17(commitBlockHeader.transactionsCount),
4596
4615
  transactionsRoot: commitBlockHeader.transactionsRoot,
4597
- height: bn16(commitBlockHeader.height),
4616
+ height: bn17(commitBlockHeader.height),
4598
4617
  prevRoot: commitBlockHeader.prevRoot,
4599
4618
  time: commitBlockHeader.time,
4600
4619
  applicationHash: commitBlockHeader.applicationHash,
4601
- messageReceiptCount: bn16(commitBlockHeader.messageReceiptCount),
4620
+ messageReceiptCount: bn17(commitBlockHeader.messageReceiptCount),
4602
4621
  messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
4603
4622
  consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
4604
4623
  eventInboxRoot: commitBlockHeader.eventInboxRoot,
@@ -4607,19 +4626,19 @@ var _Provider = class {
4607
4626
  sender: Address2.fromAddressOrString(sender),
4608
4627
  recipient: Address2.fromAddressOrString(recipient),
4609
4628
  nonce,
4610
- amount: bn16(amount),
4629
+ amount: bn17(amount),
4611
4630
  data
4612
4631
  };
4613
4632
  }
4614
4633
  async getLatestGasPrice() {
4615
4634
  const { latestGasPrice } = await this.operations.getLatestGasPrice();
4616
- return bn16(latestGasPrice.gasPrice);
4635
+ return bn17(latestGasPrice.gasPrice);
4617
4636
  }
4618
4637
  async estimateGasPrice(blockHorizon) {
4619
4638
  const { estimateGasPrice } = await this.operations.estimateGasPrice({
4620
4639
  blockHorizon: String(blockHorizon)
4621
4640
  });
4622
- return bn16(estimateGasPrice.gasPrice);
4641
+ return bn17(estimateGasPrice.gasPrice);
4623
4642
  }
4624
4643
  /**
4625
4644
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
@@ -4640,10 +4659,10 @@ var _Provider = class {
4640
4659
  */
4641
4660
  async produceBlocks(amount, startTime) {
4642
4661
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4643
- blocksToProduce: bn16(amount).toString(10),
4662
+ blocksToProduce: bn17(amount).toString(10),
4644
4663
  startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
4645
4664
  });
4646
- return bn16(latestBlockHeight);
4665
+ return bn17(latestBlockHeight);
4647
4666
  }
4648
4667
  // eslint-disable-next-line @typescript-eslint/require-await
4649
4668
  async getTransactionResponse(transactionId) {
@@ -4670,7 +4689,7 @@ cacheInputs_fn = function(inputs) {
4670
4689
  return;
4671
4690
  }
4672
4691
  inputs.forEach((input) => {
4673
- if (input.type === InputType8.Coin) {
4692
+ if (input.type === InputType7.Coin) {
4674
4693
  this.cache?.set(input.id);
4675
4694
  }
4676
4695
  });
@@ -4680,7 +4699,7 @@ __publicField(Provider, "nodeInfoCache", {});
4680
4699
 
4681
4700
  // src/providers/transaction-summary/get-transaction-summary.ts
4682
4701
  import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
4683
- import { bn as bn17 } from "@fuel-ts/math";
4702
+ import { bn as bn18 } from "@fuel-ts/math";
4684
4703
  import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
4685
4704
  import { arrayify as arrayify12 } from "@fuel-ts/utils";
4686
4705
 
@@ -4766,6 +4785,7 @@ var assembleTransferToContractScript = async (params) => {
4766
4785
  };
4767
4786
 
4768
4787
  // src/account.ts
4788
+ var MAX_FUNDING_ATTEMPTS = 2;
4769
4789
  var Account = class extends AbstractAccount {
4770
4790
  /**
4771
4791
  * The address associated with the account.
@@ -4923,16 +4943,17 @@ var Account = class extends AbstractAccount {
4923
4943
  * Adds resources to the transaction enough to fund it.
4924
4944
  *
4925
4945
  * @param request - The transaction request.
4926
- * @param coinQuantities - The coin quantities required to execute the transaction.
4946
+ * @param requiredQuantities - The coin quantities required to execute the transaction.
4927
4947
  * @param fee - The estimated transaction fee.
4928
4948
  * @returns A promise that resolves when the resources are added to the transaction.
4929
4949
  */
4930
4950
  async fund(request, params) {
4931
4951
  const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
4932
4952
  const baseAssetId = this.provider.getBaseAssetId();
4953
+ const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn19(0);
4933
4954
  const txRequest = request;
4934
4955
  const requiredQuantitiesWithFee = addAmountToCoinQuantities({
4935
- amount: bn18(fee),
4956
+ amount: bn19(fee),
4936
4957
  assetId: baseAssetId,
4937
4958
  coinQuantities: requiredQuantities
4938
4959
  });
@@ -4940,21 +4961,17 @@ var Account = class extends AbstractAccount {
4940
4961
  requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
4941
4962
  quantitiesDict[assetId] = {
4942
4963
  required: amount,
4943
- owned: bn18(0)
4964
+ owned: bn19(0)
4944
4965
  };
4945
4966
  });
4946
- txRequest.inputs.forEach((input) => {
4947
- const isResource = "amount" in input;
4948
- if (!isResource) {
4949
- return;
4950
- }
4951
- const isCoin2 = "owner" in input;
4967
+ request.inputs.filter(isRequestInputResource).forEach((input) => {
4968
+ const isCoin2 = isRequestInputCoin(input);
4952
4969
  const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
4953
4970
  if (quantitiesDict[assetId]) {
4954
4971
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
4955
4972
  }
4956
4973
  });
4957
- const missingQuantities = [];
4974
+ let missingQuantities = [];
4958
4975
  Object.entries(quantitiesDict).forEach(([assetId, { owned, required }]) => {
4959
4976
  if (owned.lt(required)) {
4960
4977
  missingQuantities.push({
@@ -4963,11 +4980,42 @@ var Account = class extends AbstractAccount {
4963
4980
  });
4964
4981
  }
4965
4982
  });
4966
- const needsToBeFunded = missingQuantities.length;
4967
- if (needsToBeFunded) {
4968
- const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
4969
- const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
4970
- txRequest.addResources(resources);
4983
+ let needsToBeFunded = missingQuantities.length > 0;
4984
+ let fundingAttempts = 0;
4985
+ while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
4986
+ const resources = await this.getResourcesToSpend(
4987
+ missingQuantities,
4988
+ cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
4989
+ );
4990
+ request.addResources(resources);
4991
+ txRequest.shiftPredicateData();
4992
+ txRequest.updatePredicateGasUsed(estimatedPredicates);
4993
+ const requestToReestimate2 = clone4(txRequest);
4994
+ if (addedSignatures) {
4995
+ Array.from({ length: addedSignatures }).forEach(
4996
+ () => requestToReestimate2.addEmptyWitness()
4997
+ );
4998
+ }
4999
+ const { maxFee: newFee } = await this.provider.estimateTxGasAndFee({
5000
+ transactionRequest: requestToReestimate2
5001
+ });
5002
+ const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
5003
+ request.inputs,
5004
+ baseAssetId,
5005
+ baseAssetId
5006
+ );
5007
+ const totalBaseAssetRequiredWithFee = requiredInBaseAsset.add(newFee);
5008
+ if (totalBaseAssetOnInputs.gt(totalBaseAssetRequiredWithFee)) {
5009
+ needsToBeFunded = false;
5010
+ } else {
5011
+ missingQuantities = [
5012
+ {
5013
+ amount: totalBaseAssetRequiredWithFee.sub(totalBaseAssetOnInputs),
5014
+ assetId: baseAssetId
5015
+ }
5016
+ ];
5017
+ }
5018
+ fundingAttempts += 1;
4971
5019
  }
4972
5020
  txRequest.shiftPredicateData();
4973
5021
  txRequest.updatePredicateGasUsed(estimatedPredicates);
@@ -5018,7 +5066,7 @@ var Account = class extends AbstractAccount {
5018
5066
  * @returns A promise that resolves to the transaction response.
5019
5067
  */
5020
5068
  async transfer(destination, amount, assetId, txParams = {}) {
5021
- if (bn18(amount).lte(0)) {
5069
+ if (bn19(amount).lte(0)) {
5022
5070
  throw new FuelError15(
5023
5071
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5024
5072
  "Transfer amount must be a positive number."
@@ -5038,7 +5086,7 @@ var Account = class extends AbstractAccount {
5038
5086
  * @returns A promise that resolves to the transaction response.
5039
5087
  */
5040
5088
  async transferToContract(contractId, amount, assetId, txParams = {}) {
5041
- if (bn18(amount).lte(0)) {
5089
+ if (bn19(amount).lte(0)) {
5042
5090
  throw new FuelError15(
5043
5091
  ErrorCode15.INVALID_TRANSFER_AMOUNT,
5044
5092
  "Transfer amount must be a positive number."
@@ -5048,7 +5096,7 @@ var Account = class extends AbstractAccount {
5048
5096
  const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5049
5097
  const { script, scriptData } = await assembleTransferToContractScript({
5050
5098
  hexlifiedContractId: contractAddress.toB256(),
5051
- amountToTransfer: bn18(amount),
5099
+ amountToTransfer: bn19(amount),
5052
5100
  assetId: assetIdToTransfer
5053
5101
  });
5054
5102
  const request = new ScriptTransactionRequest({
@@ -5059,7 +5107,7 @@ var Account = class extends AbstractAccount {
5059
5107
  request.addContractInputAndOutput(contractAddress);
5060
5108
  const txCost = await this.provider.getTransactionCost(request, {
5061
5109
  resourcesOwner: this,
5062
- quantitiesToContract: [{ amount: bn18(amount), assetId: String(assetIdToTransfer) }]
5110
+ quantitiesToContract: [{ amount: bn19(amount), assetId: String(assetIdToTransfer) }]
5063
5111
  });
5064
5112
  this.validateGasLimitAndMaxFee({
5065
5113
  gasUsed: txCost.gasUsed,
@@ -5085,7 +5133,7 @@ var Account = class extends AbstractAccount {
5085
5133
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5086
5134
  );
5087
5135
  const amountDataArray = arrayify14(
5088
- "0x".concat(bn18(amount).toHex().substring(2).padStart(16, "0"))
5136
+ "0x".concat(bn19(amount).toHex().substring(2).padStart(16, "0"))
5089
5137
  );
5090
5138
  const script = new Uint8Array([
5091
5139
  ...arrayify14(withdrawScript.bytes),
@@ -5095,7 +5143,7 @@ var Account = class extends AbstractAccount {
5095
5143
  const params = { script, ...txParams };
5096
5144
  const baseAssetId = this.provider.getBaseAssetId();
5097
5145
  const request = new ScriptTransactionRequest(params);
5098
- const quantitiesToContract = [{ amount: bn18(amount), assetId: baseAssetId }];
5146
+ const quantitiesToContract = [{ amount: bn19(amount), assetId: baseAssetId }];
5099
5147
  const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5100
5148
  this.validateGasLimitAndMaxFee({
5101
5149
  gasUsed: txCost.gasUsed,
@@ -5167,13 +5215,13 @@ var Account = class extends AbstractAccount {
5167
5215
  gasUsed,
5168
5216
  maxFee
5169
5217
  }) {
5170
- if (isDefined(setGasLimit) && gasUsed.gt(setGasLimit)) {
5218
+ if (isDefined2(setGasLimit) && gasUsed.gt(setGasLimit)) {
5171
5219
  throw new FuelError15(
5172
5220
  ErrorCode15.GAS_LIMIT_TOO_LOW,
5173
5221
  `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
5174
5222
  );
5175
5223
  }
5176
- if (isDefined(setMaxFee) && maxFee.gt(setMaxFee)) {
5224
+ if (isDefined2(setMaxFee) && maxFee.gt(setMaxFee)) {
5177
5225
  throw new FuelError15(
5178
5226
  ErrorCode15.MAX_FEE_TOO_LOW,
5179
5227
  `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
@@ -5505,7 +5553,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5505
5553
  // src/hdwallet/hdwallet.ts
5506
5554
  import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
5507
5555
  import { sha256 as sha2564 } from "@fuel-ts/hasher";
5508
- import { bn as bn19, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5556
+ import { bn as bn20, toBytes as toBytes2, toHex } from "@fuel-ts/math";
5509
5557
  import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
5510
5558
  import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
5511
5559
 
@@ -7971,7 +8019,7 @@ var HDWallet = class {
7971
8019
  const IR = bytes.slice(32);
7972
8020
  if (privateKey) {
7973
8021
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
7974
- const ki = bn19(IL).add(privateKey).mod(N).toBytes(32);
8022
+ const ki = bn20(IL).add(privateKey).mod(N).toBytes(32);
7975
8023
  return new HDWallet({
7976
8024
  privateKey: ki,
7977
8025
  chainCode: IR,
@@ -8476,14 +8524,14 @@ import { UTXO_ID_LEN as UTXO_ID_LEN4 } from "@fuel-ts/abi-coder";
8476
8524
  import { getRandomB256 } from "@fuel-ts/address";
8477
8525
  import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
8478
8526
  import { randomBytes as randomBytes7 } from "@fuel-ts/crypto";
8479
- import { bn as bn20 } from "@fuel-ts/math";
8480
- import { InputType as InputType9 } from "@fuel-ts/transactions";
8527
+ import { bn as bn21 } from "@fuel-ts/math";
8528
+ import { InputType as InputType8 } from "@fuel-ts/transactions";
8481
8529
  import { hexlify as hexlify19 } from "@fuel-ts/utils";
8482
8530
  var generateFakeRequestInputCoin = (partial = {}) => ({
8483
8531
  id: hexlify19(randomBytes7(UTXO_ID_LEN4)),
8484
- type: InputType9.Coin,
8532
+ type: InputType8.Coin,
8485
8533
  owner: getRandomB256(),
8486
- amount: bn20(100),
8534
+ amount: bn21(100),
8487
8535
  assetId: ZeroBytes329,
8488
8536
  txPointer: "0x00000000000000000000000000000000",
8489
8537
  witnessIndex: 0,
@@ -8491,16 +8539,16 @@ var generateFakeRequestInputCoin = (partial = {}) => ({
8491
8539
  });
8492
8540
  var generateFakeRequestInputMessage = (partial = {}) => ({
8493
8541
  nonce: getRandomB256(),
8494
- type: InputType9.Message,
8542
+ type: InputType8.Message,
8495
8543
  sender: getRandomB256(),
8496
8544
  recipient: getRandomB256(),
8497
- amount: bn20(100),
8545
+ amount: bn21(100),
8498
8546
  witnessIndex: 0,
8499
8547
  ...partial
8500
8548
  });
8501
8549
  var generateFakeRequestInputContract = (partial = {}) => ({
8502
8550
  contractId: getRandomB256(),
8503
- type: InputType9.Contract,
8551
+ type: InputType8.Contract,
8504
8552
  txPointer: "0x00000000000000000000000000000000",
8505
8553
  ...partial
8506
8554
  });