@fuel-ts/account 0.0.0-rc-2045-20240411194225 → 0.0.0-rc-1976-20240412113424
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/index.mjs
CHANGED
@@ -29,14 +29,12 @@ 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";
|
33
32
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
34
33
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
35
34
|
import { bn as bn17 } from "@fuel-ts/math";
|
36
35
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
37
36
|
|
38
37
|
// src/providers/coin-quantity.ts
|
39
|
-
import { BaseAssetId } from "@fuel-ts/address/configs";
|
40
38
|
import { bn } from "@fuel-ts/math";
|
41
39
|
import { hexlify } from "@fuel-ts/utils";
|
42
40
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -45,11 +43,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
45
43
|
let max2;
|
46
44
|
if (Array.isArray(coinQuantityLike)) {
|
47
45
|
amount = coinQuantityLike[0];
|
48
|
-
assetId = coinQuantityLike[1]
|
49
|
-
max2 = coinQuantityLike[2]
|
46
|
+
assetId = coinQuantityLike[1];
|
47
|
+
max2 = coinQuantityLike[2];
|
50
48
|
} else {
|
51
49
|
amount = coinQuantityLike.amount;
|
52
|
-
assetId = coinQuantityLike.assetId
|
50
|
+
assetId = coinQuantityLike.assetId;
|
53
51
|
max2 = coinQuantityLike.max ?? void 0;
|
54
52
|
}
|
55
53
|
const bnAmount = bn(amount);
|
@@ -1158,7 +1156,7 @@ var outputify = (value) => {
|
|
1158
1156
|
// src/providers/transaction-request/transaction-request.ts
|
1159
1157
|
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1160
1158
|
import { Address, addressify } from "@fuel-ts/address";
|
1161
|
-
import {
|
1159
|
+
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1162
1160
|
import { randomBytes } from "@fuel-ts/crypto";
|
1163
1161
|
import { bn as bn7 } from "@fuel-ts/math";
|
1164
1162
|
import {
|
@@ -1693,6 +1691,8 @@ var BaseTransactionRequest = class {
|
|
1693
1691
|
outputs = [];
|
1694
1692
|
/** List of witnesses */
|
1695
1693
|
witnesses = [];
|
1694
|
+
/** Base asset ID - should be fetched from the chain */
|
1695
|
+
baseAssetId;
|
1696
1696
|
/**
|
1697
1697
|
* Constructor for initializing a base transaction request.
|
1698
1698
|
*
|
@@ -1705,8 +1705,9 @@ var BaseTransactionRequest = class {
|
|
1705
1705
|
witnessLimit,
|
1706
1706
|
inputs,
|
1707
1707
|
outputs,
|
1708
|
-
witnesses
|
1709
|
-
|
1708
|
+
witnesses,
|
1709
|
+
baseAssetId
|
1710
|
+
}) {
|
1710
1711
|
this.gasPrice = bn7(gasPrice);
|
1711
1712
|
this.maturity = maturity ?? 0;
|
1712
1713
|
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
@@ -1714,6 +1715,7 @@ var BaseTransactionRequest = class {
|
|
1714
1715
|
this.inputs = inputs ?? [];
|
1715
1716
|
this.outputs = outputs ?? [];
|
1716
1717
|
this.witnesses = witnesses ?? [];
|
1718
|
+
this.baseAssetId = baseAssetId;
|
1717
1719
|
}
|
1718
1720
|
static getPolicyMeta(req) {
|
1719
1721
|
let policyTypes = 0;
|
@@ -1937,11 +1939,9 @@ var BaseTransactionRequest = class {
|
|
1937
1939
|
*
|
1938
1940
|
* @param message - Message resource.
|
1939
1941
|
* @param predicate - Predicate bytes.
|
1940
|
-
* @param predicateData - Predicate data bytes.
|
1941
1942
|
*/
|
1942
1943
|
addMessageInput(message, predicate) {
|
1943
1944
|
const { recipient, sender, amount } = message;
|
1944
|
-
const assetId = BaseAssetId2;
|
1945
1945
|
let witnessIndex;
|
1946
1946
|
if (predicate) {
|
1947
1947
|
witnessIndex = 0;
|
@@ -1961,7 +1961,7 @@ var BaseTransactionRequest = class {
|
|
1961
1961
|
predicate: predicate?.bytes
|
1962
1962
|
};
|
1963
1963
|
this.pushInput(input);
|
1964
|
-
this.addChangeOutput(recipient,
|
1964
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1965
1965
|
}
|
1966
1966
|
/**
|
1967
1967
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2022,12 +2022,12 @@ var BaseTransactionRequest = class {
|
|
2022
2022
|
* @param amount - Amount of coin.
|
2023
2023
|
* @param assetId - Asset ID of coin.
|
2024
2024
|
*/
|
2025
|
-
addCoinOutput(to, amount, assetId
|
2025
|
+
addCoinOutput(to, amount, assetId) {
|
2026
2026
|
this.pushOutput({
|
2027
2027
|
type: OutputType2.Coin,
|
2028
2028
|
to: addressify(to).toB256(),
|
2029
2029
|
amount,
|
2030
|
-
assetId
|
2030
|
+
assetId: assetId ?? this.baseAssetId
|
2031
2031
|
});
|
2032
2032
|
return this;
|
2033
2033
|
}
|
@@ -2054,7 +2054,7 @@ var BaseTransactionRequest = class {
|
|
2054
2054
|
* @param to - Address of the owner.
|
2055
2055
|
* @param assetId - Asset ID of coin.
|
2056
2056
|
*/
|
2057
|
-
addChangeOutput(to, assetId
|
2057
|
+
addChangeOutput(to, assetId) {
|
2058
2058
|
const changeOutput = this.getChangeOutputs().find(
|
2059
2059
|
(output) => hexlify7(output.assetId) === assetId
|
2060
2060
|
);
|
@@ -2062,7 +2062,7 @@ var BaseTransactionRequest = class {
|
|
2062
2062
|
this.pushOutput({
|
2063
2063
|
type: OutputType2.Change,
|
2064
2064
|
to: addressify(to).toB256(),
|
2065
|
-
assetId
|
2065
|
+
assetId: assetId ?? this.baseAssetId
|
2066
2066
|
});
|
2067
2067
|
}
|
2068
2068
|
}
|
@@ -2138,7 +2138,7 @@ var BaseTransactionRequest = class {
|
|
2138
2138
|
]);
|
2139
2139
|
}
|
2140
2140
|
};
|
2141
|
-
updateAssetInput(
|
2141
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
2142
2142
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2143
2143
|
}
|
2144
2144
|
/**
|
@@ -2308,12 +2308,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2308
2308
|
*
|
2309
2309
|
* @param createTransactionRequestLike - The initial values for the instance
|
2310
2310
|
*/
|
2311
|
-
constructor({
|
2312
|
-
bytecodeWitnessIndex,
|
2313
|
-
salt,
|
2314
|
-
storageSlots,
|
2315
|
-
...rest
|
2316
|
-
} = {}) {
|
2311
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2317
2312
|
super(rest);
|
2318
2313
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2319
2314
|
this.salt = hexlify9(salt ?? ZeroBytes326);
|
@@ -2437,7 +2432,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2437
2432
|
*
|
2438
2433
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2439
2434
|
*/
|
2440
|
-
constructor({ script, scriptData, gasLimit, ...rest }
|
2435
|
+
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2441
2436
|
super(rest);
|
2442
2437
|
this.gasLimit = bn10(gasLimit);
|
2443
2438
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
@@ -3612,6 +3607,7 @@ var processGqlChain = (chain) => {
|
|
3612
3607
|
gasPerByte: bn15(feeParams.gasPerByte),
|
3613
3608
|
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3614
3609
|
chainId: bn15(consensusParameters.chainId),
|
3610
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3615
3611
|
gasCosts
|
3616
3612
|
},
|
3617
3613
|
gasCosts,
|
@@ -3854,6 +3850,17 @@ var _Provider = class {
|
|
3854
3850
|
} = this.getChain();
|
3855
3851
|
return chainId.toNumber();
|
3856
3852
|
}
|
3853
|
+
/**
|
3854
|
+
* Returns the base asset ID
|
3855
|
+
*
|
3856
|
+
* @returns A promise that resolves to the base asset ID
|
3857
|
+
*/
|
3858
|
+
getBaseAssetId() {
|
3859
|
+
const {
|
3860
|
+
consensusParameters: { baseAssetId }
|
3861
|
+
} = this.getChain();
|
3862
|
+
return baseAssetId;
|
3863
|
+
}
|
3857
3864
|
/**
|
3858
3865
|
* Submits a transaction to the chain to be executed.
|
3859
3866
|
*
|
@@ -4917,8 +4924,9 @@ var Account = class extends AbstractAccount {
|
|
4917
4924
|
* @param assetId - The asset ID to check the balance for.
|
4918
4925
|
* @returns A promise that resolves to the balance amount.
|
4919
4926
|
*/
|
4920
|
-
async getBalance(assetId
|
4921
|
-
const
|
4927
|
+
async getBalance(assetId) {
|
4928
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4929
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4922
4930
|
return amount;
|
4923
4931
|
}
|
4924
4932
|
/**
|
@@ -4956,9 +4964,10 @@ var Account = class extends AbstractAccount {
|
|
4956
4964
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4957
4965
|
*/
|
4958
4966
|
async fund(request, coinQuantities, fee) {
|
4967
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4959
4968
|
const updatedQuantities = addAmountToAsset({
|
4960
4969
|
amount: bn17(fee),
|
4961
|
-
assetId:
|
4970
|
+
assetId: baseAssetId,
|
4962
4971
|
coinQuantities
|
4963
4972
|
});
|
4964
4973
|
const quantitiesDict = {};
|
@@ -4982,8 +4991,8 @@ var Account = class extends AbstractAccount {
|
|
4982
4991
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4983
4992
|
cachedUtxos.push(input.id);
|
4984
4993
|
}
|
4985
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4986
|
-
quantitiesDict[
|
4994
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4995
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4987
4996
|
cachedMessages.push(input.nonce);
|
4988
4997
|
}
|
4989
4998
|
}
|
@@ -5015,11 +5024,13 @@ var Account = class extends AbstractAccount {
|
|
5015
5024
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5016
5025
|
* @returns A promise that resolves to the prepared transaction request.
|
5017
5026
|
*/
|
5018
|
-
async createTransfer(destination, amount, assetId
|
5027
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5019
5028
|
const { minGasPrice } = this.provider.getGasConfig();
|
5020
|
-
const
|
5029
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5030
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5031
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5021
5032
|
const request = new ScriptTransactionRequest(params);
|
5022
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
5033
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5023
5034
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5024
5035
|
estimateTxDependencies: true,
|
5025
5036
|
resourcesOwner: this
|
@@ -5045,14 +5056,15 @@ var Account = class extends AbstractAccount {
|
|
5045
5056
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5046
5057
|
* @returns A promise that resolves to the transaction response.
|
5047
5058
|
*/
|
5048
|
-
async transfer(destination, amount, assetId
|
5059
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
5049
5060
|
if (bn17(amount).lte(0)) {
|
5050
5061
|
throw new FuelError15(
|
5051
5062
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5052
5063
|
"Transfer amount must be a positive number."
|
5053
5064
|
);
|
5054
5065
|
}
|
5055
|
-
const
|
5066
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5067
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5056
5068
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5057
5069
|
}
|
5058
5070
|
/**
|
@@ -5064,7 +5076,7 @@ var Account = class extends AbstractAccount {
|
|
5064
5076
|
* @param txParams - The optional transaction parameters.
|
5065
5077
|
* @returns A promise that resolves to the transaction response.
|
5066
5078
|
*/
|
5067
|
-
async transferToContract(contractId, amount, assetId
|
5079
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5068
5080
|
if (bn17(amount).lte(0)) {
|
5069
5081
|
throw new FuelError15(
|
5070
5082
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
@@ -5073,11 +5085,13 @@ var Account = class extends AbstractAccount {
|
|
5073
5085
|
}
|
5074
5086
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
5075
5087
|
const { minGasPrice } = this.provider.getGasConfig();
|
5076
|
-
const
|
5088
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5089
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5090
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5077
5091
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5078
5092
|
hexlifiedContractId: contractAddress.toB256(),
|
5079
5093
|
amountToTransfer: bn17(amount),
|
5080
|
-
assetId
|
5094
|
+
assetId: assetIdToTransfer
|
5081
5095
|
});
|
5082
5096
|
const request = new ScriptTransactionRequest({
|
5083
5097
|
...params,
|
@@ -5087,7 +5101,7 @@ var Account = class extends AbstractAccount {
|
|
5087
5101
|
request.addContractInputAndOutput(contractAddress);
|
5088
5102
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5089
5103
|
request,
|
5090
|
-
[{ amount: bn17(amount), assetId: String(
|
5104
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
5091
5105
|
);
|
5092
5106
|
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5093
5107
|
this.validateGas({
|
@@ -5109,6 +5123,7 @@ var Account = class extends AbstractAccount {
|
|
5109
5123
|
*/
|
5110
5124
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5111
5125
|
const { minGasPrice } = this.provider.getGasConfig();
|
5126
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5112
5127
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
5113
5128
|
const recipientDataArray = arrayify14(
|
5114
5129
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
@@ -5121,9 +5136,14 @@ var Account = class extends AbstractAccount {
|
|
5121
5136
|
...recipientDataArray,
|
5122
5137
|
...amountDataArray
|
5123
5138
|
]);
|
5124
|
-
const params = {
|
5139
|
+
const params = {
|
5140
|
+
script,
|
5141
|
+
gasPrice: minGasPrice,
|
5142
|
+
baseAssetId,
|
5143
|
+
...txParams
|
5144
|
+
};
|
5125
5145
|
const request = new ScriptTransactionRequest(params);
|
5126
|
-
const forwardingQuantities = [{ amount: bn17(amount), assetId:
|
5146
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
5127
5147
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5128
5148
|
request,
|
5129
5149
|
forwardingQuantities
|
@@ -8700,7 +8720,6 @@ import {
|
|
8700
8720
|
SCRIPT_FIXED_SIZE
|
8701
8721
|
} from "@fuel-ts/abi-coder";
|
8702
8722
|
import { Address as Address9 } from "@fuel-ts/address";
|
8703
|
-
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8704
8723
|
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8705
8724
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8706
8725
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
@@ -8778,8 +8797,9 @@ var Predicate = class extends Account {
|
|
8778
8797
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8779
8798
|
* @returns A promise that resolves to the prepared transaction request.
|
8780
8799
|
*/
|
8781
|
-
async createTransfer(destination, amount, assetId
|
8782
|
-
const
|
8800
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8801
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
8802
|
+
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8783
8803
|
return this.populateTransactionPredicateData(request);
|
8784
8804
|
}
|
8785
8805
|
/**
|