@fuel-ts/account 0.0.0-pr-1699-20240214162434 → 0.0.0-pr-1784-20240221124858

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.

Files changed (70) hide show
  1. package/dist/account.d.ts +7 -4
  2. package/dist/account.d.ts.map +1 -1
  3. package/dist/connectors/fuel.d.ts +5 -6
  4. package/dist/connectors/fuel.d.ts.map +1 -1
  5. package/dist/connectors/index.d.ts +0 -2
  6. package/dist/connectors/index.d.ts.map +1 -1
  7. package/dist/connectors/types/asset.d.ts +0 -14
  8. package/dist/connectors/types/asset.d.ts.map +1 -1
  9. package/dist/connectors/types/data-type.d.ts +0 -4
  10. package/dist/connectors/types/data-type.d.ts.map +1 -1
  11. package/dist/connectors/types/events.d.ts +0 -5
  12. package/dist/connectors/types/events.d.ts.map +1 -1
  13. package/dist/connectors/types/index.d.ts +0 -2
  14. package/dist/connectors/types/index.d.ts.map +1 -1
  15. package/dist/connectors/utils/cache.d.ts.map +1 -1
  16. package/dist/connectors/utils/index.d.ts +0 -1
  17. package/dist/connectors/utils/index.d.ts.map +1 -1
  18. package/dist/index.global.js +718 -605
  19. package/dist/index.global.js.map +1 -1
  20. package/dist/index.js +278 -162
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +336 -220
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/predicate/predicate.d.ts.map +1 -1
  25. package/dist/providers/assets/index.d.ts +4 -0
  26. package/dist/providers/assets/index.d.ts.map +1 -0
  27. package/dist/providers/assets/types.d.ts +36 -0
  28. package/dist/providers/assets/types.d.ts.map +1 -0
  29. package/dist/providers/assets/utils/index.d.ts +4 -0
  30. package/dist/providers/assets/utils/index.d.ts.map +1 -0
  31. package/dist/providers/assets/utils/network.d.ts +33 -0
  32. package/dist/providers/assets/utils/network.d.ts.map +1 -0
  33. package/dist/providers/assets/utils/resolveIconPaths.d.ts +14 -0
  34. package/dist/providers/assets/utils/resolveIconPaths.d.ts.map +1 -0
  35. package/dist/providers/assets/utils/url.d.ts +2 -0
  36. package/dist/providers/assets/utils/url.d.ts.map +1 -0
  37. package/dist/providers/chains.d.ts +11 -0
  38. package/dist/providers/chains.d.ts.map +1 -0
  39. package/dist/providers/index.d.ts +2 -0
  40. package/dist/providers/index.d.ts.map +1 -1
  41. package/dist/providers/provider.d.ts +14 -6
  42. package/dist/providers/provider.d.ts.map +1 -1
  43. package/dist/providers/transaction-request/transaction-request.d.ts +3 -10
  44. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  45. package/dist/providers/utils/json.d.ts.map +1 -1
  46. package/dist/test-utils.global.js +593 -496
  47. package/dist/test-utils.global.js.map +1 -1
  48. package/dist/test-utils.js +176 -79
  49. package/dist/test-utils.js.map +1 -1
  50. package/dist/test-utils.mjs +231 -134
  51. package/dist/test-utils.mjs.map +1 -1
  52. package/dist/wallet/base-wallet-unlocked.d.ts +3 -3
  53. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  54. package/package.json +17 -17
  55. package/dist/connectors/fixtures/generate-accounts.d.ts +0 -2
  56. package/dist/connectors/fixtures/generate-accounts.d.ts.map +0 -1
  57. package/dist/connectors/fixtures/mocked-connector.d.ts +0 -45
  58. package/dist/connectors/fixtures/mocked-connector.d.ts.map +0 -1
  59. package/dist/connectors/fixtures/promise-callback.d.ts +0 -7
  60. package/dist/connectors/fixtures/promise-callback.d.ts.map +0 -1
  61. package/dist/connectors/fuel-wallet-locked.d.ts +0 -13
  62. package/dist/connectors/fuel-wallet-locked.d.ts.map +0 -1
  63. package/dist/connectors/fuel-wallet-provider.d.ts +0 -14
  64. package/dist/connectors/fuel-wallet-provider.d.ts.map +0 -1
  65. package/dist/connectors/types/connection.d.ts +0 -7
  66. package/dist/connectors/types/connection.d.ts.map +0 -1
  67. package/dist/connectors/types/nertwork-data.d.ts +0 -7
  68. package/dist/connectors/types/nertwork-data.d.ts.map +0 -1
  69. package/dist/connectors/utils/get-asset-by-chain.d.ts +0 -3
  70. package/dist/connectors/utils/get-asset-by-chain.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -59,22 +59,17 @@ var src_exports = {};
