@fuel-ts/account 0.0.0-rc-1832-20240404134353 → 0.0.0-rc-1976-20240404170833
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/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +51 -31
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +88 -70
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -31
- 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/transaction-request.d.ts +5 -2
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +53 -32
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +89 -70
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +50 -31
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
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);
|
@@ -1151,7 +1149,7 @@ var outputify = (value) => {
|
|
1151
1149
|
|
1152
1150
|
// src/providers/transaction-request/transaction-request.ts
|
1153
1151
|
import { Address, addressify } from "@fuel-ts/address";
|
1154
|
-
import {
|
1152
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1155
1153
|
import { bn as bn7 } from "@fuel-ts/math";
|
1156
1154
|
import {
|
1157
1155
|
PolicyType,
|
@@ -1611,6 +1609,8 @@ var BaseTransactionRequest = class {
|
|
1611
1609
|
outputs = [];
|
1612
1610
|
/** List of witnesses */
|
1613
1611
|
witnesses = [];
|
1612
|
+
/** Base asset ID - should be fetched from the chain */
|
1613
|
+
baseAssetId = ZeroBytes324;
|
1614
1614
|
/**
|
1615
1615
|
* Constructor for initializing a base transaction request.
|
1616
1616
|
*
|
@@ -1623,7 +1623,8 @@ var BaseTransactionRequest = class {
|
|
1623
1623
|
witnessLimit,
|
1624
1624
|
inputs,
|
1625
1625
|
outputs,
|
1626
|
-
witnesses
|
1626
|
+
witnesses,
|
1627
|
+
baseAssetId
|
1627
1628
|
} = {}) {
|
1628
1629
|
this.gasPrice = bn7(gasPrice);
|
1629
1630
|
this.maturity = maturity ?? 0;
|
@@ -1632,6 +1633,7 @@ var BaseTransactionRequest = class {
|
|
1632
1633
|
this.inputs = inputs ?? [];
|
1633
1634
|
this.outputs = outputs ?? [];
|
1634
1635
|
this.witnesses = witnesses ?? [];
|
1636
|
+
this.baseAssetId = baseAssetId ?? ZeroBytes324;
|
1635
1637
|
}
|
1636
1638
|
static getPolicyMeta(req) {
|
1637
1639
|
let policyTypes = 0;
|
@@ -1856,11 +1858,9 @@ var BaseTransactionRequest = class {
|
|
1856
1858
|
*
|
1857
1859
|
* @param message - Message resource.
|
1858
1860
|
* @param predicate - Predicate bytes.
|
1859
|
-
* @param predicateData - Predicate data bytes.
|
1860
1861
|
*/
|
1861
1862
|
addMessageInput(message, predicate) {
|
1862
1863
|
const { recipient, sender, amount } = message;
|
1863
|
-
const assetId = BaseAssetId2;
|
1864
1864
|
let witnessIndex;
|
1865
1865
|
if (predicate) {
|
1866
1866
|
witnessIndex = 0;
|
@@ -1881,7 +1881,7 @@ var BaseTransactionRequest = class {
|
|
1881
1881
|
predicateData: predicate?.predicateDataBytes
|
1882
1882
|
};
|
1883
1883
|
this.pushInput(input);
|
1884
|
-
this.addChangeOutput(recipient,
|
1884
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1885
1885
|
}
|
1886
1886
|
/**
|
1887
1887
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1942,12 +1942,12 @@ var BaseTransactionRequest = class {
|
|
1942
1942
|
* @param amount - Amount of coin.
|
1943
1943
|
* @param assetId - Asset ID of coin.
|
1944
1944
|
*/
|
1945
|
-
addCoinOutput(to, amount, assetId
|
1945
|
+
addCoinOutput(to, amount, assetId) {
|
1946
1946
|
this.pushOutput({
|
1947
1947
|
type: OutputType2.Coin,
|
1948
1948
|
to: addressify(to).toB256(),
|
1949
1949
|
amount,
|
1950
|
-
assetId
|
1950
|
+
assetId: assetId ?? this.baseAssetId
|
1951
1951
|
});
|
1952
1952
|
return this;
|
1953
1953
|
}
|
@@ -1974,7 +1974,7 @@ var BaseTransactionRequest = class {
|
|
1974
1974
|
* @param to - Address of the owner.
|
1975
1975
|
* @param assetId - Asset ID of coin.
|
1976
1976
|
*/
|
1977
|
-
addChangeOutput(to, assetId
|
1977
|
+
addChangeOutput(to, assetId) {
|
1978
1978
|
const changeOutput = this.getChangeOutputs().find(
|
1979
1979
|
(output) => hexlify7(output.assetId) === assetId
|
1980
1980
|
);
|
@@ -1982,7 +1982,7 @@ var BaseTransactionRequest = class {
|
|
1982
1982
|
this.pushOutput({
|
1983
1983
|
type: OutputType2.Change,
|
1984
1984
|
to: addressify(to).toB256(),
|
1985
|
-
assetId
|
1985
|
+
assetId: assetId ?? this.baseAssetId
|
1986
1986
|
});
|
1987
1987
|
}
|
1988
1988
|
}
|
@@ -2064,7 +2064,7 @@ var BaseTransactionRequest = class {
|
|
2064
2064
|
]);
|
2065
2065
|
}
|
2066
2066
|
};
|
2067
|
-
updateAssetInput(
|
2067
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
2068
2068
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2069
2069
|
}
|
2070
2070
|
/**
|
@@ -3491,6 +3491,7 @@ var processGqlChain = (chain) => {
|
|
3491
3491
|
gasPerByte: bn15(feeParams.gasPerByte),
|
3492
3492
|
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3493
3493
|
chainId: bn15(consensusParameters.chainId),
|
3494
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3494
3495
|
gasCosts
|
3495
3496
|
},
|
3496
3497
|
gasCosts,
|
@@ -3733,6 +3734,17 @@ var _Provider = class {
|
|
3733
3734
|
} = this.getChain();
|
3734
3735
|
return chainId.toNumber();
|
3735
3736
|
}
|
3737
|
+
/**
|
3738
|
+
* Returns the base asset ID
|
3739
|
+
*
|
3740
|
+
* @returns A promise that resolves to the base asset ID
|
3741
|
+
*/
|
3742
|
+
getBaseAssetId() {
|
3743
|
+
const {
|
3744
|
+
consensusParameters: { baseAssetId }
|
3745
|
+
} = this.getChain();
|
3746
|
+
return baseAssetId;
|
3747
|
+
}
|
3736
3748
|
/**
|
3737
3749
|
* Submits a transaction to the chain to be executed.
|
3738
3750
|
*
|
@@ -4603,8 +4615,9 @@ var Account = class extends AbstractAccount {
|
|
4603
4615
|
* @param assetId - The asset ID to check the balance for.
|
4604
4616
|
* @returns A promise that resolves to the balance amount.
|
4605
4617
|
*/
|
4606
|
-
async getBalance(assetId
|
4607
|
-
const
|
4618
|
+
async getBalance(assetId) {
|
4619
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4620
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4608
4621
|
return amount;
|
4609
4622
|
}
|
4610
4623
|
/**
|
@@ -4642,9 +4655,10 @@ var Account = class extends AbstractAccount {
|
|
4642
4655
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4643
4656
|
*/
|
4644
4657
|
async fund(request, coinQuantities, fee) {
|
4658
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4645
4659
|
const updatedQuantities = addAmountToAsset({
|
4646
4660
|
amount: bn17(fee),
|
4647
|
-
assetId:
|
4661
|
+
assetId: baseAssetId,
|
4648
4662
|
coinQuantities
|
4649
4663
|
});
|
4650
4664
|
const quantitiesDict = {};
|
@@ -4668,8 +4682,8 @@ var Account = class extends AbstractAccount {
|
|
4668
4682
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4669
4683
|
cachedUtxos.push(input.id);
|
4670
4684
|
}
|
4671
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4672
|
-
quantitiesDict[
|
4685
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4686
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4673
4687
|
cachedMessages.push(input.nonce);
|
4674
4688
|
}
|
4675
4689
|
}
|
@@ -4701,11 +4715,12 @@ var Account = class extends AbstractAccount {
|
|
4701
4715
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4702
4716
|
* @returns A promise that resolves to the prepared transaction request.
|
4703
4717
|
*/
|
4704
|
-
async createTransfer(destination, amount, assetId
|
4718
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4705
4719
|
const { minGasPrice } = this.provider.getGasConfig();
|
4720
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4706
4721
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4707
4722
|
const request = new ScriptTransactionRequest(params);
|
4708
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
4723
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4709
4724
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4710
4725
|
estimateTxDependencies: true,
|
4711
4726
|
resourcesOwner: this
|
@@ -4731,14 +4746,15 @@ var Account = class extends AbstractAccount {
|
|
4731
4746
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4732
4747
|
* @returns A promise that resolves to the transaction response.
|
4733
4748
|
*/
|
4734
|
-
async transfer(destination, amount, assetId
|
4749
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4735
4750
|
if (bn17(amount).lte(0)) {
|
4736
4751
|
throw new FuelError15(
|
4737
4752
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4738
4753
|
"Transfer amount must be a positive number."
|
4739
4754
|
);
|
4740
4755
|
}
|
4741
|
-
const
|
4756
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4757
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4742
4758
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4743
4759
|
}
|
4744
4760
|
/**
|
@@ -4750,7 +4766,7 @@ var Account = class extends AbstractAccount {
|
|
4750
4766
|
* @param txParams - The optional transaction parameters.
|
4751
4767
|
* @returns A promise that resolves to the transaction response.
|
4752
4768
|
*/
|
4753
|
-
async transferToContract(contractId, amount, assetId
|
4769
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4754
4770
|
if (bn17(amount).lte(0)) {
|
4755
4771
|
throw new FuelError15(
|
4756
4772
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
@@ -4759,11 +4775,12 @@ var Account = class extends AbstractAccount {
|
|
4759
4775
|
}
|
4760
4776
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4761
4777
|
const { minGasPrice } = this.provider.getGasConfig();
|
4778
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4762
4779
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4763
4780
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4764
4781
|
hexlifiedContractId: contractAddress.toB256(),
|
4765
4782
|
amountToTransfer: bn17(amount),
|
4766
|
-
assetId
|
4783
|
+
assetId: assetIdToTransfer
|
4767
4784
|
});
|
4768
4785
|
const request = new ScriptTransactionRequest({
|
4769
4786
|
...params,
|
@@ -4773,7 +4790,7 @@ var Account = class extends AbstractAccount {
|
|
4773
4790
|
request.addContractInputAndOutput(contractAddress);
|
4774
4791
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4775
4792
|
request,
|
4776
|
-
[{ amount: bn17(amount), assetId: String(
|
4793
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
4777
4794
|
);
|
4778
4795
|
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4779
4796
|
this.validateGas({
|
@@ -4795,6 +4812,7 @@ var Account = class extends AbstractAccount {
|
|
4795
4812
|
*/
|
4796
4813
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4797
4814
|
const { minGasPrice } = this.provider.getGasConfig();
|
4815
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4798
4816
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4799
4817
|
const recipientDataArray = arrayify14(
|
4800
4818
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -4809,7 +4827,7 @@ var Account = class extends AbstractAccount {
|
|
4809
4827
|
]);
|
4810
4828
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4811
4829
|
const request = new ScriptTransactionRequest(params);
|
4812
|
-
const forwardingQuantities = [{ amount: bn17(amount), assetId:
|
4830
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
4813
4831
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4814
4832
|
request,
|
4815
4833
|
forwardingQuantities
|
@@ -7981,7 +7999,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7981
7999
|
};
|
7982
8000
|
|
7983
8001
|
// src/test-utils/launchNode.ts
|
7984
|
-
import {
|
8002
|
+
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
7985
8003
|
import { toHex as toHex2 } from "@fuel-ts/math";
|
7986
8004
|
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
7987
8005
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
@@ -8081,7 +8099,7 @@ var launchNode = async ({
|
|
8081
8099
|
{
|
8082
8100
|
owner: signer.address.toHexString(),
|
8083
8101
|
amount: toHex2(1e9),
|
8084
|
-
asset_id:
|
8102
|
+
asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
|
8085
8103
|
}
|
8086
8104
|
]
|
8087
8105
|
}
|
@@ -8147,9 +8165,10 @@ var launchNode = async ({
|
|
8147
8165
|
})
|
8148
8166
|
);
|
8149
8167
|
var generateWallets = async (count, provider) => {
|
8168
|
+
const baseAssetId = provider.getBaseAssetId();
|
8150
8169
|
const wallets = [];
|
8151
8170
|
for (let i = 0; i < count; i += 1) {
|
8152
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8171
|
+
const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
|
8153
8172
|
wallets.push(wallet);
|
8154
8173
|
}
|
8155
8174
|
return wallets;
|