@fuel-ts/account 0.0.0-rc-1976-20240412113424 → 0.0.0-rc-2037-20240412171107

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 (32) hide show
  1. package/dist/account.d.ts.map +1 -1
  2. package/dist/index.global.js +65 -98
  3. package/dist/index.global.js.map +1 -1
  4. package/dist/index.js +103 -134
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +65 -96
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/predicate/predicate.d.ts +9 -1
  9. package/dist/predicate/predicate.d.ts.map +1 -1
  10. package/dist/providers/coin-quantity.d.ts +2 -2
  11. package/dist/providers/coin-quantity.d.ts.map +1 -1
  12. package/dist/providers/coin.d.ts +2 -1
  13. package/dist/providers/coin.d.ts.map +1 -1
  14. package/dist/providers/message.d.ts +1 -0
  15. package/dist/providers/message.d.ts.map +1 -1
  16. package/dist/providers/provider.d.ts +0 -7
  17. package/dist/providers/provider.d.ts.map +1 -1
  18. package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
  19. package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
  20. package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
  21. package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
  22. package/dist/providers/transaction-request/transaction-request.d.ts +4 -25
  23. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  24. package/dist/test-utils/launchNode.d.ts.map +1 -1
  25. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  26. package/dist/test-utils.global.js +51 -102
  27. package/dist/test-utils.global.js.map +1 -1
  28. package/dist/test-utils.js +88 -137
  29. package/dist/test-utils.js.map +1 -1
  30. package/dist/test-utils.mjs +50 -99
  31. package/dist/test-utils.mjs.map +1 -1
  32. package/package.json +16 -16
@@ -32486,8 +32486,7 @@ This unreleased fuel-core build may include features and updates not yet support
32486
32486
  fee_params: {
32487
32487
  gas_price_factor: 92,
32488
32488
  gas_per_byte: 4
32489
- },
32490
- base_asset_id: "0x0000000000000000000000000000000000000000000000000000000000000000"
32489
+ }
32491
32490
  },
32492
32491
  gas_costs: {
32493
32492
  add: 1,
@@ -34756,6 +34755,10 @@ This unreleased fuel-core build may include features and updates not yet support
34756
34755
  }
34757
34756
  };
34758
34757
 
34758
+ // ../address/dist/configs.mjs
34759
+ var ZeroBytes32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
34760
+ var BaseAssetId = ZeroBytes32;
34761
+
34759
34762
  // ../math/dist/index.mjs
34760
34763
  var import_bn = __toESM(require_bn(), 1);
34761
34764
  var DEFAULT_PRECISION = 9;
@@ -34986,11 +34989,11 @@ This unreleased fuel-core build may include features and updates not yet support
34986
34989
  let max2;
34987
34990
  if (Array.isArray(coinQuantityLike)) {
34988
34991
  amount = coinQuantityLike[0];
34989
- assetId = coinQuantityLike[1];
34990
- max2 = coinQuantityLike[2];
34992
+ assetId = coinQuantityLike[1] ?? BaseAssetId;
34993
+ max2 = coinQuantityLike[2] ?? void 0;
34991
34994
  } else {
34992
34995
  amount = coinQuantityLike.amount;
34993
- assetId = coinQuantityLike.assetId;
34996
+ assetId = coinQuantityLike.assetId ?? BaseAssetId;
34994
34997
  max2 = coinQuantityLike.max ?? void 0;
34995
34998
  }
34996
34999
  const bnAmount = bn(amount);
