@fuel-ts/account 0.0.0-rc-2037-20240411135757 → 0.0.0-rc-1976-20240411153008

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 +98 -65
  3. package/dist/index.global.js.map +1 -1
  4. package/dist/index.js +135 -104
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +96 -65
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/predicate/predicate.d.ts +1 -9
  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 +1 -2
  13. package/dist/providers/coin.d.ts.map +1 -1
  14. package/dist/providers/message.d.ts +0 -1
  15. package/dist/providers/message.d.ts.map +1 -1
  16. package/dist/providers/provider.d.ts +7 -0
  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 +25 -4
  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 +102 -51
  27. package/dist/test-utils.global.js.map +1 -1
  28. package/dist/test-utils.js +138 -89
  29. package/dist/test-utils.js.map +1 -1
  30. package/dist/test-utils.mjs +99 -50
  31. package/dist/test-utils.mjs.map +1 -1
  32. package/package.json +16 -16
@@ -32486,7 +32486,8 @@ 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
- }
32489
+ },
32490
+ base_asset_id: "0x0000000000000000000000000000000000000000000000000000000000000000"
32490
32491
  },
32491
32492
  gas_costs: {
32492
32493
  add: 1,
@@ -34755,10 +34756,6 @@ This unreleased fuel-core build may include features and updates not yet support
34755
34756
  }
34756
34757
  };
34757
34758
 
34758
- // ../address/dist/configs.mjs
34759
- var ZeroBytes32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
34760
- var BaseAssetId = ZeroBytes32;
34761
-
34762
34759
  // ../math/dist/index.mjs
34763
34760
  var import_bn = __toESM(require_bn(), 1);
34764
34761
  var DEFAULT_PRECISION = 9;
@@ -34989,11 +34986,11 @@ This unreleased fuel-core build may include features and updates not yet support
34989
34986
  let max2;
34990
34987
  if (Array.isArray(coinQuantityLike)) {
34991
34988
  amount = coinQuantityLike[0];
34992
- assetId = coinQuantityLike[1] ?? BaseAssetId;
34993
- max2 = coinQuantityLike[2] ?? void 0;
34989
+ assetId = coinQuantityLike[1];
34990
+ max2 = coinQuantityLike[2];
34994
34991
  } else {
34995
34992
  amount = coinQuantityLike.amount;
34996
- assetId = coinQuantityLike.assetId ?? BaseAssetId;
34993
+ assetId = coinQuantityLike.assetId;
34997
34994
  max2 = coinQuantityLike.max ?? void 0;
34998
34995
  }
34999
34996
  const bnAmount = bn(amount);
