@fuel-ts/account 0.0.0-rc-2143-20240424152333 → 0.0.0-rc-1976-20240424153519
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.
- package/README.md +2 -2
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +57 -41
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +93 -79
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -41
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +2 -2
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +7 -0
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +5 -5
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/utils/merge-quantities.d.ts +1 -1
- package/dist/providers/utils/merge-quantities.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +2 -4
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +60 -44
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +95 -81
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +57 -43
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +15 -15
package/dist/test-utils.mjs
CHANGED
@@ -24,14 +24,12 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
-
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
27
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
29
28
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
29
|
import { bn as bn17 } from "@fuel-ts/math";
|
31
30
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
31
|
|
33
32
|
// src/providers/coin-quantity.ts
|
34
|
-
import { BaseAssetId } from "@fuel-ts/address/configs";
|
35
33
|
import { bn } from "@fuel-ts/math";
|
36
34
|
import { hexlify } from "@fuel-ts/utils";
|
37
35
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -40,11 +38,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
40
38
|
let max2;
|
41
39
|
if (Array.isArray(coinQuantityLike)) {
|
42
40
|
amount = coinQuantityLike[0];
|
43
|
-
assetId = coinQuantityLike[1]
|
44
|
-
max2 = coinQuantityLike[2]
|
41
|
+
assetId = coinQuantityLike[1];
|
42
|
+
max2 = coinQuantityLike[2];
|
45
43
|
} else {
|
46
44
|
amount = coinQuantityLike.amount;
|
47
|
-
assetId = coinQuantityLike.assetId
|
45
|
+
assetId = coinQuantityLike.assetId;
|
48
46
|
max2 = coinQuantityLike.max ?? void 0;
|
49
47
|
}
|
50
48
|
const bnAmount = bn(amount);
|
@@ -1162,7 +1160,7 @@ var outputify = (value) => {
|
|
1162
1160
|
// src/providers/transaction-request/transaction-request.ts
|
1163
1161
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1164
1162
|
import { Address, addressify } from "@fuel-ts/address";
|
1165
|
-
import {
|
1163
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1166
1164
|
import { randomBytes } from "@fuel-ts/crypto";
|
1167
1165
|
import { bn as bn7 } from "@fuel-ts/math";
|
1168
1166
|
import {
|
@@ -1863,15 +1861,13 @@ var BaseTransactionRequest = class {
|
|
1863
1861
|
}
|
1864
1862
|
/**
|
1865
1863
|
* Adds a single message input to the transaction and a change output for the
|
1866
|
-
*
|
1864
|
+
* asset against the message
|
1867
1865
|
*
|
1868
1866
|
* @param message - Message resource.
|
1869
1867
|
* @param predicate - Predicate bytes.
|
1870
|
-
* @param predicateData - Predicate data bytes.
|
1871
1868
|
*/
|
1872
1869
|
addMessageInput(message, predicate) {
|
1873
|
-
const { recipient, sender, amount } = message;
|
1874
|
-
const assetId = BaseAssetId2;
|
1870
|
+
const { recipient, sender, amount, assetId } = message;
|
1875
1871
|
let witnessIndex;
|
1876
1872
|
if (predicate) {
|
1877
1873
|
witnessIndex = 0;
|
@@ -1952,7 +1948,7 @@ var BaseTransactionRequest = class {
|
|
1952
1948
|
* @param amount - Amount of coin.
|
1953
1949
|
* @param assetId - Asset ID of coin.
|
1954
1950
|
*/
|
1955
|
-
addCoinOutput(to, amount, assetId
|
1951
|
+
addCoinOutput(to, amount, assetId) {
|
1956
1952
|
this.pushOutput({
|
1957
1953
|
type: OutputType2.Coin,
|
1958
1954
|
to: addressify(to).toB256(),
|
@@ -1984,7 +1980,7 @@ var BaseTransactionRequest = class {
|
|
1984
1980
|
* @param to - Address of the owner.
|
1985
1981
|
* @param assetId - Asset ID of coin.
|
1986
1982
|
*/
|
1987
|
-
addChangeOutput(to, assetId
|
1983
|
+
addChangeOutput(to, assetId) {
|
1988
1984
|
const changeOutput = this.getChangeOutputs().find(
|
1989
1985
|
(output) => hexlify7(output.assetId) === assetId
|
1990
1986
|
);
|
@@ -2041,8 +2037,9 @@ var BaseTransactionRequest = class {
|
|
2041
2037
|
* quantities array.
|
2042
2038
|
*
|
2043
2039
|
* @param quantities - CoinQuantity Array.
|
2040
|
+
* @param baseAssetId - The base asset to fund the transaction.
|
2044
2041
|
*/
|
2045
|
-
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2042
|
+
fundWithFakeUtxos(quantities, baseAssetId, resourcesOwner) {
|
2046
2043
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2047
2044
|
if ("assetId" in input) {
|
2048
2045
|
return input.assetId === assetId;
|
@@ -2068,7 +2065,7 @@ var BaseTransactionRequest = class {
|
|
2068
2065
|
]);
|
2069
2066
|
}
|
2070
2067
|
};
|
2071
|
-
updateAssetInput(
|
2068
|
+
updateAssetInput(baseAssetId, bn7(1e11));
|
2072
2069
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2073
2070
|
}
|
2074
2071
|
/**
|
@@ -2238,12 +2235,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2238
2235
|
*
|
2239
2236
|
* @param createTransactionRequestLike - The initial values for the instance
|
2240
2237
|
*/
|
2241
|
-
constructor({
|
2242
|
-
bytecodeWitnessIndex,
|
2243
|
-
salt,
|
2244
|
-
storageSlots,
|
2245
|
-
...rest
|
2246
|
-
} = {}) {
|
2238
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2247
2239
|
super(rest);
|
2248
2240
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2249
2241
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -3457,7 +3449,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3457
3449
|
}
|
3458
3450
|
|
3459
3451
|
// src/providers/utils/merge-quantities.ts
|
3460
|
-
var mergeQuantities = (
|
3452
|
+
var mergeQuantities = (...coinQuantities) => {
|
3461
3453
|
const resultMap = {};
|
3462
3454
|
function addToMap({ amount, assetId }) {
|
3463
3455
|
if (resultMap[assetId]) {
|
@@ -3466,8 +3458,7 @@ var mergeQuantities = (arr1, arr2) => {
|
|
3466
3458
|
resultMap[assetId] = amount;
|
3467
3459
|
}
|
3468
3460
|
}
|
3469
|
-
|
3470
|
-
arr2.forEach(addToMap);
|
3461
|
+
coinQuantities.forEach((arr) => arr.forEach(addToMap));
|
3471
3462
|
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
3472
3463
|
};
|
3473
3464
|
|
@@ -3495,6 +3486,7 @@ var processGqlChain = (chain) => {
|
|
3495
3486
|
gasPerByte: bn15(feeParams.gasPerByte),
|
3496
3487
|
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3497
3488
|
chainId: bn15(consensusParameters.chainId),
|
3489
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3498
3490
|
gasCosts
|
3499
3491
|
},
|
3500
3492
|
gasCosts,
|
@@ -3737,6 +3729,17 @@ var _Provider = class {
|
|
3737
3729
|
} = this.getChain();
|
3738
3730
|
return chainId.toNumber();
|
3739
3731
|
}
|
3732
|
+
/**
|
3733
|
+
* Returns the base asset ID
|
3734
|
+
*
|
3735
|
+
* @returns A promise that resolves to the base asset ID
|
3736
|
+
*/
|
3737
|
+
getBaseAssetId() {
|
3738
|
+
const {
|
3739
|
+
consensusParameters: { baseAssetId }
|
3740
|
+
} = this.getChain();
|
3741
|
+
return baseAssetId;
|
3742
|
+
}
|
3740
3743
|
/**
|
3741
3744
|
* Submits a transaction to the chain to be executed.
|
3742
3745
|
*
|
@@ -3967,9 +3970,10 @@ var _Provider = class {
|
|
3967
3970
|
const { minGasPrice } = this.getGasConfig();
|
3968
3971
|
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3969
3972
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3973
|
+
const baseAssetId = this.getBaseAssetId();
|
3970
3974
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3971
3975
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3972
|
-
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3976
|
+
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
3973
3977
|
if (isScriptTransaction) {
|
3974
3978
|
txRequestClone.gasLimit = bn15(0);
|
3975
3979
|
}
|
@@ -4634,8 +4638,9 @@ var Account = class extends AbstractAccount {
|
|
4634
4638
|
* @param assetId - The asset ID to check the balance for.
|
4635
4639
|
* @returns A promise that resolves to the balance amount.
|
4636
4640
|
*/
|
4637
|
-
async getBalance(assetId
|
4638
|
-
const
|
4641
|
+
async getBalance(assetId) {
|
4642
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4643
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4639
4644
|
return amount;
|
4640
4645
|
}
|
4641
4646
|
/**
|
@@ -4673,9 +4678,10 @@ var Account = class extends AbstractAccount {
|
|
4673
4678
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4674
4679
|
*/
|
4675
4680
|
async fund(request, coinQuantities, fee) {
|
4681
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4676
4682
|
const updatedQuantities = addAmountToAsset({
|
4677
4683
|
amount: bn17(fee),
|
4678
|
-
assetId:
|
4684
|
+
assetId: baseAssetId,
|
4679
4685
|
coinQuantities
|
4680
4686
|
});
|
4681
4687
|
const quantitiesDict = {};
|
@@ -4699,8 +4705,8 @@ var Account = class extends AbstractAccount {
|
|
4699
4705
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4700
4706
|
cachedUtxos.push(input.id);
|
4701
4707
|
}
|
4702
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4703
|
-
quantitiesDict[
|
4708
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4709
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4704
4710
|
cachedMessages.push(input.nonce);
|
4705
4711
|
}
|
4706
4712
|
}
|
@@ -4732,11 +4738,12 @@ var Account = class extends AbstractAccount {
|
|
4732
4738
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4733
4739
|
* @returns A promise that resolves to the prepared transaction request.
|
4734
4740
|
*/
|
4735
|
-
async createTransfer(destination, amount, assetId
|
4741
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4736
4742
|
const { minGasPrice } = this.provider.getGasConfig();
|
4743
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4737
4744
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4738
4745
|
const request = new ScriptTransactionRequest(params);
|
4739
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
4746
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4740
4747
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4741
4748
|
estimateTxDependencies: true,
|
4742
4749
|
resourcesOwner: this
|
@@ -4762,14 +4769,15 @@ var Account = class extends AbstractAccount {
|
|
4762
4769
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4763
4770
|
* @returns A promise that resolves to the transaction response.
|
4764
4771
|
*/
|
4765
|
-
async transfer(destination, amount, assetId
|
4772
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4766
4773
|
if (bn17(amount).lte(0)) {
|
4767
4774
|
throw new FuelError15(
|
4768
4775
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4769
4776
|
"Transfer amount must be a positive number."
|
4770
4777
|
);
|
4771
4778
|
}
|
4772
|
-
const
|
4779
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4780
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4773
4781
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4774
4782
|
}
|
4775
4783
|
/**
|
@@ -4781,7 +4789,7 @@ var Account = class extends AbstractAccount {
|
|
4781
4789
|
* @param txParams - The optional transaction parameters.
|
4782
4790
|
* @returns A promise that resolves to the transaction response.
|
4783
4791
|
*/
|
4784
|
-
async transferToContract(contractId, amount, assetId
|
4792
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4785
4793
|
if (bn17(amount).lte(0)) {
|
4786
4794
|
throw new FuelError15(
|
4787
4795
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
@@ -4790,11 +4798,12 @@ var Account = class extends AbstractAccount {
|
|
4790
4798
|
}
|
4791
4799
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4792
4800
|
const { minGasPrice } = this.provider.getGasConfig();
|
4801
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4793
4802
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4794
4803
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4795
4804
|
hexlifiedContractId: contractAddress.toB256(),
|
4796
4805
|
amountToTransfer: bn17(amount),
|
4797
|
-
assetId
|
4806
|
+
assetId: assetIdToTransfer
|
4798
4807
|
});
|
4799
4808
|
const request = new ScriptTransactionRequest({
|
4800
4809
|
...params,
|
@@ -4804,7 +4813,7 @@ var Account = class extends AbstractAccount {
|
|
4804
4813
|
request.addContractInputAndOutput(contractAddress);
|
4805
4814
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4806
4815
|
request,
|
4807
|
-
[{ amount: bn17(amount), assetId: String(
|
4816
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
4808
4817
|
);
|
4809
4818
|
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4810
4819
|
this.validateGas({
|
@@ -4826,6 +4835,7 @@ var Account = class extends AbstractAccount {
|
|
4826
4835
|
*/
|
4827
4836
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4828
4837
|
const { minGasPrice } = this.provider.getGasConfig();
|
4838
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4829
4839
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4830
4840
|
const recipientDataArray = arrayify14(
|
4831
4841
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -4838,9 +4848,13 @@ var Account = class extends AbstractAccount {
|
|
4838
4848
|
...recipientDataArray,
|
4839
4849
|
...amountDataArray
|
4840
4850
|
]);
|
4841
|
-
const params = {
|
4851
|
+
const params = {
|
4852
|
+
script,
|
4853
|
+
gasPrice: minGasPrice,
|
4854
|
+
...txParams
|
4855
|
+
};
|
4842
4856
|
const request = new ScriptTransactionRequest(params);
|
4843
|
-
const forwardingQuantities = [{ amount: bn17(amount), assetId:
|
4857
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
4844
4858
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4845
4859
|
request,
|
4846
4860
|
forwardingQuantities
|
@@ -8012,7 +8026,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8012
8026
|
};
|
8013
8027
|
|
8014
8028
|
// src/test-utils/launchNode.ts
|
8015
|
-
import {
|
8029
|
+
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
8016
8030
|
import { toHex as toHex2 } from "@fuel-ts/math";
|
8017
8031
|
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8018
8032
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
@@ -8058,7 +8072,6 @@ var launchNode = async ({
|
|
8058
8072
|
ip,
|
8059
8073
|
port,
|
8060
8074
|
args = [],
|
8061
|
-
fuelCorePath = void 0,
|
8062
8075
|
useSystemFuelCore = false,
|
8063
8076
|
loggingEnabled = true,
|
8064
8077
|
debugEnabled = false,
|
@@ -8079,7 +8092,7 @@ var launchNode = async ({
|
|
8079
8092
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
8080
8093
|
const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
|
8081
8094
|
const graphQLStartSubstring = "Binding GraphQL provider to";
|
8082
|
-
const binPath =
|
8095
|
+
const binPath = findBinPath("fuels-core", __dirname);
|
8083
8096
|
const command = useSystemFuelCore ? "fuel-core" : binPath;
|
8084
8097
|
const ipToUse = ip || "0.0.0.0";
|
8085
8098
|
const portToUse = port || (await getPortPromise({
|
@@ -8113,7 +8126,7 @@ var launchNode = async ({
|
|
8113
8126
|
{
|
8114
8127
|
owner: signer.address.toHexString(),
|
8115
8128
|
amount: toHex2(1e9),
|
8116
|
-
asset_id:
|
8129
|
+
asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
|
8117
8130
|
}
|
8118
8131
|
]
|
8119
8132
|
}
|
@@ -8179,9 +8192,10 @@ var launchNode = async ({
|
|
8179
8192
|
})
|
8180
8193
|
);
|
8181
8194
|
var generateWallets = async (count, provider) => {
|
8195
|
+
const baseAssetId = provider.getBaseAssetId();
|
8182
8196
|
const wallets = [];
|
8183
8197
|
for (let i = 0; i < count; i += 1) {
|
8184
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8198
|
+
const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
|
8185
8199
|
wallets.push(wallet);
|
8186
8200
|
}
|
8187
8201
|
return wallets;
|