@@ -42327,9 +42330,6 @@ ${MessageCoinFragmentFragmentDoc}`;
42327
42330
  }
42328
42331
  };
42329
42332
 
42330
- // ../address/dist/configs.mjs
42331
- var ZeroBytes32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
42332
-
42333
42333
  // src/providers/transaction-request/input.ts
42334
42334
  var inputify = (value) => {
42335
42335
  const { type: type3 } = value;
@@ -42930,8 +42930,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
42930
42930
  outputs = [];
42931
42931
  /** List of witnesses */
42932
42932
  witnesses = [];
42933
- /** Base asset ID - should be fetched from the chain */
42934
- baseAssetId;
42935
42933
  /**
42936
42934
  * Constructor for initializing a base transaction request.
42937
42935
  *
@@ -42944,9 +42942,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
42944
42942
  witnessLimit,
42945
42943
  inputs,
42946
42944
  outputs,
42947
- witnesses,
42948
- baseAssetId
42949
- }) {
42945
+ witnesses
42946
+ } = {}) {
42950
42947
  this.gasPrice = bn(gasPrice);
42951
42948
  this.maturity = maturity ?? 0;
42952
42949
  this.witnessLimit = witnessLimit ? bn(witnessLimit) : void 0;
@@ -42954,7 +42951,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
42954
42951
  this.inputs = inputs ?? [];
42955
42952
  this.outputs = outputs ?? [];
42956
42953
  this.witnesses = witnesses ?? [];
42957
- this.baseAssetId = baseAssetId;
42958
42954
  }
42959
42955
  static getPolicyMeta(req) {
42960
42956
  let policyTypes = 0;
@@ -43148,8 +43144,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43148
43144
  * @param predicate - Predicate bytes.
43149
43145
  * @param predicateData - Predicate data bytes.
43150
43146
  */
43151
- addCoinInput(coin, predicate) {
43152
- const { assetId, owner, amount } = coin;
43147
+ addCoinInput(coin) {
43148
+ const { assetId, owner, amount, id, predicate } = coin;
43153
43149
  let witnessIndex;
43154
43150
  if (predicate) {
43155
43151
  witnessIndex = 0;
@@ -43160,14 +43156,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43160
43156
  }
43161
43157
  }
43162
43158
  const input = {
43163
- ...coin,
43159
+ id,
43164
43160
  type: InputType.Coin,
43165
43161
  owner: owner.toB256(),
43166
43162
  amount,
43167
43163
  assetId,
43168
43164
  txPointer: "0x00000000000000000000000000000000",
43169
43165
  witnessIndex,
43170
- predicate: predicate?.bytes
43166
+ predicate
43171
43167
  };
43172
43168
  this.pushInput(input);
43173
43169
  this.addChangeOutput(owner, assetId);
@@ -43178,9 +43174,11 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43178
43174
  *
43179
43175
  * @param message - Message resource.
43180
43176
  * @param predicate - Predicate bytes.
43177
+ * @param predicateData - Predicate data bytes.
43181
43178
  */
43182
- addMessageInput(message, predicate) {
43183
- const { recipient, sender, amount } = message;
43179
+ addMessageInput(message) {
43180
+ const { recipient, sender, amount, predicate, nonce } = message;
43181
+ const assetId = BaseAssetId;
43184
43182
  let witnessIndex;
43185
43183
  if (predicate) {
43186
43184
  witnessIndex = 0;
@@ -43191,16 +43189,16 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43191
43189
  }
43192
43190
  }
43193
43191
  const input = {
43194
- ...message,
43192
+ nonce,
43195
43193
  type: InputType.Message,
43196
43194
  sender: sender.toB256(),
43197
43195
  recipient: recipient.toB256(),
43198
43196
  amount,
43199
43197
  witnessIndex,
43200
- predicate: predicate?.bytes
43198
+ predicate
43201
43199
  };
43202
43200
  this.pushInput(input);
43203
- this.addChangeOutput(recipient, this.baseAssetId);
43201
+ this.addChangeOutput(recipient, assetId);
43204
43202
  }
43205
43203
  /**
43206
43204
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -43228,32 +43226,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43228
43226
  resources.forEach((resource) => this.addResource(resource));
43229
43227
  return this;
43230
43228
  }
43231
- /**
43232
- * Adds multiple resources to the transaction by adding coin/message inputs and change
43233
- * outputs from the related assetIds.
43234
- *
43235
- * @param resources - The resources to add.
43236
- * @returns This transaction.
43237
- */
43238
- addPredicateResource(resource, predicate) {
43239
- if (isCoin(resource)) {
43240
- this.addCoinInput(resource, predicate);
43241
- } else {
43242
- this.addMessageInput(resource, predicate);
43243
- }
43244
- return this;
43245
- }
43246
- /**
43247
- * Adds multiple predicate coin/message inputs to the transaction and change outputs
43248
- * from the related assetIds.
43249
- *
43250
- * @param resources - The resources to add.
43251
- * @returns This transaction.
43252
- */
43253
- addPredicateResources(resources, predicate) {
43254
- resources.forEach((resource) => this.addPredicateResource(resource, predicate));
43255
- return this;
43256
- }
43257
43229
  /**
43258
43230
  * Adds a coin output to the transaction.
43259
43231
  *
@@ -43261,12 +43233,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43261
43233
  * @param amount - Amount of coin.
43262
43234
  * @param assetId - Asset ID of coin.
43263
43235
  */
43264
- addCoinOutput(to, amount, assetId) {
43236
+ addCoinOutput(to, amount, assetId = BaseAssetId) {
43265
43237
  this.pushOutput({
43266
43238
  type: OutputType.Coin,
43267
43239
  to: addressify(to).toB256(),
43268
43240
  amount,
43269
- assetId: assetId ?? this.baseAssetId
43241
+ assetId
43270
43242
  });
43271
43243
  return this;
43272
43244
  }
@@ -43293,7 +43265,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43293
43265
  * @param to - Address of the owner.
43294
43266
  * @param assetId - Asset ID of coin.
43295
43267
  */
43296
- addChangeOutput(to, assetId) {
43268
+ addChangeOutput(to, assetId = BaseAssetId) {
43297
43269
  const changeOutput = this.getChangeOutputs().find(
43298
43270
  (output3) => hexlify(output3.assetId) === assetId
43299
43271
  );
@@ -43301,7 +43273,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43301
43273
  this.pushOutput({
43302
43274
  type: OutputType.Change,
43303
43275
  to: addressify(to).toB256(),
43304
- assetId: assetId ?? this.baseAssetId
43276
+ assetId
43305
43277
  });
43306
43278
  }
43307
43279
  }
@@ -43377,7 +43349,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43377
43349
  ]);
43378
43350
  }
43379
43351
  };
43380
- updateAssetInput(this.baseAssetId, bn(1e11));
43352
+ updateAssetInput(BaseAssetId, bn(1e11));
43381
43353
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
43382
43354
  }
43383
43355
  /**
@@ -43534,7 +43506,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43534
43506
  *
43535
43507
  * @param createTransactionRequestLike - The initial values for the instance
43536
43508
  */
43537
- constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
43509
+ constructor({
43510
+ bytecodeWitnessIndex,
43511
+ salt,
43512
+ storageSlots,
43513
+ ...rest
43514
+ } = {}) {
43538
43515
  super(rest);
43539
43516
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
43540
43517
  this.salt = hexlify(salt ?? ZeroBytes32);
@@ -43649,7 +43626,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43649
43626
  *
43650
43627
  * @param scriptTransactionRequestLike - The initial values for the instance.
43651
43628
  */
43652
- constructor({ script, scriptData, gasLimit, ...rest }) {
43629
+ constructor({ script, scriptData, gasLimit, ...rest } = {}) {
43653
43630
  super(rest);
43654
43631
  this.gasLimit = bn(gasLimit);
43655
43632
  this.script = arrayify(script ?? returnZeroScript.bytes);
@@ -44748,7 +44725,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
44748
44725
  gasPerByte: bn(feeParams.gasPerByte),
44749
44726
  maxMessageDataLength: bn(predicateParams.maxMessageDataLength),
44750
44727
  chainId: bn(consensusParameters.chainId),
44751
- baseAssetId: consensusParameters.baseAssetId,
44752
44728
  gasCosts
44753
44729
  },
44754
44730
  gasCosts,
@@ -44991,17 +44967,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
44991
44967
  } = this.getChain();
44992
44968
  return chainId.toNumber();
44993
44969
  }
44994
- /**
44995
- * Returns the base asset ID
44996
- *
44997
- * @returns A promise that resolves to the base asset ID
44998
- */
44999
- getBaseAssetId() {
45000
- const {
45001
- consensusParameters: { baseAssetId }
45002
- } = this.getChain();
45003
- return baseAssetId;
45004
- }
45005
44970
  /**
45006
44971
  * Submits a transaction to the chain to be executed.
45007
44972
  *
@@ -45890,9 +45855,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
45890
45855
  * @param assetId - The asset ID to check the balance for.
45891
45856
  * @returns A promise that resolves to the balance amount.
45892
45857
  */
45893
- async getBalance(assetId) {
45894
- const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
45895
- const amount = await this.provider.getBalance(this.address, assetIdToFetch);
45858
+ async getBalance(assetId = BaseAssetId) {
45859
+ const amount = await this.provider.getBalance(this.address, assetId);
45896
45860
  return amount;
45897
45861
  }
45898
45862
  /**
@@ -45930,10 +45894,9 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
45930
45894
  * @returns A promise that resolves when the resources are added to the transaction.
45931
45895
  */
45932
45896
  async fund(request, coinQuantities, fee) {
45933
- const baseAssetId = this.provider.getBaseAssetId();
45934
45897
  const updatedQuantities = addAmountToAsset({
45935
45898
  amount: bn(fee),
45936
- assetId: baseAssetId,
45899
+ assetId: BaseAssetId,
45937
45900
  coinQuantities
45938
45901
  });
45939
45902
  const quantitiesDict = {};
@@ -45957,8 +45920,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
45957
45920
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
45958
45921
  cachedUtxos.push(input.id);
45959
45922
  }
45960
- } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
45961
- quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
45923
+ } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId]) {
45924
+ quantitiesDict[BaseAssetId].owned = quantitiesDict[BaseAssetId].owned.add(input.amount);
45962
45925
  cachedMessages.push(input.nonce);
45963
45926
  }
45964
45927
  }
@@ -45990,13 +45953,11 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
45990
45953
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
45991
45954
  * @returns A promise that resolves to the prepared transaction request.
45992
45955
  */
45993
- async createTransfer(destination, amount, assetId, txParams = {}) {
45956
+ async createTransfer(destination, amount, assetId = BaseAssetId, txParams = {}) {
45994
45957
  const { minGasPrice } = this.provider.getGasConfig();
45995
- const baseAssetId = this.provider.getBaseAssetId();
45996
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
45997
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
45958
+ const params = { gasPrice: minGasPrice, ...txParams };
45998
45959
  const request = new ScriptTransactionRequest(params);
45999
- request.addCoinOutput(Address.fromAddressOrString(destination), amount, assetIdToTransfer);
45960
+ request.addCoinOutput(Address.fromAddressOrString(destination), amount, assetId);
46000
45961
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
46001
45962
  estimateTxDependencies: true,
46002
45963
  resourcesOwner: this
@@ -46022,15 +45983,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
46022
45983
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
46023
45984
  * @returns A promise that resolves to the transaction response.
46024
45985
  */
46025
- async transfer(destination, amount, assetId, txParams = {}) {
45986
+ async transfer(destination, amount, assetId = BaseAssetId, txParams = {}) {
46026
45987
  if (bn(amount).lte(0)) {
46027
45988
  throw new FuelError(
46028
45989
  ErrorCode.INVALID_TRANSFER_AMOUNT,
46029
45990
  "Transfer amount must be a positive number."
46030
45991
  );
46031
45992
  }
46032
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
46033
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
45993
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
46034
45994
  return this.sendTransaction(request, { estimateTxDependencies: false });
46035
45995
  }
46036
45996
  /**
@@ -46042,7 +46002,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
46042
46002
  * @param txParams - The optional transaction parameters.
46043
46003
  * @returns A promise that resolves to the transaction response.
46044
46004
  */
46045
- async transferToContract(contractId, amount, assetId, txParams = {}) {
46005
+ async transferToContract(contractId, amount, assetId = BaseAssetId, txParams = {}) {
46046
46006
  if (bn(amount).lte(0)) {
46047
46007
  throw new FuelError(
46048
46008
  ErrorCode.INVALID_TRANSFER_AMOUNT,
@@ -46051,13 +46011,11 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
46051
46011
  }
46052
46012
  const contractAddress = Address.fromAddressOrString(contractId);
46053
46013
  const { minGasPrice } = this.provider.getGasConfig();
46054
- const baseAssetId = this.provider.getBaseAssetId();
46055
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
46056
- const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
46014
+ const params = { gasPrice: minGasPrice, ...txParams };
46057
46015
  const { script, scriptData } = await assembleTransferToContractScript({
46058
46016
  hexlifiedContractId: contractAddress.toB256(),
46059
46017
  amountToTransfer: bn(amount),
46060
- assetId: assetIdToTransfer
46018
+ assetId
46061
46019
  });
46062
46020
  const request = new ScriptTransactionRequest({
46063
46021
  ...params,
@@ -46067,7 +46025,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
46067
46025
  request.addContractInputAndOutput(contractAddress);
46068
46026
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
46069
46027
  request,
46070
- [{ amount: bn(amount), assetId: String(assetIdToTransfer) }]
46028
+ [{ amount: bn(amount), assetId: String(assetId) }]
46071
46029
  );
46072
46030
  request.gasLimit = bn(params.gasLimit ?? gasUsed);
46073
46031
  this.validateGas({
@@ -46089,7 +46047,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
46089
46047
  */
46090
46048
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
46091
46049
  const { minGasPrice } = this.provider.getGasConfig();
46092
- const baseAssetId = this.provider.getBaseAssetId();
46093
46050
  const recipientAddress = Address.fromAddressOrString(recipient);
46094
46051
  const recipientDataArray = arrayify(
46095
46052
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -46102,14 +46059,9 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
46102
46059
  ...recipientDataArray,
46103
46060
  ...amountDataArray
46104
46061
  ]);
46105
- const params = {
46106
- script,
46107
- gasPrice: minGasPrice,
46108
- baseAssetId,
46109
- ...txParams
46110
- };
46062
+ const params = { script, gasPrice: minGasPrice, ...txParams };
46111
46063
  const request = new ScriptTransactionRequest(params);
46112
- const forwardingQuantities = [{ amount: bn(amount), assetId: baseAssetId }];
46064
+ const forwardingQuantities = [{ amount: bn(amount), assetId: BaseAssetId }];
46113
46065
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
46114
46066
  request,
46115
46067
  forwardingQuantities
@@ -50541,9 +50493,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
50541
50493
  );
50542
50494
  const resources = await genesisWallet.getResourcesToSpend(quantities);
50543
50495
  const { minGasPrice } = genesisWallet.provider.getGasConfig();
50544
- const baseAssetId = genesisWallet.provider.getBaseAssetId();
50545
50496
  const request = new ScriptTransactionRequest({
50546
- baseAssetId,
50547
50497
  gasLimit: 1e4,
50548
50498
  gasPrice: minGasPrice
50549
50499
  });
@@ -50673,7 +50623,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
50673
50623
  {
50674
50624
  owner: signer.address.toHexString(),
50675
50625
  amount: toHex(1e9),
50676
- asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes32
50626
+ asset_id: BaseAssetId
50677
50627
  }
50678
50628
  ]
50679
50629
  }
@@ -50739,10 +50689,9 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
50739
50689
  })
50740
50690
  );
50741
50691
  var generateWallets = async (count, provider) => {
50742
- const baseAssetId = provider.getBaseAssetId();
50743
50692
  const wallets = [];
50744
50693
  for (let i = 0; i < count; i += 1) {
50745
- const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
50694
+ const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId]]);
50746
50695
  wallets.push(wallet);
50747
50696
  }
50748
50697
  return wallets;