@@ -42329,6 +42326,9 @@ ${MessageCoinFragmentFragmentDoc}`;
42329
42326
  }
42330
42327
  };
42331
42328
 
42329
+ // ../address/dist/configs.mjs
42330
+ var ZeroBytes32 = "0x0000000000000000000000000000000000000000000000000000000000000000";
42331
+
42332
42332
  // src/providers/transaction-request/input.ts
42333
42333
  var inputify = (value) => {
42334
42334
  const { type: type3 } = value;
@@ -42929,6 +42929,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
42929
42929
  outputs = [];
42930
42930
  /** List of witnesses */
42931
42931
  witnesses = [];
42932
+ /** Base asset ID - should be fetched from the chain */
42933
+ baseAssetId;
42932
42934
  /**
42933
42935
  * Constructor for initializing a base transaction request.
42934
42936
  *
@@ -42941,8 +42943,9 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
42941
42943
  witnessLimit,
42942
42944
  inputs,
42943
42945
  outputs,
42944
- witnesses
42945
- } = {}) {
42946
+ witnesses,
42947
+ baseAssetId
42948
+ }) {
42946
42949
  this.gasPrice = bn(gasPrice);
42947
42950
  this.maturity = maturity ?? 0;
42948
42951
  this.witnessLimit = witnessLimit ? bn(witnessLimit) : void 0;
@@ -42950,6 +42953,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
42950
42953
  this.inputs = inputs ?? [];
42951
42954
  this.outputs = outputs ?? [];
42952
42955
  this.witnesses = witnesses ?? [];
42956
+ this.baseAssetId = baseAssetId;
42953
42957
  }
42954
42958
  static getPolicyMeta(req) {
42955
42959
  let policyTypes = 0;
@@ -43143,8 +43147,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43143
43147
  * @param predicate - Predicate bytes.
43144
43148
  * @param predicateData - Predicate data bytes.
43145
43149
  */
43146
- addCoinInput(coin) {
43147
- const { assetId, owner, amount, id, predicate } = coin;
43150
+ addCoinInput(coin, predicate) {
43151
+ const { assetId, owner, amount } = coin;
43148
43152
  let witnessIndex;
43149
43153
  if (predicate) {
43150
43154
  witnessIndex = 0;
@@ -43155,14 +43159,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43155
43159
  }
43156
43160
  }
43157
43161
  const input = {
43158
- id,
43162
+ ...coin,
43159
43163
  type: InputType.Coin,
43160
43164
  owner: owner.toB256(),
43161
43165
  amount,
43162
43166
  assetId,
43163
43167
  txPointer: "0x00000000000000000000000000000000",
43164
43168
  witnessIndex,
43165
- predicate
43169
+ predicate: predicate?.bytes
43166
43170
  };
43167
43171
  this.pushInput(input);
43168
43172
  this.addChangeOutput(owner, assetId);
@@ -43173,11 +43177,9 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43173
43177
  *
43174
43178
  * @param message - Message resource.
43175
43179
  * @param predicate - Predicate bytes.
43176
- * @param predicateData - Predicate data bytes.
43177
43180
  */
43178
- addMessageInput(message) {
43179
- const { recipient, sender, amount, predicate, nonce } = message;
43180
- const assetId = BaseAssetId;
43181
+ addMessageInput(message, predicate) {
43182
+ const { recipient, sender, amount } = message;
43181
43183
  let witnessIndex;
43182
43184
  if (predicate) {
43183
43185
  witnessIndex = 0;
@@ -43188,16 +43190,16 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43188
43190
  }
43189
43191
  }
43190
43192
  const input = {
43191
- nonce,
43193
+ ...message,
43192
43194
  type: InputType.Message,
43193
43195
  sender: sender.toB256(),
43194
43196
  recipient: recipient.toB256(),
43195
43197
  amount,
43196
43198
  witnessIndex,
43197
- predicate
43199
+ predicate: predicate?.bytes
43198
43200
  };
43199
43201
  this.pushInput(input);
43200
- this.addChangeOutput(recipient, assetId);
43202
+ this.addChangeOutput(recipient, this.baseAssetId);
43201
43203
  }
43202
43204
  /**
43203
43205
  * Adds a single resource to the transaction by adding a coin/message input and a
@@ -43225,6 +43227,32 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43225
43227
  resources.forEach((resource) => this.addResource(resource));
43226
43228
  return this;
43227
43229
  }
43230
+ /**
43231
+ * Adds multiple resources to the transaction by adding coin/message inputs and change
43232
+ * outputs from the related assetIds.
43233
+ *
43234
+ * @param resources - The resources to add.
43235
+ * @returns This transaction.
43236
+ */
43237
+ addPredicateResource(resource, predicate) {
43238
+ if (isCoin(resource)) {
43239
+ this.addCoinInput(resource, predicate);
43240
+ } else {
43241
+ this.addMessageInput(resource, predicate);
43242
+ }
43243
+ return this;
43244
+ }
43245
+ /**
43246
+ * Adds multiple predicate coin/message inputs to the transaction and change outputs
43247
+ * from the related assetIds.
43248
+ *
43249
+ * @param resources - The resources to add.
43250
+ * @returns This transaction.
43251
+ */
43252
+ addPredicateResources(resources, predicate) {
43253
+ resources.forEach((resource) => this.addPredicateResource(resource, predicate));
43254
+ return this;
43255
+ }
43228
43256
  /**
43229
43257
  * Adds a coin output to the transaction.
43230
43258
  *
@@ -43232,12 +43260,12 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43232
43260
  * @param amount - Amount of coin.
43233
43261
  * @param assetId - Asset ID of coin.
43234
43262
  */
43235
- addCoinOutput(to, amount, assetId = BaseAssetId) {
43263
+ addCoinOutput(to, amount, assetId) {
43236
43264
  this.pushOutput({
43237
43265
  type: OutputType.Coin,
43238
43266
  to: addressify(to).toB256(),
43239
43267
  amount,
43240
- assetId
43268
+ assetId: assetId ?? this.baseAssetId
43241
43269
  });
43242
43270
  return this;
43243
43271
  }
@@ -43264,7 +43292,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43264
43292
  * @param to - Address of the owner.
43265
43293
  * @param assetId - Asset ID of coin.
43266
43294
  */
43267
- addChangeOutput(to, assetId = BaseAssetId) {
43295
+ addChangeOutput(to, assetId) {
43268
43296
  const changeOutput = this.getChangeOutputs().find(
43269
43297
  (output3) => hexlify(output3.assetId) === assetId
43270
43298
  );
@@ -43272,7 +43300,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43272
43300
  this.pushOutput({
43273
43301
  type: OutputType.Change,
43274
43302
  to: addressify(to).toB256(),
43275
- assetId
43303
+ assetId: assetId ?? this.baseAssetId
43276
43304
  });
43277
43305
  }
43278
43306
  }
@@ -43354,7 +43382,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43354
43382
  ]);
43355
43383
  }
43356
43384
  };
43357
- updateAssetInput(BaseAssetId, bn(1e11));
43385
+ updateAssetInput(this.baseAssetId, bn(1e11));
43358
43386
  quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
43359
43387
  }
43360
43388
  /**
@@ -43511,12 +43539,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43511
43539
  *
43512
43540
  * @param createTransactionRequestLike - The initial values for the instance
43513
43541
  */
43514
- constructor({
43515
- bytecodeWitnessIndex,
43516
- salt,
43517
- storageSlots,
43518
- ...rest
43519
- } = {}) {
43542
+ constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
43520
43543
  super(rest);
43521
43544
  this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
43522
43545
  this.salt = hexlify(salt ?? ZeroBytes32);
@@ -43631,7 +43654,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43631
43654
  *
43632
43655
  * @param scriptTransactionRequestLike - The initial values for the instance.
43633
43656
  */
43634
- constructor({ script, scriptData, gasLimit, ...rest } = {}) {
43657
+ constructor({ script, scriptData, gasLimit, ...rest }) {
43635
43658
  super(rest);
43636
43659
  this.gasLimit = bn(gasLimit);
43637
43660
  this.script = arrayify(script ?? returnZeroScript.bytes);
@@ -44730,6 +44753,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
44730
44753
  gasPerByte: bn(feeParams.gasPerByte),
44731
44754
  maxMessageDataLength: bn(predicateParams.maxMessageDataLength),
44732
44755
  chainId: bn(consensusParameters.chainId),
44756
+ baseAssetId: consensusParameters.baseAssetId,
44733
44757
  gasCosts
44734
44758
  },
44735
44759
  gasCosts,
@@ -44972,6 +44996,17 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
44972
44996
  } = this.getChain();
44973
44997
  return chainId.toNumber();
44974
44998
  }
44999
+ /**
45000
+ * Returns the base asset ID
45001
+ *
45002
+ * @returns A promise that resolves to the base asset ID
45003
+ */
45004
+ getBaseAssetId() {
45005
+ const {
45006
+ consensusParameters: { baseAssetId }
45007
+ } = this.getChain();
45008
+ return baseAssetId;
45009
+ }
44975
45010
  /**
44976
45011
  * Submits a transaction to the chain to be executed.
44977
45012
  *
@@ -45833,8 +45868,9 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
45833
45868
  * @param assetId - The asset ID to check the balance for.
45834
45869
  * @returns A promise that resolves to the balance amount.
45835
45870
  */
45836
- async getBalance(assetId = BaseAssetId) {
45837
- const amount = await this.provider.getBalance(this.address, assetId);
45871
+ async getBalance(assetId) {
45872
+ const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
45873
+ const amount = await this.provider.getBalance(this.address, assetIdToFetch);
45838
45874
  return amount;
45839
45875
  }
45840
45876
  /**
@@ -45872,9 +45908,10 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
45872
45908
  * @returns A promise that resolves when the resources are added to the transaction.
45873
45909
  */
45874
45910
  async fund(request, coinQuantities, fee) {
45911
+ const baseAssetId = this.provider.getBaseAssetId();
45875
45912
  const updatedQuantities = addAmountToAsset({
45876
45913
  amount: bn(fee),
45877
- assetId: BaseAssetId,
45914
+ assetId: baseAssetId,
45878
45915
  coinQuantities
45879
45916
  });
45880
45917
  const quantitiesDict = {};
@@ -45898,8 +45935,8 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
45898
45935
  quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
45899
45936
  cachedUtxos.push(input.id);
45900
45937
  }
45901
- } else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId]) {
45902
- quantitiesDict[BaseAssetId].owned = quantitiesDict[BaseAssetId].owned.add(input.amount);
45938
+ } else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
45939
+ quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
45903
45940
  cachedMessages.push(input.nonce);
45904
45941
  }
45905
45942
  }
@@ -45931,11 +45968,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
45931
45968
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
45932
45969
  * @returns A promise that resolves to the prepared transaction request.
45933
45970
  */
45934
- async createTransfer(destination, amount, assetId = BaseAssetId, txParams = {}) {
45971
+ async createTransfer(destination, amount, assetId, txParams = {}) {
45935
45972
  const { minGasPrice } = this.provider.getGasConfig();
45936
- const params = { gasPrice: minGasPrice, ...txParams };
45973
+ const baseAssetId = this.provider.getBaseAssetId();
45974
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
45975
+ const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
45937
45976
  const request = new ScriptTransactionRequest(params);
45938
- request.addCoinOutput(Address.fromAddressOrString(destination), amount, assetId);
45977
+ request.addCoinOutput(Address.fromAddressOrString(destination), amount, assetIdToTransfer);
45939
45978
  const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
45940
45979
  estimateTxDependencies: true,
45941
45980
  resourcesOwner: this
@@ -45961,14 +46000,15 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
45961
46000
  * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
45962
46001
  * @returns A promise that resolves to the transaction response.
45963
46002
  */
45964
- async transfer(destination, amount, assetId = BaseAssetId, txParams = {}) {
46003
+ async transfer(destination, amount, assetId, txParams = {}) {
45965
46004
  if (bn(amount).lte(0)) {
45966
46005
  throw new FuelError(
45967
46006
  ErrorCode.INVALID_TRANSFER_AMOUNT,
45968
46007
  "Transfer amount must be a positive number."
45969
46008
  );
45970
46009
  }
45971
- const request = await this.createTransfer(destination, amount, assetId, txParams);
46010
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
46011
+ const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
45972
46012
  return this.sendTransaction(request, { estimateTxDependencies: false });
45973
46013
  }
45974
46014
  /**
@@ -45980,7 +46020,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
45980
46020
  * @param txParams - The optional transaction parameters.
45981
46021
  * @returns A promise that resolves to the transaction response.
45982
46022
  */
45983
- async transferToContract(contractId, amount, assetId = BaseAssetId, txParams = {}) {
46023
+ async transferToContract(contractId, amount, assetId, txParams = {}) {
45984
46024
  if (bn(amount).lte(0)) {
45985
46025
  throw new FuelError(
45986
46026
  ErrorCode.INVALID_TRANSFER_AMOUNT,
@@ -45989,11 +46029,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
45989
46029
  }
45990
46030
  const contractAddress = Address.fromAddressOrString(contractId);
45991
46031
  const { minGasPrice } = this.provider.getGasConfig();
45992
- const params = { gasPrice: minGasPrice, ...txParams };
46032
+ const baseAssetId = this.provider.getBaseAssetId();
46033
+ const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
46034
+ const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
45993
46035
  const { script, scriptData } = await assembleTransferToContractScript({
45994
46036
  hexlifiedContractId: contractAddress.toB256(),
45995
46037
  amountToTransfer: bn(amount),
45996
- assetId
46038
+ assetId: assetIdToTransfer
45997
46039
  });
45998
46040
  const request = new ScriptTransactionRequest({
45999
46041
  ...params,
@@ -46003,7 +46045,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
46003
46045
  request.addContractInputAndOutput(contractAddress);
46004
46046
  const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
46005
46047
  request,
46006
- [{ amount: bn(amount), assetId: String(assetId) }]
46048
+ [{ amount: bn(amount), assetId: String(assetIdToTransfer) }]
46007
46049
  );
46008
46050
  request.gasLimit = bn(params.gasLimit ?? gasUsed);
46009
46051
  this.validateGas({
@@ -46025,6 +46067,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
46025
46067
  */
46026
46068
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
46027
46069
  const { minGasPrice } = this.provider.getGasConfig();
46070
+ const baseAssetId = this.provider.getBaseAssetId();
46028
46071
  const recipientAddress = Address.fromAddressOrString(recipient);
46029
46072
  const recipientDataArray = arrayify(
46030
46073
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
@@ -46037,9 +46080,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
46037
46080
  ...recipientDataArray,
46038
46081
  ...amountDataArray
46039
46082
  ]);
46040
- const params = { script, gasPrice: minGasPrice, ...txParams };
46083
+ const params = {
46084
+ script,
46085
+ gasPrice: minGasPrice,
46086
+ baseAssetId,
46087
+ ...txParams
46088
+ };
46041
46089
  const request = new ScriptTransactionRequest(params);
46042
- const forwardingQuantities = [{ amount: bn(amount), assetId: BaseAssetId }];
46090
+ const forwardingQuantities = [{ amount: bn(amount), assetId: baseAssetId }];
46043
46091
  const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
46044
46092
  request,
46045
46093
  forwardingQuantities
@@ -50471,7 +50519,9 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
50471
50519
  );
50472
50520
  const resources = await genesisWallet.getResourcesToSpend(quantities);
50473
50521
  const { minGasPrice } = genesisWallet.provider.getGasConfig();
50522
+ const baseAssetId = genesisWallet.provider.getBaseAssetId();
50474
50523
  const request = new ScriptTransactionRequest({
50524
+ baseAssetId,
50475
50525
  gasLimit: 1e4,
50476
50526
  gasPrice: minGasPrice
50477
50527
  });
@@ -50601,7 +50651,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
50601
50651
  {
50602
50652
  owner: signer.address.toHexString(),
50603
50653
  amount: toHex(1e9),
50604
- asset_id: BaseAssetId
50654
+ asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes32
50605
50655
  }
50606
50656
  ]
50607
50657
  }
@@ -50667,9 +50717,10 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
50667
50717
  })
50668
50718
  );
50669
50719
  var generateWallets = async (count, provider) => {
50720
+ const baseAssetId = provider.getBaseAssetId();
50670
50721
  const wallets = [];
50671
50722
  for (let i = 0; i < count; i += 1) {
50672
- const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId]]);
50723
+ const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
50673
50724
  wallets.push(wallet);
50674
50725
  }
50675
50726
  return wallets;