@fuel-ts/account 0.0.0-rc-1976-20240424151753 → 0.0.0-rc-2143-20240424152333
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 +41 -57
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +79 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -55
- 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/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 +4 -2
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +44 -60
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +81 -95
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +43 -57
- 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 {
|
@@ -1940,13 +1942,15 @@ var BaseTransactionRequest = class {
|
|
1940
1942
|
}
|
1941
1943
|
/**
|
1942
1944
|
* Adds a single message input to the transaction and a change output for the
|
1943
|
-
*
|
1945
|
+
* baseAssetId, if one it was not added yet.
|
1944
1946
|
*
|
1945
1947
|
* @param message - Message resource.
|
1946
1948
|
* @param predicate - Predicate bytes.
|
1949
|
+
* @param predicateData - Predicate data bytes.
|
1947
1950
|
*/
|
1948
1951
|
addMessageInput(message, predicate) {
|
1949
|
-
const { recipient, sender, amount
|
1952
|
+
const { recipient, sender, amount } = message;
|
1953
|
+
const assetId = BaseAssetId2;
|
1950
1954
|
let witnessIndex;
|
1951
1955
|
if (predicate) {
|
1952
1956
|
witnessIndex = 0;
|
@@ -2027,7 +2031,7 @@ var BaseTransactionRequest = class {
|
|
2027
2031
|
* @param amount - Amount of coin.
|
2028
2032
|
* @param assetId - Asset ID of coin.
|
2029
2033
|
*/
|
2030
|
-
addCoinOutput(to, amount, assetId) {
|
2034
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
2031
2035
|
this.pushOutput({
|
2032
2036
|
type: OutputType2.Coin,
|
2033
2037
|
to: addressify(to).toB256(),
|
@@ -2059,7 +2063,7 @@ var BaseTransactionRequest = class {
|
|
2059
2063
|
* @param to - Address of the owner.
|
2060
2064
|
* @param assetId - Asset ID of coin.
|
2061
2065
|
*/
|
2062
|
-
addChangeOutput(to, assetId) {
|
2066
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
2063
2067
|
const changeOutput = this.getChangeOutputs().find(
|
2064
2068
|
(output) => hexlify7(output.assetId) === assetId
|
2065
2069
|
);
|
@@ -2116,9 +2120,8 @@ var BaseTransactionRequest = class {
|
|
2116
2120
|
* quantities array.
|
2117
2121
|
*
|
2118
2122
|
* @param quantities - CoinQuantity Array.
|
2119
|
-
* @param baseAssetId - The base asset to fund the transaction.
|
2120
2123
|
*/
|
2121
|
-
fundWithFakeUtxos(quantities,
|
2124
|
+
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2122
2125
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2123
2126
|
if ("assetId" in input) {
|
2124
2127
|
return input.assetId === assetId;
|
@@ -2144,7 +2147,7 @@ var BaseTransactionRequest = class {
|
|
2144
2147
|
]);
|
2145
2148
|
}
|
2146
2149
|
};
|
2147
|
-
updateAssetInput(
|
2150
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2148
2151
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2149
2152
|
}
|
2150
2153
|
/**
|
@@ -2314,7 +2317,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2314
2317
|
*
|
2315
2318
|
* @param createTransactionRequestLike - The initial values for the instance
|
2316
2319
|
*/
|
2317
|
-
constructor({
|
2320
|
+
constructor({
|
2321
|
+
bytecodeWitnessIndex,
|
2322
|
+
salt,
|
2323
|
+
storageSlots,
|
2324
|
+
...rest
|
2325
|
+
} = {}) {
|
2318
2326
|
super(rest);
|
2319
2327
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2320
2328
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -3575,7 +3583,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
3575
3583
|
}
|
3576
3584
|
|
3577
3585
|
// src/providers/utils/merge-quantities.ts
|
3578
|
-
var mergeQuantities = (
|
3586
|
+
var mergeQuantities = (arr1, arr2) => {
|
3579
3587
|
const resultMap = {};
|
3580
3588
|
function addToMap({ amount, assetId }) {
|
3581
3589
|
if (resultMap[assetId]) {
|
@@ -3584,7 +3592,8 @@ var mergeQuantities = (...coinQuantities) => {
|
|
3584
3592
|
resultMap[assetId] = amount;
|
3585
3593
|
}
|
3586
3594
|
}
|
3587
|
-
|
3595
|
+
arr1.forEach(addToMap);
|
3596
|
+
arr2.forEach(addToMap);
|
3588
3597
|
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
3589
3598
|
};
|
3590
3599
|
|
@@ -3612,7 +3621,6 @@ var processGqlChain = (chain) => {
|
|
3612
3621
|
gasPerByte: bn15(feeParams.gasPerByte),
|
3613
3622
|
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3614
3623
|
chainId: bn15(consensusParameters.chainId),
|
3615
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3616
3624
|
gasCosts
|
3617
3625
|
},
|
3618
3626
|
gasCosts,
|
@@ -3855,17 +3863,6 @@ var _Provider = class {
|
|
3855
3863
|
} = this.getChain();
|
3856
3864
|
return chainId.toNumber();
|
3857
3865
|
}
|
3858
|
-
/**
|
3859
|
-
* Returns the base asset ID
|
3860
|
-
*
|
3861
|
-
* @returns A promise that resolves to the base asset ID
|
3862
|
-
*/
|
3863
|
-
getBaseAssetId() {
|
3864
|
-
const {
|
3865
|
-
consensusParameters: { baseAssetId }
|
3866
|
-
} = this.getChain();
|
3867
|
-
return baseAssetId;
|
3868
|
-
}
|
3869
3866
|
/**
|
3870
3867
|
* Submits a transaction to the chain to be executed.
|
3871
3868
|
*
|
@@ -4096,10 +4093,9 @@ var _Provider = class {
|
|
4096
4093
|
const { minGasPrice } = this.getGasConfig();
|
4097
4094
|
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
4098
4095
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
4099
|
-
const baseAssetId = this.getBaseAssetId();
|
4100
4096
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4101
4097
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4102
|
-
txRequestClone.fundWithFakeUtxos(allQuantities,
|
4098
|
+
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4103
4099
|
if (isScriptTransaction) {
|
4104
4100
|
txRequestClone.gasLimit = bn15(0);
|
4105
4101
|
}
|
@@ -4930,9 +4926,8 @@ var Account = class extends AbstractAccount {
|
|
4930
4926
|
* @param assetId - The asset ID to check the balance for.
|
4931
4927
|
* @returns A promise that resolves to the balance amount.
|
4932
4928
|
*/
|
4933
|
-
async getBalance(assetId) {
|
4934
|
-
const
|
4935
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4929
|
+
async getBalance(assetId = BaseAssetId3) {
|
4930
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4936
4931
|
return amount;
|
4937
4932
|
}
|
4938
4933
|
/**
|
@@ -4970,10 +4965,9 @@ var Account = class extends AbstractAccount {
|
|
4970
4965
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4971
4966
|
*/
|
4972
4967
|
async fund(request, coinQuantities, fee) {
|
4973
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4974
4968
|
const updatedQuantities = addAmountToAsset({
|
4975
4969
|
amount: bn17(fee),
|
4976
|
-
assetId:
|
4970
|
+
assetId: BaseAssetId3,
|
4977
4971
|
coinQuantities
|
4978
4972
|
});
|
4979
4973
|
const quantitiesDict = {};
|
@@ -4997,8 +4991,8 @@ var Account = class extends AbstractAccount {
|
|
4997
4991
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4998
4992
|
cachedUtxos.push(input.id);
|
4999
4993
|
}
|
5000
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
5001
|
-
quantitiesDict[
|
4994
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4995
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
5002
4996
|
cachedMessages.push(input.nonce);
|
5003
4997
|
}
|
5004
4998
|
}
|
@@ -5030,12 +5024,11 @@ var Account = class extends AbstractAccount {
|
|
5030
5024
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5031
5025
|
* @returns A promise that resolves to the prepared transaction request.
|
5032
5026
|
*/
|
5033
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5027
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5034
5028
|
const { minGasPrice } = this.provider.getGasConfig();
|
5035
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5036
5029
|
const params = { gasPrice: minGasPrice, ...txParams };
|
5037
5030
|
const request = new ScriptTransactionRequest(params);
|
5038
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
5031
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
5039
5032
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5040
5033
|
estimateTxDependencies: true,
|
5041
5034
|
resourcesOwner: this
|
@@ -5061,15 +5054,14 @@ var Account = class extends AbstractAccount {
|
|
5061
5054
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5062
5055
|
* @returns A promise that resolves to the transaction response.
|
5063
5056
|
*/
|
5064
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
5057
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5065
5058
|
if (bn17(amount).lte(0)) {
|
5066
5059
|
throw new FuelError15(
|
5067
5060
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5068
5061
|
"Transfer amount must be a positive number."
|
5069
5062
|
);
|
5070
5063
|
}
|
5071
|
-
const
|
5072
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5064
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
5073
5065
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5074
5066
|
}
|
5075
5067
|
/**
|
@@ -5081,7 +5073,7 @@ var Account = class extends AbstractAccount {
|
|
5081
5073
|
* @param txParams - The optional transaction parameters.
|
5082
5074
|
* @returns A promise that resolves to the transaction response.
|
5083
5075
|
*/
|
5084
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5076
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5085
5077
|
if (bn17(amount).lte(0)) {
|
5086
5078
|
throw new FuelError15(
|
5087
5079
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
@@ -5090,12 +5082,11 @@ var Account = class extends AbstractAccount {
|
|
5090
5082
|
}
|
5091
5083
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5092
5084
|
const { minGasPrice } = this.provider.getGasConfig();
|
5093
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5094
5085
|
const params = { gasPrice: minGasPrice, ...txParams };
|
5095
5086
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5096
5087
|
hexlifiedContractId: contractAddress.toB256(),
|
5097
5088
|
amountToTransfer: bn17(amount),
|
5098
|
-
assetId
|
5089
|
+
assetId
|
5099
5090
|
});
|
5100
5091
|
const request = new ScriptTransactionRequest({
|
5101
5092
|
...params,
|
@@ -5105,7 +5096,7 @@ var Account = class extends AbstractAccount {
|
|
5105
5096
|
request.addContractInputAndOutput(contractAddress);
|
5106
5097
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5107
5098
|
request,
|
5108
|
-
[{ amount: bn17(amount), assetId: String(
|
5099
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
5109
5100
|
);
|
5110
5101
|
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5111
5102
|
this.validateGas({
|
@@ -5127,7 +5118,6 @@ var Account = class extends AbstractAccount {
|
|
5127
5118
|
*/
|
5128
5119
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5129
5120
|
const { minGasPrice } = this.provider.getGasConfig();
|
5130
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5131
5121
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5132
5122
|
const recipientDataArray = arrayify14(
|
5133
5123
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -5140,13 +5130,9 @@ var Account = class extends AbstractAccount {
|
|
5140
5130
|
...recipientDataArray,
|
5141
5131
|
...amountDataArray
|
5142
5132
|
]);
|
5143
|
-
const params = {
|
5144
|
-
script,
|
5145
|
-
gasPrice: minGasPrice,
|
5146
|
-
...txParams
|
5147
|
-
};
|
5133
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5148
5134
|
const request = new ScriptTransactionRequest(params);
|
5149
|
-
const forwardingQuantities = [{ amount: bn17(amount), assetId:
|
5135
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
5150
5136
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5151
5137
|
request,
|
5152
5138
|
forwardingQuantities
|
@@ -8723,6 +8709,7 @@ import {
|
|
8723
8709
|
SCRIPT_FIXED_SIZE
|
8724
8710
|
} from "@fuel-ts/abi-coder";
|
8725
8711
|
import { Address as Address9 } from "@fuel-ts/address";
|
8712
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8726
8713
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8727
8714
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8728
8715
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
@@ -8800,9 +8787,8 @@ var Predicate = class extends Account {
|
|
8800
8787
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8801
8788
|
* @returns A promise that resolves to the prepared transaction request.
|
8802
8789
|
*/
|
8803
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8804
|
-
const
|
8805
|
-
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);
|
8806
8792
|
return this.populateTransactionPredicateData(request);
|
8807
8793
|
}
|
8808
8794
|
/**
|