@fuel-ts/account 0.101.1 → 0.101.3
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.
- package/dist/account.d.ts +45 -14
- package/dist/account.d.ts.map +1 -1
- package/dist/connectors/fuel-connector.d.ts +8 -0
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/connectors/types/connector-types.d.ts +4 -2
- package/dist/connectors/types/connector-types.d.ts.map +1 -1
- package/dist/connectors/types/events.d.ts +6 -1
- package/dist/connectors/types/events.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.global.js +723 -164
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +936 -471
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +856 -394
- package/dist/index.mjs.map +1 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +2 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts +23 -4
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/call.d.ts +4 -7
- package/dist/providers/transaction-summary/call.d.ts.map +1 -1
- package/dist/providers/transaction-summary/operations.d.ts +1 -1
- package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts +10 -1
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -1
- package/dist/providers/utils/handle-gql-error-message.d.ts.map +1 -1
- package/dist/providers/utils/transaction-response-serialization.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +650 -164
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +823 -381
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +751 -308
- package/dist/test-utils.mjs.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/consolidate-coins.d.ts +43 -0
- package/dist/utils/consolidate-coins.d.ts.map +1 -0
- package/package.json +15 -15
package/dist/test-utils.js
CHANGED
@@ -255,8 +255,9 @@ var launchNode = /* @__PURE__ */ __name(async ({
|
|
255
255
|
"--consensus-key",
|
256
256
|
"--db-type",
|
257
257
|
"--poa-instant",
|
258
|
+
"--native-executor-version",
|
258
259
|
"--min-gas-price",
|
259
|
-
"--
|
260
|
+
"--starting-gas-price"
|
260
261
|
]);
|
261
262
|
const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
|
262
263
|
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils2.defaultConsensusKey;
|
@@ -405,8 +406,8 @@ var launchNode = /* @__PURE__ */ __name(async ({
|
|
405
406
|
), "launchNode");
|
406
407
|
|
407
408
|
// src/test-utils/setup-test-provider-and-wallets.ts
|
408
|
-
var
|
409
|
-
var
|
409
|
+
var import_utils47 = require("@fuel-ts/utils");
|
410
|
+
var import_ramda11 = require("ramda");
|
410
411
|
|
411
412
|
// src/providers/coin-quantity.ts
|
412
413
|
var import_math2 = require("@fuel-ts/math");
|
@@ -447,7 +448,7 @@ var import_address4 = require("@fuel-ts/address");
|
|
447
448
|
var import_errors21 = require("@fuel-ts/errors");
|
448
449
|
var import_math20 = require("@fuel-ts/math");
|
449
450
|
var import_transactions25 = require("@fuel-ts/transactions");
|
450
|
-
var
|
451
|
+
var import_utils33 = require("@fuel-ts/utils");
|
451
452
|
var import_versions = require("@fuel-ts/versions");
|
452
453
|
var import_graphql_request = require("graphql-request");
|
453
454
|
var import_graphql_tag2 = __toESM(require("graphql-tag"));
|
@@ -1847,8 +1848,11 @@ var import_graphql = require("graphql");
|
|
1847
1848
|
|
1848
1849
|
// src/providers/utils/handle-gql-error-message.ts
|
1849
1850
|
var import_errors3 = require("@fuel-ts/errors");
|
1851
|
+
var ASSET_ID_REGEX = /[0-9a-fA-F]{32,64}/g;
|
1850
1852
|
var gqlErrorMessage = {
|
1851
1853
|
RPC_CONSISTENCY: /The required fuel block height is higher than the current block height. Required: \d+, Current: \d+/,
|
1854
|
+
INSUFFICIENT_FUNDS: /the target cannot be met due to insufficient coins available for [0-9a-fA-F]{32,64}. Collected: \d+/,
|
1855
|
+
MAX_COINS_REACHED: /the target for [0-9a-fA-F]{32,64} cannot be met due to exceeding the \d+ coin limit. Collected: \d+./,
|
1852
1856
|
NOT_ENOUGH_COINS_MAX_COINS: /the target cannot be met due to no coins available or exceeding the \d+ coin limit./,
|
1853
1857
|
ASSET_NOT_FOUND: /resource was not found in table/,
|
1854
1858
|
MULTIPLE_CHANGE_POLICIES: /The asset ([a-fA-F0-9]{64}) has multiple change policies/,
|
@@ -1864,6 +1868,46 @@ var mapGqlErrorMessage = /* @__PURE__ */ __name((error) => {
|
|
1864
1868
|
error
|
1865
1869
|
);
|
1866
1870
|
}
|
1871
|
+
if (gqlErrorMessage.MAX_COINS_REACHED.test(error.message)) {
|
1872
|
+
const matches = error.message.match(ASSET_ID_REGEX);
|
1873
|
+
const assetId = matches ? `0x${matches[0]}` : null;
|
1874
|
+
const owner = matches ? `0x${matches[1]}` : null;
|
1875
|
+
let suffix = "";
|
1876
|
+
if (assetId) {
|
1877
|
+
suffix += `
|
1878
|
+
Asset ID: '${assetId}'.`;
|
1879
|
+
}
|
1880
|
+
if (owner) {
|
1881
|
+
suffix += `
|
1882
|
+
Owner: '${owner}'.`;
|
1883
|
+
}
|
1884
|
+
return new import_errors3.FuelError(
|
1885
|
+
import_errors3.ErrorCode.MAX_COINS_REACHED,
|
1886
|
+
`You have too many small value coins - consider combining UTXOs.${suffix}`,
|
1887
|
+
{ assetId, owner },
|
1888
|
+
error
|
1889
|
+
);
|
1890
|
+
}
|
1891
|
+
if (gqlErrorMessage.INSUFFICIENT_FUNDS.test(error.message)) {
|
1892
|
+
const matches = error.message.match(ASSET_ID_REGEX);
|
1893
|
+
const assetId = matches ? `0x${matches[0]}` : null;
|
1894
|
+
const owner = matches ? `0x${matches[1]}` : null;
|
1895
|
+
let suffix = "";
|
1896
|
+
if (assetId) {
|
1897
|
+
suffix += `
|
1898
|
+
Asset ID: '${assetId}'.`;
|
1899
|
+
}
|
1900
|
+
if (owner) {
|
1901
|
+
suffix += `
|
1902
|
+
Owner: '${owner}'.`;
|
1903
|
+
}
|
1904
|
+
return new import_errors3.FuelError(
|
1905
|
+
import_errors3.ErrorCode.INSUFFICIENT_FUNDS,
|
1906
|
+
`Insufficient funds.${suffix}`,
|
1907
|
+
{ assetId, owner },
|
1908
|
+
error
|
1909
|
+
);
|
1910
|
+
}
|
1867
1911
|
if (gqlErrorMessage.MULTIPLE_CHANGE_POLICIES.test(error.message)) {
|
1868
1912
|
const match = error.message.match(/asset ([a-fA-F0-9]{64})/);
|
1869
1913
|
const assetId = match?.[1] || "";
|
@@ -2891,58 +2935,98 @@ ${import_configs5.PANIC_DOC_URL}#variant.${statusReason}`;
|
|
2891
2935
|
});
|
2892
2936
|
}, "assemblePanicError");
|
2893
2937
|
var stringify = /* @__PURE__ */ __name((obj) => JSON.stringify(obj, null, 2), "stringify");
|
2894
|
-
var
|
2938
|
+
var assembleSignalErrorMessage = /* @__PURE__ */ __name((reasonHex, logs, metadata) => {
|
2895
2939
|
let errorMessage = "The transaction reverted with an unknown reason.";
|
2896
|
-
const revertReceipt = receipts.find(({ type }) => type === import_transactions7.ReceiptType.Revert);
|
2897
2940
|
let reason = "";
|
2898
|
-
|
2899
|
-
|
2900
|
-
|
2901
|
-
|
2902
|
-
|
2903
|
-
|
2904
|
-
|
2905
|
-
|
2906
|
-
|
2907
|
-
}
|
2908
|
-
|
2909
|
-
|
2910
|
-
|
2911
|
-
errorMessage = `The transaction reverted because of an "assert_eq" statement${suffix}`;
|
2912
|
-
break;
|
2913
|
-
}
|
2914
|
-
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
2915
|
-
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
2916
|
-
reason = "assert_ne";
|
2917
|
-
errorMessage = `The transaction reverted because of an "assert_ne" statement${suffix}`;
|
2918
|
-
break;
|
2919
|
-
}
|
2920
|
-
case import_configs5.FAILED_ASSERT_SIGNAL:
|
2921
|
-
reason = "assert";
|
2922
|
-
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
2923
|
-
break;
|
2924
|
-
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
2925
|
-
reason = "MissingOutputVariable";
|
2926
|
-
errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
|
2927
|
-
break;
|
2928
|
-
default:
|
2929
|
-
throw new import_errors9.FuelError(
|
2930
|
-
import_errors9.ErrorCode.UNKNOWN,
|
2931
|
-
`The transaction reverted with an unknown reason: ${revertReceipt.val}`,
|
2932
|
-
{
|
2933
|
-
...metadata,
|
2934
|
-
reason: "unknown"
|
2935
|
-
}
|
2936
|
-
);
|
2941
|
+
const lastLog = logs[logs.length - 1];
|
2942
|
+
const lastButOneLog = logs[logs.length - 2];
|
2943
|
+
switch (reasonHex) {
|
2944
|
+
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
2945
|
+
reason = "require";
|
2946
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
|
2947
|
+
break;
|
2948
|
+
}
|
2949
|
+
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
2950
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
|
2951
|
+
reason = "assert_eq";
|
2952
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${suffix}`;
|
2953
|
+
break;
|
2937
2954
|
}
|
2955
|
+
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
2956
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
2957
|
+
reason = "assert_ne";
|
2958
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${suffix}`;
|
2959
|
+
break;
|
2960
|
+
}
|
2961
|
+
case import_configs5.FAILED_ASSERT_SIGNAL:
|
2962
|
+
reason = "assert";
|
2963
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
2964
|
+
break;
|
2965
|
+
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
2966
|
+
reason = "MissingOutputVariable";
|
2967
|
+
errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
|
2968
|
+
break;
|
2969
|
+
default:
|
2970
|
+
reason = `revert_with_log`;
|
2971
|
+
errorMessage = `The transaction reverted because a "revert_with_log" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
|
2972
|
+
break;
|
2938
2973
|
}
|
2939
2974
|
return new import_errors9.FuelError(import_errors9.ErrorCode.SCRIPT_REVERTED, errorMessage, {
|
2940
2975
|
...metadata,
|
2941
2976
|
reason
|
2942
2977
|
});
|
2978
|
+
}, "assembleSignalErrorMessage");
|
2979
|
+
function buildAbiErrorMessage(abiError, logs, metadata, reason) {
|
2980
|
+
const { pos, msg } = abiError;
|
2981
|
+
let errorMessage = "";
|
2982
|
+
const positionMessage = pos ? `
|
2983
|
+
|
2984
|
+
This error originated at ${JSON.stringify(pos, null, 2)}` : "";
|
2985
|
+
if (msg) {
|
2986
|
+
errorMessage = `A sway "panic" expression was invoked with the message: "${msg}".${positionMessage}`;
|
2987
|
+
} else {
|
2988
|
+
const value = logs[logs.length - 1];
|
2989
|
+
errorMessage = `A sway "panic" expression was invoked with the value: ${JSON.stringify(value)}.${positionMessage}`;
|
2990
|
+
}
|
2991
|
+
return new import_errors9.FuelError(import_errors9.ErrorCode.SCRIPT_REVERTED, errorMessage, {
|
2992
|
+
...metadata,
|
2993
|
+
abiError,
|
2994
|
+
reason
|
2995
|
+
});
|
2996
|
+
}
|
2997
|
+
__name(buildAbiErrorMessage, "buildAbiErrorMessage");
|
2998
|
+
function findErrorInAbis(statusReason, abis = []) {
|
2999
|
+
for (const abi of abis) {
|
3000
|
+
if (abi.errorCodes?.[statusReason]) {
|
3001
|
+
return abi.errorCodes[statusReason];
|
3002
|
+
}
|
3003
|
+
}
|
3004
|
+
return void 0;
|
3005
|
+
}
|
3006
|
+
__name(findErrorInAbis, "findErrorInAbis");
|
3007
|
+
var assembleRevertError = /* @__PURE__ */ __name((_receipts, logs, metadata, statusReason, abis) => {
|
3008
|
+
const match = statusReason.match(/Revert\((\d+)\)/);
|
3009
|
+
const reason = match?.[1] ?? statusReason;
|
3010
|
+
const reasonHex = (0, import_math8.bn)(reason).toHex();
|
3011
|
+
if (Object.values(import_configs5.SwaySignalErrors).includes(reasonHex)) {
|
3012
|
+
return assembleSignalErrorMessage(reasonHex, logs, metadata);
|
3013
|
+
}
|
3014
|
+
let abiError;
|
3015
|
+
if (abis) {
|
3016
|
+
const abisArr = [abis.main, ...Object.values(abis.otherContractsAbis)];
|
3017
|
+
abiError = findErrorInAbis(reason, abisArr);
|
3018
|
+
}
|
3019
|
+
if (abiError) {
|
3020
|
+
return buildAbiErrorMessage(abiError, logs, metadata, reason);
|
3021
|
+
}
|
3022
|
+
const errorMessage = `The transaction reverted with reason: ${reason}.`;
|
3023
|
+
return new import_errors9.FuelError(import_errors9.ErrorCode.SCRIPT_REVERTED, errorMessage, {
|
3024
|
+
...metadata,
|
3025
|
+
reason
|
3026
|
+
});
|
2943
3027
|
}, "assembleRevertError");
|
2944
3028
|
var extractTxError = /* @__PURE__ */ __name((params) => {
|
2945
|
-
const { receipts, statusReason, logs, groupedLogs } = params;
|
3029
|
+
const { receipts, statusReason, logs, groupedLogs, abis } = params;
|
2946
3030
|
const isPanic = receipts.some(({ type }) => type === import_transactions7.ReceiptType.Panic);
|
2947
3031
|
const isRevert = receipts.some(({ type }) => type === import_transactions7.ReceiptType.Revert);
|
2948
3032
|
const metadata = {
|
@@ -2956,7 +3040,7 @@ var extractTxError = /* @__PURE__ */ __name((params) => {
|
|
2956
3040
|
if (isPanic) {
|
2957
3041
|
return assemblePanicError(statusReason, metadata);
|
2958
3042
|
}
|
2959
|
-
return assembleRevertError(receipts, logs, metadata);
|
3043
|
+
return assembleRevertError(receipts, logs, metadata, statusReason, abis);
|
2960
3044
|
}, "extractTxError");
|
2961
3045
|
|
2962
3046
|
// src/providers/utils/merge-quantities.ts
|
@@ -3929,11 +4013,15 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3929
4013
|
* @deprecated Use `provider.assembleTx` instead.
|
3930
4014
|
* Check the migration guide https://docs.fuel.network/guide/assembling-transactions/migration-guide.html for more information.
|
3931
4015
|
*/
|
3932
|
-
async estimateAndFund(account, {
|
4016
|
+
async estimateAndFund(account, {
|
4017
|
+
signatureCallback,
|
4018
|
+
quantities = [],
|
4019
|
+
skipAutoConsolidation
|
4020
|
+
} = {}) {
|
3933
4021
|
const txCost = await account.getTransactionCost(this, { signatureCallback, quantities });
|
3934
4022
|
this.maxFee = txCost.maxFee;
|
3935
4023
|
this.gasLimit = txCost.gasUsed;
|
3936
|
-
await account.fund(this, txCost);
|
4024
|
+
await account.fund(this, txCost, { skipAutoConsolidation });
|
3937
4025
|
return this;
|
3938
4026
|
}
|
3939
4027
|
/**
|
@@ -4500,12 +4588,12 @@ var ResourceCache = class {
|
|
4500
4588
|
var import_errors19 = require("@fuel-ts/errors");
|
4501
4589
|
var import_math19 = require("@fuel-ts/math");
|
4502
4590
|
var import_transactions23 = require("@fuel-ts/transactions");
|
4503
|
-
var
|
4591
|
+
var import_utils30 = require("@fuel-ts/utils");
|
4504
4592
|
|
4505
4593
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
4506
4594
|
var import_math18 = require("@fuel-ts/math");
|
4507
4595
|
var import_transactions21 = require("@fuel-ts/transactions");
|
4508
|
-
var
|
4596
|
+
var import_utils28 = require("@fuel-ts/utils");
|
4509
4597
|
|
4510
4598
|
// src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
|
4511
4599
|
var import_math14 = require("@fuel-ts/math");
|
@@ -4578,6 +4666,45 @@ var import_configs11 = require("@fuel-ts/address/configs");
|
|
4578
4666
|
var import_errors17 = require("@fuel-ts/errors");
|
4579
4667
|
var import_math16 = require("@fuel-ts/math");
|
4580
4668
|
var import_transactions19 = require("@fuel-ts/transactions");
|
4669
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4670
|
+
|
4671
|
+
// src/providers/transaction-summary/call.ts
|
4672
|
+
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
4673
|
+
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4674
|
+
var getFunctionCall = /* @__PURE__ */ __name(({
|
4675
|
+
abi,
|
4676
|
+
receipt,
|
4677
|
+
offset,
|
4678
|
+
scriptData
|
4679
|
+
}) => {
|
4680
|
+
const [functionSelector, argumentsOffset] = new import_abi_coder5.StdStringCoder().decode(scriptData, offset);
|
4681
|
+
const abiInterface = new import_abi_coder6.Interface(abi);
|
4682
|
+
const functionFragment = abiInterface.getFunction(functionSelector);
|
4683
|
+
const inputs = functionFragment.jsonFn.inputs;
|
4684
|
+
let argumentsProvided;
|
4685
|
+
if (inputs.length) {
|
4686
|
+
const functionArgsBytes = scriptData.slice(argumentsOffset);
|
4687
|
+
const decodedArguments = functionFragment.decodeArguments(functionArgsBytes);
|
4688
|
+
argumentsProvided = inputs.reduce((prev, input, index) => {
|
4689
|
+
const value = decodedArguments?.[index];
|
4690
|
+
const name = input.name;
|
4691
|
+
if (name) {
|
4692
|
+
return {
|
4693
|
+
...prev,
|
4694
|
+
// reparse to remove bn
|
4695
|
+
[name]: JSON.parse(JSON.stringify(value))
|
4696
|
+
};
|
4697
|
+
}
|
4698
|
+
return prev;
|
4699
|
+
}, {});
|
4700
|
+
}
|
4701
|
+
return {
|
4702
|
+
functionSignature: functionFragment.signature,
|
4703
|
+
functionName: functionFragment.name,
|
4704
|
+
argumentsProvided,
|
4705
|
+
...receipt.amount?.isZero() ? {} : { amount: receipt.amount, assetId: receipt.assetId }
|
4706
|
+
};
|
4707
|
+
}, "getFunctionCall");
|
4581
4708
|
|
4582
4709
|
// src/providers/transaction-summary/input.ts
|
4583
4710
|
var import_errors16 = require("@fuel-ts/errors");
|
@@ -4861,12 +4988,45 @@ function getWithdrawFromFuelOperations({
|
|
4861
4988
|
return withdrawFromFuelOperations;
|
4862
4989
|
}
|
4863
4990
|
__name(getWithdrawFromFuelOperations, "getWithdrawFromFuelOperations");
|
4864
|
-
function
|
4865
|
-
|
4866
|
-
|
4867
|
-
|
4991
|
+
function findBytesSegmentIndex(whole, segment) {
|
4992
|
+
for (let i = 0; i <= whole.length - segment.length; i++) {
|
4993
|
+
let match = true;
|
4994
|
+
for (let j = 0; j < segment.length; j++) {
|
4995
|
+
if (whole[i + j] !== segment[j]) {
|
4996
|
+
match = false;
|
4997
|
+
break;
|
4998
|
+
}
|
4999
|
+
}
|
5000
|
+
if (match) {
|
5001
|
+
return i;
|
5002
|
+
}
|
4868
5003
|
}
|
4869
|
-
return
|
5004
|
+
return -1;
|
5005
|
+
}
|
5006
|
+
__name(findBytesSegmentIndex, "findBytesSegmentIndex");
|
5007
|
+
function getContractCalls(contractInput, abiMap, receipt, scriptData) {
|
5008
|
+
const calls = [];
|
5009
|
+
const abi = abiMap?.[contractInput.contractID];
|
5010
|
+
if (!abi || !scriptData) {
|
5011
|
+
return calls;
|
5012
|
+
}
|
5013
|
+
const bytesSegment = (0, import_utils26.concat)([
|
5014
|
+
(0, import_utils26.arrayify)(receipt.to),
|
5015
|
+
// Contract ID (32 bytes)
|
5016
|
+
(0, import_math16.toBytes)(receipt.param1.toHex(), 8),
|
5017
|
+
// Function selector offset (8 bytes)
|
5018
|
+
(0, import_math16.toBytes)(receipt.param2.toHex(), 8)
|
5019
|
+
// Function args offset (8 bytes)
|
5020
|
+
]);
|
5021
|
+
const segmentIndex = findBytesSegmentIndex(scriptData, bytesSegment);
|
5022
|
+
const canDecodeFunctionCall = segmentIndex !== -1;
|
5023
|
+
if (!canDecodeFunctionCall) {
|
5024
|
+
return calls;
|
5025
|
+
}
|
5026
|
+
const offset = segmentIndex + bytesSegment.length;
|
5027
|
+
const call = getFunctionCall({ abi, receipt, offset, scriptData });
|
5028
|
+
calls.push(call);
|
5029
|
+
return calls;
|
4870
5030
|
}
|
4871
5031
|
__name(getContractCalls, "getContractCalls");
|
4872
5032
|
function getAssetsSent(receipt) {
|
@@ -4878,14 +5038,14 @@ function getAssetsSent(receipt) {
|
|
4878
5038
|
];
|
4879
5039
|
}
|
4880
5040
|
__name(getAssetsSent, "getAssetsSent");
|
4881
|
-
function processCallReceipt(receipt, contractInput, inputs, abiMap,
|
5041
|
+
function processCallReceipt(receipt, contractInput, inputs, abiMap, scriptData, baseAssetId) {
|
4882
5042
|
const assetId = receipt.assetId === import_configs11.ZeroBytes32 ? baseAssetId : receipt.assetId;
|
4883
5043
|
const input = getInputFromAssetId(inputs, assetId, assetId === baseAssetId);
|
4884
5044
|
if (!input) {
|
4885
5045
|
return [];
|
4886
5046
|
}
|
4887
5047
|
const inputAddress = getInputAccountAddress(input);
|
4888
|
-
const calls = getContractCalls(contractInput, abiMap, receipt,
|
5048
|
+
const calls = getContractCalls(contractInput, abiMap, receipt, scriptData);
|
4889
5049
|
return [
|
4890
5050
|
{
|
4891
5051
|
name: "Contract call" /* contractCall */,
|
@@ -4910,7 +5070,6 @@ function getContractCallOperations({
|
|
4910
5070
|
receipts,
|
4911
5071
|
abiMap,
|
4912
5072
|
rawPayload,
|
4913
|
-
maxInputs,
|
4914
5073
|
baseAssetId
|
4915
5074
|
}) {
|
4916
5075
|
const contractCallReceipts = getReceiptsCall(receipts);
|
@@ -4920,16 +5079,15 @@ function getContractCallOperations({
|
|
4920
5079
|
if (!contractInput) {
|
4921
5080
|
return [];
|
4922
5081
|
}
|
5082
|
+
let scriptData;
|
5083
|
+
if (rawPayload) {
|
5084
|
+
const [transaction] = new import_transactions19.TransactionCoder().decode((0, import_utils26.arrayify)(rawPayload), 0);
|
5085
|
+
if (transaction.type === import_transactions19.TransactionType.Script) {
|
5086
|
+
scriptData = (0, import_utils26.arrayify)(transaction.scriptData);
|
5087
|
+
}
|
5088
|
+
}
|
4923
5089
|
return contractCallReceipts.filter((receipt) => receipt.to === contractInput.contractID).flatMap(
|
4924
|
-
(receipt) => processCallReceipt(
|
4925
|
-
receipt,
|
4926
|
-
contractInput,
|
4927
|
-
inputs,
|
4928
|
-
abiMap,
|
4929
|
-
rawPayload,
|
4930
|
-
maxInputs,
|
4931
|
-
baseAssetId
|
4932
|
-
)
|
5090
|
+
(receipt) => processCallReceipt(receipt, contractInput, inputs, abiMap, scriptData, baseAssetId)
|
4933
5091
|
);
|
4934
5092
|
});
|
4935
5093
|
}
|
@@ -5253,7 +5411,7 @@ function assembleTransactionSummary(params) {
|
|
5253
5411
|
baseAssetId
|
5254
5412
|
} = params;
|
5255
5413
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
5256
|
-
const rawPayload = (0,
|
5414
|
+
const rawPayload = (0, import_utils28.hexlify)(transactionBytes);
|
5257
5415
|
const operations = getOperations({
|
5258
5416
|
transactionType: transaction.type,
|
5259
5417
|
inputs: transaction.inputs || [],
|
@@ -5284,7 +5442,7 @@ function assembleTransactionSummary(params) {
|
|
5284
5442
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
5285
5443
|
let date;
|
5286
5444
|
if (time) {
|
5287
|
-
date =
|
5445
|
+
date = import_utils28.DateTime.fromTai64(time);
|
5288
5446
|
}
|
5289
5447
|
const transactionSummary = {
|
5290
5448
|
id,
|
@@ -5345,7 +5503,7 @@ function assemblePreConfirmationTransactionSummary(params) {
|
|
5345
5503
|
type = getTransactionTypeName(transaction.type);
|
5346
5504
|
tip = (0, import_math18.bn)(transaction.policies?.find((policy) => policy.type === import_transactions21.PolicyType.Tip)?.data);
|
5347
5505
|
if (receipts) {
|
5348
|
-
const rawPayload = (0,
|
5506
|
+
const rawPayload = (0, import_utils28.hexlify)(new import_transactions21.TransactionCoder().encode(transaction));
|
5349
5507
|
operations = getOperations({
|
5350
5508
|
transactionType: transaction.type,
|
5351
5509
|
inputs: transaction.inputs || [],
|
@@ -5391,7 +5549,7 @@ function assemblePreConfirmationTransactionSummary(params) {
|
|
5391
5549
|
__name(assemblePreConfirmationTransactionSummary, "assemblePreConfirmationTransactionSummary");
|
5392
5550
|
|
5393
5551
|
// src/providers/transaction-response/getAllDecodedLogs.ts
|
5394
|
-
var
|
5552
|
+
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
5395
5553
|
var import_configs12 = require("@fuel-ts/address/configs");
|
5396
5554
|
var import_transactions22 = require("@fuel-ts/transactions");
|
5397
5555
|
function getAllDecodedLogs(opts) {
|
@@ -5411,8 +5569,8 @@ function getAllDecodedLogs(opts) {
|
|
5411
5569
|
const isLogFromMainAbi = receipt.id === import_configs12.ZeroBytes32 || mainContract === receipt.id;
|
5412
5570
|
const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
|
5413
5571
|
if (isDecodable) {
|
5414
|
-
const interfaceToUse = isLogFromMainAbi ? new
|
5415
|
-
const data = receipt.type === import_transactions22.ReceiptType.Log ? new
|
5572
|
+
const interfaceToUse = isLogFromMainAbi ? new import_abi_coder7.Interface(mainAbi) : new import_abi_coder7.Interface(externalAbis[receipt.id]);
|
5573
|
+
const data = receipt.type === import_transactions22.ReceiptType.Log ? new import_abi_coder7.BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
5416
5574
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
5417
5575
|
logs.push(decodedLog);
|
5418
5576
|
groupedLogs[receipt.id] = [...groupedLogs[receipt.id] || [], decodedLog];
|
@@ -5427,25 +5585,6 @@ __name(getAllDecodedLogs, "getAllDecodedLogs");
|
|
5427
5585
|
|
5428
5586
|
// src/providers/transaction-response/transaction-response.ts
|
5429
5587
|
var TransactionResponse = class _TransactionResponse {
|
5430
|
-
/**
|
5431
|
-
* Constructor for `TransactionResponse`.
|
5432
|
-
*
|
5433
|
-
* @param tx - The transaction ID or TransactionRequest.
|
5434
|
-
* @param provider - The provider.
|
5435
|
-
*/
|
5436
|
-
constructor(tx, provider, chainId, abis, submitTxSubscription) {
|
5437
|
-
this.submitTxSubscription = submitTxSubscription;
|
5438
|
-
if (typeof tx === "string") {
|
5439
|
-
this.id = tx;
|
5440
|
-
} else {
|
5441
|
-
this.id = tx.getTransactionId(chainId);
|
5442
|
-
this.request = tx;
|
5443
|
-
}
|
5444
|
-
this.provider = provider;
|
5445
|
-
this.abis = abis;
|
5446
|
-
this.waitForResult = this.waitForResult.bind(this);
|
5447
|
-
this.waitForPreConfirmation = this.waitForPreConfirmation.bind(this);
|
5448
|
-
}
|
5449
5588
|
static {
|
5450
5589
|
__name(this, "TransactionResponse");
|
5451
5590
|
}
|
@@ -5460,9 +5599,42 @@ var TransactionResponse = class _TransactionResponse {
|
|
5460
5599
|
request;
|
5461
5600
|
status;
|
5462
5601
|
abis;
|
5602
|
+
submitTxSubscription;
|
5463
5603
|
preConfirmationStatus;
|
5464
5604
|
waitingForStreamData = false;
|
5465
5605
|
statusResolvers = /* @__PURE__ */ new Map();
|
5606
|
+
/**
|
5607
|
+
* Constructor for `TransactionResponse`.
|
5608
|
+
*/
|
5609
|
+
constructor(constructorParams, provider, chainId, abis, submitTxSubscription) {
|
5610
|
+
let tx;
|
5611
|
+
let _provider;
|
5612
|
+
let _chainId;
|
5613
|
+
let _abis;
|
5614
|
+
if (typeof constructorParams === "object" && "provider" in constructorParams && arguments.length === 1) {
|
5615
|
+
tx = constructorParams.transactionRequestOrId;
|
5616
|
+
_provider = constructorParams.provider;
|
5617
|
+
_chainId = constructorParams.chainId;
|
5618
|
+
_abis = constructorParams.abis;
|
5619
|
+
this.submitTxSubscription = constructorParams.submitAndAwaitSubscription;
|
5620
|
+
} else {
|
5621
|
+
tx = constructorParams;
|
5622
|
+
_provider = provider;
|
5623
|
+
_chainId = chainId;
|
5624
|
+
_abis = abis;
|
5625
|
+
this.submitTxSubscription = submitTxSubscription;
|
5626
|
+
}
|
5627
|
+
if (typeof tx === "string") {
|
5628
|
+
this.id = tx;
|
5629
|
+
} else {
|
5630
|
+
this.id = tx.getTransactionId(_chainId);
|
5631
|
+
this.request = tx;
|
5632
|
+
}
|
5633
|
+
this.provider = _provider;
|
5634
|
+
this.abis = _abis;
|
5635
|
+
this.waitForResult = this.waitForResult.bind(this);
|
5636
|
+
this.waitForPreConfirmation = this.waitForPreConfirmation.bind(this);
|
5637
|
+
}
|
5466
5638
|
/**
|
5467
5639
|
* Async constructor for `TransactionResponse`. This method can be used to create
|
5468
5640
|
* an instance of `TransactionResponse` and wait for the transaction to be fetched
|
@@ -5511,7 +5683,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
5511
5683
|
}
|
5512
5684
|
const gqlTransaction = this.gqlTransaction ?? await this.fetch();
|
5513
5685
|
const { rawPayload } = gqlTransaction;
|
5514
|
-
const bytes = (0,
|
5686
|
+
const bytes = (0, import_utils30.arrayify)(rawPayload);
|
5515
5687
|
const [tx] = new import_transactions23.TransactionCoder().decode(bytes, 0);
|
5516
5688
|
return {
|
5517
5689
|
tx,
|
@@ -5699,6 +5871,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
5699
5871
|
...transactionSummary
|
5700
5872
|
};
|
5701
5873
|
let { logs, groupedLogs } = { logs: [], groupedLogs: {} };
|
5874
|
+
let abis;
|
5702
5875
|
if (this.abis) {
|
5703
5876
|
({ logs, groupedLogs } = getAllDecodedLogs({
|
5704
5877
|
receipts: transactionSummary.receipts,
|
@@ -5707,6 +5880,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
5707
5880
|
}));
|
5708
5881
|
transactionResult.logs = logs;
|
5709
5882
|
transactionResult.groupedLogs = groupedLogs;
|
5883
|
+
abis = this.abis;
|
5710
5884
|
}
|
5711
5885
|
const { receipts } = transactionResult;
|
5712
5886
|
const status = this.getTransactionStatus();
|
@@ -5716,7 +5890,8 @@ var TransactionResponse = class _TransactionResponse {
|
|
5716
5890
|
receipts,
|
5717
5891
|
statusReason: reason,
|
5718
5892
|
logs,
|
5719
|
-
groupedLogs
|
5893
|
+
groupedLogs,
|
5894
|
+
abis
|
5720
5895
|
});
|
5721
5896
|
}
|
5722
5897
|
return transactionResult;
|
@@ -5778,12 +5953,12 @@ var TransactionResponse = class _TransactionResponse {
|
|
5778
5953
|
};
|
5779
5954
|
|
5780
5955
|
// src/providers/transaction-response/getDecodedLogs.ts
|
5781
|
-
var
|
5956
|
+
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
5782
5957
|
var import_configs13 = require("@fuel-ts/address/configs");
|
5783
5958
|
var import_transactions24 = require("@fuel-ts/transactions");
|
5784
5959
|
|
5785
5960
|
// src/providers/utils/auto-retry-fetch.ts
|
5786
|
-
var
|
5961
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5787
5962
|
function getWaitDelay(options, retryAttemptNum) {
|
5788
5963
|
const duration = options.baseDelay ?? 150;
|
5789
5964
|
switch (options.backoff) {
|
@@ -5814,7 +5989,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
5814
5989
|
throw error;
|
5815
5990
|
}
|
5816
5991
|
const delay = getWaitDelay(options, retryNum);
|
5817
|
-
await (0,
|
5992
|
+
await (0, import_utils32.sleep)(delay);
|
5818
5993
|
return autoRetryFetch(fetchFn, options, retryNum)(...args);
|
5819
5994
|
}
|
5820
5995
|
};
|
@@ -5954,7 +6129,7 @@ var Provider = class _Provider {
|
|
5954
6129
|
return url.replace(/-sub$/, "");
|
5955
6130
|
}
|
5956
6131
|
static hasWriteOperationHappened(url) {
|
5957
|
-
return (0,
|
6132
|
+
return (0, import_utils33.isDefined)(_Provider.currentBlockHeightCache[this.normalizeUrl(url)]);
|
5958
6133
|
}
|
5959
6134
|
/**
|
5960
6135
|
* @hidden
|
@@ -5976,7 +6151,15 @@ var Provider = class _Provider {
|
|
5976
6151
|
if (_Provider.ENABLE_RPC_CONSISTENCY && _Provider.hasWriteOperationHappened(url)) {
|
5977
6152
|
_Provider.applyBlockHeight(fullRequest, url);
|
5978
6153
|
}
|
5979
|
-
|
6154
|
+
const response = await _Provider.fetchAndProcessBlockHeight(url, fullRequest, options);
|
6155
|
+
if (response.body === null) {
|
6156
|
+
throw new import_errors21.FuelError(
|
6157
|
+
import_errors21.ErrorCode.RESPONSE_BODY_EMPTY,
|
6158
|
+
"The response from the server is missing the body",
|
6159
|
+
{ timestamp: (/* @__PURE__ */ new Date()).toISOString(), request, response }
|
6160
|
+
);
|
6161
|
+
}
|
6162
|
+
return response;
|
5980
6163
|
}, retryOptions);
|
5981
6164
|
}
|
5982
6165
|
static applyBlockHeight(request, url) {
|
@@ -5999,24 +6182,26 @@ var Provider = class _Provider {
|
|
5999
6182
|
baseDelay: 500
|
6000
6183
|
};
|
6001
6184
|
for (let retriesLeft = retryOptions.maxRetries; retriesLeft > 0; --retriesLeft) {
|
6002
|
-
|
6003
|
-
|
6004
|
-
|
6005
|
-
|
6006
|
-
|
6007
|
-
|
6008
|
-
|
6185
|
+
if (response.body) {
|
6186
|
+
const { extensions } = await parseGraphqlResponse({
|
6187
|
+
response,
|
6188
|
+
isSubscription: url.endsWith("-sub")
|
6189
|
+
});
|
6190
|
+
_Provider.setCurrentBlockHeight(url, extensions?.current_fuel_block_height);
|
6191
|
+
if (!extensions?.fuel_block_height_precondition_failed) {
|
6192
|
+
break;
|
6193
|
+
}
|
6009
6194
|
}
|
6010
6195
|
const retryAttempt = retryOptions.maxRetries - retriesLeft + 1;
|
6011
6196
|
const sleepTime = getWaitDelay(retryOptions, retryAttempt);
|
6012
|
-
await (0,
|
6197
|
+
await (0, import_utils33.sleep)(sleepTime);
|
6013
6198
|
response = await fetchFn();
|
6014
6199
|
}
|
6015
6200
|
return response;
|
6016
6201
|
}
|
6017
6202
|
static setCurrentBlockHeight(url, height) {
|
6018
6203
|
const writeOperationHappened = _Provider.hasWriteOperationHappened(url);
|
6019
|
-
if (!(0,
|
6204
|
+
if (!(0, import_utils33.isDefined)(height) || !writeOperationHappened) {
|
6020
6205
|
return;
|
6021
6206
|
}
|
6022
6207
|
const normalizedUrl = _Provider.normalizeUrl(url);
|
@@ -6051,7 +6236,7 @@ var Provider = class _Provider {
|
|
6051
6236
|
_Provider.chainInfoCache[this.urlWithoutAuth] = chain;
|
6052
6237
|
_Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
|
6053
6238
|
}
|
6054
|
-
if ((0,
|
6239
|
+
if ((0, import_utils33.isDefined)(resourceCacheTTL)) {
|
6055
6240
|
if (resourceCacheTTL !== -1) {
|
6056
6241
|
this.cache = new ResourceCache(resourceCacheTTL);
|
6057
6242
|
} else {
|
@@ -6414,7 +6599,7 @@ var Provider = class _Provider {
|
|
6414
6599
|
await this.estimateTxDependencies(transactionRequest);
|
6415
6600
|
}
|
6416
6601
|
await this.validateTransaction(transactionRequest);
|
6417
|
-
const encodedTransaction = (0,
|
6602
|
+
const encodedTransaction = (0, import_utils33.hexlify)(transactionRequest.toTransactionBytes());
|
6418
6603
|
let abis;
|
6419
6604
|
if (isTransactionTypeScript(transactionRequest)) {
|
6420
6605
|
abis = transactionRequest.abis;
|
@@ -6428,7 +6613,13 @@ var Provider = class _Provider {
|
|
6428
6613
|
transactionRequest.getTransactionId(await this.getChainId())
|
6429
6614
|
);
|
6430
6615
|
const chainId = await this.getChainId();
|
6431
|
-
return new TransactionResponse(
|
6616
|
+
return new TransactionResponse({
|
6617
|
+
transactionRequestOrId: transactionRequest,
|
6618
|
+
provider: this,
|
6619
|
+
chainId,
|
6620
|
+
abis,
|
6621
|
+
submitAndAwaitSubscription: subscription
|
6622
|
+
});
|
6432
6623
|
}
|
6433
6624
|
/**
|
6434
6625
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -6445,7 +6636,7 @@ var Provider = class _Provider {
|
|
6445
6636
|
if (estimateTxDependencies) {
|
6446
6637
|
return this.estimateTxDependencies(transactionRequest);
|
6447
6638
|
}
|
6448
|
-
const encodedTransaction = (0,
|
6639
|
+
const encodedTransaction = (0, import_utils33.hexlify)(transactionRequest.toTransactionBytes());
|
6449
6640
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
6450
6641
|
encodedTransactions: encodedTransaction,
|
6451
6642
|
utxoValidation: utxoValidation || false
|
@@ -6469,7 +6660,7 @@ var Provider = class _Provider {
|
|
6469
6660
|
if (!shouldEstimatePredicates) {
|
6470
6661
|
return transactionRequest;
|
6471
6662
|
}
|
6472
|
-
const encodedTransaction = (0,
|
6663
|
+
const encodedTransaction = (0, import_utils33.hexlify)(transactionRequest.toTransactionBytes());
|
6473
6664
|
const response = await this.operations.estimatePredicates({
|
6474
6665
|
encodedTransaction
|
6475
6666
|
});
|
@@ -6501,7 +6692,7 @@ var Provider = class _Provider {
|
|
6501
6692
|
estimatePredicates
|
6502
6693
|
} = await this.operations.estimatePredicatesAndGasPrice({
|
6503
6694
|
blockHorizon: String(blockHorizon),
|
6504
|
-
encodedTransaction: (0,
|
6695
|
+
encodedTransaction: (0, import_utils33.hexlify)(transactionRequest.toTransactionBytes())
|
6505
6696
|
});
|
6506
6697
|
transactionRequest = this.parseEstimatePredicatesResponse(
|
6507
6698
|
transactionRequest,
|
@@ -6539,7 +6730,7 @@ var Provider = class _Provider {
|
|
6539
6730
|
const {
|
6540
6731
|
dryRun: [{ receipts: serializedReceipts, status }]
|
6541
6732
|
} = await this.operations.dryRun({
|
6542
|
-
encodedTransactions: [(0,
|
6733
|
+
encodedTransactions: [(0, import_utils33.hexlify)(transactionRequest.toTransactionBytes())],
|
6543
6734
|
utxoValidation: false,
|
6544
6735
|
gasPrice: gasPrice.toString()
|
6545
6736
|
});
|
@@ -6594,7 +6785,7 @@ var Provider = class _Provider {
|
|
6594
6785
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
6595
6786
|
allRequests.forEach((req, index) => {
|
6596
6787
|
if (isTransactionTypeScript(req)) {
|
6597
|
-
serializedTransactionsMap.set(index, (0,
|
6788
|
+
serializedTransactionsMap.set(index, (0, import_utils33.hexlify)(req.toTransactionBytes()));
|
6598
6789
|
}
|
6599
6790
|
});
|
6600
6791
|
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
@@ -6630,7 +6821,7 @@ var Provider = class _Provider {
|
|
6630
6821
|
transactionRequest: request
|
6631
6822
|
});
|
6632
6823
|
request.maxFee = maxFee;
|
6633
|
-
serializedTransactionsMap.set(requestIdx, (0,
|
6824
|
+
serializedTransactionsMap.set(requestIdx, (0, import_utils33.hexlify)(request.toTransactionBytes()));
|
6634
6825
|
nextRoundTransactions.push(requestIdx);
|
6635
6826
|
}
|
6636
6827
|
}
|
@@ -6651,7 +6842,7 @@ var Provider = class _Provider {
|
|
6651
6842
|
if (estimateTxDependencies) {
|
6652
6843
|
return this.estimateMultipleTxDependencies(transactionRequests);
|
6653
6844
|
}
|
6654
|
-
const encodedTransactions = transactionRequests.map((tx) => (0,
|
6845
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils33.hexlify)(tx.toTransactionBytes()));
|
6655
6846
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
6656
6847
|
encodedTransactions,
|
6657
6848
|
utxoValidation: utxoValidation || false
|
@@ -6701,7 +6892,7 @@ var Provider = class _Provider {
|
|
6701
6892
|
const chainInfo = await this.getChain();
|
6702
6893
|
const { gasPriceFactor, maxGasPerTx } = await this.getGasConfig();
|
6703
6894
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
6704
|
-
if (!(0,
|
6895
|
+
if (!(0, import_utils33.isDefined)(gasPrice)) {
|
6705
6896
|
gasPrice = await this.estimateGasPrice(10);
|
6706
6897
|
}
|
6707
6898
|
const minFee = calculateGasFee({
|
@@ -6753,7 +6944,7 @@ var Provider = class _Provider {
|
|
6753
6944
|
if (estimateTxDependencies) {
|
6754
6945
|
return this.estimateTxDependencies(transactionRequest);
|
6755
6946
|
}
|
6756
|
-
const encodedTransactions = [(0,
|
6947
|
+
const encodedTransactions = [(0, import_utils33.hexlify)(transactionRequest.toTransactionBytes())];
|
6757
6948
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
6758
6949
|
encodedTransactions,
|
6759
6950
|
utxoValidation: true
|
@@ -6916,7 +7107,7 @@ var Provider = class _Provider {
|
|
6916
7107
|
const {
|
6917
7108
|
assembleTx: { status, transaction: gqlTransaction, gasPrice }
|
6918
7109
|
} = await this.operations.assembleTx({
|
6919
|
-
tx: (0,
|
7110
|
+
tx: (0, import_utils33.hexlify)(request.toTransactionBytes()),
|
6920
7111
|
blockHorizon: String(blockHorizon),
|
6921
7112
|
feeAddressIndex: String(feePayerIndex),
|
6922
7113
|
requiredBalances,
|
@@ -6968,7 +7159,7 @@ var Provider = class _Provider {
|
|
6968
7159
|
paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
|
6969
7160
|
inputArgs: paginationArgs
|
6970
7161
|
}),
|
6971
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
7162
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils33.hexlify)(assetId) }
|
6972
7163
|
});
|
6973
7164
|
const coins = edges.map(({ node }) => ({
|
6974
7165
|
id: node.utxoId,
|
@@ -7000,7 +7191,7 @@ var Provider = class _Provider {
|
|
7000
7191
|
const coinsQuery = {
|
7001
7192
|
owner: ownerAddress.toB256(),
|
7002
7193
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
7003
|
-
assetId: (0,
|
7194
|
+
assetId: (0, import_utils33.hexlify)(assetId),
|
7004
7195
|
amount: (amount.eqn(0) ? (0, import_math20.bn)(1) : amount).toString(10),
|
7005
7196
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
7006
7197
|
})),
|
@@ -7158,7 +7349,7 @@ var Provider = class _Provider {
|
|
7158
7349
|
},
|
7159
7350
|
transactionIds: block.transactions.map((tx) => tx.id),
|
7160
7351
|
transactions: block.transactions.map(
|
7161
|
-
(tx) => new import_transactions25.TransactionCoder().decode((0,
|
7352
|
+
(tx) => new import_transactions25.TransactionCoder().decode((0, import_utils33.arrayify)(tx.rawPayload), 0)?.[0]
|
7162
7353
|
)
|
7163
7354
|
};
|
7164
7355
|
}
|
@@ -7175,7 +7366,7 @@ var Provider = class _Provider {
|
|
7175
7366
|
}
|
7176
7367
|
try {
|
7177
7368
|
return new import_transactions25.TransactionCoder().decode(
|
7178
|
-
(0,
|
7369
|
+
(0, import_utils33.arrayify)(transaction.rawPayload),
|
7179
7370
|
0
|
7180
7371
|
)?.[0];
|
7181
7372
|
} catch (error) {
|
@@ -7203,7 +7394,7 @@ var Provider = class _Provider {
|
|
7203
7394
|
const coder = new import_transactions25.TransactionCoder();
|
7204
7395
|
const transactions = edges.map(({ node: { rawPayload } }) => {
|
7205
7396
|
try {
|
7206
|
-
return coder.decode((0,
|
7397
|
+
return coder.decode((0, import_utils33.arrayify)(rawPayload), 0)[0];
|
7207
7398
|
} catch (error) {
|
7208
7399
|
if (error instanceof import_errors21.FuelError && error.code === import_errors21.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
7209
7400
|
console.warn("Unsupported transaction type encountered");
|
@@ -7252,7 +7443,7 @@ var Provider = class _Provider {
|
|
7252
7443
|
async getContractBalance(contractId, assetId) {
|
7253
7444
|
const { contractBalance } = await this.operations.getContractBalance({
|
7254
7445
|
contract: new import_address4.Address(contractId).toB256(),
|
7255
|
-
asset: (0,
|
7446
|
+
asset: (0, import_utils33.hexlify)(assetId)
|
7256
7447
|
});
|
7257
7448
|
return (0, import_math20.bn)(contractBalance.amount, 10);
|
7258
7449
|
}
|
@@ -7266,7 +7457,7 @@ var Provider = class _Provider {
|
|
7266
7457
|
async getBalance(owner, assetId) {
|
7267
7458
|
const { balance } = await this.operations.getBalanceV2({
|
7268
7459
|
owner: new import_address4.Address(owner).toB256(),
|
7269
|
-
assetId: (0,
|
7460
|
+
assetId: (0, import_utils33.hexlify)(assetId)
|
7270
7461
|
});
|
7271
7462
|
return (0, import_math20.bn)(balance.amountU128, 10);
|
7272
7463
|
}
|
@@ -7471,7 +7662,7 @@ var Provider = class _Provider {
|
|
7471
7662
|
async produceBlocks(amount, startTime) {
|
7472
7663
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
7473
7664
|
blocksToProduce: (0, import_math20.bn)(amount).toString(10),
|
7474
|
-
startTimestamp: startTime ?
|
7665
|
+
startTimestamp: startTime ? import_utils33.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
7475
7666
|
});
|
7476
7667
|
return (0, import_math20.bn)(latestBlockHeight);
|
7477
7668
|
}
|
@@ -7523,7 +7714,11 @@ var Provider = class _Provider {
|
|
7523
7714
|
*/
|
7524
7715
|
async getTransactionResponse(transactionId) {
|
7525
7716
|
const chainId = await this.getChainId();
|
7526
|
-
return new TransactionResponse(
|
7717
|
+
return new TransactionResponse({
|
7718
|
+
transactionRequestOrId: transactionId,
|
7719
|
+
provider: this,
|
7720
|
+
chainId
|
7721
|
+
});
|
7527
7722
|
}
|
7528
7723
|
/**
|
7529
7724
|
* Returns Message for given nonce.
|
@@ -7574,18 +7769,21 @@ var Provider = class _Provider {
|
|
7574
7769
|
extractDryRunError(transactionRequest, receipts, reason) {
|
7575
7770
|
let logs = [];
|
7576
7771
|
let groupedLogs = {};
|
7772
|
+
let abis;
|
7577
7773
|
if (transactionRequest.type === import_transactions25.TransactionType.Script && transactionRequest.abis) {
|
7578
7774
|
({ logs, groupedLogs } = getAllDecodedLogs({
|
7579
7775
|
receipts,
|
7580
7776
|
mainAbi: transactionRequest.abis.main,
|
7581
7777
|
externalAbis: transactionRequest.abis.otherContractsAbis
|
7582
7778
|
}));
|
7779
|
+
abis = transactionRequest.abis;
|
7583
7780
|
}
|
7584
7781
|
return extractTxError({
|
7585
7782
|
logs,
|
7586
7783
|
groupedLogs,
|
7587
7784
|
receipts,
|
7588
|
-
statusReason: reason
|
7785
|
+
statusReason: reason,
|
7786
|
+
abis
|
7589
7787
|
});
|
7590
7788
|
}
|
7591
7789
|
/**
|
@@ -7624,8 +7822,8 @@ var Provider = class _Provider {
|
|
7624
7822
|
*/
|
7625
7823
|
async adjustResourcesToIgnoreForAddresses(addresses, resourcesIdsToIgnore) {
|
7626
7824
|
const final = {
|
7627
|
-
messages: resourcesIdsToIgnore?.messages?.map((nonce) => (0,
|
7628
|
-
utxos: resourcesIdsToIgnore?.utxos?.map((id) => (0,
|
7825
|
+
messages: resourcesIdsToIgnore?.messages?.map((nonce) => (0, import_utils33.hexlify)(nonce)) || [],
|
7826
|
+
utxos: resourcesIdsToIgnore?.utxos?.map((id) => (0, import_utils33.hexlify)(id)) || []
|
7629
7827
|
};
|
7630
7828
|
if (this.cache) {
|
7631
7829
|
const cache2 = this.cache;
|
@@ -7657,16 +7855,16 @@ var Provider = class _Provider {
|
|
7657
7855
|
var import_errors22 = require("@fuel-ts/errors");
|
7658
7856
|
var import_math21 = require("@fuel-ts/math");
|
7659
7857
|
var import_transactions26 = require("@fuel-ts/transactions");
|
7660
|
-
var
|
7858
|
+
var import_utils35 = require("@fuel-ts/utils");
|
7661
7859
|
|
7662
7860
|
// src/providers/transaction-summary/assemble-transaction-summary-from-serialized.ts
|
7663
7861
|
var import_math22 = require("@fuel-ts/math");
|
7664
7862
|
var import_transactions27 = require("@fuel-ts/transactions");
|
7665
|
-
var
|
7863
|
+
var import_utils36 = require("@fuel-ts/utils");
|
7666
7864
|
|
7667
7865
|
// src/test-utils/test-asset-id.ts
|
7668
7866
|
var import_crypto4 = require("@fuel-ts/crypto");
|
7669
|
-
var
|
7867
|
+
var import_utils37 = require("@fuel-ts/utils");
|
7670
7868
|
var TestAssetId = class _TestAssetId {
|
7671
7869
|
constructor(value) {
|
7672
7870
|
this.value = value;
|
@@ -7683,7 +7881,7 @@ var TestAssetId = class _TestAssetId {
|
|
7683
7881
|
static random(count = 1) {
|
7684
7882
|
const assetIds = [];
|
7685
7883
|
for (let i = 0; i < count; i++) {
|
7686
|
-
assetIds.push(new _TestAssetId((0,
|
7884
|
+
assetIds.push(new _TestAssetId((0, import_utils37.hexlify)((0, import_crypto4.randomBytes)(32))));
|
7687
7885
|
}
|
7688
7886
|
return assetIds;
|
7689
7887
|
}
|
@@ -7691,23 +7889,23 @@ var TestAssetId = class _TestAssetId {
|
|
7691
7889
|
|
7692
7890
|
// src/test-utils/wallet-config.ts
|
7693
7891
|
var import_crypto9 = require("@fuel-ts/crypto");
|
7694
|
-
var
|
7695
|
-
var
|
7696
|
-
var
|
7892
|
+
var import_errors29 = require("@fuel-ts/errors");
|
7893
|
+
var import_math26 = require("@fuel-ts/math");
|
7894
|
+
var import_utils46 = require("@fuel-ts/utils");
|
7697
7895
|
|
7698
7896
|
// src/wallet/base-wallet-unlocked.ts
|
7699
7897
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7700
|
-
var
|
7898
|
+
var import_utils41 = require("@fuel-ts/utils");
|
7701
7899
|
|
7702
7900
|
// src/account.ts
|
7703
|
-
var
|
7704
|
-
var
|
7901
|
+
var import_abi_coder10 = require("@fuel-ts/abi-coder");
|
7902
|
+
var import_address7 = require("@fuel-ts/address");
|
7705
7903
|
var import_crypto5 = require("@fuel-ts/crypto");
|
7706
|
-
var
|
7707
|
-
var
|
7708
|
-
var
|
7709
|
-
var
|
7710
|
-
var
|
7904
|
+
var import_errors24 = require("@fuel-ts/errors");
|
7905
|
+
var import_math24 = require("@fuel-ts/math");
|
7906
|
+
var import_transactions29 = require("@fuel-ts/transactions");
|
7907
|
+
var import_utils39 = require("@fuel-ts/utils");
|
7908
|
+
var import_ramda10 = require("ramda");
|
7711
7909
|
|
7712
7910
|
// src/types.ts
|
7713
7911
|
var AbstractAccount = class {
|
@@ -7716,18 +7914,166 @@ var AbstractAccount = class {
|
|
7716
7914
|
}
|
7717
7915
|
};
|
7718
7916
|
|
7719
|
-
// src/utils/
|
7720
|
-
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
7917
|
+
// src/utils/consolidate-coins.ts
|
7721
7918
|
var import_address5 = require("@fuel-ts/address");
|
7722
|
-
var
|
7919
|
+
var import_errors23 = require("@fuel-ts/errors");
|
7920
|
+
var import_math23 = require("@fuel-ts/math");
|
7921
|
+
var import_transactions28 = require("@fuel-ts/transactions");
|
7922
|
+
var import_ramda9 = require("ramda");
|
7923
|
+
var CONSOLIDATABLE_ERROR_CODES = [import_errors23.ErrorCode.MAX_COINS_REACHED];
|
7924
|
+
var consolidateCoinsIfRequired = /* @__PURE__ */ __name(async (opts) => {
|
7925
|
+
const { error: errorUnknown, account, skipAutoConsolidation = false } = opts;
|
7926
|
+
if (skipAutoConsolidation) {
|
7927
|
+
return false;
|
7928
|
+
}
|
7929
|
+
const error = import_errors23.FuelError.parse(errorUnknown);
|
7930
|
+
if (CONSOLIDATABLE_ERROR_CODES.includes(error.code)) {
|
7931
|
+
const { assetId, owner } = error.metadata;
|
7932
|
+
return account.startConsolidation({
|
7933
|
+
owner,
|
7934
|
+
assetId
|
7935
|
+
});
|
7936
|
+
}
|
7937
|
+
return false;
|
7938
|
+
}, "consolidateCoinsIfRequired");
|
7939
|
+
var getAllCoins = /* @__PURE__ */ __name(async (account, assetId) => {
|
7940
|
+
const all = [];
|
7941
|
+
let hasNextPage = true;
|
7942
|
+
let after;
|
7943
|
+
while (hasNextPage) {
|
7944
|
+
const { coins, pageInfo } = await account.getCoins(assetId, { after });
|
7945
|
+
all.push(...coins);
|
7946
|
+
after = coins.pop()?.id;
|
7947
|
+
hasNextPage = pageInfo.hasNextPage;
|
7948
|
+
}
|
7949
|
+
return { coins: all };
|
7950
|
+
}, "getAllCoins");
|
7951
|
+
var sortCoins = /* @__PURE__ */ __name(({ coins }) => coins.sort((a, b) => b.amount.cmp(a.amount)), "sortCoins");
|
7952
|
+
var createOuputCoin = /* @__PURE__ */ __name((opts) => {
|
7953
|
+
const { transactionId, outputs, baseAssetId } = opts;
|
7954
|
+
const outputChangeIndex = outputs.findIndex(
|
7955
|
+
(output) => output.type === import_transactions28.OutputType.Change && output.assetId === baseAssetId
|
7956
|
+
);
|
7957
|
+
if (outputChangeIndex === -1) {
|
7958
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.UNKNOWN, "No change output found");
|
7959
|
+
}
|
7960
|
+
const outputCoin = outputs[outputChangeIndex];
|
7961
|
+
const outputIndexPadded = Number(outputChangeIndex).toString().padStart(4, "0");
|
7962
|
+
return {
|
7963
|
+
id: `${transactionId}${outputIndexPadded}`,
|
7964
|
+
assetId: outputCoin.assetId,
|
7965
|
+
amount: outputCoin.amount,
|
7966
|
+
owner: new import_address5.Address(outputCoin.to),
|
7967
|
+
blockCreated: (0, import_math23.bn)(0),
|
7968
|
+
txCreatedIdx: (0, import_math23.bn)(0)
|
7969
|
+
};
|
7970
|
+
}, "createOuputCoin");
|
7971
|
+
var consolidateCoins = /* @__PURE__ */ __name(async ({
|
7972
|
+
account,
|
7973
|
+
assetId
|
7974
|
+
}) => {
|
7975
|
+
const chainInfo = await account.provider.getChain();
|
7976
|
+
const chainId = chainInfo.consensusParameters.chainId.toNumber();
|
7977
|
+
const gasPrice = await account.provider.estimateGasPrice(10);
|
7978
|
+
const maxInputs = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
|
7979
|
+
const baseAssetId = await account.provider.getBaseAssetId();
|
7980
|
+
const isBaseAsset = assetId === baseAssetId;
|
7981
|
+
const batchSize = maxInputs;
|
7982
|
+
const numberOfFundingCoins = maxInputs;
|
7983
|
+
let funding = [];
|
7984
|
+
let dust = [];
|
7985
|
+
if (isBaseAsset) {
|
7986
|
+
const coins = await getAllCoins(account, baseAssetId).then(sortCoins);
|
7987
|
+
funding = coins.slice(0, numberOfFundingCoins);
|
7988
|
+
dust = coins.slice(numberOfFundingCoins);
|
7989
|
+
} else {
|
7990
|
+
funding = await getAllCoins(account, baseAssetId).then(sortCoins).then((coins) => coins.slice(0, numberOfFundingCoins));
|
7991
|
+
dust = await getAllCoins(account, assetId).then(({ coins }) => coins);
|
7992
|
+
}
|
7993
|
+
if (funding.length === 0) {
|
7994
|
+
throw new import_errors23.FuelError(
|
7995
|
+
import_errors23.ErrorCode.INSUFFICIENT_FUNDS,
|
7996
|
+
`Insufficient funds to consolidate.
|
7997
|
+
Asset ID: ${baseAssetId}
|
7998
|
+
Owner: ${account.address.toB256()}`
|
7999
|
+
);
|
8000
|
+
}
|
8001
|
+
const batches = [
|
8002
|
+
...(0, import_ramda9.splitEvery)(batchSize, funding),
|
8003
|
+
// We leave one coin for the funding coin
|
8004
|
+
...(0, import_ramda9.splitEvery)(batchSize - 1, dust)
|
8005
|
+
];
|
8006
|
+
const txs = batches.map((batch) => {
|
8007
|
+
const request = new ScriptTransactionRequest({
|
8008
|
+
scriptData: "0x"
|
8009
|
+
});
|
8010
|
+
request.addResources(batch);
|
8011
|
+
return request;
|
8012
|
+
});
|
8013
|
+
const submitAll = /* @__PURE__ */ __name(async (opts = {}) => {
|
8014
|
+
const txResponses = [];
|
8015
|
+
let previousTx;
|
8016
|
+
for (let i = 0; i < txs.length; i++) {
|
8017
|
+
let currentTx = txs[i];
|
8018
|
+
const step = i + 1;
|
8019
|
+
if (previousTx) {
|
8020
|
+
const coin = createOuputCoin({
|
8021
|
+
transactionId: previousTx.transactionId,
|
8022
|
+
outputs: previousTx.outputs,
|
8023
|
+
baseAssetId
|
8024
|
+
});
|
8025
|
+
currentTx.addResource(coin);
|
8026
|
+
}
|
8027
|
+
if ("populateTransactionPredicateData" in account && typeof account.populateTransactionPredicateData === "function") {
|
8028
|
+
currentTx = account.populateTransactionPredicateData(currentTx);
|
8029
|
+
currentTx = await account.provider.estimatePredicates(currentTx);
|
8030
|
+
}
|
8031
|
+
const fee = calculateGasFee({
|
8032
|
+
gasPrice,
|
8033
|
+
gas: currentTx.calculateMinGas(chainInfo),
|
8034
|
+
priceFactor: chainInfo.consensusParameters.feeParameters.gasPriceFactor,
|
8035
|
+
tip: currentTx.tip
|
8036
|
+
});
|
8037
|
+
currentTx.maxFee = fee;
|
8038
|
+
currentTx.gasLimit = (0, import_math23.bn)(1e3);
|
8039
|
+
opts.onTransactionStart?.({
|
8040
|
+
tx: currentTx,
|
8041
|
+
step,
|
8042
|
+
assetId,
|
8043
|
+
transactionId: currentTx.getTransactionId(chainId)
|
8044
|
+
});
|
8045
|
+
const response = await account.sendTransaction(currentTx);
|
8046
|
+
const result = await response.waitForResult();
|
8047
|
+
txResponses.push(result);
|
8048
|
+
previousTx = {
|
8049
|
+
transactionId: response.id,
|
8050
|
+
outputs: result.transaction.outputs
|
8051
|
+
};
|
8052
|
+
}
|
8053
|
+
return {
|
8054
|
+
txResponses,
|
8055
|
+
errors: []
|
8056
|
+
};
|
8057
|
+
}, "submitAll");
|
8058
|
+
return {
|
8059
|
+
txs,
|
8060
|
+
totalFeeCost: txs.reduce((acc, request) => acc.add(request.maxFee), (0, import_math23.bn)(0)),
|
8061
|
+
submitAll
|
8062
|
+
};
|
8063
|
+
}, "consolidateCoins");
|
8064
|
+
|
8065
|
+
// src/utils/formatTransferToContractScriptData.ts
|
8066
|
+
var import_abi_coder9 = require("@fuel-ts/abi-coder");
|
8067
|
+
var import_address6 = require("@fuel-ts/address");
|
8068
|
+
var import_utils38 = require("@fuel-ts/utils");
|
7723
8069
|
var asm = __toESM(require("@fuels/vm-asm"));
|
7724
8070
|
var formatTransferToContractScriptData = /* @__PURE__ */ __name((transferParams) => {
|
7725
|
-
const numberCoder = new
|
8071
|
+
const numberCoder = new import_abi_coder9.BigNumberCoder("u64");
|
7726
8072
|
return transferParams.reduce((acc, transferParam) => {
|
7727
8073
|
const { assetId, amount, contractId } = transferParam;
|
7728
8074
|
const encoded = numberCoder.encode(amount);
|
7729
|
-
const scriptData = (0,
|
7730
|
-
return (0,
|
8075
|
+
const scriptData = (0, import_utils38.concat)([new import_address6.Address(contractId).toBytes(), encoded, (0, import_utils38.arrayify)(assetId)]);
|
8076
|
+
return (0, import_utils38.concat)([acc, scriptData]);
|
7731
8077
|
}, new Uint8Array());
|
7732
8078
|
}, "formatTransferToContractScriptData");
|
7733
8079
|
var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferParams) => {
|
@@ -7735,24 +8081,24 @@ var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferPar
|
|
7735
8081
|
await asm.initWasm();
|
7736
8082
|
let script = new Uint8Array();
|
7737
8083
|
transferParams.forEach((_, i) => {
|
7738
|
-
const offset = (
|
7739
|
-
script = (0,
|
8084
|
+
const offset = (import_abi_coder9.CONTRACT_ID_LEN + import_abi_coder9.WORD_SIZE + import_abi_coder9.ASSET_ID_LEN) * i;
|
8085
|
+
script = (0, import_utils38.concat)([
|
7740
8086
|
script,
|
7741
8087
|
// Load ScriptData into register 0x10.
|
7742
8088
|
asm.gtf(16, 0, asm.GTFArgs.ScriptData).to_bytes(),
|
7743
8089
|
// Add the offset to 0x10 so it will point to the current contract ID, store in 0x11.
|
7744
8090
|
asm.addi(17, 16, offset).to_bytes(),
|
7745
8091
|
// Add CONTRACT_ID_LEN to 0x11 to point to the amount in the ScriptData, store in 0x12.
|
7746
|
-
asm.addi(18, 17,
|
8092
|
+
asm.addi(18, 17, import_abi_coder9.CONTRACT_ID_LEN).to_bytes(),
|
7747
8093
|
// Load word to the amount at 0x12 into register 0x13.
|
7748
8094
|
asm.lw(19, 18, 0).to_bytes(),
|
7749
8095
|
// Add WORD_SIZE to 0x12 to point to the asset ID in the ScriptData, store in 0x14.
|
7750
|
-
asm.addi(20, 18,
|
8096
|
+
asm.addi(20, 18, import_abi_coder9.WORD_SIZE).to_bytes(),
|
7751
8097
|
// Perform the transfer using contract ID in 0x11, amount in 0x13, and asset ID in 0x14.
|
7752
8098
|
asm.tr(17, 19, 20).to_bytes()
|
7753
8099
|
]);
|
7754
8100
|
});
|
7755
|
-
script = (0,
|
8101
|
+
script = (0, import_utils38.concat)([script, asm.ret(1).to_bytes()]);
|
7756
8102
|
return { script, scriptData };
|
7757
8103
|
}, "assembleTransferToContractScript");
|
7758
8104
|
|
@@ -7797,7 +8143,7 @@ var Account = class extends AbstractAccount {
|
|
7797
8143
|
super();
|
7798
8144
|
this._provider = provider;
|
7799
8145
|
this._connector = connector;
|
7800
|
-
this.address = new
|
8146
|
+
this.address = new import_address7.Address(address);
|
7801
8147
|
}
|
7802
8148
|
/**
|
7803
8149
|
* The provider used to interact with the network.
|
@@ -7808,7 +8154,7 @@ var Account = class extends AbstractAccount {
|
|
7808
8154
|
*/
|
7809
8155
|
get provider() {
|
7810
8156
|
if (!this._provider) {
|
7811
|
-
throw new
|
8157
|
+
throw new import_errors24.FuelError(import_errors24.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
7812
8158
|
}
|
7813
8159
|
return this._provider;
|
7814
8160
|
}
|
@@ -7835,10 +8181,24 @@ var Account = class extends AbstractAccount {
|
|
7835
8181
|
*
|
7836
8182
|
* @param quantities - Quantities of resources to be obtained.
|
7837
8183
|
* @param resourcesIdsToIgnore - IDs of resources to be excluded from the query (optional).
|
8184
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
7838
8185
|
* @returns A promise that resolves to an array of Resources.
|
7839
8186
|
*/
|
7840
|
-
async getResourcesToSpend(quantities, resourcesIdsToIgnore) {
|
7841
|
-
|
8187
|
+
async getResourcesToSpend(quantities, resourcesIdsToIgnore, { skipAutoConsolidation } = {}) {
|
8188
|
+
const getResourcesToSpend = /* @__PURE__ */ __name(() => this.provider.getResourcesToSpend(this.address, quantities, resourcesIdsToIgnore), "getResourcesToSpend");
|
8189
|
+
try {
|
8190
|
+
return await getResourcesToSpend();
|
8191
|
+
} catch (error) {
|
8192
|
+
const shouldRetry = await consolidateCoinsIfRequired({
|
8193
|
+
error,
|
8194
|
+
account: this,
|
8195
|
+
skipAutoConsolidation
|
8196
|
+
});
|
8197
|
+
if (!shouldRetry) {
|
8198
|
+
throw error;
|
8199
|
+
}
|
8200
|
+
return await getResourcesToSpend();
|
8201
|
+
}
|
7842
8202
|
}
|
7843
8203
|
/**
|
7844
8204
|
* Retrieves coins owned by the account.
|
@@ -7887,7 +8247,7 @@ var Account = class extends AbstractAccount {
|
|
7887
8247
|
* @deprecated Use provider.assembleTx instead
|
7888
8248
|
* Check the migration guide https://docs.fuel.network/docs/fuels-ts/transactions/assemble-tx-migration-guide/ for more information.
|
7889
8249
|
*/
|
7890
|
-
async fund(request, params) {
|
8250
|
+
async fund(request, params, { skipAutoConsolidation } = {}) {
|
7891
8251
|
const {
|
7892
8252
|
addedSignatures,
|
7893
8253
|
estimatedPredicates,
|
@@ -7899,9 +8259,9 @@ var Account = class extends AbstractAccount {
|
|
7899
8259
|
const chainId = await this.provider.getChainId();
|
7900
8260
|
const fee = request.maxFee;
|
7901
8261
|
const baseAssetId = await this.provider.getBaseAssetId();
|
7902
|
-
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0,
|
8262
|
+
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math24.bn)(0);
|
7903
8263
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
7904
|
-
amount: (0,
|
8264
|
+
amount: (0, import_math24.bn)(fee),
|
7905
8265
|
assetId: baseAssetId,
|
7906
8266
|
coinQuantities: requiredQuantities
|
7907
8267
|
});
|
@@ -7909,7 +8269,7 @@ var Account = class extends AbstractAccount {
|
|
7909
8269
|
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
7910
8270
|
quantitiesDict[assetId] = {
|
7911
8271
|
required: amount,
|
7912
|
-
owned: (0,
|
8272
|
+
owned: (0, import_math24.bn)(0)
|
7913
8273
|
};
|
7914
8274
|
});
|
7915
8275
|
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
@@ -7933,11 +8293,12 @@ var Account = class extends AbstractAccount {
|
|
7933
8293
|
while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
|
7934
8294
|
const resources = await this.getResourcesToSpend(
|
7935
8295
|
missingQuantities,
|
7936
|
-
cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
|
8296
|
+
cacheRequestInputsResourcesFromOwner(request.inputs, this.address),
|
8297
|
+
{ skipAutoConsolidation }
|
7937
8298
|
);
|
7938
8299
|
request.addResources(resources);
|
7939
8300
|
request.updatePredicateGasUsed(estimatedPredicates);
|
7940
|
-
const requestToReestimate2 = (0,
|
8301
|
+
const requestToReestimate2 = (0, import_ramda10.clone)(request);
|
7941
8302
|
if (addedSignatures) {
|
7942
8303
|
Array.from({ length: addedSignatures }).forEach(
|
7943
8304
|
() => requestToReestimate2.addEmptyWitness()
|
@@ -7970,15 +8331,15 @@ var Account = class extends AbstractAccount {
|
|
7970
8331
|
fundingAttempts += 1;
|
7971
8332
|
}
|
7972
8333
|
if (needsToBeFunded) {
|
7973
|
-
throw new
|
7974
|
-
|
8334
|
+
throw new import_errors24.FuelError(
|
8335
|
+
import_errors24.ErrorCode.INSUFFICIENT_FUNDS,
|
7975
8336
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
7976
8337
|
);
|
7977
8338
|
}
|
7978
8339
|
request.updateState(chainId, "funded", transactionSummary);
|
7979
8340
|
await this.provider.validateTransaction(request);
|
7980
8341
|
request.updatePredicateGasUsed(estimatedPredicates);
|
7981
|
-
const requestToReestimate = (0,
|
8342
|
+
const requestToReestimate = (0, import_ramda10.clone)(request);
|
7982
8343
|
if (addedSignatures) {
|
7983
8344
|
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
7984
8345
|
}
|
@@ -7999,16 +8360,20 @@ var Account = class extends AbstractAccount {
|
|
7999
8360
|
* @param amount - The amount of coins to transfer.
|
8000
8361
|
* @param assetId - The asset ID of the coins to transfer (optional).
|
8001
8362
|
* @param txParams - The transaction parameters (optional).
|
8363
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
8002
8364
|
* @returns A promise that resolves to the prepared transaction request.
|
8003
8365
|
*/
|
8004
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8366
|
+
async createTransfer(destination, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
|
8005
8367
|
let request = new ScriptTransactionRequest(txParams);
|
8006
8368
|
request = this.addTransfer(request, {
|
8007
8369
|
destination,
|
8008
8370
|
amount,
|
8009
8371
|
assetId: assetId || await this.provider.getBaseAssetId()
|
8010
8372
|
});
|
8011
|
-
const { gasPrice, transactionRequest } = await this.assembleTx(
|
8373
|
+
const { gasPrice, transactionRequest } = await this.assembleTx({
|
8374
|
+
transactionRequest: request,
|
8375
|
+
skipAutoConsolidation
|
8376
|
+
});
|
8012
8377
|
request = await setAndValidateGasAndFeeForAssembledTx({
|
8013
8378
|
gasPrice,
|
8014
8379
|
provider: this.provider,
|
@@ -8025,10 +8390,13 @@ var Account = class extends AbstractAccount {
|
|
8025
8390
|
* @param amount - The amount of coins to transfer.
|
8026
8391
|
* @param assetId - The asset ID of the coins to transfer (optional).
|
8027
8392
|
* @param txParams - The transaction parameters (optional).
|
8393
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
8028
8394
|
* @returns A promise that resolves to the transaction response.
|
8029
8395
|
*/
|
8030
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
8031
|
-
const request = await this.createTransfer(destination, amount, assetId, txParams
|
8396
|
+
async transfer(destination, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
|
8397
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams, {
|
8398
|
+
skipAutoConsolidation
|
8399
|
+
});
|
8032
8400
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
8033
8401
|
}
|
8034
8402
|
/**
|
@@ -8036,12 +8404,16 @@ var Account = class extends AbstractAccount {
|
|
8036
8404
|
*
|
8037
8405
|
* @param transferParams - An array of `TransferParams` objects representing the transfers to be made.
|
8038
8406
|
* @param txParams - Optional transaction parameters.
|
8407
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
8039
8408
|
* @returns A promise that resolves to a `TransactionResponse` object representing the transaction result.
|
8040
8409
|
*/
|
8041
|
-
async batchTransfer(transferParams, txParams = {}) {
|
8410
|
+
async batchTransfer(transferParams, txParams = {}, { skipAutoConsolidation } = {}) {
|
8042
8411
|
let request = new ScriptTransactionRequest(txParams);
|
8043
8412
|
request = this.addBatchTransfer(request, transferParams);
|
8044
|
-
const { gasPrice, transactionRequest } = await this.assembleTx(
|
8413
|
+
const { gasPrice, transactionRequest } = await this.assembleTx({
|
8414
|
+
transactionRequest: request,
|
8415
|
+
skipAutoConsolidation
|
8416
|
+
});
|
8045
8417
|
request = await setAndValidateGasAndFeeForAssembledTx({
|
8046
8418
|
gasPrice,
|
8047
8419
|
provider: this.provider,
|
@@ -8061,7 +8433,7 @@ var Account = class extends AbstractAccount {
|
|
8061
8433
|
addTransfer(request, transferParams) {
|
8062
8434
|
const { destination, amount, assetId } = transferParams;
|
8063
8435
|
this.validateTransferAmount(amount);
|
8064
|
-
request.addCoinOutput(new
|
8436
|
+
request.addCoinOutput(new import_address7.Address(destination), amount, assetId);
|
8065
8437
|
return request;
|
8066
8438
|
}
|
8067
8439
|
/**
|
@@ -8088,24 +8460,27 @@ var Account = class extends AbstractAccount {
|
|
8088
8460
|
* @param amount - The amount of coins to transfer.
|
8089
8461
|
* @param assetId - The asset ID of the coins to transfer (optional).
|
8090
8462
|
* @param txParams - The transaction parameters (optional).
|
8463
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
8091
8464
|
* @returns A promise that resolves to the transaction response.
|
8092
8465
|
*/
|
8093
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
8094
|
-
return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams
|
8466
|
+
async transferToContract(contractId, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
|
8467
|
+
return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams, {
|
8468
|
+
skipAutoConsolidation
|
8469
|
+
});
|
8095
8470
|
}
|
8096
|
-
async batchTransferToContracts(contractTransferParams, txParams = {}) {
|
8471
|
+
async batchTransferToContracts(contractTransferParams, txParams = {}, { skipAutoConsolidation } = {}) {
|
8097
8472
|
let request = new ScriptTransactionRequest({
|
8098
8473
|
...txParams
|
8099
8474
|
});
|
8100
8475
|
const quantities = [];
|
8101
8476
|
const defaultAssetId = await this.provider.getBaseAssetId();
|
8102
8477
|
const transferParams = contractTransferParams.map((transferParam) => {
|
8103
|
-
const amount = (0,
|
8104
|
-
const contractAddress = new
|
8105
|
-
const assetId = transferParam.assetId ? (0,
|
8478
|
+
const amount = (0, import_math24.bn)(transferParam.amount);
|
8479
|
+
const contractAddress = new import_address7.Address(transferParam.contractId);
|
8480
|
+
const assetId = transferParam.assetId ? (0, import_utils39.hexlify)(transferParam.assetId) : defaultAssetId;
|
8106
8481
|
if (amount.lte(0)) {
|
8107
|
-
throw new
|
8108
|
-
|
8482
|
+
throw new import_errors24.FuelError(
|
8483
|
+
import_errors24.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
8109
8484
|
"Transfer amount must be a positive number."
|
8110
8485
|
);
|
8111
8486
|
}
|
@@ -8120,7 +8495,11 @@ var Account = class extends AbstractAccount {
|
|
8120
8495
|
const { script, scriptData } = await assembleTransferToContractScript(transferParams);
|
8121
8496
|
request.script = script;
|
8122
8497
|
request.scriptData = scriptData;
|
8123
|
-
const { gasPrice, transactionRequest } = await this.assembleTx(
|
8498
|
+
const { gasPrice, transactionRequest } = await this.assembleTx({
|
8499
|
+
transactionRequest: request,
|
8500
|
+
quantities,
|
8501
|
+
skipAutoConsolidation
|
8502
|
+
});
|
8124
8503
|
request = await setAndValidateGasAndFeeForAssembledTx({
|
8125
8504
|
gasPrice,
|
8126
8505
|
provider: this.provider,
|
@@ -8136,26 +8515,31 @@ var Account = class extends AbstractAccount {
|
|
8136
8515
|
* @param recipient - Address of the recipient on the base chain.
|
8137
8516
|
* @param amount - Amount of base asset.
|
8138
8517
|
* @param txParams - The transaction parameters (optional).
|
8518
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
8139
8519
|
* @returns A promise that resolves to the transaction response.
|
8140
8520
|
*/
|
8141
|
-
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
8142
|
-
const recipientAddress = new
|
8143
|
-
const recipientDataArray = (0,
|
8521
|
+
async withdrawToBaseLayer(recipient, amount, txParams = {}, { skipAutoConsolidation } = {}) {
|
8522
|
+
const recipientAddress = new import_address7.Address(recipient);
|
8523
|
+
const recipientDataArray = (0, import_utils39.arrayify)(
|
8144
8524
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
8145
8525
|
);
|
8146
|
-
const amountDataArray = (0,
|
8147
|
-
"0x".concat((0,
|
8526
|
+
const amountDataArray = (0, import_utils39.arrayify)(
|
8527
|
+
"0x".concat((0, import_math24.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
8148
8528
|
);
|
8149
8529
|
const script = new Uint8Array([
|
8150
|
-
...(0,
|
8530
|
+
...(0, import_utils39.arrayify)(withdrawScript.bytes),
|
8151
8531
|
...recipientDataArray,
|
8152
8532
|
...amountDataArray
|
8153
8533
|
]);
|
8154
8534
|
const params = { script, ...txParams };
|
8155
8535
|
const baseAssetId = await this.provider.getBaseAssetId();
|
8156
8536
|
let request = new ScriptTransactionRequest(params);
|
8157
|
-
const quantities = [{ amount: (0,
|
8158
|
-
const { gasPrice, transactionRequest } = await this.assembleTx(
|
8537
|
+
const quantities = [{ amount: (0, import_math24.bn)(amount), assetId: baseAssetId }];
|
8538
|
+
const { gasPrice, transactionRequest } = await this.assembleTx({
|
8539
|
+
transactionRequest: request,
|
8540
|
+
quantities,
|
8541
|
+
skipAutoConsolidation
|
8542
|
+
});
|
8159
8543
|
request = await setAndValidateGasAndFeeForAssembledTx({
|
8160
8544
|
gasPrice,
|
8161
8545
|
provider: this.provider,
|
@@ -8165,6 +8549,25 @@ var Account = class extends AbstractAccount {
|
|
8165
8549
|
});
|
8166
8550
|
return this.sendTransaction(request);
|
8167
8551
|
}
|
8552
|
+
/**
|
8553
|
+
* Start the consolidation process
|
8554
|
+
*
|
8555
|
+
* @param owner - The B256 address of the owner.
|
8556
|
+
* @param assetId - The asset ID that requires consolidation.
|
8557
|
+
*/
|
8558
|
+
async startConsolidation(opts) {
|
8559
|
+
if (this._connector) {
|
8560
|
+
await this._connector.startConsolidation(opts);
|
8561
|
+
return false;
|
8562
|
+
}
|
8563
|
+
const { owner, assetId } = opts;
|
8564
|
+
if (owner !== this.address.toB256()) {
|
8565
|
+
return false;
|
8566
|
+
}
|
8567
|
+
const { submitAll } = await consolidateCoins({ account: this, assetId });
|
8568
|
+
await submitAll();
|
8569
|
+
return true;
|
8570
|
+
}
|
8168
8571
|
/**
|
8169
8572
|
* Consolidates base asset UTXOs into fewer, larger ones.
|
8170
8573
|
*
|
@@ -8184,6 +8587,7 @@ var Account = class extends AbstractAccount {
|
|
8184
8587
|
const isBaseAsset = baseAssetId === assetId;
|
8185
8588
|
let submitAll;
|
8186
8589
|
const consolidationParams = {
|
8590
|
+
assetId,
|
8187
8591
|
coins,
|
8188
8592
|
mode: params.mode,
|
8189
8593
|
outputNum: params.outputNum
|
@@ -8191,10 +8595,7 @@ var Account = class extends AbstractAccount {
|
|
8191
8595
|
if (isBaseAsset) {
|
8192
8596
|
({ submitAll } = await this.assembleBaseAssetConsolidationTxs(consolidationParams));
|
8193
8597
|
} else {
|
8194
|
-
|
8195
|
-
import_errors23.ErrorCode.UNSUPPORTED_FEATURE,
|
8196
|
-
"Consolidation for non-base assets is not supported yet."
|
8197
|
-
);
|
8598
|
+
({ submitAll } = await this.assembleNonBaseAssetConsolidationTxs(consolidationParams));
|
8198
8599
|
}
|
8199
8600
|
return submitAll();
|
8200
8601
|
}
|
@@ -8215,7 +8616,7 @@ var Account = class extends AbstractAccount {
|
|
8215
8616
|
this.validateConsolidationTxsCoins(coins, baseAssetId);
|
8216
8617
|
const chainInfo = await this.provider.getChain();
|
8217
8618
|
const maxInputsNumber = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
|
8218
|
-
let totalFeeCost = (0,
|
8619
|
+
let totalFeeCost = (0, import_math24.bn)(0);
|
8219
8620
|
const txs = [];
|
8220
8621
|
const coinsBatches = splitCoinsIntoBatches(coins, maxInputsNumber);
|
8221
8622
|
const gasPrice = await this.provider.estimateGasPrice(10);
|
@@ -8239,15 +8640,79 @@ var Account = class extends AbstractAccount {
|
|
8239
8640
|
});
|
8240
8641
|
request.maxFee = fee;
|
8241
8642
|
if (consolidateMoreThanOneCoin) {
|
8242
|
-
const total = request.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), (0,
|
8643
|
+
const total = request.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), (0, import_math24.bn)(0));
|
8644
|
+
const amountPerNewUtxo = total.div(outputNum + 1);
|
8645
|
+
request.outputs.forEach((output) => {
|
8646
|
+
if (output.type === import_transactions29.OutputType.Coin) {
|
8647
|
+
output.amount = amountPerNewUtxo;
|
8648
|
+
}
|
8649
|
+
});
|
8650
|
+
}
|
8651
|
+
totalFeeCost = totalFeeCost.add(fee);
|
8652
|
+
txs.push(request);
|
8653
|
+
});
|
8654
|
+
const submitAll = this.prepareSubmitAll({ txs, mode });
|
8655
|
+
return { txs, totalFeeCost, submitAll };
|
8656
|
+
}
|
8657
|
+
async assembleNonBaseAssetConsolidationTxs(params) {
|
8658
|
+
const { assetId, coins, mode = "parallel", outputNum = 1 } = params;
|
8659
|
+
this.validateConsolidationTxsCoins(coins, assetId);
|
8660
|
+
const chainInfo = await this.provider.getChain();
|
8661
|
+
const maxInputsNumber = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
|
8662
|
+
const baseAssetId = chainInfo.consensusParameters.baseAssetId;
|
8663
|
+
const { coins: baseAssetCoins } = await this.provider.getCoins(this.address, baseAssetId);
|
8664
|
+
let totalFeeCost = (0, import_math24.bn)(0);
|
8665
|
+
const txs = [];
|
8666
|
+
const gasPrice = await this.provider.estimateGasPrice(10);
|
8667
|
+
const consolidateMoreThanOneCoin = outputNum > 1;
|
8668
|
+
const assetCoinBatches = splitCoinsIntoBatches(coins, maxInputsNumber);
|
8669
|
+
assetCoinBatches.filter((batch) => batch.length > 1).forEach((coinBatch) => {
|
8670
|
+
const request = new ScriptTransactionRequest({
|
8671
|
+
script: "0x"
|
8672
|
+
});
|
8673
|
+
request.addResources(coinBatch);
|
8674
|
+
if (consolidateMoreThanOneCoin) {
|
8675
|
+
Array.from({ length: outputNum - 1 }).forEach(() => {
|
8676
|
+
request.addCoinOutput(this.address, 0, assetId);
|
8677
|
+
});
|
8678
|
+
}
|
8679
|
+
const minGas = request.calculateMinGas(chainInfo);
|
8680
|
+
const fee = calculateGasFee({
|
8681
|
+
gasPrice,
|
8682
|
+
gas: minGas,
|
8683
|
+
priceFactor: chainInfo.consensusParameters.feeParameters.gasPriceFactor,
|
8684
|
+
tip: request.tip
|
8685
|
+
});
|
8686
|
+
request.maxFee = fee;
|
8687
|
+
if (consolidateMoreThanOneCoin) {
|
8688
|
+
const total = request.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), (0, import_math24.bn)(0));
|
8243
8689
|
const amountPerNewUtxo = total.div(outputNum + 1);
|
8244
8690
|
request.outputs.forEach((output) => {
|
8245
|
-
if (output.type ===
|
8691
|
+
if (output.type === import_transactions29.OutputType.Coin) {
|
8246
8692
|
output.amount = amountPerNewUtxo;
|
8247
8693
|
}
|
8248
8694
|
});
|
8249
8695
|
}
|
8250
8696
|
totalFeeCost = totalFeeCost.add(fee);
|
8697
|
+
const baseAssetResources = [];
|
8698
|
+
let fundingFeeTotal = (0, import_math24.bn)(0);
|
8699
|
+
while (fundingFeeTotal.lt(fee)) {
|
8700
|
+
const baseAssetCoin = baseAssetCoins.pop();
|
8701
|
+
if (!baseAssetCoin) {
|
8702
|
+
break;
|
8703
|
+
}
|
8704
|
+
baseAssetResources.push(baseAssetCoin);
|
8705
|
+
fundingFeeTotal = fundingFeeTotal.add(baseAssetCoin.amount);
|
8706
|
+
}
|
8707
|
+
const { inputs } = request;
|
8708
|
+
request.inputs = inputs.slice(0, maxInputsNumber - baseAssetResources.length);
|
8709
|
+
const removedCoins = coinBatch.slice(maxInputsNumber - baseAssetResources.length);
|
8710
|
+
request.addResources(baseAssetResources);
|
8711
|
+
const lastCoinBatch = assetCoinBatches[assetCoinBatches.length - 1];
|
8712
|
+
lastCoinBatch.push(...removedCoins);
|
8713
|
+
if (lastCoinBatch.length > maxInputsNumber) {
|
8714
|
+
assetCoinBatches.push(lastCoinBatch.slice(maxInputsNumber));
|
8715
|
+
}
|
8251
8716
|
txs.push(request);
|
8252
8717
|
});
|
8253
8718
|
const submitAll = this.prepareSubmitAll({ txs, mode });
|
@@ -8307,13 +8772,13 @@ var Account = class extends AbstractAccount {
|
|
8307
8772
|
* Check the migration guide https://docs.fuel.network/docs/fuels-ts/transactions/assemble-tx-migration-guide/ for more information.
|
8308
8773
|
*/
|
8309
8774
|
async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [], gasPrice } = {}) {
|
8310
|
-
const txRequestClone = (0,
|
8775
|
+
const txRequestClone = (0, import_ramda10.clone)(transactionRequestify(transactionRequestLike));
|
8311
8776
|
const baseAssetId = await this.provider.getBaseAssetId();
|
8312
8777
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
8313
8778
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
8314
|
-
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0,
|
8779
|
+
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math24.bn)("100000000000000000") }];
|
8315
8780
|
const findAssetInput = /* @__PURE__ */ __name((assetId) => txRequestClone.inputs.find((input) => {
|
8316
|
-
if (input.type ===
|
8781
|
+
if (input.type === import_transactions29.InputType.Coin) {
|
8317
8782
|
return input.assetId === assetId;
|
8318
8783
|
}
|
8319
8784
|
if (isRequestInputMessageWithoutData(input)) {
|
@@ -8359,7 +8824,7 @@ var Account = class extends AbstractAccount {
|
|
8359
8824
|
*/
|
8360
8825
|
async signMessage(message) {
|
8361
8826
|
if (!this._connector) {
|
8362
|
-
throw new
|
8827
|
+
throw new import_errors24.FuelError(import_errors24.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
8363
8828
|
}
|
8364
8829
|
return this._connector.signMessage(this.address.toString(), message);
|
8365
8830
|
}
|
@@ -8371,8 +8836,8 @@ var Account = class extends AbstractAccount {
|
|
8371
8836
|
*/
|
8372
8837
|
async signTransaction(transactionRequestLike, connectorOptions = {}) {
|
8373
8838
|
if (!this._connector) {
|
8374
|
-
throw new
|
8375
|
-
|
8839
|
+
throw new import_errors24.FuelError(
|
8840
|
+
import_errors24.ErrorCode.MISSING_CONNECTOR,
|
8376
8841
|
"A connector is required to sign transactions."
|
8377
8842
|
);
|
8378
8843
|
}
|
@@ -8437,17 +8902,17 @@ var Account = class extends AbstractAccount {
|
|
8437
8902
|
*/
|
8438
8903
|
generateFakeResources(coins) {
|
8439
8904
|
return coins.map((coin) => ({
|
8440
|
-
id: (0,
|
8905
|
+
id: (0, import_utils39.hexlify)((0, import_crypto5.randomBytes)(import_abi_coder10.UTXO_ID_LEN)),
|
8441
8906
|
owner: this.address,
|
8442
|
-
blockCreated: (0,
|
8443
|
-
txCreatedIdx: (0,
|
8907
|
+
blockCreated: (0, import_math24.bn)(1),
|
8908
|
+
txCreatedIdx: (0, import_math24.bn)(1),
|
8444
8909
|
...coin
|
8445
8910
|
}));
|
8446
8911
|
}
|
8447
8912
|
/** @hidden */
|
8448
8913
|
async prepareTransactionForSend(request) {
|
8449
8914
|
const { transactionId } = request.flag;
|
8450
|
-
if (!(0,
|
8915
|
+
if (!(0, import_utils39.isDefined)(transactionId)) {
|
8451
8916
|
return request;
|
8452
8917
|
}
|
8453
8918
|
const chainId = await this.provider.getChainId();
|
@@ -8460,80 +8925,57 @@ var Account = class extends AbstractAccount {
|
|
8460
8925
|
/** @hidden */
|
8461
8926
|
async prepareTransactionSummary(request) {
|
8462
8927
|
const chainId = await this.provider.getChainId();
|
8463
|
-
return (0,
|
8928
|
+
return (0, import_utils39.isDefined)(request.flag.summary) ? {
|
8464
8929
|
...request.flag.summary,
|
8465
8930
|
id: request.getTransactionId(chainId),
|
8466
|
-
transactionBytes: (0,
|
8931
|
+
transactionBytes: (0, import_utils39.hexlify)(request.toTransactionBytes())
|
8467
8932
|
} : void 0;
|
8468
8933
|
}
|
8469
8934
|
/** @hidden * */
|
8470
|
-
async assembleTx(
|
8471
|
-
const
|
8472
|
-
transactionRequest.
|
8473
|
-
transactionRequest.
|
8474
|
-
|
8475
|
-
|
8476
|
-
|
8477
|
-
|
8478
|
-
|
8479
|
-
|
8935
|
+
async assembleTx(opts) {
|
8936
|
+
const { transactionRequest, quantities = [], skipAutoConsolidation } = opts;
|
8937
|
+
const outputQuantities = transactionRequest.outputs.filter((o) => o.type === import_transactions29.OutputType.Coin).map(({ amount, assetId }) => ({ assetId: String(assetId), amount: (0, import_math24.bn)(amount) }));
|
8938
|
+
transactionRequest.gasLimit = (0, import_math24.bn)(0);
|
8939
|
+
transactionRequest.maxFee = (0, import_math24.bn)(0);
|
8940
|
+
const assembleTx = /* @__PURE__ */ __name(async () => {
|
8941
|
+
const { assembledRequest, gasPrice } = await this.provider.assembleTx({
|
8942
|
+
request: transactionRequest,
|
8943
|
+
accountCoinQuantities: mergeQuantities(outputQuantities, quantities),
|
8944
|
+
feePayerAccount: this
|
8945
|
+
});
|
8946
|
+
return { transactionRequest: assembledRequest, gasPrice };
|
8947
|
+
}, "assembleTx");
|
8948
|
+
try {
|
8949
|
+
return await assembleTx();
|
8950
|
+
} catch (error) {
|
8951
|
+
const shouldRetry = await consolidateCoinsIfRequired({
|
8952
|
+
error,
|
8953
|
+
account: this,
|
8954
|
+
skipAutoConsolidation
|
8955
|
+
});
|
8956
|
+
if (!shouldRetry) {
|
8957
|
+
throw error;
|
8958
|
+
}
|
8959
|
+
return await assembleTx();
|
8960
|
+
}
|
8480
8961
|
}
|
8481
8962
|
/** @hidden * */
|
8482
8963
|
validateTransferAmount(amount) {
|
8483
|
-
if ((0,
|
8484
|
-
throw new
|
8485
|
-
|
8964
|
+
if ((0, import_math24.bn)(amount).lte(0)) {
|
8965
|
+
throw new import_errors24.FuelError(
|
8966
|
+
import_errors24.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
8486
8967
|
"Transfer amount must be a positive number."
|
8487
8968
|
);
|
8488
8969
|
}
|
8489
8970
|
}
|
8490
8971
|
/** @hidden * */
|
8491
|
-
async estimateAndFundTransaction(transactionRequest, txParams, costParams) {
|
8492
|
-
let request = transactionRequest;
|
8493
|
-
const txCost = await this.getTransactionCost(request, costParams);
|
8494
|
-
request = this.validateGasLimitAndMaxFee({
|
8495
|
-
transactionRequest: request,
|
8496
|
-
gasUsed: txCost.gasUsed,
|
8497
|
-
maxFee: txCost.maxFee,
|
8498
|
-
txParams
|
8499
|
-
});
|
8500
|
-
request = await this.fund(request, txCost);
|
8501
|
-
return request;
|
8502
|
-
}
|
8503
|
-
/** @hidden * */
|
8504
|
-
validateGasLimitAndMaxFee({
|
8505
|
-
gasUsed,
|
8506
|
-
maxFee,
|
8507
|
-
transactionRequest,
|
8508
|
-
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
|
8509
|
-
}) {
|
8510
|
-
const request = transactionRequestify(transactionRequest);
|
8511
|
-
if (!(0, import_utils38.isDefined)(setGasLimit)) {
|
8512
|
-
request.gasLimit = gasUsed;
|
8513
|
-
} else if (gasUsed.gt(setGasLimit)) {
|
8514
|
-
throw new import_errors23.FuelError(
|
8515
|
-
import_errors23.ErrorCode.GAS_LIMIT_TOO_LOW,
|
8516
|
-
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
8517
|
-
);
|
8518
|
-
}
|
8519
|
-
if (!(0, import_utils38.isDefined)(setMaxFee)) {
|
8520
|
-
request.maxFee = maxFee;
|
8521
|
-
} else if (maxFee.gt(setMaxFee)) {
|
8522
|
-
throw new import_errors23.FuelError(
|
8523
|
-
import_errors23.ErrorCode.MAX_FEE_TOO_LOW,
|
8524
|
-
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
8525
|
-
);
|
8526
|
-
}
|
8527
|
-
return request;
|
8528
|
-
}
|
8529
|
-
/** @hidden * */
|
8530
8972
|
validateConsolidationTxsCoins(coins, assetId) {
|
8531
8973
|
if (coins.length <= 1) {
|
8532
|
-
throw new
|
8974
|
+
throw new import_errors24.FuelError(import_errors24.ErrorCode.NO_COINS_TO_CONSOLIDATE, "No coins to consolidate.");
|
8533
8975
|
}
|
8534
8976
|
if (!coins.every((c) => c.assetId === assetId)) {
|
8535
|
-
throw new
|
8536
|
-
|
8977
|
+
throw new import_errors24.FuelError(
|
8978
|
+
import_errors24.ErrorCode.COINS_ASSET_ID_MISMATCH,
|
8537
8979
|
"All coins to consolidate must be from the same asset id."
|
8538
8980
|
);
|
8539
8981
|
}
|
@@ -8558,10 +9000,10 @@ var Account = class extends AbstractAccount {
|
|
8558
9000
|
};
|
8559
9001
|
|
8560
9002
|
// src/wallet/keystore-wallet.ts
|
8561
|
-
var
|
9003
|
+
var import_address8 = require("@fuel-ts/address");
|
8562
9004
|
var import_crypto6 = require("@fuel-ts/crypto");
|
8563
|
-
var
|
8564
|
-
var
|
9005
|
+
var import_errors25 = require("@fuel-ts/errors");
|
9006
|
+
var import_utils40 = require("@fuel-ts/utils");
|
8565
9007
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
8566
9008
|
var DEFAULT_KDF_PARAMS_R = 8;
|
8567
9009
|
var DEFAULT_KDF_PARAMS_P = 1;
|
@@ -8575,7 +9017,7 @@ var removeHexPrefix = /* @__PURE__ */ __name((hexString) => {
|
|
8575
9017
|
}, "removeHexPrefix");
|
8576
9018
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
8577
9019
|
const privateKeyBuffer = (0, import_crypto6.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
8578
|
-
const ownerAddress = new
|
9020
|
+
const ownerAddress = new import_address8.Address(address);
|
8579
9021
|
const salt = (0, import_crypto6.randomBytes)(DEFAULT_KEY_SIZE);
|
8580
9022
|
const key = (0, import_crypto6.scrypt)({
|
8581
9023
|
password: (0, import_crypto6.bufferFromString)(password),
|
@@ -8638,13 +9080,13 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
8638
9080
|
const macHashUint8Array = (0, import_crypto6.keccak256)(data);
|
8639
9081
|
const macHash = (0, import_crypto6.stringFromBuffer)(macHashUint8Array, "hex");
|
8640
9082
|
if (mac !== macHash) {
|
8641
|
-
throw new
|
8642
|
-
|
9083
|
+
throw new import_errors25.FuelError(
|
9084
|
+
import_errors25.ErrorCode.INVALID_PASSWORD,
|
8643
9085
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
8644
9086
|
);
|
8645
9087
|
}
|
8646
9088
|
const buffer = await (0, import_crypto6.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
8647
|
-
const privateKey = (0,
|
9089
|
+
const privateKey = (0, import_utils40.hexlify)(buffer);
|
8648
9090
|
return privateKey;
|
8649
9091
|
}
|
8650
9092
|
__name(decryptKeystoreWallet, "decryptKeystoreWallet");
|
@@ -8697,7 +9139,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
8697
9139
|
*/
|
8698
9140
|
async signMessage(message) {
|
8699
9141
|
const signedMessage = await this.signer().sign((0, import_hasher4.hashMessage)(message));
|
8700
|
-
return (0,
|
9142
|
+
return (0, import_utils41.hexlify)(signedMessage);
|
8701
9143
|
}
|
8702
9144
|
/**
|
8703
9145
|
* Signs a transaction with the wallet's private key.
|
@@ -8710,7 +9152,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
8710
9152
|
const chainId = await this.provider.getChainId();
|
8711
9153
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
8712
9154
|
const signature = await this.signer().sign(hashedTransaction);
|
8713
|
-
return (0,
|
9155
|
+
return (0, import_utils41.hexlify)(signature);
|
8714
9156
|
}
|
8715
9157
|
/**
|
8716
9158
|
* Populates a transaction with the witnesses signature.
|
@@ -8778,16 +9220,16 @@ var BaseWalletUnlocked = class extends Account {
|
|
8778
9220
|
|
8779
9221
|
// src/hdwallet/hdwallet.ts
|
8780
9222
|
var import_crypto8 = require("@fuel-ts/crypto");
|
8781
|
-
var
|
9223
|
+
var import_errors28 = require("@fuel-ts/errors");
|
8782
9224
|
var import_hasher7 = require("@fuel-ts/hasher");
|
8783
|
-
var
|
8784
|
-
var
|
9225
|
+
var import_math25 = require("@fuel-ts/math");
|
9226
|
+
var import_utils45 = require("@fuel-ts/utils");
|
8785
9227
|
|
8786
9228
|
// src/mnemonic/mnemonic.ts
|
8787
9229
|
var import_crypto7 = require("@fuel-ts/crypto");
|
8788
|
-
var
|
9230
|
+
var import_errors27 = require("@fuel-ts/errors");
|
8789
9231
|
var import_hasher6 = require("@fuel-ts/hasher");
|
8790
|
-
var
|
9232
|
+
var import_utils43 = require("@fuel-ts/utils");
|
8791
9233
|
|
8792
9234
|
// src/wordlists/words/english.ts
|
8793
9235
|
var english = [
|
@@ -10842,9 +11284,9 @@ var english = [
|
|
10842
11284
|
];
|
10843
11285
|
|
10844
11286
|
// src/mnemonic/utils.ts
|
10845
|
-
var
|
11287
|
+
var import_errors26 = require("@fuel-ts/errors");
|
10846
11288
|
var import_hasher5 = require("@fuel-ts/hasher");
|
10847
|
-
var
|
11289
|
+
var import_utils42 = require("@fuel-ts/utils");
|
10848
11290
|
function getLowerMask(bits) {
|
10849
11291
|
return (1 << bits) - 1;
|
10850
11292
|
}
|
@@ -10883,7 +11325,7 @@ function entropyToMnemonicIndices(entropy) {
|
|
10883
11325
|
}
|
10884
11326
|
}
|
10885
11327
|
const checksumBits = entropy.length / 4;
|
10886
|
-
const checksum = (0,
|
11328
|
+
const checksum = (0, import_utils42.arrayify)((0, import_hasher5.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
10887
11329
|
indices[indices.length - 1] <<= checksumBits;
|
10888
11330
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
10889
11331
|
return indices;
|
@@ -10891,13 +11333,13 @@ function entropyToMnemonicIndices(entropy) {
|
|
10891
11333
|
__name(entropyToMnemonicIndices, "entropyToMnemonicIndices");
|
10892
11334
|
function mnemonicWordsToEntropy(words, wordlist) {
|
10893
11335
|
const size = Math.ceil(11 * words.length / 8);
|
10894
|
-
const entropy = (0,
|
11336
|
+
const entropy = (0, import_utils42.arrayify)(new Uint8Array(size));
|
10895
11337
|
let offset = 0;
|
10896
11338
|
for (let i = 0; i < words.length; i += 1) {
|
10897
11339
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
10898
11340
|
if (index === -1) {
|
10899
|
-
throw new
|
10900
|
-
|
11341
|
+
throw new import_errors26.FuelError(
|
11342
|
+
import_errors26.ErrorCode.INVALID_MNEMONIC,
|
10901
11343
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
10902
11344
|
);
|
10903
11345
|
}
|
@@ -10911,10 +11353,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
10911
11353
|
const entropyBits = 32 * words.length / 3;
|
10912
11354
|
const checksumBits = words.length / 3;
|
10913
11355
|
const checksumMask = getUpperMask(checksumBits);
|
10914
|
-
const checksum = (0,
|
11356
|
+
const checksum = (0, import_utils42.arrayify)((0, import_hasher5.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
10915
11357
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
10916
|
-
throw new
|
10917
|
-
|
11358
|
+
throw new import_errors26.FuelError(
|
11359
|
+
import_errors26.ErrorCode.INVALID_CHECKSUM,
|
10918
11360
|
"Checksum validation failed for the provided mnemonic."
|
10919
11361
|
);
|
10920
11362
|
}
|
@@ -10923,14 +11365,14 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
10923
11365
|
__name(mnemonicWordsToEntropy, "mnemonicWordsToEntropy");
|
10924
11366
|
|
10925
11367
|
// src/mnemonic/mnemonic.ts
|
10926
|
-
var MasterSecret = (0,
|
11368
|
+
var MasterSecret = (0, import_utils43.toUtf8Bytes)("Bitcoin seed");
|
10927
11369
|
var MainnetPRV = "0x0488ade4";
|
10928
11370
|
var TestnetPRV = "0x04358394";
|
10929
11371
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
10930
11372
|
function assertWordList(wordlist) {
|
10931
11373
|
if (wordlist.length !== 2048) {
|
10932
|
-
throw new
|
10933
|
-
|
11374
|
+
throw new import_errors27.FuelError(
|
11375
|
+
import_errors27.ErrorCode.INVALID_WORD_LIST,
|
10934
11376
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
10935
11377
|
);
|
10936
11378
|
}
|
@@ -10938,8 +11380,8 @@ function assertWordList(wordlist) {
|
|
10938
11380
|
__name(assertWordList, "assertWordList");
|
10939
11381
|
function assertEntropy(entropy) {
|
10940
11382
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
10941
|
-
throw new
|
10942
|
-
|
11383
|
+
throw new import_errors27.FuelError(
|
11384
|
+
import_errors27.ErrorCode.INVALID_ENTROPY,
|
10943
11385
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
10944
11386
|
);
|
10945
11387
|
}
|
@@ -10950,7 +11392,7 @@ function assertMnemonic(words) {
|
|
10950
11392
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
10951
11393
|
", "
|
10952
11394
|
)}] words, but got ${words.length}.`;
|
10953
|
-
throw new
|
11395
|
+
throw new import_errors27.FuelError(import_errors27.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
10954
11396
|
}
|
10955
11397
|
}
|
10956
11398
|
__name(assertMnemonic, "assertMnemonic");
|
@@ -10993,7 +11435,7 @@ var Mnemonic = class _Mnemonic {
|
|
10993
11435
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
10994
11436
|
const words = getWords(phrase);
|
10995
11437
|
assertMnemonic(words);
|
10996
|
-
return (0,
|
11438
|
+
return (0, import_utils43.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
10997
11439
|
}
|
10998
11440
|
/**
|
10999
11441
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -11001,7 +11443,7 @@ var Mnemonic = class _Mnemonic {
|
|
11001
11443
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
11002
11444
|
*/
|
11003
11445
|
static entropyToMnemonic(entropy, wordlist = english) {
|
11004
|
-
const entropyBytes = (0,
|
11446
|
+
const entropyBytes = (0, import_utils43.arrayify)(entropy);
|
11005
11447
|
assertWordList(wordlist);
|
11006
11448
|
assertEntropy(entropyBytes);
|
11007
11449
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -11013,8 +11455,8 @@ var Mnemonic = class _Mnemonic {
|
|
11013
11455
|
*/
|
11014
11456
|
static mnemonicToSeed(phrase, passphrase = "") {
|
11015
11457
|
assertMnemonic(getWords(phrase));
|
11016
|
-
const phraseBytes = (0,
|
11017
|
-
const salt = (0,
|
11458
|
+
const phraseBytes = (0, import_utils43.toUtf8Bytes)(getPhrase(phrase));
|
11459
|
+
const salt = (0, import_utils43.toUtf8Bytes)(`mnemonic${passphrase}`);
|
11018
11460
|
return (0, import_crypto7.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
11019
11461
|
}
|
11020
11462
|
/**
|
@@ -11070,14 +11512,14 @@ var Mnemonic = class _Mnemonic {
|
|
11070
11512
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
11071
11513
|
*/
|
11072
11514
|
static masterKeysFromSeed(seed) {
|
11073
|
-
const seedArray = (0,
|
11515
|
+
const seedArray = (0, import_utils43.arrayify)(seed);
|
11074
11516
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
11075
|
-
throw new
|
11076
|
-
|
11517
|
+
throw new import_errors27.FuelError(
|
11518
|
+
import_errors27.ErrorCode.INVALID_SEED,
|
11077
11519
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
11078
11520
|
);
|
11079
11521
|
}
|
11080
|
-
return (0,
|
11522
|
+
return (0, import_utils43.arrayify)((0, import_crypto7.computeHmac)("sha512", MasterSecret, seedArray));
|
11081
11523
|
}
|
11082
11524
|
/**
|
11083
11525
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -11088,22 +11530,22 @@ var Mnemonic = class _Mnemonic {
|
|
11088
11530
|
*/
|
11089
11531
|
static seedToExtendedKey(seed, testnet = false) {
|
11090
11532
|
const masterKey = _Mnemonic.masterKeysFromSeed(seed);
|
11091
|
-
const prefix = (0,
|
11533
|
+
const prefix = (0, import_utils43.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
11092
11534
|
const depth = "0x00";
|
11093
11535
|
const fingerprint = "0x00000000";
|
11094
11536
|
const index = "0x00000000";
|
11095
11537
|
const chainCode = masterKey.slice(32);
|
11096
11538
|
const privateKey = masterKey.slice(0, 32);
|
11097
|
-
const extendedKey = (0,
|
11539
|
+
const extendedKey = (0, import_utils43.concat)([
|
11098
11540
|
prefix,
|
11099
11541
|
depth,
|
11100
11542
|
fingerprint,
|
11101
11543
|
index,
|
11102
11544
|
chainCode,
|
11103
|
-
(0,
|
11545
|
+
(0, import_utils43.concat)(["0x00", privateKey])
|
11104
11546
|
]);
|
11105
|
-
const checksum = (0,
|
11106
|
-
return (0,
|
11547
|
+
const checksum = (0, import_utils43.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(extendedKey)), 0, 4);
|
11548
|
+
return (0, import_utils43.encodeBase58)((0, import_utils43.concat)([extendedKey, checksum]));
|
11107
11549
|
}
|
11108
11550
|
/**
|
11109
11551
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -11118,7 +11560,7 @@ var Mnemonic = class _Mnemonic {
|
|
11118
11560
|
* @returns A randomly generated mnemonic
|
11119
11561
|
*/
|
11120
11562
|
static generate(size = 32, extraEntropy = "") {
|
11121
|
-
const entropy = extraEntropy ? (0, import_hasher6.sha256)((0,
|
11563
|
+
const entropy = extraEntropy ? (0, import_hasher6.sha256)((0, import_utils43.concat)([(0, import_crypto7.randomBytes)(size), (0, import_utils43.arrayify)(extraEntropy)])) : (0, import_crypto7.randomBytes)(size);
|
11122
11564
|
return _Mnemonic.entropyToMnemonic(entropy);
|
11123
11565
|
}
|
11124
11566
|
};
|
@@ -11126,12 +11568,12 @@ var mnemonic_default = Mnemonic;
|
|
11126
11568
|
|
11127
11569
|
// src/hdwallet/hdwallet.ts
|
11128
11570
|
var HARDENED_INDEX = 2147483648;
|
11129
|
-
var MainnetPRV2 = (0,
|
11130
|
-
var MainnetPUB = (0,
|
11131
|
-
var TestnetPRV2 = (0,
|
11132
|
-
var TestnetPUB = (0,
|
11571
|
+
var MainnetPRV2 = (0, import_utils45.hexlify)("0x0488ade4");
|
11572
|
+
var MainnetPUB = (0, import_utils45.hexlify)("0x0488b21e");
|
11573
|
+
var TestnetPRV2 = (0, import_utils45.hexlify)("0x04358394");
|
11574
|
+
var TestnetPUB = (0, import_utils45.hexlify)("0x043587cf");
|
11133
11575
|
function base58check(data) {
|
11134
|
-
return (0,
|
11576
|
+
return (0, import_utils45.encodeBase58)((0, import_utils45.concat)([data, (0, import_utils45.dataSlice)((0, import_hasher7.sha256)((0, import_hasher7.sha256)(data)), 0, 4)]));
|
11135
11577
|
}
|
11136
11578
|
__name(base58check, "base58check");
|
11137
11579
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
@@ -11142,19 +11584,19 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
11142
11584
|
}
|
11143
11585
|
__name(getExtendedKeyPrefix, "getExtendedKeyPrefix");
|
11144
11586
|
function isPublicExtendedKey(extendedKey) {
|
11145
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
11587
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils45.hexlify)(extendedKey.slice(0, 4)));
|
11146
11588
|
}
|
11147
11589
|
__name(isPublicExtendedKey, "isPublicExtendedKey");
|
11148
11590
|
function isValidExtendedKey(extendedKey) {
|
11149
11591
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
11150
|
-
(0,
|
11592
|
+
(0, import_utils45.hexlify)(extendedKey.slice(0, 4))
|
11151
11593
|
);
|
11152
11594
|
}
|
11153
11595
|
__name(isValidExtendedKey, "isValidExtendedKey");
|
11154
11596
|
function parsePath(path2, depth = 0) {
|
11155
11597
|
const components = path2.split("/");
|
11156
11598
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
11157
|
-
throw new
|
11599
|
+
throw new import_errors28.FuelError(import_errors28.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
11158
11600
|
}
|
11159
11601
|
if (components[0] === "m") {
|
11160
11602
|
components.shift();
|
@@ -11170,8 +11612,8 @@ var HDWallet = class _HDWallet {
|
|
11170
11612
|
}
|
11171
11613
|
depth = 0;
|
11172
11614
|
index = 0;
|
11173
|
-
fingerprint = (0,
|
11174
|
-
parentFingerprint = (0,
|
11615
|
+
fingerprint = (0, import_utils45.hexlify)("0x00000000");
|
11616
|
+
parentFingerprint = (0, import_utils45.hexlify)("0x00000000");
|
11175
11617
|
privateKey;
|
11176
11618
|
publicKey;
|
11177
11619
|
chainCode;
|
@@ -11183,19 +11625,19 @@ var HDWallet = class _HDWallet {
|
|
11183
11625
|
constructor(config) {
|
11184
11626
|
if (config.privateKey) {
|
11185
11627
|
const signer = new Signer(config.privateKey);
|
11186
|
-
this.publicKey = (0,
|
11187
|
-
this.privateKey = (0,
|
11628
|
+
this.publicKey = (0, import_utils45.hexlify)(signer.compressedPublicKey);
|
11629
|
+
this.privateKey = (0, import_utils45.hexlify)(config.privateKey);
|
11188
11630
|
} else {
|
11189
11631
|
if (!config.publicKey) {
|
11190
|
-
throw new
|
11191
|
-
|
11632
|
+
throw new import_errors28.FuelError(
|
11633
|
+
import_errors28.ErrorCode.HD_WALLET_ERROR,
|
11192
11634
|
"Both public and private Key cannot be missing. At least one should be provided."
|
11193
11635
|
);
|
11194
11636
|
}
|
11195
|
-
this.publicKey = (0,
|
11637
|
+
this.publicKey = (0, import_utils45.hexlify)(config.publicKey);
|
11196
11638
|
}
|
11197
11639
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
11198
|
-
this.fingerprint = (0,
|
11640
|
+
this.fingerprint = (0, import_utils45.dataSlice)((0, import_crypto8.ripemd160)((0, import_hasher7.sha256)(this.publicKey)), 0, 4);
|
11199
11641
|
this.depth = config.depth || this.depth;
|
11200
11642
|
this.index = config.index || this.index;
|
11201
11643
|
this.chainCode = config.chainCode;
|
@@ -11211,28 +11653,28 @@ var HDWallet = class _HDWallet {
|
|
11211
11653
|
* @returns A new instance of HDWallet on the derived index
|
11212
11654
|
*/
|
11213
11655
|
deriveIndex(index) {
|
11214
|
-
const privateKey = this.privateKey && (0,
|
11215
|
-
const publicKey = (0,
|
11216
|
-
const chainCode = (0,
|
11656
|
+
const privateKey = this.privateKey && (0, import_utils45.arrayify)(this.privateKey);
|
11657
|
+
const publicKey = (0, import_utils45.arrayify)(this.publicKey);
|
11658
|
+
const chainCode = (0, import_utils45.arrayify)(this.chainCode);
|
11217
11659
|
const data = new Uint8Array(37);
|
11218
11660
|
if (index & HARDENED_INDEX) {
|
11219
11661
|
if (!privateKey) {
|
11220
|
-
throw new
|
11221
|
-
|
11662
|
+
throw new import_errors28.FuelError(
|
11663
|
+
import_errors28.ErrorCode.HD_WALLET_ERROR,
|
11222
11664
|
"Cannot derive a hardened index without a private Key."
|
11223
11665
|
);
|
11224
11666
|
}
|
11225
11667
|
data.set(privateKey, 1);
|
11226
11668
|
} else {
|
11227
|
-
data.set((0,
|
11669
|
+
data.set((0, import_utils45.arrayify)(this.publicKey));
|
11228
11670
|
}
|
11229
|
-
data.set((0,
|
11230
|
-
const bytes = (0,
|
11671
|
+
data.set((0, import_math25.toBytes)(index, 4), 33);
|
11672
|
+
const bytes = (0, import_utils45.arrayify)((0, import_crypto8.computeHmac)("sha512", chainCode, data));
|
11231
11673
|
const IL = bytes.slice(0, 32);
|
11232
11674
|
const IR = bytes.slice(32);
|
11233
11675
|
if (privateKey) {
|
11234
11676
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
11235
|
-
const ki = (0,
|
11677
|
+
const ki = (0, import_math25.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
11236
11678
|
return new _HDWallet({
|
11237
11679
|
privateKey: ki,
|
11238
11680
|
chainCode: IR,
|
@@ -11241,7 +11683,7 @@ var HDWallet = class _HDWallet {
|
|
11241
11683
|
parentFingerprint: this.fingerprint
|
11242
11684
|
});
|
11243
11685
|
}
|
11244
|
-
const signer = new Signer((0,
|
11686
|
+
const signer = new Signer((0, import_utils45.hexlify)(IL));
|
11245
11687
|
const Ki = signer.addPoint(publicKey);
|
11246
11688
|
return new _HDWallet({
|
11247
11689
|
publicKey: Ki,
|
@@ -11270,18 +11712,18 @@ var HDWallet = class _HDWallet {
|
|
11270
11712
|
*/
|
11271
11713
|
toExtendedKey(isPublic = false, testnet = false) {
|
11272
11714
|
if (this.depth >= 256) {
|
11273
|
-
throw new
|
11274
|
-
|
11715
|
+
throw new import_errors28.FuelError(
|
11716
|
+
import_errors28.ErrorCode.HD_WALLET_ERROR,
|
11275
11717
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
11276
11718
|
);
|
11277
11719
|
}
|
11278
11720
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
11279
|
-
const depth = (0,
|
11721
|
+
const depth = (0, import_utils45.hexlify)(Uint8Array.from([this.depth]));
|
11280
11722
|
const parentFingerprint = this.parentFingerprint;
|
11281
|
-
const index = (0,
|
11723
|
+
const index = (0, import_math25.toHex)(this.index, 4);
|
11282
11724
|
const chainCode = this.chainCode;
|
11283
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
11284
|
-
const extendedKey = (0,
|
11725
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils45.concat)(["0x00", this.privateKey]) : this.publicKey;
|
11726
|
+
const extendedKey = (0, import_utils45.arrayify)((0, import_utils45.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
11285
11727
|
return base58check(extendedKey);
|
11286
11728
|
}
|
11287
11729
|
/**
|
@@ -11293,34 +11735,34 @@ var HDWallet = class _HDWallet {
|
|
11293
11735
|
static fromSeed(seed) {
|
11294
11736
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
11295
11737
|
return new _HDWallet({
|
11296
|
-
chainCode: (0,
|
11297
|
-
privateKey: (0,
|
11738
|
+
chainCode: (0, import_utils45.arrayify)(masterKey.slice(32)),
|
11739
|
+
privateKey: (0, import_utils45.arrayify)(masterKey.slice(0, 32))
|
11298
11740
|
});
|
11299
11741
|
}
|
11300
11742
|
static fromExtendedKey(extendedKey) {
|
11301
|
-
const decoded = (0,
|
11302
|
-
const bytes = (0,
|
11743
|
+
const decoded = (0, import_utils45.hexlify)((0, import_math25.toBytes)((0, import_utils45.decodeBase58)(extendedKey)));
|
11744
|
+
const bytes = (0, import_utils45.arrayify)(decoded);
|
11303
11745
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
11304
11746
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
11305
|
-
throw new
|
11747
|
+
throw new import_errors28.FuelError(import_errors28.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
11306
11748
|
}
|
11307
11749
|
if (!validChecksum) {
|
11308
|
-
throw new
|
11750
|
+
throw new import_errors28.FuelError(import_errors28.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
11309
11751
|
}
|
11310
11752
|
const depth = bytes[4];
|
11311
|
-
const parentFingerprint = (0,
|
11312
|
-
const index = parseInt((0,
|
11313
|
-
const chainCode = (0,
|
11753
|
+
const parentFingerprint = (0, import_utils45.hexlify)(bytes.slice(5, 9));
|
11754
|
+
const index = parseInt((0, import_utils45.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
11755
|
+
const chainCode = (0, import_utils45.hexlify)(bytes.slice(13, 45));
|
11314
11756
|
const key = bytes.slice(45, 78);
|
11315
11757
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
11316
|
-
throw new
|
11317
|
-
|
11758
|
+
throw new import_errors28.FuelError(
|
11759
|
+
import_errors28.ErrorCode.HD_WALLET_ERROR,
|
11318
11760
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
11319
11761
|
);
|
11320
11762
|
}
|
11321
11763
|
if (isPublicExtendedKey(bytes)) {
|
11322
11764
|
if (key[0] !== 3) {
|
11323
|
-
throw new
|
11765
|
+
throw new import_errors28.FuelError(import_errors28.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
11324
11766
|
}
|
11325
11767
|
return new _HDWallet({
|
11326
11768
|
publicKey: key,
|
@@ -11331,7 +11773,7 @@ var HDWallet = class _HDWallet {
|
|
11331
11773
|
});
|
11332
11774
|
}
|
11333
11775
|
if (key[0] !== 0) {
|
11334
|
-
throw new
|
11776
|
+
throw new import_errors28.FuelError(import_errors28.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
11335
11777
|
}
|
11336
11778
|
return new _HDWallet({
|
11337
11779
|
privateKey: key.slice(1),
|
@@ -11540,7 +11982,7 @@ var WalletsConfig = class _WalletsConfig {
|
|
11540
11982
|
return {
|
11541
11983
|
...snapshotConfig,
|
11542
11984
|
stateConfig: {
|
11543
|
-
...snapshotConfig?.stateConfig ??
|
11985
|
+
...snapshotConfig?.stateConfig ?? import_utils46.defaultSnapshotConfigs.stateConfig,
|
11544
11986
|
coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
|
11545
11987
|
messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
|
11546
11988
|
}
|
@@ -11567,13 +12009,13 @@ var WalletsConfig = class _WalletsConfig {
|
|
11567
12009
|
assetIds.forEach((assetId) => {
|
11568
12010
|
for (let index = 0; index < coinsPerAsset; index++) {
|
11569
12011
|
coins.push({
|
11570
|
-
amount: (0,
|
12012
|
+
amount: (0, import_math26.bn)(amountPerCoin).toString(),
|
11571
12013
|
asset_id: assetId,
|
11572
12014
|
owner: walletAddress,
|
11573
12015
|
tx_pointer_block_height: 0,
|
11574
12016
|
tx_pointer_tx_idx: 0,
|
11575
12017
|
output_index: 0,
|
11576
|
-
tx_id: (0,
|
12018
|
+
tx_id: (0, import_utils46.hexlify)((0, import_crypto9.randomBytes)(32))
|
11577
12019
|
});
|
11578
12020
|
}
|
11579
12021
|
});
|
@@ -11587,26 +12029,26 @@ var WalletsConfig = class _WalletsConfig {
|
|
11587
12029
|
amountPerCoin
|
11588
12030
|
}) {
|
11589
12031
|
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
11590
|
-
throw new
|
11591
|
-
|
12032
|
+
throw new import_errors29.FuelError(
|
12033
|
+
import_errors29.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
11592
12034
|
"Number of wallets must be greater than zero."
|
11593
12035
|
);
|
11594
12036
|
}
|
11595
12037
|
if (Array.isArray(assets) && assets.length === 0 || typeof assets === "number" && assets <= 0) {
|
11596
|
-
throw new
|
11597
|
-
|
12038
|
+
throw new import_errors29.FuelError(
|
12039
|
+
import_errors29.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
11598
12040
|
"Number of assets per wallet must be greater than zero."
|
11599
12041
|
);
|
11600
12042
|
}
|
11601
12043
|
if (coinsPerAsset <= 0) {
|
11602
|
-
throw new
|
11603
|
-
|
12044
|
+
throw new import_errors29.FuelError(
|
12045
|
+
import_errors29.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
11604
12046
|
"Number of coins per asset must be greater than zero."
|
11605
12047
|
);
|
11606
12048
|
}
|
11607
|
-
if ((0,
|
11608
|
-
throw new
|
11609
|
-
|
12049
|
+
if ((0, import_math26.bn)(amountPerCoin).lt(0)) {
|
12050
|
+
throw new import_errors29.FuelError(
|
12051
|
+
import_errors29.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
11610
12052
|
"Amount per coin must be greater than or equal to zero."
|
11611
12053
|
);
|
11612
12054
|
}
|
@@ -11629,7 +12071,7 @@ async function setupTestProviderAndWallets({
|
|
11629
12071
|
} = {}) {
|
11630
12072
|
Symbol.dispose ??= Symbol("Symbol.dispose");
|
11631
12073
|
const walletsConfig = new WalletsConfig(
|
11632
|
-
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V2?.base_asset_id ??
|
12074
|
+
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V2?.base_asset_id ?? import_utils47.defaultSnapshotConfigs.chainConfig.consensus_parameters.V2.base_asset_id,
|
11633
12075
|
{
|
11634
12076
|
...defaultWalletConfigOptions,
|
11635
12077
|
...walletsConfigOptions
|
@@ -11638,8 +12080,8 @@ async function setupTestProviderAndWallets({
|
|
11638
12080
|
const launchNodeOptions = {
|
11639
12081
|
loggingEnabled: false,
|
11640
12082
|
...nodeOptions,
|
11641
|
-
snapshotConfig: (0,
|
11642
|
-
|
12083
|
+
snapshotConfig: (0, import_ramda11.mergeDeepRight)(
|
12084
|
+
import_utils47.defaultSnapshotConfigs,
|
11643
12085
|
walletsConfig.apply(nodeOptions?.snapshotConfig)
|
11644
12086
|
),
|
11645
12087
|
port: nodeOptions.port || "0"
|
@@ -11682,10 +12124,10 @@ async function setupTestProviderAndWallets({
|
|
11682
12124
|
__name(setupTestProviderAndWallets, "setupTestProviderAndWallets");
|
11683
12125
|
|
11684
12126
|
// src/test-utils/test-message.ts
|
11685
|
-
var
|
12127
|
+
var import_address9 = require("@fuel-ts/address");
|
11686
12128
|
var import_crypto10 = require("@fuel-ts/crypto");
|
11687
|
-
var
|
11688
|
-
var
|
12129
|
+
var import_math27 = require("@fuel-ts/math");
|
12130
|
+
var import_utils48 = require("@fuel-ts/utils");
|
11689
12131
|
var TestMessage = class {
|
11690
12132
|
static {
|
11691
12133
|
__name(this, "TestMessage");
|
@@ -11703,9 +12145,9 @@ var TestMessage = class {
|
|
11703
12145
|
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
11704
12146
|
*/
|
11705
12147
|
constructor({
|
11706
|
-
sender =
|
11707
|
-
recipient =
|
11708
|
-
nonce = (0,
|
12148
|
+
sender = import_address9.Address.fromRandom(),
|
12149
|
+
recipient = import_address9.Address.fromRandom(),
|
12150
|
+
nonce = (0, import_utils48.hexlify)((0, import_crypto10.randomBytes)(32)),
|
11709
12151
|
amount = 1e6,
|
11710
12152
|
data = "",
|
11711
12153
|
// Will default to empty data in order to be a spendable message
|
@@ -11724,7 +12166,7 @@ var TestMessage = class {
|
|
11724
12166
|
sender: this.sender.toB256(),
|
11725
12167
|
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
11726
12168
|
nonce: this.nonce,
|
11727
|
-
amount: (0,
|
12169
|
+
amount: (0, import_math27.bn)(this.amount).toNumber(),
|
11728
12170
|
data,
|
11729
12171
|
da_height: this.da_height
|
11730
12172
|
};
|