@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/index.mjs
CHANGED
@@ -29,12 +29,14 @@ var __privateMethod = (obj, member, method) => {
|
|
29
29
|
|
30
30
|
// src/account.ts
|
31
31
|
import { Address as Address3 } from "@fuel-ts/address";
|
32
|
+
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
32
33
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
33
34
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
34
35
|
import { bn as bn17 } from "@fuel-ts/math";
|
35
36
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
36
37
|
|
37
38
|
// src/providers/coin-quantity.ts
|
39
|
+
import { BaseAssetId } from "@fuel-ts/address/configs";
|
38
40
|
import { bn } from "@fuel-ts/math";
|
39
41
|
import { hexlify } from "@fuel-ts/utils";
|
40
42
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -43,11 +45,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
43
45
|
let max2;
|
44
46
|
if (Array.isArray(coinQuantityLike)) {
|
45
47
|
amount = coinQuantityLike[0];
|
46
|
-
assetId = coinQuantityLike[1];
|
47
|
-
max2 = coinQuantityLike[2];
|
48
|
+
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
49
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
48
50
|
} else {
|
49
51
|
amount = coinQuantityLike.amount;
|
50
|
-
assetId = coinQuantityLike.assetId;
|
52
|
+
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
51
53
|
max2 = coinQuantityLike.max ?? void 0;
|
52
54
|
}
|
53
55
|
const bnAmount = bn(amount);
|
@@ -1165,7 +1167,7 @@ var outputify = (value) => {
|
|
1165
1167
|
// src/providers/transaction-request/transaction-request.ts
|
1166
1168
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1167
1169
|
import { Address, addressify } from "@fuel-ts/address";
|
1168
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1170
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1169
1171
|
import { randomBytes } from "@fuel-ts/crypto";
|
1170
1172
|
import { bn as bn7 } from "@fuel-ts/math";
|
1171
1173
|
import {
|
@@ -1700,8 +1702,6 @@ var BaseTransactionRequest = class {
|
|
1700
1702
|
outputs = [];
|
1701
1703
|
/** List of witnesses */
|
1702
1704
|
witnesses = [];
|
1703
|
-
/** Base asset ID - should be fetched from the chain */
|
1704
|
-
baseAssetId;
|
1705
1705
|
/**
|
1706
1706
|
* Constructor for initializing a base transaction request.
|
1707
1707
|
*
|
@@ -1714,9 +1714,8 @@ var BaseTransactionRequest = class {
|
|
1714
1714
|
witnessLimit,
|
1715
1715
|
inputs,
|
1716
1716
|
outputs,
|
1717
|
-
witnesses
|
1718
|
-
|
1719
|
-
}) {
|
1717
|
+
witnesses
|
1718
|
+
} = {}) {
|
1720
1719
|
this.gasPrice = bn7(gasPrice);
|
1721
1720
|
this.maturity = maturity ?? 0;
|
1722
1721
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
@@ -1724,7 +1723,6 @@ var BaseTransactionRequest = class {
|
|
1724
1723
|
this.inputs = inputs ?? [];
|
1725
1724
|
this.outputs = outputs ?? [];
|
1726
1725
|
this.witnesses = witnesses ?? [];
|
1727
|
-
this.baseAssetId = baseAssetId;
|
1728
1726
|
}
|
1729
1727
|
static getPolicyMeta(req) {
|
1730
1728
|
let policyTypes = 0;
|
@@ -1948,9 +1946,11 @@ var BaseTransactionRequest = class {
|
|
1948
1946
|
*
|
1949
1947
|
* @param message - Message resource.
|
1950
1948
|
* @param predicate - Predicate bytes.
|
1949
|
+
* @param predicateData - Predicate data bytes.
|
1951
1950
|
*/
|
1952
1951
|
addMessageInput(message, predicate) {
|
1953
1952
|
const { recipient, sender, amount } = message;
|
1953
|
+
const assetId = BaseAssetId2;
|
1954
1954
|
let witnessIndex;
|
1955
1955
|
if (predicate) {
|
1956
1956
|
witnessIndex = 0;
|
@@ -1970,7 +1970,7 @@ var BaseTransactionRequest = class {
|
|
1970
1970
|
predicate: predicate?.bytes
|
1971
1971
|
};
|
1972
1972
|
this.pushInput(input);
|
1973
|
-
this.addChangeOutput(recipient,
|
1973
|
+
this.addChangeOutput(recipient, assetId);
|
1974
1974
|
}
|
1975
1975
|
/**
|
1976
1976
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2031,12 +2031,12 @@ var BaseTransactionRequest = class {
|
|
2031
2031
|
* @param amount - Amount of coin.
|
2032
2032
|
* @param assetId - Asset ID of coin.
|
2033
2033
|
*/
|
2034
|
-
addCoinOutput(to, amount, assetId) {
|
2034
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
2035
2035
|
this.pushOutput({
|
2036
2036
|
type: OutputType2.Coin,
|
2037
2037
|
to: addressify(to).toB256(),
|
2038
2038
|
amount,
|
2039
|
-
assetId
|
2039
|
+
assetId
|
2040
2040
|
});
|
2041
2041
|
return this;
|
2042
2042
|
}
|
@@ -2063,7 +2063,7 @@ var BaseTransactionRequest = class {
|
|
2063
2063
|
* @param to - Address of the owner.
|
2064
2064
|
* @param assetId - Asset ID of coin.
|
2065
2065
|
*/
|
2066
|
-
addChangeOutput(to, assetId) {
|
2066
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
2067
2067
|
const changeOutput = this.getChangeOutputs().find(
|
2068
2068
|
(output) => hexlify7(output.assetId) === assetId
|
2069
2069
|
);
|
@@ -2071,7 +2071,7 @@ var BaseTransactionRequest = class {
|
|
2071
2071
|
this.pushOutput({
|
2072
2072
|
type: OutputType2.Change,
|
2073
2073
|
to: addressify(to).toB256(),
|
2074
|
-
assetId
|
2074
|
+
assetId
|
2075
2075
|
});
|
2076
2076
|
}
|
2077
2077
|
}
|
@@ -2147,7 +2147,7 @@ var BaseTransactionRequest = class {
|
|
2147
2147
|
]);
|
2148
2148
|
}
|
2149
2149
|
};
|
2150
|
-
updateAssetInput(
|
2150
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2151
2151
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2152
2152
|
}
|
2153
2153
|
/**
|
@@ -2317,7 +2317,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2317
2317
|
*
|
2318
2318
|
* @param createTransactionRequestLike - The initial values for the instance
|
2319
2319
|
*/
|
2320
|
-
constructor({
|
2320
|
+
constructor({
|
2321
|
+
bytecodeWitnessIndex,
|
2322
|
+
salt,
|
2323
|
+
storageSlots,
|
2324
|
+
...rest
|
2325
|
+
} = {}) {
|
2321
2326
|
super(rest);
|
2322
2327
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2323
2328
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2441,7 +2446,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2441
2446
|
*
|
2442
2447
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2443
2448
|
*/
|
2444
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2449
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2445
2450
|
super(rest);
|
2446
2451
|
this.gasLimit = bn10(gasLimit);
|
2447
2452
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -3616,7 +3621,6 @@ var processGqlChain = (chain) => {
|
|
3616
3621
|
gasPerByte: bn15(feeParams.gasPerByte),
|
3617
3622
|
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3618
3623
|
chainId: bn15(consensusParameters.chainId),
|
3619
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3620
3624
|
gasCosts
|
3621
3625
|
},
|
3622
3626
|
gasCosts,
|
@@ -3859,17 +3863,6 @@ var _Provider = class {
|
|
3859
3863
|
} = this.getChain();
|
3860
3864
|
return chainId.toNumber();
|
3861
3865
|
}
|
3862
|
-
/**
|
3863
|
-
* Returns the base asset ID
|
3864
|
-
*
|
3865
|
-
* @returns A promise that resolves to the base asset ID
|
3866
|
-
*/
|
3867
|
-
getBaseAssetId() {
|
3868
|
-
const {
|
3869
|
-
consensusParameters: { baseAssetId }
|
3870
|
-
} = this.getChain();
|
3871
|
-
return baseAssetId;
|
3872
|
-
}
|
3873
3866
|
/**
|
3874
3867
|
* Submits a transaction to the chain to be executed.
|
3875
3868
|
*
|
@@ -4933,9 +4926,8 @@ var Account = class extends AbstractAccount {
|
|
4933
4926
|
* @param assetId - The asset ID to check the balance for.
|
4934
4927
|
* @returns A promise that resolves to the balance amount.
|
4935
4928
|
*/
|
4936
|
-
async getBalance(assetId) {
|
4937
|
-
const
|
4938
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4929
|
+
async getBalance(assetId = BaseAssetId3) {
|
4930
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4939
4931
|
return amount;
|
4940
4932
|
}
|
4941
4933
|
/**
|
@@ -4973,10 +4965,9 @@ var Account = class extends AbstractAccount {
|
|
4973
4965
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4974
4966
|
*/
|
4975
4967
|
async fund(request, coinQuantities, fee) {
|
4976
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4977
4968
|
const updatedQuantities = addAmountToAsset({
|
4978
4969
|
amount: bn17(fee),
|
4979
|
-
assetId:
|
4970
|
+
assetId: BaseAssetId3,
|
4980
4971
|
coinQuantities
|
4981
4972
|
});
|
4982
4973
|
const quantitiesDict = {};
|
@@ -5000,8 +4991,8 @@ var Account = class extends AbstractAccount {
|
|
5000
4991
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5001
4992
|
cachedUtxos.push(input.id);
|
5002
4993
|
}
|
5003
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
5004
|
-
quantitiesDict[
|
4994
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4995
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
5005
4996
|
cachedMessages.push(input.nonce);
|
5006
4997
|
}
|
5007
4998
|
}
|
@@ -5033,13 +5024,11 @@ var Account = class extends AbstractAccount {
|
|
5033
5024
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5034
5025
|
* @returns A promise that resolves to the prepared transaction request.
|
5035
5026
|
*/
|
5036
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5027
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5037
5028
|
const { minGasPrice } = this.provider.getGasConfig();
|
5038
|
-
const
|
5039
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5040
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5029
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5041
5030
|
const request = new ScriptTransactionRequest(params);
|
5042
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
5031
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
5043
5032
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5044
5033
|
estimateTxDependencies: true,
|
5045
5034
|
resourcesOwner: this
|
@@ -5065,15 +5054,14 @@ var Account = class extends AbstractAccount {
|
|
5065
5054
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5066
5055
|
* @returns A promise that resolves to the transaction response.
|
5067
5056
|
*/
|
5068
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
5057
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5069
5058
|
if (bn17(amount).lte(0)) {
|
5070
5059
|
throw new FuelError15(
|
5071
5060
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5072
5061
|
"Transfer amount must be a positive number."
|
5073
5062
|
);
|
5074
5063
|
}
|
5075
|
-
const
|
5076
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5064
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
5077
5065
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5078
5066
|
}
|
5079
5067
|
/**
|
@@ -5085,7 +5073,7 @@ var Account = class extends AbstractAccount {
|
|
5085
5073
|
* @param txParams - The optional transaction parameters.
|
5086
5074
|
* @returns A promise that resolves to the transaction response.
|
5087
5075
|
*/
|
5088
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5076
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5089
5077
|
if (bn17(amount).lte(0)) {
|
5090
5078
|
throw new FuelError15(
|
5091
5079
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
@@ -5094,13 +5082,11 @@ var Account = class extends AbstractAccount {
|
|
5094
5082
|
}
|
5095
5083
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5096
5084
|
const { minGasPrice } = this.provider.getGasConfig();
|
5097
|
-
const
|
5098
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5099
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5085
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5100
5086
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5101
5087
|
hexlifiedContractId: contractAddress.toB256(),
|
5102
5088
|
amountToTransfer: bn17(amount),
|
5103
|
-
assetId
|
5089
|
+
assetId
|
5104
5090
|
});
|
5105
5091
|
const request = new ScriptTransactionRequest({
|
5106
5092
|
...params,
|
@@ -5110,7 +5096,7 @@ var Account = class extends AbstractAccount {
|
|
5110
5096
|
request.addContractInputAndOutput(contractAddress);
|
5111
5097
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5112
5098
|
request,
|
5113
|
-
[{ amount: bn17(amount), assetId: String(
|
5099
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
5114
5100
|
);
|
5115
5101
|
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5116
5102
|
this.validateGas({
|
@@ -5132,7 +5118,6 @@ var Account = class extends AbstractAccount {
|
|
5132
5118
|
*/
|
5133
5119
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5134
5120
|
const { minGasPrice } = this.provider.getGasConfig();
|
5135
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5136
5121
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5137
5122
|
const recipientDataArray = arrayify14(
|
5138
5123
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -5145,14 +5130,9 @@ var Account = class extends AbstractAccount {
|
|
5145
5130
|
...recipientDataArray,
|
5146
5131
|
...amountDataArray
|
5147
5132
|
]);
|
5148
|
-
const params = {
|
5149
|
-
script,
|
5150
|
-
gasPrice: minGasPrice,
|
5151
|
-
baseAssetId,
|
5152
|
-
...txParams
|
5153
|
-
};
|
5133
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5154
5134
|
const request = new ScriptTransactionRequest(params);
|
5155
|
-
const forwardingQuantities = [{ amount: bn17(amount), assetId:
|
5135
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
5156
5136
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5157
5137
|
request,
|
5158
5138
|
forwardingQuantities
|
@@ -8729,6 +8709,7 @@ import {
|
|
8729
8709
|
SCRIPT_FIXED_SIZE
|
8730
8710
|
} from "@fuel-ts/abi-coder";
|
8731
8711
|
import { Address as Address9 } from "@fuel-ts/address";
|
8712
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8732
8713
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8733
8714
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8734
8715
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
@@ -8806,9 +8787,8 @@ var Predicate = class extends Account {
|
|
8806
8787
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8807
8788
|
* @returns A promise that resolves to the prepared transaction request.
|
8808
8789
|
*/
|
8809
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8810
|
-
const
|
8811
|
-
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8790
|
+
async createTransfer(destination, amount, assetId = BaseAssetId4, txParams = {}) {
|
8791
|
+
const request = await super.createTransfer(destination, amount, assetId, txParams);
|
8812
8792
|
return this.populateTransactionPredicateData(request);
|
8813
8793
|
}
|
8814
8794
|
/**
|