@fuel-ts/account 0.97.0 → 0.97.2

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.
Files changed (34) hide show
  1. package/dist/account.d.ts.map +1 -1
  2. package/dist/connectors/fuel-connector.d.ts.map +1 -1
  3. package/dist/index.global.js +588 -14248
  4. package/dist/index.global.js.map +1 -1
  5. package/dist/index.js +31 -29
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +9 -7
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/predicate/predicate.d.ts.map +1 -1
  10. package/dist/providers/provider.d.ts.map +1 -1
  11. package/dist/providers/transaction-request/blob-transaction-request.d.ts.map +1 -1
  12. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  13. package/dist/providers/transaction-request/errors.d.ts.map +1 -1
  14. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  15. package/dist/providers/transaction-request/upgrade-transaction-request.d.ts.map +1 -1
  16. package/dist/providers/transaction-request/upload-transaction-request.d.ts.map +1 -1
  17. package/dist/providers/transaction-summary/get-transaction-summary.d.ts +6 -1
  18. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  19. package/dist/providers/transaction-summary/operations.d.ts +21 -3
  20. package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
  21. package/dist/test-utils/launchNode.d.ts +3 -1
  22. package/dist/test-utils/launchNode.d.ts.map +1 -1
  23. package/dist/test-utils/test-coin.d.ts +1 -0
  24. package/dist/test-utils/test-coin.d.ts.map +1 -0
  25. package/dist/test-utils.global.js +9958 -24049
  26. package/dist/test-utils.global.js.map +1 -1
  27. package/dist/test-utils.js +67 -30
  28. package/dist/test-utils.js.map +1 -1
  29. package/dist/test-utils.mjs +49 -12
  30. package/dist/test-utils.mjs.map +1 -1
  31. package/dist/utils/formatTransferToContractScriptData.d.ts +1 -1
  32. package/dist/utils/formatTransferToContractScriptData.d.ts.map +1 -1
  33. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  34. package/package.json +18 -18
@@ -192,7 +192,11 @@ var extractRemainingArgs = (args, flagsToRemove) => {
192
192
  });
193
193
  return newArgs;
194
194
  };
195
- function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
195
+ function getFinalStateConfigJSON({
196
+ stateConfig,
197
+ chainConfig,
198
+ includeInitialState = false
199
+ }) {
196
200
  const defaultCoins = import_utils2.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
197
201
  ...coin,
198
202
  amount: "18446744073709551615"
@@ -203,6 +207,26 @@ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
203
207
  }));
204
208
  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);
205
209
  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);
