@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/index.js
CHANGED
@@ -88,6 +88,7 @@ __export(src_exports, {
|
|
88
88
|
assemblePreConfirmationTransactionSummary: () => assemblePreConfirmationTransactionSummary,
|
89
89
|
assembleReceiptByType: () => assembleReceiptByType,
|
90
90
|
assembleRevertError: () => assembleRevertError,
|
91
|
+
assembleSignalErrorMessage: () => assembleSignalErrorMessage,
|
91
92
|
assembleTransactionSummary: () => assembleTransactionSummary,
|
92
93
|
assembleTransactionSummaryFromJson: () => assembleTransactionSummaryFromJson,
|
93
94
|
assets: () => assets,
|
@@ -104,6 +105,8 @@ __export(src_exports, {
|
|
104
105
|
calculateMinGasForTxUpload: () => calculateMinGasForTxUpload,
|
105
106
|
calculateTXFeeForSummary: () => calculateTXFeeForSummary,
|
106
107
|
coinQuantityfy: () => coinQuantityfy,
|
108
|
+
consolidateCoins: () => consolidateCoins,
|
109
|
+
consolidateCoinsIfRequired: () => consolidateCoinsIfRequired,
|
107
110
|
deferPromise: () => deferPromise,
|
108
111
|
deployScriptOrPredicate: () => deployScriptOrPredicate,
|
109
112
|
deserializeChain: () => deserializeChain,
|
@@ -122,6 +125,7 @@ __export(src_exports, {
|
|
122
125
|
extractTxError: () => extractTxError,
|
123
126
|
fuelAssetsBaseUrl: () => fuelAssetsBaseUrl,
|
124
127
|
gasUsedByInputs: () => gasUsedByInputs,
|
128
|
+
getAllCoins: () => getAllCoins,
|
125
129
|
getAllDecodedLogs: () => getAllDecodedLogs,
|
126
130
|
getAssetAmountInRequestInputs: () => getAssetAmountInRequestInputs,
|
127
131
|
getAssetById: () => getAssetById,
|
@@ -927,14 +931,14 @@ var getAssetsByOwner = /* @__PURE__ */ __name(async (opts) => {
|
|
927
931
|
}, "getAssetsByOwner");
|
928
932
|
|
929
933
|
// src/account.ts
|
930
|
-
var
|
931
|
-
var
|
934
|
+
var import_abi_coder9 = require("@fuel-ts/abi-coder");
|
935
|
+
var import_address6 = require("@fuel-ts/address");
|
932
936
|
var import_crypto2 = require("@fuel-ts/crypto");
|
933
|
-
var
|
934
|
-
var
|
935
|
-
var
|
936
|
-
var
|
937
|
-
var
|
937
|
+
var import_errors23 = require("@fuel-ts/errors");
|
938
|
+
var import_math23 = require("@fuel-ts/math");
|
939
|
+
var import_transactions29 = require("@fuel-ts/transactions");
|
940
|
+
var import_utils37 = require("@fuel-ts/utils");
|
941
|
+
var import_ramda10 = require("ramda");
|
938
942
|
|
939
943
|
// src/providers/coin-quantity.ts
|
940
944
|
var import_math = require("@fuel-ts/math");
|
@@ -975,7 +979,7 @@ var import_address3 = require("@fuel-ts/address");
|
|
975
979
|
var import_errors20 = require("@fuel-ts/errors");
|
976
980
|
var import_math19 = require("@fuel-ts/math");
|
977
981
|
var import_transactions25 = require("@fuel-ts/transactions");
|
978
|
-
var
|
982
|
+
var import_utils32 = require("@fuel-ts/utils");
|
979
983
|
var import_versions = require("@fuel-ts/versions");
|
980
984
|
var import_graphql_request = require("graphql-request");
|
981
985
|
var import_graphql_tag2 = __toESM(require("graphql-tag"));
|
@@ -2375,8 +2379,11 @@ var import_graphql = require("graphql");
|
|
2375
2379
|
|
2376
2380
|
// src/providers/utils/handle-gql-error-message.ts
|
2377
2381
|
var import_errors2 = require("@fuel-ts/errors");
|
2382
|
+
var ASSET_ID_REGEX = /[0-9a-fA-F]{32,64}/g;
|
2378
2383
|
var gqlErrorMessage = {
|
2379
2384
|
RPC_CONSISTENCY: /The required fuel block height is higher than the current block height. Required: \d+, Current: \d+/,
|
2385
|
+
INSUFFICIENT_FUNDS: /the target cannot be met due to insufficient coins available for [0-9a-fA-F]{32,64}. Collected: \d+/,
|
2386
|
+
MAX_COINS_REACHED: /the target for [0-9a-fA-F]{32,64} cannot be met due to exceeding the \d+ coin limit. Collected: \d+./,
|
2380
2387
|
NOT_ENOUGH_COINS_MAX_COINS: /the target cannot be met due to no coins available or exceeding the \d+ coin limit./,
|
2381
2388
|
ASSET_NOT_FOUND: /resource was not found in table/,
|
2382
2389
|
MULTIPLE_CHANGE_POLICIES: /The asset ([a-fA-F0-9]{64}) has multiple change policies/,
|
@@ -2392,6 +2399,46 @@ var mapGqlErrorMessage = /* @__PURE__ */ __name((error) => {
|
|
2392
2399
|
error
|
2393
2400
|
);
|
2394
2401
|
}
|
2402
|
+
if (gqlErrorMessage.MAX_COINS_REACHED.test(error.message)) {
|
2403
|
+
const matches = error.message.match(ASSET_ID_REGEX);
|
2404
|
+
const assetId = matches ? `0x${matches[0]}` : null;
|
2405
|
+
const owner = matches ? `0x${matches[1]}` : null;
|
2406
|
+
let suffix = "";
|
2407
|
+
if (assetId) {
|
2408
|
+
suffix += `
|
2409
|
+
Asset ID: '${assetId}'.`;
|
2410
|
+
}
|
2411
|
+
if (owner) {
|
2412
|
+
suffix += `
|
2413
|
+
Owner: '${owner}'.`;
|
2414
|
+
}
|
2415
|
+
return new import_errors2.FuelError(
|
2416
|
+
import_errors2.ErrorCode.MAX_COINS_REACHED,
|
2417
|
+
`You have too many small value coins - consider combining UTXOs.${suffix}`,
|
2418
|
+
{ assetId, owner },
|
2419
|
+
error
|
2420
|
+
);
|
2421
|
+
}
|
2422
|
+
if (gqlErrorMessage.INSUFFICIENT_FUNDS.test(error.message)) {
|
2423
|
+
const matches = error.message.match(ASSET_ID_REGEX);
|
2424
|
+
const assetId = matches ? `0x${matches[0]}` : null;
|
2425
|
+
const owner = matches ? `0x${matches[1]}` : null;
|
2426
|
+
let suffix = "";
|
2427
|
+
if (assetId) {
|
2428
|
+
suffix += `
|
2429
|
+
Asset ID: '${assetId}'.`;
|
2430
|
+
}
|
2431
|
+
if (owner) {
|
2432
|
+
suffix += `
|
2433
|
+
Owner: '${owner}'.`;
|
2434
|
+
}
|
2435
|
+
return new import_errors2.FuelError(
|
2436
|
+
import_errors2.ErrorCode.INSUFFICIENT_FUNDS,
|
2437
|
+
`Insufficient funds.${suffix}`,
|
2438
|
+
{ assetId, owner },
|
2439
|
+
error
|
2440
|
+
);
|
2441
|
+
}
|
2395
2442
|
if (gqlErrorMessage.MULTIPLE_CHANGE_POLICIES.test(error.message)) {
|
2396
2443
|
const match = error.message.match(/asset ([a-fA-F0-9]{64})/);
|
2397
2444
|
const assetId = match?.[1] || "";
|
@@ -3482,58 +3529,98 @@ ${import_configs5.PANIC_DOC_URL}#variant.${statusReason}`;
|
|
3482
3529
|
});
|
3483
3530
|
}, "assemblePanicError");
|
3484
3531
|
var stringify = /* @__PURE__ */ __name((obj) => JSON.stringify(obj, null, 2), "stringify");
|
3485
|
-
var
|
3532
|
+
var assembleSignalErrorMessage = /* @__PURE__ */ __name((reasonHex, logs, metadata) => {
|
3486
3533
|
let errorMessage = "The transaction reverted with an unknown reason.";
|
3487
|
-
const revertReceipt = receipts.find(({ type }) => type === import_transactions7.ReceiptType.Revert);
|
3488
3534
|
let reason = "";
|
3489
|
-
|
3490
|
-
|
3491
|
-
|
3492
|
-
|
3493
|
-
|
3494
|
-
|
3495
|
-
|
3496
|
-
|
3497
|
-
|
3498
|
-
}
|
3499
|
-
|
3500
|
-
|
3501
|
-
|
3502
|
-
|
3503
|
-
|
3504
|
-
}
|
3505
|
-
|
3506
|
-
|
3507
|
-
|
3508
|
-
|
3509
|
-
|
3510
|
-
|
3511
|
-
|
3512
|
-
|
3513
|
-
|
3514
|
-
|
3515
|
-
|
3516
|
-
|
3517
|
-
|
3518
|
-
|
3519
|
-
|
3520
|
-
|
3521
|
-
|
3522
|
-
|
3523
|
-
|
3524
|
-
|
3525
|
-
|
3526
|
-
|
3527
|
-
|
3535
|
+
const lastLog = logs[logs.length - 1];
|
3536
|
+
const lastButOneLog = logs[logs.length - 2];
|
3537
|
+
switch (reasonHex) {
|
3538
|
+
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
3539
|
+
reason = "require";
|
3540
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
|
3541
|
+
break;
|
3542
|
+
}
|
3543
|
+
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
3544
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastLog)} and ${stringify(lastButOneLog)}.` : ".";
|
3545
|
+
reason = "assert_eq";
|
3546
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${suffix}`;
|
3547
|
+
break;
|
3548
|
+
}
|
3549
|
+
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
3550
|
+
const suffix = logs.length >= 2 ? ` comparing ${stringify(lastButOneLog)} and ${stringify(lastLog)}.` : ".";
|
3551
|
+
reason = "assert_ne";
|
3552
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${suffix}`;
|
3553
|
+
break;
|
3554
|
+
}
|
3555
|
+
case import_configs5.FAILED_ASSERT_SIGNAL:
|
3556
|
+
reason = "assert";
|
3557
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
3558
|
+
break;
|
3559
|
+
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
3560
|
+
reason = "MissingOutputVariable";
|
3561
|
+
errorMessage = `The transaction reverted because it's missing an "OutputVariable".`;
|
3562
|
+
break;
|
3563
|
+
default:
|
3564
|
+
reason = `revert_with_log`;
|
3565
|
+
errorMessage = `The transaction reverted because a "revert_with_log" statement has thrown ${logs.length ? stringify(lastLog) : "an error."}.`;
|
3566
|
+
break;
|
3567
|
+
}
|
3568
|
+
return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
|
3569
|
+
...metadata,
|
3570
|
+
reason
|
3571
|
+
});
|
3572
|
+
}, "assembleSignalErrorMessage");
|
3573
|
+
function buildAbiErrorMessage(abiError, logs, metadata, reason) {
|
3574
|
+
const { pos, msg } = abiError;
|
3575
|
+
let errorMessage = "";
|
3576
|
+
const positionMessage = pos ? `
|
3577
|
+
|
3578
|
+
This error originated at ${JSON.stringify(pos, null, 2)}` : "";
|
3579
|
+
if (msg) {
|
3580
|
+
errorMessage = `A sway "panic" expression was invoked with the message: "${msg}".${positionMessage}`;
|
3581
|
+
} else {
|
3582
|
+
const value = logs[logs.length - 1];
|
3583
|
+
errorMessage = `A sway "panic" expression was invoked with the value: ${JSON.stringify(value)}.${positionMessage}`;
|
3584
|
+
}
|
3585
|
+
return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
|
3586
|
+
...metadata,
|
3587
|
+
abiError,
|
3588
|
+
reason
|
3589
|
+
});
|
3590
|
+
}
|
3591
|
+
__name(buildAbiErrorMessage, "buildAbiErrorMessage");
|
3592
|
+
function findErrorInAbis(statusReason, abis = []) {
|
3593
|
+
for (const abi of abis) {
|
3594
|
+
if (abi.errorCodes?.[statusReason]) {
|
3595
|
+
return abi.errorCodes[statusReason];
|
3528
3596
|
}
|
3529
3597
|
}
|
3598
|
+
return void 0;
|
3599
|
+
}
|
3600
|
+
__name(findErrorInAbis, "findErrorInAbis");
|
3601
|
+
var assembleRevertError = /* @__PURE__ */ __name((_receipts, logs, metadata, statusReason, abis) => {
|
3602
|
+
const match = statusReason.match(/Revert\((\d+)\)/);
|
3603
|
+
const reason = match?.[1] ?? statusReason;
|
3604
|
+
const reasonHex = (0, import_math7.bn)(reason).toHex();
|
3605
|
+
if (Object.values(import_configs5.SwaySignalErrors).includes(reasonHex)) {
|
3606
|
+
return assembleSignalErrorMessage(reasonHex, logs, metadata);
|
3607
|
+
}
|
3608
|
+
let abiError;
|
3609
|
+
if (abis) {
|
3610
|
+
const abisArr = [abis.main, ...Object.values(abis.otherContractsAbis)];
|
3611
|
+
abiError = findErrorInAbis(reason, abisArr);
|
3612
|
+
}
|
3613
|
+
if (abiError) {
|
3614
|
+
return buildAbiErrorMessage(abiError, logs, metadata, reason);
|
3615
|
+
}
|
3616
|
+
const errorMessage = `The transaction reverted with reason: ${reason}.`;
|
3530
3617
|
return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
|
3531
3618
|
...metadata,
|
3532
3619
|
reason
|
3533
3620
|
});
|
3534
3621
|
}, "assembleRevertError");
|
3535
3622
|
var extractTxError = /* @__PURE__ */ __name((params) => {
|
3536
|
-
const { receipts, statusReason, logs, groupedLogs } = params;
|
3623
|
+
const { receipts, statusReason, logs, groupedLogs, abis } = params;
|
3537
3624
|
const isPanic = receipts.some(({ type }) => type === import_transactions7.ReceiptType.Panic);
|
3538
3625
|
const isRevert = receipts.some(({ type }) => type === import_transactions7.ReceiptType.Revert);
|
3539
3626
|
const metadata = {
|
@@ -3547,7 +3634,7 @@ var extractTxError = /* @__PURE__ */ __name((params) => {
|
|
3547
3634
|
if (isPanic) {
|
3548
3635
|
return assemblePanicError(statusReason, metadata);
|
3549
3636
|
}
|
3550
|
-
return assembleRevertError(receipts, logs, metadata);
|
3637
|
+
return assembleRevertError(receipts, logs, metadata, statusReason, abis);
|
3551
3638
|
}, "extractTxError");
|
3552
3639
|
|
3553
3640
|
// src/providers/utils/merge-quantities.ts
|
@@ -4552,11 +4639,15 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
4552
4639
|
* @deprecated Use `provider.assembleTx` instead.
|
4553
4640
|
* Check the migration guide https://docs.fuel.network/guide/assembling-transactions/migration-guide.html for more information.
|
4554
4641
|
*/
|
4555
|
-
async estimateAndFund(account, {
|
4642
|
+
async estimateAndFund(account, {
|
4643
|
+
signatureCallback,
|
4644
|
+
quantities = [],
|
4645
|
+
skipAutoConsolidation
|
4646
|
+
} = {}) {
|
4556
4647
|
const txCost = await account.getTransactionCost(this, { signatureCallback, quantities });
|
4557
4648
|
this.maxFee = txCost.maxFee;
|
4558
4649
|
this.gasLimit = txCost.gasUsed;
|
4559
|
-
await account.fund(this, txCost);
|
4650
|
+
await account.fund(this, txCost, { skipAutoConsolidation });
|
4560
4651
|
return this;
|
4561
4652
|
}
|
4562
4653
|
/**
|
@@ -5133,12 +5224,12 @@ var ResourceCache = class {
|
|
5133
5224
|
var import_errors18 = require("@fuel-ts/errors");
|
5134
5225
|
var import_math18 = require("@fuel-ts/math");
|
5135
5226
|
var import_transactions23 = require("@fuel-ts/transactions");
|
5136
|
-
var
|
5227
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5137
5228
|
|
5138
5229
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
5139
5230
|
var import_math17 = require("@fuel-ts/math");
|
5140
5231
|
var import_transactions21 = require("@fuel-ts/transactions");
|
5141
|
-
var
|
5232
|
+
var import_utils27 = require("@fuel-ts/utils");
|
5142
5233
|
|
5143
5234
|
// src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
|
5144
5235
|
var import_math13 = require("@fuel-ts/math");
|
@@ -5211,6 +5302,45 @@ var import_configs11 = require("@fuel-ts/address/configs");
|
|
5211
5302
|
var import_errors16 = require("@fuel-ts/errors");
|
5212
5303
|
var import_math15 = require("@fuel-ts/math");
|
5213
5304
|
var import_transactions19 = require("@fuel-ts/transactions");
|
5305
|
+
var import_utils25 = require("@fuel-ts/utils");
|
5306
|
+
|
5307
|
+
// src/providers/transaction-summary/call.ts
|
5308
|
+
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
5309
|
+
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
5310
|
+
var getFunctionCall = /* @__PURE__ */ __name(({
|
5311
|
+
abi,
|
5312
|
+
receipt,
|
5313
|
+
offset,
|
5314
|
+
scriptData
|
5315
|
+
}) => {
|
5316
|
+
const [functionSelector, argumentsOffset] = new import_abi_coder4.StdStringCoder().decode(scriptData, offset);
|
5317
|
+
const abiInterface = new import_abi_coder5.Interface(abi);
|
5318
|
+
const functionFragment = abiInterface.getFunction(functionSelector);
|
5319
|
+
const inputs = functionFragment.jsonFn.inputs;
|
5320
|
+
let argumentsProvided;
|
5321
|
+
if (inputs.length) {
|
5322
|
+
const functionArgsBytes = scriptData.slice(argumentsOffset);
|
5323
|
+
const decodedArguments = functionFragment.decodeArguments(functionArgsBytes);
|
5324
|
+
argumentsProvided = inputs.reduce((prev, input, index) => {
|
5325
|
+
const value = decodedArguments?.[index];
|
5326
|
+
const name = input.name;
|
5327
|
+
if (name) {
|
5328
|
+
return {
|
5329
|
+
...prev,
|
5330
|
+
// reparse to remove bn
|
5331
|
+
[name]: JSON.parse(JSON.stringify(value))
|
5332
|
+
};
|
5333
|
+
}
|
5334
|
+
return prev;
|
5335
|
+
}, {});
|
5336
|
+
}
|
5337
|
+
return {
|
5338
|
+
functionSignature: functionFragment.signature,
|
5339
|
+
functionName: functionFragment.name,
|
5340
|
+
argumentsProvided,
|
5341
|
+
...receipt.amount?.isZero() ? {} : { amount: receipt.amount, assetId: receipt.assetId }
|
5342
|
+
};
|
5343
|
+
}, "getFunctionCall");
|
5214
5344
|
|
5215
5345
|
// src/providers/transaction-summary/input.ts
|
5216
5346
|
var import_errors15 = require("@fuel-ts/errors");
|
@@ -5545,12 +5675,45 @@ function getWithdrawFromFuelOperations({
|
|
5545
5675
|
return withdrawFromFuelOperations;
|
5546
5676
|
}
|
5547
5677
|
__name(getWithdrawFromFuelOperations, "getWithdrawFromFuelOperations");
|
5548
|
-
function
|
5549
|
-
|
5550
|
-
|
5551
|
-
|
5678
|
+
function findBytesSegmentIndex(whole, segment) {
|
5679
|
+
for (let i = 0; i <= whole.length - segment.length; i++) {
|
5680
|
+
let match = true;
|
5681
|
+
for (let j = 0; j < segment.length; j++) {
|
5682
|
+
if (whole[i + j] !== segment[j]) {
|
5683
|
+
match = false;
|
5684
|
+
break;
|
5685
|
+
}
|
5686
|
+
}
|
5687
|
+
if (match) {
|
5688
|
+
return i;
|
5689
|
+
}
|
5552
5690
|
}
|
5553
|
-
return
|
5691
|
+
return -1;
|
5692
|
+
}
|
5693
|
+
__name(findBytesSegmentIndex, "findBytesSegmentIndex");
|
5694
|
+
function getContractCalls(contractInput, abiMap, receipt, scriptData) {
|
5695
|
+
const calls = [];
|
5696
|
+
const abi = abiMap?.[contractInput.contractID];
|
5697
|
+
if (!abi || !scriptData) {
|
5698
|
+
return calls;
|
5699
|
+
}
|
5700
|
+
const bytesSegment = (0, import_utils25.concat)([
|
5701
|
+
(0, import_utils25.arrayify)(receipt.to),
|
5702
|
+
// Contract ID (32 bytes)
|
5703
|
+
(0, import_math15.toBytes)(receipt.param1.toHex(), 8),
|
5704
|
+
// Function selector offset (8 bytes)
|
5705
|
+
(0, import_math15.toBytes)(receipt.param2.toHex(), 8)
|
5706
|
+
// Function args offset (8 bytes)
|
5707
|
+
]);
|
5708
|
+
const segmentIndex = findBytesSegmentIndex(scriptData, bytesSegment);
|
5709
|
+
const canDecodeFunctionCall = segmentIndex !== -1;
|
5710
|
+
if (!canDecodeFunctionCall) {
|
5711
|
+
return calls;
|
5712
|
+
}
|
5713
|
+
const offset = segmentIndex + bytesSegment.length;
|
5714
|
+
const call = getFunctionCall({ abi, receipt, offset, scriptData });
|
5715
|
+
calls.push(call);
|
5716
|
+
return calls;
|
5554
5717
|
}
|
5555
5718
|
__name(getContractCalls, "getContractCalls");
|
5556
5719
|
function getAssetsSent(receipt) {
|
@@ -5562,14 +5725,14 @@ function getAssetsSent(receipt) {
|
|
5562
5725
|
];
|
5563
5726
|
}
|
5564
5727
|
__name(getAssetsSent, "getAssetsSent");
|
5565
|
-
function processCallReceipt(receipt, contractInput, inputs, abiMap,
|
5728
|
+
function processCallReceipt(receipt, contractInput, inputs, abiMap, scriptData, baseAssetId) {
|
5566
5729
|
const assetId = receipt.assetId === import_configs11.ZeroBytes32 ? baseAssetId : receipt.assetId;
|
5567
5730
|
const input = getInputFromAssetId(inputs, assetId, assetId === baseAssetId);
|
5568
5731
|
if (!input) {
|
5569
5732
|
return [];
|
5570
5733
|
}
|
5571
5734
|
const inputAddress = getInputAccountAddress(input);
|
5572
|
-
const calls = getContractCalls(contractInput, abiMap, receipt,
|
5735
|
+
const calls = getContractCalls(contractInput, abiMap, receipt, scriptData);
|
5573
5736
|
return [
|
5574
5737
|
{
|
5575
5738
|
name: "Contract call" /* contractCall */,
|
@@ -5594,7 +5757,6 @@ function getContractCallOperations({
|
|
5594
5757
|
receipts,
|
5595
5758
|
abiMap,
|
5596
5759
|
rawPayload,
|
5597
|
-
maxInputs,
|
5598
5760
|
baseAssetId
|
5599
5761
|
}) {
|
5600
5762
|
const contractCallReceipts = getReceiptsCall(receipts);
|
@@ -5604,16 +5766,15 @@ function getContractCallOperations({
|
|
5604
5766
|
if (!contractInput) {
|
5605
5767
|
return [];
|
5606
5768
|
}
|
5769
|
+
let scriptData;
|
5770
|
+
if (rawPayload) {
|
5771
|
+
const [transaction] = new import_transactions19.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
|
5772
|
+
if (transaction.type === import_transactions19.TransactionType.Script) {
|
5773
|
+
scriptData = (0, import_utils25.arrayify)(transaction.scriptData);
|
5774
|
+
}
|
5775
|
+
}
|
5607
5776
|
return contractCallReceipts.filter((receipt) => receipt.to === contractInput.contractID).flatMap(
|
5608
|
-
(receipt) => processCallReceipt(
|
5609
|
-
receipt,
|
5610
|
-
contractInput,
|
5611
|
-
inputs,
|
5612
|
-
abiMap,
|
5613
|
-
rawPayload,
|
5614
|
-
maxInputs,
|
5615
|
-
baseAssetId
|
5616
|
-
)
|
5777
|
+
(receipt) => processCallReceipt(receipt, contractInput, inputs, abiMap, scriptData, baseAssetId)
|
5617
5778
|
);
|
5618
5779
|
});
|
5619
5780
|
}
|
@@ -5938,7 +6099,7 @@ function assembleTransactionSummary(params) {
|
|
5938
6099
|
baseAssetId
|
5939
6100
|
} = params;
|
5940
6101
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
5941
|
-
const rawPayload = (0,
|
6102
|
+
const rawPayload = (0, import_utils27.hexlify)(transactionBytes);
|
5942
6103
|
const operations = getOperations({
|
5943
6104
|
transactionType: transaction.type,
|
5944
6105
|
inputs: transaction.inputs || [],
|
@@ -5969,7 +6130,7 @@ function assembleTransactionSummary(params) {
|
|
5969
6130
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
5970
6131
|
let date;
|
5971
6132
|
if (time) {
|
5972
|
-
date =
|
6133
|
+
date = import_utils27.DateTime.fromTai64(time);
|
5973
6134
|
}
|
5974
6135
|
const transactionSummary = {
|
5975
6136
|
id,
|
@@ -6030,7 +6191,7 @@ function assemblePreConfirmationTransactionSummary(params) {
|
|
6030
6191
|
type = getTransactionTypeName(transaction.type);
|
6031
6192
|
tip = (0, import_math17.bn)(transaction.policies?.find((policy) => policy.type === import_transactions21.PolicyType.Tip)?.data);
|
6032
6193
|
if (receipts) {
|
6033
|
-
const rawPayload = (0,
|
6194
|
+
const rawPayload = (0, import_utils27.hexlify)(new import_transactions21.TransactionCoder().encode(transaction));
|
6034
6195
|
operations = getOperations({
|
6035
6196
|
transactionType: transaction.type,
|
6036
6197
|
inputs: transaction.inputs || [],
|
@@ -6076,7 +6237,7 @@ function assemblePreConfirmationTransactionSummary(params) {
|
|
6076
6237
|
__name(assemblePreConfirmationTransactionSummary, "assemblePreConfirmationTransactionSummary");
|
6077
6238
|
|
6078
6239
|
// src/providers/transaction-response/getAllDecodedLogs.ts
|
6079
|
-
var
|
6240
|
+
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
6080
6241
|
var import_configs12 = require("@fuel-ts/address/configs");
|
6081
6242
|
var import_transactions22 = require("@fuel-ts/transactions");
|
6082
6243
|
function getAllDecodedLogs(opts) {
|
@@ -6096,8 +6257,8 @@ function getAllDecodedLogs(opts) {
|
|
6096
6257
|
const isLogFromMainAbi = receipt.id === import_configs12.ZeroBytes32 || mainContract === receipt.id;
|
6097
6258
|
const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
|
6098
6259
|
if (isDecodable) {
|
6099
|
-
const interfaceToUse = isLogFromMainAbi ? new
|
6100
|
-
const data = receipt.type === import_transactions22.ReceiptType.Log ? new
|
6260
|
+
const interfaceToUse = isLogFromMainAbi ? new import_abi_coder6.Interface(mainAbi) : new import_abi_coder6.Interface(externalAbis[receipt.id]);
|
6261
|
+
const data = receipt.type === import_transactions22.ReceiptType.Log ? new import_abi_coder6.BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
6101
6262
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
6102
6263
|
logs.push(decodedLog);
|
6103
6264
|
groupedLogs[receipt.id] = [...groupedLogs[receipt.id] || [], decodedLog];
|
@@ -6112,25 +6273,6 @@ __name(getAllDecodedLogs, "getAllDecodedLogs");
|
|
6112
6273
|
|
6113
6274
|
// src/providers/transaction-response/transaction-response.ts
|
6114
6275
|
var TransactionResponse = class _TransactionResponse {
|
6115
|
-
/**
|
6116
|
-
* Constructor for `TransactionResponse`.
|
6117
|
-
*
|
6118
|
-
* @param tx - The transaction ID or TransactionRequest.
|
6119
|
-
* @param provider - The provider.
|
6120
|
-
*/
|
6121
|
-
constructor(tx, provider, chainId, abis, submitTxSubscription) {
|
6122
|
-
this.submitTxSubscription = submitTxSubscription;
|
6123
|
-
if (typeof tx === "string") {
|
6124
|
-
this.id = tx;
|
6125
|
-
} else {
|
6126
|
-
this.id = tx.getTransactionId(chainId);
|
6127
|
-
this.request = tx;
|
6128
|
-
}
|
6129
|
-
this.provider = provider;
|
6130
|
-
this.abis = abis;
|
6131
|
-
this.waitForResult = this.waitForResult.bind(this);
|
6132
|
-
this.waitForPreConfirmation = this.waitForPreConfirmation.bind(this);
|
6133
|
-
}
|
6134
6276
|
static {
|
6135
6277
|
__name(this, "TransactionResponse");
|
6136
6278
|
}
|
@@ -6145,9 +6287,42 @@ var TransactionResponse = class _TransactionResponse {
|
|
6145
6287
|
request;
|
6146
6288
|
status;
|
6147
6289
|
abis;
|
6290
|
+
submitTxSubscription;
|
6148
6291
|
preConfirmationStatus;
|
6149
6292
|
waitingForStreamData = false;
|
6150
6293
|
statusResolvers = /* @__PURE__ */ new Map();
|
6294
|
+
/**
|
6295
|
+
* Constructor for `TransactionResponse`.
|
6296
|
+
*/
|
6297
|
+
constructor(constructorParams, provider, chainId, abis, submitTxSubscription) {
|
6298
|
+
let tx;
|
6299
|
+
let _provider;
|
6300
|
+
let _chainId;
|
6301
|
+
let _abis;
|
6302
|
+
if (typeof constructorParams === "object" && "provider" in constructorParams && arguments.length === 1) {
|
6303
|
+
tx = constructorParams.transactionRequestOrId;
|
6304
|
+
_provider = constructorParams.provider;
|
6305
|
+
_chainId = constructorParams.chainId;
|
6306
|
+
_abis = constructorParams.abis;
|
6307
|
+
this.submitTxSubscription = constructorParams.submitAndAwaitSubscription;
|
6308
|
+
} else {
|
6309
|
+
tx = constructorParams;
|
6310
|
+
_provider = provider;
|
6311
|
+
_chainId = chainId;
|
6312
|
+
_abis = abis;
|
6313
|
+
this.submitTxSubscription = submitTxSubscription;
|
6314
|
+
}
|
6315
|
+
if (typeof tx === "string") {
|
6316
|
+
this.id = tx;
|
6317
|
+
} else {
|
6318
|
+
this.id = tx.getTransactionId(_chainId);
|
6319
|
+
this.request = tx;
|
6320
|
+
}
|
6321
|
+
this.provider = _provider;
|
6322
|
+
this.abis = _abis;
|
6323
|
+
this.waitForResult = this.waitForResult.bind(this);
|
6324
|
+
this.waitForPreConfirmation = this.waitForPreConfirmation.bind(this);
|
6325
|
+
}
|
6151
6326
|
/**
|
6152
6327
|
* Async constructor for `TransactionResponse`. This method can be used to create
|
6153
6328
|
* an instance of `TransactionResponse` and wait for the transaction to be fetched
|
@@ -6196,7 +6371,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
6196
6371
|
}
|
6197
6372
|
const gqlTransaction = this.gqlTransaction ?? await this.fetch();
|
6198
6373
|
const { rawPayload } = gqlTransaction;
|
6199
|
-
const bytes = (0,
|
6374
|
+
const bytes = (0, import_utils29.arrayify)(rawPayload);
|
6200
6375
|
const [tx] = new import_transactions23.TransactionCoder().decode(bytes, 0);
|
6201
6376
|
return {
|
6202
6377
|
tx,
|
@@ -6384,6 +6559,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
6384
6559
|
...transactionSummary
|
6385
6560
|
};
|
6386
6561
|
let { logs, groupedLogs } = { logs: [], groupedLogs: {} };
|
6562
|
+
let abis;
|
6387
6563
|
if (this.abis) {
|
6388
6564
|
({ logs, groupedLogs } = getAllDecodedLogs({
|
6389
6565
|
receipts: transactionSummary.receipts,
|
@@ -6392,6 +6568,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
6392
6568
|
}));
|
6393
6569
|
transactionResult.logs = logs;
|
6394
6570
|
transactionResult.groupedLogs = groupedLogs;
|
6571
|
+
abis = this.abis;
|
6395
6572
|
}
|
6396
6573
|
const { receipts } = transactionResult;
|
6397
6574
|
const status = this.getTransactionStatus();
|
@@ -6401,7 +6578,8 @@ var TransactionResponse = class _TransactionResponse {
|
|
6401
6578
|
receipts,
|
6402
6579
|
statusReason: reason,
|
6403
6580
|
logs,
|
6404
|
-
groupedLogs
|
6581
|
+
groupedLogs,
|
6582
|
+
abis
|
6405
6583
|
});
|
6406
6584
|
}
|
6407
6585
|
return transactionResult;
|
@@ -6463,7 +6641,7 @@ var TransactionResponse = class _TransactionResponse {
|
|
6463
6641
|
};
|
6464
6642
|
|
6465
6643
|
// src/providers/transaction-response/getDecodedLogs.ts
|
6466
|
-
var
|
6644
|
+
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
6467
6645
|
var import_configs13 = require("@fuel-ts/address/configs");
|
6468
6646
|
var import_transactions24 = require("@fuel-ts/transactions");
|
6469
6647
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
@@ -6479,8 +6657,8 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
|
6479
6657
|
const isLogFromMainAbi = receipt.id === import_configs13.ZeroBytes32 || mainContract === receipt.id;
|
6480
6658
|
const isDecodable = isLogFromMainAbi || externalAbis[receipt.id];
|
6481
6659
|
if (isDecodable) {
|
6482
|
-
const interfaceToUse = isLogFromMainAbi ? new
|
6483
|
-
const data = receipt.type === import_transactions24.ReceiptType.Log ? new
|
6660
|
+
const interfaceToUse = isLogFromMainAbi ? new import_abi_coder7.Interface(mainAbi) : new import_abi_coder7.Interface(externalAbis[receipt.id]);
|
6661
|
+
const data = receipt.type === import_transactions24.ReceiptType.Log ? new import_abi_coder7.BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
6484
6662
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
6485
6663
|
logs.push(decodedLog);
|
6486
6664
|
}
|
@@ -6491,7 +6669,7 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
|
6491
6669
|
__name(getDecodedLogs, "getDecodedLogs");
|
6492
6670
|
|
6493
6671
|
// src/providers/utils/auto-retry-fetch.ts
|
6494
|
-
var
|
6672
|
+
var import_utils31 = require("@fuel-ts/utils");
|
6495
6673
|
function getWaitDelay(options, retryAttemptNum) {
|
6496
6674
|
const duration = options.baseDelay ?? 150;
|
6497
6675
|
switch (options.backoff) {
|
@@ -6522,7 +6700,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
6522
6700
|
throw error;
|
6523
6701
|
}
|
6524
6702
|
const delay = getWaitDelay(options, retryNum);
|
6525
|
-
await (0,
|
6703
|
+
await (0, import_utils31.sleep)(delay);
|
6526
6704
|
return autoRetryFetch(fetchFn, options, retryNum)(...args);
|
6527
6705
|
}
|
6528
6706
|
};
|
@@ -6662,7 +6840,7 @@ var Provider = class _Provider {
|
|
6662
6840
|
return url.replace(/-sub$/, "");
|
6663
6841
|
}
|
6664
6842
|
static hasWriteOperationHappened(url) {
|
6665
|
-
return (0,
|
6843
|
+
return (0, import_utils32.isDefined)(_Provider.currentBlockHeightCache[this.normalizeUrl(url)]);
|
6666
6844
|
}
|
6667
6845
|
/**
|
6668
6846
|
* @hidden
|
@@ -6684,7 +6862,15 @@ var Provider = class _Provider {
|
|
6684
6862
|
if (_Provider.ENABLE_RPC_CONSISTENCY && _Provider.hasWriteOperationHappened(url)) {
|
6685
6863
|
_Provider.applyBlockHeight(fullRequest, url);
|
6686
6864
|
}
|
6687
|
-
|
6865
|
+
const response = await _Provider.fetchAndProcessBlockHeight(url, fullRequest, options);
|
6866
|
+
if (response.body === null) {
|
6867
|
+
throw new import_errors20.FuelError(
|
6868
|
+
import_errors20.ErrorCode.RESPONSE_BODY_EMPTY,
|
6869
|
+
"The response from the server is missing the body",
|
6870
|
+
{ timestamp: (/* @__PURE__ */ new Date()).toISOString(), request: request2, response }
|
6871
|
+
);
|
6872
|
+
}
|
6873
|
+
return response;
|
6688
6874
|
}, retryOptions);
|
6689
6875
|
}
|
6690
6876
|
static applyBlockHeight(request2, url) {
|
@@ -6707,24 +6893,26 @@ var Provider = class _Provider {
|
|
6707
6893
|
baseDelay: 500
|
6708
6894
|
};
|
6709
6895
|
for (let retriesLeft = retryOptions.maxRetries; retriesLeft > 0; --retriesLeft) {
|
6710
|
-
|
6711
|
-
|
6712
|
-
|
6713
|
-
|
6714
|
-
|
6715
|
-
|
6716
|
-
|
6896
|
+
if (response.body) {
|
6897
|
+
const { extensions } = await parseGraphqlResponse({
|
6898
|
+
response,
|
6899
|
+
isSubscription: url.endsWith("-sub")
|
6900
|
+
});
|
6901
|
+
_Provider.setCurrentBlockHeight(url, extensions?.current_fuel_block_height);
|
6902
|
+
if (!extensions?.fuel_block_height_precondition_failed) {
|
6903
|
+
break;
|
6904
|
+
}
|
6717
6905
|
}
|
6718
6906
|
const retryAttempt = retryOptions.maxRetries - retriesLeft + 1;
|
6719
6907
|
const sleepTime = getWaitDelay(retryOptions, retryAttempt);
|
6720
|
-
await (0,
|
6908
|
+
await (0, import_utils32.sleep)(sleepTime);
|
6721
6909
|
response = await fetchFn();
|
6722
6910
|
}
|
6723
6911
|
return response;
|
6724
6912
|
}
|
6725
6913
|
static setCurrentBlockHeight(url, height) {
|
6726
6914
|
const writeOperationHappened = _Provider.hasWriteOperationHappened(url);
|
6727
|
-
if (!(0,
|
6915
|
+
if (!(0, import_utils32.isDefined)(height) || !writeOperationHappened) {
|
6728
6916
|
return;
|
6729
6917
|
}
|
6730
6918
|
const normalizedUrl = _Provider.normalizeUrl(url);
|
@@ -6759,7 +6947,7 @@ var Provider = class _Provider {
|
|
6759
6947
|
_Provider.chainInfoCache[this.urlWithoutAuth] = chain;
|
6760
6948
|
_Provider.nodeInfoCache[this.urlWithoutAuth] = nodeInfo;
|
6761
6949
|
}
|
6762
|
-
if ((0,
|
6950
|
+
if ((0, import_utils32.isDefined)(resourceCacheTTL)) {
|
6763
6951
|
if (resourceCacheTTL !== -1) {
|
6764
6952
|
this.cache = new ResourceCache(resourceCacheTTL);
|
6765
6953
|
} else {
|
@@ -7122,7 +7310,7 @@ var Provider = class _Provider {
|
|
7122
7310
|
await this.estimateTxDependencies(transactionRequest);
|
7123
7311
|
}
|
7124
7312
|
await this.validateTransaction(transactionRequest);
|
7125
|
-
const encodedTransaction = (0,
|
7313
|
+
const encodedTransaction = (0, import_utils32.hexlify)(transactionRequest.toTransactionBytes());
|
7126
7314
|
let abis;
|
7127
7315
|
if (isTransactionTypeScript(transactionRequest)) {
|
7128
7316
|
abis = transactionRequest.abis;
|
@@ -7136,7 +7324,13 @@ var Provider = class _Provider {
|
|
7136
7324
|
transactionRequest.getTransactionId(await this.getChainId())
|
7137
7325
|
);
|
7138
7326
|
const chainId = await this.getChainId();
|
7139
|
-
return new TransactionResponse(
|
7327
|
+
return new TransactionResponse({
|
7328
|
+
transactionRequestOrId: transactionRequest,
|
7329
|
+
provider: this,
|
7330
|
+
chainId,
|
7331
|
+
abis,
|
7332
|
+
submitAndAwaitSubscription: subscription
|
7333
|
+
});
|
7140
7334
|
}
|
7141
7335
|
/**
|
7142
7336
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -7153,7 +7347,7 @@ var Provider = class _Provider {
|
|
7153
7347
|
if (estimateTxDependencies) {
|
7154
7348
|
return this.estimateTxDependencies(transactionRequest);
|
7155
7349
|
}
|
7156
|
-
const encodedTransaction = (0,
|
7350
|
+
const encodedTransaction = (0, import_utils32.hexlify)(transactionRequest.toTransactionBytes());
|
7157
7351
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
7158
7352
|
encodedTransactions: encodedTransaction,
|
7159
7353
|
utxoValidation: utxoValidation || false
|
@@ -7177,7 +7371,7 @@ var Provider = class _Provider {
|
|
7177
7371
|
if (!shouldEstimatePredicates) {
|
7178
7372
|
return transactionRequest;
|
7179
7373
|
}
|
7180
|
-
const encodedTransaction = (0,
|
7374
|
+
const encodedTransaction = (0, import_utils32.hexlify)(transactionRequest.toTransactionBytes());
|
7181
7375
|
const response = await this.operations.estimatePredicates({
|
7182
7376
|
encodedTransaction
|
7183
7377
|
});
|
@@ -7209,7 +7403,7 @@ var Provider = class _Provider {
|
|
7209
7403
|
estimatePredicates
|
7210
7404
|
} = await this.operations.estimatePredicatesAndGasPrice({
|
7211
7405
|
blockHorizon: String(blockHorizon),
|
7212
|
-
encodedTransaction: (0,
|
7406
|
+
encodedTransaction: (0, import_utils32.hexlify)(transactionRequest.toTransactionBytes())
|
7213
7407
|
});
|
7214
7408
|
transactionRequest = this.parseEstimatePredicatesResponse(
|
7215
7409
|
transactionRequest,
|
@@ -7247,7 +7441,7 @@ var Provider = class _Provider {
|
|
7247
7441
|
const {
|
7248
7442
|
dryRun: [{ receipts: serializedReceipts, status }]
|
7249
7443
|
} = await this.operations.dryRun({
|
7250
|
-
encodedTransactions: [(0,
|
7444
|
+
encodedTransactions: [(0, import_utils32.hexlify)(transactionRequest.toTransactionBytes())],
|
7251
7445
|
utxoValidation: false,
|
7252
7446
|
gasPrice: gasPrice.toString()
|
7253
7447
|
});
|
@@ -7302,7 +7496,7 @@ var Provider = class _Provider {
|
|
7302
7496
|
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
7303
7497
|
allRequests.forEach((req, index) => {
|
7304
7498
|
if (isTransactionTypeScript(req)) {
|
7305
|
-
serializedTransactionsMap.set(index, (0,
|
7499
|
+
serializedTransactionsMap.set(index, (0, import_utils32.hexlify)(req.toTransactionBytes()));
|
7306
7500
|
}
|
7307
7501
|
});
|
7308
7502
|
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
@@ -7338,7 +7532,7 @@ var Provider = class _Provider {
|
|
7338
7532
|
transactionRequest: request2
|
7339
7533
|
});
|
7340
7534
|
request2.maxFee = maxFee;
|
7341
|
-
serializedTransactionsMap.set(requestIdx, (0,
|
7535
|
+
serializedTransactionsMap.set(requestIdx, (0, import_utils32.hexlify)(request2.toTransactionBytes()));
|
7342
7536
|
nextRoundTransactions.push(requestIdx);
|
7343
7537
|
}
|
7344
7538
|
}
|
@@ -7359,7 +7553,7 @@ var Provider = class _Provider {
|
|
7359
7553
|
if (estimateTxDependencies) {
|
7360
7554
|
return this.estimateMultipleTxDependencies(transactionRequests);
|
7361
7555
|
}
|
7362
|
-
const encodedTransactions = transactionRequests.map((tx) => (0,
|
7556
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils32.hexlify)(tx.toTransactionBytes()));
|
7363
7557
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
7364
7558
|
encodedTransactions,
|
7365
7559
|
utxoValidation: utxoValidation || false
|
@@ -7409,7 +7603,7 @@ var Provider = class _Provider {
|
|
7409
7603
|
const chainInfo = await this.getChain();
|
7410
7604
|
const { gasPriceFactor, maxGasPerTx } = await this.getGasConfig();
|
7411
7605
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
7412
|
-
if (!(0,
|
7606
|
+
if (!(0, import_utils32.isDefined)(gasPrice)) {
|
7413
7607
|
gasPrice = await this.estimateGasPrice(10);
|
7414
7608
|
}
|
7415
7609
|
const minFee = calculateGasFee({
|
@@ -7461,7 +7655,7 @@ var Provider = class _Provider {
|
|
7461
7655
|
if (estimateTxDependencies) {
|
7462
7656
|
return this.estimateTxDependencies(transactionRequest);
|
7463
7657
|
}
|
7464
|
-
const encodedTransactions = [(0,
|
7658
|
+
const encodedTransactions = [(0, import_utils32.hexlify)(transactionRequest.toTransactionBytes())];
|
7465
7659
|
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
7466
7660
|
encodedTransactions,
|
7467
7661
|
utxoValidation: true
|
@@ -7624,7 +7818,7 @@ var Provider = class _Provider {
|
|
7624
7818
|
const {
|
7625
7819
|
assembleTx: { status, transaction: gqlTransaction, gasPrice }
|
7626
7820
|
} = await this.operations.assembleTx({
|
7627
|
-
tx: (0,
|
7821
|
+
tx: (0, import_utils32.hexlify)(request2.toTransactionBytes()),
|
7628
7822
|
blockHorizon: String(blockHorizon),
|
7629
7823
|
feeAddressIndex: String(feePayerIndex),
|
7630
7824
|
requiredBalances,
|
@@ -7676,7 +7870,7 @@ var Provider = class _Provider {
|
|
7676
7870
|
paginationLimit: RESOURCES_PAGE_SIZE_LIMIT,
|
7677
7871
|
inputArgs: paginationArgs
|
7678
7872
|
}),
|
7679
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
7873
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils32.hexlify)(assetId) }
|
7680
7874
|
});
|
7681
7875
|
const coins = edges.map(({ node }) => ({
|
7682
7876
|
id: node.utxoId,
|
@@ -7708,7 +7902,7 @@ var Provider = class _Provider {
|
|
7708
7902
|
const coinsQuery = {
|
7709
7903
|
owner: ownerAddress.toB256(),
|
7710
7904
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
7711
|
-
assetId: (0,
|
7905
|
+
assetId: (0, import_utils32.hexlify)(assetId),
|
7712
7906
|
amount: (amount.eqn(0) ? (0, import_math19.bn)(1) : amount).toString(10),
|
7713
7907
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
7714
7908
|
})),
|
@@ -7866,7 +8060,7 @@ var Provider = class _Provider {
|
|
7866
8060
|
},
|
7867
8061
|
transactionIds: block.transactions.map((tx) => tx.id),
|
7868
8062
|
transactions: block.transactions.map(
|
7869
|
-
(tx) => new import_transactions25.TransactionCoder().decode((0,
|
8063
|
+
(tx) => new import_transactions25.TransactionCoder().decode((0, import_utils32.arrayify)(tx.rawPayload), 0)?.[0]
|
7870
8064
|
)
|
7871
8065
|
};
|
7872
8066
|
}
|
@@ -7883,7 +8077,7 @@ var Provider = class _Provider {
|
|
7883
8077
|
}
|
7884
8078
|
try {
|
7885
8079
|
return new import_transactions25.TransactionCoder().decode(
|
7886
|
-
(0,
|
8080
|
+
(0, import_utils32.arrayify)(transaction.rawPayload),
|
7887
8081
|
0
|
7888
8082
|
)?.[0];
|
7889
8083
|
} catch (error) {
|
@@ -7911,7 +8105,7 @@ var Provider = class _Provider {
|
|
7911
8105
|
const coder = new import_transactions25.TransactionCoder();
|
7912
8106
|
const transactions = edges.map(({ node: { rawPayload } }) => {
|
7913
8107
|
try {
|
7914
|
-
return coder.decode((0,
|
8108
|
+
return coder.decode((0, import_utils32.arrayify)(rawPayload), 0)[0];
|
7915
8109
|
} catch (error) {
|
7916
8110
|
if (error instanceof import_errors20.FuelError && error.code === import_errors20.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
7917
8111
|
console.warn("Unsupported transaction type encountered");
|
@@ -7960,7 +8154,7 @@ var Provider = class _Provider {
|
|
7960
8154
|
async getContractBalance(contractId, assetId) {
|
7961
8155
|
const { contractBalance } = await this.operations.getContractBalance({
|
7962
8156
|
contract: new import_address3.Address(contractId).toB256(),
|
7963
|
-
asset: (0,
|
8157
|
+
asset: (0, import_utils32.hexlify)(assetId)
|
7964
8158
|
});
|
7965
8159
|
return (0, import_math19.bn)(contractBalance.amount, 10);
|
7966
8160
|
}
|
@@ -7974,7 +8168,7 @@ var Provider = class _Provider {
|
|
7974
8168
|
async getBalance(owner, assetId) {
|
7975
8169
|
const { balance } = await this.operations.getBalanceV2({
|
7976
8170
|
owner: new import_address3.Address(owner).toB256(),
|
7977
|
-
assetId: (0,
|
8171
|
+
assetId: (0, import_utils32.hexlify)(assetId)
|
7978
8172
|
});
|
7979
8173
|
return (0, import_math19.bn)(balance.amountU128, 10);
|
7980
8174
|
}
|
@@ -8179,7 +8373,7 @@ var Provider = class _Provider {
|
|
8179
8373
|
async produceBlocks(amount, startTime) {
|
8180
8374
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
8181
8375
|
blocksToProduce: (0, import_math19.bn)(amount).toString(10),
|
8182
|
-
startTimestamp: startTime ?
|
8376
|
+
startTimestamp: startTime ? import_utils32.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
8183
8377
|
});
|
8184
8378
|
return (0, import_math19.bn)(latestBlockHeight);
|
8185
8379
|
}
|
@@ -8231,7 +8425,11 @@ var Provider = class _Provider {
|
|
8231
8425
|
*/
|
8232
8426
|
async getTransactionResponse(transactionId) {
|
8233
8427
|
const chainId = await this.getChainId();
|
8234
|
-
return new TransactionResponse(
|
8428
|
+
return new TransactionResponse({
|
8429
|
+
transactionRequestOrId: transactionId,
|
8430
|
+
provider: this,
|
8431
|
+
chainId
|
8432
|
+
});
|
8235
8433
|
}
|
8236
8434
|
/**
|
8237
8435
|
* Returns Message for given nonce.
|
@@ -8282,18 +8480,21 @@ var Provider = class _Provider {
|
|
8282
8480
|
extractDryRunError(transactionRequest, receipts, reason) {
|
8283
8481
|
let logs = [];
|
8284
8482
|
let groupedLogs = {};
|
8483
|
+
let abis;
|
8285
8484
|
if (transactionRequest.type === import_transactions25.TransactionType.Script && transactionRequest.abis) {
|
8286
8485
|
({ logs, groupedLogs } = getAllDecodedLogs({
|
8287
8486
|
receipts,
|
8288
8487
|
mainAbi: transactionRequest.abis.main,
|
8289
8488
|
externalAbis: transactionRequest.abis.otherContractsAbis
|
8290
8489
|
}));
|
8490
|
+
abis = transactionRequest.abis;
|
8291
8491
|
}
|
8292
8492
|
return extractTxError({
|
8293
8493
|
logs,
|
8294
8494
|
groupedLogs,
|
8295
8495
|
receipts,
|
8296
|
-
statusReason: reason
|
8496
|
+
statusReason: reason,
|
8497
|
+
abis
|
8297
8498
|
});
|
8298
8499
|
}
|
8299
8500
|
/**
|
@@ -8332,8 +8533,8 @@ var Provider = class _Provider {
|
|
8332
8533
|
*/
|
8333
8534
|
async adjustResourcesToIgnoreForAddresses(addresses, resourcesIdsToIgnore) {
|
8334
8535
|
const final = {
|
8335
|
-
messages: resourcesIdsToIgnore?.messages?.map((nonce) => (0,
|
8336
|
-
utxos: resourcesIdsToIgnore?.utxos?.map((id) => (0,
|
8536
|
+
messages: resourcesIdsToIgnore?.messages?.map((nonce) => (0, import_utils32.hexlify)(nonce)) || [],
|
8537
|
+
utxos: resourcesIdsToIgnore?.utxos?.map((id) => (0, import_utils32.hexlify)(id)) || []
|
8337
8538
|
};
|
8338
8539
|
if (this.cache) {
|
8339
8540
|
const cache2 = this.cache;
|
@@ -8365,7 +8566,7 @@ var Provider = class _Provider {
|
|
8365
8566
|
var import_errors21 = require("@fuel-ts/errors");
|
8366
8567
|
var import_math20 = require("@fuel-ts/math");
|
8367
8568
|
var import_transactions26 = require("@fuel-ts/transactions");
|
8368
|
-
var
|
8569
|
+
var import_utils34 = require("@fuel-ts/utils");
|
8369
8570
|
async function getTransactionSummary(params) {
|
8370
8571
|
const { id, provider, abiMap } = params;
|
8371
8572
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -8378,7 +8579,7 @@ async function getTransactionSummary(params) {
|
|
8378
8579
|
);
|
8379
8580
|
}
|
8380
8581
|
const [decodedTransaction] = new import_transactions26.TransactionCoder().decode(
|
8381
|
-
(0,
|
8582
|
+
(0, import_utils34.arrayify)(gqlTransaction.rawPayload),
|
8382
8583
|
0
|
8383
8584
|
);
|
8384
8585
|
let txReceipts = [];
|
@@ -8400,7 +8601,7 @@ async function getTransactionSummary(params) {
|
|
8400
8601
|
id: gqlTransaction.id,
|
8401
8602
|
receipts,
|
8402
8603
|
transaction: decodedTransaction,
|
8403
|
-
transactionBytes: (0,
|
8604
|
+
transactionBytes: (0, import_utils34.arrayify)(gqlTransaction.rawPayload),
|
8404
8605
|
gqlTransactionStatus: gqlTransaction.status,
|
8405
8606
|
gasPerByte: (0, import_math20.bn)(gasPerByte),
|
8406
8607
|
gasPriceFactor: (0, import_math20.bn)(gasPriceFactor),
|
@@ -8466,7 +8667,7 @@ async function getTransactionsSummaries(params) {
|
|
8466
8667
|
const transactions = edges.map((edge) => {
|
8467
8668
|
const { node: gqlTransaction } = edge;
|
8468
8669
|
const { id, rawPayload, status } = gqlTransaction;
|
8469
|
-
const [decodedTransaction] = new import_transactions26.TransactionCoder().decode((0,
|
8670
|
+
const [decodedTransaction] = new import_transactions26.TransactionCoder().decode((0, import_utils34.arrayify)(rawPayload), 0);
|
8470
8671
|
let txReceipts = [];
|
8471
8672
|
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
8472
8673
|
txReceipts = gqlTransaction.status.receipts;
|
@@ -8476,7 +8677,7 @@ async function getTransactionsSummaries(params) {
|
|
8476
8677
|
id,
|
8477
8678
|
receipts,
|
8478
8679
|
transaction: decodedTransaction,
|
8479
|
-
transactionBytes: (0,
|
8680
|
+
transactionBytes: (0, import_utils34.arrayify)(rawPayload),
|
8480
8681
|
gqlTransactionStatus: status,
|
8481
8682
|
abiMap,
|
8482
8683
|
gasPerByte,
|
@@ -8502,7 +8703,7 @@ __name(getTransactionsSummaries, "getTransactionsSummaries");
|
|
8502
8703
|
// src/providers/transaction-summary/assemble-transaction-summary-from-serialized.ts
|
8503
8704
|
var import_math21 = require("@fuel-ts/math");
|
8504
8705
|
var import_transactions27 = require("@fuel-ts/transactions");
|
8505
|
-
var
|
8706
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8506
8707
|
var assembleTransactionSummaryFromJson = /* @__PURE__ */ __name(async (opts) => {
|
8507
8708
|
const { provider, transactionSummary } = opts;
|
8508
8709
|
const { id, transactionBytes, gasPrice, receipts } = transactionSummary;
|
@@ -8514,7 +8715,7 @@ var assembleTransactionSummaryFromJson = /* @__PURE__ */ __name(async (opts) =>
|
|
8514
8715
|
gasCosts
|
8515
8716
|
}
|
8516
8717
|
} = await provider.getChain();
|
8517
|
-
const deserializedTransactionBytes = (0,
|
8718
|
+
const deserializedTransactionBytes = (0, import_utils35.arrayify)(transactionBytes);
|
8518
8719
|
const [transaction] = new import_transactions27.TransactionCoder().decode(deserializedTransactionBytes, 0);
|
8519
8720
|
return assembleTransactionSummary({
|
8520
8721
|
id,
|
@@ -8559,7 +8760,12 @@ var deserializeTransactionResponseJson = /* @__PURE__ */ __name((json) => {
|
|
8559
8760
|
} = json;
|
8560
8761
|
const provider = new Provider(providerUrl, { cache: providerCache });
|
8561
8762
|
const { chainId } = providerCache.chain.consensusParameters;
|
8562
|
-
const response = new TransactionResponse(
|
8763
|
+
const response = new TransactionResponse({
|
8764
|
+
transactionRequestOrId: id,
|
8765
|
+
provider,
|
8766
|
+
chainId: Number(chainId),
|
8767
|
+
abis
|
8768
|
+
});
|
8563
8769
|
if (requestJson) {
|
8564
8770
|
response.request = transactionRequestify(JSON.parse(requestJson));
|
8565
8771
|
}
|
@@ -8576,18 +8782,166 @@ var AbstractAccount = class {
|
|
8576
8782
|
}
|
8577
8783
|
};
|
8578
8784
|
|
8579
|
-
// src/utils/
|
8580
|
-
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
8785
|
+
// src/utils/consolidate-coins.ts
|
8581
8786
|
var import_address4 = require("@fuel-ts/address");
|
8582
|
-
var
|
8787
|
+
var import_errors22 = require("@fuel-ts/errors");
|
8788
|
+
var import_math22 = require("@fuel-ts/math");
|
8789
|
+
var import_transactions28 = require("@fuel-ts/transactions");
|
8790
|
+
var import_ramda9 = require("ramda");
|
8791
|
+
var CONSOLIDATABLE_ERROR_CODES = [import_errors22.ErrorCode.MAX_COINS_REACHED];
|
8792
|
+
var consolidateCoinsIfRequired = /* @__PURE__ */ __name(async (opts) => {
|
8793
|
+
const { error: errorUnknown, account, skipAutoConsolidation = false } = opts;
|
8794
|
+
if (skipAutoConsolidation) {
|
8795
|
+
return false;
|
8796
|
+
}
|
8797
|
+
const error = import_errors22.FuelError.parse(errorUnknown);
|
8798
|
+
if (CONSOLIDATABLE_ERROR_CODES.includes(error.code)) {
|
8799
|
+
const { assetId, owner } = error.metadata;
|
8800
|
+
return account.startConsolidation({
|
8801
|
+
owner,
|
8802
|
+
assetId
|
8803
|
+
});
|
8804
|
+
}
|
8805
|
+
return false;
|
8806
|
+
}, "consolidateCoinsIfRequired");
|
8807
|
+
var getAllCoins = /* @__PURE__ */ __name(async (account, assetId) => {
|
8808
|
+
const all = [];
|
8809
|
+
let hasNextPage = true;
|
8810
|
+
let after;
|
8811
|
+
while (hasNextPage) {
|
8812
|
+
const { coins, pageInfo } = await account.getCoins(assetId, { after });
|
8813
|
+
all.push(...coins);
|
8814
|
+
after = coins.pop()?.id;
|
8815
|
+
hasNextPage = pageInfo.hasNextPage;
|
8816
|
+
}
|
8817
|
+
return { coins: all };
|
8818
|
+
}, "getAllCoins");
|
8819
|
+
var sortCoins = /* @__PURE__ */ __name(({ coins }) => coins.sort((a, b) => b.amount.cmp(a.amount)), "sortCoins");
|
8820
|
+
var createOuputCoin = /* @__PURE__ */ __name((opts) => {
|
8821
|
+
const { transactionId, outputs, baseAssetId } = opts;
|
8822
|
+
const outputChangeIndex = outputs.findIndex(
|
8823
|
+
(output) => output.type === import_transactions28.OutputType.Change && output.assetId === baseAssetId
|
8824
|
+
);
|
8825
|
+
if (outputChangeIndex === -1) {
|
8826
|
+
throw new import_errors22.FuelError(import_errors22.ErrorCode.UNKNOWN, "No change output found");
|
8827
|
+
}
|
8828
|
+
const outputCoin = outputs[outputChangeIndex];
|
8829
|
+
const outputIndexPadded = Number(outputChangeIndex).toString().padStart(4, "0");
|
8830
|
+
return {
|
8831
|
+
id: `${transactionId}${outputIndexPadded}`,
|
8832
|
+
assetId: outputCoin.assetId,
|
8833
|
+
amount: outputCoin.amount,
|
8834
|
+
owner: new import_address4.Address(outputCoin.to),
|
8835
|
+
blockCreated: (0, import_math22.bn)(0),
|
8836
|
+
txCreatedIdx: (0, import_math22.bn)(0)
|
8837
|
+
};
|
8838
|
+
}, "createOuputCoin");
|
8839
|
+
var consolidateCoins = /* @__PURE__ */ __name(async ({
|
8840
|
+
account,
|
8841
|
+
assetId
|
8842
|
+
}) => {
|
8843
|
+
const chainInfo = await account.provider.getChain();
|
8844
|
+
const chainId = chainInfo.consensusParameters.chainId.toNumber();
|
8845
|
+
const gasPrice = await account.provider.estimateGasPrice(10);
|
8846
|
+
const maxInputs = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
|
8847
|
+
const baseAssetId = await account.provider.getBaseAssetId();
|
8848
|
+
const isBaseAsset = assetId === baseAssetId;
|
8849
|
+
const batchSize = maxInputs;
|
8850
|
+
const numberOfFundingCoins = maxInputs;
|
8851
|
+
let funding = [];
|
8852
|
+
let dust = [];
|
8853
|
+
if (isBaseAsset) {
|
8854
|
+
const coins = await getAllCoins(account, baseAssetId).then(sortCoins);
|
8855
|
+
funding = coins.slice(0, numberOfFundingCoins);
|
8856
|
+
dust = coins.slice(numberOfFundingCoins);
|
8857
|
+
} else {
|
8858
|
+
funding = await getAllCoins(account, baseAssetId).then(sortCoins).then((coins) => coins.slice(0, numberOfFundingCoins));
|
8859
|
+
dust = await getAllCoins(account, assetId).then(({ coins }) => coins);
|
8860
|
+
}
|
8861
|
+
if (funding.length === 0) {
|
8862
|
+
throw new import_errors22.FuelError(
|
8863
|
+
import_errors22.ErrorCode.INSUFFICIENT_FUNDS,
|
8864
|
+
`Insufficient funds to consolidate.
|
8865
|
+
Asset ID: ${baseAssetId}
|
8866
|
+
Owner: ${account.address.toB256()}`
|
8867
|
+
);
|
8868
|
+
}
|
8869
|
+
const batches = [
|
8870
|
+
...(0, import_ramda9.splitEvery)(batchSize, funding),
|
8871
|
+
// We leave one coin for the funding coin
|
8872
|
+
...(0, import_ramda9.splitEvery)(batchSize - 1, dust)
|
8873
|
+
];
|
8874
|
+
const txs = batches.map((batch) => {
|
8875
|
+
const request2 = new ScriptTransactionRequest({
|
8876
|
+
scriptData: "0x"
|
8877
|
+
});
|
8878
|
+
request2.addResources(batch);
|
8879
|
+
return request2;
|
8880
|
+
});
|
8881
|
+
const submitAll = /* @__PURE__ */ __name(async (opts = {}) => {
|
8882
|
+
const txResponses = [];
|
8883
|
+
let previousTx;
|
8884
|
+
for (let i = 0; i < txs.length; i++) {
|
8885
|
+
let currentTx = txs[i];
|
8886
|
+
const step = i + 1;
|
8887
|
+
if (previousTx) {
|
8888
|
+
const coin = createOuputCoin({
|
8889
|
+
transactionId: previousTx.transactionId,
|
8890
|
+
outputs: previousTx.outputs,
|
8891
|
+
baseAssetId
|
8892
|
+
});
|
8893
|
+
currentTx.addResource(coin);
|
8894
|
+
}
|
8895
|
+
if ("populateTransactionPredicateData" in account && typeof account.populateTransactionPredicateData === "function") {
|
8896
|
+
currentTx = account.populateTransactionPredicateData(currentTx);
|
8897
|
+
currentTx = await account.provider.estimatePredicates(currentTx);
|
8898
|
+
}
|
8899
|
+
const fee = calculateGasFee({
|
8900
|
+
gasPrice,
|
8901
|
+
gas: currentTx.calculateMinGas(chainInfo),
|
8902
|
+
priceFactor: chainInfo.consensusParameters.feeParameters.gasPriceFactor,
|
8903
|
+
tip: currentTx.tip
|
8904
|
+
});
|
8905
|
+
currentTx.maxFee = fee;
|
8906
|
+
currentTx.gasLimit = (0, import_math22.bn)(1e3);
|
8907
|
+
opts.onTransactionStart?.({
|
8908
|
+
tx: currentTx,
|
8909
|
+
step,
|
8910
|
+
assetId,
|
8911
|
+
transactionId: currentTx.getTransactionId(chainId)
|
8912
|
+
});
|
8913
|
+
const response = await account.sendTransaction(currentTx);
|
8914
|
+
const result = await response.waitForResult();
|
8915
|
+
txResponses.push(result);
|
8916
|
+
previousTx = {
|
8917
|
+
transactionId: response.id,
|
8918
|
+
outputs: result.transaction.outputs
|
8919
|
+
};
|
8920
|
+
}
|
8921
|
+
return {
|
8922
|
+
txResponses,
|
8923
|
+
errors: []
|
8924
|
+
};
|
8925
|
+
}, "submitAll");
|
8926
|
+
return {
|
8927
|
+
txs,
|
8928
|
+
totalFeeCost: txs.reduce((acc, request2) => acc.add(request2.maxFee), (0, import_math22.bn)(0)),
|
8929
|
+
submitAll
|
8930
|
+
};
|
8931
|
+
}, "consolidateCoins");
|
8932
|
+
|
8933
|
+
// src/utils/formatTransferToContractScriptData.ts
|
8934
|
+
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
8935
|
+
var import_address5 = require("@fuel-ts/address");
|
8936
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8583
8937
|
var asm = __toESM(require("@fuels/vm-asm"));
|
8584
8938
|
var formatTransferToContractScriptData = /* @__PURE__ */ __name((transferParams) => {
|
8585
|
-
const numberCoder = new
|
8939
|
+
const numberCoder = new import_abi_coder8.BigNumberCoder("u64");
|
8586
8940
|
return transferParams.reduce((acc, transferParam) => {
|
8587
8941
|
const { assetId, amount, contractId } = transferParam;
|
8588
8942
|
const encoded = numberCoder.encode(amount);
|
8589
|
-
const scriptData = (0,
|
8590
|
-
return (0,
|
8943
|
+
const scriptData = (0, import_utils36.concat)([new import_address5.Address(contractId).toBytes(), encoded, (0, import_utils36.arrayify)(assetId)]);
|
8944
|
+
return (0, import_utils36.concat)([acc, scriptData]);
|
8591
8945
|
}, new Uint8Array());
|
8592
8946
|
}, "formatTransferToContractScriptData");
|
8593
8947
|
var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferParams) => {
|
@@ -8595,24 +8949,24 @@ var assembleTransferToContractScript = /* @__PURE__ */ __name(async (transferPar
|
|
8595
8949
|
await asm.initWasm();
|
8596
8950
|
let script = new Uint8Array();
|
8597
8951
|
transferParams.forEach((_, i) => {
|
8598
|
-
const offset = (
|
8599
|
-
script = (0,
|
8952
|
+
const offset = (import_abi_coder8.CONTRACT_ID_LEN + import_abi_coder8.WORD_SIZE + import_abi_coder8.ASSET_ID_LEN) * i;
|
8953
|
+
script = (0, import_utils36.concat)([
|
8600
8954
|
script,
|
8601
8955
|
// Load ScriptData into register 0x10.
|
8602
8956
|
asm.gtf(16, 0, asm.GTFArgs.ScriptData).to_bytes(),
|
8603
8957
|
// Add the offset to 0x10 so it will point to the current contract ID, store in 0x11.
|
8604
8958
|
asm.addi(17, 16, offset).to_bytes(),
|
8605
8959
|
// Add CONTRACT_ID_LEN to 0x11 to point to the amount in the ScriptData, store in 0x12.
|
8606
|
-
asm.addi(18, 17,
|
8960
|
+
asm.addi(18, 17, import_abi_coder8.CONTRACT_ID_LEN).to_bytes(),
|
8607
8961
|
// Load word to the amount at 0x12 into register 0x13.
|
8608
8962
|
asm.lw(19, 18, 0).to_bytes(),
|
8609
8963
|
// Add WORD_SIZE to 0x12 to point to the asset ID in the ScriptData, store in 0x14.
|
8610
|
-
asm.addi(20, 18,
|
8964
|
+
asm.addi(20, 18, import_abi_coder8.WORD_SIZE).to_bytes(),
|
8611
8965
|
// Perform the transfer using contract ID in 0x11, amount in 0x13, and asset ID in 0x14.
|
8612
8966
|
asm.tr(17, 19, 20).to_bytes()
|
8613
8967
|
]);
|
8614
8968
|
});
|
8615
|
-
script = (0,
|
8969
|
+
script = (0, import_utils36.concat)([script, asm.ret(1).to_bytes()]);
|
8616
8970
|
return { script, scriptData };
|
8617
8971
|
}, "assembleTransferToContractScript");
|
8618
8972
|
|
@@ -8657,7 +9011,7 @@ var Account = class extends AbstractAccount {
|
|
8657
9011
|
super();
|
8658
9012
|
this._provider = provider;
|
8659
9013
|
this._connector = connector;
|
8660
|
-
this.address = new
|
9014
|
+
this.address = new import_address6.Address(address);
|
8661
9015
|
}
|
8662
9016
|
/**
|
8663
9017
|
* The provider used to interact with the network.
|
@@ -8668,7 +9022,7 @@ var Account = class extends AbstractAccount {
|
|
8668
9022
|
*/
|
8669
9023
|
get provider() {
|
8670
9024
|
if (!this._provider) {
|
8671
|
-
throw new
|
9025
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
8672
9026
|
}
|
8673
9027
|
return this._provider;
|
8674
9028
|
}
|
@@ -8695,10 +9049,24 @@ var Account = class extends AbstractAccount {
|
|
8695
9049
|
*
|
8696
9050
|
* @param quantities - Quantities of resources to be obtained.
|
8697
9051
|
* @param resourcesIdsToIgnore - IDs of resources to be excluded from the query (optional).
|
9052
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
8698
9053
|
* @returns A promise that resolves to an array of Resources.
|
8699
9054
|
*/
|
8700
|
-
async getResourcesToSpend(quantities, resourcesIdsToIgnore) {
|
8701
|
-
|
9055
|
+
async getResourcesToSpend(quantities, resourcesIdsToIgnore, { skipAutoConsolidation } = {}) {
|
9056
|
+
const getResourcesToSpend = /* @__PURE__ */ __name(() => this.provider.getResourcesToSpend(this.address, quantities, resourcesIdsToIgnore), "getResourcesToSpend");
|
9057
|
+
try {
|
9058
|
+
return await getResourcesToSpend();
|
9059
|
+
} catch (error) {
|
9060
|
+
const shouldRetry = await consolidateCoinsIfRequired({
|
9061
|
+
error,
|
9062
|
+
account: this,
|
9063
|
+
skipAutoConsolidation
|
9064
|
+
});
|
9065
|
+
if (!shouldRetry) {
|
9066
|
+
throw error;
|
9067
|
+
}
|
9068
|
+
return await getResourcesToSpend();
|
9069
|
+
}
|
8702
9070
|
}
|
8703
9071
|
/**
|
8704
9072
|
* Retrieves coins owned by the account.
|
@@ -8747,7 +9115,7 @@ var Account = class extends AbstractAccount {
|
|
8747
9115
|
* @deprecated Use provider.assembleTx instead
|
8748
9116
|
* Check the migration guide https://docs.fuel.network/docs/fuels-ts/transactions/assemble-tx-migration-guide/ for more information.
|
8749
9117
|
*/
|
8750
|
-
async fund(request2, params) {
|
9118
|
+
async fund(request2, params, { skipAutoConsolidation } = {}) {
|
8751
9119
|
const {
|
8752
9120
|
addedSignatures,
|
8753
9121
|
estimatedPredicates,
|
@@ -8759,9 +9127,9 @@ var Account = class extends AbstractAccount {
|
|
8759
9127
|
const chainId = await this.provider.getChainId();
|
8760
9128
|
const fee = request2.maxFee;
|
8761
9129
|
const baseAssetId = await this.provider.getBaseAssetId();
|
8762
|
-
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0,
|
9130
|
+
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math23.bn)(0);
|
8763
9131
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
8764
|
-
amount: (0,
|
9132
|
+
amount: (0, import_math23.bn)(fee),
|
8765
9133
|
assetId: baseAssetId,
|
8766
9134
|
coinQuantities: requiredQuantities
|
8767
9135
|
});
|
@@ -8769,7 +9137,7 @@ var Account = class extends AbstractAccount {
|
|
8769
9137
|
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
8770
9138
|
quantitiesDict[assetId] = {
|
8771
9139
|
required: amount,
|
8772
|
-
owned: (0,
|
9140
|
+
owned: (0, import_math23.bn)(0)
|
8773
9141
|
};
|
8774
9142
|
});
|
8775
9143
|
request2.inputs.filter(isRequestInputResource).forEach((input) => {
|
@@ -8793,11 +9161,12 @@ var Account = class extends AbstractAccount {
|
|
8793
9161
|
while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
|
8794
9162
|
const resources = await this.getResourcesToSpend(
|
8795
9163
|
missingQuantities,
|
8796
|
-
cacheRequestInputsResourcesFromOwner(request2.inputs, this.address)
|
9164
|
+
cacheRequestInputsResourcesFromOwner(request2.inputs, this.address),
|
9165
|
+
{ skipAutoConsolidation }
|
8797
9166
|
);
|
8798
9167
|
request2.addResources(resources);
|
8799
9168
|
request2.updatePredicateGasUsed(estimatedPredicates);
|
8800
|
-
const requestToReestimate2 = (0,
|
9169
|
+
const requestToReestimate2 = (0, import_ramda10.clone)(request2);
|
8801
9170
|
if (addedSignatures) {
|
8802
9171
|
Array.from({ length: addedSignatures }).forEach(
|
8803
9172
|
() => requestToReestimate2.addEmptyWitness()
|
@@ -8830,15 +9199,15 @@ var Account = class extends AbstractAccount {
|
|
8830
9199
|
fundingAttempts += 1;
|
8831
9200
|
}
|
8832
9201
|
if (needsToBeFunded) {
|
8833
|
-
throw new
|
8834
|
-
|
9202
|
+
throw new import_errors23.FuelError(
|
9203
|
+
import_errors23.ErrorCode.INSUFFICIENT_FUNDS,
|
8835
9204
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
8836
9205
|
);
|
8837
9206
|
}
|
8838
9207
|
request2.updateState(chainId, "funded", transactionSummary);
|
8839
9208
|
await this.provider.validateTransaction(request2);
|
8840
9209
|
request2.updatePredicateGasUsed(estimatedPredicates);
|
8841
|
-
const requestToReestimate = (0,
|
9210
|
+
const requestToReestimate = (0, import_ramda10.clone)(request2);
|
8842
9211
|
if (addedSignatures) {
|
8843
9212
|
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
8844
9213
|
}
|
@@ -8859,16 +9228,20 @@ var Account = class extends AbstractAccount {
|
|
8859
9228
|
* @param amount - The amount of coins to transfer.
|
8860
9229
|
* @param assetId - The asset ID of the coins to transfer (optional).
|
8861
9230
|
* @param txParams - The transaction parameters (optional).
|
9231
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
8862
9232
|
* @returns A promise that resolves to the prepared transaction request.
|
8863
9233
|
*/
|
8864
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
9234
|
+
async createTransfer(destination, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
|
8865
9235
|
let request2 = new ScriptTransactionRequest(txParams);
|
8866
9236
|
request2 = this.addTransfer(request2, {
|
8867
9237
|
destination,
|
8868
9238
|
amount,
|
8869
9239
|
assetId: assetId || await this.provider.getBaseAssetId()
|
8870
9240
|
});
|
8871
|
-
const { gasPrice, transactionRequest } = await this.assembleTx(
|
9241
|
+
const { gasPrice, transactionRequest } = await this.assembleTx({
|
9242
|
+
transactionRequest: request2,
|
9243
|
+
skipAutoConsolidation
|
9244
|
+
});
|
8872
9245
|
request2 = await setAndValidateGasAndFeeForAssembledTx({
|
8873
9246
|
gasPrice,
|
8874
9247
|
provider: this.provider,
|
@@ -8885,10 +9258,13 @@ var Account = class extends AbstractAccount {
|
|
8885
9258
|
* @param amount - The amount of coins to transfer.
|
8886
9259
|
* @param assetId - The asset ID of the coins to transfer (optional).
|
8887
9260
|
* @param txParams - The transaction parameters (optional).
|
9261
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
8888
9262
|
* @returns A promise that resolves to the transaction response.
|
8889
9263
|
*/
|
8890
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
8891
|
-
const request2 = await this.createTransfer(destination, amount, assetId, txParams
|
9264
|
+
async transfer(destination, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
|
9265
|
+
const request2 = await this.createTransfer(destination, amount, assetId, txParams, {
|
9266
|
+
skipAutoConsolidation
|
9267
|
+
});
|
8892
9268
|
return this.sendTransaction(request2, { estimateTxDependencies: false });
|
8893
9269
|
}
|
8894
9270
|
/**
|
@@ -8896,12 +9272,16 @@ var Account = class extends AbstractAccount {
|
|
8896
9272
|
*
|
8897
9273
|
* @param transferParams - An array of `TransferParams` objects representing the transfers to be made.
|
8898
9274
|
* @param txParams - Optional transaction parameters.
|
9275
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
8899
9276
|
* @returns A promise that resolves to a `TransactionResponse` object representing the transaction result.
|
8900
9277
|
*/
|
8901
|
-
async batchTransfer(transferParams, txParams = {}) {
|
9278
|
+
async batchTransfer(transferParams, txParams = {}, { skipAutoConsolidation } = {}) {
|
8902
9279
|
let request2 = new ScriptTransactionRequest(txParams);
|
8903
9280
|
request2 = this.addBatchTransfer(request2, transferParams);
|
8904
|
-
const { gasPrice, transactionRequest } = await this.assembleTx(
|
9281
|
+
const { gasPrice, transactionRequest } = await this.assembleTx({
|
9282
|
+
transactionRequest: request2,
|
9283
|
+
skipAutoConsolidation
|
9284
|
+
});
|
8905
9285
|
request2 = await setAndValidateGasAndFeeForAssembledTx({
|
8906
9286
|
gasPrice,
|
8907
9287
|
provider: this.provider,
|
@@ -8921,7 +9301,7 @@ var Account = class extends AbstractAccount {
|
|
8921
9301
|
addTransfer(request2, transferParams) {
|
8922
9302
|
const { destination, amount, assetId } = transferParams;
|
8923
9303
|
this.validateTransferAmount(amount);
|
8924
|
-
request2.addCoinOutput(new
|
9304
|
+
request2.addCoinOutput(new import_address6.Address(destination), amount, assetId);
|
8925
9305
|
return request2;
|
8926
9306
|
}
|
8927
9307
|
/**
|
@@ -8948,24 +9328,27 @@ var Account = class extends AbstractAccount {
|
|
8948
9328
|
* @param amount - The amount of coins to transfer.
|
8949
9329
|
* @param assetId - The asset ID of the coins to transfer (optional).
|
8950
9330
|
* @param txParams - The transaction parameters (optional).
|
9331
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
8951
9332
|
* @returns A promise that resolves to the transaction response.
|
8952
9333
|
*/
|
8953
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
8954
|
-
return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams
|
9334
|
+
async transferToContract(contractId, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
|
9335
|
+
return this.batchTransferToContracts([{ amount, assetId, contractId }], txParams, {
|
9336
|
+
skipAutoConsolidation
|
9337
|
+
});
|
8955
9338
|
}
|
8956
|
-
async batchTransferToContracts(contractTransferParams, txParams = {}) {
|
9339
|
+
async batchTransferToContracts(contractTransferParams, txParams = {}, { skipAutoConsolidation } = {}) {
|
8957
9340
|
let request2 = new ScriptTransactionRequest({
|
8958
9341
|
...txParams
|
8959
9342
|
});
|
8960
9343
|
const quantities = [];
|
8961
9344
|
const defaultAssetId = await this.provider.getBaseAssetId();
|
8962
9345
|
const transferParams = contractTransferParams.map((transferParam) => {
|
8963
|
-
const amount = (0,
|
8964
|
-
const contractAddress = new
|
8965
|
-
const assetId = transferParam.assetId ? (0,
|
9346
|
+
const amount = (0, import_math23.bn)(transferParam.amount);
|
9347
|
+
const contractAddress = new import_address6.Address(transferParam.contractId);
|
9348
|
+
const assetId = transferParam.assetId ? (0, import_utils37.hexlify)(transferParam.assetId) : defaultAssetId;
|
8966
9349
|
if (amount.lte(0)) {
|
8967
|
-
throw new
|
8968
|
-
|
9350
|
+
throw new import_errors23.FuelError(
|
9351
|
+
import_errors23.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
8969
9352
|
"Transfer amount must be a positive number."
|
8970
9353
|
);
|
8971
9354
|
}
|
@@ -8980,7 +9363,11 @@ var Account = class extends AbstractAccount {
|
|
8980
9363
|
const { script, scriptData } = await assembleTransferToContractScript(transferParams);
|
8981
9364
|
request2.script = script;
|
8982
9365
|
request2.scriptData = scriptData;
|
8983
|
-
const { gasPrice, transactionRequest } = await this.assembleTx(
|
9366
|
+
const { gasPrice, transactionRequest } = await this.assembleTx({
|
9367
|
+
transactionRequest: request2,
|
9368
|
+
quantities,
|
9369
|
+
skipAutoConsolidation
|
9370
|
+
});
|
8984
9371
|
request2 = await setAndValidateGasAndFeeForAssembledTx({
|
8985
9372
|
gasPrice,
|
8986
9373
|
provider: this.provider,
|
@@ -8996,26 +9383,31 @@ var Account = class extends AbstractAccount {
|
|
8996
9383
|
* @param recipient - Address of the recipient on the base chain.
|
8997
9384
|
* @param amount - Amount of base asset.
|
8998
9385
|
* @param txParams - The transaction parameters (optional).
|
9386
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
8999
9387
|
* @returns A promise that resolves to the transaction response.
|
9000
9388
|
*/
|
9001
|
-
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
9002
|
-
const recipientAddress = new
|
9003
|
-
const recipientDataArray = (0,
|
9389
|
+
async withdrawToBaseLayer(recipient, amount, txParams = {}, { skipAutoConsolidation } = {}) {
|
9390
|
+
const recipientAddress = new import_address6.Address(recipient);
|
9391
|
+
const recipientDataArray = (0, import_utils37.arrayify)(
|
9004
9392
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
9005
9393
|
);
|
9006
|
-
const amountDataArray = (0,
|
9007
|
-
"0x".concat((0,
|
9394
|
+
const amountDataArray = (0, import_utils37.arrayify)(
|
9395
|
+
"0x".concat((0, import_math23.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
9008
9396
|
);
|
9009
9397
|
const script = new Uint8Array([
|
9010
|
-
...(0,
|
9398
|
+
...(0, import_utils37.arrayify)(withdrawScript.bytes),
|
9011
9399
|
...recipientDataArray,
|
9012
9400
|
...amountDataArray
|
9013
9401
|
]);
|
9014
9402
|
const params = { script, ...txParams };
|
9015
9403
|
const baseAssetId = await this.provider.getBaseAssetId();
|
9016
9404
|
let request2 = new ScriptTransactionRequest(params);
|
9017
|
-
const quantities = [{ amount: (0,
|
9018
|
-
const { gasPrice, transactionRequest } = await this.assembleTx(
|
9405
|
+
const quantities = [{ amount: (0, import_math23.bn)(amount), assetId: baseAssetId }];
|
9406
|
+
const { gasPrice, transactionRequest } = await this.assembleTx({
|
9407
|
+
transactionRequest: request2,
|
9408
|
+
quantities,
|
9409
|
+
skipAutoConsolidation
|
9410
|
+
});
|
9019
9411
|
request2 = await setAndValidateGasAndFeeForAssembledTx({
|
9020
9412
|
gasPrice,
|
9021
9413
|
provider: this.provider,
|
@@ -9025,6 +9417,25 @@ var Account = class extends AbstractAccount {
|
|
9025
9417
|
});
|
9026
9418
|
return this.sendTransaction(request2);
|
9027
9419
|
}
|
9420
|
+
/**
|
9421
|
+
* Start the consolidation process
|
9422
|
+
*
|
9423
|
+
* @param owner - The B256 address of the owner.
|
9424
|
+
* @param assetId - The asset ID that requires consolidation.
|
9425
|
+
*/
|
9426
|
+
async startConsolidation(opts) {
|
9427
|
+
if (this._connector) {
|
9428
|
+
await this._connector.startConsolidation(opts);
|
9429
|
+
return false;
|
9430
|
+
}
|
9431
|
+
const { owner, assetId } = opts;
|
9432
|
+
if (owner !== this.address.toB256()) {
|
9433
|
+
return false;
|
9434
|
+
}
|
9435
|
+
const { submitAll } = await consolidateCoins({ account: this, assetId });
|
9436
|
+
await submitAll();
|
9437
|
+
return true;
|
9438
|
+
}
|
9028
9439
|
/**
|
9029
9440
|
* Consolidates base asset UTXOs into fewer, larger ones.
|
9030
9441
|
*
|
@@ -9044,6 +9455,7 @@ var Account = class extends AbstractAccount {
|
|
9044
9455
|
const isBaseAsset = baseAssetId === assetId;
|
9045
9456
|
let submitAll;
|
9046
9457
|
const consolidationParams = {
|
9458
|
+
assetId,
|
9047
9459
|
coins,
|
9048
9460
|
mode: params.mode,
|
9049
9461
|
outputNum: params.outputNum
|
@@ -9051,10 +9463,7 @@ var Account = class extends AbstractAccount {
|
|
9051
9463
|
if (isBaseAsset) {
|
9052
9464
|
({ submitAll } = await this.assembleBaseAssetConsolidationTxs(consolidationParams));
|
9053
9465
|
} else {
|
9054
|
-
|
9055
|
-
import_errors22.ErrorCode.UNSUPPORTED_FEATURE,
|
9056
|
-
"Consolidation for non-base assets is not supported yet."
|
9057
|
-
);
|
9466
|
+
({ submitAll } = await this.assembleNonBaseAssetConsolidationTxs(consolidationParams));
|
9058
9467
|
}
|
9059
9468
|
return submitAll();
|
9060
9469
|
}
|
@@ -9075,7 +9484,7 @@ var Account = class extends AbstractAccount {
|
|
9075
9484
|
this.validateConsolidationTxsCoins(coins, baseAssetId);
|
9076
9485
|
const chainInfo = await this.provider.getChain();
|
9077
9486
|
const maxInputsNumber = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
|
9078
|
-
let totalFeeCost = (0,
|
9487
|
+
let totalFeeCost = (0, import_math23.bn)(0);
|
9079
9488
|
const txs = [];
|
9080
9489
|
const coinsBatches = splitCoinsIntoBatches(coins, maxInputsNumber);
|
9081
9490
|
const gasPrice = await this.provider.estimateGasPrice(10);
|
@@ -9099,10 +9508,10 @@ var Account = class extends AbstractAccount {
|
|
9099
9508
|
});
|
9100
9509
|
request2.maxFee = fee;
|
9101
9510
|
if (consolidateMoreThanOneCoin) {
|
9102
|
-
const total = request2.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), (0,
|
9511
|
+
const total = request2.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), (0, import_math23.bn)(0));
|
9103
9512
|
const amountPerNewUtxo = total.div(outputNum + 1);
|
9104
9513
|
request2.outputs.forEach((output) => {
|
9105
|
-
if (output.type ===
|
9514
|
+
if (output.type === import_transactions29.OutputType.Coin) {
|
9106
9515
|
output.amount = amountPerNewUtxo;
|
9107
9516
|
}
|
9108
9517
|
});
|
@@ -9113,6 +9522,70 @@ var Account = class extends AbstractAccount {
|
|
9113
9522
|
const submitAll = this.prepareSubmitAll({ txs, mode });
|
9114
9523
|
return { txs, totalFeeCost, submitAll };
|
9115
9524
|
}
|
9525
|
+
async assembleNonBaseAssetConsolidationTxs(params) {
|
9526
|
+
const { assetId, coins, mode = "parallel", outputNum = 1 } = params;
|
9527
|
+
this.validateConsolidationTxsCoins(coins, assetId);
|
9528
|
+
const chainInfo = await this.provider.getChain();
|
9529
|
+
const maxInputsNumber = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
|
9530
|
+
const baseAssetId = chainInfo.consensusParameters.baseAssetId;
|
9531
|
+
const { coins: baseAssetCoins } = await this.provider.getCoins(this.address, baseAssetId);
|
9532
|
+
let totalFeeCost = (0, import_math23.bn)(0);
|
9533
|
+
const txs = [];
|
9534
|
+
const gasPrice = await this.provider.estimateGasPrice(10);
|
9535
|
+
const consolidateMoreThanOneCoin = outputNum > 1;
|
9536
|
+
const assetCoinBatches = splitCoinsIntoBatches(coins, maxInputsNumber);
|
9537
|
+
assetCoinBatches.filter((batch) => batch.length > 1).forEach((coinBatch) => {
|
9538
|
+
const request2 = new ScriptTransactionRequest({
|
9539
|
+
script: "0x"
|
9540
|
+
});
|
9541
|
+
request2.addResources(coinBatch);
|
9542
|
+
if (consolidateMoreThanOneCoin) {
|
9543
|
+
Array.from({ length: outputNum - 1 }).forEach(() => {
|
9544
|
+
request2.addCoinOutput(this.address, 0, assetId);
|
9545
|
+
});
|
9546
|
+
}
|
9547
|
+
const minGas = request2.calculateMinGas(chainInfo);
|
9548
|
+
const fee = calculateGasFee({
|
9549
|
+
gasPrice,
|
9550
|
+
gas: minGas,
|
9551
|
+
priceFactor: chainInfo.consensusParameters.feeParameters.gasPriceFactor,
|
9552
|
+
tip: request2.tip
|
9553
|
+
});
|
9554
|
+
request2.maxFee = fee;
|
9555
|
+
if (consolidateMoreThanOneCoin) {
|
9556
|
+
const total = request2.inputs.filter(isRequestInputCoin).reduce((acc, input) => acc.add(input.amount), (0, import_math23.bn)(0));
|
9557
|
+
const amountPerNewUtxo = total.div(outputNum + 1);
|
9558
|
+
request2.outputs.forEach((output) => {
|
9559
|
+
if (output.type === import_transactions29.OutputType.Coin) {
|
9560
|
+
output.amount = amountPerNewUtxo;
|
9561
|
+
}
|
9562
|
+
});
|
9563
|
+
}
|
9564
|
+
totalFeeCost = totalFeeCost.add(fee);
|
9565
|
+
const baseAssetResources = [];
|
9566
|
+
let fundingFeeTotal = (0, import_math23.bn)(0);
|
9567
|
+
while (fundingFeeTotal.lt(fee)) {
|
9568
|
+
const baseAssetCoin = baseAssetCoins.pop();
|
9569
|
+
if (!baseAssetCoin) {
|
9570
|
+
break;
|
9571
|
+
}
|
9572
|
+
baseAssetResources.push(baseAssetCoin);
|
9573
|
+
fundingFeeTotal = fundingFeeTotal.add(baseAssetCoin.amount);
|
9574
|
+
}
|
9575
|
+
const { inputs } = request2;
|
9576
|
+
request2.inputs = inputs.slice(0, maxInputsNumber - baseAssetResources.length);
|
9577
|
+
const removedCoins = coinBatch.slice(maxInputsNumber - baseAssetResources.length);
|
9578
|
+
request2.addResources(baseAssetResources);
|
9579
|
+
const lastCoinBatch = assetCoinBatches[assetCoinBatches.length - 1];
|
9580
|
+
lastCoinBatch.push(...removedCoins);
|
9581
|
+
if (lastCoinBatch.length > maxInputsNumber) {
|
9582
|
+
assetCoinBatches.push(lastCoinBatch.slice(maxInputsNumber));
|
9583
|
+
}
|
9584
|
+
txs.push(request2);
|
9585
|
+
});
|
9586
|
+
const submitAll = this.prepareSubmitAll({ txs, mode });
|
9587
|
+
return { txs, totalFeeCost, submitAll };
|
9588
|
+
}
|
9116
9589
|
/**
|
9117
9590
|
* Prepares a function to submit all transactions either sequentially or in parallel.
|
9118
9591
|
*
|
@@ -9167,13 +9640,13 @@ var Account = class extends AbstractAccount {
|
|
9167
9640
|
* Check the migration guide https://docs.fuel.network/docs/fuels-ts/transactions/assemble-tx-migration-guide/ for more information.
|
9168
9641
|
*/
|
9169
9642
|
async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [], gasPrice } = {}) {
|
9170
|
-
const txRequestClone = (0,
|
9643
|
+
const txRequestClone = (0, import_ramda10.clone)(transactionRequestify(transactionRequestLike));
|
9171
9644
|
const baseAssetId = await this.provider.getBaseAssetId();
|
9172
9645
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
9173
9646
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
9174
|
-
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0,
|
9647
|
+
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math23.bn)("100000000000000000") }];
|
9175
9648
|
const findAssetInput = /* @__PURE__ */ __name((assetId) => txRequestClone.inputs.find((input) => {
|
9176
|
-
if (input.type ===
|
9649
|
+
if (input.type === import_transactions29.InputType.Coin) {
|
9177
9650
|
return input.assetId === assetId;
|
9178
9651
|
}
|
9179
9652
|
if (isRequestInputMessageWithoutData(input)) {
|
@@ -9219,7 +9692,7 @@ var Account = class extends AbstractAccount {
|
|
9219
9692
|
*/
|
9220
9693
|
async signMessage(message) {
|
9221
9694
|
if (!this._connector) {
|
9222
|
-
throw new
|
9695
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
9223
9696
|
}
|
9224
9697
|
return this._connector.signMessage(this.address.toString(), message);
|
9225
9698
|
}
|
@@ -9231,8 +9704,8 @@ var Account = class extends AbstractAccount {
|
|
9231
9704
|
*/
|
9232
9705
|
async signTransaction(transactionRequestLike, connectorOptions = {}) {
|
9233
9706
|
if (!this._connector) {
|
9234
|
-
throw new
|
9235
|
-
|
9707
|
+
throw new import_errors23.FuelError(
|
9708
|
+
import_errors23.ErrorCode.MISSING_CONNECTOR,
|
9236
9709
|
"A connector is required to sign transactions."
|
9237
9710
|
);
|
9238
9711
|
}
|
@@ -9297,17 +9770,17 @@ var Account = class extends AbstractAccount {
|
|
9297
9770
|
*/
|
9298
9771
|
generateFakeResources(coins) {
|
9299
9772
|
return coins.map((coin) => ({
|
9300
|
-
id: (0,
|
9773
|
+
id: (0, import_utils37.hexlify)((0, import_crypto2.randomBytes)(import_abi_coder9.UTXO_ID_LEN)),
|
9301
9774
|
owner: this.address,
|
9302
|
-
blockCreated: (0,
|
9303
|
-
txCreatedIdx: (0,
|
9775
|
+
blockCreated: (0, import_math23.bn)(1),
|
9776
|
+
txCreatedIdx: (0, import_math23.bn)(1),
|
9304
9777
|
...coin
|
9305
9778
|
}));
|
9306
9779
|
}
|
9307
9780
|
/** @hidden */
|
9308
9781
|
async prepareTransactionForSend(request2) {
|
9309
9782
|
const { transactionId } = request2.flag;
|
9310
|
-
if (!(0,
|
9783
|
+
if (!(0, import_utils37.isDefined)(transactionId)) {
|
9311
9784
|
return request2;
|
9312
9785
|
}
|
9313
9786
|
const chainId = await this.provider.getChainId();
|
@@ -9320,80 +9793,57 @@ var Account = class extends AbstractAccount {
|
|
9320
9793
|
/** @hidden */
|
9321
9794
|
async prepareTransactionSummary(request2) {
|
9322
9795
|
const chainId = await this.provider.getChainId();
|
9323
|
-
return (0,
|
9796
|
+
return (0, import_utils37.isDefined)(request2.flag.summary) ? {
|
9324
9797
|
...request2.flag.summary,
|
9325
9798
|
id: request2.getTransactionId(chainId),
|
9326
|
-
transactionBytes: (0,
|
9799
|
+
transactionBytes: (0, import_utils37.hexlify)(request2.toTransactionBytes())
|
9327
9800
|
} : void 0;
|
9328
9801
|
}
|
9329
9802
|
/** @hidden * */
|
9330
|
-
async assembleTx(
|
9331
|
-
const
|
9332
|
-
transactionRequest.
|
9333
|
-
transactionRequest.
|
9334
|
-
|
9335
|
-
|
9336
|
-
|
9337
|
-
|
9338
|
-
|
9339
|
-
|
9803
|
+
async assembleTx(opts) {
|
9804
|
+
const { transactionRequest, quantities = [], skipAutoConsolidation } = opts;
|
9805
|
+
const outputQuantities = transactionRequest.outputs.filter((o) => o.type === import_transactions29.OutputType.Coin).map(({ amount, assetId }) => ({ assetId: String(assetId), amount: (0, import_math23.bn)(amount) }));
|
9806
|
+
transactionRequest.gasLimit = (0, import_math23.bn)(0);
|
9807
|
+
transactionRequest.maxFee = (0, import_math23.bn)(0);
|
9808
|
+
const assembleTx = /* @__PURE__ */ __name(async () => {
|
9809
|
+
const { assembledRequest, gasPrice } = await this.provider.assembleTx({
|
9810
|
+
request: transactionRequest,
|
9811
|
+
accountCoinQuantities: mergeQuantities(outputQuantities, quantities),
|
9812
|
+
feePayerAccount: this
|
9813
|
+
});
|
9814
|
+
return { transactionRequest: assembledRequest, gasPrice };
|
9815
|
+
}, "assembleTx");
|
9816
|
+
try {
|
9817
|
+
return await assembleTx();
|
9818
|
+
} catch (error) {
|
9819
|
+
const shouldRetry = await consolidateCoinsIfRequired({
|
9820
|
+
error,
|
9821
|
+
account: this,
|
9822
|
+
skipAutoConsolidation
|
9823
|
+
});
|
9824
|
+
if (!shouldRetry) {
|
9825
|
+
throw error;
|
9826
|
+
}
|
9827
|
+
return await assembleTx();
|
9828
|
+
}
|
9340
9829
|
}
|
9341
9830
|
/** @hidden * */
|
9342
9831
|
validateTransferAmount(amount) {
|
9343
|
-
if ((0,
|
9344
|
-
throw new
|
9345
|
-
|
9832
|
+
if ((0, import_math23.bn)(amount).lte(0)) {
|
9833
|
+
throw new import_errors23.FuelError(
|
9834
|
+
import_errors23.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
9346
9835
|
"Transfer amount must be a positive number."
|
9347
9836
|
);
|
9348
9837
|
}
|
9349
9838
|
}
|
9350
9839
|
/** @hidden * */
|
9351
|
-
async estimateAndFundTransaction(transactionRequest, txParams, costParams) {
|
9352
|
-
let request2 = transactionRequest;
|
9353
|
-
const txCost = await this.getTransactionCost(request2, costParams);
|
9354
|
-
request2 = this.validateGasLimitAndMaxFee({
|
9355
|
-
transactionRequest: request2,
|
9356
|
-
gasUsed: txCost.gasUsed,
|
9357
|
-
maxFee: txCost.maxFee,
|
9358
|
-
txParams
|
9359
|
-
});
|
9360
|
-
request2 = await this.fund(request2, txCost);
|
9361
|
-
return request2;
|
9362
|
-
}
|
9363
|
-
/** @hidden * */
|
9364
|
-
validateGasLimitAndMaxFee({
|
9365
|
-
gasUsed,
|
9366
|
-
maxFee,
|
9367
|
-
transactionRequest,
|
9368
|
-
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
|
9369
|
-
}) {
|
9370
|
-
const request2 = transactionRequestify(transactionRequest);
|
9371
|
-
if (!(0, import_utils36.isDefined)(setGasLimit)) {
|
9372
|
-
request2.gasLimit = gasUsed;
|
9373
|
-
} else if (gasUsed.gt(setGasLimit)) {
|
9374
|
-
throw new import_errors22.FuelError(
|
9375
|
-
import_errors22.ErrorCode.GAS_LIMIT_TOO_LOW,
|
9376
|
-
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
9377
|
-
);
|
9378
|
-
}
|
9379
|
-
if (!(0, import_utils36.isDefined)(setMaxFee)) {
|
9380
|
-
request2.maxFee = maxFee;
|
9381
|
-
} else if (maxFee.gt(setMaxFee)) {
|
9382
|
-
throw new import_errors22.FuelError(
|
9383
|
-
import_errors22.ErrorCode.MAX_FEE_TOO_LOW,
|
9384
|
-
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
9385
|
-
);
|
9386
|
-
}
|
9387
|
-
return request2;
|
9388
|
-
}
|
9389
|
-
/** @hidden * */
|
9390
9840
|
validateConsolidationTxsCoins(coins, assetId) {
|
9391
9841
|
if (coins.length <= 1) {
|
9392
|
-
throw new
|
9842
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NO_COINS_TO_CONSOLIDATE, "No coins to consolidate.");
|
9393
9843
|
}
|
9394
9844
|
if (!coins.every((c) => c.assetId === assetId)) {
|
9395
|
-
throw new
|
9396
|
-
|
9845
|
+
throw new import_errors23.FuelError(
|
9846
|
+
import_errors23.ErrorCode.COINS_ASSET_ID_MISMATCH,
|
9397
9847
|
"All coins to consolidate must be from the same asset id."
|
9398
9848
|
);
|
9399
9849
|
}
|
@@ -9419,14 +9869,14 @@ var Account = class extends AbstractAccount {
|
|
9419
9869
|
|
9420
9870
|
// src/wallet/base-wallet-unlocked.ts
|
9421
9871
|
var import_hasher4 = require("@fuel-ts/hasher");
|
9422
|
-
var
|
9872
|
+
var import_utils40 = require("@fuel-ts/utils");
|
9423
9873
|
|
9424
9874
|
// src/signer/signer.ts
|
9425
|
-
var
|
9875
|
+
var import_address7 = require("@fuel-ts/address");
|
9426
9876
|
var import_crypto3 = require("@fuel-ts/crypto");
|
9427
9877
|
var import_hasher3 = require("@fuel-ts/hasher");
|
9428
|
-
var
|
9429
|
-
var
|
9878
|
+
var import_math24 = require("@fuel-ts/math");
|
9879
|
+
var import_utils38 = require("@fuel-ts/utils");
|
9430
9880
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
9431
9881
|
var Signer = class _Signer {
|
9432
9882
|
static {
|
@@ -9448,11 +9898,11 @@ var Signer = class _Signer {
|
|
9448
9898
|
privateKey = `0x${privateKey}`;
|
9449
9899
|
}
|
9450
9900
|
}
|
9451
|
-
const privateKeyBytes = (0,
|
9452
|
-
this.privateKey = (0,
|
9453
|
-
this.publicKey = (0,
|
9454
|
-
this.compressedPublicKey = (0,
|
9455
|
-
this.address = new
|
9901
|
+
const privateKeyBytes = (0, import_math24.toBytes)(privateKey, 32);
|
9902
|
+
this.privateKey = (0, import_utils38.hexlify)(privateKeyBytes);
|
9903
|
+
this.publicKey = (0, import_utils38.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
9904
|
+
this.compressedPublicKey = (0, import_utils38.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
9905
|
+
this.address = new import_address7.Address(this.publicKey);
|
9456
9906
|
}
|
9457
9907
|
/**
|
9458
9908
|
* Sign data using the Signer instance
|
@@ -9465,11 +9915,11 @@ var Signer = class _Signer {
|
|
9465
9915
|
* @returns hashed signature
|
9466
9916
|
*/
|
9467
9917
|
sign(data) {
|
9468
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
9469
|
-
const r = (0,
|
9470
|
-
const s = (0,
|
9918
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils38.arrayify)(data), (0, import_utils38.arrayify)(this.privateKey));
|
9919
|
+
const r = (0, import_math24.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
9920
|
+
const s = (0, import_math24.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
9471
9921
|
s[0] |= (signature.recovery || 0) << 7;
|
9472
|
-
return (0,
|
9922
|
+
return (0, import_utils38.hexlify)((0, import_utils38.concat)([r, s]));
|
9473
9923
|
}
|
9474
9924
|
/**
|
9475
9925
|
* Add point on the current elliptic curve
|
@@ -9478,8 +9928,8 @@ var Signer = class _Signer {
|
|
9478
9928
|
* @returns compressed point on the curve
|
9479
9929
|
*/
|
9480
9930
|
addPoint(point) {
|
9481
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
9482
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
9931
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils38.arrayify)(this.compressedPublicKey));
|
9932
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils38.arrayify)(point));
|
9483
9933
|
const result = p0.add(p1);
|
9484
9934
|
return `0x${result.toHex(true)}`;
|
9485
9935
|
}
|
@@ -9491,16 +9941,16 @@ var Signer = class _Signer {
|
|
9491
9941
|
* @returns public key from signature from the
|
9492
9942
|
*/
|
9493
9943
|
static recoverPublicKey(data, signature) {
|
9494
|
-
const signedMessageBytes = (0,
|
9944
|
+
const signedMessageBytes = (0, import_utils38.arrayify)(signature);
|
9495
9945
|
const r = signedMessageBytes.slice(0, 32);
|
9496
9946
|
const s = signedMessageBytes.slice(32, 64);
|
9497
9947
|
const recoveryParam = (s[0] & 128) >> 7;
|
9498
9948
|
s[0] &= 127;
|
9499
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
9949
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils38.hexlify)(r)), BigInt((0, import_utils38.hexlify)(s))).addRecoveryBit(
|
9500
9950
|
recoveryParam
|
9501
9951
|
);
|
9502
|
-
const publicKey = sig.recoverPublicKey((0,
|
9503
|
-
return (0,
|
9952
|
+
const publicKey = sig.recoverPublicKey((0, import_utils38.arrayify)(data)).toRawBytes(false).slice(1);
|
9953
|
+
return (0, import_utils38.hexlify)(publicKey);
|
9504
9954
|
}
|
9505
9955
|
/**
|
9506
9956
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -9510,7 +9960,7 @@ var Signer = class _Signer {
|
|
9510
9960
|
* @returns Address from signature
|
9511
9961
|
*/
|
9512
9962
|
static recoverAddress(data, signature) {
|
9513
|
-
return new
|
9963
|
+
return new import_address7.Address(_Signer.recoverPublicKey(data, signature));
|
9514
9964
|
}
|
9515
9965
|
/**
|
9516
9966
|
* Generate a random privateKey
|
@@ -9519,7 +9969,7 @@ var Signer = class _Signer {
|
|
9519
9969
|
* @returns random 32-byte hashed
|
9520
9970
|
*/
|
9521
9971
|
static generatePrivateKey(entropy) {
|
9522
|
-
return entropy ? (0, import_hasher3.hash)((0,
|
9972
|
+
return entropy ? (0, import_hasher3.hash)((0, import_utils38.concat)([(0, import_crypto3.randomBytes)(32), (0, import_utils38.arrayify)(entropy)])) : (0, import_crypto3.randomBytes)(32);
|
9523
9973
|
}
|
9524
9974
|
/**
|
9525
9975
|
* Extended publicKey from a compact publicKey
|
@@ -9528,16 +9978,16 @@ var Signer = class _Signer {
|
|
9528
9978
|
* @returns extended publicKey
|
9529
9979
|
*/
|
9530
9980
|
static extendPublicKey(publicKey) {
|
9531
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
9532
|
-
return (0,
|
9981
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils38.arrayify)(publicKey));
|
9982
|
+
return (0, import_utils38.hexlify)(point.toRawBytes(false).slice(1));
|
9533
9983
|
}
|
9534
9984
|
};
|
9535
9985
|
|
9536
9986
|
// src/wallet/keystore-wallet.ts
|
9537
|
-
var
|
9987
|
+
var import_address8 = require("@fuel-ts/address");
|
9538
9988
|
var import_crypto4 = require("@fuel-ts/crypto");
|
9539
|
-
var
|
9540
|
-
var
|
9989
|
+
var import_errors24 = require("@fuel-ts/errors");
|
9990
|
+
var import_utils39 = require("@fuel-ts/utils");
|
9541
9991
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
9542
9992
|
var DEFAULT_KDF_PARAMS_R = 8;
|
9543
9993
|
var DEFAULT_KDF_PARAMS_P = 1;
|
@@ -9551,7 +10001,7 @@ var removeHexPrefix = /* @__PURE__ */ __name((hexString) => {
|
|
9551
10001
|
}, "removeHexPrefix");
|
9552
10002
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
9553
10003
|
const privateKeyBuffer = (0, import_crypto4.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
9554
|
-
const ownerAddress = new
|
10004
|
+
const ownerAddress = new import_address8.Address(address);
|
9555
10005
|
const salt = (0, import_crypto4.randomBytes)(DEFAULT_KEY_SIZE);
|
9556
10006
|
const key = (0, import_crypto4.scrypt)({
|
9557
10007
|
password: (0, import_crypto4.bufferFromString)(password),
|
@@ -9614,13 +10064,13 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
9614
10064
|
const macHashUint8Array = (0, import_crypto4.keccak256)(data);
|
9615
10065
|
const macHash = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
|
9616
10066
|
if (mac !== macHash) {
|
9617
|
-
throw new
|
9618
|
-
|
10067
|
+
throw new import_errors24.FuelError(
|
10068
|
+
import_errors24.ErrorCode.INVALID_PASSWORD,
|
9619
10069
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
9620
10070
|
);
|
9621
10071
|
}
|
9622
10072
|
const buffer = await (0, import_crypto4.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
9623
|
-
const privateKey = (0,
|
10073
|
+
const privateKey = (0, import_utils39.hexlify)(buffer);
|
9624
10074
|
return privateKey;
|
9625
10075
|
}
|
9626
10076
|
__name(decryptKeystoreWallet, "decryptKeystoreWallet");
|
@@ -9673,7 +10123,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
9673
10123
|
*/
|
9674
10124
|
async signMessage(message) {
|
9675
10125
|
const signedMessage = await this.signer().sign((0, import_hasher4.hashMessage)(message));
|
9676
|
-
return (0,
|
10126
|
+
return (0, import_utils40.hexlify)(signedMessage);
|
9677
10127
|
}
|
9678
10128
|
/**
|
9679
10129
|
* Signs a transaction with the wallet's private key.
|
@@ -9686,7 +10136,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
9686
10136
|
const chainId = await this.provider.getChainId();
|
9687
10137
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
9688
10138
|
const signature = await this.signer().sign(hashedTransaction);
|
9689
|
-
return (0,
|
10139
|
+
return (0, import_utils40.hexlify)(signature);
|
9690
10140
|
}
|
9691
10141
|
/**
|
9692
10142
|
* Populates a transaction with the witnesses signature.
|
@@ -9754,16 +10204,16 @@ var BaseWalletUnlocked = class extends Account {
|
|
9754
10204
|
|
9755
10205
|
// src/hdwallet/hdwallet.ts
|
9756
10206
|
var import_crypto6 = require("@fuel-ts/crypto");
|
9757
|
-
var
|
10207
|
+
var import_errors27 = require("@fuel-ts/errors");
|
9758
10208
|
var import_hasher7 = require("@fuel-ts/hasher");
|
9759
|
-
var
|
9760
|
-
var
|
10209
|
+
var import_math25 = require("@fuel-ts/math");
|
10210
|
+
var import_utils44 = require("@fuel-ts/utils");
|
9761
10211
|
|
9762
10212
|
// src/mnemonic/mnemonic.ts
|
9763
10213
|
var import_crypto5 = require("@fuel-ts/crypto");
|
9764
|
-
var
|
10214
|
+
var import_errors26 = require("@fuel-ts/errors");
|
9765
10215
|
var import_hasher6 = require("@fuel-ts/hasher");
|
9766
|
-
var
|
10216
|
+
var import_utils42 = require("@fuel-ts/utils");
|
9767
10217
|
|
9768
10218
|
// src/wordlists/words/english.ts
|
9769
10219
|
var english = [
|
@@ -11824,9 +12274,9 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
11824
12274
|
})(Language || {});
|
11825
12275
|
|
11826
12276
|
// src/mnemonic/utils.ts
|
11827
|
-
var
|
12277
|
+
var import_errors25 = require("@fuel-ts/errors");
|
11828
12278
|
var import_hasher5 = require("@fuel-ts/hasher");
|
11829
|
-
var
|
12279
|
+
var import_utils41 = require("@fuel-ts/utils");
|
11830
12280
|
function getLowerMask(bits) {
|
11831
12281
|
return (1 << bits) - 1;
|
11832
12282
|
}
|
@@ -11865,7 +12315,7 @@ function entropyToMnemonicIndices(entropy) {
|
|
11865
12315
|
}
|
11866
12316
|
}
|
11867
12317
|
const checksumBits = entropy.length / 4;
|
11868
|
-
const checksum = (0,
|
12318
|
+
const checksum = (0, import_utils41.arrayify)((0, import_hasher5.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
11869
12319
|
indices[indices.length - 1] <<= checksumBits;
|
11870
12320
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
11871
12321
|
return indices;
|
@@ -11873,13 +12323,13 @@ function entropyToMnemonicIndices(entropy) {
|
|
11873
12323
|
__name(entropyToMnemonicIndices, "entropyToMnemonicIndices");
|
11874
12324
|
function mnemonicWordsToEntropy(words, wordlist) {
|
11875
12325
|
const size = Math.ceil(11 * words.length / 8);
|
11876
|
-
const entropy = (0,
|
12326
|
+
const entropy = (0, import_utils41.arrayify)(new Uint8Array(size));
|
11877
12327
|
let offset = 0;
|
11878
12328
|
for (let i = 0; i < words.length; i += 1) {
|
11879
12329
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
11880
12330
|
if (index === -1) {
|
11881
|
-
throw new
|
11882
|
-
|
12331
|
+
throw new import_errors25.FuelError(
|
12332
|
+
import_errors25.ErrorCode.INVALID_MNEMONIC,
|
11883
12333
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
11884
12334
|
);
|
11885
12335
|
}
|
@@ -11893,10 +12343,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
11893
12343
|
const entropyBits = 32 * words.length / 3;
|
11894
12344
|
const checksumBits = words.length / 3;
|
11895
12345
|
const checksumMask = getUpperMask(checksumBits);
|
11896
|
-
const checksum = (0,
|
12346
|
+
const checksum = (0, import_utils41.arrayify)((0, import_hasher5.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
11897
12347
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
11898
|
-
throw new
|
11899
|
-
|
12348
|
+
throw new import_errors25.FuelError(
|
12349
|
+
import_errors25.ErrorCode.INVALID_CHECKSUM,
|
11900
12350
|
"Checksum validation failed for the provided mnemonic."
|
11901
12351
|
);
|
11902
12352
|
}
|
@@ -11905,14 +12355,14 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
11905
12355
|
__name(mnemonicWordsToEntropy, "mnemonicWordsToEntropy");
|
11906
12356
|
|
11907
12357
|
// src/mnemonic/mnemonic.ts
|
11908
|
-
var MasterSecret = (0,
|
12358
|
+
var MasterSecret = (0, import_utils42.toUtf8Bytes)("Bitcoin seed");
|
11909
12359
|
var MainnetPRV = "0x0488ade4";
|
11910
12360
|
var TestnetPRV = "0x04358394";
|
11911
12361
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
11912
12362
|
function assertWordList(wordlist) {
|
11913
12363
|
if (wordlist.length !== 2048) {
|
11914
|
-
throw new
|
11915
|
-
|
12364
|
+
throw new import_errors26.FuelError(
|
12365
|
+
import_errors26.ErrorCode.INVALID_WORD_LIST,
|
11916
12366
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
11917
12367
|
);
|
11918
12368
|
}
|
@@ -11920,8 +12370,8 @@ function assertWordList(wordlist) {
|
|
11920
12370
|
__name(assertWordList, "assertWordList");
|
11921
12371
|
function assertEntropy(entropy) {
|
11922
12372
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
11923
|
-
throw new
|
11924
|
-
|
12373
|
+
throw new import_errors26.FuelError(
|
12374
|
+
import_errors26.ErrorCode.INVALID_ENTROPY,
|
11925
12375
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
11926
12376
|
);
|
11927
12377
|
}
|
@@ -11932,7 +12382,7 @@ function assertMnemonic(words) {
|
|
11932
12382
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
11933
12383
|
", "
|
11934
12384
|
)}] words, but got ${words.length}.`;
|
11935
|
-
throw new
|
12385
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
11936
12386
|
}
|
11937
12387
|
}
|
11938
12388
|
__name(assertMnemonic, "assertMnemonic");
|
@@ -11975,7 +12425,7 @@ var Mnemonic = class _Mnemonic {
|
|
11975
12425
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
11976
12426
|
const words = getWords(phrase);
|
11977
12427
|
assertMnemonic(words);
|
11978
|
-
return (0,
|
12428
|
+
return (0, import_utils42.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
11979
12429
|
}
|
11980
12430
|
/**
|
11981
12431
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -11983,7 +12433,7 @@ var Mnemonic = class _Mnemonic {
|
|
11983
12433
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
11984
12434
|
*/
|
11985
12435
|
static entropyToMnemonic(entropy, wordlist = english) {
|
11986
|
-
const entropyBytes = (0,
|
12436
|
+
const entropyBytes = (0, import_utils42.arrayify)(entropy);
|
11987
12437
|
assertWordList(wordlist);
|
11988
12438
|
assertEntropy(entropyBytes);
|
11989
12439
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -11995,8 +12445,8 @@ var Mnemonic = class _Mnemonic {
|
|
11995
12445
|
*/
|
11996
12446
|
static mnemonicToSeed(phrase, passphrase = "") {
|
11997
12447
|
assertMnemonic(getWords(phrase));
|
11998
|
-
const phraseBytes = (0,
|
11999
|
-
const salt = (0,
|
12448
|
+
const phraseBytes = (0, import_utils42.toUtf8Bytes)(getPhrase(phrase));
|
12449
|
+
const salt = (0, import_utils42.toUtf8Bytes)(`mnemonic${passphrase}`);
|
12000
12450
|
return (0, import_crypto5.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
12001
12451
|
}
|
12002
12452
|
/**
|
@@ -12052,14 +12502,14 @@ var Mnemonic = class _Mnemonic {
|
|
12052
12502
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
12053
12503
|
*/
|
12054
12504
|
static masterKeysFromSeed(seed) {
|
12055
|
-
const seedArray = (0,
|
12505
|
+
const seedArray = (0, import_utils42.arrayify)(seed);
|
12056
12506
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
12057
|
-
throw new
|
12058
|
-
|
12507
|
+
throw new import_errors26.FuelError(
|
12508
|
+
import_errors26.ErrorCode.INVALID_SEED,
|
12059
12509
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
12060
12510
|
);
|
12061
12511
|
}
|
12062
|
-
return (0,
|
12512
|
+
return (0, import_utils42.arrayify)((0, import_crypto5.computeHmac)("sha512", MasterSecret, seedArray));
|
12063
12513
|
}
|
12064
12514
|
/**
|
12065
12515
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -12070,22 +12520,22 @@ var Mnemonic = class _Mnemonic {
|
|
12070
12520
|
*/
|
12071
12521
|
static seedToExtendedKey(seed, testnet = false) {
|
12072
12522
|
const masterKey = _Mnemonic.masterKeysFromSeed(seed);
|
12073
|
-
const prefix = (0,
|
12523
|
+
const prefix = (0, import_utils42.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
12074
12524
|
const depth = "0x00";
|
12075
12525
|
const fingerprint = "0x00000000";
|
12076
12526
|
const index = "0x00000000";
|
12077
12527
|
const chainCode = masterKey.slice(32);
|
12078
12528
|
const privateKey = masterKey.slice(0, 32);
|
12079
|
-
const extendedKey = (0,
|
12529
|
+
const extendedKey = (0, import_utils42.concat)([
|
12080
12530
|
prefix,
|
12081
12531
|
depth,
|
12082
12532
|
fingerprint,
|
12083
12533
|
index,
|
12084
12534
|
chainCode,
|
12085
|
-
(0,
|
12535
|
+
(0, import_utils42.concat)(["0x00", privateKey])
|
12086
12536
|
]);
|
12087
|
-
const checksum = (0,
|
12088
|
-
return (0,
|
12537
|
+
const checksum = (0, import_utils42.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(extendedKey)), 0, 4);
|
12538
|
+
return (0, import_utils42.encodeBase58)((0, import_utils42.concat)([extendedKey, checksum]));
|
12089
12539
|
}
|
12090
12540
|
/**
|
12091
12541
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -12100,7 +12550,7 @@ var Mnemonic = class _Mnemonic {
|
|
12100
12550
|
* @returns A randomly generated mnemonic
|
12101
12551
|
*/
|
12102
12552
|
static generate(size = 32, extraEntropy = "") {
|
12103
|
-
const entropy = extraEntropy ? (0, import_hasher6.sha256)((0,
|
12553
|
+
const entropy = extraEntropy ? (0, import_hasher6.sha256)((0, import_utils42.concat)([(0, import_crypto5.randomBytes)(size), (0, import_utils42.arrayify)(extraEntropy)])) : (0, import_crypto5.randomBytes)(size);
|
12104
12554
|
return _Mnemonic.entropyToMnemonic(entropy);
|
12105
12555
|
}
|
12106
12556
|
};
|
@@ -12108,12 +12558,12 @@ var mnemonic_default = Mnemonic;
|
|
12108
12558
|
|
12109
12559
|
// src/hdwallet/hdwallet.ts
|
12110
12560
|
var HARDENED_INDEX = 2147483648;
|
12111
|
-
var MainnetPRV2 = (0,
|
12112
|
-
var MainnetPUB = (0,
|
12113
|
-
var TestnetPRV2 = (0,
|
12114
|
-
var TestnetPUB = (0,
|
12561
|
+
var MainnetPRV2 = (0, import_utils44.hexlify)("0x0488ade4");
|
12562
|
+
var MainnetPUB = (0, import_utils44.hexlify)("0x0488b21e");
|
12563
|
+
var TestnetPRV2 = (0, import_utils44.hexlify)("0x04358394");
|
12564
|
+
var TestnetPUB = (0, import_utils44.hexlify)("0x043587cf");
|
12115
12565
|
function base58check(data) {
|
12116
|
-
return (0,
|
12566
|
+
return (0, import_utils44.encodeBase58)((0, import_utils44.concat)([data, (0, import_utils44.dataSlice)((0, import_hasher7.sha256)((0, import_hasher7.sha256)(data)), 0, 4)]));
|
12117
12567
|
}
|
12118
12568
|
__name(base58check, "base58check");
|
12119
12569
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
@@ -12124,19 +12574,19 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
12124
12574
|
}
|
12125
12575
|
__name(getExtendedKeyPrefix, "getExtendedKeyPrefix");
|
12126
12576
|
function isPublicExtendedKey(extendedKey) {
|
12127
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
12577
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils44.hexlify)(extendedKey.slice(0, 4)));
|
12128
12578
|
}
|
12129
12579
|
__name(isPublicExtendedKey, "isPublicExtendedKey");
|
12130
12580
|
function isValidExtendedKey(extendedKey) {
|
12131
12581
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
12132
|
-
(0,
|
12582
|
+
(0, import_utils44.hexlify)(extendedKey.slice(0, 4))
|
12133
12583
|
);
|
12134
12584
|
}
|
12135
12585
|
__name(isValidExtendedKey, "isValidExtendedKey");
|
12136
12586
|
function parsePath(path, depth = 0) {
|
12137
12587
|
const components = path.split("/");
|
12138
12588
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
12139
|
-
throw new
|
12589
|
+
throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path}`);
|
12140
12590
|
}
|
12141
12591
|
if (components[0] === "m") {
|
12142
12592
|
components.shift();
|
@@ -12152,8 +12602,8 @@ var HDWallet = class _HDWallet {
|
|
12152
12602
|
}
|
12153
12603
|
depth = 0;
|
12154
12604
|
index = 0;
|
12155
|
-
fingerprint = (0,
|
12156
|
-
parentFingerprint = (0,
|
12605
|
+
fingerprint = (0, import_utils44.hexlify)("0x00000000");
|
12606
|
+
parentFingerprint = (0, import_utils44.hexlify)("0x00000000");
|
12157
12607
|
privateKey;
|
12158
12608
|
publicKey;
|
12159
12609
|
chainCode;
|
@@ -12165,19 +12615,19 @@ var HDWallet = class _HDWallet {
|
|
12165
12615
|
constructor(config) {
|
12166
12616
|
if (config.privateKey) {
|
12167
12617
|
const signer = new Signer(config.privateKey);
|
12168
|
-
this.publicKey = (0,
|
12169
|
-
this.privateKey = (0,
|
12618
|
+
this.publicKey = (0, import_utils44.hexlify)(signer.compressedPublicKey);
|
12619
|
+
this.privateKey = (0, import_utils44.hexlify)(config.privateKey);
|
12170
12620
|
} else {
|
12171
12621
|
if (!config.publicKey) {
|
12172
|
-
throw new
|
12173
|
-
|
12622
|
+
throw new import_errors27.FuelError(
|
12623
|
+
import_errors27.ErrorCode.HD_WALLET_ERROR,
|
12174
12624
|
"Both public and private Key cannot be missing. At least one should be provided."
|
12175
12625
|
);
|
12176
12626
|
}
|
12177
|
-
this.publicKey = (0,
|
12627
|
+
this.publicKey = (0, import_utils44.hexlify)(config.publicKey);
|
12178
12628
|
}
|
12179
12629
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
12180
|
-
this.fingerprint = (0,
|
12630
|
+
this.fingerprint = (0, import_utils44.dataSlice)((0, import_crypto6.ripemd160)((0, import_hasher7.sha256)(this.publicKey)), 0, 4);
|
12181
12631
|
this.depth = config.depth || this.depth;
|
12182
12632
|
this.index = config.index || this.index;
|
12183
12633
|
this.chainCode = config.chainCode;
|
@@ -12193,28 +12643,28 @@ var HDWallet = class _HDWallet {
|
|
12193
12643
|
* @returns A new instance of HDWallet on the derived index
|
12194
12644
|
*/
|
12195
12645
|
deriveIndex(index) {
|
12196
|
-
const privateKey = this.privateKey && (0,
|
12197
|
-
const publicKey = (0,
|
12198
|
-
const chainCode = (0,
|
12646
|
+
const privateKey = this.privateKey && (0, import_utils44.arrayify)(this.privateKey);
|
12647
|
+
const publicKey = (0, import_utils44.arrayify)(this.publicKey);
|
12648
|
+
const chainCode = (0, import_utils44.arrayify)(this.chainCode);
|
12199
12649
|
const data = new Uint8Array(37);
|
12200
12650
|
if (index & HARDENED_INDEX) {
|
12201
12651
|
if (!privateKey) {
|
12202
|
-
throw new
|
12203
|
-
|
12652
|
+
throw new import_errors27.FuelError(
|
12653
|
+
import_errors27.ErrorCode.HD_WALLET_ERROR,
|
12204
12654
|
"Cannot derive a hardened index without a private Key."
|
12205
12655
|
);
|
12206
12656
|
}
|
12207
12657
|
data.set(privateKey, 1);
|
12208
12658
|
} else {
|
12209
|
-
data.set((0,
|
12659
|
+
data.set((0, import_utils44.arrayify)(this.publicKey));
|
12210
12660
|
}
|
12211
|
-
data.set((0,
|
12212
|
-
const bytes = (0,
|
12661
|
+
data.set((0, import_math25.toBytes)(index, 4), 33);
|
12662
|
+
const bytes = (0, import_utils44.arrayify)((0, import_crypto6.computeHmac)("sha512", chainCode, data));
|
12213
12663
|
const IL = bytes.slice(0, 32);
|
12214
12664
|
const IR = bytes.slice(32);
|
12215
12665
|
if (privateKey) {
|
12216
12666
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
12217
|
-
const ki = (0,
|
12667
|
+
const ki = (0, import_math25.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
12218
12668
|
return new _HDWallet({
|
12219
12669
|
privateKey: ki,
|
12220
12670
|
chainCode: IR,
|
@@ -12223,7 +12673,7 @@ var HDWallet = class _HDWallet {
|
|
12223
12673
|
parentFingerprint: this.fingerprint
|
12224
12674
|
});
|
12225
12675
|
}
|
12226
|
-
const signer = new Signer((0,
|
12676
|
+
const signer = new Signer((0, import_utils44.hexlify)(IL));
|
12227
12677
|
const Ki = signer.addPoint(publicKey);
|
12228
12678
|
return new _HDWallet({
|
12229
12679
|
publicKey: Ki,
|
@@ -12252,18 +12702,18 @@ var HDWallet = class _HDWallet {
|
|
12252
12702
|
*/
|
12253
12703
|
toExtendedKey(isPublic = false, testnet = false) {
|
12254
12704
|
if (this.depth >= 256) {
|
12255
|
-
throw new
|
12256
|
-
|
12705
|
+
throw new import_errors27.FuelError(
|
12706
|
+
import_errors27.ErrorCode.HD_WALLET_ERROR,
|
12257
12707
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
12258
12708
|
);
|
12259
12709
|
}
|
12260
12710
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
12261
|
-
const depth = (0,
|
12711
|
+
const depth = (0, import_utils44.hexlify)(Uint8Array.from([this.depth]));
|
12262
12712
|
const parentFingerprint = this.parentFingerprint;
|
12263
|
-
const index = (0,
|
12713
|
+
const index = (0, import_math25.toHex)(this.index, 4);
|
12264
12714
|
const chainCode = this.chainCode;
|
12265
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
12266
|
-
const extendedKey = (0,
|
12715
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils44.concat)(["0x00", this.privateKey]) : this.publicKey;
|
12716
|
+
const extendedKey = (0, import_utils44.arrayify)((0, import_utils44.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
12267
12717
|
return base58check(extendedKey);
|
12268
12718
|
}
|
12269
12719
|
/**
|
@@ -12275,34 +12725,34 @@ var HDWallet = class _HDWallet {
|
|
12275
12725
|
static fromSeed(seed) {
|
12276
12726
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
12277
12727
|
return new _HDWallet({
|
12278
|
-
chainCode: (0,
|
12279
|
-
privateKey: (0,
|
12728
|
+
chainCode: (0, import_utils44.arrayify)(masterKey.slice(32)),
|
12729
|
+
privateKey: (0, import_utils44.arrayify)(masterKey.slice(0, 32))
|
12280
12730
|
});
|
12281
12731
|
}
|
12282
12732
|
static fromExtendedKey(extendedKey) {
|
12283
|
-
const decoded = (0,
|
12284
|
-
const bytes = (0,
|
12733
|
+
const decoded = (0, import_utils44.hexlify)((0, import_math25.toBytes)((0, import_utils44.decodeBase58)(extendedKey)));
|
12734
|
+
const bytes = (0, import_utils44.arrayify)(decoded);
|
12285
12735
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
12286
12736
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
12287
|
-
throw new
|
12737
|
+
throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
12288
12738
|
}
|
12289
12739
|
if (!validChecksum) {
|
12290
|
-
throw new
|
12740
|
+
throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
12291
12741
|
}
|
12292
12742
|
const depth = bytes[4];
|
12293
|
-
const parentFingerprint = (0,
|
12294
|
-
const index = parseInt((0,
|
12295
|
-
const chainCode = (0,
|
12743
|
+
const parentFingerprint = (0, import_utils44.hexlify)(bytes.slice(5, 9));
|
12744
|
+
const index = parseInt((0, import_utils44.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
12745
|
+
const chainCode = (0, import_utils44.hexlify)(bytes.slice(13, 45));
|
12296
12746
|
const key = bytes.slice(45, 78);
|
12297
12747
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
12298
|
-
throw new
|
12299
|
-
|
12748
|
+
throw new import_errors27.FuelError(
|
12749
|
+
import_errors27.ErrorCode.HD_WALLET_ERROR,
|
12300
12750
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
12301
12751
|
);
|
12302
12752
|
}
|
12303
12753
|
if (isPublicExtendedKey(bytes)) {
|
12304
12754
|
if (key[0] !== 3) {
|
12305
|
-
throw new
|
12755
|
+
throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
12306
12756
|
}
|
12307
12757
|
return new _HDWallet({
|
12308
12758
|
publicKey: key,
|
@@ -12313,7 +12763,7 @@ var HDWallet = class _HDWallet {
|
|
12313
12763
|
});
|
12314
12764
|
}
|
12315
12765
|
if (key[0] !== 0) {
|
12316
|
-
throw new
|
12766
|
+
throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
12317
12767
|
}
|
12318
12768
|
return new _HDWallet({
|
12319
12769
|
privateKey: key.slice(1),
|
@@ -12488,9 +12938,9 @@ var Wallet = class {
|
|
12488
12938
|
};
|
12489
12939
|
|
12490
12940
|
// src/wallet-manager/wallet-manager.ts
|
12491
|
-
var
|
12941
|
+
var import_address11 = require("@fuel-ts/address");
|
12492
12942
|
var import_crypto7 = require("@fuel-ts/crypto");
|
12493
|
-
var
|
12943
|
+
var import_errors30 = require("@fuel-ts/errors");
|
12494
12944
|
var import_events = require("events");
|
12495
12945
|
|
12496
12946
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -12515,8 +12965,8 @@ var MemoryStorage = class {
|
|
12515
12965
|
};
|
12516
12966
|
|
12517
12967
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
12518
|
-
var
|
12519
|
-
var
|
12968
|
+
var import_address9 = require("@fuel-ts/address");
|
12969
|
+
var import_errors28 = require("@fuel-ts/errors");
|
12520
12970
|
var MnemonicVault = class {
|
12521
12971
|
static {
|
12522
12972
|
__name(this, "MnemonicVault");
|
@@ -12567,7 +13017,7 @@ var MnemonicVault = class {
|
|
12567
13017
|
}
|
12568
13018
|
exportAccount(address) {
|
12569
13019
|
let numberOfAccounts = 0;
|
12570
|
-
const ownerAddress = new
|
13020
|
+
const ownerAddress = new import_address9.Address(address);
|
12571
13021
|
do {
|
12572
13022
|
const wallet = Wallet.fromMnemonic(this.#secret, this.getDerivePath(numberOfAccounts));
|
12573
13023
|
if (wallet.address.equals(ownerAddress)) {
|
@@ -12575,8 +13025,8 @@ var MnemonicVault = class {
|
|
12575
13025
|
}
|
12576
13026
|
numberOfAccounts += 1;
|
12577
13027
|
} while (numberOfAccounts < this.numberOfAccounts);
|
12578
|
-
throw new
|
12579
|
-
|
13028
|
+
throw new import_errors28.FuelError(
|
13029
|
+
import_errors28.ErrorCode.WALLET_MANAGER_ERROR,
|
12580
13030
|
`Account with address '${address}' not found in derived wallets.`
|
12581
13031
|
);
|
12582
13032
|
}
|
@@ -12587,8 +13037,8 @@ var MnemonicVault = class {
|
|
12587
13037
|
};
|
12588
13038
|
|
12589
13039
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
12590
|
-
var
|
12591
|
-
var
|
13040
|
+
var import_address10 = require("@fuel-ts/address");
|
13041
|
+
var import_errors29 = require("@fuel-ts/errors");
|
12592
13042
|
var PrivateKeyVault = class {
|
12593
13043
|
static {
|
12594
13044
|
__name(this, "PrivateKeyVault");
|
@@ -12627,13 +13077,13 @@ var PrivateKeyVault = class {
|
|
12627
13077
|
return this.getPublicAccount(wallet.privateKey);
|
12628
13078
|
}
|
12629
13079
|
exportAccount(address) {
|
12630
|
-
const ownerAddress = new
|
13080
|
+
const ownerAddress = new import_address10.Address(address);
|
12631
13081
|
const privateKey = this.#privateKeys.find(
|
12632
13082
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
12633
13083
|
);
|
12634
13084
|
if (!privateKey) {
|
12635
|
-
throw new
|
12636
|
-
|
13085
|
+
throw new import_errors29.FuelError(
|
13086
|
+
import_errors29.ErrorCode.WALLET_MANAGER_ERROR,
|
12637
13087
|
`No private key found for address '${address}'.`
|
12638
13088
|
);
|
12639
13089
|
}
|
@@ -12655,7 +13105,7 @@ var ERROR_MESSAGES = {
|
|
12655
13105
|
};
|
12656
13106
|
function assert(condition, message) {
|
12657
13107
|
if (!condition) {
|
12658
|
-
throw new
|
13108
|
+
throw new import_errors30.FuelError(import_errors30.ErrorCode.WALLET_MANAGER_ERROR, message);
|
12659
13109
|
}
|
12660
13110
|
}
|
12661
13111
|
__name(assert, "assert");
|
@@ -12724,7 +13174,7 @@ var WalletManager = class _WalletManager extends import_events.EventEmitter {
|
|
12724
13174
|
* Create a Wallet instance for the specific account
|
12725
13175
|
*/
|
12726
13176
|
getWallet(address) {
|
12727
|
-
const ownerAddress = new
|
13177
|
+
const ownerAddress = new import_address11.Address(address);
|
12728
13178
|
const vaultState = this.#vaults.find(
|
12729
13179
|
(vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
|
12730
13180
|
);
|
@@ -12735,7 +13185,7 @@ var WalletManager = class _WalletManager extends import_events.EventEmitter {
|
|
12735
13185
|
* Export specific account privateKey
|
12736
13186
|
*/
|
12737
13187
|
exportPrivateKey(address) {
|
12738
|
-
const ownerAddress = new
|
13188
|
+
const ownerAddress = new import_address11.Address(address);
|
12739
13189
|
assert(!this.#isLocked, ERROR_MESSAGES.wallet_not_unlocked);
|
12740
13190
|
const vaultState = this.#vaults.find(
|
12741
13191
|
(vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
|
@@ -12876,29 +13326,29 @@ var WalletManager = class _WalletManager extends import_events.EventEmitter {
|
|
12876
13326
|
};
|
12877
13327
|
|
12878
13328
|
// src/wallet-manager/types.ts
|
12879
|
-
var
|
13329
|
+
var import_errors31 = require("@fuel-ts/errors");
|
12880
13330
|
var Vault = class {
|
12881
13331
|
static {
|
12882
13332
|
__name(this, "Vault");
|
12883
13333
|
}
|
12884
13334
|
static type;
|
12885
13335
|
constructor(_options) {
|
12886
|
-
throw new
|
13336
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
12887
13337
|
}
|
12888
13338
|
serialize() {
|
12889
|
-
throw new
|
13339
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
12890
13340
|
}
|
12891
13341
|
getAccounts() {
|
12892
|
-
throw new
|
13342
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
12893
13343
|
}
|
12894
13344
|
addAccount() {
|
12895
|
-
throw new
|
13345
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
12896
13346
|
}
|
12897
13347
|
exportAccount(_address) {
|
12898
|
-
throw new
|
13348
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
12899
13349
|
}
|
12900
13350
|
getWallet(_address) {
|
12901
|
-
throw new
|
13351
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
12902
13352
|
}
|
12903
13353
|
};
|
12904
13354
|
var StorageAbstract = class {
|
@@ -12908,19 +13358,19 @@ var StorageAbstract = class {
|
|
12908
13358
|
};
|
12909
13359
|
|
12910
13360
|
// src/predicate/predicate.ts
|
12911
|
-
var
|
12912
|
-
var
|
12913
|
-
var
|
12914
|
-
var
|
13361
|
+
var import_abi_coder11 = require("@fuel-ts/abi-coder");
|
13362
|
+
var import_address12 = require("@fuel-ts/address");
|
13363
|
+
var import_errors33 = require("@fuel-ts/errors");
|
13364
|
+
var import_utils48 = require("@fuel-ts/utils");
|
12915
13365
|
|
12916
13366
|
// src/utils/deployScriptOrPredicate.ts
|
12917
|
-
var
|
12918
|
-
var
|
13367
|
+
var import_errors32 = require("@fuel-ts/errors");
|
13368
|
+
var import_utils46 = require("@fuel-ts/utils");
|
12919
13369
|
|
12920
13370
|
// src/utils/predicate-script-loader-instructions.ts
|
12921
|
-
var
|
13371
|
+
var import_abi_coder10 = require("@fuel-ts/abi-coder");
|
12922
13372
|
var import_hasher8 = require("@fuel-ts/hasher");
|
12923
|
-
var
|
13373
|
+
var import_utils45 = require("@fuel-ts/utils");
|
12924
13374
|
var asm2 = __toESM(require("@fuels/vm-asm"));
|
12925
13375
|
var BLOB_ID_SIZE = 32;
|
12926
13376
|
var REG_ADDRESS_OF_DATA_AFTER_CODE = 16;
|
@@ -12930,12 +13380,12 @@ var WORD_SIZE2 = 8;
|
|
12930
13380
|
var DATA_OFFSET_INDEX = 8;
|
12931
13381
|
var CONFIGURABLE_OFFSET_INDEX = 16;
|
12932
13382
|
function getBytecodeDataOffset(bytecode) {
|
12933
|
-
const [offset] = new
|
13383
|
+
const [offset] = new import_abi_coder10.BigNumberCoder("u64").decode(bytecode, DATA_OFFSET_INDEX);
|
12934
13384
|
return offset.toNumber();
|
12935
13385
|
}
|
12936
13386
|
__name(getBytecodeDataOffset, "getBytecodeDataOffset");
|
12937
13387
|
function getBytecodeConfigurableOffset(bytecode) {
|
12938
|
-
const [offset] = new
|
13388
|
+
const [offset] = new import_abi_coder10.BigNumberCoder("u64").decode(bytecode, CONFIGURABLE_OFFSET_INDEX);
|
12939
13389
|
return offset.toNumber();
|
12940
13390
|
}
|
12941
13391
|
__name(getBytecodeConfigurableOffset, "getBytecodeConfigurableOffset");
|
@@ -13046,7 +13496,7 @@ function getPredicateScriptLoaderInstructions(originalBinary, blobId) {
|
|
13046
13496
|
...dataSectionLenBytes
|
13047
13497
|
]);
|
13048
13498
|
return {
|
13049
|
-
loaderBytecode: (0,
|
13499
|
+
loaderBytecode: (0, import_utils45.concat)([loaderBytecode2, configurableSection]),
|
13050
13500
|
blobOffset: loaderBytecode2.length
|
13051
13501
|
};
|
13052
13502
|
}
|
@@ -13090,8 +13540,8 @@ async function deployScriptOrPredicate({
|
|
13090
13540
|
abi,
|
13091
13541
|
loaderInstanceCallback
|
13092
13542
|
}) {
|
13093
|
-
const blobId = getBytecodeId((0,
|
13094
|
-
const configurableOffset = getBytecodeConfigurableOffset((0,
|
13543
|
+
const blobId = getBytecodeId((0, import_utils46.arrayify)(bytecode));
|
13544
|
+
const configurableOffset = getBytecodeConfigurableOffset((0, import_utils46.arrayify)(bytecode));
|
13095
13545
|
const byteCodeWithoutConfigurableSection = bytecode.slice(0, configurableOffset);
|
13096
13546
|
const blobTxRequest = new BlobTransactionRequest({
|
13097
13547
|
blobId,
|
@@ -13099,8 +13549,8 @@ async function deployScriptOrPredicate({
|
|
13099
13549
|
witnesses: [byteCodeWithoutConfigurableSection]
|
13100
13550
|
});
|
13101
13551
|
const { loaderBytecode, blobOffset } = getPredicateScriptLoaderInstructions(
|
13102
|
-
(0,
|
13103
|
-
(0,
|
13552
|
+
(0, import_utils46.arrayify)(bytecode),
|
13553
|
+
(0, import_utils46.arrayify)(blobId)
|
13104
13554
|
);
|
13105
13555
|
const newConfigurableOffsetDiff = byteCodeWithoutConfigurableSection.length - (blobOffset || 0);
|
13106
13556
|
const newAbi = adjustConfigurableOffsets(abi, newConfigurableOffsetDiff);
|
@@ -13121,7 +13571,7 @@ async function deployScriptOrPredicate({
|
|
13121
13571
|
throw new Error();
|
13122
13572
|
}
|
13123
13573
|
} catch (err) {
|
13124
|
-
throw new
|
13574
|
+
throw new import_errors32.FuelError(import_errors32.ErrorCode.TRANSACTION_FAILED, "Failed to deploy predicate chunk");
|
13125
13575
|
}
|
13126
13576
|
return loaderInstance;
|
13127
13577
|
}, "waitForResult");
|
@@ -13135,13 +13585,13 @@ __name(deployScriptOrPredicate, "deployScriptOrPredicate");
|
|
13135
13585
|
// src/predicate/utils/getPredicateRoot.ts
|
13136
13586
|
var import_hasher9 = require("@fuel-ts/hasher");
|
13137
13587
|
var import_merkle = require("@fuel-ts/merkle");
|
13138
|
-
var
|
13588
|
+
var import_utils47 = require("@fuel-ts/utils");
|
13139
13589
|
var getPredicateRoot = /* @__PURE__ */ __name((bytecode) => {
|
13140
13590
|
const chunkSize = 16 * 1024;
|
13141
|
-
const bytes = (0,
|
13142
|
-
const chunks = (0,
|
13143
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
13144
|
-
const predicateRoot = (0, import_hasher9.hash)((0,
|
13591
|
+
const bytes = (0, import_utils47.arrayify)(bytecode);
|
13592
|
+
const chunks = (0, import_utils47.chunkAndPadBytes)(bytes, chunkSize);
|
13593
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils47.hexlify)(c)));
|
13594
|
+
const predicateRoot = (0, import_hasher9.hash)((0, import_utils47.concat)(["0x4655454C", codeRoot]));
|
13145
13595
|
return predicateRoot;
|
13146
13596
|
}, "getPredicateRoot");
|
13147
13597
|
|
@@ -13176,9 +13626,9 @@ var Predicate = class _Predicate extends Account {
|
|
13176
13626
|
abi,
|
13177
13627
|
configurableConstants
|
13178
13628
|
);
|
13179
|
-
const address = new
|
13629
|
+
const address = new import_address12.Address(getPredicateRoot(predicateBytes));
|
13180
13630
|
super(address, provider);
|
13181
|
-
this.initialBytecode = (0,
|
13631
|
+
this.initialBytecode = (0, import_utils48.arrayify)(bytecode);
|
13182
13632
|
this.bytes = predicateBytes;
|
13183
13633
|
this.interface = predicateInterface;
|
13184
13634
|
this.configurableConstants = configurableConstants;
|
@@ -13200,8 +13650,8 @@ var Predicate = class _Predicate extends Account {
|
|
13200
13650
|
}
|
13201
13651
|
request2.inputs.filter(isRequestInputCoinOrMessage).forEach((input) => {
|
13202
13652
|
if (isRequestInputResourceFromOwner(input, this.address)) {
|
13203
|
-
input.predicate = (0,
|
13204
|
-
input.predicateData = (0,
|
13653
|
+
input.predicate = (0, import_utils48.hexlify)(this.bytes);
|
13654
|
+
input.predicateData = (0, import_utils48.hexlify)(this.getPredicateData());
|
13205
13655
|
input.witnessIndex = 0;
|
13206
13656
|
}
|
13207
13657
|
});
|
@@ -13270,11 +13720,11 @@ var Predicate = class _Predicate extends Account {
|
|
13270
13720
|
* @returns An object containing the new predicate bytes and interface.
|
13271
13721
|
*/
|
13272
13722
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
13273
|
-
let predicateBytes = (0,
|
13274
|
-
const abiInterface = new
|
13723
|
+
let predicateBytes = (0, import_utils48.arrayify)(bytes);
|
13724
|
+
const abiInterface = new import_abi_coder11.Interface(jsonAbi);
|
13275
13725
|
if (abiInterface.functions.main === void 0) {
|
13276
|
-
throw new
|
13277
|
-
|
13726
|
+
throw new import_errors33.FuelError(
|
13727
|
+
import_errors33.ErrorCode.ABI_MAIN_METHOD_MISSING,
|
13278
13728
|
'Cannot use ABI without "main" function.'
|
13279
13729
|
);
|
13280
13730
|
}
|
@@ -13305,8 +13755,8 @@ var Predicate = class _Predicate extends Account {
|
|
13305
13755
|
);
|
13306
13756
|
return resources.map((resource) => ({
|
13307
13757
|
...resource,
|
13308
|
-
predicate: (0,
|
13309
|
-
predicateData: (0,
|
13758
|
+
predicate: (0, import_utils48.hexlify)(this.bytes),
|
13759
|
+
predicateData: (0, import_utils48.hexlify)(this.getPredicateData())
|
13310
13760
|
}));
|
13311
13761
|
}
|
13312
13762
|
/**
|
@@ -13318,8 +13768,8 @@ var Predicate = class _Predicate extends Account {
|
|
13318
13768
|
generateFakeResources(coins) {
|
13319
13769
|
return super.generateFakeResources(coins).map((coin) => ({
|
13320
13770
|
...coin,
|
13321
|
-
predicate: (0,
|
13322
|
-
predicateData: (0,
|
13771
|
+
predicate: (0, import_utils48.hexlify)(this.bytes),
|
13772
|
+
predicateData: (0, import_utils48.hexlify)(this.getPredicateData())
|
13323
13773
|
}));
|
13324
13774
|
}
|
13325
13775
|
/**
|
@@ -13334,15 +13784,15 @@ var Predicate = class _Predicate extends Account {
|
|
13334
13784
|
const mutatedBytes = bytes;
|
13335
13785
|
try {
|
13336
13786
|
if (Object.keys(abiInterface.configurables).length === 0) {
|
13337
|
-
throw new
|
13338
|
-
|
13787
|
+
throw new import_errors33.FuelError(
|
13788
|
+
import_errors33.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
13339
13789
|
"Predicate has no configurable constants to be set"
|
13340
13790
|
);
|
13341
13791
|
}
|
13342
13792
|
Object.entries(configurableConstants).forEach(([key, value]) => {
|
13343
13793
|
if (!abiInterface?.configurables[key]) {
|
13344
|
-
throw new
|
13345
|
-
|
13794
|
+
throw new import_errors33.FuelError(
|
13795
|
+
import_errors33.ErrorCode.CONFIGURABLE_NOT_FOUND,
|
13346
13796
|
`No configurable constant named '${key}' found in the Predicate`
|
13347
13797
|
);
|
13348
13798
|
}
|
@@ -13351,8 +13801,8 @@ var Predicate = class _Predicate extends Account {
|
|
13351
13801
|
mutatedBytes.set(encoded, offset);
|
13352
13802
|
});
|
13353
13803
|
} catch (err) {
|
13354
|
-
throw new
|
13355
|
-
|
13804
|
+
throw new import_errors33.FuelError(
|
13805
|
+
import_errors33.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
13356
13806
|
`Error setting configurable constants: ${err.message}.`
|
13357
13807
|
);
|
13358
13808
|
}
|
@@ -13405,10 +13855,10 @@ var Predicate = class _Predicate extends Account {
|
|
13405
13855
|
};
|
13406
13856
|
|
13407
13857
|
// src/connectors/fuel.ts
|
13408
|
-
var
|
13858
|
+
var import_errors36 = require("@fuel-ts/errors");
|
13409
13859
|
|
13410
13860
|
// src/connectors/fuel-connector.ts
|
13411
|
-
var
|
13861
|
+
var import_errors34 = require("@fuel-ts/errors");
|
13412
13862
|
var import_events2 = require("events");
|
13413
13863
|
|
13414
13864
|
// src/connectors/types/connector-types.ts
|
@@ -13433,6 +13883,7 @@ var FuelConnectorMethods = /* @__PURE__ */ ((FuelConnectorMethods2) => {
|
|
13433
13883
|
FuelConnectorMethods2["addABI"] = "addABI";
|
13434
13884
|
FuelConnectorMethods2["getABI"] = "getABI";
|
13435
13885
|
FuelConnectorMethods2["hasABI"] = "hasABI";
|
13886
|
+
FuelConnectorMethods2["startConsolidation"] = "startConsolidation";
|
13436
13887
|
return FuelConnectorMethods2;
|
13437
13888
|
})(FuelConnectorMethods || {});
|
13438
13889
|
var FuelConnectorEventTypes = /* @__PURE__ */ ((FuelConnectorEventTypes2) => {
|
@@ -13445,6 +13896,7 @@ var FuelConnectorEventTypes = /* @__PURE__ */ ((FuelConnectorEventTypes2) => {
|
|
13445
13896
|
FuelConnectorEventTypes2["currentNetwork"] = "currentNetwork";
|
13446
13897
|
FuelConnectorEventTypes2["assets"] = "assets";
|
13447
13898
|
FuelConnectorEventTypes2["abis"] = "abis";
|
13899
|
+
FuelConnectorEventTypes2["consolidateCoins"] = "consolidateCoins";
|
13448
13900
|
return FuelConnectorEventTypes2;
|
13449
13901
|
})(FuelConnectorEventTypes || {});
|
13450
13902
|
var FuelConnectorEventType = "FuelConnector";
|
@@ -13490,7 +13942,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13490
13942
|
* @returns Always true.
|
13491
13943
|
*/
|
13492
13944
|
async ping() {
|
13493
|
-
throw new
|
13945
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13494
13946
|
}
|
13495
13947
|
/**
|
13496
13948
|
* Should return the current version of the connector
|
@@ -13499,7 +13951,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13499
13951
|
* @returns boolean - connection status.
|
13500
13952
|
*/
|
13501
13953
|
async version() {
|
13502
|
-
throw new
|
13954
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13503
13955
|
}
|
13504
13956
|
/**
|
13505
13957
|
* Should return true if the connector is connected
|
@@ -13508,7 +13960,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13508
13960
|
* @returns The connection status.
|
13509
13961
|
*/
|
13510
13962
|
async isConnected() {
|
13511
|
-
throw new
|
13963
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13512
13964
|
}
|
13513
13965
|
/**
|
13514
13966
|
* Should return all the accounts authorized for the
|
@@ -13517,7 +13969,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13517
13969
|
* @returns The accounts addresses strings
|
13518
13970
|
*/
|
13519
13971
|
async accounts() {
|
13520
|
-
throw new
|
13972
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13521
13973
|
}
|
13522
13974
|
/**
|
13523
13975
|
* Should start the connection process and return
|
@@ -13529,7 +13981,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13529
13981
|
* @returns boolean - connection status.
|
13530
13982
|
*/
|
13531
13983
|
async connect() {
|
13532
|
-
throw new
|
13984
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13533
13985
|
}
|
13534
13986
|
/**
|
13535
13987
|
* Should disconnect the current connection and
|
@@ -13539,7 +13991,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13539
13991
|
* @returns The connection status.
|
13540
13992
|
*/
|
13541
13993
|
async disconnect() {
|
13542
|
-
throw new
|
13994
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13543
13995
|
}
|
13544
13996
|
/**
|
13545
13997
|
* Should start the sign message process and return
|
@@ -13551,7 +14003,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13551
14003
|
* @returns Message signature
|
13552
14004
|
*/
|
13553
14005
|
async signMessage(_address, _message) {
|
13554
|
-
throw new
|
14006
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13555
14007
|
}
|
13556
14008
|
/**
|
13557
14009
|
* Should start the sign transaction process and return
|
@@ -13563,7 +14015,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13563
14015
|
* @returns Transaction signature
|
13564
14016
|
*/
|
13565
14017
|
async signTransaction(_address, _transaction, _params) {
|
13566
|
-
throw new
|
14018
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13567
14019
|
}
|
13568
14020
|
/**
|
13569
14021
|
* Should start the send transaction process and return
|
@@ -13579,7 +14031,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13579
14031
|
* @returns The transaction id or transaction response
|
13580
14032
|
*/
|
13581
14033
|
async sendTransaction(_address, _transaction, _params) {
|
13582
|
-
throw new
|
14034
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13583
14035
|
}
|
13584
14036
|
/**
|
13585
14037
|
* Should return the current account selected inside the connector, if the account
|
@@ -13590,7 +14042,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13590
14042
|
* @returns The current account selected otherwise null.
|
13591
14043
|
*/
|
13592
14044
|
async currentAccount() {
|
13593
|
-
throw new
|
14045
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13594
14046
|
}
|
13595
14047
|
/**
|
13596
14048
|
* Should add the assets metadata to the connector and return true if the asset
|
@@ -13604,7 +14056,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13604
14056
|
* @returns True if the asset was added successfully
|
13605
14057
|
*/
|
13606
14058
|
async addAssets(_assets) {
|
13607
|
-
throw new
|
14059
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13608
14060
|
}
|
13609
14061
|
/**
|
13610
14062
|
* Should add the asset metadata to the connector and return true if the asset
|
@@ -13618,7 +14070,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13618
14070
|
* @returns True if the asset was added successfully
|
13619
14071
|
*/
|
13620
14072
|
async addAsset(_asset) {
|
13621
|
-
throw new
|
14073
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13622
14074
|
}
|
13623
14075
|
/**
|
13624
14076
|
* Should return all the assets added to the connector. If a connection is already established.
|
@@ -13626,7 +14078,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13626
14078
|
* @returns Array of assets metadata from the connector vinculated to the all accounts from a specific Wallet.
|
13627
14079
|
*/
|
13628
14080
|
async assets() {
|
13629
|
-
throw new
|
14081
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13630
14082
|
}
|
13631
14083
|
/**
|
13632
14084
|
* Should start the add network process and return true if the network was added successfully.
|
@@ -13637,7 +14089,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13637
14089
|
* @returns Return true if the network was added successfully
|
13638
14090
|
*/
|
13639
14091
|
async addNetwork(_networkUrl) {
|
13640
|
-
throw new
|
14092
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13641
14093
|
}
|
13642
14094
|
/**
|
13643
14095
|
* Should start the select network process and return true if the network has change successfully.
|
@@ -13648,7 +14100,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13648
14100
|
* @returns Return true if the network was added successfully
|
13649
14101
|
*/
|
13650
14102
|
async selectNetwork(_network) {
|
13651
|
-
throw new
|
14103
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13652
14104
|
}
|
13653
14105
|
/**
|
13654
14106
|
* Should return all the networks available from the connector. If the connection is already established.
|
@@ -13656,7 +14108,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13656
14108
|
* @returns Return all the networks added to the connector.
|
13657
14109
|
*/
|
13658
14110
|
async networks() {
|
13659
|
-
throw new
|
14111
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13660
14112
|
}
|
13661
14113
|
/**
|
13662
14114
|
* Should return the current network selected inside the connector. Even if the connection is not established.
|
@@ -13664,7 +14116,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13664
14116
|
* @returns Return the current network selected inside the connector.
|
13665
14117
|
*/
|
13666
14118
|
async currentNetwork() {
|
13667
|
-
throw new
|
14119
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13668
14120
|
}
|
13669
14121
|
/**
|
13670
14122
|
* Should add the ABI to the connector and return true if the ABI was added successfully.
|
@@ -13674,7 +14126,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13674
14126
|
* @returns Return true if the ABI was added successfully.
|
13675
14127
|
*/
|
13676
14128
|
async addABI(_contractId, _abi) {
|
13677
|
-
throw new
|
14129
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13678
14130
|
}
|
13679
14131
|
/**
|
13680
14132
|
* Should return the ABI from the connector vinculated to the all accounts from a specific Wallet.
|
@@ -13683,7 +14135,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13683
14135
|
* @returns The ABI if it exists, otherwise return null.
|
13684
14136
|
*/
|
13685
14137
|
async getABI(_id) {
|
13686
|
-
throw new
|
14138
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13687
14139
|
}
|
13688
14140
|
/**
|
13689
14141
|
* Should return true if the abi exists in the connector vinculated to the all accounts from a specific Wallet.
|
@@ -13692,7 +14144,16 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13692
14144
|
* @returns Returns true if the abi exists or false if not.
|
13693
14145
|
*/
|
13694
14146
|
async hasABI(_id) {
|
13695
|
-
throw new
|
14147
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
14148
|
+
}
|
14149
|
+
/**
|
14150
|
+
* Start the consolidation of coins process
|
14151
|
+
*
|
14152
|
+
* @param owner - The B256 address of the owner.
|
14153
|
+
* @param assetId - The asset ID that requires consolidation.
|
14154
|
+
*/
|
14155
|
+
async startConsolidation(_opts) {
|
14156
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13696
14157
|
}
|
13697
14158
|
/**
|
13698
14159
|
* Event listener for the connector.
|
@@ -13738,7 +14199,7 @@ function dispatchFuelConnectorEvent(connector) {
|
|
13738
14199
|
__name(dispatchFuelConnectorEvent, "dispatchFuelConnectorEvent");
|
13739
14200
|
|
13740
14201
|
// src/connectors/utils/promises.ts
|
13741
|
-
var
|
14202
|
+
var import_errors35 = require("@fuel-ts/errors");
|
13742
14203
|
function deferPromise() {
|
13743
14204
|
const defer = {};
|
13744
14205
|
defer.promise = new Promise((resolve, reject) => {
|
@@ -13751,7 +14212,7 @@ __name(deferPromise, "deferPromise");
|
|
13751
14212
|
async function withTimeout(promise, timeout = 1050) {
|
13752
14213
|
const timeoutPromise = new Promise((resolve, reject) => {
|
13753
14214
|
setTimeout(() => {
|
13754
|
-
reject(new
|
14215
|
+
reject(new import_errors35.FuelError(import_errors35.FuelError.CODES.TIMEOUT_EXCEEDED, "Promise timed out"));
|
13755
14216
|
}, timeout);
|
13756
14217
|
});
|
13757
14218
|
return Promise.race([timeoutPromise, promise]);
|
@@ -13792,7 +14253,7 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
13792
14253
|
this._targetUnsubscribe = this.setupConnectorListener();
|
13793
14254
|
await connectResponse;
|
13794
14255
|
} catch (error) {
|
13795
|
-
throw new
|
14256
|
+
throw new import_errors36.FuelError(import_errors36.ErrorCode.INVALID_PROVIDER, "Error initializing Fuel Connector");
|
13796
14257
|
}
|
13797
14258
|
}
|
13798
14259
|
async init() {
|
@@ -13858,8 +14319,8 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
13858
14319
|
const hasConnector = await this.hasConnector();
|
13859
14320
|
await this.pingConnector();
|
13860
14321
|
if (!this._currentConnector || !hasConnector) {
|
13861
|
-
throw new
|
13862
|
-
|
14322
|
+
throw new import_errors36.FuelError(
|
14323
|
+
import_errors36.ErrorCode.MISSING_CONNECTOR,
|
13863
14324
|
`No connector selected for calling ${method}. Use hasConnector before executing other methods.`
|
13864
14325
|
);
|
13865
14326
|
}
|
@@ -13923,7 +14384,7 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
13923
14384
|
cacheTime: PING_CACHE_TIME
|
13924
14385
|
})();
|
13925
14386
|
} catch {
|
13926
|
-
throw new
|
14387
|
+
throw new import_errors36.FuelError(import_errors36.ErrorCode.INVALID_PROVIDER, "Current connector is not available.");
|
13927
14388
|
}
|
13928
14389
|
}
|
13929
14390
|
/**
|
@@ -14072,7 +14533,7 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
14072
14533
|
const currentNetwork = await this.currentNetwork();
|
14073
14534
|
provider = new Provider(currentNetwork.url);
|
14074
14535
|
} else {
|
14075
|
-
throw new
|
14536
|
+
throw new import_errors36.FuelError(import_errors36.ErrorCode.INVALID_PROVIDER, "Provider is not valid.");
|
14076
14537
|
}
|
14077
14538
|
return provider;
|
14078
14539
|
}
|
@@ -14166,6 +14627,7 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
14166
14627
|
assemblePreConfirmationTransactionSummary,
|
14167
14628
|
assembleReceiptByType,
|
14168
14629
|
assembleRevertError,
|
14630
|
+
assembleSignalErrorMessage,
|
14169
14631
|
assembleTransactionSummary,
|
14170
14632
|
assembleTransactionSummaryFromJson,
|
14171
14633
|
assets,
|
@@ -14182,6 +14644,8 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
14182
14644
|
calculateMinGasForTxUpload,
|
14183
14645
|
calculateTXFeeForSummary,
|
14184
14646
|
coinQuantityfy,
|
14647
|
+
consolidateCoins,
|
14648
|
+
consolidateCoinsIfRequired,
|
14185
14649
|
deferPromise,
|
14186
14650
|
deployScriptOrPredicate,
|
14187
14651
|
deserializeChain,
|
@@ -14200,6 +14664,7 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
14200
14664
|
extractTxError,
|
14201
14665
|
fuelAssetsBaseUrl,
|
14202
14666
|
gasUsedByInputs,
|
14667
|
+
getAllCoins,
|
14203
14668
|
getAllDecodedLogs,
|
14204
14669
|
getAssetAmountInRequestInputs,
|
14205
14670
|
getAssetById,
|