@fuel-ts/account 0.0.0-rc-2045-20240411194225 → 0.0.0-rc-1976-20240412134847
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 +67 -45
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +100 -80
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -42
- 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/script-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/script-transaction-request.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/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +71 -46
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +103 -80
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +65 -42
- 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);
|
@@ -1153,7 +1151,7 @@ var outputify = (value) => {
|
|
1153
1151
|
// src/providers/transaction-request/transaction-request.ts
|
1154
1152
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1155
1153
|
import { Address, addressify } from "@fuel-ts/address";
|
1156
|
-
import {
|
1154
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1157
1155
|
import { randomBytes } from "@fuel-ts/crypto";
|
1158
1156
|
import { bn as bn7 } from "@fuel-ts/math";
|
1159
1157
|
import {
|
@@ -1614,6 +1612,8 @@ var BaseTransactionRequest = class {
|
|
1614
1612
|
outputs = [];
|
1615
1613
|
/** List of witnesses */
|
1616
1614
|
witnesses = [];
|
1615
|
+
/** Base asset ID - should be fetched from the chain */
|
1616
|
+
baseAssetId;
|
1617
1617
|
/**
|
1618
1618
|
* Constructor for initializing a base transaction request.
|
1619
1619
|
*
|
@@ -1626,8 +1626,9 @@ var BaseTransactionRequest = class {
|
|
1626
1626
|
witnessLimit,
|
1627
1627
|
inputs,
|
1628
1628
|
outputs,
|
1629
|
-
witnesses
|
1630
|
-
|
1629
|
+
witnesses,
|
1630
|
+
baseAssetId
|
1631
|
+
}) {
|
1631
1632
|
this.gasPrice = bn7(gasPrice);
|
1632
1633
|
this.maturity = maturity ?? 0;
|
1633
1634
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
@@ -1635,6 +1636,7 @@ var BaseTransactionRequest = class {
|
|
1635
1636
|
this.inputs = inputs ?? [];
|
1636
1637
|
this.outputs = outputs ?? [];
|
1637
1638
|
this.witnesses = witnesses ?? [];
|
1639
|
+
this.baseAssetId = baseAssetId;
|
1638
1640
|
}
|
1639
1641
|
static getPolicyMeta(req) {
|
1640
1642
|
let policyTypes = 0;
|
@@ -1858,11 +1860,9 @@ var BaseTransactionRequest = class {
|
|
1858
1860
|
*
|
1859
1861
|
* @param message - Message resource.
|
1860
1862
|
* @param predicate - Predicate bytes.
|
1861
|
-
* @param predicateData - Predicate data bytes.
|
1862
1863
|
*/
|
1863
1864
|
addMessageInput(message, predicate) {
|
1864
1865
|
const { recipient, sender, amount } = message;
|
1865
|
-
const assetId = BaseAssetId2;
|
1866
1866
|
let witnessIndex;
|
1867
1867
|
if (predicate) {
|
1868
1868
|
witnessIndex = 0;
|
@@ -1882,7 +1882,7 @@ var BaseTransactionRequest = class {
|
|
1882
1882
|
predicate: predicate?.bytes
|
1883
1883
|
};
|
1884
1884
|
this.pushInput(input);
|
1885
|
-
this.addChangeOutput(recipient,
|
1885
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1886
1886
|
}
|
1887
1887
|
/**
|
1888
1888
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1943,12 +1943,12 @@ var BaseTransactionRequest = class {
|
|
1943
1943
|
* @param amount - Amount of coin.
|
1944
1944
|
* @param assetId - Asset ID of coin.
|
1945
1945
|
*/
|
1946
|
-
addCoinOutput(to, amount, assetId
|
1946
|
+
addCoinOutput(to, amount, assetId) {
|
1947
1947
|
this.pushOutput({
|
1948
1948
|
type: OutputType2.Coin,
|
1949
1949
|
to: addressify(to).toB256(),
|
1950
1950
|
amount,
|
1951
|
-
assetId
|
1951
|
+
assetId: assetId ?? this.baseAssetId
|
1952
1952
|
});
|
1953
1953
|
return this;
|
1954
1954
|
}
|
@@ -1975,7 +1975,7 @@ var BaseTransactionRequest = class {
|
|
1975
1975
|
* @param to - Address of the owner.
|
1976
1976
|
* @param assetId - Asset ID of coin.
|
1977
1977
|
*/
|
1978
|
-
addChangeOutput(to, assetId
|
1978
|
+
addChangeOutput(to, assetId) {
|
1979
1979
|
const changeOutput = this.getChangeOutputs().find(
|
1980
1980
|
(output) => hexlify7(output.assetId) === assetId
|
1981
1981
|
);
|
@@ -1983,7 +1983,7 @@ var BaseTransactionRequest = class {
|
|
1983
1983
|
this.pushOutput({
|
1984
1984
|
type: OutputType2.Change,
|
1985
1985
|
to: addressify(to).toB256(),
|
1986
|
-
assetId
|
1986
|
+
assetId: assetId ?? this.baseAssetId
|
1987
1987
|
});
|
1988
1988
|
}
|
1989
1989
|
}
|
@@ -2059,7 +2059,7 @@ var BaseTransactionRequest = class {
|
|
2059
2059
|
]);
|
2060
2060
|
}
|
2061
2061
|
};
|
2062
|
-
updateAssetInput(
|
2062
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
2063
2063
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2064
2064
|
}
|
2065
2065
|
/**
|
@@ -2229,12 +2229,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2229
2229
|
*
|
2230
2230
|
* @param createTransactionRequestLike - The initial values for the instance
|
2231
2231
|
*/
|
2232
|
-
constructor({
|
2233
|
-
bytecodeWitnessIndex,
|
2234
|
-
salt,
|
2235
|
-
storageSlots,
|
2236
|
-
...rest
|
2237
|
-
} = {}) {
|
2232
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2238
2233
|
super(rest);
|
2239
2234
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2240
2235
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2358,7 +2353,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2358
2353
|
*
|
2359
2354
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2360
2355
|
*/
|
2361
|
-
constructor({ script, scriptData, gasLimit, ...rest }
|
2356
|
+
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2362
2357
|
super(rest);
|
2363
2358
|
this.gasLimit = bn10(gasLimit);
|
2364
2359
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -3486,6 +3481,7 @@ var processGqlChain = (chain) => {
|
|
3486
3481
|
gasPerByte: bn15(feeParams.gasPerByte),
|
3487
3482
|
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3488
3483
|
chainId: bn15(consensusParameters.chainId),
|
3484
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3489
3485
|
gasCosts
|
3490
3486
|
},
|
3491
3487
|
gasCosts,
|
@@ -3728,6 +3724,17 @@ var _Provider = class {
|
|
3728
3724
|
} = this.getChain();
|
3729
3725
|
return chainId.toNumber();
|
3730
3726
|
}
|
3727
|
+
/**
|
3728
|
+
* Returns the base asset ID
|
3729
|
+
*
|
3730
|
+
* @returns A promise that resolves to the base asset ID
|
3731
|
+
*/
|
3732
|
+
getBaseAssetId() {
|
3733
|
+
const {
|
3734
|
+
consensusParameters: { baseAssetId }
|
3735
|
+
} = this.getChain();
|
3736
|
+
return baseAssetId;
|
3737
|
+
}
|
3731
3738
|
/**
|
3732
3739
|
* Submits a transaction to the chain to be executed.
|
3733
3740
|
*
|
@@ -4625,8 +4632,9 @@ var Account = class extends AbstractAccount {
|
|
4625
4632
|
* @param assetId - The asset ID to check the balance for.
|
4626
4633
|
* @returns A promise that resolves to the balance amount.
|
4627
4634
|
*/
|
4628
|
-
async getBalance(assetId
|
4629
|
-
const
|
4635
|
+
async getBalance(assetId) {
|
4636
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4637
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4630
4638
|
return amount;
|
4631
4639
|
}
|
4632
4640
|
/**
|
@@ -4664,9 +4672,10 @@ var Account = class extends AbstractAccount {
|
|
4664
4672
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4665
4673
|
*/
|
4666
4674
|
async fund(request, coinQuantities, fee) {
|
4675
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4667
4676
|
const updatedQuantities = addAmountToAsset({
|
4668
4677
|
amount: bn17(fee),
|
4669
|
-
assetId:
|
4678
|
+
assetId: baseAssetId,
|
4670
4679
|
coinQuantities
|
4671
4680
|
});
|
4672
4681
|
const quantitiesDict = {};
|
@@ -4690,8 +4699,8 @@ var Account = class extends AbstractAccount {
|
|
4690
4699
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4691
4700
|
cachedUtxos.push(input.id);
|
4692
4701
|
}
|
4693
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4694
|
-
quantitiesDict[
|
4702
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4703
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4695
4704
|
cachedMessages.push(input.nonce);
|
4696
4705
|
}
|
4697
4706
|
}
|
@@ -4723,11 +4732,13 @@ var Account = class extends AbstractAccount {
|
|
4723
4732
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4724
4733
|
* @returns A promise that resolves to the prepared transaction request.
|
4725
4734
|
*/
|
4726
|
-
async createTransfer(destination, amount, assetId
|
4735
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4727
4736
|
const { minGasPrice } = this.provider.getGasConfig();
|
4728
|
-
const
|
4737
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4738
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4739
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4729
4740
|
const request = new ScriptTransactionRequest(params);
|
4730
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
4741
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4731
4742
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4732
4743
|
estimateTxDependencies: true,
|
4733
4744
|
resourcesOwner: this
|
@@ -4753,14 +4764,15 @@ var Account = class extends AbstractAccount {
|
|
4753
4764
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4754
4765
|
* @returns A promise that resolves to the transaction response.
|
4755
4766
|
*/
|
4756
|
-
async transfer(destination, amount, assetId
|
4767
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4757
4768
|
if (bn17(amount).lte(0)) {
|
4758
4769
|
throw new FuelError15(
|
4759
4770
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4760
4771
|
"Transfer amount must be a positive number."
|
4761
4772
|
);
|
4762
4773
|
}
|
4763
|
-
const
|
4774
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4775
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4764
4776
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4765
4777
|
}
|
4766
4778
|
/**
|
@@ -4772,7 +4784,7 @@ var Account = class extends AbstractAccount {
|
|
4772
4784
|
* @param txParams - The optional transaction parameters.
|
4773
4785
|
* @returns A promise that resolves to the transaction response.
|
4774
4786
|
*/
|
4775
|
-
async transferToContract(contractId, amount, assetId
|
4787
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4776
4788
|
if (bn17(amount).lte(0)) {
|
4777
4789
|
throw new FuelError15(
|
4778
4790
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
@@ -4781,11 +4793,13 @@ var Account = class extends AbstractAccount {
|
|
4781
4793
|
}
|
4782
4794
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4783
4795
|
const { minGasPrice } = this.provider.getGasConfig();
|
4784
|
-
const
|
4796
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4797
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4798
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4785
4799
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4786
4800
|
hexlifiedContractId: contractAddress.toB256(),
|
4787
4801
|
amountToTransfer: bn17(amount),
|
4788
|
-
assetId
|
4802
|
+
assetId: assetIdToTransfer
|
4789
4803
|
});
|
4790
4804
|
const request = new ScriptTransactionRequest({
|
4791
4805
|
...params,
|
@@ -4795,7 +4809,7 @@ var Account = class extends AbstractAccount {
|
|
4795
4809
|
request.addContractInputAndOutput(contractAddress);
|
4796
4810
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4797
4811
|
request,
|
4798
|
-
[{ amount: bn17(amount), assetId: String(
|
4812
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
4799
4813
|
);
|
4800
4814
|
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4801
4815
|
this.validateGas({
|
@@ -4817,6 +4831,7 @@ var Account = class extends AbstractAccount {
|
|
4817
4831
|
*/
|
4818
4832
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4819
4833
|
const { minGasPrice } = this.provider.getGasConfig();
|
4834
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4820
4835
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4821
4836
|
const recipientDataArray = arrayify14(
|
4822
4837
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -4829,9 +4844,14 @@ var Account = class extends AbstractAccount {
|
|
4829
4844
|
...recipientDataArray,
|
4830
4845
|
...amountDataArray
|
4831
4846
|
]);
|
4832
|
-
const params = {
|
4847
|
+
const params = {
|
4848
|
+
script,
|
4849
|
+
gasPrice: minGasPrice,
|
4850
|
+
baseAssetId,
|
4851
|
+
...txParams
|
4852
|
+
};
|
4833
4853
|
const request = new ScriptTransactionRequest(params);
|
4834
|
-
const forwardingQuantities = [{ amount: bn17(amount), assetId:
|
4854
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
4835
4855
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4836
4856
|
request,
|
4837
4857
|
forwardingQuantities
|
@@ -7984,7 +8004,9 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
7984
8004
|
);
|
7985
8005
|
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7986
8006
|
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
8007
|
+
const baseAssetId = genesisWallet.provider.getBaseAssetId();
|
7987
8008
|
const request = new ScriptTransactionRequest({
|
8009
|
+
baseAssetId,
|
7988
8010
|
gasLimit: 1e4,
|
7989
8011
|
gasPrice: minGasPrice
|
7990
8012
|
});
|
@@ -8003,7 +8025,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8003
8025
|
};
|
8004
8026
|
|
8005
8027
|
// src/test-utils/launchNode.ts
|
8006
|
-
import {
|
8028
|
+
import { ZeroBytes32 as ZeroBytes329 } from "@fuel-ts/address/configs";
|
8007
8029
|
import { toHex as toHex2 } from "@fuel-ts/math";
|
8008
8030
|
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8009
8031
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
@@ -8103,7 +8125,7 @@ var launchNode = async ({
|
|
8103
8125
|
{
|
8104
8126
|
owner: signer.address.toHexString(),
|
8105
8127
|
amount: toHex2(1e9),
|
8106
|
-
asset_id:
|
8128
|
+
asset_id: defaultChainConfig?.consensus_parameters?.base_asset_id ?? ZeroBytes329
|
8107
8129
|
}
|
8108
8130
|
]
|
8109
8131
|
}
|
@@ -8169,9 +8191,10 @@ var launchNode = async ({
|
|
8169
8191
|
})
|
8170
8192
|
);
|
8171
8193
|
var generateWallets = async (count, provider) => {
|
8194
|
+
const baseAssetId = provider.getBaseAssetId();
|
8172
8195
|
const wallets = [];
|
8173
8196
|
for (let i = 0; i < count; i += 1) {
|
8174
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8197
|
+
const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
|
8175
8198
|
wallets.push(wallet);
|
8176
8199
|
}
|
8177
8200
|
return wallets;
|