210
+ if (includeInitialState) {
211
+ coins.push({
212
+ tx_id: "0x0000000000000000000000000000000000000000000000000000000000000001",
213
+ output_index: 0,
214
+ tx_pointer_block_height: 0,
215
+ tx_pointer_tx_idx: 0,
216
+ owner: "0x94ffcc53b892684acefaebc8a3d4a595e528a8cf664eeb3ef36f1020b0809d0d",
217
+ amount: "18446744073709551615",
218
+ asset_id: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
219
+ });
220
+ coins.push({
221
+ tx_id: "0x0000000000000000000000000000000000000000000000000000000000000002",
222
+ output_index: 0,
223
+ tx_pointer_block_height: 0,
224
+ tx_pointer_tx_idx: 0,
225
+ owner: "0x09c0b2d1a486c439a87bcba6b46a7a1a23f3897cc83a94521a96da5c23bc58db",
226
+ amount: "18446744073709551615",
227
+ asset_id: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
228
+ });
229
+ }
206
230
  if (!process.env.GENESIS_SECRET) {
207
231
  const pk = Signer.generatePrivateKey();
208
232
  const signer = new Signer(pk);
@@ -212,7 +236,7 @@ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
212
236
  owner: signer.address.toHexString(),
213
237
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
214
238
  amount: "18446744073709551615",
215
- asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
239
+ asset_id: chainConfig.consensus_parameters.V2.base_asset_id,
216
240
  output_index: 0,
217
241
  tx_pointer_block_height: 0,
218
242
  tx_pointer_tx_idx: 0
@@ -233,7 +257,8 @@ var launchNode = async ({
233
257
  fuelCorePath = process.env.FUEL_CORE_PATH || void 0,
234
258
  loggingEnabled = true,
235
259
  basePath,
236
- snapshotConfig = import_utils2.defaultSnapshotConfigs
260
+ snapshotConfig = import_utils2.defaultSnapshotConfigs,
261
+ includeInitialState = false
237
262
  } = {}) => (
238
263
  // eslint-disable-next-line no-async-promise-executor
239
264
  new Promise(async (resolve, reject) => {
@@ -273,7 +298,14 @@ var launchNode = async ({
273
298
  const stateConfigPath = import_path.default.join(tempDir, metadata.table_encoding.Json.filepath);
274
299
  const stateTransitionPath = import_path.default.join(tempDir, "state_transition_bytecode.wasm");
275
300
  (0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
276
- (0, import_fs.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
301
+ (0, import_fs.writeFileSync)(
302
+ stateConfigPath,
303
+ getFinalStateConfigJSON({
304
+ ...snapshotConfig,
305
+ includeInitialState
306
+ }),
307
+ "utf8"
308
+ );
277
309
  (0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
278
310
  (0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
279
311
  snapshotDirToUse = tempDir;
@@ -329,6 +361,8 @@ var launchNode = async ({
329
361
  console.log(
330
362
  `fuel-core node under pid ${child.pid} does not exist. The node might have been killed before cleanup was called. Exiting cleanly.`
331
363
  );
364
+ } else if (error.message.includes("pid must be a positive integer")) {
365
+ process.kill(+child.pid);
332
366
  } else {
333
367
  throw e;
334
368
  }
@@ -357,6 +391,7 @@ var launchNode = async ({
357
391
  reject(new import_errors.FuelError(import_errors.FuelError.CODES.NODE_LAUNCH_FAILED, text));
358
392
  }
359
393
  });
394
+ process.setMaxListeners(100);
360
395
  process.on("exit", cleanup);
361
396
  process.on("SIGINT", cleanup);
362
397
  process.on("SIGUSR1", cleanup);
@@ -4934,7 +4969,7 @@ Supported fuel-core version: ${supportedVersion}.`
4934
4969
  createOperations() {
4935
4970
  const fetchFn = _Provider.getFetchFn(this.options);
4936
4971
  const gqlClient = new import_graphql_request.GraphQLClient(this.urlWithoutAuth, {
4937
- fetch: (url, requestInit) => fetchFn(url, requestInit, this.options),
4972
+ fetch: (input, requestInit) => fetchFn(input.toString(), requestInit || {}, this.options),
4938
4973
  responseMiddleware: (response) => {
4939
4974
  if ("response" in response) {
4940
4975
  const graphQlResponse = response.response;
@@ -5185,7 +5220,8 @@ Supported fuel-core version: ${supportedVersion}.`
5185
5220
  dryRun: [{ receipts: rawReceipts, status }]
5186
5221
  } = await this.operations.dryRun({
5187
5222
  encodedTransactions: [(0, import_utils30.hexlify)(transactionRequest.toTransactionBytes())],
5188
- utxoValidation: false
5223
+ utxoValidation: false,
5224
+ gasPrice: "0"
5189
5225
  });
5190
5226
  receipts = rawReceipts.map(processGqlReceipt);
5191
5227
  dryRunStatus = status;
@@ -5199,7 +5235,8 @@ Supported fuel-core version: ${supportedVersion}.`
5199
5235
  missingContractIds.push(contractId);
5200
5236
  });
5201
5237
  const { maxFee } = await this.estimateTxGasAndFee({
5202
- transactionRequest
5238
+ transactionRequest,
5239
+ gasPrice: (0, import_math19.bn)(0)
5203
5240
  });
5204
5241
  transactionRequest.maxFee = maxFee;
5205
5242
  } else {
@@ -5335,7 +5372,7 @@ Supported fuel-core version: ${supportedVersion}.`
5335
5372
  const chainInfo = this.getChain();
5336
5373
  const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
5337
5374
  const minGas = transactionRequest.calculateMinGas(chainInfo);
5338
- if (!gasPrice) {
5375
+ if (!(0, import_utils30.isDefined)(gasPrice)) {
5339
5376
  gasPrice = await this.estimateGasPrice(10);
5340
5377
  }
5341
5378
  const minFee = calculateGasFee({
@@ -6757,7 +6794,7 @@ var import_address6 = require("@fuel-ts/address");
6757
6794
  var import_crypto5 = require("@fuel-ts/crypto");
6758
6795
  var import_errors21 = require("@fuel-ts/errors");
6759
6796
  var import_interfaces = require("@fuel-ts/interfaces");
6760
- var import_math22 = require("@fuel-ts/math");
6797
+ var import_math21 = require("@fuel-ts/math");
6761
6798
  var import_transactions24 = require("@fuel-ts/transactions");
6762
6799
  var import_utils37 = require("@fuel-ts/utils");
6763
6800
  var import_ramda9 = require("ramda");
@@ -6779,14 +6816,13 @@ var mergeQuantities = (...coinQuantities) => {
6779
6816
  // src/utils/formatTransferToContractScriptData.ts
6780
6817
  var import_abi_coder7 = require("@fuel-ts/abi-coder");
6781
6818
  var import_address5 = require("@fuel-ts/address");
6782
- var import_math21 = require("@fuel-ts/math");
6783
6819
  var import_utils36 = require("@fuel-ts/utils");
6784
6820
  var asm = __toESM(require("@fuels/vm-asm"));
6785
6821
  var formatTransferToContractScriptData = (transferParams) => {
6786
6822
  const numberCoder = new import_abi_coder7.BigNumberCoder("u64");
6787
6823
  return transferParams.reduce((acc, transferParam) => {
6788
6824
  const { assetId, amount, contractId } = transferParam;
6789
- const encoded = numberCoder.encode(new import_math21.BN(amount).toNumber());
6825
+ const encoded = numberCoder.encode(amount);
6790
6826
  const scriptData = (0, import_utils36.concat)([
6791
6827
  import_address5.Address.fromAddressOrString(contractId).toBytes(),
6792
6828
  encoded,
@@ -6938,9 +6974,9 @@ var Account = class extends import_interfaces.AbstractAccount {
6938
6974
  const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee, gasPrice } = params;
6939
6975
  const fee = request.maxFee;
6940
6976
  const baseAssetId = this.provider.getBaseAssetId();
6941
- const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math22.bn)(0);
6977
+ const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math21.bn)(0);
6942
6978
  const requiredQuantitiesWithFee = addAmountToCoinQuantities({
6943
- amount: (0, import_math22.bn)(fee),
6979
+ amount: (0, import_math21.bn)(fee),
6944
6980
  assetId: baseAssetId,
6945
6981
  coinQuantities: requiredQuantities
6946
6982
  });
@@ -6948,7 +6984,7 @@ var Account = class extends import_interfaces.AbstractAccount {
6948
6984
  requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
6949
6985
  quantitiesDict[assetId] = {
6950
6986
  required: amount,
6951
- owned: (0, import_math22.bn)(0)
6987
+ owned: (0, import_math21.bn)(0)
6952
6988
  };
6953
6989
  });
6954
6990
  request.inputs.filter(isRequestInputResource).forEach((input) => {
@@ -7024,7 +7060,8 @@ var Account = class extends import_interfaces.AbstractAccount {
7024
7060
  return request;
7025
7061
  }
7026
7062
  const { maxFee } = await this.provider.estimateTxGasAndFee({
7027
- transactionRequest: requestToReestimate
7063
+ transactionRequest: requestToReestimate,
7064
+ gasPrice
7028
7065
  });
7029
7066
  request.maxFee = maxFee;
7030
7067
  return request;
@@ -7123,7 +7160,7 @@ var Account = class extends import_interfaces.AbstractAccount {
7123
7160
  });
7124
7161
  const quantities = [];
7125
7162
  const transferParams = contractTransferParams.map((transferParam) => {
7126
- const amount = (0, import_math22.bn)(transferParam.amount);
7163
+ const amount = (0, import_math21.bn)(transferParam.amount);
7127
7164
  const contractAddress = import_address6.Address.fromAddressOrString(transferParam.contractId);
7128
7165
  const assetId = transferParam.assetId ? (0, import_utils37.hexlify)(transferParam.assetId) : this.provider.getBaseAssetId();
7129
7166
  if (amount.lte(0)) {
@@ -7160,7 +7197,7 @@ var Account = class extends import_interfaces.AbstractAccount {
7160
7197
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
7161
7198
  );
7162
7199
  const amountDataArray = (0, import_utils37.arrayify)(
7163
- "0x".concat((0, import_math22.bn)(amount).toHex().substring(2).padStart(16, "0"))
7200
+ "0x".concat((0, import_math21.bn)(amount).toHex().substring(2).padStart(16, "0"))
7164
7201
  );
7165
7202
  const script = new Uint8Array([
7166
7203
  ...(0, import_utils37.arrayify)(withdrawScript.bytes),
@@ -7170,7 +7207,7 @@ var Account = class extends import_interfaces.AbstractAccount {
7170
7207
  const params = { script, ...txParams };
7171
7208
  const baseAssetId = this.provider.getBaseAssetId();
7172
7209
  let request = new ScriptTransactionRequest(params);
7173
- const quantities = [{ amount: (0, import_math22.bn)(amount), assetId: baseAssetId }];
7210
+ const quantities = [{ amount: (0, import_math21.bn)(amount), assetId: baseAssetId }];
7174
7211
  const txCost = await this.getTransactionCost(request, { quantities });
7175
7212
  request = this.validateGasLimitAndMaxFee({
7176
7213
  transactionRequest: request,
@@ -7196,7 +7233,7 @@ var Account = class extends import_interfaces.AbstractAccount {
7196
7233
  const baseAssetId = this.provider.getBaseAssetId();
7197
7234
  const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
7198
7235
  const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
7199
- const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math22.bn)("100000000000000000") }];
7236
+ const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math21.bn)("100000000000000000") }];
7200
7237
  const findAssetInput = (assetId) => txRequestClone.inputs.find((input) => {
7201
7238
  if (input.type === import_transactions24.InputType.Coin) {
7202
7239
  return input.assetId === assetId;
@@ -7307,14 +7344,14 @@ var Account = class extends import_interfaces.AbstractAccount {
7307
7344
  return coins.map((coin) => ({
7308
7345
  id: (0, import_utils37.hexlify)((0, import_crypto5.randomBytes)(import_abi_coder8.UTXO_ID_LEN)),
7309
7346
  owner: this.address,
7310
- blockCreated: (0, import_math22.bn)(1),
7311
- txCreatedIdx: (0, import_math22.bn)(1),
7347
+ blockCreated: (0, import_math21.bn)(1),
7348
+ txCreatedIdx: (0, import_math21.bn)(1),
7312
7349
  ...coin
7313
7350
  }));
7314
7351
  }
7315
7352
  /** @hidden * */
7316
7353
  validateTransferAmount(amount) {
7317
- if ((0, import_math22.bn)(amount).lte(0)) {
7354
+ if ((0, import_math21.bn)(amount).lte(0)) {
7318
7355
  throw new import_errors21.FuelError(
7319
7356
  import_errors21.ErrorCode.INVALID_TRANSFER_AMOUNT,
7320
7357
  "Transfer amount must be a positive number."
@@ -7575,7 +7612,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
7575
7612
  var import_crypto8 = require("@fuel-ts/crypto");
7576
7613
  var import_errors25 = require("@fuel-ts/errors");
7577
7614
  var import_hasher7 = require("@fuel-ts/hasher");
7578
- var import_math23 = require("@fuel-ts/math");
7615
+ var import_math22 = require("@fuel-ts/math");
7579
7616
  var import_utils43 = require("@fuel-ts/utils");
7580
7617
 
7581
7618
  // src/mnemonic/mnemonic.ts
@@ -10001,13 +10038,13 @@ var HDWallet = class {
10001
10038
  } else {
10002
10039
  data.set((0, import_utils43.arrayify)(this.publicKey));
10003
10040
  }
10004
- data.set((0, import_math23.toBytes)(index, 4), 33);
10041
+ data.set((0, import_math22.toBytes)(index, 4), 33);
10005
10042
  const bytes = (0, import_utils43.arrayify)((0, import_crypto8.computeHmac)("sha512", chainCode, data));
10006
10043
  const IL = bytes.slice(0, 32);
10007
10044
  const IR = bytes.slice(32);
10008
10045
  if (privateKey) {
10009
10046
  const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
10010
- const ki = (0, import_math23.bn)(IL).add(privateKey).mod(N).toBytes(32);
10047
+ const ki = (0, import_math22.bn)(IL).add(privateKey).mod(N).toBytes(32);
10011
10048
  return new HDWallet({
10012
10049
  privateKey: ki,
10013
10050
  chainCode: IR,
@@ -10053,7 +10090,7 @@ var HDWallet = class {
10053
10090
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
10054
10091
  const depth = (0, import_utils43.hexlify)(Uint8Array.from([this.depth]));
10055
10092
  const parentFingerprint = this.parentFingerprint;
10056
- const index = (0, import_math23.toHex)(this.index, 4);
10093
+ const index = (0, import_math22.toHex)(this.index, 4);
10057
10094
  const chainCode = this.chainCode;
10058
10095
  const key = this.privateKey != null && !isPublic ? (0, import_utils43.concat)(["0x00", this.privateKey]) : this.publicKey;
10059
10096
  const extendedKey = (0, import_utils43.arrayify)((0, import_utils43.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
@@ -10073,7 +10110,7 @@ var HDWallet = class {
10073
10110
  });
10074
10111
  }
10075
10112
  static fromExtendedKey(extendedKey) {
10076
- const decoded = (0, import_utils43.hexlify)((0, import_math23.toBytes)((0, import_utils43.decodeBase58)(extendedKey)));
10113
+ const decoded = (0, import_utils43.hexlify)((0, import_math22.toBytes)((0, import_utils43.decodeBase58)(extendedKey)));
10077
10114
  const bytes = (0, import_utils43.arrayify)(decoded);
10078
10115
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
10079
10116
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
@@ -10392,7 +10429,7 @@ async function setupTestProviderAndWallets({
10392
10429
  } = {}) {
10393
10430
  Symbol.dispose ??= Symbol("Symbol.dispose");
10394
10431
  const walletsConfig = new WalletsConfig(
10395
- nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? import_utils45.defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
10432
+ nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V2?.base_asset_id ?? import_utils45.defaultSnapshotConfigs.chainConfig.consensus_parameters.V2.base_asset_id,
10396
10433
  {
10397
10434
  ...defaultWalletConfigOptions,
10398
10435
  ...walletsConfigOptions
@@ -10442,7 +10479,7 @@ async function setupTestProviderAndWallets({
10442
10479
  // src/test-utils/test-message.ts
10443
10480
  var import_address8 = require("@fuel-ts/address");
10444
10481
  var import_crypto10 = require("@fuel-ts/crypto");
10445
- var import_math24 = require("@fuel-ts/math");
10482
+ var import_math23 = require("@fuel-ts/math");
10446
10483
  var import_utils46 = require("@fuel-ts/utils");
10447
10484
  var TestMessage = class {
10448
10485
  sender;
@@ -10479,7 +10516,7 @@ var TestMessage = class {
10479
10516
  sender: this.sender.toB256(),
10480
10517
  recipient: recipient?.toB256() ?? this.recipient.toB256(),
10481
10518
  nonce: this.nonce,
10482
- amount: (0, import_math24.bn)(this.amount).toNumber(),
10519
+ amount: (0, import_math23.bn)(this.amount).toNumber(),
10483
10520
  data,
10484
10521
  da_height: this.da_height
10485
10522
  };