@fuel-ts/account 0.0.0-pr-2943-20240815143842 → 0.0.0-pr-2942-20240816061339

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 (85) hide show
  1. package/README.md +9 -29
  2. package/dist/account.d.ts +15 -4
  3. package/dist/account.d.ts.map +1 -1
  4. package/dist/configs.d.ts +0 -2
  5. package/dist/configs.d.ts.map +1 -1
  6. package/dist/configs.global.js +0 -2
  7. package/dist/configs.global.js.map +1 -1
  8. package/dist/configs.js +0 -6
  9. package/dist/configs.js.map +1 -1
  10. package/dist/configs.mjs +0 -4
  11. package/dist/configs.mjs.map +1 -1
  12. package/dist/connectors/fuel-connector.d.ts +24 -1
  13. package/dist/connectors/fuel-connector.d.ts.map +1 -1
  14. package/dist/connectors/fuel.d.ts +14 -2
  15. package/dist/connectors/fuel.d.ts.map +1 -1
  16. package/dist/connectors/types/connector-metadata.d.ts.map +1 -1
  17. package/dist/connectors/utils/promises.d.ts.map +1 -1
  18. package/dist/index.global.js +1388 -1033
  19. package/dist/index.global.js.map +1 -1
  20. package/dist/index.js +706 -528
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +534 -367
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/predicate/predicate.d.ts +15 -9
  25. package/dist/predicate/predicate.d.ts.map +1 -1
  26. package/dist/providers/__generated__/operations.d.ts +119 -0
  27. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  28. package/dist/providers/fuel-graphql-subscriber.d.ts +1 -0
  29. package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
  30. package/dist/providers/provider.d.ts +14 -47
  31. package/dist/providers/provider.d.ts.map +1 -1
  32. package/dist/providers/resource-cache.d.ts +14 -0
  33. package/dist/providers/resource-cache.d.ts.map +1 -0
  34. package/dist/providers/transaction-request/blob-transaction-request.d.ts +48 -0
  35. package/dist/providers/transaction-request/blob-transaction-request.d.ts.map +1 -0
  36. package/dist/providers/transaction-request/index.d.ts +1 -0
  37. package/dist/providers/transaction-request/index.d.ts.map +1 -1
  38. package/dist/providers/transaction-request/transaction-request.d.ts +4 -3
  39. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  40. package/dist/providers/transaction-request/types.d.ts +5 -2
  41. package/dist/providers/transaction-request/types.d.ts.map +1 -1
  42. package/dist/providers/transaction-request/utils.d.ts +9 -0
  43. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  44. package/dist/providers/transaction-response/transaction-response.d.ts +3 -0
  45. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  46. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  47. package/dist/providers/transaction-summary/call.d.ts +4 -3
  48. package/dist/providers/transaction-summary/call.d.ts.map +1 -1
  49. package/dist/providers/transaction-summary/input.d.ts +1 -1
  50. package/dist/providers/transaction-summary/input.d.ts.map +1 -1
  51. package/dist/providers/transaction-summary/operations.d.ts +3 -1
  52. package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
  53. package/dist/providers/transaction-summary/types.d.ts +3 -1
  54. package/dist/providers/transaction-summary/types.d.ts.map +1 -1
  55. package/dist/providers/utils/gas.d.ts +6 -0
  56. package/dist/providers/utils/gas.d.ts.map +1 -1
  57. package/dist/test-utils/launchNode.d.ts +0 -16
  58. package/dist/test-utils/launchNode.d.ts.map +1 -1
  59. package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -1
  60. package/dist/test-utils/test-asset-id.d.ts +8 -0
  61. package/dist/test-utils/test-asset-id.d.ts.map +1 -0
  62. package/dist/test-utils/test-message.d.ts +4 -2
  63. package/dist/test-utils/test-message.d.ts.map +1 -1
  64. package/dist/test-utils/wallet-config.d.ts +3 -3
  65. package/dist/test-utils/wallet-config.d.ts.map +1 -1
  66. package/dist/test-utils.d.ts +1 -3
  67. package/dist/test-utils.d.ts.map +1 -1
  68. package/dist/test-utils.global.js +39070 -38743
  69. package/dist/test-utils.global.js.map +1 -1
  70. package/dist/test-utils.js +1314 -1201
  71. package/dist/test-utils.js.map +1 -1
  72. package/dist/test-utils.mjs +1031 -919
  73. package/dist/test-utils.mjs.map +1 -1
  74. package/dist/wallet/base-wallet-unlocked.d.ts +1 -2
  75. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  76. package/dist/wallet/keystore-wallet.d.ts.map +1 -1
  77. package/package.json +19 -21
  78. package/dist/providers/memory-cache.d.ts +0 -11
  79. package/dist/providers/memory-cache.d.ts.map +0 -1
  80. package/dist/test-utils/asset-id.d.ts +0 -8
  81. package/dist/test-utils/asset-id.d.ts.map +0 -1
  82. package/dist/test-utils/generateTestWallet.d.ts +0 -4
  83. package/dist/test-utils/generateTestWallet.d.ts.map +0 -1
  84. package/dist/test-utils/seedTestWallet.d.ts +0 -4
  85. package/dist/test-utils/seedTestWallet.d.ts.map +0 -1
