@fuel-ts/account 0.0.0-rc-1976-20240417074721 → 0.0.0-rc-2045-20240417092921
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 +45 -67
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +80 -100
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -62
- 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 +0 -7
- 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 +2 -5
- 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 +46 -71
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +80 -103
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +42 -65
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +15 -15
package/dist/test-utils.mjs
CHANGED
@@ -24,12 +24,14 @@ 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";
|
27
28
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
28
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
30
|
import { bn as bn17 } from "@fuel-ts/math";
|
30
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
31
32
|
|
32
33
|
// src/providers/coin-quantity.ts
|
34
|
+
import { BaseAssetId } from "@fuel-ts/address/configs";
|
33
35
|
import { bn } from "@fuel-ts/math";
|
34
36
|
import { hexlify } from "@fuel-ts/utils";
|
35
37
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -38,11 +40,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
38
40
|
let max2;
|
39
41
|
if (Array.isArray(coinQuantityLike)) {
|
40
42
|
amount = coinQuantityLike[0];
|
41
|
-
assetId = coinQuantityLike[1];
|
42
|
-
max2 = coinQuantityLike[2];
|
43
|
+
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
44
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
43
45
|
} else {
|
44
46
|
amount = coinQuantityLike.amount;
|
45
|
-
assetId = coinQuantityLike.assetId;
|
47
|
+
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
46
48
|
max2 = coinQuantityLike.max ?? void 0;
|
47
49
|
}
|
48
50
|
const bnAmount = bn(amount);
|
@@ -1160,7 +1162,7 @@ var outputify = (value) => {
|
|
1160
1162
|
// src/providers/transaction-request/transaction-request.ts
|
1161
1163
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1162
1164
|
import { Address, addressify } from "@fuel-ts/address";
|
1163
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1165
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1164
1166
|
import { randomBytes } from "@fuel-ts/crypto";
|
1165
1167
|
import { bn as bn7 } from "@fuel-ts/math";
|
1166
1168
|
import {
|
@@ -1621,8 +1623,6 @@ var BaseTransactionRequest = class {
|
|
1621
1623
|
outputs = [];
|
1622
1624
|
/** List of witnesses */
|
1623
1625
|
witnesses = [];
|
1624
|
-
/** Base asset ID - should be fetched from the chain */
|
1625
|
-
baseAssetId;
|
1626
1626
|
/**
|
1627
1627
|
* Constructor for initializing a base transaction request.
|
1628
1628
|
*
|
@@ -1635,9 +1635,8 @@ var BaseTransactionRequest = class {
|
|
1635
1635
|
witnessLimit,
|
1636
1636
|
inputs,
|
1637
1637
|
outputs,
|
1638
|
-
witnesses
|
1639
|
-
|
1640
|
-
}) {
|
1638
|
+
witnesses
|
1639
|
+
} = {}) {
|
1641
1640
|
this.gasPrice = bn7(gasPrice);
|
1642
1641
|
this.maturity = maturity ?? 0;
|
1643
1642
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
@@ -1645,7 +1644,6 @@ var BaseTransactionRequest = class {
|
|
1645
1644
|
this.inputs = inputs ?? [];
|
1646
1645
|
this.outputs = outputs ?? [];
|
1647
1646
|
this.witnesses = witnesses ?? [];
|
1648
|
-
this.baseAssetId = baseAssetId;
|
1649
1647
|
}
|
1650
1648
|
static getPolicyMeta(req) {
|
1651
1649
|
let policyTypes = 0;
|
@@ -1869,9 +1867,11 @@ var BaseTransactionRequest = class {
|
|
1869
1867
|
*
|
1870
1868
|
* @param message - Message resource.
|
1871
1869
|
* @param predicate - Predicate bytes.
|
1870
|
+
* @param predicateData - Predicate data bytes.
|
1872
1871
|
*/
|
1873
1872
|
addMessageInput(message, predicate) {
|
1874
1873
|
const { recipient, sender, amount } = message;
|
1874
|
+
const assetId = BaseAssetId2;
|
1875
1875
|
let witnessIndex;
|
1876
1876
|
if (predicate) {
|
1877
1877
|
witnessIndex = 0;
|
@@ -1891,7 +1891,7 @@ var BaseTransactionRequest = class {
|
|
1891
1891
|
predicate: predicate?.bytes
|
1892
1892
|
};
|
1893
1893
|
this.pushInput(input);
|
1894
|
-
this.addChangeOutput(recipient,
|
1894
|
+
this.addChangeOutput(recipient, assetId);
|
1895
1895
|
}
|
1896
1896
|
/**
|
1897
1897
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1952,12 +1952,12 @@ var BaseTransactionRequest = class {
|
|
1952
1952
|
* @param amount - Amount of coin.
|
1953
1953
|
* @param assetId - Asset ID of coin.
|
1954
1954
|
*/
|
1955
|
-
addCoinOutput(to, amount, assetId) {
|
1955
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
1956
1956
|
this.pushOutput({
|
1957
1957
|
type: OutputType2.Coin,
|
1958
1958
|
to: addressify(to).toB256(),
|
1959
1959
|
amount,
|
1960
|
-
assetId
|
1960
|
+
assetId
|
1961
1961
|
});
|
1962
1962
|
return this;
|
1963
1963
|
}
|
@@ -1984,7 +1984,7 @@ var BaseTransactionRequest = class {
|
|
1984
1984
|
* @param to - Address of the owner.
|
1985
1985
|
* @param assetId - Asset ID of coin.
|
1986
1986
|
*/
|
1987
|
-
addChangeOutput(to, assetId) {
|
1987
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
1988
1988
|
const changeOutput = this.getChangeOutputs().find(
|
1989
1989
|
(output) => hexlify7(output.assetId) === assetId
|
1990
1990
|
);
|
@@ -1992,7 +1992,7 @@ var BaseTransactionRequest = class {
|
|
1992
1992
|
this.pushOutput({
|
1993
1993
|
type: OutputType2.Change,
|
1994
1994
|
to: addressify(to).toB256(),
|
1995
|
-
assetId
|
1995
|
+
assetId
|
1996
1996
|
});
|
1997
1997
|
}
|
1998
1998
|
}
|
@@ -2068,7 +2068,7 @@ var BaseTransactionRequest = class {
|
|
2068
2068
|
]);
|
2069
2069
|
}
|
2070
2070
|
};
|
2071
|
-
updateAssetInput(
|
2071
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2072
2072
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2073
2073
|
}
|
2074
2074
|
/**
|
@@ -2238,7 +2238,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2238
2238
|
*
|
2239
2239
|
* @param createTransactionRequestLike - The initial values for the instance
|
2240
2240
|
*/
|
2241
|
-
constructor({
|
2241
|
+
constructor({
|
2242
|
+
bytecodeWitnessIndex,
|
2243
|
+
salt,
|
2244
|
+
storageSlots,
|
2245
|
+
...rest
|
2246
|
+
} = {}) {
|
2242
2247
|
super(rest);
|
2243
2248
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2244
2249
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2362,7 +2367,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2362
2367
|
*
|
2363
2368
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2364
2369
|
*/
|
2365
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2370
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2366
2371
|
super(rest);
|
2367
2372
|
this.gasLimit = bn10(gasLimit);
|
2368
2373
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -3490,7 +3495,6 @@ var processGqlChain = (chain) => {
|
|
3490
3495
|
gasPerByte: bn15(feeParams.gasPerByte),
|
3491
3496
|
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3492
3497
|
chainId: bn15(consensusParameters.chainId),
|
3493
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3494
3498
|
gasCosts
|
3495
3499
|
},
|
3496
3500
|
gasCosts,
|
@@ -3733,17 +3737,6 @@ var _Provider = class {
|
|
3733
3737
|
} = this.getChain();
|
3734
3738
|
return chainId.toNumber();
|
3735
3739
|
}
|
3736
|
-
/**
|
3737
|
-
* Returns the base asset ID
|
3738
|
-
*
|
3739
|
-
* @returns A promise that resolves to the base asset ID
|
3740
|
-
*/
|
3741
|
-
getBaseAssetId() {
|
3742
|
-
const {
|
3743
|
-
consensusParameters: { baseAssetId }
|
3744
|
-
} = this.getChain();
|
3745
|
-
return baseAssetId;
|
3746
|
-
}
|
3747
3740
|
/**
|
3748
3741
|
* Submits a transaction to the chain to be executed.
|
3749
3742
|
*
|
@@ -4641,9 +4634,8 @@ var Account = class extends AbstractAccount {
|
|
4641
4634
|
* @param assetId - The asset ID to check the balance for.
|
4642
4635
|
* @returns A promise that resolves to the balance amount.
|
4643
4636
|
*/
|
4644
|
-
async getBalance(assetId) {
|
4645
|
-
const
|
4646
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4637
|
+
async getBalance(assetId = BaseAssetId3) {
|
4638
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4647
4639
|
return amount;
|
4648
4640
|
}
|
4649
4641
|
/**
|
@@ -4681,10 +4673,9 @@ var Account = class extends AbstractAccount {
|
|
4681
4673
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4682
4674
|
*/
|
4683
4675
|
async fund(request, coinQuantities, fee) {
|
4684
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4685
4676
|
const updatedQuantities = addAmountToAsset({
|
4686
4677
|
amount: bn17(fee),
|
4687
|
-
assetId:
|
4678
|
+
assetId: BaseAssetId3,
|
4688
4679
|
coinQuantities
|
4689
4680
|
});
|
4690
4681
|
const quantitiesDict = {};
|
@@ -4708,8 +4699,8 @@ var Account = class extends AbstractAccount {
|
|
4708
4699
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4709
4700
|
cachedUtxos.push(input.id);
|
4710
4701
|
}
|
4711
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4712
|
-
quantitiesDict[
|
4702
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4703
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4713
4704
|
cachedMessages.push(input.nonce);
|
4714
4705
|
}
|
4715
4706
|
}
|
@@ -4741,13 +4732,11 @@ var Account = class extends AbstractAccount {
|
|
4741
4732
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4742
4733
|
* @returns A promise that resolves to the prepared transaction request.
|
4743
4734
|
*/
|
4744
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4735
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4745
4736
|
const { minGasPrice } = this.provider.getGasConfig();
|
4746
|
-
const
|
4747
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4748
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4737
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4749
4738
|
const request = new ScriptTransactionRequest(params);
|
4750
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
4739
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4751
4740
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4752
4741
|
estimateTxDependencies: true,
|
4753
4742
|
resourcesOwner: this
|
@@ -4773,15 +4762,14 @@ var Account = class extends AbstractAccount {
|
|
4773
4762
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4774
4763
|
* @returns A promise that resolves to the transaction response.
|
4775
4764
|
*/
|
4776
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4765
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4777
4766
|
if (bn17(amount).lte(0)) {
|
4778
4767
|
throw new FuelError15(
|
4779
4768
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4780
4769
|
"Transfer amount must be a positive number."
|
4781
4770
|
);
|
4782
4771
|
}
|
4783
|
-
const
|
4784
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4772
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4785
4773
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4786
4774
|
}
|
4787
4775
|
/**
|
@@ -4793,7 +4781,7 @@ var Account = class extends AbstractAccount {
|
|
4793
4781
|
* @param txParams - The optional transaction parameters.
|
4794
4782
|
* @returns A promise that resolves to the transaction response.
|
4795
4783
|
*/
|
4796
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4784
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4797
4785
|
if (bn17(amount).lte(0)) {
|
4798
4786
|
throw new FuelError15(
|
4799
4787
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
@@ -4802,13 +4790,11 @@ var Account = class extends AbstractAccount {
|
|
4802
4790
|
}
|
4803
4791
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4804
4792
|
const { minGasPrice } = this.provider.getGasConfig();
|
4805
|
-
const
|
4806
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4807
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4793
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
4808
4794
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4809
4795
|
hexlifiedContractId: contractAddress.toB256(),
|
4810
4796
|
amountToTransfer: bn17(amount),
|
4811
|
-
assetId
|
4797
|
+
assetId
|
4812
4798
|
});
|
4813
4799
|
const request = new ScriptTransactionRequest({
|
4814
4800
|
...params,
|
@@ -4818,7 +4804,7 @@ var Account = class extends AbstractAccount {
|
|
4818
4804
|
request.addContractInputAndOutput(contractAddress);
|
4819
4805
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4820
4806
|
request,
|
4821
|
-
[{ amount: bn17(amount), assetId: String(
|
4807
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
4822
4808
|
);
|
4823
4809
|
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4824
4810
|
this.validateGas({
|
@@ -4840,7 +4826,6 @@ var Account = class extends AbstractAccount {
|
|
4840
4826
|
*/
|
4841
4827
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4842
4828
|
const { minGasPrice } = this.provider.getGasConfig();
|
4843
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4844
4829
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4845
4830
|
const recipientDataArray = arrayify14(
|
4846
4831
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -4853,14 +4838,9 @@ var Account = class extends AbstractAccount {
|
|
4853
4838
|
...recipientDataArray,
|
4854
4839
|
...amountDataArray
|
4855
4840
|
]);
|
4856
|
-
const params = {
|
4857
|
-
script,
|
4858
|
-
gasPrice: minGasPrice,
|
4859
|
-
baseAssetId,
|
4860
|
-
...txParams
|
4861
|
-
};
|
4841
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4862
4842
|
const request = new ScriptTransactionRequest(params);
|
4863
|
-
const forwardingQuantities = [{ amount: bn17(amount), assetId:
|
4843
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
4864
4844
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4865
4845
|
request,
|
4866
4846
|
forwardingQuantities
|
@@ -8013,9 +7993,7 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8013
7993
|
);
|
8014
7994
|
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
8015
7995
|
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
8016
|
-
const baseAssetId = genesisWallet.provider.getBaseAssetId();
|
8017
7996
|
const request = new ScriptTransactionRequest({
|
8018
|
-
baseAssetId,
|
8019
7997
|
gasLimit: 1e4,
|
8020
7998
|
gasPrice: minGasPrice
|
8021
7999
|
});
|
@@ -8034,7 +8012,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8034
8012
|
};
|
8035
8013
|
|
8036
8014
|
// src/test-utils/launchNode.ts
|
8037
|
-
import {
|
8015
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8038
8016
|
import { toHex as toHex2 } from "@fuel-ts/math";
|
8039
8017
|
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8040
8018
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
@@ -8134,7 +8112,7 @@ var launchNode = async ({
|
|
8134
8112
|
{
|
8135
8113
|
owner: signer.address.toHexString(),
|
8136
8114
|
amount: toHex2(1e9),
|
8137
|
-
asset_id:
|
8115
|
+
asset_id: BaseAssetId4
|
8138
8116
|
}
|
8139
8117
|
]
|
8140
8118
|
}
|
@@ -8200,10 +8178,9 @@ var launchNode = async ({
|
|
8200
8178
|
})
|
8201
8179
|
);
|
8202
8180
|
var generateWallets = async (count, provider) => {
|
8203
|
-
const baseAssetId = provider.getBaseAssetId();
|
8204
8181
|
const wallets = [];
|
8205
8182
|
for (let i = 0; i < count; i += 1) {
|
8206
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8183
|
+
const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
|
8207
8184
|
wallets.push(wallet);
|
8208
8185
|
}
|
8209
8186
|
return wallets;
|