59
59
  __export(src_exports, {
60
60
  Account: () => Account,
61
61
  AddressType: () => AddressType,
62
- BACKGROUND_SCRIPT_NAME: () => BACKGROUND_SCRIPT_NAME,
63
62
  BaseTransactionRequest: () => BaseTransactionRequest,
64
63
  BaseWalletUnlocked: () => BaseWalletUnlocked,
65
- CONNECTOR_SCRIPT: () => CONNECTOR_SCRIPT,
66
- CONTENT_SCRIPT_NAME: () => CONTENT_SCRIPT_NAME,
64
+ CHAIN_IDS: () => CHAIN_IDS,
67
65
  ChainName: () => ChainName,
68
66
  ChangeOutputCollisionError: () => ChangeOutputCollisionError,
69
67
  CreateTransactionRequest: () => CreateTransactionRequest,
70
- EVENT_MESSAGE: () => EVENT_MESSAGE,
71
68
  Fuel: () => Fuel,
72
69
  FuelConnector: () => FuelConnector,
73
70
  FuelConnectorEventType: () => FuelConnectorEventType,
74
71
  FuelConnectorEventTypes: () => FuelConnectorEventTypes,
75
72
  FuelConnectorMethods: () => FuelConnectorMethods,
76
- FuelWalletLocked: () => FuelWalletLocked,
77
- FuelWalletProvider: () => FuelWalletProvider,
78
73
  HDWallet: () => hdwallet_default,
79
74
  Language: () => Language,
80
75
  LocalStorage: () => LocalStorage,
@@ -86,7 +81,6 @@ __export(src_exports, {
86
81
  NoWitnessAtIndexError: () => NoWitnessAtIndexError,
87
82
  NoWitnessByOwnerError: () => NoWitnessByOwnerError,
88
83
  OperationName: () => OperationName,
89
- POPUP_SCRIPT_NAME: () => POPUP_SCRIPT_NAME,
90
84
  Predicate: () => Predicate,
91
85
  PrivateKeyVault: () => PrivateKeyVault,
92
86
  Provider: () => Provider,
@@ -97,7 +91,6 @@ __export(src_exports, {
97
91
  TransactionStatus: () => TransactionStatus,
98
92
  TransactionType: () => import_transactions5.TransactionType,
99
93
  TransactionTypeName: () => TransactionTypeName,
100
- VAULT_SCRIPT_NAME: () => VAULT_SCRIPT_NAME,
101
94
  Vault: () => Vault,
102
95
  Wallet: () => Wallet,
103
96
  WalletLocked: () => WalletLocked,
@@ -107,6 +100,7 @@ __export(src_exports, {
107
100
  addOperation: () => addOperation,
108
101
  assembleReceiptByType: () => assembleReceiptByType,
109
102
  assembleTransactionSummary: () => assembleTransactionSummary,
103
+ assets: () => assets,
110
104
  buildBlockExplorerUrl: () => buildBlockExplorerUrl,
111
105
  cacheFor: () => cacheFor,
112
106
  calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
@@ -124,11 +118,15 @@ __export(src_exports, {
124
118
  fromTai64ToUnix: () => fromTai64ToUnix,
125
119
  fromUnixToTai64: () => fromUnixToTai64,
126
120
  gasUsedByInputs: () => gasUsedByInputs,
127
- getAssetByChain: () => getAssetByChain,
121
+ getAssetEth: () => getAssetEth,
122
+ getAssetFuel: () => getAssetFuel,
123
+ getAssetNetwork: () => getAssetNetwork,
124
+ getAssetWithNetwork: () => getAssetWithNetwork,
128
125
  getContractCallOperations: () => getContractCallOperations,
129
126
  getContractCreatedOperations: () => getContractCreatedOperations,
130
127
  getContractTransferOperations: () => getContractTransferOperations,
131
128
  getDecodedLogs: () => getDecodedLogs,
129
+ getDefaultChainId: () => getDefaultChainId,
132
130
  getGasUsedFromReceipts: () => getGasUsedFromReceipts,
133
131
  getInputAccountAddress: () => getInputAccountAddress,
134
132
  getInputContractFromIndex: () => getInputContractFromIndex,
@@ -177,9 +175,11 @@ __export(src_exports, {
177
175
  processGqlReceipt: () => processGqlReceipt,
178
176
  processGraphqlStatus: () => processGraphqlStatus,
179
177
  resolveGasDependentCosts: () => resolveGasDependentCosts,
178
+ resolveIconPaths: () => resolveIconPaths,
180
179
  returnZeroScript: () => returnZeroScript,
181
180
  sleep: () => sleep,
182
181
  transactionRequestify: () => transactionRequestify,
182
+ urlJoin: () => urlJoin,
183
183
  withTimeout: () => withTimeout,
184
184
  withdrawScript: () => withdrawScript
185
185
  });
@@ -234,7 +234,9 @@ var import_address3 = require("@fuel-ts/address");
234
234
  var import_errors13 = require("@fuel-ts/errors");
235
235
  var import_math14 = require("@fuel-ts/math");
236
236
  var import_transactions17 = require("@fuel-ts/transactions");
237
+ var import_utils5 = require("@fuel-ts/utils");
237
238
  var import_versions = require("@fuel-ts/versions");
239
+ var import_utils6 = require("@noble/curves/abstract/utils");
238
240
  var import_ethers18 = require("ethers");
239
241
  var import_graphql_request = require("graphql-request");
240
242
  var import_ramda3 = require("ramda");
@@ -2140,7 +2142,7 @@ var BaseTransactionRequest = class {
2140
2142
  *
2141
2143
  * @param quantities - CoinQuantity Array.
2142
2144
  */
2143
- fundWithFakeUtxos(quantities) {
2145
+ fundWithFakeUtxos(quantities, resourcesOwner) {
2144
2146
  let idCounter = 0;
2145
2147
  const generateId = () => {
2146
2148
  const counterString = String(idCounter++);
@@ -2164,7 +2166,7 @@ var BaseTransactionRequest = class {
2164
2166
  id: generateId(),
2165
2167
  amount: quantity,
2166
2168
  assetId,
2167
- owner: import_address.Address.fromRandom(),
2169
+ owner: resourcesOwner || import_address.Address.fromRandom(),
2168
2170
  maturity: 0,
2169
2171
  blockCreated: (0, import_math6.bn)(1),
2170
2172
  txCreatedIdx: (0, import_math6.bn)(1)
@@ -2197,19 +2199,29 @@ var BaseTransactionRequest = class {
2197
2199
  toJSON() {
2198
2200
  return normalizeJSON(this);
2199
2201
  }
2200
- /**
2201
- * @hidden
2202
- *
2203
- * Determines whether the transaction has a predicate input.
2204
- *
2205
- * @returns Whether the transaction has a predicate input.
2206
- */
2207
- hasPredicateInput() {
2208
- return Boolean(
2209
- this.inputs.find(
2210
- (input) => "predicate" in input && input.predicate && input.predicate !== (0, import_ethers9.getBytesCopy)("0x")
2211
- )
2212
- );
2202
+ updatePredicateInputs(inputs) {
2203
+ this.inputs.forEach((i) => {
2204
+ let correspondingInput;
2205
+ switch (i.type) {
2206
+ case import_transactions5.InputType.Contract:
2207
+ return;
2208
+ case import_transactions5.InputType.Coin:
2209
+ correspondingInput = inputs.find((x) => x.type === import_transactions5.InputType.Coin && x.owner === i.owner);
2210
+ break;
2211
+ case import_transactions5.InputType.Message:
2212
+ correspondingInput = inputs.find(
2213
+ (x) => x.type === import_transactions5.InputType.Message && x.sender === i.sender
2214
+ );
2215
+ break;
2216
+ default:
2217
+ break;
2218
+ }
2219
+ if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math6.bn)(correspondingInput.predicateGasUsed).gt(0)) {
2220
+ i.predicate = correspondingInput.predicate;
2221
+ i.predicateData = correspondingInput.predicateData;
2222
+ i.predicateGasUsed = correspondingInput.predicateGasUsed;
2223
+ }
2224
+ });
2213
2225
  }
2214
2226
  };
2215
2227
 
@@ -3932,7 +3944,7 @@ var _Provider = class {
3932
3944
  async call(transactionRequestLike, { utxoValidation, estimateTxDependencies = true } = {}) {
3933
3945
  const transactionRequest = transactionRequestify(transactionRequestLike);
3934
3946
  if (estimateTxDependencies) {
3935
- await this.estimateTxDependencies(transactionRequest);
3947
+ return this.estimateTxDependencies(transactionRequest);
3936
3948
  }
3937
3949
  const encodedTransaction = (0, import_ethers18.hexlify)(transactionRequest.toTransactionBytes());
3938
3950
  const { dryRun: gqlReceipts } = await this.operations.dryRun({
@@ -3951,6 +3963,14 @@ var _Provider = class {
3951
3963
  * @returns A promise that resolves to the estimated transaction request object.
3952
3964
  */
3953
3965
  async estimatePredicates(transactionRequest) {
3966
+ const shouldEstimatePredicates = Boolean(
3967
+ transactionRequest.inputs.find(
3968
+ (input) => "predicate" in input && input.predicate && !(0, import_utils6.equalBytes)((0, import_utils5.arrayify)(input.predicate), (0, import_utils5.arrayify)("0x")) && new import_math14.BN(input.predicateGasUsed).isZero()
3969
+ )
3970
+ );
3971
+ if (!shouldEstimatePredicates) {
3972
+ return transactionRequest;
3973
+ }
3954
3974
  const encodedTransaction = (0, import_ethers18.hexlify)(transactionRequest.toTransactionBytes());
3955
3975
  const response = await this.operations.estimatePredicates({
3956
3976
  encodedTransaction
@@ -3981,34 +4001,33 @@ var _Provider = class {
3981
4001
  * @returns A promise.
3982
4002
  */
3983
4003
  async estimateTxDependencies(transactionRequest) {
3984
- let missingOutputVariableCount = 0;
3985
- let missingOutputContractIdsCount = 0;
3986
- let tries = 0;
3987
4004
  if (transactionRequest.type === import_transactions17.TransactionType.Create) {
3988
- return;
3989
- }
3990
- let txRequest = transactionRequest;
3991
- if (txRequest.hasPredicateInput()) {
3992
- txRequest = await this.estimatePredicates(txRequest);
4005
+ return {
4006
+ receipts: []
4007
+ };
3993
4008
  }
3994
- while (tries < MAX_RETRIES) {
4009
+ await this.estimatePredicates(transactionRequest);
4010
+ let receipts = [];
4011
+ for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
3995
4012
  const { dryRun: gqlReceipts } = await this.operations.dryRun({
3996
- encodedTransaction: (0, import_ethers18.hexlify)(txRequest.toTransactionBytes()),
4013
+ encodedTransaction: (0, import_ethers18.hexlify)(transactionRequest.toTransactionBytes()),
3997
4014
  utxoValidation: false
3998
4015
  });
3999
- const receipts = gqlReceipts.map(processGqlReceipt);
4016
+ receipts = gqlReceipts.map(processGqlReceipt);
4000
4017
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
4001
- missingOutputVariableCount = missingOutputVariables.length;
4002
- missingOutputContractIdsCount = missingOutputContractIds.length;
4003
- if (missingOutputVariableCount === 0 && missingOutputContractIdsCount === 0) {
4004
- return;
4018
+ const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
4019
+ if (hasMissingOutputs) {
4020
+ transactionRequest.addVariableOutputs(missingOutputVariables.length);
4021
+ missingOutputContractIds.forEach(({ contractId }) => {
4022
+ transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4023
+ });
4024
+ } else {
4025
+ break;
4005
4026
  }
4006
- txRequest.addVariableOutputs(missingOutputVariableCount);
4007
- missingOutputContractIds.forEach(
4008
- ({ contractId }) => txRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId))
4009
- );
4010
- tries += 1;
4011
4027
  }
4028
+ return {
4029
+ receipts
4030
+ };
4012
4031
  }
4013
4032
  /**
4014
4033
  * Executes a signed transaction without applying the states changes
@@ -4023,7 +4042,7 @@ var _Provider = class {
4023
4042
  async simulate(transactionRequestLike, { estimateTxDependencies = true } = {}) {
4024
4043
  const transactionRequest = transactionRequestify(transactionRequestLike);
4025
4044
  if (estimateTxDependencies) {
4026
- await this.estimateTxDependencies(transactionRequest);
4045
+ return this.estimateTxDependencies(transactionRequest);
4027
4046
  }
4028
4047
  const encodedTransaction = (0, import_ethers18.hexlify)(transactionRequest.toTransactionBytes());
4029
4048
  const { dryRun: gqlReceipts } = await this.operations.dryRun({
@@ -4050,36 +4069,38 @@ var _Provider = class {
4050
4069
  * @param tolerance - The tolerance to add on top of the gasUsed.
4051
4070
  * @returns A promise that resolves to the transaction cost object.
4052
4071
  */
4053
- async getTransactionCost(transactionRequestLike, forwardingQuantities = [], { estimateTxDependencies = true, estimatePredicates = true } = {}) {
4054
- const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4072
+ async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
4073
+ estimateTxDependencies = true,
4074
+ estimatePredicates = true,
4075
+ resourcesOwner
4076
+ } = {}) {
4077
+ const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4055
4078
  const chainInfo = this.getChain();
4056
4079
  const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
4057
- const gasPrice = (0, import_math14.max)(transactionRequest.gasPrice, minGasPrice);
4058
- const isScriptTransaction = transactionRequest.type === import_transactions17.TransactionType.Script;
4059
- if (transactionRequest.hasPredicateInput() && estimatePredicates) {
4080
+ const gasPrice = (0, import_math14.max)(txRequestClone.gasPrice, minGasPrice);
4081
+ const isScriptTransaction = txRequestClone.type === import_transactions17.TransactionType.Script;
4082
+ const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4083
+ const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4084
+ txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
4085
+ if (estimatePredicates) {
4060
4086
  if (isScriptTransaction) {
4061
- transactionRequest.gasLimit = (0, import_math14.bn)(0);
4087
+ txRequestClone.gasLimit = (0, import_math14.bn)(0);
4062
4088
  }
4063
- await this.estimatePredicates(transactionRequest);
4089
+ if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4090
+ resourcesOwner.populateTransactionPredicateData(txRequestClone);
4091
+ }
4092
+ await this.estimatePredicates(txRequestClone);
4064
4093
  }
4065
- const minGas = transactionRequest.calculateMinGas(chainInfo);
4066
- const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4067
- const coinOutputsQuantities = transactionRequest.getCoinOutputsQuantities();
4068
- const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
4069
- transactionRequest.fundWithFakeUtxos(allQuantities);
4070
- let gasUsed = minGas;
4094
+ const minGas = txRequestClone.calculateMinGas(chainInfo);
4095
+ const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
4071
4096
  let receipts = [];
4072
- if (isScriptTransaction) {
4073
- transactionRequest.gasPrice = (0, import_math14.bn)(0);
4074
- transactionRequest.gasLimit = (0, import_math14.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
4075
- const result = await this.call(transactionRequest, {
4076
- estimateTxDependencies
4077
- });
4097
+ if (isScriptTransaction && estimateTxDependencies) {
4098
+ txRequestClone.gasPrice = (0, import_math14.bn)(0);
4099
+ txRequestClone.gasLimit = (0, import_math14.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
4100
+ const result = await this.estimateTxDependencies(txRequestClone);
4078
4101
  receipts = result.receipts;
4079
- gasUsed = getGasUsedFromReceipts(receipts);
4080
- } else {
4081
- gasUsed = minGas;
4082
4102
  }
4103
+ const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
4083
4104
  const usedFee = calculatePriceWithFactor(
4084
4105
  gasUsed,
4085
4106
  gasPrice,
@@ -4097,7 +4118,9 @@ var _Provider = class {
4097
4118
  maxGas,
4098
4119
  usedFee,
4099
4120
  minFee,
4100
- maxFee
4121
+ maxFee,
4122
+ estimatedInputs: txRequestClone.inputs,
4123
+ estimatedOutputs: txRequestClone.outputs
4101
4124
  };
4102
4125
  }
4103
4126
  async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
@@ -4487,6 +4510,10 @@ var _Provider = class {
4487
4510
  });
4488
4511
  return (0, import_math14.bn)(latestBlockHeight);
4489
4512
  }
4513
+ // eslint-disable-next-line @typescript-eslint/require-await
4514
+ async getTransactionResponse(transactionId) {
4515
+ return new TransactionResponse(transactionId, this);
4516
+ }
4490
4517
  };
4491
4518
  var Provider = _Provider;
4492
4519
  _cacheInputs = new WeakSet();
@@ -4599,6 +4626,127 @@ async function getTransactionsSummaries(params) {
4599
4626
  };
4600
4627
  }
4601
4628
 
4629
+ // src/providers/chains.ts
4630
+ var CHAIN_IDS = {
4631
+ eth: {
4632
+ sepolia: 11155111,
4633
+ foundry: 31337
4634
+ },
4635
+ fuel: {
4636
+ beta5: 0,
4637
+ devnet: 10
4638
+ }
4639
+ };
4640
+
4641
+ // src/providers/assets/utils/network.ts
4642
+ var getDefaultChainId = (networkType) => {
4643
+ if (networkType === "ethereum") {
4644
+ return CHAIN_IDS.eth.sepolia;
4645
+ }
4646
+ if (networkType === "fuel") {
4647
+ return CHAIN_IDS.fuel.beta5;
4648
+ }
4649
+ return void 0;
4650
+ };
4651
+ var getAssetNetwork = ({
4652
+ asset,
4653
+ chainId,
4654
+ networkType
4655
+ }) => {
4656
+ const network = asset.networks.find(
4657
+ (item) => item.chainId === chainId && item.type === networkType
4658
+ );
4659
+ return network;
4660
+ };
4661
+ var getAssetWithNetwork = ({
4662
+ asset,
4663
+ chainId,
4664
+ networkType
4665
+ }) => {
4666
+ const { networks: _, ...assetRest } = asset;
4667
+ const chainIdToUse = chainId ?? getDefaultChainId(networkType);
4668
+ if (chainIdToUse === void 0) {
4669
+ return void 0;
4670
+ }
4671
+ const assetNetwork = getAssetNetwork({
4672
+ asset,
4673
+ chainId: chainIdToUse,
4674
+ networkType
4675
+ });
4676
+ if (!assetNetwork) {
4677
+ return void 0;
4678
+ }
4679
+ return {
4680
+ ...assetRest,
4681
+ ...assetNetwork
4682
+ };
4683
+ };
4684
+ var getAssetEth = (asset, chainId) => getAssetWithNetwork({
4685
+ asset,
4686
+ networkType: "ethereum",
4687
+ chainId
4688
+ });
4689
+ var getAssetFuel = (asset, chainId) => getAssetWithNetwork({
4690
+ asset,
4691
+ networkType: "fuel",
4692
+ chainId
4693
+ });
4694
+
4695
+ // src/providers/assets/utils/url.ts
4696
+ var DELIMITER_PATH = "/";
4697
+ var trimRegex = /^\/|\/$/g;
4698
+ var trimPath = (path = "") => path.replace(trimRegex, "");
4699
+ function urlJoin(baseUrl, ...paths) {
4700
+ const hasBaseUrl = baseUrl !== null && baseUrl !== void 0;
4701
+ const rootPath = baseUrl?.[0] === "/" && baseUrl.length > 1;
4702
+ const allPaths = [baseUrl, ...paths].filter(Boolean).map(trimPath);
4703
+ if (rootPath && hasBaseUrl) {
4704
+ allPaths.unshift("");
4705
+ }
4706
+ return allPaths.join(DELIMITER_PATH);
4707
+ }
4708
+
4709
+ // src/providers/assets/utils/resolveIconPaths.ts
4710
+ function resolveIconPaths(assets2, basePath = "./") {
4711
+ return assets2.map((asset) => ({
4712
+ ...asset,
4713
+ icon: urlJoin(basePath, asset.icon)
4714
+ }));
4715
+ }
4716
+
4717
+ // src/providers/assets/index.ts
4718
+ var assets = [
4719
+ {
4720
+ name: "Ethereum",
4721
+ symbol: "ETH",
4722
+ icon: "eth.svg",
4723
+ networks: [
4724
+ {
4725
+ type: "ethereum",
4726
+ chainId: CHAIN_IDS.eth.sepolia,
4727
+ decimals: 18
4728
+ },
4729
+ {
4730
+ type: "ethereum",
4731
+ chainId: CHAIN_IDS.eth.foundry,
4732
+ decimals: 18
4733
+ },
4734
+ {
4735
+ type: "fuel",
4736
+ chainId: CHAIN_IDS.fuel.beta5,
4737
+ decimals: 9,
4738
+ assetId: "0x0000000000000000000000000000000000000000000000000000000000000000"
4739
+ },
4740
+ {
4741
+ type: "fuel",
4742
+ chainId: CHAIN_IDS.fuel.devnet,
4743
+ decimals: 9,
4744
+ assetId: "0x0000000000000000000000000000000000000000000000000000000000000000"
4745
+ }
4746
+ ]
4747
+ }
4748
+ ];
4749
+
4602
4750
  // src/utils/formatTransferToContractScriptData.ts
4603
4751
  var import_abi_coder4 = require("@fuel-ts/abi-coder");
4604
4752
  var import_math16 = require("@fuel-ts/math");
@@ -4645,15 +4793,17 @@ var Account = class extends import_interfaces.AbstractAccount {
4645
4793
  * The provider used to interact with the network.
4646
4794
  */
4647
4795
  _provider;
4796
+ _connector;
4648
4797
  /**
4649
4798
  * Creates a new Account instance.
4650
4799
  *
4651
4800
  * @param address - The address of the account.
4652
4801
  * @param provider - A Provider instance (optional).
4653
4802
  */
4654
- constructor(address, provider) {
4803
+ constructor(address, provider, connector) {
4655
4804
  super();
4656
4805
  this._provider = provider;
4806
+ this._connector = connector;
4657
4807
  this.address = import_address4.Address.fromDynamicInput(address);
4658
4808
  }
4659
4809
  /**
@@ -4859,7 +5009,10 @@ var Account = class extends import_interfaces.AbstractAccount {
4859
5009
  const params = { gasPrice: minGasPrice, ...txParams };
4860
5010
  const request = new ScriptTransactionRequest(params);
4861
5011
  request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
4862
- const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(request);
5012
+ const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
5013
+ estimateTxDependencies: true,
5014
+ resourcesOwner: this
5015
+ });
4863
5016
  request.gasPrice = (0, import_math17.bn)(txParams.gasPrice ?? minGasPrice);
4864
5017
  request.gasLimit = (0, import_math17.bn)(txParams.gasLimit ?? gasUsed);
4865
5018
  this.validateGas({
@@ -4869,6 +5022,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4869
5022
  minGasPrice
4870
5023
  });
4871
5024
  await this.fund(request, requiredQuantities, maxFee);
5025
+ request.updatePredicateInputs(estimatedInputs);
4872
5026
  return request;
4873
5027
  }
4874
5028
  /**
@@ -4882,7 +5036,7 @@ var Account = class extends import_interfaces.AbstractAccount {
4882
5036
  */
4883
5037
  async transfer(destination, amount, assetId = import_configs10.BaseAssetId, txParams = {}) {
4884
5038
  const request = await this.createTransfer(destination, amount, assetId, txParams);
4885
- return this.sendTransaction(request);
5039
+ return this.sendTransaction(request, { estimateTxDependencies: false });
4886
5040
  }
4887
5041
  /**
4888
5042
  * Transfers coins to a contract address.
@@ -4961,17 +5115,30 @@ var Account = class extends import_interfaces.AbstractAccount {
4961
5115
  await this.fund(request, requiredQuantities, maxFee);
4962
5116
  return this.sendTransaction(request);
4963
5117
  }
5118
+ async signMessage(message) {
5119
+ if (!this._connector) {
5120
+ throw new import_errors15.FuelError(import_errors15.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
5121
+ }
5122
+ return this._connector.signMessage(this.address.toString(), message);
5123
+ }
4964
5124
  /**
4965
5125
  * Sends a transaction to the network.
4966
5126
  *
4967
5127
  * @param transactionRequestLike - The transaction request to be sent.
4968
5128
  * @returns A promise that resolves to the transaction response.
4969
5129
  */
4970
- async sendTransaction(transactionRequestLike, options) {
5130
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5131
+ if (this._connector) {
5132
+ return this.provider.getTransactionResponse(
5133
+ await this._connector.sendTransaction(this.address.toString(), transactionRequestLike)
5134
+ );
5135
+ }
4971
5136
  const transactionRequest = transactionRequestify(transactionRequestLike);
4972
- await this.provider.estimateTxDependencies(transactionRequest);
5137
+ if (estimateTxDependencies) {
5138
+ await this.provider.estimateTxDependencies(transactionRequest);
5139
+ }
4973
5140
  return this.provider.sendTransaction(transactionRequest, {
4974
- ...options,
5141
+ awaitExecution,
4975
5142
  estimateTxDependencies: false
4976
5143
  });
4977
5144
  }
@@ -4981,9 +5148,11 @@ var Account = class extends import_interfaces.AbstractAccount {
4981
5148
  * @param transactionRequestLike - The transaction request to be simulated.
4982
5149
  * @returns A promise that resolves to the call result.
4983
5150
  */
4984
- async simulateTransaction(transactionRequestLike) {
5151
+ async simulateTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
4985
5152
  const transactionRequest = transactionRequestify(transactionRequestLike);
4986
- await this.provider.estimateTxDependencies(transactionRequest);
5153
+ if (estimateTxDependencies) {
5154
+ await this.provider.estimateTxDependencies(transactionRequest);
5155
+ }
4987
5156
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
4988
5157
  }
4989
5158
  validateGas({
@@ -5284,12 +5453,14 @@ var BaseWalletUnlocked = class extends Account {
5284
5453
  * @param transactionRequestLike - The transaction request to send.
5285
5454
  * @returns A promise that resolves to the TransactionResponse object.
5286
5455
  */
5287
- async sendTransaction(transactionRequestLike, options) {
5456
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
5288
5457
  const transactionRequest = transactionRequestify(transactionRequestLike);
5289
- await this.provider.estimateTxDependencies(transactionRequest);
5458
+ if (estimateTxDependencies) {
5459
+ await this.provider.estimateTxDependencies(transactionRequest);
5460
+ }
5290
5461
  return this.provider.sendTransaction(
5291
5462
  await this.populateTransactionWitnessesSignature(transactionRequest),
5292
- { ...options, estimateTxDependencies: false }
5463
+ { awaitExecution, estimateTxDependencies: false }
5293
5464
  );
5294
5465
  }
5295
5466
  /**
@@ -5298,9 +5469,11 @@ var BaseWalletUnlocked = class extends Account {
5298
5469
  * @param transactionRequestLike - The transaction request to simulate.
5299
5470
  * @returns A promise that resolves to the CallResult object.
5300
5471
  */
5301
- async simulateTransaction(transactionRequestLike) {
5472
+ async simulateTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
5302
5473
  const transactionRequest = transactionRequestify(transactionRequestLike);
5303
- await this.provider.estimateTxDependencies(transactionRequest);
5474
+ if (estimateTxDependencies) {
5475
+ await this.provider.estimateTxDependencies(transactionRequest);
5476
+ }
5304
5477
  return this.provider.call(
5305
5478
  await this.populateTransactionWitnessesSignature(transactionRequest),
5306
5479
  {
@@ -8479,12 +8652,12 @@ var import_ethers28 = require("ethers");
8479
8652
  // src/predicate/utils/getPredicateRoot.ts
8480
8653
  var import_hasher4 = require("@fuel-ts/hasher");
8481
8654
  var import_merkle = require("@fuel-ts/merkle");
8482
- var import_utils7 = require("@fuel-ts/utils");
8655
+ var import_utils9 = require("@fuel-ts/utils");
8483
8656
  var import_ethers27 = require("ethers");
8484
8657
  var getPredicateRoot = (bytecode) => {
8485
8658
  const chunkSize = 16 * 1024;
8486
8659
  const bytes = (0, import_ethers27.getBytesCopy)(bytecode);
8487
- const chunks = (0, import_utils7.chunkAndPadBytes)(bytes, chunkSize);
8660
+ const chunks = (0, import_utils9.chunkAndPadBytes)(bytes, chunkSize);
8488
8661
  const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_ethers27.hexlify)(c)));
8489
8662
  const predicateRoot = (0, import_hasher4.hash)((0, import_ethers27.concat)(["0x4655454C", codeRoot]));
8490
8663
  return predicateRoot;
@@ -8656,6 +8829,9 @@ var Predicate = class extends Account {
8656
8829
  }
8657
8830
  };
8658
8831
 
8832
+ // src/connectors/fuel.ts
8833
+ var import_errors25 = require("@fuel-ts/errors");
8834
+
8659
8835
  // src/connectors/fuel-connector.ts
8660
8836
  var import_events2 = require("events");
8661
8837
 
@@ -8696,14 +8872,6 @@ var FuelConnectorEventTypes = /* @__PURE__ */ ((FuelConnectorEventTypes2) => {
8696
8872
  })(FuelConnectorEventTypes || {});
8697
8873
  var FuelConnectorEventType = "FuelConnector";
8698
8874
 
8699
- // src/connectors/types/constants.ts
8700
- var CONNECTOR_SCRIPT = "FuelConnectorScript";
8701
- var CONTENT_SCRIPT_NAME = "FuelContentScript";
8702
- var BACKGROUND_SCRIPT_NAME = "FuelBackgroundScript";
8703
- var POPUP_SCRIPT_NAME = "FuelPopUpScript";
8704
- var VAULT_SCRIPT_NAME = "FuelVaultScript";
8705
- var EVENT_MESSAGE = "message";
8706
-
8707
8875
  // src/connectors/types/data-type.ts
8708
8876
  var MessageTypes = /* @__PURE__ */ ((MessageTypes2) => {
8709
8877
  MessageTypes2["ping"] = "ping";
@@ -8953,40 +9121,6 @@ var FuelConnector = class extends import_events2.EventEmitter {
8953
9121
  }
8954
9122
  };
8955
9123
 
8956
- // src/connectors/fuel-wallet-locked.ts
8957
- var FuelWalletLocked = class extends WalletLocked {
8958
- connector;
8959
- _provider;
8960
- constructor(address, connector, provider) {
8961
- super(address, provider);
8962
- this.connector = connector;
8963
- this._provider = provider;
8964
- }
8965
- async signMessage(message) {
8966
- return this.connector.signMessage(this.address.toString(), message);
8967
- }
8968
- async sendTransaction(transaction) {
8969
- const transactionId = await this.connector.sendTransaction(
8970
- this.address.toString(),
8971
- transaction
8972
- );
8973
- return this.provider.getTransactionResponse(transactionId);
8974
- }
8975
- };
8976
-
8977
- // src/connectors/fuel-wallet-provider.ts
8978
- var FuelWalletProvider = class extends Provider {
8979
- static async create(url, options) {
8980
- const provider = new FuelWalletProvider(url, options);
8981
- await provider.fetchChainAndNodeInfo();
8982
- return provider;
8983
- }
8984
- // eslint-disable-next-line @typescript-eslint/require-await
8985
- async getTransactionResponse(transactionId) {
8986
- return new TransactionResponse(transactionId, this);
8987
- }
8988
- };
8989
-
8990
9124
  // src/connectors/utils/cache.ts
8991
9125
  function cacheFor(fn, { cache: cache2, cacheTime, key }) {
8992
9126
  return async (...args) => {
@@ -9016,23 +9150,6 @@ function dispatchFuelConnectorEvent(connector) {
9016
9150
  );
9017
9151
  }
9018
9152
 
9019
- // src/connectors/utils/get-asset-by-chain.ts
9020
- function getAssetByChain(asset, chainId, network = "fuel") {
9021
- const assetFuelNetwork = asset.networks.find(
9022
- (item) => item.chainId === chainId && item.type === network
9023
- );
9024
- if (!assetFuelNetwork) {
9025
- throw new Error("Asset not found for the given chain and network.");
9026
- }
9027
- return {
9028
- ...asset,
9029
- assetId: assetFuelNetwork.assetId,
9030
- decimals: assetFuelNetwork.decimals,
9031
- chainId: assetFuelNetwork.chainId,
9032
- network: assetFuelNetwork.type
9033
- };
9034
- }
9035
-
9036
9153
  // src/connectors/utils/promises.ts
9037
9154
  function deferPromise() {
9038
9155
  const defer = {};
@@ -9054,6 +9171,7 @@ async function withTimeout(promise, timeout = 1050) {
9054
9171
  // src/connectors/fuel.ts
9055
9172
  var HAS_CONNECTOR_TIMEOUT = 2e3;
9056
9173
  var PING_CACHE_TIME = 5e3;
9174
+ var { warn } = console;
9057
9175
  var _Fuel = class extends FuelConnector {
9058
9176
  _storage = null;
9059
9177
  _connectors = [];
@@ -9322,14 +9440,12 @@ var _Fuel = class extends FuelConnector {
9322
9440
  * Return a Fuel Provider instance with extends features to work with
9323
9441
  * connectors.
9324
9442
  *
9325
- * @deprecated Provider is going to be deprecated in the future.
9443
+ * @deprecated getProvider is deprecated and is going to be removed in the future, use getWallet instead.
9326
9444
  */
9327
9445
  async getProvider(providerOrNetwork) {
9328
- if (process.env.NODE_ENV !== "production") {
9329
- console.warn(
9330
- "Get provider is deprecated, use getWallet instead. Provider is going to be removed in the future."
9331
- );
9332
- }
9446
+ warn(
9447
+ "getProvider is deprecated and is going to be removed in the future, use getWallet instead."
9448
+ );
9333
9449
  return this._getProvider(providerOrNetwork);
9334
9450
  }
9335
9451
  /**
@@ -9341,12 +9457,12 @@ var _Fuel = class extends FuelConnector {
9341
9457
  if (providerOrNetwork && "getTransactionResponse" in providerOrNetwork) {
9342
9458
  provider = providerOrNetwork;
9343
9459
  } else if (providerOrNetwork && "chainId" in providerOrNetwork && "url" in providerOrNetwork) {
9344
- provider = await FuelWalletProvider.create(providerOrNetwork.url);
9460
+ provider = await Provider.create(providerOrNetwork.url);
9345
9461
  } else if (!providerOrNetwork) {
9346
9462
  const currentNetwork = await this.currentNetwork();
9347
- provider = await FuelWalletProvider.create(currentNetwork.url);
9463
+ provider = await Provider.create(currentNetwork.url);
9348
9464
  } else {
9349
- throw new Error("Provider is not valid.");
9465
+ throw new import_errors25.FuelError(import_errors25.ErrorCode.INVALID_PROVIDER, "Provider is not valid.");
9350
9466
  }
9351
9467
  return provider;
9352
9468
  }
@@ -9356,7 +9472,7 @@ var _Fuel = class extends FuelConnector {
9356
9472
  */
9357
9473
  async getWallet(address, providerOrNetwork) {
9358
9474
  const provider = await this._getProvider(providerOrNetwork);
9359
- return new FuelWalletLocked(address, this, provider);
9475
+ return new Account(address, provider, this);
9360
9476
  }
9361
9477
  /**
9362
9478
  * Remove all open listeners this is useful when you want to
@@ -9388,22 +9504,17 @@ __publicField(Fuel, "defaultConfig", {});
9388
9504
  0 && (module.exports = {
9389
9505
  Account,
9390
9506
  AddressType,
9391
- BACKGROUND_SCRIPT_NAME,
9392
9507
  BaseTransactionRequest,
9393
9508
  BaseWalletUnlocked,
9394
- CONNECTOR_SCRIPT,
9395
- CONTENT_SCRIPT_NAME,
9509
+ CHAIN_IDS,
9396
9510
  ChainName,
9397
9511
  ChangeOutputCollisionError,
9398
9512
  CreateTransactionRequest,
9399
- EVENT_MESSAGE,
9400
9513
  Fuel,
9401
9514
  FuelConnector,
9402
9515
  FuelConnectorEventType,
9403
9516
  FuelConnectorEventTypes,
9404
9517
  FuelConnectorMethods,
9405
- FuelWalletLocked,
9406
- FuelWalletProvider,
9407
9518
  HDWallet,
9408
9519
  Language,
9409
9520
  LocalStorage,
@@ -9415,7 +9526,6 @@ __publicField(Fuel, "defaultConfig", {});
9415
9526
  NoWitnessAtIndexError,
9416
9527
  NoWitnessByOwnerError,
9417
9528
  OperationName,
9418
- POPUP_SCRIPT_NAME,
9419
9529
  Predicate,
9420
9530
  PrivateKeyVault,
9421
9531
  Provider,
@@ -9426,7 +9536,6 @@ __publicField(Fuel, "defaultConfig", {});
9426
9536
  TransactionStatus,
9427
9537
  TransactionType,
9428
9538
  TransactionTypeName,
9429
- VAULT_SCRIPT_NAME,
9430
9539
  Vault,
9431
9540
  Wallet,
9432
9541
  WalletLocked,
@@ -9436,6 +9545,7 @@ __publicField(Fuel, "defaultConfig", {});
9436
9545
  addOperation,
9437
9546
  assembleReceiptByType,
9438
9547
  assembleTransactionSummary,
9548
+ assets,
9439
9549
  buildBlockExplorerUrl,
9440
9550
  cacheFor,
9441
9551
  calculateMetadataGasForTxCreate,
@@ -9453,11 +9563,15 @@ __publicField(Fuel, "defaultConfig", {});
9453
9563
  fromTai64ToUnix,
9454
9564
  fromUnixToTai64,
9455
9565
  gasUsedByInputs,
9456
- getAssetByChain,
9566
+ getAssetEth,
9567
+ getAssetFuel,
9568
+ getAssetNetwork,
9569
+ getAssetWithNetwork,
9457
9570
  getContractCallOperations,
9458
9571
  getContractCreatedOperations,
9459
9572
  getContractTransferOperations,
9460
9573
  getDecodedLogs,
9574
+ getDefaultChainId,
9461
9575
  getGasUsedFromReceipts,
9462
9576
  getInputAccountAddress,
9463
9577
  getInputContractFromIndex,
@@ -9506,9 +9620,11 @@ __publicField(Fuel, "defaultConfig", {});
9506
9620
  processGqlReceipt,
9507
9621
  processGraphqlStatus,
9508
9622
  resolveGasDependentCosts,
9623
+ resolveIconPaths,
9509
9624
  returnZeroScript,
9510
9625
  sleep,
9511
9626
  transactionRequestify,
9627
+ urlJoin,
9512
9628
  withTimeout,
9513
9629
  withdrawScript
9514
9630
  });