@@ -48,34 +48,338 @@ var __privateMethod = (obj, member, method) => {
48
48
  // src/test-utils.ts
49
49
  var test_utils_exports = {};
50
50
  __export(test_utils_exports, {
51
- AssetId: () => AssetId,
51
+ TestAssetId: () => TestAssetId,
52
52
  TestMessage: () => TestMessage,
53
53
  WalletsConfig: () => WalletsConfig,
54
- generateTestWallet: () => generateTestWallet,
55
54
  launchNode: () => launchNode,
56
- launchNodeAndGetWallets: () => launchNodeAndGetWallets,
57
- seedTestWallet: () => seedTestWallet,
58
55
  setupTestProviderAndWallets: () => setupTestProviderAndWallets
59
56
  });
60
57
  module.exports = __toCommonJS(test_utils_exports);
61
58
 
62
- // src/wallet/base-wallet-unlocked.ts
63
- var import_hasher3 = require("@fuel-ts/hasher");
64
- var import_utils32 = require("@fuel-ts/utils");
65
-
66
- // src/account.ts
67
- var import_abi_coder7 = require("@fuel-ts/abi-coder");
68
- var import_address4 = require("@fuel-ts/address");
59
+ // src/test-utils/launchNode.ts
60
+ var import_abi_coder = require("@fuel-ts/abi-coder");
69
61
  var import_crypto2 = require("@fuel-ts/crypto");
70
- var import_errors16 = require("@fuel-ts/errors");
71
- var import_interfaces = require("@fuel-ts/interfaces");
72
- var import_math20 = require("@fuel-ts/math");
73
- var import_utils29 = require("@fuel-ts/utils");
74
- var import_ramda4 = require("ramda");
62
+ var import_errors = require("@fuel-ts/errors");
63
+ var import_utils2 = require("@fuel-ts/utils");
64
+ var import_fs = require("fs");
65
+ var import_os = __toESM(require("os"));
66
+ var import_path = __toESM(require("path"));
67
+ var import_portfinder = require("portfinder");
68
+
69
+ // src/signer/signer.ts
70
+ var import_address = require("@fuel-ts/address");
71
+ var import_crypto = require("@fuel-ts/crypto");
72
+ var import_hasher = require("@fuel-ts/hasher");
73
+ var import_math = require("@fuel-ts/math");
74
+ var import_utils = require("@fuel-ts/utils");
75
+ var import_secp256k1 = require("@noble/curves/secp256k1");
76
+ var Signer = class {
77
+ address;
78
+ publicKey;
79
+ compressedPublicKey;
80
+ privateKey;
81
+ /**
82
+ * Create a Signer instance from a given private key
83
+ *
84
+ * @param privateKey - The private key to use for signing
85
+ * @returns A new Signer instance
86
+ */
87
+ constructor(privateKey) {
88
+ if (typeof privateKey === "string") {
89
+ if (privateKey.match(/^[0-9a-f]*$/i) && privateKey.length === 64) {
90
+ privateKey = `0x${privateKey}`;
91
+ }
92
+ }
93
+ const privateKeyBytes = (0, import_math.toBytes)(privateKey, 32);
94
+ this.privateKey = (0, import_utils.hexlify)(privateKeyBytes);
95
+ this.publicKey = (0, import_utils.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
96
+ this.compressedPublicKey = (0, import_utils.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
97
+ this.address = import_address.Address.fromPublicKey(this.publicKey);
98
+ }
99
+ /**
100
+ * Sign data using the Signer instance
101
+ *
102
+ * Signature is a 64 byte array of the concatenated r and s values with the compressed recoveryParam byte.
103
+ * @ignore
104
+ * [Read more](FuelLabs/fuel-specs/specs/protocol/cryptographic_primitives.md#public-key-cryptography)
105
+ *
106
+ * @param data - The data to be sign
107
+ * @returns hashed signature
108
+ */
109
+ sign(data) {
110
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils.arrayify)(data), (0, import_utils.arrayify)(this.privateKey));
111
+ const r = (0, import_math.toBytes)(`0x${signature.r.toString(16)}`, 32);
112
+ const s = (0, import_math.toBytes)(`0x${signature.s.toString(16)}`, 32);
113
+ s[0] |= (signature.recovery || 0) << 7;
114
+ return (0, import_utils.hexlify)((0, import_utils.concat)([r, s]));
115
+ }
116
+ /**
117
+ * Add point on the current elliptic curve
118
+ *
119
+ * @param point - Point to add on the curve
120
+ * @returns compressed point on the curve
121
+ */
122
+ addPoint(point) {
123
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils.arrayify)(this.compressedPublicKey));
124
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils.arrayify)(point));
125
+ const result = p0.add(p1);
126
+ return `0x${result.toHex(true)}`;
127
+ }
128
+ /**
129
+ * Recover the public key from a signature performed with [`sign`](#sign).
130
+ *
131
+ * @param data - Data
132
+ * @param signature - hashed signature
133
+ * @returns public key from signature from the
134
+ */
135
+ static recoverPublicKey(data, signature) {
136
+ const signedMessageBytes = (0, import_utils.arrayify)(signature);
137
+ const r = signedMessageBytes.slice(0, 32);
138
+ const s = signedMessageBytes.slice(32, 64);
139
+ const recoveryParam = (s[0] & 128) >> 7;
140
+ s[0] &= 127;
141
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils.hexlify)(r)), BigInt((0, import_utils.hexlify)(s))).addRecoveryBit(
142
+ recoveryParam
143
+ );
144
+ const publicKey = sig.recoverPublicKey((0, import_utils.arrayify)(data)).toRawBytes(false).slice(1);
145
+ return (0, import_utils.hexlify)(publicKey);
146
+ }
147
+ /**
148
+ * Recover the address from a signature performed with [`sign`](#sign).
149
+ *
150
+ * @param data - Data
151
+ * @param signature - Signature
152
+ * @returns Address from signature
153
+ */
154
+ static recoverAddress(data, signature) {
155
+ return import_address.Address.fromPublicKey(Signer.recoverPublicKey(data, signature));
156
+ }
157
+ /**
158
+ * Generate a random privateKey
159
+ *
160
+ * @param entropy - Adds extra entropy to generate the privateKey
161
+ * @returns random 32-byte hashed
162
+ */
163
+ static generatePrivateKey(entropy) {
164
+ return entropy ? (0, import_hasher.hash)((0, import_utils.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
165
+ }
166
+ /**
167
+ * Extended publicKey from a compact publicKey
168
+ *
169
+ * @param publicKey - Compact publicKey
170
+ * @returns extended publicKey
171
+ */
172
+ static extendPublicKey(publicKey) {
173
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils.arrayify)(publicKey));
174
+ return (0, import_utils.hexlify)(point.toRawBytes(false).slice(1));
175
+ }
176
+ };
177
+
178
+ // src/test-utils/launchNode.ts
179
+ var getFlagValueFromArgs = (args, flag) => {
180
+ const flagIndex = args.indexOf(flag);
181
+ if (flagIndex === -1) {
182
+ return void 0;
183
+ }
184
+ return args[flagIndex + 1];
185
+ };
186
+ var extractRemainingArgs = (args, flagsToRemove) => {
187
+ const newArgs = [...args];
188
+ flagsToRemove.forEach((flag) => {
189
+ const flagIndex = newArgs.indexOf(flag);
190
+ if (flagIndex !== -1) {
191
+ newArgs.splice(flagIndex, 2);
192
+ }
193
+ });
194
+ return newArgs;
195
+ };
196
+ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
197
+ const defaultCoins = import_utils2.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
198
+ ...coin,
199
+ amount: "18446744073709551615"
200
+ }));
201
+ const defaultMessages = import_utils2.defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
202
+ ...message,
203
+ amount: "18446744073709551615"
204
+ }));
205
+ const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self) => self.findIndex((c) => c.tx_id === coin.tx_id) === index);
206
+ const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self) => self.findIndex((m) => m.nonce === msg.nonce) === index);
207
+ if (!process.env.GENESIS_SECRET) {
208
+ const pk = Signer.generatePrivateKey();
209
+ const signer = new Signer(pk);
210
+ process.env.GENESIS_SECRET = (0, import_utils2.hexlify)(pk);
211
+ coins.push({
212
+ tx_id: (0, import_utils2.hexlify)((0, import_crypto2.randomBytes)(import_abi_coder.BYTES_32)),
213
+ owner: signer.address.toHexString(),
214
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
215
+ amount: "18446744073709551615",
216
+ asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
217
+ output_index: 0,
218
+ tx_pointer_block_height: 0,
219
+ tx_pointer_tx_idx: 0
220
+ });
221
+ }
222
+ const json = JSON.stringify({
223
+ ...stateConfig,
224
+ coins,
225
+ messages
226
+ });
227
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
228
+ return json.replace(regexMakeNumber, "$1$2");
229
+ }
230
+ var launchNode = async ({
231
+ ip,
232
+ port,
233
+ args = [],
234
+ fuelCorePath = process.env.FUEL_CORE_PATH || void 0,
235
+ loggingEnabled = true,
236
+ basePath,
237
+ snapshotConfig = import_utils2.defaultSnapshotConfigs
238
+ } = {}) => (
239
+ // eslint-disable-next-line no-async-promise-executor
240
+ new Promise(async (resolve, reject) => {
241
+ const remainingArgs = extractRemainingArgs(args, [
242
+ "--snapshot",
243
+ "--consensus-key",
244
+ "--db-type",
245
+ "--poa-instant",
246
+ "--min-gas-price",
247
+ "--native-executor-version"
248
+ ]);
249
+ const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
250
+ const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils2.defaultConsensusKey;
251
+ const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
252
+ const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
253
+ const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
254
+ const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
255
+ const nativeExecutorVersion = getFlagValueFromArgs(args, "--native-executor-version") || "0";
256
+ const minGasPrice = getFlagValueFromArgs(args, "--min-gas-price") || "1";
257
+ const graphQLStartSubstring = "Binding GraphQL provider to";
258
+ const command = fuelCorePath || "fuel-core";
259
+ const ipToUse = ip || "0.0.0.0";
260
+ const portToUse = port || (await (0, import_portfinder.getPortPromise)({
261
+ port: 4e3,
262
+ // tries 4000 first, then 4001, then 4002, etc.
263
+ stopPort: 5e3
264
+ // don't try ports above 5000
265
+ })).toString();
266
+ let snapshotDirToUse;
267
+ const prefix = basePath || import_os.default.tmpdir();
268
+ const suffix = basePath ? "" : (0, import_crypto2.randomUUID)();
269
+ const tempDir = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
270
+ if (snapshotDir) {
271
+ snapshotDirToUse = snapshotDir;
272
+ } else {
273
+ if (!(0, import_fs.existsSync)(tempDir)) {
274
+ (0, import_fs.mkdirSync)(tempDir, { recursive: true });
275
+ }
276
+ const { metadata } = snapshotConfig;
277
+ const metadataPath = import_path.default.join(tempDir, "metadata.json");
278
+ const chainConfigPath = import_path.default.join(tempDir, metadata.chain_config);
279
+ const stateConfigPath = import_path.default.join(tempDir, metadata.table_encoding.Json.filepath);
280
+ const stateTransitionPath = import_path.default.join(tempDir, "state_transition_bytecode.wasm");
281
+ (0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
282
+ (0, import_fs.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
283
+ (0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
284
+ (0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
285
+ snapshotDirToUse = tempDir;
286
+ }
287
+ const { spawn } = await import("child_process");
288
+ const child = spawn(
289
+ command,
290
+ [
291
+ "run",
292
+ ["--ip", ipToUse],
293
+ ["--port", portToUse],
294
+ useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
295
+ ["--min-gas-price", minGasPrice],
296
+ poaInstant ? ["--poa-instant", "true"] : [],
297
+ ["--native-executor-version", nativeExecutorVersion],
298
+ ["--consensus-key", consensusKey],
299
+ ["--snapshot", snapshotDirToUse],
300
+ "--vm-backtrace",
301
+ "--utxo-validation",
302
+ "--debug",
303
+ ...remainingArgs
304
+ ].flat(),
305
+ { stdio: "pipe", detached: true }
306
+ );
307
+ if (loggingEnabled) {
308
+ child.stderr.on("data", (chunk) => {
309
+ console.log(chunk.toString());
310
+ });
311
+ }
312
+ const removeSideffects = () => {
313
+ child.stderr.removeAllListeners();
314
+ if ((0, import_fs.existsSync)(tempDir)) {
315
+ (0, import_fs.rmSync)(tempDir, { recursive: true });
316
+ }
317
+ };
318
+ child.on("error", removeSideffects);
319
+ child.on("exit", removeSideffects);
320
+ const childState = {
321
+ isDead: false
322
+ };
323
+ const cleanup = () => {
324
+ if (childState.isDead) {
325
+ return;
326
+ }
327
+ childState.isDead = true;
328
+ removeSideffects();
329
+ if (child.pid !== void 0) {
330
+ try {
331
+ process.kill(-child.pid);
332
+ } catch (e) {
333
+ const error = e;
334
+ if (error.code === "ESRCH") {
335
+ console.log(
336
+ `fuel-core node under pid ${child.pid} does not exist. The node might have been killed before cleanup was called. Exiting cleanly.`
337
+ );
338
+ } else {
339
+ throw e;
340
+ }
341
+ }
342
+ } else {
343
+ console.error("No PID available for the child process, unable to kill launched node");
344
+ }
345
+ };
346
+ child.stderr.on("data", (chunk) => {
347
+ const text = typeof chunk === "string" ? chunk : chunk.toString();
348
+ if (text.indexOf(graphQLStartSubstring) !== -1) {
349
+ const rows = text.split("\n");
350
+ const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
351
+ const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
352
+ resolve({
353
+ cleanup,
354
+ ip: realIp,
355
+ port: realPort,
356
+ url: `http://${realIp}:${realPort}/v1/graphql`,
357
+ snapshotDir: snapshotDirToUse,
358
+ pid: child.pid
359
+ });
360
+ }
361
+ if (/error/i.test(text)) {
362
+ console.log(text);
363
+ reject(new import_errors.FuelError(import_errors.FuelError.CODES.NODE_LAUNCH_FAILED, text));
364
+ }
365
+ });
366
+ process.on("exit", cleanup);
367
+ process.on("SIGINT", cleanup);
368
+ process.on("SIGUSR1", cleanup);
369
+ process.on("SIGUSR2", cleanup);
370
+ process.on("beforeExit", cleanup);
371
+ process.on("uncaughtException", cleanup);
372
+ child.on("error", reject);
373
+ })
374
+ );
375
+
376
+ // src/test-utils/setup-test-provider-and-wallets.ts
377
+ var import_utils41 = require("@fuel-ts/utils");
378
+ var import_ramda5 = require("ramda");
75
379
 
76
380
  // src/providers/coin-quantity.ts
77
- var import_math = require("@fuel-ts/math");
78
- var import_utils = require("@fuel-ts/utils");
381
+ var import_math2 = require("@fuel-ts/math");
382
+ var import_utils3 = require("@fuel-ts/utils");
79
383
  var coinQuantityfy = (coinQuantityLike) => {
80
384
  let assetId;
81
385
  let amount;
@@ -89,11 +393,11 @@ var coinQuantityfy = (coinQuantityLike) => {
89
393
  assetId = coinQuantityLike.assetId;
90
394
  max = coinQuantityLike.max ?? void 0;
91
395
  }
92
- const bnAmount = (0, import_math.bn)(amount);
396
+ const bnAmount = (0, import_math2.bn)(amount);
93
397
  return {
94
- assetId: (0, import_utils.hexlify)(assetId),
95
- amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
96
- max: max ? (0, import_math.bn)(max) : void 0
398
+ assetId: (0, import_utils3.hexlify)(assetId),
399
+ amount: bnAmount.lt(1) ? (0, import_math2.bn)(1) : bnAmount,
400
+ max: max ? (0, import_math2.bn)(max) : void 0
97
401
  };
98
402
  };
99
403
  var addAmountToCoinQuantities = (params) => {
@@ -109,13 +413,13 @@ var addAmountToCoinQuantities = (params) => {
109
413
  };
110
414
 
111
415
  // src/providers/provider.ts
112
- var import_address3 = require("@fuel-ts/address");
113
- var import_errors14 = require("@fuel-ts/errors");
114
- var import_math17 = require("@fuel-ts/math");
416
+ var import_address4 = require("@fuel-ts/address");
417
+ var import_errors16 = require("@fuel-ts/errors");
418
+ var import_math18 = require("@fuel-ts/math");
115
419
  var import_transactions20 = require("@fuel-ts/transactions");
116
- var import_utils23 = require("@fuel-ts/utils");
420
+ var import_utils26 = require("@fuel-ts/utils");
117
421
  var import_versions = require("@fuel-ts/versions");
118
- var import_utils24 = require("@noble/curves/abstract/utils");
422
+ var import_utils27 = require("@noble/curves/abstract/utils");
119
423
  var import_graphql_request = require("graphql-request");
120
424
  var import_ramda3 = require("ramda");
121
425
 
@@ -546,6 +850,12 @@ var GasCostsFragmentDoc = import_graphql_tag.default`
546
850
  alocDependentCost {
547
851
  ...DependentCostFragment
548
852
  }
853
+ bldd {
854
+ ...DependentCostFragment
855
+ }
856
+ bsiz {
857
+ ...DependentCostFragment
858
+ }
549
859
  cfe {
550
860
  ...DependentCostFragment
551
861
  }
@@ -564,6 +874,9 @@ var GasCostsFragmentDoc = import_graphql_tag.default`
564
874
  csiz {
565
875
  ...DependentCostFragment
566
876
  }
877
+ ed19DependentCost {
878
+ ...DependentCostFragment
879
+ }
567
880
  k256 {
568
881
  ...DependentCostFragment
569
882
  }
@@ -1092,7 +1405,7 @@ function getSdk(requester) {
1092
1405
  }
1093
1406
 
1094
1407
  // src/providers/fuel-graphql-subscriber.ts
1095
- var import_errors = require("@fuel-ts/errors");
1408
+ var import_errors2 = require("@fuel-ts/errors");
1096
1409
  var import_graphql = require("graphql");
1097
1410
  var _FuelGraphqlSubscriber = class {
1098
1411
  constructor(options) {
@@ -1124,8 +1437,8 @@ var _FuelGraphqlSubscriber = class {
1124
1437
  if (this.events.length > 0) {
1125
1438
  const { data, errors } = this.events.shift();
1126
1439
  if (Array.isArray(errors)) {
1127
- throw new import_errors.FuelError(
1128
- import_errors.FuelError.CODES.INVALID_REQUEST,
1440
+ throw new import_errors2.FuelError(
1441
+ import_errors2.FuelError.CODES.INVALID_REQUEST,
1129
1442
  errors.map((err) => err.message).join("\n\n")
1130
1443
  );
1131
1444
  }
@@ -1146,8 +1459,8 @@ var _FuelGraphqlSubscriber = class {
1146
1459
  try {
1147
1460
  this.events.push(JSON.parse(match.replace(/^data:/, "")));
1148
1461
  } catch (e) {
1149
- throw new import_errors.FuelError(
1150
- import_errors.ErrorCode.STREAM_PARSING_ERROR,
1462
+ throw new import_errors2.FuelError(
1463
+ import_errors2.ErrorCode.STREAM_PARSING_ERROR,
1151
1464
  `Error while parsing stream data response: ${text}`
1152
1465
  );
1153
1466
  }
@@ -1170,95 +1483,98 @@ var _FuelGraphqlSubscriber = class {
1170
1483
  var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
1171
1484
  __publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
1172
1485
 
1173
- // src/providers/memory-cache.ts
1174
- var import_errors2 = require("@fuel-ts/errors");
1175
- var import_utils2 = require("@fuel-ts/utils");
1176
- var cache = {};
1177
- var DEFAULT_TTL_IN_MS = 30 * 1e3;
1178
- var MemoryCache = class {
1486
+ // src/providers/resource-cache.ts
1487
+ var import_errors3 = require("@fuel-ts/errors");
1488
+ var import_utils4 = require("@fuel-ts/utils");
1489
+ var cache = /* @__PURE__ */ new Map();
1490
+ var ResourceCache = class {
1179
1491
  ttl;
1180
- constructor(ttlInMs = DEFAULT_TTL_IN_MS) {
1181
- this.ttl = ttlInMs;
1182
- if (typeof ttlInMs !== "number" || this.ttl <= 0) {
1183
- throw new import_errors2.FuelError(
1184
- import_errors2.ErrorCode.INVALID_TTL,
1492
+ constructor(ttl) {
1493
+ this.ttl = ttl;
1494
+ if (typeof ttl !== "number" || this.ttl <= 0) {
1495
+ throw new import_errors3.FuelError(
1496
+ import_errors3.ErrorCode.INVALID_TTL,
1185
1497
  `Invalid TTL: ${this.ttl}. Use a value greater than zero.`
1186
1498
  );
1187
1499
  }
1188
1500
  }
1189
- get(value, isAutoExpiring = true) {
1190
- const key = (0, import_utils2.hexlify)(value);
1191
- if (cache[key]) {
1192
- if (!isAutoExpiring || cache[key].expires > Date.now()) {
1193
- return cache[key].value;
1194
- }
1195
- this.del(value);
1196
- }
1197
- return void 0;
1198
- }
1199
- set(value) {
1200
- const expiresAt = Date.now() + this.ttl;
1201
- const key = (0, import_utils2.hexlify)(value);
1202
- cache[key] = {
1203
- expires: expiresAt,
1204
- value
1501
+ // Add resources to the cache
1502
+ set(transactionId, resources) {
1503
+ const currentTime = Date.now();
1504
+ const existingResources = cache.get(transactionId) || {
1505
+ utxos: /* @__PURE__ */ new Set(),
1506
+ messages: /* @__PURE__ */ new Set(),
1507
+ timestamp: currentTime
1205
1508
  };
1206
- return expiresAt;
1509
+ resources.utxos.forEach((utxo) => existingResources.utxos.add((0, import_utils4.hexlify)(utxo)));
1510
+ resources.messages.forEach((message) => existingResources.messages.add((0, import_utils4.hexlify)(message)));
1511
+ cache.set(transactionId, existingResources);
1207
1512
  }
1208
- getAllData() {
1209
- return Object.keys(cache).reduce((list, key) => {
1210
- const data = this.get(key, false);
1211
- if (data) {
1212
- list.push(data);
1213
- }
1214
- return list;
1215
- }, []);
1513
+ // Remove resources from the cache for a given transaction ID
1514
+ unset(transactionId) {
1515
+ cache.delete(transactionId);
1216
1516
  }
1517
+ // Get all cached resources and remove expired ones
1217
1518
  getActiveData() {
1218
- return Object.keys(cache).reduce((list, key) => {
1219
- const data = this.get(key);
1220
- if (data) {
1221
- list.push(data);
1519
+ const allResources = { utxos: [], messages: [] };
1520
+ const currentTime = Date.now();
1521
+ cache.forEach((resource, transactionId) => {
1522
+ if (currentTime - resource.timestamp < this.ttl) {
1523
+ allResources.utxos.push(...resource.utxos);
1524
+ allResources.messages.push(...resource.messages);
1525
+ } else {
1526
+ cache.delete(transactionId);
1527
+ }
1528
+ });
1529
+ return allResources;
1530
+ }
1531
+ // Check if a UTXO ID or message nonce is already cached and not expired
1532
+ isCached(key) {
1533
+ const currentTime = Date.now();
1534
+ for (const [transactionId, resourceData] of cache.entries()) {
1535
+ if (currentTime - resourceData.timestamp > this.ttl) {
1536
+ cache.delete(transactionId);
1537
+ } else if (resourceData.utxos.has(key) || resourceData.messages.has(key)) {
1538
+ return true;
1222
1539
  }
1223
- return list;
1224
- }, []);
1540
+ }
1541
+ return false;
1225
1542
  }
1226
- del(value) {
1227
- const key = (0, import_utils2.hexlify)(value);
1228
- delete cache[key];
1543
+ clear() {
1544
+ cache.clear();
1229
1545
  }
1230
1546
  };
1231
1547
 
1232
1548
  // src/providers/transaction-request/input.ts
1233
- var import_abi_coder = require("@fuel-ts/abi-coder");
1549
+ var import_abi_coder2 = require("@fuel-ts/abi-coder");
1234
1550
  var import_configs = require("@fuel-ts/address/configs");
1235
- var import_errors3 = require("@fuel-ts/errors");
1236
- var import_math2 = require("@fuel-ts/math");
1551
+ var import_errors4 = require("@fuel-ts/errors");
1552
+ var import_math3 = require("@fuel-ts/math");
1237
1553
  var import_transactions = require("@fuel-ts/transactions");
1238
- var import_utils3 = require("@fuel-ts/utils");
1554
+ var import_utils5 = require("@fuel-ts/utils");
1239
1555
  var inputify = (value) => {
1240
1556
  const { type } = value;
1241
1557
  switch (value.type) {
1242
1558
  case import_transactions.InputType.Coin: {
1243
- const predicate = (0, import_utils3.arrayify)(value.predicate ?? "0x");
1244
- const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
1559
+ const predicate = (0, import_utils5.arrayify)(value.predicate ?? "0x");
1560
+ const predicateData = (0, import_utils5.arrayify)(value.predicateData ?? "0x");
1245
1561
  return {
1246
1562
  type: import_transactions.InputType.Coin,
1247
- txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, import_abi_coder.BYTES_32)),
1248
- outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(import_abi_coder.BYTES_32, import_abi_coder.UTXO_ID_LEN)),
1249
- owner: (0, import_utils3.hexlify)(value.owner),
1250
- amount: (0, import_math2.bn)(value.amount),
1251
- assetId: (0, import_utils3.hexlify)(value.assetId),
1563
+ txID: (0, import_utils5.hexlify)((0, import_utils5.arrayify)(value.id).slice(0, import_abi_coder2.BYTES_32)),
1564
+ outputIndex: (0, import_math3.toNumber)((0, import_utils5.arrayify)(value.id).slice(import_abi_coder2.BYTES_32, import_abi_coder2.UTXO_ID_LEN)),
1565
+ owner: (0, import_utils5.hexlify)(value.owner),
1566
+ amount: (0, import_math3.bn)(value.amount),
1567
+ assetId: (0, import_utils5.hexlify)(value.assetId),
1252
1568
  txPointer: {
1253
- blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
1254
- txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1569
+ blockHeight: (0, import_math3.toNumber)((0, import_utils5.arrayify)(value.txPointer).slice(0, 8)),
1570
+ txIndex: (0, import_math3.toNumber)((0, import_utils5.arrayify)(value.txPointer).slice(8, 16))
1255
1571
  },
1256
1572
  witnessIndex: value.witnessIndex,
1257
- predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1258
- predicateLength: (0, import_math2.bn)(predicate.length),
1259
- predicateDataLength: (0, import_math2.bn)(predicateData.length),
1260
- predicate: (0, import_utils3.hexlify)(predicate),
1261
- predicateData: (0, import_utils3.hexlify)(predicateData)
1573
+ predicateGasUsed: (0, import_math3.bn)(value.predicateGasUsed),
1574
+ predicateLength: (0, import_math3.bn)(predicate.length),
1575
+ predicateDataLength: (0, import_math3.bn)(predicateData.length),
1576
+ predicate: (0, import_utils5.hexlify)(predicate),
1577
+ predicateData: (0, import_utils5.hexlify)(predicateData)
1262
1578
  };
1263
1579
  }
1264
1580
  case import_transactions.InputType.Contract: {
@@ -1269,35 +1585,35 @@ var inputify = (value) => {
1269
1585
  balanceRoot: import_configs.ZeroBytes32,
1270
1586
  stateRoot: import_configs.ZeroBytes32,
1271
1587
  txPointer: {
1272
- blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
1273
- txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
1588
+ blockHeight: (0, import_math3.toNumber)((0, import_utils5.arrayify)(value.txPointer).slice(0, 8)),
1589
+ txIndex: (0, import_math3.toNumber)((0, import_utils5.arrayify)(value.txPointer).slice(8, 16))
1274
1590
  },
1275
- contractID: (0, import_utils3.hexlify)(value.contractId)
1591
+ contractID: (0, import_utils5.hexlify)(value.contractId)
1276
1592
  };
1277
1593
  }
1278
1594
  case import_transactions.InputType.Message: {
1279
- const predicate = (0, import_utils3.arrayify)(value.predicate ?? "0x");
1280
- const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
1281
- const data = (0, import_utils3.arrayify)(value.data ?? "0x");
1595
+ const predicate = (0, import_utils5.arrayify)(value.predicate ?? "0x");
1596
+ const predicateData = (0, import_utils5.arrayify)(value.predicateData ?? "0x");
1597
+ const data = (0, import_utils5.arrayify)(value.data ?? "0x");
1282
1598
  return {
1283
1599
  type: import_transactions.InputType.Message,
1284
- sender: (0, import_utils3.hexlify)(value.sender),
1285
- recipient: (0, import_utils3.hexlify)(value.recipient),
1286
- amount: (0, import_math2.bn)(value.amount),
1287
- nonce: (0, import_utils3.hexlify)(value.nonce),
1600
+ sender: (0, import_utils5.hexlify)(value.sender),
1601
+ recipient: (0, import_utils5.hexlify)(value.recipient),
1602
+ amount: (0, import_math3.bn)(value.amount),
1603
+ nonce: (0, import_utils5.hexlify)(value.nonce),
1288
1604
  witnessIndex: value.witnessIndex,
1289
- predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
1290
- predicateLength: (0, import_math2.bn)(predicate.length),
1291
- predicateDataLength: (0, import_math2.bn)(predicateData.length),
1292
- predicate: (0, import_utils3.hexlify)(predicate),
1293
- predicateData: (0, import_utils3.hexlify)(predicateData),
1294
- data: (0, import_utils3.hexlify)(data),
1605
+ predicateGasUsed: (0, import_math3.bn)(value.predicateGasUsed),
1606
+ predicateLength: (0, import_math3.bn)(predicate.length),
1607
+ predicateDataLength: (0, import_math3.bn)(predicateData.length),
1608
+ predicate: (0, import_utils5.hexlify)(predicate),
1609
+ predicateData: (0, import_utils5.hexlify)(predicateData),
1610
+ data: (0, import_utils5.hexlify)(data),
1295
1611
  dataLength: data.length
1296
1612
  };
1297
1613
  }
1298
1614
  default: {
1299
- throw new import_errors3.FuelError(
1300
- import_errors3.ErrorCode.INVALID_TRANSACTION_INPUT,
1615
+ throw new import_errors4.FuelError(
1616
+ import_errors4.ErrorCode.INVALID_TRANSACTION_INPUT,
1301
1617
  `Invalid transaction input type: ${type}.`
1302
1618
  );
1303
1619
  }
@@ -1306,19 +1622,19 @@ var inputify = (value) => {
1306
1622
 
1307
1623
  // src/providers/transaction-request/output.ts
1308
1624
  var import_configs2 = require("@fuel-ts/address/configs");
1309
- var import_errors4 = require("@fuel-ts/errors");
1310
- var import_math3 = require("@fuel-ts/math");
1625
+ var import_errors5 = require("@fuel-ts/errors");
1626
+ var import_math4 = require("@fuel-ts/math");
1311
1627
  var import_transactions2 = require("@fuel-ts/transactions");
1312
- var import_utils4 = require("@fuel-ts/utils");
1628
+ var import_utils6 = require("@fuel-ts/utils");
1313
1629
  var outputify = (value) => {
1314
1630
  const { type } = value;
1315
1631
  switch (type) {
1316
1632
  case import_transactions2.OutputType.Coin: {
1317
1633
  return {
1318
1634
  type: import_transactions2.OutputType.Coin,
1319
- to: (0, import_utils4.hexlify)(value.to),
1320
- amount: (0, import_math3.bn)(value.amount),
1321
- assetId: (0, import_utils4.hexlify)(value.assetId)
1635
+ to: (0, import_utils6.hexlify)(value.to),
1636
+ amount: (0, import_math4.bn)(value.amount),
1637
+ assetId: (0, import_utils6.hexlify)(value.assetId)
1322
1638
  };
1323
1639
  }
1324
1640
  case import_transactions2.OutputType.Contract: {
@@ -1332,29 +1648,29 @@ var outputify = (value) => {
1332
1648
  case import_transactions2.OutputType.Change: {
1333
1649
  return {
1334
1650
  type: import_transactions2.OutputType.Change,
1335
- to: (0, import_utils4.hexlify)(value.to),
1336
- amount: (0, import_math3.bn)(0),
1337
- assetId: (0, import_utils4.hexlify)(value.assetId)
1651
+ to: (0, import_utils6.hexlify)(value.to),
1652
+ amount: (0, import_math4.bn)(0),
1653
+ assetId: (0, import_utils6.hexlify)(value.assetId)
1338
1654
  };
1339
1655
  }
1340
1656
  case import_transactions2.OutputType.Variable: {
1341
1657
  return {
1342
1658
  type: import_transactions2.OutputType.Variable,
1343
1659
  to: import_configs2.ZeroBytes32,
1344
- amount: (0, import_math3.bn)(0),
1660
+ amount: (0, import_math4.bn)(0),
1345
1661
  assetId: import_configs2.ZeroBytes32
1346
1662
  };
1347
1663
  }
1348
1664
  case import_transactions2.OutputType.ContractCreated: {
1349
1665
  return {
1350
1666
  type: import_transactions2.OutputType.ContractCreated,
1351
- contractId: (0, import_utils4.hexlify)(value.contractId),
1352
- stateRoot: (0, import_utils4.hexlify)(value.stateRoot)
1667
+ contractId: (0, import_utils6.hexlify)(value.contractId),
1668
+ stateRoot: (0, import_utils6.hexlify)(value.stateRoot)
1353
1669
  };
1354
1670
  }
1355
1671
  default: {
1356
- throw new import_errors4.FuelError(
1357
- import_errors4.ErrorCode.INVALID_TRANSACTION_INPUT,
1672
+ throw new import_errors5.FuelError(
1673
+ import_errors5.ErrorCode.INVALID_TRANSACTION_INPUT,
1358
1674
  `Invalid transaction output type: ${type}.`
1359
1675
  );
1360
1676
  }
@@ -1362,24 +1678,25 @@ var outputify = (value) => {
1362
1678
  };
1363
1679
 
1364
1680
  // src/providers/transaction-request/transaction-request.ts
1365
- var import_abi_coder2 = require("@fuel-ts/abi-coder");
1366
- var import_address = require("@fuel-ts/address");
1681
+ var import_abi_coder3 = require("@fuel-ts/abi-coder");
1682
+ var import_address2 = require("@fuel-ts/address");
1367
1683
  var import_configs6 = require("@fuel-ts/address/configs");
1368
- var import_crypto = require("@fuel-ts/crypto");
1369
- var import_math8 = require("@fuel-ts/math");
1684
+ var import_crypto3 = require("@fuel-ts/crypto");
1685
+ var import_errors9 = require("@fuel-ts/errors");
1686
+ var import_math9 = require("@fuel-ts/math");
1370
1687
  var import_transactions7 = require("@fuel-ts/transactions");
1371
- var import_utils9 = require("@fuel-ts/utils");
1688
+ var import_utils11 = require("@fuel-ts/utils");
1372
1689
 
1373
1690
  // src/providers/resource.ts
1374
1691
  var isCoin = (resource) => "id" in resource;
1375
1692
 
1376
1693
  // src/providers/utils/receipts.ts
1377
1694
  var import_configs3 = require("@fuel-ts/address/configs");
1378
- var import_errors5 = require("@fuel-ts/errors");
1379
- var import_math4 = require("@fuel-ts/math");
1695
+ var import_errors6 = require("@fuel-ts/errors");
1696
+ var import_math5 = require("@fuel-ts/math");
1380
1697
  var import_transactions3 = require("@fuel-ts/transactions");
1381
1698
  var import_configs4 = require("@fuel-ts/transactions/configs");
1382
- var import_utils5 = require("@fuel-ts/utils");
1699
+ var import_utils7 = require("@fuel-ts/utils");
1383
1700
  var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
1384
1701
  var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
1385
1702
  var getReceiptsWithMissingData = (receipts) => receipts.reduce(
@@ -1406,13 +1723,13 @@ function assembleReceiptByType(receipt) {
1406
1723
  type: import_transactions3.ReceiptType.Call,
1407
1724
  from: hexOrZero(receipt.id || receipt.contractId),
1408
1725
  to: hexOrZero(receipt?.to),
1409
- amount: (0, import_math4.bn)(receipt.amount),
1726
+ amount: (0, import_math5.bn)(receipt.amount),
1410
1727
  assetId: hexOrZero(receipt.assetId),
1411
- gas: (0, import_math4.bn)(receipt.gas),
1412
- param1: (0, import_math4.bn)(receipt.param1),
1413
- param2: (0, import_math4.bn)(receipt.param2),
1414
- pc: (0, import_math4.bn)(receipt.pc),
1415
- is: (0, import_math4.bn)(receipt.is)
1728
+ gas: (0, import_math5.bn)(receipt.gas),
1729
+ param1: (0, import_math5.bn)(receipt.param1),
1730
+ param2: (0, import_math5.bn)(receipt.param2),
1731
+ pc: (0, import_math5.bn)(receipt.pc),
1732
+ is: (0, import_math5.bn)(receipt.is)
1416
1733
  };
1417
1734
  return callReceipt;
1418
1735
  }
@@ -1420,9 +1737,9 @@ function assembleReceiptByType(receipt) {
1420
1737
  const returnReceipt = {
1421
1738
  type: import_transactions3.ReceiptType.Return,
1422
1739
  id: hexOrZero(receipt.id || receipt.contractId),
1423
- val: (0, import_math4.bn)(receipt.val),
1424
- pc: (0, import_math4.bn)(receipt.pc),
1425
- is: (0, import_math4.bn)(receipt.is)
1740
+ val: (0, import_math5.bn)(receipt.val),
1741
+ pc: (0, import_math5.bn)(receipt.pc),
1742
+ is: (0, import_math5.bn)(receipt.is)
1426
1743
  };
1427
1744
  return returnReceipt;
1428
1745
  }
@@ -1430,11 +1747,11 @@ function assembleReceiptByType(receipt) {
1430
1747
  const returnDataReceipt = {
1431
1748
  type: import_transactions3.ReceiptType.ReturnData,
1432
1749
  id: hexOrZero(receipt.id || receipt.contractId),
1433
- ptr: (0, import_math4.bn)(receipt.ptr),
1434
- len: (0, import_math4.bn)(receipt.len),
1750
+ ptr: (0, import_math5.bn)(receipt.ptr),
1751
+ len: (0, import_math5.bn)(receipt.len),
1435
1752
  digest: hexOrZero(receipt.digest),
1436
- pc: (0, import_math4.bn)(receipt.pc),
1437
- is: (0, import_math4.bn)(receipt.is)
1753
+ pc: (0, import_math5.bn)(receipt.pc),
1754
+ is: (0, import_math5.bn)(receipt.is)
1438
1755
  };
1439
1756
  return returnDataReceipt;
1440
1757
  }
@@ -1442,9 +1759,9 @@ function assembleReceiptByType(receipt) {
1442
1759
  const panicReceipt = {
1443
1760
  type: import_transactions3.ReceiptType.Panic,
1444
1761
  id: hexOrZero(receipt.id),
1445
- reason: (0, import_math4.bn)(receipt.reason),
1446
- pc: (0, import_math4.bn)(receipt.pc),
1447
- is: (0, import_math4.bn)(receipt.is),
1762
+ reason: (0, import_math5.bn)(receipt.reason),
1763
+ pc: (0, import_math5.bn)(receipt.pc),
1764
+ is: (0, import_math5.bn)(receipt.is),
1448
1765
  contractId: hexOrZero(receipt.contractId)
1449
1766
  };
1450
1767
  return panicReceipt;
@@ -1453,9 +1770,9 @@ function assembleReceiptByType(receipt) {
1453
1770
  const revertReceipt = {
1454
1771
  type: import_transactions3.ReceiptType.Revert,
1455
1772
  id: hexOrZero(receipt.id || receipt.contractId),
1456
- val: (0, import_math4.bn)(receipt.ra),
1457
- pc: (0, import_math4.bn)(receipt.pc),
1458
- is: (0, import_math4.bn)(receipt.is)
1773
+ val: (0, import_math5.bn)(receipt.ra),
1774
+ pc: (0, import_math5.bn)(receipt.pc),
1775
+ is: (0, import_math5.bn)(receipt.is)
1459
1776
  };
1460
1777
  return revertReceipt;
1461
1778
  }
@@ -1463,12 +1780,12 @@ function assembleReceiptByType(receipt) {
1463
1780
  const logReceipt = {
1464
1781
  type: import_transactions3.ReceiptType.Log,
1465
1782
  id: hexOrZero(receipt.id || receipt.contractId),
1466
- val0: (0, import_math4.bn)(receipt.ra),
1467
- val1: (0, import_math4.bn)(receipt.rb),
1468
- val2: (0, import_math4.bn)(receipt.rc),
1469
- val3: (0, import_math4.bn)(receipt.rd),
1470
- pc: (0, import_math4.bn)(receipt.pc),
1471
- is: (0, import_math4.bn)(receipt.is)
1783
+ val0: (0, import_math5.bn)(receipt.ra),
1784
+ val1: (0, import_math5.bn)(receipt.rb),
1785
+ val2: (0, import_math5.bn)(receipt.rc),
1786
+ val3: (0, import_math5.bn)(receipt.rd),
1787
+ pc: (0, import_math5.bn)(receipt.pc),
1788
+ is: (0, import_math5.bn)(receipt.is)
1472
1789
  };
1473
1790
  return logReceipt;
1474
1791
  }
@@ -1476,13 +1793,13 @@ function assembleReceiptByType(receipt) {
1476
1793
  const logDataReceipt = {
1477
1794
  type: import_transactions3.ReceiptType.LogData,
1478
1795
  id: hexOrZero(receipt.id || receipt.contractId),
1479
- val0: (0, import_math4.bn)(receipt.ra),
1480
- val1: (0, import_math4.bn)(receipt.rb),
1481
- ptr: (0, import_math4.bn)(receipt.ptr),
1482
- len: (0, import_math4.bn)(receipt.len),
1796
+ val0: (0, import_math5.bn)(receipt.ra),
1797
+ val1: (0, import_math5.bn)(receipt.rb),
1798
+ ptr: (0, import_math5.bn)(receipt.ptr),
1799
+ len: (0, import_math5.bn)(receipt.len),
1483
1800
  digest: hexOrZero(receipt.digest),
1484
- pc: (0, import_math4.bn)(receipt.pc),
1485
- is: (0, import_math4.bn)(receipt.is)
1801
+ pc: (0, import_math5.bn)(receipt.pc),
1802
+ is: (0, import_math5.bn)(receipt.is)
1486
1803
  };
1487
1804
  return logDataReceipt;
1488
1805
  }
@@ -1491,10 +1808,10 @@ function assembleReceiptByType(receipt) {
1491
1808
  type: import_transactions3.ReceiptType.Transfer,
1492
1809
  from: hexOrZero(receipt.id || receipt.contractId),
1493
1810
  to: hexOrZero(receipt.toAddress || receipt?.to),
1494
- amount: (0, import_math4.bn)(receipt.amount),
1811
+ amount: (0, import_math5.bn)(receipt.amount),
1495
1812
  assetId: hexOrZero(receipt.assetId),
1496
- pc: (0, import_math4.bn)(receipt.pc),
1497
- is: (0, import_math4.bn)(receipt.is)
1813
+ pc: (0, import_math5.bn)(receipt.pc),
1814
+ is: (0, import_math5.bn)(receipt.is)
1498
1815
  };
1499
1816
  return transferReceipt;
1500
1817
  }
@@ -1503,18 +1820,18 @@ function assembleReceiptByType(receipt) {
1503
1820
  type: import_transactions3.ReceiptType.TransferOut,
1504
1821
  from: hexOrZero(receipt.id || receipt.contractId),
1505
1822
  to: hexOrZero(receipt.toAddress || receipt.to),
1506
- amount: (0, import_math4.bn)(receipt.amount),
1823
+ amount: (0, import_math5.bn)(receipt.amount),
1507
1824
  assetId: hexOrZero(receipt.assetId),
1508
- pc: (0, import_math4.bn)(receipt.pc),
1509
- is: (0, import_math4.bn)(receipt.is)
1825
+ pc: (0, import_math5.bn)(receipt.pc),
1826
+ is: (0, import_math5.bn)(receipt.is)
1510
1827
  };
1511
1828
  return transferOutReceipt;
1512
1829
  }
1513
1830
  case "SCRIPT_RESULT" /* ScriptResult */: {
1514
1831
  const scriptResultReceipt = {
1515
1832
  type: import_transactions3.ReceiptType.ScriptResult,
1516
- result: (0, import_math4.bn)(receipt.result),
1517
- gasUsed: (0, import_math4.bn)(receipt.gasUsed)
1833
+ result: (0, import_math5.bn)(receipt.result),
1834
+ gasUsed: (0, import_math5.bn)(receipt.gasUsed)
1518
1835
  };
1519
1836
  return scriptResultReceipt;
1520
1837
  }
@@ -1522,8 +1839,8 @@ function assembleReceiptByType(receipt) {
1522
1839
  const sender = hexOrZero(receipt.sender);
1523
1840
  const recipient = hexOrZero(receipt.recipient);
1524
1841
  const nonce = hexOrZero(receipt.nonce);
1525
- const amount = (0, import_math4.bn)(receipt.amount);
1526
- const data = receipt.data ? (0, import_utils5.arrayify)(receipt.data) : Uint8Array.from([]);
1842
+ const amount = (0, import_math5.bn)(receipt.amount);
1843
+ const data = receipt.data ? (0, import_utils7.arrayify)(receipt.data) : Uint8Array.from([]);
1527
1844
  const digest = hexOrZero(receipt.digest);
1528
1845
  const messageId = import_transactions3.ReceiptMessageOutCoder.getMessageId({
1529
1846
  sender,
@@ -1553,9 +1870,9 @@ function assembleReceiptByType(receipt) {
1553
1870
  subId,
1554
1871
  contractId,
1555
1872
  assetId,
1556
- val: (0, import_math4.bn)(receipt.val),
1557
- pc: (0, import_math4.bn)(receipt.pc),
1558
- is: (0, import_math4.bn)(receipt.is)
1873
+ val: (0, import_math5.bn)(receipt.val),
1874
+ pc: (0, import_math5.bn)(receipt.pc),
1875
+ is: (0, import_math5.bn)(receipt.is)
1559
1876
  };
1560
1877
  return mintReceipt;
1561
1878
  }
@@ -1568,38 +1885,38 @@ function assembleReceiptByType(receipt) {
1568
1885
  subId,
1569
1886
  contractId,
1570
1887
  assetId,
1571
- val: (0, import_math4.bn)(receipt.val),
1572
- pc: (0, import_math4.bn)(receipt.pc),
1573
- is: (0, import_math4.bn)(receipt.is)
1888
+ val: (0, import_math5.bn)(receipt.val),
1889
+ pc: (0, import_math5.bn)(receipt.pc),
1890
+ is: (0, import_math5.bn)(receipt.is)
1574
1891
  };
1575
1892
  return burnReceipt;
1576
1893
  }
1577
1894
  default:
1578
- throw new import_errors5.FuelError(import_errors5.ErrorCode.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
1895
+ throw new import_errors6.FuelError(import_errors6.ErrorCode.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
1579
1896
  }
1580
1897
  }
1581
1898
 
1582
1899
  // src/providers/utils/block-explorer.ts
1583
- var import_errors6 = require("@fuel-ts/errors");
1900
+ var import_errors7 = require("@fuel-ts/errors");
1584
1901
 
1585
1902
  // src/providers/utils/gas.ts
1586
- var import_math5 = require("@fuel-ts/math");
1903
+ var import_math6 = require("@fuel-ts/math");
1587
1904
  var import_transactions4 = require("@fuel-ts/transactions");
1588
- var import_utils6 = require("@fuel-ts/utils");
1905
+ var import_utils8 = require("@fuel-ts/utils");
1589
1906
  var getGasUsedFromReceipts = (receipts) => {
1590
1907
  const scriptResult = receipts.filter(
1591
1908
  (receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
1592
1909
  );
1593
- const gasUsed = scriptResult.reduce((prev, receipt) => prev.add(receipt.gasUsed), (0, import_math5.bn)(0));
1910
+ const gasUsed = scriptResult.reduce((prev, receipt) => prev.add(receipt.gasUsed), (0, import_math6.bn)(0));
1594
1911
  return gasUsed;
1595
1912
  };
1596
1913
  function resolveGasDependentCosts(byteSize, gasDependentCost) {
1597
- const base = (0, import_math5.bn)(gasDependentCost.base);
1598
- let dependentValue = (0, import_math5.bn)(0);
1914
+ const base = (0, import_math6.bn)(gasDependentCost.base);
1915
+ let dependentValue = (0, import_math6.bn)(0);
1599
1916
  if ("unitsPerGas" in gasDependentCost) {
1600
- dependentValue = (0, import_math5.bn)(byteSize).div((0, import_math5.bn)(gasDependentCost.unitsPerGas));
1917
+ dependentValue = (0, import_math6.bn)(byteSize).div((0, import_math6.bn)(gasDependentCost.unitsPerGas));
1601
1918
  } else {
1602
- dependentValue = (0, import_math5.bn)(byteSize).mul((0, import_math5.bn)(gasDependentCost.gasPerUnit));
1919
+ dependentValue = (0, import_math6.bn)(byteSize).mul((0, import_math6.bn)(gasDependentCost.gasPerUnit));
1603
1920
  }
1604
1921
  return base.add(dependentValue);
1605
1922
  }
@@ -1622,17 +1939,17 @@ function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
1622
1939
  const totalGas = chargeableInputs.reduce((total, input) => {
1623
1940
  if ("predicate" in input && input.predicate && input.predicate !== "0x") {
1624
1941
  return total.add(
1625
- vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
1942
+ vmInitializationCost.add(resolveGasDependentCosts((0, import_utils8.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math6.bn)(input.predicateGasUsed))
1626
1943
  );
1627
1944
  }
1628
1945
  return total.add(gasCosts.ecr1);
1629
- }, (0, import_math5.bn)(0));
1946
+ }, (0, import_math6.bn)(0));
1630
1947
  return totalGas;
1631
1948
  }
1632
1949
  function getMinGas(params) {
1633
1950
  const { gasCosts, gasPerByte, inputs, metadataGas, txBytesSize } = params;
1634
1951
  const vmInitGas = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
1635
- const bytesGas = (0, import_math5.bn)(txBytesSize).mul(gasPerByte);
1952
+ const bytesGas = (0, import_math6.bn)(txBytesSize).mul(gasPerByte);
1636
1953
  const inputsGas = gasUsedByInputs(inputs, txBytesSize, gasCosts);
1637
1954
  const minGas = vmInitGas.add(bytesGas).add(inputsGas).add(metadataGas).maxU64();
1638
1955
  return minGas;
@@ -1643,12 +1960,12 @@ function getMaxGas(params) {
1643
1960
  witnessesLength,
1644
1961
  witnessLimit,
1645
1962
  minGas,
1646
- gasLimit = (0, import_math5.bn)(0),
1963
+ gasLimit = (0, import_math6.bn)(0),
1647
1964
  maxGasPerTx
1648
1965
  } = params;
1649
- let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
1966
+ let remainingAllowedWitnessGas = (0, import_math6.bn)(0);
1650
1967
  if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
1651
- remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1968
+ remainingAllowedWitnessGas = (0, import_math6.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
1652
1969
  }
1653
1970
  const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
1654
1971
  return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
@@ -1662,7 +1979,7 @@ function calculateMetadataGasForTxCreate({
1662
1979
  const contractRootGas = resolveGasDependentCosts(contractBytesSize, gasCosts.contractRoot);
1663
1980
  const stateRootGas = resolveGasDependentCosts(stateRootSize, gasCosts.stateRoot);
1664
1981
  const txIdGas = resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1665
- const contractIdInputSize = (0, import_math5.bn)(4 + 32 + 32 + 32);
1982
+ const contractIdInputSize = (0, import_math6.bn)(4 + 32 + 32 + 32);
1666
1983
  const contractIdGas = resolveGasDependentCosts(contractIdInputSize, gasCosts.s256);
1667
1984
  const metadataGas = contractRootGas.add(stateRootGas).add(txIdGas).add(contractIdGas);
1668
1985
  return metadataGas.maxU64();
@@ -1673,19 +1990,28 @@ function calculateMetadataGasForTxScript({
1673
1990
  }) {
1674
1991
  return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1675
1992
  }
1993
+ function calculateMetadataGasForTxBlob({
1994
+ gasCosts,
1995
+ txBytesSize,
1996
+ witnessBytesSize
1997
+ }) {
1998
+ const txId = resolveGasDependentCosts(txBytesSize, gasCosts.s256);
1999
+ const blobLen = resolveGasDependentCosts(witnessBytesSize, gasCosts.s256);
2000
+ return txId.add(blobLen);
2001
+ }
1676
2002
  var calculateGasFee = (params) => {
1677
2003
  const { gas, gasPrice, priceFactor, tip } = params;
1678
- return gas.mul(gasPrice).div(priceFactor).add((0, import_math5.bn)(tip));
2004
+ return gas.mul(gasPrice).div(priceFactor).add((0, import_math6.bn)(tip));
1679
2005
  };
1680
2006
 
1681
2007
  // src/providers/utils/json.ts
1682
- var import_utils7 = require("@fuel-ts/utils");
2008
+ var import_utils9 = require("@fuel-ts/utils");
1683
2009
  var import_ramda = require("ramda");
1684
2010
  function normalize(object) {
1685
2011
  Object.keys(object).forEach((key) => {
1686
2012
  switch (object[key]?.constructor.name) {
1687
2013
  case "Uint8Array":
1688
- object[key] = (0, import_utils7.hexlify)(object[key]);
2014
+ object[key] = (0, import_utils9.hexlify)(object[key]);
1689
2015
  break;
1690
2016
  case "Array":
1691
2017
  object[key] = normalize(object[key]);
@@ -1710,8 +2036,8 @@ function normalizeJSON(root) {
1710
2036
  }
1711
2037
 
1712
2038
  // src/providers/utils/extract-tx-error.ts
1713
- var import_errors7 = require("@fuel-ts/errors");
1714
- var import_math6 = require("@fuel-ts/math");
2039
+ var import_errors8 = require("@fuel-ts/errors");
2040
+ var import_math7 = require("@fuel-ts/math");
1715
2041
  var import_transactions5 = require("@fuel-ts/transactions");
1716
2042
  var import_configs5 = require("@fuel-ts/transactions/configs");
1717
2043
  var assemblePanicError = (statusReason, metadata) => {
@@ -1723,7 +2049,7 @@ You can read more about this error at:
1723
2049
 
1724
2050
  ${import_configs5.PANIC_DOC_URL}#variant.${statusReason}`;
1725
2051
  }
1726
- return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, {
2052
+ return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
1727
2053
  ...metadata,
1728
2054
  reason: statusReason
1729
2055
  });
@@ -1734,7 +2060,7 @@ var assembleRevertError = (receipts, logs, metadata) => {
1734
2060
  const revertReceipt = receipts.find(({ type }) => type === import_transactions5.ReceiptType.Revert);
1735
2061
  let reason = "";
1736
2062
  if (revertReceipt) {
1737
- const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
2063
+ const reasonHex = (0, import_math7.bn)(revertReceipt.val).toHex();
1738
2064
  switch (reasonHex) {
1739
2065
  case import_configs5.FAILED_REQUIRE_SIGNAL: {
1740
2066
  reason = "require";
@@ -1762,8 +2088,8 @@ var assembleRevertError = (receipts, logs, metadata) => {
1762
2088
  errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1763
2089
  break;
1764
2090
  default:
1765
- throw new import_errors7.FuelError(
1766
- import_errors7.ErrorCode.UNKNOWN,
2091
+ throw new import_errors8.FuelError(
2092
+ import_errors8.ErrorCode.UNKNOWN,
1767
2093
  `The transaction reverted with an unknown reason: ${revertReceipt.val}`,
1768
2094
  {
1769
2095
  ...metadata,
@@ -1772,7 +2098,7 @@ var assembleRevertError = (receipts, logs, metadata) => {
1772
2098
  );
1773
2099
  }
1774
2100
  }
1775
- return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, {
2101
+ return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
1776
2102
  ...metadata,
1777
2103
  reason
1778
2104
  });
@@ -1805,7 +2131,7 @@ var NoWitnessAtIndexError = class extends Error {
1805
2131
  };
1806
2132
 
1807
2133
  // src/providers/transaction-request/helpers.ts
1808
- var import_math7 = require("@fuel-ts/math");
2134
+ var import_math8 = require("@fuel-ts/math");
1809
2135
  var import_transactions6 = require("@fuel-ts/transactions");
1810
2136
  var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
1811
2137
  var isRequestInputMessage = (input) => input.type === import_transactions6.InputType.Message;
@@ -1820,7 +2146,7 @@ var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filte
1820
2146
  return acc.add(input.amount);
1821
2147
  }
1822
2148
  return acc;
1823
- }, (0, import_math7.bn)(0));
2149
+ }, (0, import_math8.bn)(0));
1824
2150
  var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
1825
2151
  (acc, input) => {
1826
2152
  if (isRequestInputCoin(input) && input.owner === owner.toB256()) {
@@ -1837,11 +2163,11 @@ var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
1837
2163
  );
1838
2164
 
1839
2165
  // src/providers/transaction-request/witness.ts
1840
- var import_utils8 = require("@fuel-ts/utils");
2166
+ var import_utils10 = require("@fuel-ts/utils");
1841
2167
  var witnessify = (value) => {
1842
- const data = (0, import_utils8.arrayify)(value);
2168
+ const data = (0, import_utils10.arrayify)(value);
1843
2169
  return {
1844
- data: (0, import_utils8.hexlify)(data),
2170
+ data: (0, import_utils10.hexlify)(data),
1845
2171
  dataLength: data.length
1846
2172
  };
1847
2173
  };
@@ -1876,10 +2202,10 @@ var BaseTransactionRequest = class {
1876
2202
  outputs,
1877
2203
  witnesses
1878
2204
  } = {}) {
1879
- this.tip = tip ? (0, import_math8.bn)(tip) : void 0;
2205
+ this.tip = tip ? (0, import_math9.bn)(tip) : void 0;
1880
2206
  this.maturity = maturity && maturity > 0 ? maturity : void 0;
1881
- this.witnessLimit = (0, import_utils9.isDefined)(witnessLimit) ? (0, import_math8.bn)(witnessLimit) : void 0;
1882
- this.maxFee = (0, import_math8.bn)(maxFee);
2207
+ this.witnessLimit = (0, import_utils11.isDefined)(witnessLimit) ? (0, import_math9.bn)(witnessLimit) : void 0;
2208
+ this.maxFee = (0, import_math9.bn)(maxFee);
1883
2209
  this.inputs = inputs ?? [];
1884
2210
  this.outputs = outputs ?? [];
1885
2211
  this.witnesses = witnesses ?? [];
@@ -1888,13 +2214,13 @@ var BaseTransactionRequest = class {
1888
2214
  let policyTypes = 0;
1889
2215
  const policies = [];
1890
2216
  const { tip, witnessLimit, maturity } = req;
1891
- if ((0, import_math8.bn)(tip).gt(0)) {
2217
+ if ((0, import_math9.bn)(tip).gt(0)) {
1892
2218
  policyTypes += import_transactions7.PolicyType.Tip;
1893
- policies.push({ data: (0, import_math8.bn)(tip), type: import_transactions7.PolicyType.Tip });
2219
+ policies.push({ data: (0, import_math9.bn)(tip), type: import_transactions7.PolicyType.Tip });
1894
2220
  }
1895
- if ((0, import_utils9.isDefined)(witnessLimit) && (0, import_math8.bn)(witnessLimit).gte(0)) {
2221
+ if ((0, import_utils11.isDefined)(witnessLimit) && (0, import_math9.bn)(witnessLimit).gte(0)) {
1896
2222
  policyTypes += import_transactions7.PolicyType.WitnessLimit;
1897
- policies.push({ data: (0, import_math8.bn)(witnessLimit), type: import_transactions7.PolicyType.WitnessLimit });
2223
+ policies.push({ data: (0, import_math9.bn)(witnessLimit), type: import_transactions7.PolicyType.WitnessLimit });
1898
2224
  }
1899
2225
  if (maturity && maturity > 0) {
1900
2226
  policyTypes += import_transactions7.PolicyType.Maturity;
@@ -1974,7 +2300,7 @@ var BaseTransactionRequest = class {
1974
2300
  * @returns The index of the created witness.
1975
2301
  */
1976
2302
  addEmptyWitness() {
1977
- this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
2303
+ this.addWitness((0, import_utils11.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
1978
2304
  return this.witnesses.length - 1;
1979
2305
  }
1980
2306
  /**
@@ -1984,7 +2310,7 @@ var BaseTransactionRequest = class {
1984
2310
  * @param signature - The signature to update the witness with.
1985
2311
  */
1986
2312
  updateWitnessByOwner(address, signature) {
1987
- const ownerAddress = import_address.Address.fromAddressOrString(address);
2313
+ const ownerAddress = import_address2.Address.fromAddressOrString(address);
1988
2314
  const witnessIndex = this.getCoinInputWitnessIndexByOwner(ownerAddress);
1989
2315
  if (typeof witnessIndex === "number") {
1990
2316
  this.updateWitness(witnessIndex, signature);
@@ -2054,13 +2380,13 @@ var BaseTransactionRequest = class {
2054
2380
  * Returns the witnessIndex of the found CoinInput.
2055
2381
  */
2056
2382
  getCoinInputWitnessIndexByOwner(owner) {
2057
- const ownerAddress = (0, import_address.addressify)(owner);
2383
+ const ownerAddress = (0, import_address2.addressify)(owner);
2058
2384
  const found = this.inputs.find((input) => {
2059
2385
  switch (input.type) {
2060
2386
  case import_transactions7.InputType.Coin:
2061
- return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
2387
+ return (0, import_utils11.hexlify)(input.owner) === ownerAddress.toB256();
2062
2388
  case import_transactions7.InputType.Message:
2063
- return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
2389
+ return (0, import_utils11.hexlify)(input.recipient) === ownerAddress.toB256();
2064
2390
  default:
2065
2391
  return false;
2066
2392
  }
@@ -2164,7 +2490,7 @@ var BaseTransactionRequest = class {
2164
2490
  addCoinOutput(to, amount, assetId) {
2165
2491
  this.pushOutput({
2166
2492
  type: import_transactions7.OutputType.Coin,
2167
- to: (0, import_address.addressify)(to).toB256(),
2493
+ to: (0, import_address2.addressify)(to).toB256(),
2168
2494
  amount,
2169
2495
  assetId
2170
2496
  });
@@ -2180,7 +2506,7 @@ var BaseTransactionRequest = class {
2180
2506
  quantities.map(coinQuantityfy).forEach((quantity) => {
2181
2507
  this.pushOutput({
2182
2508
  type: import_transactions7.OutputType.Coin,
2183
- to: (0, import_address.addressify)(to).toB256(),
2509
+ to: (0, import_address2.addressify)(to).toB256(),
2184
2510
  amount: quantity.amount,
2185
2511
  assetId: quantity.assetId
2186
2512
  });
@@ -2195,12 +2521,12 @@ var BaseTransactionRequest = class {
2195
2521
  */
2196
2522
  addChangeOutput(to, assetId) {
2197
2523
  const changeOutput = this.getChangeOutputs().find(
2198
- (output) => (0, import_utils9.hexlify)(output.assetId) === assetId
2524
+ (output) => (0, import_utils11.hexlify)(output.assetId) === assetId
2199
2525
  );
2200
2526
  if (!changeOutput) {
2201
2527
  this.pushOutput({
2202
2528
  type: import_transactions7.OutputType.Change,
2203
- to: (0, import_address.addressify)(to).toB256(),
2529
+ to: (0, import_address2.addressify)(to).toB256(),
2204
2530
  assetId
2205
2531
  });
2206
2532
  }
@@ -2215,7 +2541,7 @@ var BaseTransactionRequest = class {
2215
2541
  * @hidden
2216
2542
  */
2217
2543
  metadataGas(_gasCosts) {
2218
- throw new Error("Not implemented");
2544
+ throw new import_errors9.FuelError(import_errors9.FuelError.CODES.NOT_IMPLEMENTED, "Not implemented");
2219
2545
  }
2220
2546
  /**
2221
2547
  * @hidden
@@ -2270,26 +2596,27 @@ var BaseTransactionRequest = class {
2270
2596
  const assetInput = findAssetInput(assetId);
2271
2597
  let usedQuantity = quantity;
2272
2598
  if (assetId === baseAssetId) {
2273
- usedQuantity = (0, import_math8.bn)("1000000000000000000");
2599
+ usedQuantity = (0, import_math9.bn)("1000000000000000000");
2274
2600
  }
2275
2601
  if (assetInput && "assetId" in assetInput) {
2276
- assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
2602
+ assetInput.id = (0, import_utils11.hexlify)((0, import_crypto3.randomBytes)(import_abi_coder3.UTXO_ID_LEN));
2277
2603
  assetInput.amount = usedQuantity;
2278
2604
  } else {
2279
2605
  this.addResources([
2280
2606
  {
2281
- id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
2607
+ id: (0, import_utils11.hexlify)((0, import_crypto3.randomBytes)(import_abi_coder3.UTXO_ID_LEN)),
2282
2608
  amount: usedQuantity,
2283
2609
  assetId,
2284
- owner: resourcesOwner || import_address.Address.fromRandom(),
2285
- blockCreated: (0, import_math8.bn)(1),
2286
- txCreatedIdx: (0, import_math8.bn)(1)
2610
+ owner: resourcesOwner || import_address2.Address.fromRandom(),
2611
+ blockCreated: (0, import_math9.bn)(1),
2612
+ txCreatedIdx: (0, import_math9.bn)(1)
2287
2613
  }
2288
2614
  ]);
2289
2615
  }
2290
2616
  };
2291
- updateAssetInput(baseAssetId, (0, import_math8.bn)(1e11));
2617
+ updateAssetInput(baseAssetId, (0, import_math9.bn)(1e11));
2292
2618
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
2619
+ return this;
2293
2620
  }
2294
2621
  /**
2295
2622
  * Retrieves an array of CoinQuantity for each coin output present in the transaction.
@@ -2299,7 +2626,7 @@ var BaseTransactionRequest = class {
2299
2626
  */
2300
2627
  getCoinOutputsQuantities() {
2301
2628
  const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
2302
- amount: (0, import_math8.bn)(amount),
2629
+ amount: (0, import_math9.bn)(amount),
2303
2630
  assetId: assetId.toString()
2304
2631
  }));
2305
2632
  return coinsQuantities;
@@ -2329,27 +2656,24 @@ var BaseTransactionRequest = class {
2329
2656
  this.inputs.filter(isRequestInputResource).forEach((i) => {
2330
2657
  const owner = getRequestInputResourceOwner(i);
2331
2658
  const correspondingInput = inputsToExtractGasUsed.find(
2332
- (x) => isRequestInputResourceFromOwner(x, import_address.Address.fromString(String(owner)))
2659
+ (x) => isRequestInputResourceFromOwner(x, import_address2.Address.fromString(String(owner)))
2333
2660
  );
2334
- if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math8.bn)(correspondingInput.predicateGasUsed).gt(0)) {
2661
+ if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math9.bn)(correspondingInput.predicateGasUsed).gt(0)) {
2335
2662
  i.predicateGasUsed = correspondingInput.predicateGasUsed;
2336
2663
  }
2337
2664
  });
2338
2665
  }
2666
+ byteLength() {
2667
+ return this.toTransactionBytes().byteLength;
2668
+ }
2339
2669
  };
2340
2670
 
2341
- // src/providers/transaction-request/create-transaction-request.ts
2342
- var import_configs8 = require("@fuel-ts/address/configs");
2343
- var import_math10 = require("@fuel-ts/math");
2344
- var import_transactions9 = require("@fuel-ts/transactions");
2345
- var import_utils13 = require("@fuel-ts/utils");
2346
-
2347
2671
  // src/providers/transaction-request/hash-transaction.ts
2348
2672
  var import_configs7 = require("@fuel-ts/address/configs");
2349
- var import_hasher = require("@fuel-ts/hasher");
2350
- var import_math9 = require("@fuel-ts/math");
2673
+ var import_hasher2 = require("@fuel-ts/hasher");
2674
+ var import_math10 = require("@fuel-ts/math");
2351
2675
  var import_transactions8 = require("@fuel-ts/transactions");
2352
- var import_utils11 = require("@fuel-ts/utils");
2676
+ var import_utils13 = require("@fuel-ts/utils");
2353
2677
  var import_ramda2 = require("ramda");
2354
2678
  function hashTransaction(transactionRequest, chainId) {
2355
2679
  const transaction = transactionRequest.toTransaction();
@@ -2364,11 +2688,11 @@ function hashTransaction(transactionRequest, chainId) {
2364
2688
  blockHeight: 0,
2365
2689
  txIndex: 0
2366
2690
  };
2367
- inputClone.predicateGasUsed = (0, import_math9.bn)(0);
2691
+ inputClone.predicateGasUsed = (0, import_math10.bn)(0);
2368
2692
  return inputClone;
2369
2693
  }
2370
2694
  case import_transactions8.InputType.Message: {
2371
- inputClone.predicateGasUsed = (0, import_math9.bn)(0);
2695
+ inputClone.predicateGasUsed = (0, import_math10.bn)(0);
2372
2696
  return inputClone;
2373
2697
  }
2374
2698
  case import_transactions8.InputType.Contract: {
@@ -2395,12 +2719,12 @@ function hashTransaction(transactionRequest, chainId) {
2395
2719
  return outputClone;
2396
2720
  }
2397
2721
  case import_transactions8.OutputType.Change: {
2398
- outputClone.amount = (0, import_math9.bn)(0);
2722
+ outputClone.amount = (0, import_math10.bn)(0);
2399
2723
  return outputClone;
2400
2724
  }
2401
2725
  case import_transactions8.OutputType.Variable: {
2402
2726
  outputClone.to = import_configs7.ZeroBytes32;
2403
- outputClone.amount = (0, import_math9.bn)(0);
2727
+ outputClone.amount = (0, import_math10.bn)(0);
2404
2728
  outputClone.assetId = import_configs7.ZeroBytes32;
2405
2729
  return outputClone;
2406
2730
  }
@@ -2410,16 +2734,86 @@ function hashTransaction(transactionRequest, chainId) {
2410
2734
  });
2411
2735
  transaction.witnessesCount = 0;
2412
2736
  transaction.witnesses = [];
2413
- const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
2414
- const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions8.TransactionCoder().encode(transaction)]);
2415
- return (0, import_hasher.sha256)(concatenatedData);
2737
+ const chainIdBytes = (0, import_hasher2.uint64ToBytesBE)(chainId);
2738
+ const concatenatedData = (0, import_utils13.concat)([chainIdBytes, new import_transactions8.TransactionCoder().encode(transaction)]);
2739
+ return (0, import_hasher2.sha256)(concatenatedData);
2416
2740
  }
2417
2741
 
2742
+ // src/providers/transaction-request/blob-transaction-request.ts
2743
+ var BlobTransactionRequest = class extends BaseTransactionRequest {
2744
+ static from(obj) {
2745
+ if (obj instanceof this) {
2746
+ return obj;
2747
+ }
2748
+ return new this(obj);
2749
+ }
2750
+ /** Type of the transaction */
2751
+ type = import_transactions7.TransactionType.Blob;
2752
+ /** Blob ID */
2753
+ blobId;
2754
+ /** Witness index of contract bytecode to create */
2755
+ witnessIndex;
2756
+ /**
2757
+ * Creates an instance `BlobTransactionRequest`.
2758
+ *
2759
+ * @param blobTransactionRequestLike - The initial values for the instance
2760
+ */
2761
+ constructor({ witnessIndex, blobId, ...rest }) {
2762
+ super(rest);
2763
+ this.blobId = blobId;
2764
+ this.witnessIndex = witnessIndex ?? 0;
2765
+ }
2766
+ /**
2767
+ * Converts the transaction request to a `TransactionBlob`.
2768
+ *
2769
+ * @returns The transaction create object.
2770
+ */
2771
+ toTransaction() {
2772
+ const baseTransaction = this.getBaseTransaction();
2773
+ const { witnessIndex, blobId } = this;
2774
+ return {
2775
+ type: import_transactions7.TransactionType.Blob,
2776
+ ...baseTransaction,
2777
+ blobId,
2778
+ witnessIndex
2779
+ };
2780
+ }
2781
+ /**
2782
+ * Gets the Transaction Request by hashing the transaction.
2783
+ *
2784
+ * @param chainId - The chain ID.
2785
+ *
2786
+ * @returns - A hash of the transaction, which is the transaction ID.
2787
+ */
2788
+ getTransactionId(chainId) {
2789
+ return hashTransaction(this, chainId);
2790
+ }
2791
+ /**
2792
+ * Calculates the metadata gas cost for a blob transaction.
2793
+ *
2794
+ * @param gasCosts - gas costs passed from the chain.
2795
+ * @returns metadata gas cost for the blob transaction.
2796
+ */
2797
+ metadataGas(gasCosts) {
2798
+ return calculateMetadataGasForTxBlob({
2799
+ gasCosts,
2800
+ txBytesSize: this.byteSize(),
2801
+ witnessBytesSize: this.witnesses[this.witnessIndex].length
2802
+ });
2803
+ }
2804
+ };
2805
+
2806
+ // src/providers/transaction-request/create-transaction-request.ts
2807
+ var import_configs8 = require("@fuel-ts/address/configs");
2808
+ var import_math11 = require("@fuel-ts/math");
2809
+ var import_transactions9 = require("@fuel-ts/transactions");
2810
+ var import_utils16 = require("@fuel-ts/utils");
2811
+
2418
2812
  // src/providers/transaction-request/storage-slot.ts
2419
- var import_utils12 = require("@fuel-ts/utils");
2813
+ var import_utils15 = require("@fuel-ts/utils");
2420
2814
  var getStorageValue = (value) => {
2421
2815
  const v = new Uint8Array(32);
2422
- v.set((0, import_utils12.arrayify)(value));
2816
+ v.set((0, import_utils15.arrayify)(value));
2423
2817
  return v;
2424
2818
  };
2425
2819
  var storageSlotify = (storageSlot) => {
@@ -2433,8 +2827,8 @@ var storageSlotify = (storageSlot) => {
2433
2827
  value = storageSlot.value;
2434
2828
  }
2435
2829
  return {
2436
- key: (0, import_utils12.hexlify)(key),
2437
- value: (0, import_utils12.hexlify)(getStorageValue(value))
2830
+ key: (0, import_utils15.hexlify)(key),
2831
+ value: (0, import_utils15.hexlify)(getStorageValue(value))
2438
2832
  };
2439
2833
  };
2440
2834
 
@@ -2462,7 +2856,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2462
2856
  constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
2463
2857
  super(rest);
2464
2858
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
2465
- this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
2859
+ this.salt = (0, import_utils16.hexlify)(salt ?? import_configs8.ZeroBytes32);
2466
2860
  this.storageSlots = [...storageSlots ?? []];
2467
2861
  }
2468
2862
  /**
@@ -2478,8 +2872,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2478
2872
  type: import_transactions9.TransactionType.Create,
2479
2873
  ...baseTransaction,
2480
2874
  bytecodeWitnessIndex,
2481
- storageSlotsCount: (0, import_math10.bn)(storageSlots.length),
2482
- salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2875
+ storageSlotsCount: (0, import_math11.bn)(storageSlots.length),
2876
+ salt: this.salt ? (0, import_utils16.hexlify)(this.salt) : import_configs8.ZeroBytes32,
2483
2877
  storageSlots
2484
2878
  };
2485
2879
  }
@@ -2518,7 +2912,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2518
2912
  }
2519
2913
  metadataGas(gasCosts) {
2520
2914
  return calculateMetadataGasForTxCreate({
2521
- contractBytesSize: (0, import_math10.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2915
+ contractBytesSize: (0, import_math11.bn)((0, import_utils16.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
2522
2916
  gasCosts,
2523
2917
  stateRootSize: this.storageSlots.length,
2524
2918
  txBytesSize: this.byteSize()
@@ -2527,22 +2921,22 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
2527
2921
  };
2528
2922
 
2529
2923
  // src/providers/transaction-request/script-transaction-request.ts
2530
- var import_abi_coder3 = require("@fuel-ts/abi-coder");
2531
- var import_address2 = require("@fuel-ts/address");
2924
+ var import_abi_coder4 = require("@fuel-ts/abi-coder");
2925
+ var import_address3 = require("@fuel-ts/address");
2532
2926
  var import_configs9 = require("@fuel-ts/address/configs");
2533
- var import_math11 = require("@fuel-ts/math");
2927
+ var import_math12 = require("@fuel-ts/math");
2534
2928
  var import_transactions10 = require("@fuel-ts/transactions");
2535
- var import_utils15 = require("@fuel-ts/utils");
2929
+ var import_utils18 = require("@fuel-ts/utils");
2536
2930
 
2537
2931
  // src/providers/transaction-request/scripts.ts
2538
- var import_utils14 = require("@fuel-ts/utils");
2932
+ var import_utils17 = require("@fuel-ts/utils");
2539
2933
  var returnZeroScript = {
2540
2934
  /*
2541
2935
  Opcode::RET(REG_ZERO)
2542
2936
  Opcode::NOOP
2543
2937
  */
2544
2938
  // TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
2545
- bytes: (0, import_utils14.arrayify)("0x24000000"),
2939
+ bytes: (0, import_utils17.arrayify)("0x24000000"),
2546
2940
  encodeScriptData: () => new Uint8Array(0)
2547
2941
  };
2548
2942
  var withdrawScript = {
@@ -2556,7 +2950,7 @@ var withdrawScript = {
2556
2950
  00000000 00000000 [amount value]
2557
2951
  */
2558
2952
  // TODO: Don't use hardcoded scripts: https://github.com/FuelLabs/fuels-ts/issues/281
2559
- bytes: (0, import_utils14.arrayify)("0x5040C0105D44C0064C40001124000000"),
2953
+ bytes: (0, import_utils17.arrayify)("0x5040C0105D44C0064C40001124000000"),
2560
2954
  encodeScriptData: () => new Uint8Array(0)
2561
2955
  };
2562
2956
 
@@ -2584,9 +2978,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2584
2978
  */
2585
2979
  constructor({ script, scriptData, gasLimit, ...rest } = {}) {
2586
2980
  super(rest);
2587
- this.gasLimit = (0, import_math11.bn)(gasLimit);
2588
- this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
2589
- this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
2981
+ this.gasLimit = (0, import_math12.bn)(gasLimit);
2982
+ this.script = (0, import_utils18.arrayify)(script ?? returnZeroScript.bytes);
2983
+ this.scriptData = (0, import_utils18.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
2590
2984
  this.abis = rest.abis;
2591
2985
  }
2592
2986
  /**
@@ -2595,17 +2989,17 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2595
2989
  * @returns The transaction script object.
2596
2990
  */
2597
2991
  toTransaction() {
2598
- const script = (0, import_utils15.arrayify)(this.script ?? "0x");
2599
- const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
2992
+ const script = (0, import_utils18.arrayify)(this.script ?? "0x");
2993
+ const scriptData = (0, import_utils18.arrayify)(this.scriptData ?? "0x");
2600
2994
  return {
2601
2995
  type: import_transactions10.TransactionType.Script,
2602
2996
  scriptGasLimit: this.gasLimit,
2603
2997
  ...super.getBaseTransaction(),
2604
- scriptLength: (0, import_math11.bn)(script.length),
2605
- scriptDataLength: (0, import_math11.bn)(scriptData.length),
2998
+ scriptLength: (0, import_math12.bn)(script.length),
2999
+ scriptDataLength: (0, import_math12.bn)(scriptData.length),
2606
3000
  receiptsRoot: import_configs9.ZeroBytes32,
2607
- script: (0, import_utils15.hexlify)(script),
2608
- scriptData: (0, import_utils15.hexlify)(scriptData)
3001
+ script: (0, import_utils18.hexlify)(script),
3002
+ scriptData: (0, import_utils18.hexlify)(scriptData)
2609
3003
  };
2610
3004
  }
2611
3005
  /**
@@ -2697,7 +3091,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2697
3091
  * @returns The current instance of the `ScriptTransactionRequest`.
2698
3092
  */
2699
3093
  addContractInputAndOutput(contract) {
2700
- const contractAddress = (0, import_address2.addressify)(contract);
3094
+ const contractAddress = (0, import_address3.addressify)(contract);
2701
3095
  if (this.getContractInputs().find((i) => i.contractId === contractAddress.toB256())) {
2702
3096
  return this;
2703
3097
  }
@@ -2730,7 +3124,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2730
3124
  * @returns The current instance of the `ScriptTransactionRequest`.
2731
3125
  */
2732
3126
  setData(abi, args) {
2733
- const abiInterface = new import_abi_coder3.Interface(abi);
3127
+ const abiInterface = new import_abi_coder4.Interface(abi);
2734
3128
  this.scriptData = abiInterface.functions.main.encodeArguments(args);
2735
3129
  return this;
2736
3130
  }
@@ -2743,10 +3137,10 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
2743
3137
  };
2744
3138
 
2745
3139
  // src/providers/transaction-request/utils.ts
2746
- var import_errors9 = require("@fuel-ts/errors");
3140
+ var import_errors11 = require("@fuel-ts/errors");
2747
3141
  var import_transactions11 = require("@fuel-ts/transactions");
2748
3142
  var transactionRequestify = (obj) => {
2749
- if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
3143
+ if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest || obj instanceof BlobTransactionRequest) {
2750
3144
  return obj;
2751
3145
  }
2752
3146
  const { type } = obj;
@@ -2757,27 +3151,35 @@ var transactionRequestify = (obj) => {
2757
3151
  case import_transactions11.TransactionType.Create: {
2758
3152
  return CreateTransactionRequest.from(obj);
2759
3153
  }
3154
+ case import_transactions11.TransactionType.Blob: {
3155
+ return BlobTransactionRequest.from(obj);
3156
+ }
2760
3157
  default: {
2761
- throw new import_errors9.FuelError(import_errors9.ErrorCode.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
3158
+ throw new import_errors11.FuelError(
3159
+ import_errors11.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
3160
+ `Unsupported transaction type: ${type}.`
3161
+ );
2762
3162
  }
2763
3163
  }
2764
3164
  };
3165
+ var isTransactionTypeScript = (request) => request.type === import_transactions11.TransactionType.Script;
3166
+ var isTransactionTypeCreate = (request) => request.type === import_transactions11.TransactionType.Create;
2765
3167
 
2766
3168
  // src/providers/transaction-response/transaction-response.ts
2767
- var import_errors13 = require("@fuel-ts/errors");
2768
- var import_math16 = require("@fuel-ts/math");
3169
+ var import_errors15 = require("@fuel-ts/errors");
3170
+ var import_math17 = require("@fuel-ts/math");
2769
3171
  var import_transactions19 = require("@fuel-ts/transactions");
2770
- var import_utils20 = require("@fuel-ts/utils");
3172
+ var import_utils23 = require("@fuel-ts/utils");
2771
3173
 
2772
3174
  // src/providers/transaction-summary/assemble-transaction-summary.ts
2773
- var import_math15 = require("@fuel-ts/math");
3175
+ var import_math16 = require("@fuel-ts/math");
2774
3176
  var import_transactions17 = require("@fuel-ts/transactions");
2775
- var import_utils18 = require("@fuel-ts/utils");
3177
+ var import_utils21 = require("@fuel-ts/utils");
2776
3178
 
2777
3179
  // src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
2778
- var import_math12 = require("@fuel-ts/math");
3180
+ var import_math13 = require("@fuel-ts/math");
2779
3181
  var import_transactions12 = require("@fuel-ts/transactions");
2780
- var import_utils16 = require("@fuel-ts/utils");
3182
+ var import_utils19 = require("@fuel-ts/utils");
2781
3183
  var calculateTXFeeForSummary = (params) => {
2782
3184
  const {
2783
3185
  gasPrice,
@@ -2789,19 +3191,19 @@ var calculateTXFeeForSummary = (params) => {
2789
3191
  if (totalFee) {
2790
3192
  return totalFee;
2791
3193
  }
2792
- const gasPerByte = (0, import_math12.bn)(feeParams.gasPerByte);
2793
- const gasPriceFactor = (0, import_math12.bn)(feeParams.gasPriceFactor);
2794
- const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
3194
+ const gasPerByte = (0, import_math13.bn)(feeParams.gasPerByte);
3195
+ const gasPriceFactor = (0, import_math13.bn)(feeParams.gasPriceFactor);
3196
+ const transactionBytes = (0, import_utils19.arrayify)(rawPayload);
2795
3197
  const [transaction] = new import_transactions12.TransactionCoder().decode(transactionBytes, 0);
2796
3198
  const { type, witnesses, inputs, policies } = transaction;
2797
- let metadataGas = (0, import_math12.bn)(0);
2798
- let gasLimit = (0, import_math12.bn)(0);
3199
+ let metadataGas = (0, import_math13.bn)(0);
3200
+ let gasLimit = (0, import_math13.bn)(0);
2799
3201
  if (type !== import_transactions12.TransactionType.Create && type !== import_transactions12.TransactionType.Script) {
2800
- return (0, import_math12.bn)(0);
3202
+ return (0, import_math13.bn)(0);
2801
3203
  }
2802
3204
  if (type === import_transactions12.TransactionType.Create) {
2803
3205
  const { bytecodeWitnessIndex, storageSlots } = transaction;
2804
- const contractBytesSize = (0, import_math12.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
3206
+ const contractBytesSize = (0, import_math13.bn)((0, import_utils19.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
2805
3207
  metadataGas = calculateMetadataGasForTxCreate({
2806
3208
  contractBytesSize,
2807
3209
  gasCosts,
@@ -2820,7 +3222,7 @@ var calculateTXFeeForSummary = (params) => {
2820
3222
  }
2821
3223
  const minGas = getMinGas({
2822
3224
  gasCosts,
2823
- gasPerByte: (0, import_math12.bn)(gasPerByte),
3225
+ gasPerByte: (0, import_math13.bn)(gasPerByte),
2824
3226
  inputs,
2825
3227
  metadataGas,
2826
3228
  txBytesSize: transactionBytes.length
@@ -2846,14 +3248,14 @@ var calculateTXFeeForSummary = (params) => {
2846
3248
 
2847
3249
  // src/providers/transaction-summary/operations.ts
2848
3250
  var import_configs10 = require("@fuel-ts/address/configs");
2849
- var import_errors11 = require("@fuel-ts/errors");
2850
- var import_math13 = require("@fuel-ts/math");
3251
+ var import_errors13 = require("@fuel-ts/errors");
3252
+ var import_math14 = require("@fuel-ts/math");
2851
3253
  var import_transactions15 = require("@fuel-ts/transactions");
2852
3254
 
2853
3255
  // src/providers/transaction-summary/call.ts
2854
- var import_abi_coder4 = require("@fuel-ts/abi-coder");
3256
+ var import_abi_coder5 = require("@fuel-ts/abi-coder");
2855
3257
  var getFunctionCall = ({ abi, receipt }) => {
2856
- const abiInterface = new import_abi_coder4.Interface(abi);
3258
+ const abiInterface = new import_abi_coder5.Interface(abi);
2857
3259
  const callFunctionSelector = receipt.param1.toHex(8);
2858
3260
  const functionFragment = abiInterface.getFunction(callFunctionSelector);
2859
3261
  const inputs = functionFragment.jsonFn.inputs;
@@ -2884,7 +3286,7 @@ var getFunctionCall = ({ abi, receipt }) => {
2884
3286
  };
2885
3287
 
2886
3288
  // src/providers/transaction-summary/input.ts
2887
- var import_errors10 = require("@fuel-ts/errors");
3289
+ var import_errors12 = require("@fuel-ts/errors");
2888
3290
  var import_transactions13 = require("@fuel-ts/transactions");
2889
3291
  function getInputsByTypes(inputs, types) {
2890
3292
  return inputs.filter((i) => types.includes(i.type));
@@ -2904,14 +3306,22 @@ function getInputsCoinAndMessage(inputs) {
2904
3306
  function getInputsContract(inputs) {
2905
3307
  return getInputsByType(inputs, import_transactions13.InputType.Contract);
2906
3308
  }
2907
- function getInputFromAssetId(inputs, assetId) {
3309
+ function findCoinInput(inputs, assetId) {
2908
3310
  const coinInputs = getInputsCoin(inputs);
2909
- const messageInputs = getInputsMessage(inputs);
2910
- const coinInput = coinInputs.find((i) => i.assetId === assetId);
2911
- const messageInput = messageInputs.find(
2912
- (_) => assetId === "0x0000000000000000000000000000000000000000000000000000000000000000"
2913
- );
2914
- return coinInput || messageInput;
3311
+ return coinInputs.find((i) => i.assetId === assetId);
3312
+ }
3313
+ function findMessageInput(inputs) {
3314
+ return getInputsMessage(inputs)?.[0];
3315
+ }
3316
+ function getInputFromAssetId(inputs, assetId, isBaseAsset = false) {
3317
+ const coinInput = findCoinInput(inputs, assetId);
3318
+ if (coinInput) {
3319
+ return coinInput;
3320
+ }
3321
+ if (isBaseAsset) {
3322
+ return findMessageInput(inputs);
3323
+ }
3324
+ return void 0;
2915
3325
  }
2916
3326
  function getInputContractFromIndex(inputs, inputIndex) {
2917
3327
  if (inputIndex == null) {
@@ -2922,8 +3332,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
2922
3332
  return void 0;
2923
3333
  }
2924
3334
  if (contractInput.type !== import_transactions13.InputType.Contract) {
2925
- throw new import_errors10.FuelError(
2926
- import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
3335
+ throw new import_errors12.FuelError(
3336
+ import_errors12.ErrorCode.INVALID_TRANSACTION_INPUT,
2927
3337
  `Contract input should be of type 'contract'.`
2928
3338
  );
2929
3339
  }
@@ -2969,10 +3379,12 @@ function getTransactionTypeName(transactionType) {
2969
3379
  return "Create" /* Create */;
2970
3380
  case import_transactions15.TransactionType.Script:
2971
3381
  return "Script" /* Script */;
3382
+ case import_transactions15.TransactionType.Blob:
3383
+ return "Blob" /* Blob */;
2972
3384
  default:
2973
- throw new import_errors11.FuelError(
2974
- import_errors11.ErrorCode.INVALID_TRANSACTION_TYPE,
2975
- `Invalid transaction type: ${transactionType}.`
3385
+ throw new import_errors13.FuelError(
3386
+ import_errors13.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
3387
+ `Unsupported transaction type: ${transactionType}.`
2976
3388
  );
2977
3389
  }
2978
3390
  }
@@ -2995,47 +3407,60 @@ function isTypeUpgrade(transactionType) {
2995
3407
  function isTypeUpload(transactionType) {
2996
3408
  return isType(transactionType, "Upload" /* Upload */);
2997
3409
  }
3410
+ function isTypeBlob(transactionType) {
3411
+ return isType(transactionType, "Blob" /* Blob */);
3412
+ }
2998
3413
  function getReceiptsCall(receipts) {
2999
3414
  return getReceiptsByType(receipts, import_transactions15.ReceiptType.Call);
3000
3415
  }
3001
3416
  function getReceiptsMessageOut(receipts) {
3002
3417
  return getReceiptsByType(receipts, import_transactions15.ReceiptType.MessageOut);
3003
3418
  }
3004
- var mergeAssets = (op1, op2) => {
3419
+ function mergeAssets(op1, op2) {
3005
3420
  const assets1 = op1.assetsSent || [];
3006
3421
  const assets2 = op2.assetsSent || [];
3007
- const filteredAssets = assets2.filter(
3008
- (asset2) => !assets1.some((asset1) => asset1.assetId === asset2.assetId)
3009
- );
3010
- const mergedAssets = assets1.map((asset1) => {
3011
- const matchingAsset = assets2.find((asset2) => asset2.assetId === asset1.assetId);
3012
- if (!matchingAsset) {
3013
- return asset1;
3422
+ const assetMap = /* @__PURE__ */ new Map();
3423
+ assets1.forEach((asset) => {
3424
+ assetMap.set(asset.assetId, { ...asset });
3425
+ });
3426
+ assets2.forEach((asset) => {
3427
+ const existingAsset = assetMap.get(asset.assetId);
3428
+ if (existingAsset) {
3429
+ existingAsset.amount = (0, import_math14.bn)(existingAsset.amount).add(asset.amount);
3430
+ } else {
3431
+ assetMap.set(asset.assetId, { ...asset });
3014
3432
  }
3015
- const mergedAmount = (0, import_math13.bn)(asset1.amount).add(matchingAsset.amount);
3016
- return { ...asset1, amount: mergedAmount };
3017
3433
  });
3018
- return mergedAssets.concat(filteredAssets);
3019
- };
3434
+ return Array.from(assetMap.values());
3435
+ }
3020
3436
  function isSameOperation(a, b) {
3021
3437
  return a.name === b.name && a.from?.address === b.from?.address && a.to?.address === b.to?.address && a.from?.type === b.from?.type && a.to?.type === b.to?.type;
3022
3438
  }
3439
+ function mergeAssetsSent(existing, toAdd) {
3440
+ if (!toAdd.assetsSent?.length) {
3441
+ return existing.assetsSent;
3442
+ }
3443
+ return existing.assetsSent?.length ? mergeAssets(existing, toAdd) : toAdd.assetsSent;
3444
+ }
3445
+ function mergeCalls(existing, toAdd) {
3446
+ if (!toAdd.calls?.length) {
3447
+ return existing.calls;
3448
+ }
3449
+ return [...existing.calls || [], ...toAdd.calls];
3450
+ }
3451
+ function mergeOperations(existing, toAdd) {
3452
+ return {
3453
+ ...existing,
3454
+ assetsSent: mergeAssetsSent(existing, toAdd),
3455
+ calls: mergeCalls(existing, toAdd)
3456
+ };
3457
+ }
3023
3458
  function addOperation(operations, toAdd) {
3024
- const allOperations = [...operations];
3025
- const index = allOperations.findIndex((op) => isSameOperation(op, toAdd));
3026
- if (allOperations[index]) {
3027
- const existentOperation = { ...allOperations[index] };
3028
- if (toAdd.assetsSent?.length) {
3029
- existentOperation.assetsSent = existentOperation.assetsSent?.length ? mergeAssets(existentOperation, toAdd) : toAdd.assetsSent;
3030
- }
3031
- if (toAdd.calls?.length) {
3032
- existentOperation.calls = [...existentOperation.calls || [], ...toAdd.calls];
3033
- }
3034
- allOperations[index] = existentOperation;
3035
- } else {
3036
- allOperations.push(toAdd);
3459
+ const existingIndex = operations.findIndex((op) => isSameOperation(op, toAdd));
3460
+ if (existingIndex === -1) {
3461
+ return [...operations, toAdd];
3037
3462
  }
3038
- return allOperations;
3463
+ return operations.map((op, index) => index === existingIndex ? mergeOperations(op, toAdd) : op);
3039
3464
  }
3040
3465
  function getWithdrawFromFuelOperations({
3041
3466
  inputs,
@@ -3045,7 +3470,7 @@ function getWithdrawFromFuelOperations({
3045
3470
  const messageOutReceipts = getReceiptsMessageOut(receipts);
3046
3471
  const withdrawFromFuelOperations = messageOutReceipts.reduce(
3047
3472
  (prevWithdrawFromFuelOps, receipt) => {
3048
- const input = getInputFromAssetId(inputs, baseAssetId);
3473
+ const input = getInputFromAssetId(inputs, baseAssetId, true);
3049
3474
  if (input) {
3050
3475
  const inputAddress = getInputAccountAddress(input);
3051
3476
  const newWithdrawFromFuelOps = addOperation(prevWithdrawFromFuelOps, {
@@ -3074,65 +3499,80 @@ function getWithdrawFromFuelOperations({
3074
3499
  );
3075
3500
  return withdrawFromFuelOperations;
3076
3501
  }
3502
+ function getContractCalls(contractInput, abiMap, receipt, rawPayload, maxInputs) {
3503
+ const abi = abiMap?.[contractInput.contractID];
3504
+ if (!abi) {
3505
+ return [];
3506
+ }
3507
+ return [
3508
+ getFunctionCall({
3509
+ abi,
3510
+ receipt,
3511
+ rawPayload,
3512
+ maxInputs
3513
+ })
3514
+ ];
3515
+ }
3516
+ function getAssetsSent(receipt) {
3517
+ return receipt.amount?.isZero() ? void 0 : [
3518
+ {
3519
+ amount: receipt.amount,
3520
+ assetId: receipt.assetId
3521
+ }
3522
+ ];
3523
+ }
3524
+ function processCallReceipt(receipt, contractInput, inputs, abiMap, rawPayload, maxInputs, baseAssetId) {
3525
+ const assetId = receipt.assetId === import_configs10.ZeroBytes32 ? baseAssetId : receipt.assetId;
3526
+ const input = getInputFromAssetId(inputs, assetId, assetId === baseAssetId);
3527
+ if (!input) {
3528
+ return [];
3529
+ }
3530
+ const inputAddress = getInputAccountAddress(input);
3531
+ const calls = getContractCalls(contractInput, abiMap, receipt, rawPayload, maxInputs);
3532
+ return [
3533
+ {
3534
+ name: "Contract call" /* contractCall */,
3535
+ from: {
3536
+ type: 1 /* account */,
3537
+ address: inputAddress
3538
+ },
3539
+ to: {
3540
+ type: 0 /* contract */,
3541
+ address: receipt.to
3542
+ },
3543
+ assetsSent: getAssetsSent(receipt),
3544
+ calls
3545
+ }
3546
+ ];
3547
+ }
3077
3548
  function getContractCallOperations({
3078
3549
  inputs,
3079
3550
  outputs,
3080
3551
  receipts,
3081
3552
  abiMap,
3082
3553
  rawPayload,
3083
- maxInputs
3554
+ maxInputs,
3555
+ baseAssetId
3084
3556
  }) {
3085
3557
  const contractCallReceipts = getReceiptsCall(receipts);
3086
3558
  const contractOutputs = getOutputsContract(outputs);
3087
- const contractCallOperations = contractOutputs.reduce((prevOutputCallOps, output) => {
3559
+ return contractOutputs.flatMap((output) => {
3088
3560
  const contractInput = getInputContractFromIndex(inputs, output.inputIndex);
3089
- if (contractInput) {
3090
- const newCallOps = contractCallReceipts.reduce((prevContractCallOps, receipt) => {
3091
- if (receipt.to === contractInput.contractID) {
3092
- const input = getInputFromAssetId(inputs, receipt.assetId);
3093
- if (input) {
3094
- const inputAddress = getInputAccountAddress(input);
3095
- const calls = [];
3096
- const abi = abiMap?.[contractInput.contractID];
3097
- if (abi) {
3098
- calls.push(
3099
- getFunctionCall({
3100
- abi,
3101
- receipt,
3102
- rawPayload,
3103
- maxInputs
3104
- })
3105
- );
3106
- }
3107
- const newContractCallOps = addOperation(prevContractCallOps, {
3108
- name: "Contract call" /* contractCall */,
3109
- from: {
3110
- type: 1 /* account */,
3111
- address: inputAddress
3112
- },
3113
- to: {
3114
- type: 0 /* contract */,
3115
- address: receipt.to
3116
- },
3117
- // if no amount is forwarded to the contract, skip showing assetsSent
3118
- assetsSent: receipt.amount?.isZero() ? void 0 : [
3119
- {
3120
- amount: receipt.amount,
3121
- assetId: receipt.assetId
3122
- }
3123
- ],
3124
- calls
3125
- });
3126
- return newContractCallOps;
3127
- }
3128
- }
3129
- return prevContractCallOps;
3130
- }, prevOutputCallOps);
3131
- return newCallOps;
3561
+ if (!contractInput) {
3562
+ return [];
3132
3563
  }
3133
- return prevOutputCallOps;
3134
- }, []);
3135
- return contractCallOperations;
3564
+ return contractCallReceipts.filter((receipt) => receipt.to === contractInput.contractID).flatMap(
3565
+ (receipt) => processCallReceipt(
3566
+ receipt,
3567
+ contractInput,
3568
+ inputs,
3569
+ abiMap,
3570
+ rawPayload,
3571
+ maxInputs,
3572
+ baseAssetId
3573
+ )
3574
+ );
3575
+ });
3136
3576
  }
3137
3577
  function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
3138
3578
  const { to: toAddress, assetId, amount } = receipt;
@@ -3276,7 +3716,8 @@ function getOperations({
3276
3716
  receipts,
3277
3717
  abiMap,
3278
3718
  rawPayload,
3279
- maxInputs
3719
+ maxInputs,
3720
+ baseAssetId
3280
3721
  }),
3281
3722
  ...getWithdrawFromFuelOperations({ inputs, receipts, baseAssetId })
3282
3723
  ];
@@ -3335,8 +3776,8 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
3335
3776
  };
3336
3777
 
3337
3778
  // src/providers/transaction-summary/status.ts
3338
- var import_errors12 = require("@fuel-ts/errors");
3339
- var import_math14 = require("@fuel-ts/math");
3779
+ var import_errors14 = require("@fuel-ts/errors");
3780
+ var import_math15 = require("@fuel-ts/math");
3340
3781
  var getTransactionStatusName = (gqlStatus) => {
3341
3782
  switch (gqlStatus) {
3342
3783
  case "FailureStatus":
@@ -3348,8 +3789,8 @@ var getTransactionStatusName = (gqlStatus) => {
3348
3789
  case "SqueezedOutStatus":
3349
3790
  return "squeezedout" /* squeezedout */;
3350
3791
  default:
3351
- throw new import_errors12.FuelError(
3352
- import_errors12.ErrorCode.INVALID_TRANSACTION_STATUS,
3792
+ throw new import_errors14.FuelError(
3793
+ import_errors14.ErrorCode.INVALID_TRANSACTION_STATUS,
3353
3794
  `Invalid transaction status: ${gqlStatus}.`
3354
3795
  );
3355
3796
  }
@@ -3370,15 +3811,15 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
3370
3811
  time = gqlTransactionStatus.time;
3371
3812
  blockId = gqlTransactionStatus.block.id;
3372
3813
  isStatusSuccess = true;
3373
- totalFee = (0, import_math14.bn)(gqlTransactionStatus.totalFee);
3374
- totalGas = (0, import_math14.bn)(gqlTransactionStatus.totalGas);
3814
+ totalFee = (0, import_math15.bn)(gqlTransactionStatus.totalFee);
3815
+ totalGas = (0, import_math15.bn)(gqlTransactionStatus.totalGas);
3375
3816
  break;
3376
3817
  case "FailureStatus":
3377
3818
  time = gqlTransactionStatus.time;
3378
3819
  blockId = gqlTransactionStatus.block.id;
3379
3820
  isStatusFailure = true;
3380
- totalFee = (0, import_math14.bn)(gqlTransactionStatus.totalFee);
3381
- totalGas = (0, import_math14.bn)(gqlTransactionStatus.totalGas);
3821
+ totalFee = (0, import_math15.bn)(gqlTransactionStatus.totalFee);
3822
+ totalGas = (0, import_math15.bn)(gqlTransactionStatus.totalGas);
3382
3823
  break;
3383
3824
  case "SubmittedStatus":
3384
3825
  time = gqlTransactionStatus.time;
@@ -3418,7 +3859,7 @@ function assembleTransactionSummary(params) {
3418
3859
  baseAssetId
3419
3860
  } = params;
3420
3861
  const gasUsed = getGasUsedFromReceipts(receipts);
3421
- const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
3862
+ const rawPayload = (0, import_utils21.hexlify)(transactionBytes);
3422
3863
  const operations = getOperations({
3423
3864
  transactionType: transaction.type,
3424
3865
  inputs: transaction.inputs || [],
@@ -3430,7 +3871,7 @@ function assembleTransactionSummary(params) {
3430
3871
  baseAssetId
3431
3872
  });
3432
3873
  const typeName = getTransactionTypeName(transaction.type);
3433
- const tip = (0, import_math15.bn)(transaction.policies?.find((policy) => policy.type === import_transactions17.PolicyType.Tip)?.data);
3874
+ const tip = (0, import_math16.bn)(transaction.policies?.find((policy) => policy.type === import_transactions17.PolicyType.Tip)?.data);
3434
3875
  const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
3435
3876
  const fee = calculateTXFeeForSummary({
3436
3877
  totalFee,
@@ -3450,7 +3891,7 @@ function assembleTransactionSummary(params) {
3450
3891
  const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
3451
3892
  let date;
3452
3893
  if (time) {
3453
- date = import_utils18.DateTime.fromTai64(time);
3894
+ date = import_utils21.DateTime.fromTai64(time);
3454
3895
  }
3455
3896
  const transactionSummary = {
3456
3897
  id,
@@ -3470,6 +3911,7 @@ function assembleTransactionSummary(params) {
3470
3911
  isTypeScript: isTypeScript(transaction.type),
3471
3912
  isTypeUpgrade: isTypeUpgrade(transaction.type),
3472
3913
  isTypeUpload: isTypeUpload(transaction.type),
3914
+ isTypeBlob: isTypeBlob(transaction.type),
3473
3915
  isStatusFailure,
3474
3916
  isStatusSuccess,
3475
3917
  isStatusPending,
@@ -3480,13 +3922,13 @@ function assembleTransactionSummary(params) {
3480
3922
  }
3481
3923
 
3482
3924
  // src/providers/transaction-response/getDecodedLogs.ts
3483
- var import_abi_coder5 = require("@fuel-ts/abi-coder");
3925
+ var import_abi_coder6 = require("@fuel-ts/abi-coder");
3484
3926
  var import_transactions18 = require("@fuel-ts/transactions");
3485
3927
  function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
3486
3928
  return receipts.reduce((logs, receipt) => {
3487
3929
  if (receipt.type === import_transactions18.ReceiptType.LogData || receipt.type === import_transactions18.ReceiptType.Log) {
3488
- const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
3489
- const data = receipt.type === import_transactions18.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3930
+ const interfaceToUse = new import_abi_coder6.Interface(externalAbis[receipt.id] || mainAbi);
3931
+ const data = receipt.type === import_transactions18.ReceiptType.Log ? new import_abi_coder6.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
3490
3932
  const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toString());
3491
3933
  logs.push(decodedLog);
3492
3934
  }
@@ -3501,10 +3943,12 @@ var TransactionResponse = class {
3501
3943
  /** Current provider */
3502
3944
  provider;
3503
3945
  /** Gas used on the transaction */
3504
- gasUsed = (0, import_math16.bn)(0);
3946
+ gasUsed = (0, import_math17.bn)(0);
3505
3947
  /** The graphql Transaction with receipts object. */
3506
3948
  gqlTransaction;
3507
3949
  abis;
3950
+ /** The expected status from the getTransactionWithReceipts response */
3951
+ expectedStatus;
3508
3952
  /**
3509
3953
  * Constructor for `TransactionResponse`.
3510
3954
  *
@@ -3544,11 +3988,16 @@ var TransactionResponse = class {
3544
3988
  });
3545
3989
  for await (const { statusChange } of subscription) {
3546
3990
  if (statusChange) {
3991
+ this.expectedStatus = statusChange.type;
3547
3992
  break;
3548
3993
  }
3549
3994
  }
3550
3995
  return this.fetch();
3551
3996
  }
3997
+ if (this.expectedStatus && response.transaction.status?.type !== this.expectedStatus) {
3998
+ await (0, import_utils23.sleep)(100);
3999
+ return this.fetch();
4000
+ }
3552
4001
  this.gqlTransaction = response.transaction;
3553
4002
  return response.transaction;
3554
4003
  }
@@ -3560,7 +4009,7 @@ var TransactionResponse = class {
3560
4009
  */
3561
4010
  decodeTransaction(transactionWithReceipts) {
3562
4011
  return new import_transactions19.TransactionCoder().decode(
3563
- (0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
4012
+ (0, import_utils23.arrayify)(transactionWithReceipts.rawPayload),
3564
4013
  0
3565
4014
  )?.[0];
3566
4015
  }
@@ -3592,7 +4041,7 @@ var TransactionResponse = class {
3592
4041
  id: this.id,
3593
4042
  receipts,
3594
4043
  transaction: decodedTransaction,
3595
- transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
4044
+ transactionBytes: (0, import_utils23.arrayify)(transaction.rawPayload),
3596
4045
  gqlTransactionStatus: transaction.status,
3597
4046
  gasPerByte,
3598
4047
  gasPriceFactor,
@@ -3615,12 +4064,14 @@ var TransactionResponse = class {
3615
4064
  });
3616
4065
  for await (const { statusChange } of subscription) {
3617
4066
  if (statusChange.type === "SqueezedOutStatus") {
3618
- throw new import_errors13.FuelError(
3619
- import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
4067
+ this.unsetResourceCache();
4068
+ throw new import_errors15.FuelError(
4069
+ import_errors15.ErrorCode.TRANSACTION_SQUEEZED_OUT,
3620
4070
  `Transaction Squeezed Out with reason: ${statusChange.reason}`
3621
4071
  );
3622
4072
  }
3623
4073
  if (statusChange.type !== "SubmittedStatus") {
4074
+ this.expectedStatus = statusChange.type;
3624
4075
  break;
3625
4076
  }
3626
4077
  }
@@ -3655,6 +4106,7 @@ var TransactionResponse = class {
3655
4106
  }
3656
4107
  const { gqlTransaction, receipts } = transactionResult;
3657
4108
  if (gqlTransaction.status?.type === "FailureStatus") {
4109
+ this.unsetResourceCache();
3658
4110
  const { reason } = gqlTransaction.status;
3659
4111
  throw extractTxError({
3660
4112
  receipts,
@@ -3681,10 +4133,13 @@ var TransactionResponse = class {
3681
4133
  async wait(contractsAbiMap) {
3682
4134
  return this.waitForResult(contractsAbiMap);
3683
4135
  }
4136
+ unsetResourceCache() {
4137
+ this.provider.cache?.unset(this.id);
4138
+ }
3684
4139
  };
3685
4140
 
3686
4141
  // src/providers/utils/auto-retry-fetch.ts
3687
- var import_utils22 = require("@fuel-ts/utils");
4142
+ var import_utils25 = require("@fuel-ts/utils");
3688
4143
  function getWaitDelay(options, retryAttemptNum) {
3689
4144
  const duration = options.baseDelay ?? 150;
3690
4145
  switch (options.backoff) {
@@ -3714,30 +4169,17 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3714
4169
  throw error;
3715
4170
  }
3716
4171
  const delay = getWaitDelay(options, retryNum);
3717
- await (0, import_utils22.sleep)(delay);
4172
+ await (0, import_utils25.sleep)(delay);
3718
4173
  return autoRetryFetch(fetchFn, options, retryNum)(...args);
3719
4174
  }
3720
4175
  };
3721
4176
  }
3722
4177
 
3723
- // src/providers/utils/merge-quantities.ts
3724
- var mergeQuantities = (...coinQuantities) => {
3725
- const resultMap = {};
3726
- function addToMap({ amount, assetId }) {
3727
- if (resultMap[assetId]) {
3728
- resultMap[assetId] = resultMap[assetId].add(amount);
3729
- } else {
3730
- resultMap[assetId] = amount;
3731
- }
3732
- }
3733
- coinQuantities.forEach((arr) => arr.forEach(addToMap));
3734
- return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
3735
- };
3736
-
3737
4178
  // src/providers/provider.ts
3738
4179
  var MAX_RETRIES = 10;
3739
4180
  var RESOURCES_PAGE_SIZE_LIMIT = 512;
3740
4181
  var BLOCKS_PAGE_SIZE_LIMIT = 5;
4182
+ var DEFAULT_RESOURCE_CACHE_TTL = 2e4;
3741
4183
  var processGqlChain = (chain) => {
3742
4184
  const { name, daHeight, consensusParameters, latestBlock } = chain;
3743
4185
  const {
@@ -3753,47 +4195,47 @@ var processGqlChain = (chain) => {
3753
4195
  } = consensusParameters;
3754
4196
  return {
3755
4197
  name,
3756
- baseChainHeight: (0, import_math17.bn)(daHeight),
4198
+ baseChainHeight: (0, import_math18.bn)(daHeight),
3757
4199
  consensusParameters: {
3758
4200
  version,
3759
- chainId: (0, import_math17.bn)(chainId),
4201
+ chainId: (0, import_math18.bn)(chainId),
3760
4202
  baseAssetId,
3761
4203
  feeParameters: {
3762
4204
  version: feeParams.version,
3763
- gasPerByte: (0, import_math17.bn)(feeParams.gasPerByte),
3764
- gasPriceFactor: (0, import_math17.bn)(feeParams.gasPriceFactor)
4205
+ gasPerByte: (0, import_math18.bn)(feeParams.gasPerByte),
4206
+ gasPriceFactor: (0, import_math18.bn)(feeParams.gasPriceFactor)
3765
4207
  },
3766
4208
  contractParameters: {
3767
4209
  version: contractParams.version,
3768
- contractMaxSize: (0, import_math17.bn)(contractParams.contractMaxSize),
3769
- maxStorageSlots: (0, import_math17.bn)(contractParams.maxStorageSlots)
4210
+ contractMaxSize: (0, import_math18.bn)(contractParams.contractMaxSize),
4211
+ maxStorageSlots: (0, import_math18.bn)(contractParams.maxStorageSlots)
3770
4212
  },
3771
4213
  txParameters: {
3772
4214
  version: txParams.version,
3773
- maxInputs: (0, import_math17.bn)(txParams.maxInputs),
3774
- maxOutputs: (0, import_math17.bn)(txParams.maxOutputs),
3775
- maxWitnesses: (0, import_math17.bn)(txParams.maxWitnesses),
3776
- maxGasPerTx: (0, import_math17.bn)(txParams.maxGasPerTx),
3777
- maxSize: (0, import_math17.bn)(txParams.maxSize),
3778
- maxBytecodeSubsections: (0, import_math17.bn)(txParams.maxBytecodeSubsections)
4215
+ maxInputs: (0, import_math18.bn)(txParams.maxInputs),
4216
+ maxOutputs: (0, import_math18.bn)(txParams.maxOutputs),
4217
+ maxWitnesses: (0, import_math18.bn)(txParams.maxWitnesses),
4218
+ maxGasPerTx: (0, import_math18.bn)(txParams.maxGasPerTx),
4219
+ maxSize: (0, import_math18.bn)(txParams.maxSize),
4220
+ maxBytecodeSubsections: (0, import_math18.bn)(txParams.maxBytecodeSubsections)
3779
4221
  },
3780
4222
  predicateParameters: {
3781
4223
  version: predicateParams.version,
3782
- maxPredicateLength: (0, import_math17.bn)(predicateParams.maxPredicateLength),
3783
- maxPredicateDataLength: (0, import_math17.bn)(predicateParams.maxPredicateDataLength),
3784
- maxGasPerPredicate: (0, import_math17.bn)(predicateParams.maxGasPerPredicate),
3785
- maxMessageDataLength: (0, import_math17.bn)(predicateParams.maxMessageDataLength)
4224
+ maxPredicateLength: (0, import_math18.bn)(predicateParams.maxPredicateLength),
4225
+ maxPredicateDataLength: (0, import_math18.bn)(predicateParams.maxPredicateDataLength),
4226
+ maxGasPerPredicate: (0, import_math18.bn)(predicateParams.maxGasPerPredicate),
4227
+ maxMessageDataLength: (0, import_math18.bn)(predicateParams.maxMessageDataLength)
3786
4228
  },
3787
4229
  scriptParameters: {
3788
4230
  version: scriptParams.version,
3789
- maxScriptLength: (0, import_math17.bn)(scriptParams.maxScriptLength),
3790
- maxScriptDataLength: (0, import_math17.bn)(scriptParams.maxScriptDataLength)
4231
+ maxScriptLength: (0, import_math18.bn)(scriptParams.maxScriptLength),
4232
+ maxScriptDataLength: (0, import_math18.bn)(scriptParams.maxScriptDataLength)
3791
4233
  },
3792
4234
  gasCosts
3793
4235
  },
3794
4236
  latestBlock: {
3795
4237
  id: latestBlock.id,
3796
- height: (0, import_math17.bn)(latestBlock.height),
4238
+ height: (0, import_math18.bn)(latestBlock.height),
3797
4239
  time: latestBlock.header.time,
3798
4240
  transactions: latestBlock.transactions.map((i) => ({
3799
4241
  id: i.id
@@ -3820,14 +4262,23 @@ var _Provider = class {
3820
4262
  __publicField(this, "cache");
3821
4263
  __publicField(this, "options", {
3822
4264
  timeout: void 0,
3823
- cacheUtxo: void 0,
4265
+ resourceCacheTTL: void 0,
3824
4266
  fetch: void 0,
3825
4267
  retryOptions: void 0
3826
4268
  });
3827
4269
  this.options = { ...this.options, ...options };
3828
4270
  this.url = url;
3829
4271
  this.operations = this.createOperations();
3830
- this.cache = options.cacheUtxo ? new MemoryCache(options.cacheUtxo) : void 0;
4272
+ const { resourceCacheTTL } = this.options;
4273
+ if ((0, import_utils26.isDefined)(resourceCacheTTL)) {
4274
+ if (resourceCacheTTL !== -1) {
4275
+ this.cache = new ResourceCache(resourceCacheTTL);
4276
+ } else {
4277
+ this.cache = void 0;
4278
+ }
4279
+ } else {
4280
+ this.cache = new ResourceCache(DEFAULT_RESOURCE_CACHE_TTL);
4281
+ }
3831
4282
  }
3832
4283
  /** @hidden */
3833
4284
  static clearChainAndNodeCaches() {
@@ -3871,8 +4322,8 @@ var _Provider = class {
3871
4322
  getChain() {
3872
4323
  const chain = _Provider.chainInfoCache[this.url];
3873
4324
  if (!chain) {
3874
- throw new import_errors14.FuelError(
3875
- import_errors14.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
4325
+ throw new import_errors16.FuelError(
4326
+ import_errors16.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
3876
4327
  "Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
3877
4328
  );
3878
4329
  }
@@ -3886,8 +4337,8 @@ var _Provider = class {
3886
4337
  getNode() {
3887
4338
  const node = _Provider.nodeInfoCache[this.url];
3888
4339
  if (!node) {
3889
- throw new import_errors14.FuelError(
3890
- import_errors14.ErrorCode.NODE_INFO_CACHE_EMPTY,
4340
+ throw new import_errors16.FuelError(
4341
+ import_errors16.ErrorCode.NODE_INFO_CACHE_EMPTY,
3891
4342
  "Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
3892
4343
  );
3893
4344
  }
@@ -3965,8 +4416,8 @@ Supported fuel-core version: ${supportedVersion}.`
3965
4416
  if ("response" in response) {
3966
4417
  const graphQlResponse = response.response;
3967
4418
  if (Array.isArray(graphQlResponse?.errors)) {
3968
- throw new import_errors14.FuelError(
3969
- import_errors14.FuelError.CODES.INVALID_REQUEST,
4419
+ throw new import_errors16.FuelError(
4420
+ import_errors16.FuelError.CODES.INVALID_REQUEST,
3970
4421
  graphQlResponse.errors.map((err) => err.message).join("\n\n")
3971
4422
  );
3972
4423
  }
@@ -4006,7 +4457,7 @@ Supported fuel-core version: ${supportedVersion}.`
4006
4457
  */
4007
4458
  async getBlockNumber() {
4008
4459
  const { chain } = await this.operations.getChain();
4009
- return (0, import_math17.bn)(chain.latestBlock.height, 10);
4460
+ return (0, import_math18.bn)(chain.latestBlock.height, 10);
4010
4461
  }
4011
4462
  /**
4012
4463
  * Returns the node information for the current provider network.
@@ -4016,8 +4467,8 @@ Supported fuel-core version: ${supportedVersion}.`
4016
4467
  async fetchNode() {
4017
4468
  const { nodeInfo } = await this.operations.getNodeInfo();
4018
4469
  const processedNodeInfo = {
4019
- maxDepth: (0, import_math17.bn)(nodeInfo.maxDepth),
4020
- maxTx: (0, import_math17.bn)(nodeInfo.maxTx),
4470
+ maxDepth: (0, import_math18.bn)(nodeInfo.maxDepth),
4471
+ maxTx: (0, import_math18.bn)(nodeInfo.maxTx),
4021
4472
  nodeVersion: nodeInfo.nodeVersion,
4022
4473
  utxoValidation: nodeInfo.utxoValidation,
4023
4474
  vmBacktrace: nodeInfo.vmBacktrace
@@ -4058,6 +4509,21 @@ Supported fuel-core version: ${supportedVersion}.`
4058
4509
  } = this.getChain();
4059
4510
  return baseAssetId;
4060
4511
  }
4512
+ validateTransaction(tx, consensusParameters) {
4513
+ const { maxOutputs, maxInputs } = consensusParameters.txParameters;
4514
+ if ((0, import_math18.bn)(tx.inputs.length).gt(maxInputs)) {
4515
+ throw new import_errors16.FuelError(
4516
+ import_errors16.ErrorCode.MAX_INPUTS_EXCEEDED,
4517
+ "The transaction exceeds the maximum allowed number of inputs."
4518
+ );
4519
+ }
4520
+ if ((0, import_math18.bn)(tx.outputs.length).gt(maxOutputs)) {
4521
+ throw new import_errors16.FuelError(
4522
+ import_errors16.ErrorCode.MAX_OUTPUTS_EXCEEDED,
4523
+ "The transaction exceeds the maximum allowed number of outputs."
4524
+ );
4525
+ }
4526
+ }
4061
4527
  /**
4062
4528
  * Submits a transaction to the chain to be executed.
4063
4529
  *
@@ -4069,38 +4535,22 @@ Supported fuel-core version: ${supportedVersion}.`
4069
4535
  * @returns A promise that resolves to the transaction response object.
4070
4536
  */
4071
4537
  // #region Provider-sendTransaction
4072
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution = false } = {}) {
4538
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
4073
4539
  const transactionRequest = transactionRequestify(transactionRequestLike);
4074
- __privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs);
4075
4540
  if (estimateTxDependencies) {
4076
4541
  await this.estimateTxDependencies(transactionRequest);
4077
4542
  }
4078
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4543
+ const { consensusParameters } = this.getChain();
4544
+ this.validateTransaction(transactionRequest, consensusParameters);
4545
+ const encodedTransaction = (0, import_utils26.hexlify)(transactionRequest.toTransactionBytes());
4079
4546
  let abis;
4080
- if (transactionRequest.type === import_transactions20.TransactionType.Script) {
4547
+ if (isTransactionTypeScript(transactionRequest)) {
4081
4548
  abis = transactionRequest.abis;
4082
4549
  }
4083
- if (awaitExecution) {
4084
- const subscription = this.operations.submitAndAwait({ encodedTransaction });
4085
- for await (const { submitAndAwait } of subscription) {
4086
- if (submitAndAwait.type === "SqueezedOutStatus") {
4087
- throw new import_errors14.FuelError(
4088
- import_errors14.ErrorCode.TRANSACTION_SQUEEZED_OUT,
4089
- `Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
4090
- );
4091
- }
4092
- if (submitAndAwait.type !== "SubmittedStatus") {
4093
- break;
4094
- }
4095
- }
4096
- const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
4097
- const response = new TransactionResponse(transactionId2, this, abis);
4098
- await response.fetch();
4099
- return response;
4100
- }
4101
4550
  const {
4102
4551
  submit: { id: transactionId }
4103
4552
  } = await this.operations.submit({ encodedTransaction });
4553
+ __privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionId);
4104
4554
  return new TransactionResponse(transactionId, this, abis);
4105
4555
  }
4106
4556
  /**
@@ -4118,7 +4568,7 @@ Supported fuel-core version: ${supportedVersion}.`
4118
4568
  if (estimateTxDependencies) {
4119
4569
  return this.estimateTxDependencies(transactionRequest);
4120
4570
  }
4121
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4571
+ const encodedTransaction = (0, import_utils26.hexlify)(transactionRequest.toTransactionBytes());
4122
4572
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4123
4573
  encodedTransactions: encodedTransaction,
4124
4574
  utxoValidation: utxoValidation || false
@@ -4138,13 +4588,13 @@ Supported fuel-core version: ${supportedVersion}.`
4138
4588
  async estimatePredicates(transactionRequest) {
4139
4589
  const shouldEstimatePredicates = Boolean(
4140
4590
  transactionRequest.inputs.find(
4141
- (input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math17.BN(input.predicateGasUsed).isZero()
4591
+ (input) => "predicate" in input && input.predicate && !(0, import_utils27.equalBytes)((0, import_utils26.arrayify)(input.predicate), (0, import_utils26.arrayify)("0x")) && new import_math18.BN(input.predicateGasUsed).isZero()
4142
4592
  )
4143
4593
  );
4144
4594
  if (!shouldEstimatePredicates) {
4145
4595
  return transactionRequest;
4146
4596
  }
4147
- const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4597
+ const encodedTransaction = (0, import_utils26.hexlify)(transactionRequest.toTransactionBytes());
4148
4598
  const response = await this.operations.estimatePredicates({
4149
4599
  encodedTransaction
4150
4600
  });
@@ -4153,7 +4603,7 @@ Supported fuel-core version: ${supportedVersion}.`
4153
4603
  } = response;
4154
4604
  if (inputs) {
4155
4605
  inputs.forEach((input, index) => {
4156
- if ("predicateGasUsed" in input && (0, import_math17.bn)(input.predicateGasUsed).gt(0)) {
4606
+ if ("predicateGasUsed" in input && (0, import_math18.bn)(input.predicateGasUsed).gt(0)) {
4157
4607
  transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
4158
4608
  }
4159
4609
  });
@@ -4170,7 +4620,7 @@ Supported fuel-core version: ${supportedVersion}.`
4170
4620
  * @returns A promise that resolves to the estimate transaction dependencies.
4171
4621
  */
4172
4622
  async estimateTxDependencies(transactionRequest) {
4173
- if (transactionRequest.type === import_transactions20.TransactionType.Create) {
4623
+ if (isTransactionTypeCreate(transactionRequest)) {
4174
4624
  return {
4175
4625
  receipts: [],
4176
4626
  outputVariables: 0,
@@ -4185,18 +4635,18 @@ Supported fuel-core version: ${supportedVersion}.`
4185
4635
  const {
4186
4636
  dryRun: [{ receipts: rawReceipts, status }]
4187
4637
  } = await this.operations.dryRun({
4188
- encodedTransactions: [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())],
4638
+ encodedTransactions: [(0, import_utils26.hexlify)(transactionRequest.toTransactionBytes())],
4189
4639
  utxoValidation: false
4190
4640
  });
4191
4641
  receipts = rawReceipts.map(processGqlReceipt);
4192
4642
  dryRunStatus = status;
4193
4643
  const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
4194
4644
  const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
4195
- if (hasMissingOutputs) {
4645
+ if (hasMissingOutputs && isTransactionTypeScript(transactionRequest)) {
4196
4646
  outputVariables += missingOutputVariables.length;
4197
4647
  transactionRequest.addVariableOutputs(missingOutputVariables.length);
4198
4648
  missingOutputContractIds.forEach(({ contractId }) => {
4199
- transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4649
+ transactionRequest.addContractInputAndOutput(import_address4.Address.fromString(contractId));
4200
4650
  missingContractIds.push(contractId);
4201
4651
  });
4202
4652
  const { maxFee } = await this.estimateTxGasAndFee({
@@ -4234,8 +4684,8 @@ Supported fuel-core version: ${supportedVersion}.`
4234
4684
  const allRequests = (0, import_ramda3.clone)(transactionRequests);
4235
4685
  const serializedTransactionsMap = /* @__PURE__ */ new Map();
4236
4686
  allRequests.forEach((req, index) => {
4237
- if (req.type === import_transactions20.TransactionType.Script) {
4238
- serializedTransactionsMap.set(index, (0, import_utils23.hexlify)(req.toTransactionBytes()));
4687
+ if (isTransactionTypeScript(req)) {
4688
+ serializedTransactionsMap.set(index, (0, import_utils26.hexlify)(req.toTransactionBytes()));
4239
4689
  }
4240
4690
  });
4241
4691
  let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
@@ -4260,18 +4710,18 @@ Supported fuel-core version: ${supportedVersion}.`
4260
4710
  );
4261
4711
  const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
4262
4712
  const request = allRequests[requestIdx];
4263
- if (hasMissingOutputs && request?.type === import_transactions20.TransactionType.Script) {
4713
+ if (hasMissingOutputs && isTransactionTypeScript(request)) {
4264
4714
  result.outputVariables += missingOutputVariables.length;
4265
4715
  request.addVariableOutputs(missingOutputVariables.length);
4266
4716
  missingOutputContractIds.forEach(({ contractId }) => {
4267
- request.addContractInputAndOutput(import_address3.Address.fromString(contractId));
4717
+ request.addContractInputAndOutput(import_address4.Address.fromString(contractId));
4268
4718
  result.missingContractIds.push(contractId);
4269
4719
  });
4270
4720
  const { maxFee } = await this.estimateTxGasAndFee({
4271
4721
  transactionRequest: request
4272
4722
  });
4273
4723
  request.maxFee = maxFee;
4274
- serializedTransactionsMap.set(requestIdx, (0, import_utils23.hexlify)(request.toTransactionBytes()));
4724
+ serializedTransactionsMap.set(requestIdx, (0, import_utils26.hexlify)(request.toTransactionBytes()));
4275
4725
  nextRoundTransactions.push(requestIdx);
4276
4726
  }
4277
4727
  }
@@ -4292,7 +4742,7 @@ Supported fuel-core version: ${supportedVersion}.`
4292
4742
  if (estimateTxDependencies) {
4293
4743
  return this.estimateMultipleTxDependencies(transactionRequests);
4294
4744
  }
4295
- const encodedTransactions = transactionRequests.map((tx) => (0, import_utils23.hexlify)(tx.toTransactionBytes()));
4745
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils26.hexlify)(tx.toTransactionBytes()));
4296
4746
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4297
4747
  encodedTransactions,
4298
4748
  utxoValidation: utxoValidation || false
@@ -4318,13 +4768,13 @@ Supported fuel-core version: ${supportedVersion}.`
4318
4768
  gasPrice = await this.estimateGasPrice(10);
4319
4769
  }
4320
4770
  const minFee = calculateGasFee({
4321
- gasPrice: (0, import_math17.bn)(gasPrice),
4771
+ gasPrice: (0, import_math18.bn)(gasPrice),
4322
4772
  gas: minGas,
4323
4773
  priceFactor: gasPriceFactor,
4324
4774
  tip: transactionRequest.tip
4325
4775
  }).add(1);
4326
- let gasLimit = (0, import_math17.bn)(0);
4327
- if (transactionRequest.type === import_transactions20.TransactionType.Script) {
4776
+ let gasLimit = (0, import_math18.bn)(0);
4777
+ if (isTransactionTypeScript(transactionRequest)) {
4328
4778
  gasLimit = transactionRequest.gasLimit;
4329
4779
  if (transactionRequest.gasLimit.eq(0)) {
4330
4780
  transactionRequest.gasLimit = minGas;
@@ -4336,7 +4786,7 @@ Supported fuel-core version: ${supportedVersion}.`
4336
4786
  }
4337
4787
  const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
4338
4788
  const maxFee = calculateGasFee({
4339
- gasPrice: (0, import_math17.bn)(gasPrice),
4789
+ gasPrice: (0, import_math18.bn)(gasPrice),
4340
4790
  gas: maxGas,
4341
4791
  priceFactor: gasPriceFactor,
4342
4792
  tip: transactionRequest.tip
@@ -4366,7 +4816,7 @@ Supported fuel-core version: ${supportedVersion}.`
4366
4816
  if (estimateTxDependencies) {
4367
4817
  return this.estimateTxDependencies(transactionRequest);
4368
4818
  }
4369
- const encodedTransactions = [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())];
4819
+ const encodedTransactions = [(0, import_utils26.hexlify)(transactionRequest.toTransactionBytes())];
4370
4820
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4371
4821
  encodedTransactions,
4372
4822
  utxoValidation: true
@@ -4379,6 +4829,8 @@ Supported fuel-core version: ${supportedVersion}.`
4379
4829
  return { receipts: callResult[0].receipts };
4380
4830
  }
4381
4831
  /**
4832
+ * @hidden
4833
+ *
4382
4834
  * Returns a transaction cost to enable user
4383
4835
  * to set gasLimit and also reserve balance amounts
4384
4836
  * on the transaction.
@@ -4388,23 +4840,16 @@ Supported fuel-core version: ${supportedVersion}.`
4388
4840
  *
4389
4841
  * @returns A promise that resolves to the transaction cost object.
4390
4842
  */
4391
- async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
4843
+ async getTransactionCost(transactionRequestLike, { signatureCallback } = {}) {
4392
4844
  const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
4393
- const isScriptTransaction = txRequestClone.type === import_transactions20.TransactionType.Script;
4394
- const baseAssetId = this.getBaseAssetId();
4395
4845
  const updateMaxFee = txRequestClone.maxFee.eq(0);
4396
- const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
4397
- const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
4398
- txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
4846
+ const isScriptTransaction = isTransactionTypeScript(txRequestClone);
4399
4847
  if (isScriptTransaction) {
4400
- txRequestClone.gasLimit = (0, import_math17.bn)(0);
4401
- }
4402
- if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
4403
- resourcesOwner.populateTransactionPredicateData(txRequestClone);
4848
+ txRequestClone.gasLimit = (0, import_math18.bn)(0);
4404
4849
  }
4405
4850
  const signedRequest = (0, import_ramda3.clone)(txRequestClone);
4406
4851
  let addedSignatures = 0;
4407
- if (signatureCallback && isScriptTransaction) {
4852
+ if (signatureCallback && isTransactionTypeScript(signedRequest)) {
4408
4853
  const lengthBefore = signedRequest.witnesses.length;
4409
4854
  await signatureCallback(signedRequest);
4410
4855
  addedSignatures = signedRequest.witnesses.length - lengthBefore;
@@ -4418,7 +4863,7 @@ Supported fuel-core version: ${supportedVersion}.`
4418
4863
  let dryRunStatus;
4419
4864
  let missingContractIds = [];
4420
4865
  let outputVariables = 0;
4421
- let gasUsed = (0, import_math17.bn)(0);
4866
+ let gasUsed = (0, import_math18.bn)(0);
4422
4867
  txRequestClone.maxFee = maxFee;
4423
4868
  if (isScriptTransaction) {
4424
4869
  txRequestClone.gasLimit = gasLimit;
@@ -4437,7 +4882,6 @@ Supported fuel-core version: ${supportedVersion}.`
4437
4882
  }));
4438
4883
  }
4439
4884
  return {
4440
- requiredQuantities: allQuantities,
4441
4885
  receipts,
4442
4886
  gasUsed,
4443
4887
  gasPrice,
@@ -4453,34 +4897,6 @@ Supported fuel-core version: ${supportedVersion}.`
4453
4897
  updateMaxFee
4454
4898
  };
4455
4899
  }
4456
- /**
4457
- * Get the required quantities and associated resources for a transaction.
4458
- *
4459
- * @param owner - address to add resources from.
4460
- * @param transactionRequestLike - transaction request to populate resources for.
4461
- * @param quantitiesToContract - quantities for the contract (optional).
4462
- *
4463
- * @returns a promise resolving to the required quantities for the transaction.
4464
- */
4465
- async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
4466
- const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4467
- const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
4468
- const transactionCost = await this.getTransactionCost(transactionRequest, {
4469
- quantitiesToContract
4470
- });
4471
- transactionRequest.addResources(
4472
- await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
4473
- );
4474
- const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
4475
- quantitiesToContract
4476
- });
4477
- const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
4478
- return {
4479
- resources,
4480
- requiredQuantities,
4481
- ...txCost
4482
- };
4483
- }
4484
4900
  /**
4485
4901
  * Returns coins for the given owner.
4486
4902
  *
@@ -4491,7 +4907,7 @@ Supported fuel-core version: ${supportedVersion}.`
4491
4907
  * @returns A promise that resolves to the coins.
4492
4908
  */
4493
4909
  async getCoins(owner, assetId, paginationArgs) {
4494
- const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4910
+ const ownerAddress = import_address4.Address.fromAddressOrString(owner);
4495
4911
  const {
4496
4912
  coins: { edges, pageInfo }
4497
4913
  } = await this.operations.getCoins({
@@ -4499,15 +4915,15 @@ Supported fuel-core version: ${supportedVersion}.`
4499
4915
  paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
4500
4916
  inputArgs: paginationArgs
4501
4917
  }),
4502
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4918
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils26.hexlify)(assetId) }
4503
4919
  });
4504
4920
  const coins = edges.map(({ node }) => ({
4505
4921
  id: node.utxoId,
4506
4922
  assetId: node.assetId,
4507
- amount: (0, import_math17.bn)(node.amount),
4508
- owner: import_address3.Address.fromAddressOrString(node.owner),
4509
- blockCreated: (0, import_math17.bn)(node.blockCreated),
4510
- txCreatedIdx: (0, import_math17.bn)(node.txCreatedIdx)
4923
+ amount: (0, import_math18.bn)(node.amount),
4924
+ owner: import_address4.Address.fromAddressOrString(node.owner),
4925
+ blockCreated: (0, import_math18.bn)(node.blockCreated),
4926
+ txCreatedIdx: (0, import_math18.bn)(node.txCreatedIdx)
4511
4927
  }));
4512
4928
  return {
4513
4929
  coins,
@@ -4523,21 +4939,20 @@ Supported fuel-core version: ${supportedVersion}.`
4523
4939
  * @returns A promise that resolves to the resources.
4524
4940
  */
4525
4941
  async getResourcesToSpend(owner, quantities, excludedIds) {
4526
- const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4942
+ const ownerAddress = import_address4.Address.fromAddressOrString(owner);
4527
4943
  const excludeInput = {
4528
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4529
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4944
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils26.hexlify)(nonce)) || [],
4945
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils26.hexlify)(id)) || []
4530
4946
  };
4531
4947
  if (this.cache) {
4532
- const uniqueUtxos = new Set(
4533
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4534
- );
4535
- excludeInput.utxos = Array.from(uniqueUtxos);
4948
+ const cached = this.cache.getActiveData();
4949
+ excludeInput.messages.push(...cached.messages);
4950
+ excludeInput.utxos.push(...cached.utxos);
4536
4951
  }
4537
4952
  const coinsQuery = {
4538
4953
  owner: ownerAddress.toB256(),
4539
4954
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4540
- assetId: (0, import_utils23.hexlify)(assetId),
4955
+ assetId: (0, import_utils26.hexlify)(assetId),
4541
4956
  amount: amount.toString(10),
4542
4957
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4543
4958
  })),
@@ -4548,21 +4963,21 @@ Supported fuel-core version: ${supportedVersion}.`
4548
4963
  switch (coin.type) {
4549
4964
  case "MessageCoin":
4550
4965
  return {
4551
- amount: (0, import_math17.bn)(coin.amount),
4966
+ amount: (0, import_math18.bn)(coin.amount),
4552
4967
  assetId: coin.assetId,
4553
- daHeight: (0, import_math17.bn)(coin.daHeight),
4554
- sender: import_address3.Address.fromAddressOrString(coin.sender),
4555
- recipient: import_address3.Address.fromAddressOrString(coin.recipient),
4968
+ daHeight: (0, import_math18.bn)(coin.daHeight),
4969
+ sender: import_address4.Address.fromAddressOrString(coin.sender),
4970
+ recipient: import_address4.Address.fromAddressOrString(coin.recipient),
4556
4971
  nonce: coin.nonce
4557
4972
  };
4558
4973
  case "Coin":
4559
4974
  return {
4560
4975
  id: coin.utxoId,
4561
- amount: (0, import_math17.bn)(coin.amount),
4976
+ amount: (0, import_math18.bn)(coin.amount),
4562
4977
  assetId: coin.assetId,
4563
- owner: import_address3.Address.fromAddressOrString(coin.owner),
4564
- blockCreated: (0, import_math17.bn)(coin.blockCreated),
4565
- txCreatedIdx: (0, import_math17.bn)(coin.txCreatedIdx)
4978
+ owner: import_address4.Address.fromAddressOrString(coin.owner),
4979
+ blockCreated: (0, import_math18.bn)(coin.blockCreated),
4980
+ txCreatedIdx: (0, import_math18.bn)(coin.txCreatedIdx)
4566
4981
  };
4567
4982
  default:
4568
4983
  return null;
@@ -4579,13 +4994,13 @@ Supported fuel-core version: ${supportedVersion}.`
4579
4994
  async getBlock(idOrHeight) {
4580
4995
  let variables;
4581
4996
  if (typeof idOrHeight === "number") {
4582
- variables = { height: (0, import_math17.bn)(idOrHeight).toString(10) };
4997
+ variables = { height: (0, import_math18.bn)(idOrHeight).toString(10) };
4583
4998
  } else if (idOrHeight === "latest") {
4584
4999
  variables = { height: (await this.getBlockNumber()).toString(10) };
4585
5000
  } else if (idOrHeight.length === 66) {
4586
5001
  variables = { blockId: idOrHeight };
4587
5002
  } else {
4588
- variables = { blockId: (0, import_math17.bn)(idOrHeight).toString(10) };
5003
+ variables = { blockId: (0, import_math18.bn)(idOrHeight).toString(10) };
4589
5004
  }
4590
5005
  const { block } = await this.operations.getBlock(variables);
4591
5006
  if (!block) {
@@ -4593,7 +5008,7 @@ Supported fuel-core version: ${supportedVersion}.`
4593
5008
  }
4594
5009
  return {
4595
5010
  id: block.id,
4596
- height: (0, import_math17.bn)(block.height),
5011
+ height: (0, import_math18.bn)(block.height),
4597
5012
  time: block.header.time,
4598
5013
  transactionIds: block.transactions.map((tx) => tx.id)
4599
5014
  };
@@ -4615,7 +5030,7 @@ Supported fuel-core version: ${supportedVersion}.`
4615
5030
  });
4616
5031
  const blocks = edges.map(({ node: block }) => ({
4617
5032
  id: block.id,
4618
- height: (0, import_math17.bn)(block.height),
5033
+ height: (0, import_math18.bn)(block.height),
4619
5034
  time: block.header.time,
4620
5035
  transactionIds: block.transactions.map((tx) => tx.id)
4621
5036
  }));
@@ -4630,7 +5045,7 @@ Supported fuel-core version: ${supportedVersion}.`
4630
5045
  async getBlockWithTransactions(idOrHeight) {
4631
5046
  let variables;
4632
5047
  if (typeof idOrHeight === "number") {
4633
- variables = { blockHeight: (0, import_math17.bn)(idOrHeight).toString(10) };
5048
+ variables = { blockHeight: (0, import_math18.bn)(idOrHeight).toString(10) };
4634
5049
  } else if (idOrHeight === "latest") {
4635
5050
  variables = { blockHeight: (await this.getBlockNumber()).toString() };
4636
5051
  } else {
@@ -4642,11 +5057,11 @@ Supported fuel-core version: ${supportedVersion}.`
4642
5057
  }
4643
5058
  return {
4644
5059
  id: block.id,
4645
- height: (0, import_math17.bn)(block.height, 10),
5060
+ height: (0, import_math18.bn)(block.height, 10),
4646
5061
  time: block.header.time,
4647
5062
  transactionIds: block.transactions.map((tx) => tx.id),
4648
5063
  transactions: block.transactions.map(
4649
- (tx) => new import_transactions20.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
5064
+ (tx) => new import_transactions20.TransactionCoder().decode((0, import_utils26.arrayify)(tx.rawPayload), 0)?.[0]
4650
5065
  )
4651
5066
  };
4652
5067
  }
@@ -4662,7 +5077,7 @@ Supported fuel-core version: ${supportedVersion}.`
4662
5077
  return null;
4663
5078
  }
4664
5079
  return new import_transactions20.TransactionCoder().decode(
4665
- (0, import_utils23.arrayify)(transaction.rawPayload),
5080
+ (0, import_utils26.arrayify)(transaction.rawPayload),
4666
5081
  0
4667
5082
  )?.[0];
4668
5083
  }
@@ -4677,7 +5092,7 @@ Supported fuel-core version: ${supportedVersion}.`
4677
5092
  } = await this.operations.getTransactions(paginationArgs);
4678
5093
  const coder = new import_transactions20.TransactionCoder();
4679
5094
  const transactions = edges.map(
4680
- ({ node: { rawPayload } }) => coder.decode((0, import_utils23.arrayify)(rawPayload), 0)[0]
5095
+ ({ node: { rawPayload } }) => coder.decode((0, import_utils26.arrayify)(rawPayload), 0)[0]
4681
5096
  );
4682
5097
  return { transactions, pageInfo };
4683
5098
  }
@@ -4703,10 +5118,10 @@ Supported fuel-core version: ${supportedVersion}.`
4703
5118
  */
4704
5119
  async getContractBalance(contractId, assetId) {
4705
5120
  const { contractBalance } = await this.operations.getContractBalance({
4706
- contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4707
- asset: (0, import_utils23.hexlify)(assetId)
5121
+ contract: import_address4.Address.fromAddressOrString(contractId).toB256(),
5122
+ asset: (0, import_utils26.hexlify)(assetId)
4708
5123
  });
4709
- return (0, import_math17.bn)(contractBalance.amount, 10);
5124
+ return (0, import_math18.bn)(contractBalance.amount, 10);
4710
5125
  }
4711
5126
  /**
4712
5127
  * Returns the balance for the given owner for the given asset ID.
@@ -4717,10 +5132,10 @@ Supported fuel-core version: ${supportedVersion}.`
4717
5132
  */
4718
5133
  async getBalance(owner, assetId) {
4719
5134
  const { balance } = await this.operations.getBalance({
4720
- owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4721
- assetId: (0, import_utils23.hexlify)(assetId)
5135
+ owner: import_address4.Address.fromAddressOrString(owner).toB256(),
5136
+ assetId: (0, import_utils26.hexlify)(assetId)
4722
5137
  });
4723
- return (0, import_math17.bn)(balance.amount, 10);
5138
+ return (0, import_math18.bn)(balance.amount, 10);
4724
5139
  }
4725
5140
  /**
4726
5141
  * Returns balances for the given owner.
@@ -4738,11 +5153,11 @@ Supported fuel-core version: ${supportedVersion}.`
4738
5153
  * but the current Fuel-Core implementation does not support pagination yet.
4739
5154
  */
4740
5155
  first: 1e4,
4741
- filter: { owner: import_address3.Address.fromAddressOrString(owner).toB256() }
5156
+ filter: { owner: import_address4.Address.fromAddressOrString(owner).toB256() }
4742
5157
  });
4743
5158
  const balances = edges.map(({ node }) => ({
4744
5159
  assetId: node.assetId,
4745
- amount: (0, import_math17.bn)(node.amount)
5160
+ amount: (0, import_math18.bn)(node.amount)
4746
5161
  }));
4747
5162
  return { balances };
4748
5163
  }
@@ -4761,22 +5176,22 @@ Supported fuel-core version: ${supportedVersion}.`
4761
5176
  inputArgs: paginationArgs,
4762
5177
  paginationLimit: RESOURCES_PAGE_SIZE_LIMIT
4763
5178
  }),
4764
- owner: import_address3.Address.fromAddressOrString(address).toB256()
5179
+ owner: import_address4.Address.fromAddressOrString(address).toB256()
4765
5180
  });
4766
5181
  const messages = edges.map(({ node }) => ({
4767
5182
  messageId: import_transactions20.InputMessageCoder.getMessageId({
4768
5183
  sender: node.sender,
4769
5184
  recipient: node.recipient,
4770
5185
  nonce: node.nonce,
4771
- amount: (0, import_math17.bn)(node.amount),
5186
+ amount: (0, import_math18.bn)(node.amount),
4772
5187
  data: node.data
4773
5188
  }),
4774
- sender: import_address3.Address.fromAddressOrString(node.sender),
4775
- recipient: import_address3.Address.fromAddressOrString(node.recipient),
5189
+ sender: import_address4.Address.fromAddressOrString(node.sender),
5190
+ recipient: import_address4.Address.fromAddressOrString(node.recipient),
4776
5191
  nonce: node.nonce,
4777
- amount: (0, import_math17.bn)(node.amount),
5192
+ amount: (0, import_math18.bn)(node.amount),
4778
5193
  data: import_transactions20.InputMessageCoder.decodeData(node.data),
4779
- daHeight: (0, import_math17.bn)(node.daHeight)
5194
+ daHeight: (0, import_math18.bn)(node.daHeight)
4780
5195
  }));
4781
5196
  return {
4782
5197
  messages,
@@ -4798,8 +5213,8 @@ Supported fuel-core version: ${supportedVersion}.`
4798
5213
  nonce
4799
5214
  };
4800
5215
  if (commitBlockId && commitBlockHeight) {
4801
- throw new import_errors14.FuelError(
4802
- import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5216
+ throw new import_errors16.FuelError(
5217
+ import_errors16.ErrorCode.INVALID_INPUT_PARAMETERS,
4803
5218
  "commitBlockId and commitBlockHeight cannot be used together"
4804
5219
  );
4805
5220
  }
@@ -4833,19 +5248,19 @@ Supported fuel-core version: ${supportedVersion}.`
4833
5248
  } = result.messageProof;
4834
5249
  return {
4835
5250
  messageProof: {
4836
- proofIndex: (0, import_math17.bn)(messageProof.proofIndex),
5251
+ proofIndex: (0, import_math18.bn)(messageProof.proofIndex),
4837
5252
  proofSet: messageProof.proofSet
4838
5253
  },
4839
5254
  blockProof: {
4840
- proofIndex: (0, import_math17.bn)(blockProof.proofIndex),
5255
+ proofIndex: (0, import_math18.bn)(blockProof.proofIndex),
4841
5256
  proofSet: blockProof.proofSet
4842
5257
  },
4843
5258
  messageBlockHeader: {
4844
5259
  id: messageBlockHeader.id,
4845
- daHeight: (0, import_math17.bn)(messageBlockHeader.daHeight),
5260
+ daHeight: (0, import_math18.bn)(messageBlockHeader.daHeight),
4846
5261
  transactionsCount: Number(messageBlockHeader.transactionsCount),
4847
5262
  transactionsRoot: messageBlockHeader.transactionsRoot,
4848
- height: (0, import_math17.bn)(messageBlockHeader.height),
5263
+ height: (0, import_math18.bn)(messageBlockHeader.height),
4849
5264
  prevRoot: messageBlockHeader.prevRoot,
4850
5265
  time: messageBlockHeader.time,
4851
5266
  applicationHash: messageBlockHeader.applicationHash,
@@ -4857,10 +5272,10 @@ Supported fuel-core version: ${supportedVersion}.`
4857
5272
  },
4858
5273
  commitBlockHeader: {
4859
5274
  id: commitBlockHeader.id,
4860
- daHeight: (0, import_math17.bn)(commitBlockHeader.daHeight),
5275
+ daHeight: (0, import_math18.bn)(commitBlockHeader.daHeight),
4861
5276
  transactionsCount: Number(commitBlockHeader.transactionsCount),
4862
5277
  transactionsRoot: commitBlockHeader.transactionsRoot,
4863
- height: (0, import_math17.bn)(commitBlockHeader.height),
5278
+ height: (0, import_math18.bn)(commitBlockHeader.height),
4864
5279
  prevRoot: commitBlockHeader.prevRoot,
4865
5280
  time: commitBlockHeader.time,
4866
5281
  applicationHash: commitBlockHeader.applicationHash,
@@ -4870,10 +5285,10 @@ Supported fuel-core version: ${supportedVersion}.`
4870
5285
  eventInboxRoot: commitBlockHeader.eventInboxRoot,
4871
5286
  stateTransitionBytecodeVersion: Number(commitBlockHeader.stateTransitionBytecodeVersion)
4872
5287
  },
4873
- sender: import_address3.Address.fromAddressOrString(sender),
4874
- recipient: import_address3.Address.fromAddressOrString(recipient),
5288
+ sender: import_address4.Address.fromAddressOrString(sender),
5289
+ recipient: import_address4.Address.fromAddressOrString(recipient),
4875
5290
  nonce,
4876
- amount: (0, import_math17.bn)(amount),
5291
+ amount: (0, import_math18.bn)(amount),
4877
5292
  data
4878
5293
  };
4879
5294
  }
@@ -4884,7 +5299,7 @@ Supported fuel-core version: ${supportedVersion}.`
4884
5299
  */
4885
5300
  async getLatestGasPrice() {
4886
5301
  const { latestGasPrice } = await this.operations.getLatestGasPrice();
4887
- return (0, import_math17.bn)(latestGasPrice.gasPrice);
5302
+ return (0, import_math18.bn)(latestGasPrice.gasPrice);
4888
5303
  }
4889
5304
  /**
4890
5305
  * Returns the estimate gas price for the given block horizon.
@@ -4896,7 +5311,7 @@ Supported fuel-core version: ${supportedVersion}.`
4896
5311
  const { estimateGasPrice } = await this.operations.estimateGasPrice({
4897
5312
  blockHorizon: String(blockHorizon)
4898
5313
  });
4899
- return (0, import_math17.bn)(estimateGasPrice.gasPrice);
5314
+ return (0, import_math18.bn)(estimateGasPrice.gasPrice);
4900
5315
  }
4901
5316
  /**
4902
5317
  * Returns Message Proof for given transaction id and the message id from MessageOut receipt.
@@ -4917,10 +5332,10 @@ Supported fuel-core version: ${supportedVersion}.`
4917
5332
  */
4918
5333
  async produceBlocks(amount, startTime) {
4919
5334
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4920
- blocksToProduce: (0, import_math17.bn)(amount).toString(10),
4921
- startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
5335
+ blocksToProduce: (0, import_math18.bn)(amount).toString(10),
5336
+ startTimestamp: startTime ? import_utils26.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4922
5337
  });
4923
- return (0, import_math17.bn)(latestBlockHeight);
5338
+ return (0, import_math18.bn)(latestBlockHeight);
4924
5339
  }
4925
5340
  /**
4926
5341
  * Get the transaction response for the given transaction ID.
@@ -4967,26 +5382,26 @@ Supported fuel-core version: ${supportedVersion}.`
4967
5382
  const { paginationLimit, inputArgs = {} } = params;
4968
5383
  const { first, last, after, before } = inputArgs;
4969
5384
  if (after && before) {
4970
- throw new import_errors14.FuelError(
4971
- import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5385
+ throw new import_errors16.FuelError(
5386
+ import_errors16.ErrorCode.INVALID_INPUT_PARAMETERS,
4972
5387
  'Pagination arguments "after" and "before" cannot be used together'
4973
5388
  );
4974
5389
  }
4975
5390
  if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
4976
- throw new import_errors14.FuelError(
4977
- import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5391
+ throw new import_errors16.FuelError(
5392
+ import_errors16.ErrorCode.INVALID_INPUT_PARAMETERS,
4978
5393
  `Pagination limit for this query cannot exceed ${paginationLimit} items`
4979
5394
  );
4980
5395
  }
4981
5396
  if (first && before) {
4982
- throw new import_errors14.FuelError(
4983
- import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5397
+ throw new import_errors16.FuelError(
5398
+ import_errors16.ErrorCode.INVALID_INPUT_PARAMETERS,
4984
5399
  'The use of pagination argument "first" with "before" is not supported'
4985
5400
  );
4986
5401
  }
4987
5402
  if (last && after) {
4988
- throw new import_errors14.FuelError(
4989
- import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
5403
+ throw new import_errors16.FuelError(
5404
+ import_errors16.ErrorCode.INVALID_INPUT_PARAMETERS,
4990
5405
  'The use of pagination argument "last" with "after" is not supported'
4991
5406
  );
4992
5407
  }
@@ -5017,15 +5432,22 @@ Supported fuel-core version: ${supportedVersion}.`
5017
5432
  };
5018
5433
  var Provider = _Provider;
5019
5434
  _cacheInputs = new WeakSet();
5020
- cacheInputs_fn = function(inputs) {
5435
+ cacheInputs_fn = function(inputs, transactionId) {
5021
5436
  if (!this.cache) {
5022
5437
  return;
5023
5438
  }
5024
- inputs.forEach((input) => {
5025
- if (input.type === import_transactions20.InputType.Coin) {
5026
- this.cache?.set(input.id);
5027
- }
5028
- });
5439
+ const inputsToCache = inputs.reduce(
5440
+ (acc, input) => {
5441
+ if (input.type === import_transactions20.InputType.Coin) {
5442
+ acc.utxos.push(input.id);
5443
+ } else if (input.type === import_transactions20.InputType.Message) {
5444
+ acc.messages.push(input.nonce);
5445
+ }
5446
+ return acc;
5447
+ },
5448
+ { utxos: [], messages: [] }
5449
+ );
5450
+ this.cache.set(transactionId, inputsToCache);
5029
5451
  };
5030
5452
  /** @hidden */
5031
5453
  __publicField(Provider, "chainInfoCache", {});
@@ -5033,10 +5455,10 @@ __publicField(Provider, "chainInfoCache", {});
5033
5455
  __publicField(Provider, "nodeInfoCache", {});
5034
5456
 
5035
5457
  // src/providers/transaction-summary/get-transaction-summary.ts
5036
- var import_errors15 = require("@fuel-ts/errors");
5037
- var import_math18 = require("@fuel-ts/math");
5458
+ var import_errors17 = require("@fuel-ts/errors");
5459
+ var import_math19 = require("@fuel-ts/math");
5038
5460
  var import_transactions21 = require("@fuel-ts/transactions");
5039
- var import_utils26 = require("@fuel-ts/utils");
5461
+ var import_utils29 = require("@fuel-ts/utils");
5040
5462
 
5041
5463
  // src/providers/chains.ts
5042
5464
  var CHAIN_IDS = {
@@ -5109,19 +5531,75 @@ var rawAssets = [
5109
5531
  ];
5110
5532
  var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
5111
5533
 
5534
+ // src/test-utils/test-asset-id.ts
5535
+ var import_crypto4 = require("@fuel-ts/crypto");
5536
+ var import_utils31 = require("@fuel-ts/utils");
5537
+ var _TestAssetId = class {
5538
+ constructor(value) {
5539
+ this.value = value;
5540
+ }
5541
+ static random(count = 1) {
5542
+ const assetIds = [];
5543
+ for (let i = 0; i < count; i++) {
5544
+ assetIds.push(new _TestAssetId((0, import_utils31.hexlify)((0, import_crypto4.randomBytes)(32))));
5545
+ }
5546
+ return assetIds;
5547
+ }
5548
+ };
5549
+ var TestAssetId = _TestAssetId;
5550
+ __publicField(TestAssetId, "A", new _TestAssetId(
5551
+ "0x0101010101010101010101010101010101010101010101010101010101010101"
5552
+ ));
5553
+ __publicField(TestAssetId, "B", new _TestAssetId(
5554
+ "0x0202020202020202020202020202020202020202020202020202020202020202"
5555
+ ));
5556
+
5557
+ // src/test-utils/wallet-config.ts
5558
+ var import_crypto9 = require("@fuel-ts/crypto");
5559
+ var import_errors23 = require("@fuel-ts/errors");
5560
+ var import_utils40 = require("@fuel-ts/utils");
5561
+
5562
+ // src/wallet/base-wallet-unlocked.ts
5563
+ var import_hasher3 = require("@fuel-ts/hasher");
5564
+ var import_utils35 = require("@fuel-ts/utils");
5565
+
5566
+ // src/account.ts
5567
+ var import_abi_coder8 = require("@fuel-ts/abi-coder");
5568
+ var import_address5 = require("@fuel-ts/address");
5569
+ var import_crypto5 = require("@fuel-ts/crypto");
5570
+ var import_errors18 = require("@fuel-ts/errors");
5571
+ var import_interfaces = require("@fuel-ts/interfaces");
5572
+ var import_math21 = require("@fuel-ts/math");
5573
+ var import_utils33 = require("@fuel-ts/utils");
5574
+ var import_ramda4 = require("ramda");
5575
+
5576
+ // src/providers/utils/merge-quantities.ts
5577
+ var mergeQuantities = (...coinQuantities) => {
5578
+ const resultMap = {};
5579
+ function addToMap({ amount, assetId }) {
5580
+ if (resultMap[assetId]) {
5581
+ resultMap[assetId] = resultMap[assetId].add(amount);
5582
+ } else {
5583
+ resultMap[assetId] = amount;
5584
+ }
5585
+ }
5586
+ coinQuantities.forEach((arr) => arr.forEach(addToMap));
5587
+ return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
5588
+ };
5589
+
5112
5590
  // src/utils/formatTransferToContractScriptData.ts
5113
- var import_abi_coder6 = require("@fuel-ts/abi-coder");
5114
- var import_math19 = require("@fuel-ts/math");
5115
- var import_utils28 = require("@fuel-ts/utils");
5591
+ var import_abi_coder7 = require("@fuel-ts/abi-coder");
5592
+ var import_math20 = require("@fuel-ts/math");
5593
+ var import_utils32 = require("@fuel-ts/utils");
5116
5594
  var asm = __toESM(require("@fuels/vm-asm"));
5117
5595
  var formatTransferToContractScriptData = (params) => {
5118
5596
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
5119
- const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
5120
- const encoded = numberCoder.encode(new import_math19.BN(amountToTransfer).toNumber());
5597
+ const numberCoder = new import_abi_coder7.BigNumberCoder("u64");
5598
+ const encoded = numberCoder.encode(new import_math20.BN(amountToTransfer).toNumber());
5121
5599
  const scriptData = Uint8Array.from([
5122
- ...(0, import_utils28.arrayify)(hexlifiedContractId),
5600
+ ...(0, import_utils32.arrayify)(hexlifiedContractId),
5123
5601
  ...encoded,
5124
- ...(0, import_utils28.arrayify)(assetId)
5602
+ ...(0, import_utils32.arrayify)(assetId)
5125
5603
  ]);
5126
5604
  return scriptData;
5127
5605
  };
@@ -5146,7 +5624,7 @@ var assembleTransferToContractScript = async (params) => {
5146
5624
  };
5147
5625
 
5148
5626
  // src/account.ts
5149
- var MAX_FUNDING_ATTEMPTS = 2;
5627
+ var MAX_FUNDING_ATTEMPTS = 5;
5150
5628
  var Account = class extends import_interfaces.AbstractAccount {
5151
5629
  /**
5152
5630
  * The address associated with the account.
@@ -5171,7 +5649,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5171
5649
  super();
5172
5650
  this._provider = provider;
5173
5651
  this._connector = connector;
5174
- this.address = import_address4.Address.fromDynamicInput(address);
5652
+ this.address = import_address5.Address.fromDynamicInput(address);
5175
5653
  }
5176
5654
  /**
5177
5655
  * The provider used to interact with the network.
@@ -5182,7 +5660,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5182
5660
  */
5183
5661
  get provider() {
5184
5662
  if (!this._provider) {
5185
- throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_PROVIDER, "Provider not set");
5663
+ throw new import_errors18.FuelError(import_errors18.ErrorCode.MISSING_PROVIDER, "Provider not set");
5186
5664
  }
5187
5665
  return this._provider;
5188
5666
  }
@@ -5259,12 +5737,12 @@ var Account = class extends import_interfaces.AbstractAccount {
5259
5737
  * @returns A promise that resolves to the funded transaction request.
5260
5738
  */
5261
5739
  async fund(request, params) {
5262
- const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee } = params;
5740
+ const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee, gasPrice } = params;
5263
5741
  const fee = request.maxFee;
5264
5742
  const baseAssetId = this.provider.getBaseAssetId();
5265
- const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math20.bn)(0);
5743
+ const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math21.bn)(0);
5266
5744
  const requiredQuantitiesWithFee = addAmountToCoinQuantities({
5267
- amount: (0, import_math20.bn)(fee),
5745
+ amount: (0, import_math21.bn)(fee),
5268
5746
  assetId: baseAssetId,
5269
5747
  coinQuantities: requiredQuantities
5270
5748
  });
@@ -5272,7 +5750,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5272
5750
  requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
5273
5751
  quantitiesDict[assetId] = {
5274
5752
  required: amount,
5275
- owned: (0, import_math20.bn)(0)
5753
+ owned: (0, import_math21.bn)(0)
5276
5754
  };
5277
5755
  });
5278
5756
  request.inputs.filter(isRequestInputResource).forEach((input) => {
@@ -5307,10 +5785,12 @@ var Account = class extends import_interfaces.AbstractAccount {
5307
5785
  );
5308
5786
  }
5309
5787
  if (!updateMaxFee) {
5788
+ needsToBeFunded = false;
5310
5789
  break;
5311
5790
  }
5312
5791
  const { maxFee: newFee } = await this.provider.estimateTxGasAndFee({
5313
- transactionRequest: requestToReestimate2
5792
+ transactionRequest: requestToReestimate2,
5793
+ gasPrice
5314
5794
  });
5315
5795
  const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
5316
5796
  request.inputs,
@@ -5330,6 +5810,12 @@ var Account = class extends import_interfaces.AbstractAccount {
5330
5810
  }
5331
5811
  fundingAttempts += 1;
5332
5812
  }
5813
+ if (needsToBeFunded) {
5814
+ throw new import_errors18.FuelError(
5815
+ import_errors18.ErrorCode.NOT_ENOUGH_FUNDS,
5816
+ `The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
5817
+ );
5818
+ }
5333
5819
  request.updatePredicateGasUsed(estimatedPredicates);
5334
5820
  const requestToReestimate = (0, import_ramda4.clone)(request);
5335
5821
  if (addedSignatures) {
@@ -5396,7 +5882,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5396
5882
  const { destination, amount, assetId } = transferParams;
5397
5883
  this.validateTransferAmount(amount);
5398
5884
  request.addCoinOutput(
5399
- import_address4.Address.fromAddressOrString(destination),
5885
+ import_address5.Address.fromAddressOrString(destination),
5400
5886
  amount,
5401
5887
  assetId ?? this.provider.getBaseAssetId()
5402
5888
  );
@@ -5430,17 +5916,17 @@ var Account = class extends import_interfaces.AbstractAccount {
5430
5916
  * @returns A promise that resolves to the transaction response.
5431
5917
  */
5432
5918
  async transferToContract(contractId, amount, assetId, txParams = {}) {
5433
- if ((0, import_math20.bn)(amount).lte(0)) {
5434
- throw new import_errors16.FuelError(
5435
- import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
5919
+ if ((0, import_math21.bn)(amount).lte(0)) {
5920
+ throw new import_errors18.FuelError(
5921
+ import_errors18.ErrorCode.INVALID_TRANSFER_AMOUNT,
5436
5922
  "Transfer amount must be a positive number."
5437
5923
  );
5438
5924
  }
5439
- const contractAddress = import_address4.Address.fromAddressOrString(contractId);
5925
+ const contractAddress = import_address5.Address.fromAddressOrString(contractId);
5440
5926
  const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
5441
5927
  const { script, scriptData } = await assembleTransferToContractScript({
5442
5928
  hexlifiedContractId: contractAddress.toB256(),
5443
- amountToTransfer: (0, import_math20.bn)(amount),
5929
+ amountToTransfer: (0, import_math21.bn)(amount),
5444
5930
  assetId: assetIdToTransfer
5445
5931
  });
5446
5932
  let request = new ScriptTransactionRequest({
@@ -5449,9 +5935,8 @@ var Account = class extends import_interfaces.AbstractAccount {
5449
5935
  scriptData
5450
5936
  });
5451
5937
  request.addContractInputAndOutput(contractAddress);
5452
- const txCost = await this.provider.getTransactionCost(request, {
5453
- resourcesOwner: this,
5454
- quantitiesToContract: [{ amount: (0, import_math20.bn)(amount), assetId: String(assetIdToTransfer) }]
5938
+ const txCost = await this.getTransactionCost(request, {
5939
+ quantities: [{ amount: (0, import_math21.bn)(amount), assetId: String(assetIdToTransfer) }]
5455
5940
  });
5456
5941
  request = this.validateGasLimitAndMaxFee({
5457
5942
  transactionRequest: request,
@@ -5471,23 +5956,23 @@ var Account = class extends import_interfaces.AbstractAccount {
5471
5956
  * @returns A promise that resolves to the transaction response.
5472
5957
  */
5473
5958
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5474
- const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5475
- const recipientDataArray = (0, import_utils29.arrayify)(
5959
+ const recipientAddress = import_address5.Address.fromAddressOrString(recipient);
5960
+ const recipientDataArray = (0, import_utils33.arrayify)(
5476
5961
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5477
5962
  );
5478
- const amountDataArray = (0, import_utils29.arrayify)(
5479
- "0x".concat((0, import_math20.bn)(amount).toHex().substring(2).padStart(16, "0"))
5963
+ const amountDataArray = (0, import_utils33.arrayify)(
5964
+ "0x".concat((0, import_math21.bn)(amount).toHex().substring(2).padStart(16, "0"))
5480
5965
  );
5481
5966
  const script = new Uint8Array([
5482
- ...(0, import_utils29.arrayify)(withdrawScript.bytes),
5967
+ ...(0, import_utils33.arrayify)(withdrawScript.bytes),
5483
5968
  ...recipientDataArray,
5484
5969
  ...amountDataArray
5485
5970
  ]);
5486
5971
  const params = { script, ...txParams };
5487
5972
  const baseAssetId = this.provider.getBaseAssetId();
5488
5973
  let request = new ScriptTransactionRequest(params);
5489
- const quantitiesToContract = [{ amount: (0, import_math20.bn)(amount), assetId: baseAssetId }];
5490
- const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
5974
+ const quantities = [{ amount: (0, import_math21.bn)(amount), assetId: baseAssetId }];
5975
+ const txCost = await this.getTransactionCost(request, { quantities });
5491
5976
  request = this.validateGasLimitAndMaxFee({
5492
5977
  transactionRequest: request,
5493
5978
  gasUsed: txCost.gasUsed,
@@ -5497,6 +5982,34 @@ var Account = class extends import_interfaces.AbstractAccount {
5497
5982
  await this.fund(request, txCost);
5498
5983
  return this.sendTransaction(request);
5499
5984
  }
5985
+ /**
5986
+ * Returns a transaction cost to enable user
5987
+ * to set gasLimit and also reserve balance amounts
5988
+ * on the transaction.
5989
+ *
5990
+ * @param transactionRequestLike - The transaction request object.
5991
+ * @param transactionCostParams - The transaction cost parameters (optional).
5992
+ *
5993
+ * @returns A promise that resolves to the transaction cost object.
5994
+ */
5995
+ async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [] } = {}) {
5996
+ const txRequestClone = (0, import_ramda4.clone)(transactionRequestify(transactionRequestLike));
5997
+ const baseAssetId = this.provider.getBaseAssetId();
5998
+ const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
5999
+ const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
6000
+ const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math21.bn)("100000000000000000") }];
6001
+ const resources = this.generateFakeResources(
6002
+ mergeQuantities(requiredQuantities, transactionFeeForDryRun)
6003
+ );
6004
+ txRequestClone.addResources(resources);
6005
+ const txCost = await this.provider.getTransactionCost(txRequestClone, {
6006
+ signatureCallback
6007
+ });
6008
+ return {
6009
+ ...txCost,
6010
+ requiredQuantities
6011
+ };
6012
+ }
5500
6013
  /**
5501
6014
  * Sign a message from the account via the connector.
5502
6015
  *
@@ -5507,7 +6020,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5507
6020
  */
5508
6021
  async signMessage(message) {
5509
6022
  if (!this._connector) {
5510
- throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
6023
+ throw new import_errors18.FuelError(import_errors18.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
5511
6024
  }
5512
6025
  return this._connector.signMessage(this.address.toString(), message);
5513
6026
  }
@@ -5519,8 +6032,8 @@ var Account = class extends import_interfaces.AbstractAccount {
5519
6032
  */
5520
6033
  async signTransaction(transactionRequestLike) {
5521
6034
  if (!this._connector) {
5522
- throw new import_errors16.FuelError(
5523
- import_errors16.ErrorCode.MISSING_CONNECTOR,
6035
+ throw new import_errors18.FuelError(
6036
+ import_errors18.ErrorCode.MISSING_CONNECTOR,
5524
6037
  "A connector is required to sign transactions."
5525
6038
  );
5526
6039
  }
@@ -5533,7 +6046,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5533
6046
  * @param sendTransactionParams - The provider send transaction parameters (optional).
5534
6047
  * @returns A promise that resolves to the transaction response.
5535
6048
  */
5536
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
6049
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
5537
6050
  if (this._connector) {
5538
6051
  return this.provider.getTransactionResponse(
5539
6052
  await this._connector.sendTransaction(this.address.toString(), transactionRequestLike)
@@ -5544,7 +6057,6 @@ var Account = class extends import_interfaces.AbstractAccount {
5544
6057
  await this.provider.estimateTxDependencies(transactionRequest);
5545
6058
  }
5546
6059
  return this.provider.sendTransaction(transactionRequest, {
5547
- awaitExecution,
5548
6060
  estimateTxDependencies: false
5549
6061
  });
5550
6062
  }
@@ -5570,18 +6082,18 @@ var Account = class extends import_interfaces.AbstractAccount {
5570
6082
  */
5571
6083
  generateFakeResources(coins) {
5572
6084
  return coins.map((coin) => ({
5573
- id: (0, import_utils29.hexlify)((0, import_crypto2.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
6085
+ id: (0, import_utils33.hexlify)((0, import_crypto5.randomBytes)(import_abi_coder8.UTXO_ID_LEN)),
5574
6086
  owner: this.address,
5575
- blockCreated: (0, import_math20.bn)(1),
5576
- txCreatedIdx: (0, import_math20.bn)(1),
6087
+ blockCreated: (0, import_math21.bn)(1),
6088
+ txCreatedIdx: (0, import_math21.bn)(1),
5577
6089
  ...coin
5578
6090
  }));
5579
6091
  }
5580
6092
  /** @hidden * */
5581
6093
  validateTransferAmount(amount) {
5582
- if ((0, import_math20.bn)(amount).lte(0)) {
5583
- throw new import_errors16.FuelError(
5584
- import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
6094
+ if ((0, import_math21.bn)(amount).lte(0)) {
6095
+ throw new import_errors18.FuelError(
6096
+ import_errors18.ErrorCode.INVALID_TRANSFER_AMOUNT,
5585
6097
  "Transfer amount must be a positive number."
5586
6098
  );
5587
6099
  }
@@ -5589,9 +6101,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5589
6101
  /** @hidden * */
5590
6102
  async estimateAndFundTransaction(transactionRequest, txParams) {
5591
6103
  let request = transactionRequest;
5592
- const txCost = await this.provider.getTransactionCost(request, {
5593
- resourcesOwner: this
5594
- });
6104
+ const txCost = await this.getTransactionCost(request);
5595
6105
  request = this.validateGasLimitAndMaxFee({
5596
6106
  transactionRequest: request,
5597
6107
  gasUsed: txCost.gasUsed,
@@ -5609,19 +6119,19 @@ var Account = class extends import_interfaces.AbstractAccount {
5609
6119
  txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
5610
6120
  }) {
5611
6121
  const request = transactionRequestify(transactionRequest);
5612
- if (!(0, import_utils29.isDefined)(setGasLimit)) {
6122
+ if (!(0, import_utils33.isDefined)(setGasLimit)) {
5613
6123
  request.gasLimit = gasUsed;
5614
6124
  } else if (gasUsed.gt(setGasLimit)) {
5615
- throw new import_errors16.FuelError(
5616
- import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
6125
+ throw new import_errors18.FuelError(
6126
+ import_errors18.ErrorCode.GAS_LIMIT_TOO_LOW,
5617
6127
  `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
5618
6128
  );
5619
6129
  }
5620
- if (!(0, import_utils29.isDefined)(setMaxFee)) {
6130
+ if (!(0, import_utils33.isDefined)(setMaxFee)) {
5621
6131
  request.maxFee = maxFee;
5622
6132
  } else if (maxFee.gt(setMaxFee)) {
5623
- throw new import_errors16.FuelError(
5624
- import_errors16.ErrorCode.MAX_FEE_TOO_LOW,
6133
+ throw new import_errors18.FuelError(
6134
+ import_errors18.ErrorCode.MAX_FEE_TOO_LOW,
5625
6135
  `Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
5626
6136
  );
5627
6137
  }
@@ -5629,121 +6139,11 @@ var Account = class extends import_interfaces.AbstractAccount {
5629
6139
  }
5630
6140
  };
5631
6141
 
5632
- // src/signer/signer.ts
5633
- var import_address5 = require("@fuel-ts/address");
5634
- var import_crypto3 = require("@fuel-ts/crypto");
5635
- var import_hasher2 = require("@fuel-ts/hasher");
5636
- var import_math21 = require("@fuel-ts/math");
5637
- var import_utils30 = require("@fuel-ts/utils");
5638
- var import_secp256k1 = require("@noble/curves/secp256k1");
5639
- var Signer = class {
5640
- address;
5641
- publicKey;
5642
- compressedPublicKey;
5643
- privateKey;
5644
- /**
5645
- * Create a Signer instance from a given private key
5646
- *
5647
- * @param privateKey - The private key to use for signing
5648
- * @returns A new Signer instance
5649
- */
5650
- constructor(privateKey) {
5651
- if (typeof privateKey === "string") {
5652
- if (privateKey.match(/^[0-9a-f]*$/i) && privateKey.length === 64) {
5653
- privateKey = `0x${privateKey}`;
5654
- }
5655
- }
5656
- const privateKeyBytes = (0, import_math21.toBytes)(privateKey, 32);
5657
- this.privateKey = (0, import_utils30.hexlify)(privateKeyBytes);
5658
- this.publicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5659
- this.compressedPublicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5660
- this.address = import_address5.Address.fromPublicKey(this.publicKey);
5661
- }
5662
- /**
5663
- * Sign data using the Signer instance
5664
- *
5665
- * Signature is a 64 byte array of the concatenated r and s values with the compressed recoveryParam byte.
5666
- * @ignore
5667
- * [Read more](FuelLabs/fuel-specs/specs/protocol/cryptographic_primitives.md#public-key-cryptography)
5668
- *
5669
- * @param data - The data to be sign
5670
- * @returns hashed signature
5671
- */
5672
- sign(data) {
5673
- const signature = import_secp256k1.secp256k1.sign((0, import_utils30.arrayify)(data), (0, import_utils30.arrayify)(this.privateKey));
5674
- const r = (0, import_math21.toBytes)(`0x${signature.r.toString(16)}`, 32);
5675
- const s = (0, import_math21.toBytes)(`0x${signature.s.toString(16)}`, 32);
5676
- s[0] |= (signature.recovery || 0) << 7;
5677
- return (0, import_utils30.hexlify)((0, import_utils30.concat)([r, s]));
5678
- }
5679
- /**
5680
- * Add point on the current elliptic curve
5681
- *
5682
- * @param point - Point to add on the curve
5683
- * @returns compressed point on the curve
5684
- */
5685
- addPoint(point) {
5686
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(this.compressedPublicKey));
5687
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(point));
5688
- const result = p0.add(p1);
5689
- return `0x${result.toHex(true)}`;
5690
- }
5691
- /**
5692
- * Recover the public key from a signature performed with [`sign`](#sign).
5693
- *
5694
- * @param data - Data
5695
- * @param signature - hashed signature
5696
- * @returns public key from signature from the
5697
- */
5698
- static recoverPublicKey(data, signature) {
5699
- const signedMessageBytes = (0, import_utils30.arrayify)(signature);
5700
- const r = signedMessageBytes.slice(0, 32);
5701
- const s = signedMessageBytes.slice(32, 64);
5702
- const recoveryParam = (s[0] & 128) >> 7;
5703
- s[0] &= 127;
5704
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils30.hexlify)(r)), BigInt((0, import_utils30.hexlify)(s))).addRecoveryBit(
5705
- recoveryParam
5706
- );
5707
- const publicKey = sig.recoverPublicKey((0, import_utils30.arrayify)(data)).toRawBytes(false).slice(1);
5708
- return (0, import_utils30.hexlify)(publicKey);
5709
- }
5710
- /**
5711
- * Recover the address from a signature performed with [`sign`](#sign).
5712
- *
5713
- * @param data - Data
5714
- * @param signature - Signature
5715
- * @returns Address from signature
5716
- */
5717
- static recoverAddress(data, signature) {
5718
- return import_address5.Address.fromPublicKey(Signer.recoverPublicKey(data, signature));
5719
- }
5720
- /**
5721
- * Generate a random privateKey
5722
- *
5723
- * @param entropy - Adds extra entropy to generate the privateKey
5724
- * @returns random 32-byte hashed
5725
- */
5726
- static generatePrivateKey(entropy) {
5727
- return entropy ? (0, import_hasher2.hash)((0, import_utils30.concat)([(0, import_crypto3.randomBytes)(32), (0, import_utils30.arrayify)(entropy)])) : (0, import_crypto3.randomBytes)(32);
5728
- }
5729
- /**
5730
- * Extended publicKey from a compact publicKey
5731
- *
5732
- * @param publicKey - Compact publicKey
5733
- * @returns extended publicKey
5734
- */
5735
- static extendPublicKey(publicKey) {
5736
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(publicKey));
5737
- return (0, import_utils30.hexlify)(point.toRawBytes(false).slice(1));
5738
- }
5739
- };
5740
-
5741
6142
  // src/wallet/keystore-wallet.ts
5742
6143
  var import_address6 = require("@fuel-ts/address");
5743
- var import_crypto4 = require("@fuel-ts/crypto");
5744
- var import_errors17 = require("@fuel-ts/errors");
5745
- var import_utils31 = require("@fuel-ts/utils");
5746
- var import_uuid = require("uuid");
6144
+ var import_crypto6 = require("@fuel-ts/crypto");
6145
+ var import_errors19 = require("@fuel-ts/errors");
6146
+ var import_utils34 = require("@fuel-ts/utils");
5747
6147
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5748
6148
  var DEFAULT_KDF_PARAMS_R = 8;
5749
6149
  var DEFAULT_KDF_PARAMS_P = 1;
@@ -5756,38 +6156,38 @@ var removeHexPrefix = (hexString) => {
5756
6156
  return hexString;
5757
6157
  };
5758
6158
  async function encryptKeystoreWallet(privateKey, address, password) {
5759
- const privateKeyBuffer = (0, import_crypto4.bufferFromString)(removeHexPrefix(privateKey), "hex");
6159
+ const privateKeyBuffer = (0, import_crypto6.bufferFromString)(removeHexPrefix(privateKey), "hex");
5760
6160
  const ownerAddress = import_address6.Address.fromAddressOrString(address);
5761
- const salt = (0, import_crypto4.randomBytes)(DEFAULT_KEY_SIZE);
5762
- const key = (0, import_crypto4.scrypt)({
5763
- password: (0, import_crypto4.bufferFromString)(password),
6161
+ const salt = (0, import_crypto6.randomBytes)(DEFAULT_KEY_SIZE);
6162
+ const key = (0, import_crypto6.scrypt)({
6163
+ password: (0, import_crypto6.bufferFromString)(password),
5764
6164
  salt,
5765
6165
  dklen: DEFAULT_KEY_SIZE,
5766
6166
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5767
6167
  r: DEFAULT_KDF_PARAMS_R,
5768
6168
  p: DEFAULT_KDF_PARAMS_P
5769
6169
  });
5770
- const iv = (0, import_crypto4.randomBytes)(DEFAULT_IV_SIZE);
5771
- const ciphertext = await (0, import_crypto4.encryptJsonWalletData)(privateKeyBuffer, key, iv);
6170
+ const iv = (0, import_crypto6.randomBytes)(DEFAULT_IV_SIZE);
6171
+ const ciphertext = await (0, import_crypto6.encryptJsonWalletData)(privateKeyBuffer, key, iv);
5772
6172
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
5773
- const macHashUint8Array = (0, import_crypto4.keccak256)(data);
5774
- const mac = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
6173
+ const macHashUint8Array = (0, import_crypto6.keccak256)(data);
6174
+ const mac = (0, import_crypto6.stringFromBuffer)(macHashUint8Array, "hex");
5775
6175
  const keystore = {
5776
- id: (0, import_uuid.v4)(),
6176
+ id: (0, import_crypto6.randomUUID)(),
5777
6177
  version: 3,
5778
6178
  address: removeHexPrefix(ownerAddress.toHexString()),
5779
6179
  crypto: {
5780
6180
  cipher: "aes-128-ctr",
5781
6181
  mac,
5782
- cipherparams: { iv: (0, import_crypto4.stringFromBuffer)(iv, "hex") },
5783
- ciphertext: (0, import_crypto4.stringFromBuffer)(ciphertext, "hex"),
6182
+ cipherparams: { iv: (0, import_crypto6.stringFromBuffer)(iv, "hex") },
6183
+ ciphertext: (0, import_crypto6.stringFromBuffer)(ciphertext, "hex"),
5784
6184
  kdf: "scrypt",
5785
6185
  kdfparams: {
5786
6186
  dklen: DEFAULT_KEY_SIZE,
5787
6187
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5788
6188
  p: DEFAULT_KDF_PARAMS_P,
5789
6189
  r: DEFAULT_KDF_PARAMS_R,
5790
- salt: (0, import_crypto4.stringFromBuffer)(salt, "hex")
6190
+ salt: (0, import_crypto6.stringFromBuffer)(salt, "hex")
5791
6191
  }
5792
6192
  }
5793
6193
  };
@@ -5803,11 +6203,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5803
6203
  kdfparams: { dklen, n, r, p, salt }
5804
6204
  }
5805
6205
  } = keystoreWallet;
5806
- const ciphertextBuffer = (0, import_crypto4.bufferFromString)(ciphertext, "hex");
5807
- const ivBuffer = (0, import_crypto4.bufferFromString)(iv, "hex");
5808
- const saltBuffer = (0, import_crypto4.bufferFromString)(salt, "hex");
5809
- const passwordBuffer = (0, import_crypto4.bufferFromString)(password);
5810
- const key = (0, import_crypto4.scrypt)({
6206
+ const ciphertextBuffer = (0, import_crypto6.bufferFromString)(ciphertext, "hex");
6207
+ const ivBuffer = (0, import_crypto6.bufferFromString)(iv, "hex");
6208
+ const saltBuffer = (0, import_crypto6.bufferFromString)(salt, "hex");
6209
+ const passwordBuffer = (0, import_crypto6.bufferFromString)(password);
6210
+ const key = (0, import_crypto6.scrypt)({
5811
6211
  password: passwordBuffer,
5812
6212
  salt: saltBuffer,
5813
6213
  n,
@@ -5816,16 +6216,16 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5816
6216
  dklen
5817
6217
  });
5818
6218
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
5819
- const macHashUint8Array = (0, import_crypto4.keccak256)(data);
5820
- const macHash = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
6219
+ const macHashUint8Array = (0, import_crypto6.keccak256)(data);
6220
+ const macHash = (0, import_crypto6.stringFromBuffer)(macHashUint8Array, "hex");
5821
6221
  if (mac !== macHash) {
5822
- throw new import_errors17.FuelError(
5823
- import_errors17.ErrorCode.INVALID_PASSWORD,
6222
+ throw new import_errors19.FuelError(
6223
+ import_errors19.ErrorCode.INVALID_PASSWORD,
5824
6224
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
5825
6225
  );
5826
6226
  }
5827
- const buffer = await (0, import_crypto4.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5828
- const privateKey = (0, import_utils31.hexlify)(buffer);
6227
+ const buffer = await (0, import_crypto6.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
6228
+ const privateKey = (0, import_utils34.hexlify)(buffer);
5829
6229
  return privateKey;
5830
6230
  }
5831
6231
 
@@ -5870,7 +6270,7 @@ var BaseWalletUnlocked = class extends Account {
5870
6270
  */
5871
6271
  async signMessage(message) {
5872
6272
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5873
- return (0, import_utils32.hexlify)(signedMessage);
6273
+ return (0, import_utils35.hexlify)(signedMessage);
5874
6274
  }
5875
6275
  /**
5876
6276
  * Signs a transaction with the wallet's private key.
@@ -5883,7 +6283,7 @@ var BaseWalletUnlocked = class extends Account {
5883
6283
  const chainId = this.provider.getChainId();
5884
6284
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5885
6285
  const signature = await this.signer().sign(hashedTransaction);
5886
- return (0, import_utils32.hexlify)(signature);
6286
+ return (0, import_utils35.hexlify)(signature);
5887
6287
  }
5888
6288
  /**
5889
6289
  * Populates a transaction with the witnesses signature.
@@ -5902,17 +6302,16 @@ var BaseWalletUnlocked = class extends Account {
5902
6302
  *
5903
6303
  * @param transactionRequestLike - The transaction request to send.
5904
6304
  * @param estimateTxDependencies - Whether to estimate the transaction dependencies.
5905
- * @param awaitExecution - Whether to wait for the transaction to be executed.
5906
6305
  * @returns A promise that resolves to the TransactionResponse object.
5907
6306
  */
5908
- async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
6307
+ async sendTransaction(transactionRequestLike, { estimateTxDependencies = false } = {}) {
5909
6308
  const transactionRequest = transactionRequestify(transactionRequestLike);
5910
6309
  if (estimateTxDependencies) {
5911
6310
  await this.provider.estimateTxDependencies(transactionRequest);
5912
6311
  }
5913
6312
  return this.provider.sendTransaction(
5914
6313
  await this.populateTransactionWitnessesSignature(transactionRequest),
5915
- { awaitExecution, estimateTxDependencies: false }
6314
+ { estimateTxDependencies: false }
5916
6315
  );
5917
6316
  }
5918
6317
  /**
@@ -5949,18 +6348,18 @@ var BaseWalletUnlocked = class extends Account {
5949
6348
  */
5950
6349
  __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5951
6350
 
5952
- // src/hdwallet/hdwallet.ts
5953
- var import_crypto6 = require("@fuel-ts/crypto");
5954
- var import_errors20 = require("@fuel-ts/errors");
6351
+ // src/hdwallet/hdwallet.ts
6352
+ var import_crypto8 = require("@fuel-ts/crypto");
6353
+ var import_errors22 = require("@fuel-ts/errors");
5955
6354
  var import_hasher6 = require("@fuel-ts/hasher");
5956
6355
  var import_math22 = require("@fuel-ts/math");
5957
- var import_utils36 = require("@fuel-ts/utils");
6356
+ var import_utils39 = require("@fuel-ts/utils");
5958
6357
 
5959
6358
  // src/mnemonic/mnemonic.ts
5960
- var import_crypto5 = require("@fuel-ts/crypto");
5961
- var import_errors19 = require("@fuel-ts/errors");
6359
+ var import_crypto7 = require("@fuel-ts/crypto");
6360
+ var import_errors21 = require("@fuel-ts/errors");
5962
6361
  var import_hasher5 = require("@fuel-ts/hasher");
5963
- var import_utils34 = require("@fuel-ts/utils");
6362
+ var import_utils37 = require("@fuel-ts/utils");
5964
6363
 
5965
6364
  // src/wordlists/words/english.ts
5966
6365
  var english = [
@@ -8015,9 +8414,9 @@ var english = [
8015
8414
  ];
8016
8415
 
8017
8416
  // src/mnemonic/utils.ts
8018
- var import_errors18 = require("@fuel-ts/errors");
8417
+ var import_errors20 = require("@fuel-ts/errors");
8019
8418
  var import_hasher4 = require("@fuel-ts/hasher");
8020
- var import_utils33 = require("@fuel-ts/utils");
8419
+ var import_utils36 = require("@fuel-ts/utils");
8021
8420
  function getLowerMask(bits) {
8022
8421
  return (1 << bits) - 1;
8023
8422
  }
@@ -8052,20 +8451,20 @@ function entropyToMnemonicIndices(entropy) {
8052
8451
  }
8053
8452
  }
8054
8453
  const checksumBits = entropy.length / 4;
8055
- const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
8454
+ const checksum = (0, import_utils36.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
8056
8455
  indices[indices.length - 1] <<= checksumBits;
8057
8456
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
8058
8457
  return indices;
8059
8458
  }
8060
8459
  function mnemonicWordsToEntropy(words, wordlist) {
8061
8460
  const size = Math.ceil(11 * words.length / 8);
8062
- const entropy = (0, import_utils33.arrayify)(new Uint8Array(size));
8461
+ const entropy = (0, import_utils36.arrayify)(new Uint8Array(size));
8063
8462
  let offset = 0;
8064
8463
  for (let i = 0; i < words.length; i += 1) {
8065
8464
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
8066
8465
  if (index === -1) {
8067
- throw new import_errors18.FuelError(
8068
- import_errors18.ErrorCode.INVALID_MNEMONIC,
8466
+ throw new import_errors20.FuelError(
8467
+ import_errors20.ErrorCode.INVALID_MNEMONIC,
8069
8468
  `Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
8070
8469
  );
8071
8470
  }
@@ -8079,10 +8478,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
8079
8478
  const entropyBits = 32 * words.length / 3;
8080
8479
  const checksumBits = words.length / 3;
8081
8480
  const checksumMask = getUpperMask(checksumBits);
8082
- const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
8481
+ const checksum = (0, import_utils36.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
8083
8482
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
8084
- throw new import_errors18.FuelError(
8085
- import_errors18.ErrorCode.INVALID_CHECKSUM,
8483
+ throw new import_errors20.FuelError(
8484
+ import_errors20.ErrorCode.INVALID_CHECKSUM,
8086
8485
  "Checksum validation failed for the provided mnemonic."
8087
8486
  );
8088
8487
  }
@@ -8090,22 +8489,22 @@ function mnemonicWordsToEntropy(words, wordlist) {
8090
8489
  }
8091
8490
 
8092
8491
  // src/mnemonic/mnemonic.ts
8093
- var MasterSecret = (0, import_utils34.toUtf8Bytes)("Bitcoin seed");
8492
+ var MasterSecret = (0, import_utils37.toUtf8Bytes)("Bitcoin seed");
8094
8493
  var MainnetPRV = "0x0488ade4";
8095
8494
  var TestnetPRV = "0x04358394";
8096
8495
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
8097
8496
  function assertWordList(wordlist) {
8098
8497
  if (wordlist.length !== 2048) {
8099
- throw new import_errors19.FuelError(
8100
- import_errors19.ErrorCode.INVALID_WORD_LIST,
8498
+ throw new import_errors21.FuelError(
8499
+ import_errors21.ErrorCode.INVALID_WORD_LIST,
8101
8500
  `Expected word list length of 2048, but got ${wordlist.length}.`
8102
8501
  );
8103
8502
  }
8104
8503
  }
8105
8504
  function assertEntropy(entropy) {
8106
8505
  if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
8107
- throw new import_errors19.FuelError(
8108
- import_errors19.ErrorCode.INVALID_ENTROPY,
8506
+ throw new import_errors21.FuelError(
8507
+ import_errors21.ErrorCode.INVALID_ENTROPY,
8109
8508
  `Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
8110
8509
  );
8111
8510
  }
@@ -8115,7 +8514,7 @@ function assertMnemonic(words) {
8115
8514
  const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
8116
8515
  ", "
8117
8516
  )}] words, but got ${words.length}.`;
8118
- throw new import_errors19.FuelError(import_errors19.ErrorCode.INVALID_MNEMONIC, errorMsg);
8517
+ throw new import_errors21.FuelError(import_errors21.ErrorCode.INVALID_MNEMONIC, errorMsg);
8119
8518
  }
8120
8519
  }
8121
8520
  var Mnemonic = class {
@@ -8154,7 +8553,7 @@ var Mnemonic = class {
8154
8553
  static mnemonicToEntropy(phrase, wordlist = english) {
8155
8554
  const words = getWords(phrase);
8156
8555
  assertMnemonic(words);
8157
- return (0, import_utils34.hexlify)(mnemonicWordsToEntropy(words, wordlist));
8556
+ return (0, import_utils37.hexlify)(mnemonicWordsToEntropy(words, wordlist));
8158
8557
  }
8159
8558
  /**
8160
8559
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -8162,7 +8561,7 @@ var Mnemonic = class {
8162
8561
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
8163
8562
  */
8164
8563
  static entropyToMnemonic(entropy, wordlist = english) {
8165
- const entropyBytes = (0, import_utils34.arrayify)(entropy);
8564
+ const entropyBytes = (0, import_utils37.arrayify)(entropy);
8166
8565
  assertWordList(wordlist);
8167
8566
  assertEntropy(entropyBytes);
8168
8567
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -8174,9 +8573,9 @@ var Mnemonic = class {
8174
8573
  */
8175
8574
  static mnemonicToSeed(phrase, passphrase = "") {
8176
8575
  assertMnemonic(getWords(phrase));
8177
- const phraseBytes = (0, import_utils34.toUtf8Bytes)(getPhrase(phrase));
8178
- const salt = (0, import_utils34.toUtf8Bytes)(`mnemonic${passphrase}`);
8179
- return (0, import_crypto5.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
8576
+ const phraseBytes = (0, import_utils37.toUtf8Bytes)(getPhrase(phrase));
8577
+ const salt = (0, import_utils37.toUtf8Bytes)(`mnemonic${passphrase}`);
8578
+ return (0, import_crypto7.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
8180
8579
  }
8181
8580
  /**
8182
8581
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -8231,14 +8630,14 @@ var Mnemonic = class {
8231
8630
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
8232
8631
  */
8233
8632
  static masterKeysFromSeed(seed) {
8234
- const seedArray = (0, import_utils34.arrayify)(seed);
8633
+ const seedArray = (0, import_utils37.arrayify)(seed);
8235
8634
  if (seedArray.length < 16 || seedArray.length > 64) {
8236
- throw new import_errors19.FuelError(
8237
- import_errors19.ErrorCode.INVALID_SEED,
8635
+ throw new import_errors21.FuelError(
8636
+ import_errors21.ErrorCode.INVALID_SEED,
8238
8637
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
8239
8638
  );
8240
8639
  }
8241
- return (0, import_utils34.arrayify)((0, import_crypto5.computeHmac)("sha512", MasterSecret, seedArray));
8640
+ return (0, import_utils37.arrayify)((0, import_crypto7.computeHmac)("sha512", MasterSecret, seedArray));
8242
8641
  }
8243
8642
  /**
8244
8643
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -8249,22 +8648,22 @@ var Mnemonic = class {
8249
8648
  */
8250
8649
  static seedToExtendedKey(seed, testnet = false) {
8251
8650
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
8252
- const prefix = (0, import_utils34.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8651
+ const prefix = (0, import_utils37.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8253
8652
  const depth = "0x00";
8254
8653
  const fingerprint = "0x00000000";
8255
8654
  const index = "0x00000000";
8256
8655
  const chainCode = masterKey.slice(32);
8257
8656
  const privateKey = masterKey.slice(0, 32);
8258
- const extendedKey = (0, import_utils34.concat)([
8657
+ const extendedKey = (0, import_utils37.concat)([
8259
8658
  prefix,
8260
8659
  depth,
8261
8660
  fingerprint,
8262
8661
  index,
8263
8662
  chainCode,
8264
- (0, import_utils34.concat)(["0x00", privateKey])
8663
+ (0, import_utils37.concat)(["0x00", privateKey])
8265
8664
  ]);
8266
- const checksum = (0, import_utils34.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8267
- return (0, import_utils34.encodeBase58)((0, import_utils34.concat)([extendedKey, checksum]));
8665
+ const checksum = (0, import_utils37.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8666
+ return (0, import_utils37.encodeBase58)((0, import_utils37.concat)([extendedKey, checksum]));
8268
8667
  }
8269
8668
  /**
8270
8669
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -8279,7 +8678,7 @@ var Mnemonic = class {
8279
8678
  * @returns A randomly generated mnemonic
8280
8679
  */
8281
8680
  static generate(size = 32, extraEntropy = "") {
8282
- const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils34.concat)([(0, import_crypto5.randomBytes)(size), (0, import_utils34.arrayify)(extraEntropy)])) : (0, import_crypto5.randomBytes)(size);
8681
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils37.concat)([(0, import_crypto7.randomBytes)(size), (0, import_utils37.arrayify)(extraEntropy)])) : (0, import_crypto7.randomBytes)(size);
8283
8682
  return Mnemonic.entropyToMnemonic(entropy);
8284
8683
  }
8285
8684
  };
@@ -8287,12 +8686,12 @@ var mnemonic_default = Mnemonic;
8287
8686
 
8288
8687
  // src/hdwallet/hdwallet.ts
8289
8688
  var HARDENED_INDEX = 2147483648;
8290
- var MainnetPRV2 = (0, import_utils36.hexlify)("0x0488ade4");
8291
- var MainnetPUB = (0, import_utils36.hexlify)("0x0488b21e");
8292
- var TestnetPRV2 = (0, import_utils36.hexlify)("0x04358394");
8293
- var TestnetPUB = (0, import_utils36.hexlify)("0x043587cf");
8689
+ var MainnetPRV2 = (0, import_utils39.hexlify)("0x0488ade4");
8690
+ var MainnetPUB = (0, import_utils39.hexlify)("0x0488b21e");
8691
+ var TestnetPRV2 = (0, import_utils39.hexlify)("0x04358394");
8692
+ var TestnetPUB = (0, import_utils39.hexlify)("0x043587cf");
8294
8693
  function base58check(data) {
8295
- return (0, import_utils36.encodeBase58)((0, import_utils36.concat)([data, (0, import_utils36.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
8694
+ return (0, import_utils39.encodeBase58)((0, import_utils39.concat)([data, (0, import_utils39.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
8296
8695
  }
8297
8696
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8298
8697
  if (isPublic) {
@@ -8301,17 +8700,17 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8301
8700
  return testnet ? TestnetPRV2 : MainnetPRV2;
8302
8701
  }
8303
8702
  function isPublicExtendedKey(extendedKey) {
8304
- return [MainnetPUB, TestnetPUB].includes((0, import_utils36.hexlify)(extendedKey.slice(0, 4)));
8703
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils39.hexlify)(extendedKey.slice(0, 4)));
8305
8704
  }
8306
8705
  function isValidExtendedKey(extendedKey) {
8307
8706
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
8308
- (0, import_utils36.hexlify)(extendedKey.slice(0, 4))
8707
+ (0, import_utils39.hexlify)(extendedKey.slice(0, 4))
8309
8708
  );
8310
8709
  }
8311
8710
  function parsePath(path2, depth = 0) {
8312
8711
  const components = path2.split("/");
8313
8712
  if (components.length === 0 || components[0] === "m" && depth !== 0) {
8314
- throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
8713
+ throw new import_errors22.FuelError(import_errors22.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
8315
8714
  }
8316
8715
  if (components[0] === "m") {
8317
8716
  components.shift();
@@ -8323,8 +8722,8 @@ function parsePath(path2, depth = 0) {
8323
8722
  var HDWallet = class {
8324
8723
  depth = 0;
8325
8724
  index = 0;
8326
- fingerprint = (0, import_utils36.hexlify)("0x00000000");
8327
- parentFingerprint = (0, import_utils36.hexlify)("0x00000000");
8725
+ fingerprint = (0, import_utils39.hexlify)("0x00000000");
8726
+ parentFingerprint = (0, import_utils39.hexlify)("0x00000000");
8328
8727
  privateKey;
8329
8728
  publicKey;
8330
8729
  chainCode;
@@ -8336,19 +8735,19 @@ var HDWallet = class {
8336
8735
  constructor(config) {
8337
8736
  if (config.privateKey) {
8338
8737
  const signer = new Signer(config.privateKey);
8339
- this.publicKey = (0, import_utils36.hexlify)(signer.compressedPublicKey);
8340
- this.privateKey = (0, import_utils36.hexlify)(config.privateKey);
8738
+ this.publicKey = (0, import_utils39.hexlify)(signer.compressedPublicKey);
8739
+ this.privateKey = (0, import_utils39.hexlify)(config.privateKey);
8341
8740
  } else {
8342
8741
  if (!config.publicKey) {
8343
- throw new import_errors20.FuelError(
8344
- import_errors20.ErrorCode.HD_WALLET_ERROR,
8742
+ throw new import_errors22.FuelError(
8743
+ import_errors22.ErrorCode.HD_WALLET_ERROR,
8345
8744
  "Both public and private Key cannot be missing. At least one should be provided."
8346
8745
  );
8347
8746
  }
8348
- this.publicKey = (0, import_utils36.hexlify)(config.publicKey);
8747
+ this.publicKey = (0, import_utils39.hexlify)(config.publicKey);
8349
8748
  }
8350
8749
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8351
- this.fingerprint = (0, import_utils36.dataSlice)((0, import_crypto6.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8750
+ this.fingerprint = (0, import_utils39.dataSlice)((0, import_crypto8.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8352
8751
  this.depth = config.depth || this.depth;
8353
8752
  this.index = config.index || this.index;
8354
8753
  this.chainCode = config.chainCode;
@@ -8364,23 +8763,23 @@ var HDWallet = class {
8364
8763
  * @returns A new instance of HDWallet on the derived index
8365
8764
  */
8366
8765
  deriveIndex(index) {
8367
- const privateKey = this.privateKey && (0, import_utils36.arrayify)(this.privateKey);
8368
- const publicKey = (0, import_utils36.arrayify)(this.publicKey);
8369
- const chainCode = (0, import_utils36.arrayify)(this.chainCode);
8766
+ const privateKey = this.privateKey && (0, import_utils39.arrayify)(this.privateKey);
8767
+ const publicKey = (0, import_utils39.arrayify)(this.publicKey);
8768
+ const chainCode = (0, import_utils39.arrayify)(this.chainCode);
8370
8769
  const data = new Uint8Array(37);
8371
8770
  if (index & HARDENED_INDEX) {
8372
8771
  if (!privateKey) {
8373
- throw new import_errors20.FuelError(
8374
- import_errors20.ErrorCode.HD_WALLET_ERROR,
8772
+ throw new import_errors22.FuelError(
8773
+ import_errors22.ErrorCode.HD_WALLET_ERROR,
8375
8774
  "Cannot derive a hardened index without a private Key."
8376
8775
  );
8377
8776
  }
8378
8777
  data.set(privateKey, 1);
8379
8778
  } else {
8380
- data.set((0, import_utils36.arrayify)(this.publicKey));
8779
+ data.set((0, import_utils39.arrayify)(this.publicKey));
8381
8780
  }
8382
8781
  data.set((0, import_math22.toBytes)(index, 4), 33);
8383
- const bytes = (0, import_utils36.arrayify)((0, import_crypto6.computeHmac)("sha512", chainCode, data));
8782
+ const bytes = (0, import_utils39.arrayify)((0, import_crypto8.computeHmac)("sha512", chainCode, data));
8384
8783
  const IL = bytes.slice(0, 32);
8385
8784
  const IR = bytes.slice(32);
8386
8785
  if (privateKey) {
@@ -8394,7 +8793,7 @@ var HDWallet = class {
8394
8793
  parentFingerprint: this.fingerprint
8395
8794
  });
8396
8795
  }
8397
- const signer = new Signer((0, import_utils36.hexlify)(IL));
8796
+ const signer = new Signer((0, import_utils39.hexlify)(IL));
8398
8797
  const Ki = signer.addPoint(publicKey);
8399
8798
  return new HDWallet({
8400
8799
  publicKey: Ki,
@@ -8423,18 +8822,18 @@ var HDWallet = class {
8423
8822
  */
8424
8823
  toExtendedKey(isPublic = false, testnet = false) {
8425
8824
  if (this.depth >= 256) {
8426
- throw new import_errors20.FuelError(
8427
- import_errors20.ErrorCode.HD_WALLET_ERROR,
8825
+ throw new import_errors22.FuelError(
8826
+ import_errors22.ErrorCode.HD_WALLET_ERROR,
8428
8827
  `Exceeded max depth of 255. Current depth: ${this.depth}.`
8429
8828
  );
8430
8829
  }
8431
8830
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8432
- const depth = (0, import_utils36.hexlify)(Uint8Array.from([this.depth]));
8831
+ const depth = (0, import_utils39.hexlify)(Uint8Array.from([this.depth]));
8433
8832
  const parentFingerprint = this.parentFingerprint;
8434
8833
  const index = (0, import_math22.toHex)(this.index, 4);
8435
8834
  const chainCode = this.chainCode;
8436
- const key = this.privateKey != null && !isPublic ? (0, import_utils36.concat)(["0x00", this.privateKey]) : this.publicKey;
8437
- const extendedKey = (0, import_utils36.arrayify)((0, import_utils36.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8835
+ const key = this.privateKey != null && !isPublic ? (0, import_utils39.concat)(["0x00", this.privateKey]) : this.publicKey;
8836
+ const extendedKey = (0, import_utils39.arrayify)((0, import_utils39.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8438
8837
  return base58check(extendedKey);
8439
8838
  }
8440
8839
  /**
@@ -8446,34 +8845,34 @@ var HDWallet = class {
8446
8845
  static fromSeed(seed) {
8447
8846
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
8448
8847
  return new HDWallet({
8449
- chainCode: (0, import_utils36.arrayify)(masterKey.slice(32)),
8450
- privateKey: (0, import_utils36.arrayify)(masterKey.slice(0, 32))
8848
+ chainCode: (0, import_utils39.arrayify)(masterKey.slice(32)),
8849
+ privateKey: (0, import_utils39.arrayify)(masterKey.slice(0, 32))
8451
8850
  });
8452
8851
  }
8453
8852
  static fromExtendedKey(extendedKey) {
8454
- const decoded = (0, import_utils36.hexlify)((0, import_math22.toBytes)((0, import_utils36.decodeBase58)(extendedKey)));
8455
- const bytes = (0, import_utils36.arrayify)(decoded);
8853
+ const decoded = (0, import_utils39.hexlify)((0, import_math22.toBytes)((0, import_utils39.decodeBase58)(extendedKey)));
8854
+ const bytes = (0, import_utils39.arrayify)(decoded);
8456
8855
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8457
8856
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8458
- throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
8857
+ throw new import_errors22.FuelError(import_errors22.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
8459
8858
  }
8460
8859
  if (!validChecksum) {
8461
- throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8860
+ throw new import_errors22.FuelError(import_errors22.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8462
8861
  }
8463
8862
  const depth = bytes[4];
8464
- const parentFingerprint = (0, import_utils36.hexlify)(bytes.slice(5, 9));
8465
- const index = parseInt((0, import_utils36.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8466
- const chainCode = (0, import_utils36.hexlify)(bytes.slice(13, 45));
8863
+ const parentFingerprint = (0, import_utils39.hexlify)(bytes.slice(5, 9));
8864
+ const index = parseInt((0, import_utils39.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8865
+ const chainCode = (0, import_utils39.hexlify)(bytes.slice(13, 45));
8467
8866
  const key = bytes.slice(45, 78);
8468
8867
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8469
- throw new import_errors20.FuelError(
8470
- import_errors20.ErrorCode.HD_WALLET_ERROR,
8868
+ throw new import_errors22.FuelError(
8869
+ import_errors22.ErrorCode.HD_WALLET_ERROR,
8471
8870
  "Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
8472
8871
  );
8473
8872
  }
8474
8873
  if (isPublicExtendedKey(bytes)) {
8475
8874
  if (key[0] !== 3) {
8476
- throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
8875
+ throw new import_errors22.FuelError(import_errors22.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
8477
8876
  }
8478
8877
  return new HDWallet({
8479
8878
  publicKey: key,
@@ -8484,7 +8883,7 @@ var HDWallet = class {
8484
8883
  });
8485
8884
  }
8486
8885
  if (key[0] !== 0) {
8487
- throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
8886
+ throw new import_errors22.FuelError(import_errors22.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
8488
8887
  }
8489
8888
  return new HDWallet({
8490
8889
  privateKey: key.slice(1),
@@ -8649,292 +9048,7 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
8649
9048
  */
8650
9049
  __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
8651
9050
 
8652
- // src/test-utils/seedTestWallet.ts
8653
- var import_crypto7 = require("@fuel-ts/crypto");
8654
- var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
8655
- const accountsToBeFunded = Array.isArray(wallet) ? wallet : [wallet];
8656
- const [{ provider }] = accountsToBeFunded;
8657
- const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET || (0, import_crypto7.randomBytes)(32), provider);
8658
- const request = new ScriptTransactionRequest();
8659
- quantities.map(coinQuantityfy).forEach(
8660
- ({ amount, assetId }) => accountsToBeFunded.forEach(({ address }) => {
8661
- for (let i = 0; i < utxosAmount; i++) {
8662
- request.addCoinOutput(address, amount.div(utxosAmount), assetId);
8663
- }
8664
- })
8665
- );
8666
- const txCost = await genesisWallet.provider.getTransactionCost(request);
8667
- request.gasLimit = txCost.gasUsed;
8668
- request.maxFee = txCost.maxFee;
8669
- await genesisWallet.fund(request, txCost);
8670
- await genesisWallet.sendTransaction(request, { awaitExecution: true });
8671
- };
8672
-
8673
- // src/test-utils/generateTestWallet.ts
8674
- var generateTestWallet = async (provider, quantities) => {
8675
- const wallet = Wallet.generate({ provider });
8676
- if (quantities) {
8677
- await seedTestWallet(wallet, quantities);
8678
- }
8679
- return wallet;
8680
- };
8681
-
8682
- // src/test-utils/launchNode.ts
8683
- var import_abi_coder8 = require("@fuel-ts/abi-coder");
8684
- var import_crypto8 = require("@fuel-ts/crypto");
8685
- var import_errors21 = require("@fuel-ts/errors");
8686
- var import_utils37 = require("@fuel-ts/utils");
8687
- var import_crypto9 = require("crypto");
8688
- var import_fs = require("fs");
8689
- var import_os = __toESM(require("os"));
8690
- var import_path = __toESM(require("path"));
8691
- var import_portfinder = require("portfinder");
8692
- var getFlagValueFromArgs = (args, flag) => {
8693
- const flagIndex = args.indexOf(flag);
8694
- if (flagIndex === -1) {
8695
- return void 0;
8696
- }
8697
- return args[flagIndex + 1];
8698
- };
8699
- var extractRemainingArgs = (args, flagsToRemove) => {
8700
- const newArgs = [...args];
8701
- flagsToRemove.forEach((flag) => {
8702
- const flagIndex = newArgs.indexOf(flag);
8703
- if (flagIndex !== -1) {
8704
- newArgs.splice(flagIndex, 2);
8705
- }
8706
- });
8707
- return newArgs;
8708
- };
8709
- function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
8710
- const defaultCoins = import_utils37.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
8711
- ...coin,
8712
- amount: "18446744073709551615"
8713
- }));
8714
- const defaultMessages = import_utils37.defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
8715
- ...message,
8716
- amount: "18446744073709551615"
8717
- }));
8718
- const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self) => self.findIndex((c) => c.tx_id === coin.tx_id) === index);
8719
- const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self) => self.findIndex((m) => m.nonce === msg.nonce) === index);
8720
- if (!process.env.GENESIS_SECRET) {
8721
- const pk = Signer.generatePrivateKey();
8722
- const signer = new Signer(pk);
8723
- process.env.GENESIS_SECRET = (0, import_utils37.hexlify)(pk);
8724
- coins.push({
8725
- tx_id: (0, import_utils37.hexlify)((0, import_crypto8.randomBytes)(import_abi_coder8.BYTES_32)),
8726
- owner: signer.address.toHexString(),
8727
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8728
- amount: "18446744073709551615",
8729
- asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
8730
- output_index: 0,
8731
- tx_pointer_block_height: 0,
8732
- tx_pointer_tx_idx: 0
8733
- });
8734
- }
8735
- const json = JSON.stringify({
8736
- ...stateConfig,
8737
- coins,
8738
- messages
8739
- });
8740
- const regexMakeNumber = /("amount":)"(\d+)"/gm;
8741
- return json.replace(regexMakeNumber, "$1$2");
8742
- }
8743
- var launchNode = async ({
8744
- ip,
8745
- port,
8746
- args = [],
8747
- fuelCorePath = process.env.FUEL_CORE_PATH || void 0,
8748
- loggingEnabled = true,
8749
- basePath,
8750
- snapshotConfig = import_utils37.defaultSnapshotConfigs
8751
- } = {}) => (
8752
- // eslint-disable-next-line no-async-promise-executor
8753
- new Promise(async (resolve, reject) => {
8754
- const remainingArgs = extractRemainingArgs(args, [
8755
- "--snapshot",
8756
- "--consensus-key",
8757
- "--db-type",
8758
- "--poa-instant"
8759
- ]);
8760
- const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
8761
- const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils37.defaultConsensusKey;
8762
- const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8763
- const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
8764
- const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
8765
- const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
8766
- const nativeExecutorVersion = getFlagValueFromArgs(args, "--native-executor-version") || "0";
8767
- const graphQLStartSubstring = "Binding GraphQL provider to";
8768
- const command = fuelCorePath || "fuel-core";
8769
- const ipToUse = ip || "0.0.0.0";
8770
- const portToUse = port || (await (0, import_portfinder.getPortPromise)({
8771
- port: 4e3,
8772
- // tries 4000 first, then 4001, then 4002, etc.
8773
- stopPort: 5e3
8774
- // don't try ports above 5000
8775
- })).toString();
8776
- let snapshotDirToUse;
8777
- const prefix = basePath || import_os.default.tmpdir();
8778
- const suffix = basePath ? "" : (0, import_crypto9.randomUUID)();
8779
- const tempDir = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
8780
- if (snapshotDir) {
8781
- snapshotDirToUse = snapshotDir;
8782
- } else {
8783
- if (!(0, import_fs.existsSync)(tempDir)) {
8784
- (0, import_fs.mkdirSync)(tempDir, { recursive: true });
8785
- }
8786
- const { metadata } = snapshotConfig;
8787
- const metadataPath = import_path.default.join(tempDir, "metadata.json");
8788
- const chainConfigPath = import_path.default.join(tempDir, metadata.chain_config);
8789
- const stateConfigPath = import_path.default.join(tempDir, metadata.table_encoding.Json.filepath);
8790
- const stateTransitionPath = import_path.default.join(tempDir, "state_transition_bytecode.wasm");
8791
- (0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
8792
- (0, import_fs.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
8793
- (0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
8794
- (0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
8795
- snapshotDirToUse = tempDir;
8796
- }
8797
- const { spawn } = await import("child_process");
8798
- const child = spawn(
8799
- command,
8800
- [
8801
- "run",
8802
- ["--ip", ipToUse],
8803
- ["--port", portToUse],
8804
- useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
8805
- ["--min-gas-price", "1"],
8806
- poaInstant ? ["--poa-instant", "true"] : [],
8807
- ["--native-executor-version", nativeExecutorVersion],
8808
- ["--consensus-key", consensusKey],
8809
- ["--snapshot", snapshotDirToUse],
8810
- "--vm-backtrace",
8811
- "--utxo-validation",
8812
- "--debug",
8813
- ...remainingArgs
8814
- ].flat(),
8815
- { stdio: "pipe", detached: true }
8816
- );
8817
- if (loggingEnabled) {
8818
- child.stderr.on("data", (chunk) => {
8819
- console.log(chunk.toString());
8820
- });
8821
- }
8822
- const removeSideffects = () => {
8823
- child.stderr.removeAllListeners();
8824
- if ((0, import_fs.existsSync)(tempDir)) {
8825
- (0, import_fs.rmSync)(tempDir, { recursive: true });
8826
- }
8827
- };
8828
- child.on("error", removeSideffects);
8829
- child.on("exit", removeSideffects);
8830
- const childState = {
8831
- isDead: false
8832
- };
8833
- const cleanup = () => {
8834
- if (childState.isDead) {
8835
- return;
8836
- }
8837
- childState.isDead = true;
8838
- removeSideffects();
8839
- if (child.pid !== void 0) {
8840
- try {
8841
- process.kill(-child.pid);
8842
- } catch (e) {
8843
- const error = e;
8844
- if (error.code === "ESRCH") {
8845
- console.log(
8846
- `fuel-core node under pid ${child.pid} does not exist. The node might have been killed before cleanup was called. Exiting cleanly.`
8847
- );
8848
- } else {
8849
- throw e;
8850
- }
8851
- }
8852
- } else {
8853
- console.error("No PID available for the child process, unable to kill launched node");
8854
- }
8855
- };
8856
- child.stderr.on("data", (chunk) => {
8857
- const text = typeof chunk === "string" ? chunk : chunk.toString();
8858
- if (text.indexOf(graphQLStartSubstring) !== -1) {
8859
- const rows = text.split("\n");
8860
- const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
8861
- const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
8862
- resolve({
8863
- cleanup,
8864
- ip: realIp,
8865
- port: realPort,
8866
- url: `http://${realIp}:${realPort}/v1/graphql`,
8867
- snapshotDir: snapshotDirToUse,
8868
- pid: child.pid
8869
- });
8870
- }
8871
- if (/error/i.test(text)) {
8872
- console.log(text);
8873
- reject(new import_errors21.FuelError(import_errors21.FuelError.CODES.NODE_LAUNCH_FAILED, text));
8874
- }
8875
- });
8876
- process.on("exit", cleanup);
8877
- process.on("SIGINT", cleanup);
8878
- process.on("SIGUSR1", cleanup);
8879
- process.on("SIGUSR2", cleanup);
8880
- process.on("beforeExit", cleanup);
8881
- process.on("uncaughtException", cleanup);
8882
- child.on("error", reject);
8883
- })
8884
- );
8885
- var generateWallets = async (count, provider) => {
8886
- const baseAssetId = provider.getBaseAssetId();
8887
- const wallets = [];
8888
- for (let i = 0; i < count; i += 1) {
8889
- const wallet = await generateTestWallet(provider, [[1e5, baseAssetId]]);
8890
- wallets.push(wallet);
8891
- }
8892
- return wallets;
8893
- };
8894
- var launchNodeAndGetWallets = async ({
8895
- launchNodeOptions,
8896
- walletCount = 10
8897
- } = {}) => {
8898
- const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
8899
- const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
8900
- const wallets = await generateWallets(walletCount, provider);
8901
- const cleanup = () => {
8902
- closeNode();
8903
- };
8904
- return { wallets, stop: cleanup, provider };
8905
- };
8906
-
8907
- // src/test-utils/setup-test-provider-and-wallets.ts
8908
- var import_utils40 = require("@fuel-ts/utils");
8909
- var import_ramda5 = require("ramda");
8910
-
8911
- // src/test-utils/asset-id.ts
8912
- var import_crypto10 = require("@fuel-ts/crypto");
8913
- var import_utils38 = require("@fuel-ts/utils");
8914
- var _AssetId = class {
8915
- constructor(value) {
8916
- this.value = value;
8917
- }
8918
- static random(count = 1) {
8919
- const assetIds = [];
8920
- for (let i = 0; i < count; i++) {
8921
- assetIds.push(new _AssetId((0, import_utils38.hexlify)((0, import_crypto10.randomBytes)(32))));
8922
- }
8923
- return assetIds;
8924
- }
8925
- };
8926
- var AssetId = _AssetId;
8927
- __publicField(AssetId, "A", new _AssetId(
8928
- "0x0101010101010101010101010101010101010101010101010101010101010101"
8929
- ));
8930
- __publicField(AssetId, "B", new _AssetId(
8931
- "0x0202020202020202020202020202020202020202020202020202020202020202"
8932
- ));
8933
-
8934
9051
  // src/test-utils/wallet-config.ts
8935
- var import_crypto11 = require("@fuel-ts/crypto");
8936
- var import_errors22 = require("@fuel-ts/errors");
8937
- var import_utils39 = require("@fuel-ts/utils");
8938
9052
  var WalletsConfig = class {
8939
9053
  initialState;
8940
9054
  options;
@@ -8942,7 +9056,7 @@ var WalletsConfig = class {
8942
9056
  generateWallets = () => {
8943
9057
  const generatedWallets = [];
8944
9058
  for (let index = 1; index <= this.options.count; index++) {
8945
- generatedWallets.push(new WalletUnlocked((0, import_crypto11.randomBytes)(32)));
9059
+ generatedWallets.push(new WalletUnlocked((0, import_crypto9.randomBytes)(32)));
8946
9060
  }
8947
9061
  return generatedWallets;
8948
9062
  };
@@ -8966,7 +9080,7 @@ var WalletsConfig = class {
8966
9080
  return {
8967
9081
  ...snapshotConfig,
8968
9082
  stateConfig: {
8969
- ...snapshotConfig?.stateConfig ?? import_utils39.defaultSnapshotConfigs.stateConfig,
9083
+ ...snapshotConfig?.stateConfig ?? import_utils40.defaultSnapshotConfigs.stateConfig,
8970
9084
  coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
8971
9085
  messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
8972
9086
  }
@@ -8987,7 +9101,7 @@ var WalletsConfig = class {
8987
9101
  if (Array.isArray(assets2)) {
8988
9102
  assetIds = assetIds.concat(assets2.map((a) => a.value));
8989
9103
  } else {
8990
- assetIds = assetIds.concat(AssetId.random(assets2 - 1).map((a) => a.value));
9104
+ assetIds = assetIds.concat(TestAssetId.random(assets2 - 1).map((a) => a.value));
8991
9105
  }
8992
9106
  wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
8993
9107
  assetIds.forEach((assetId) => {
@@ -8999,7 +9113,7 @@ var WalletsConfig = class {
8999
9113
  tx_pointer_block_height: 0,
9000
9114
  tx_pointer_tx_idx: 0,
9001
9115
  output_index: 0,
9002
- tx_id: (0, import_utils39.hexlify)((0, import_crypto11.randomBytes)(32))
9116
+ tx_id: (0, import_utils40.hexlify)((0, import_crypto9.randomBytes)(32))
9003
9117
  });
9004
9118
  }
9005
9119
  });
@@ -9013,27 +9127,27 @@ var WalletsConfig = class {
9013
9127
  amountPerCoin
9014
9128
  }) {
9015
9129
  if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
9016
- throw new import_errors22.FuelError(
9017
- import_errors22.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9130
+ throw new import_errors23.FuelError(
9131
+ import_errors23.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9018
9132
  "Number of wallets must be greater than zero."
9019
9133
  );
9020
9134
  }
9021
9135
  if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
9022
- throw new import_errors22.FuelError(
9023
- import_errors22.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9136
+ throw new import_errors23.FuelError(
9137
+ import_errors23.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9024
9138
  "Number of assets per wallet must be greater than zero."
9025
9139
  );
9026
9140
  }
9027
9141
  if (coinsPerAsset <= 0) {
9028
- throw new import_errors22.FuelError(
9029
- import_errors22.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9142
+ throw new import_errors23.FuelError(
9143
+ import_errors23.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9030
9144
  "Number of coins per asset must be greater than zero."
9031
9145
  );
9032
9146
  }
9033
- if (amountPerCoin <= 0) {
9034
- throw new import_errors22.FuelError(
9035
- import_errors22.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9036
- "Amount per coin must be greater than zero."
9147
+ if (amountPerCoin < 0) {
9148
+ throw new import_errors23.FuelError(
9149
+ import_errors23.FuelError.CODES.INVALID_INPUT_PARAMETERS,
9150
+ "Amount per coin must be greater than or equal to zero."
9037
9151
  );
9038
9152
  }
9039
9153
  }
@@ -9042,7 +9156,7 @@ var WalletsConfig = class {
9042
9156
  // src/test-utils/setup-test-provider-and-wallets.ts
9043
9157
  var defaultWalletConfigOptions = {
9044
9158
  count: 2,
9045
- assets: [AssetId.A, AssetId.B],
9159
+ assets: [TestAssetId.A, TestAssetId.B],
9046
9160
  coinsPerAsset: 1,
9047
9161
  amountPerCoin: 1e10,
9048
9162
  messages: []
@@ -9055,7 +9169,7 @@ async function setupTestProviderAndWallets({
9055
9169
  } = {}) {
9056
9170
  Symbol.dispose ??= Symbol("Symbol.dispose");
9057
9171
  const walletsConfig = new WalletsConfig(
9058
- nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? import_utils40.defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
9172
+ nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? import_utils41.defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
9059
9173
  {
9060
9174
  ...defaultWalletConfigOptions,
9061
9175
  ...walletsConfigOptions
@@ -9065,10 +9179,10 @@ async function setupTestProviderAndWallets({
9065
9179
  loggingEnabled: false,
9066
9180
  ...nodeOptions,
9067
9181
  snapshotConfig: (0, import_ramda5.mergeDeepRight)(
9068
- import_utils40.defaultSnapshotConfigs,
9182
+ import_utils41.defaultSnapshotConfigs,
9069
9183
  walletsConfig.apply(nodeOptions?.snapshotConfig)
9070
9184
  ),
9071
- port: "0"
9185
+ port: nodeOptions.port || "0"
9072
9186
  };
9073
9187
  let cleanup;
9074
9188
  let url;
@@ -9104,9 +9218,9 @@ async function setupTestProviderAndWallets({
9104
9218
 
9105
9219
  // src/test-utils/test-message.ts
9106
9220
  var import_address7 = require("@fuel-ts/address");
9107
- var import_crypto12 = require("@fuel-ts/crypto");
9221
+ var import_crypto10 = require("@fuel-ts/crypto");
9108
9222
  var import_math23 = require("@fuel-ts/math");
9109
- var import_utils41 = require("@fuel-ts/utils");
9223
+ var import_utils42 = require("@fuel-ts/utils");
9110
9224
  var TestMessage = class {
9111
9225
  sender;
9112
9226
  recipient;
@@ -9123,9 +9237,10 @@ var TestMessage = class {
9123
9237
  constructor({
9124
9238
  sender = import_address7.Address.fromRandom(),
9125
9239
  recipient = import_address7.Address.fromRandom(),
9126
- nonce = (0, import_utils41.hexlify)((0, import_crypto12.randomBytes)(32)),
9240
+ nonce = (0, import_utils42.hexlify)((0, import_crypto10.randomBytes)(32)),
9127
9241
  amount = 1e6,
9128
- data = "02",
9242
+ data = "",
9243
+ // Will default to empty data in order to be a spendable message
9129
9244
  da_height = 0
9130
9245
  } = {}) {
9131
9246
  this.sender = sender;
@@ -9136,25 +9251,23 @@ var TestMessage = class {
9136
9251
  this.da_height = da_height;
9137
9252
  }
9138
9253
  toChainMessage(recipient) {
9254
+ const data = /^0x/.test(this.data) ? this.data.replace(/^0x/, "") : this.data;
9139
9255
  return {
9140
9256
  sender: this.sender.toB256(),
9141
9257
  recipient: recipient?.toB256() ?? this.recipient.toB256(),
9142
9258
  nonce: this.nonce,
9143
9259
  amount: (0, import_math23.bn)(this.amount).toNumber(),
9144
- data: this.data,
9260
+ data,
9145
9261
  da_height: this.da_height
9146
9262
  };
9147
9263
  }
9148
9264
  };
9149
9265
  // Annotate the CommonJS export names for ESM import in node:
9150
9266
  0 && (module.exports = {
9151
- AssetId,
9267
+ TestAssetId,
9152
9268
  TestMessage,
9153
9269
  WalletsConfig,
9154
- generateTestWallet,
9155
9270
  launchNode,
9156
- launchNodeAndGetWallets,
9157
- seedTestWallet,
9158
9271
  setupTestProviderAndWallets
9159
9272
  });
9160
9273
  //# sourceMappingURL=test-utils.js.map