@fuel-ts/account 0.101.2 → 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 +538 -101
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +598 -250
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +583 -238
- 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/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 +465 -101
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +525 -198
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +515 -188
- 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 +14 -14
package/dist/index.js
CHANGED
@@ -105,6 +105,8 @@ __export(src_exports, {
|
|
105
105
|
calculateMinGasForTxUpload: () => calculateMinGasForTxUpload,
|
106
106
|
calculateTXFeeForSummary: () => calculateTXFeeForSummary,
|
107
107
|
coinQuantityfy: () => coinQuantityfy,
|
108
|
+
consolidateCoins: () => consolidateCoins,
|
109
|
+
consolidateCoinsIfRequired: () => consolidateCoinsIfRequired,
|
108
110
|
deferPromise: () => deferPromise,
|
109
111
|
deployScriptOrPredicate: () => deployScriptOrPredicate,
|
110
112
|
deserializeChain: () => deserializeChain,
|
@@ -123,6 +125,7 @@ __export(src_exports, {
|
|
123
125
|
extractTxError: () => extractTxError,
|
124
126
|
fuelAssetsBaseUrl: () => fuelAssetsBaseUrl,
|
125
127
|
gasUsedByInputs: () => gasUsedByInputs,
|
128
|
+
getAllCoins: () => getAllCoins,
|
126
129
|
getAllDecodedLogs: () => getAllDecodedLogs,
|
127
130
|
getAssetAmountInRequestInputs: () => getAssetAmountInRequestInputs,
|
128
131
|
getAssetById: () => getAssetById,
|
@@ -929,13 +932,13 @@ var getAssetsByOwner = /* @__PURE__ */ __name(async (opts) => {
|
|
929
932
|
|
930
933
|
// src/account.ts
|
931
934
|
var import_abi_coder9 = require("@fuel-ts/abi-coder");
|
932
|
-
var
|
935
|
+
var import_address6 = require("@fuel-ts/address");
|
933
936
|
var import_crypto2 = require("@fuel-ts/crypto");
|
934
|
-
var
|
935
|
-
var
|
936
|
-
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");
|
937
940
|
var import_utils37 = require("@fuel-ts/utils");
|
938
|
-
var
|
941
|
+
var import_ramda10 = require("ramda");
|
939
942
|
|
940
943
|
// src/providers/coin-quantity.ts
|
941
944
|
var import_math = require("@fuel-ts/math");
|
@@ -2376,8 +2379,11 @@ var import_graphql = require("graphql");
|
|
2376
2379
|
|
2377
2380
|
// src/providers/utils/handle-gql-error-message.ts
|
2378
2381
|
var import_errors2 = require("@fuel-ts/errors");
|
2382
|
+
var ASSET_ID_REGEX = /[0-9a-fA-F]{32,64}/g;
|
2379
2383
|
var gqlErrorMessage = {
|
2380
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+./,
|
2381
2387
|
NOT_ENOUGH_COINS_MAX_COINS: /the target cannot be met due to no coins available or exceeding the \d+ coin limit./,
|
2382
2388
|
ASSET_NOT_FOUND: /resource was not found in table/,
|
2383
2389
|
MULTIPLE_CHANGE_POLICIES: /The asset ([a-fA-F0-9]{64}) has multiple change policies/,
|
@@ -2393,6 +2399,46 @@ var mapGqlErrorMessage = /* @__PURE__ */ __name((error) => {
|
|
2393
2399
|
error
|
2394
2400
|
);
|
2395
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
|
+
}
|
2396
2442
|
if (gqlErrorMessage.MULTIPLE_CHANGE_POLICIES.test(error.message)) {
|
2397
2443
|
const match = error.message.match(/asset ([a-fA-F0-9]{64})/);
|
2398
2444
|
const assetId = match?.[1] || "";
|
@@ -3538,6 +3584,7 @@ This error originated at ${JSON.stringify(pos, null, 2)}` : "";
|
|
3538
3584
|
}
|
3539
3585
|
return new import_errors8.FuelError(import_errors8.ErrorCode.SCRIPT_REVERTED, errorMessage, {
|
3540
3586
|
...metadata,
|
3587
|
+
abiError,
|
3541
3588
|
reason
|
3542
3589
|
});
|
3543
3590
|
}
|
@@ -4592,11 +4639,15 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
4592
4639
|
* @deprecated Use `provider.assembleTx` instead.
|
4593
4640
|
* Check the migration guide https://docs.fuel.network/guide/assembling-transactions/migration-guide.html for more information.
|
4594
4641
|
*/
|
4595
|
-
async estimateAndFund(account, {
|
4642
|
+
async estimateAndFund(account, {
|
4643
|
+
signatureCallback,
|
4644
|
+
quantities = [],
|
4645
|
+
skipAutoConsolidation
|
4646
|
+
} = {}) {
|
4596
4647
|
const txCost = await account.getTransactionCost(this, { signatureCallback, quantities });
|
4597
4648
|
this.maxFee = txCost.maxFee;
|
4598
4649
|
this.gasLimit = txCost.gasUsed;
|
4599
|
-
await account.fund(this, txCost);
|
4650
|
+
await account.fund(this, txCost, { skipAutoConsolidation });
|
4600
4651
|
return this;
|
4601
4652
|
}
|
4602
4653
|
/**
|
@@ -6222,25 +6273,6 @@ __name(getAllDecodedLogs, "getAllDecodedLogs");
|
|
6222
6273
|
|
6223
6274
|
// src/providers/transaction-response/transaction-response.ts
|
6224
6275
|
var TransactionResponse = class _TransactionResponse {
|
6225
|
-
/**
|
6226
|
-
* Constructor for `TransactionResponse`.
|
6227
|
-
*
|
6228
|
-
* @param tx - The transaction ID or TransactionRequest.
|
6229
|
-
* @param provider - The provider.
|
6230
|
-
*/
|
6231
|
-
constructor(tx, provider, chainId, abis, submitTxSubscription) {
|
6232
|
-
this.submitTxSubscription = submitTxSubscription;
|
6233
|
-
if (typeof tx === "string") {
|
6234
|
-
this.id = tx;
|
6235
|
-
} else {
|
6236
|
-
this.id = tx.getTransactionId(chainId);
|
6237
|
-
this.request = tx;
|
6238
|
-
}
|
6239
|
-
this.provider = provider;
|
6240
|
-
this.abis = abis;
|
6241
|
-
this.waitForResult = this.waitForResult.bind(this);
|
6242
|
-
this.waitForPreConfirmation = this.waitForPreConfirmation.bind(this);
|
6243
|
-
}
|
6244
6276
|
static {
|
6245
6277
|
__name(this, "TransactionResponse");
|
6246
6278
|
}
|
@@ -6255,9 +6287,42 @@ var TransactionResponse = class _TransactionResponse {
|
|
6255
6287
|
request;
|
6256
6288
|
status;
|
6257
6289
|
abis;
|
6290
|
+
submitTxSubscription;
|
6258
6291
|
preConfirmationStatus;
|
6259
6292
|
waitingForStreamData = false;
|
6260
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
|
+
}
|
6261
6326
|
/**
|
6262
6327
|
* Async constructor for `TransactionResponse`. This method can be used to create
|
6263
6328
|
* an instance of `TransactionResponse` and wait for the transaction to be fetched
|
@@ -6797,7 +6862,15 @@ var Provider = class _Provider {
|
|
6797
6862
|
if (_Provider.ENABLE_RPC_CONSISTENCY && _Provider.hasWriteOperationHappened(url)) {
|
6798
6863
|
_Provider.applyBlockHeight(fullRequest, url);
|
6799
6864
|
}
|
6800
|
-
|
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;
|
6801
6874
|
}, retryOptions);
|
6802
6875
|
}
|
6803
6876
|
static applyBlockHeight(request2, url) {
|
@@ -6820,13 +6893,15 @@ var Provider = class _Provider {
|
|
6820
6893
|
baseDelay: 500
|
6821
6894
|
};
|
6822
6895
|
for (let retriesLeft = retryOptions.maxRetries; retriesLeft > 0; --retriesLeft) {
|
6823
|
-
|
6824
|
-
|
6825
|
-
|
6826
|
-
|
6827
|
-
|
6828
|
-
|
6829
|
-
|
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
|
+
}
|
6830
6905
|
}
|
6831
6906
|
const retryAttempt = retryOptions.maxRetries - retriesLeft + 1;
|
6832
6907
|
const sleepTime = getWaitDelay(retryOptions, retryAttempt);
|
@@ -7249,7 +7324,13 @@ var Provider = class _Provider {
|
|
7249
7324
|
transactionRequest.getTransactionId(await this.getChainId())
|
7250
7325
|
);
|
7251
7326
|
const chainId = await this.getChainId();
|
7252
|
-
return new TransactionResponse(
|
7327
|
+
return new TransactionResponse({
|
7328
|
+
transactionRequestOrId: transactionRequest,
|
7329
|
+
provider: this,
|
7330
|
+
chainId,
|
7331
|
+
abis,
|
7332
|
+
submitAndAwaitSubscription: subscription
|
7333
|
+
});
|
7253
7334
|
}
|
7254
7335
|
/**
|
7255
7336
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -8344,7 +8425,11 @@ var Provider = class _Provider {
|
|
8344
8425
|
*/
|
8345
8426
|
async getTransactionResponse(transactionId) {
|
8346
8427
|
const chainId = await this.getChainId();
|
8347
|
-
return new TransactionResponse(
|
8428
|
+
return new TransactionResponse({
|
8429
|
+
transactionRequestOrId: transactionId,
|
8430
|
+
provider: this,
|
8431
|
+
chainId
|
8432
|
+
});
|
8348
8433
|
}
|
8349
8434
|
/**
|
8350
8435
|
* Returns Message for given nonce.
|
@@ -8675,7 +8760,12 @@ var deserializeTransactionResponseJson = /* @__PURE__ */ __name((json) => {
|
|
8675
8760
|
} = json;
|
8676
8761
|
const provider = new Provider(providerUrl, { cache: providerCache });
|
8677
8762
|
const { chainId } = providerCache.chain.consensusParameters;
|
8678
|
-
const response = new TransactionResponse(
|
8763
|
+
const response = new TransactionResponse({
|
8764
|
+
transactionRequestOrId: id,
|
8765
|
+
provider,
|
8766
|
+
chainId: Number(chainId),
|
8767
|
+
abis
|
8768
|
+
});
|
8679
8769
|
if (requestJson) {
|
8680
8770
|
response.request = transactionRequestify(JSON.parse(requestJson));
|
8681
8771
|
}
|
@@ -8692,9 +8782,157 @@ var AbstractAccount = class {
|
|
8692
8782
|
}
|
8693
8783
|
};
|
8694
8784
|
|
8785
|
+
// src/utils/consolidate-coins.ts
|
8786
|
+
var import_address4 = require("@fuel-ts/address");
|
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
|
+
|
8695
8933
|
// src/utils/formatTransferToContractScriptData.ts
|
8696
8934
|
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
8697
|
-
var
|
8935
|
+
var import_address5 = require("@fuel-ts/address");
|
8698
8936
|
var import_utils36 = require("@fuel-ts/utils");
|
8699
8937
|
var asm = __toESM(require("@fuels/vm-asm"));
|
8700
8938
|
var formatTransferToContractScriptData = /* @__PURE__ */ __name((transferParams) => {
|
@@ -8702,7 +8940,7 @@ var formatTransferToContractScriptData = /* @__PURE__ */ __name((transferParams)
|
|
8702
8940
|
return transferParams.reduce((acc, transferParam) => {
|
8703
8941
|
const { assetId, amount, contractId } = transferParam;
|
8704
8942
|
const encoded = numberCoder.encode(amount);
|
8705
|
-
const scriptData = (0, import_utils36.concat)([new
|
8943
|
+
const scriptData = (0, import_utils36.concat)([new import_address5.Address(contractId).toBytes(), encoded, (0, import_utils36.arrayify)(assetId)]);
|
8706
8944
|
return (0, import_utils36.concat)([acc, scriptData]);
|
8707
8945
|
}, new Uint8Array());
|
8708
8946
|
}, "formatTransferToContractScriptData");
|
@@ -8773,7 +9011,7 @@ var Account = class extends AbstractAccount {
|
|
8773
9011
|
super();
|
8774
9012
|
this._provider = provider;
|
8775
9013
|
this._connector = connector;
|
8776
|
-
this.address = new
|
9014
|
+
this.address = new import_address6.Address(address);
|
8777
9015
|
}
|
8778
9016
|
/**
|
8779
9017
|
* The provider used to interact with the network.
|
@@ -8784,7 +9022,7 @@ var Account = class extends AbstractAccount {
|
|
8784
9022
|
*/
|
8785
9023
|
get provider() {
|
8786
9024
|
if (!this._provider) {
|
8787
|
-
throw new
|
9025
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
8788
9026
|
}
|
8789
9027
|
return this._provider;
|
8790
9028
|
}
|
@@ -8811,10 +9049,24 @@ var Account = class extends AbstractAccount {
|
|
8811
9049
|
*
|
8812
9050
|
* @param quantities - Quantities of resources to be obtained.
|
8813
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).
|
8814
9053
|
* @returns A promise that resolves to an array of Resources.
|
8815
9054
|
*/
|
8816
|
-
async getResourcesToSpend(quantities, resourcesIdsToIgnore) {
|
8817
|
-
|
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
|
+
}
|
8818
9070
|
}
|
8819
9071
|
/**
|
8820
9072
|
* Retrieves coins owned by the account.
|
@@ -8863,7 +9115,7 @@ var Account = class extends AbstractAccount {
|
|
8863
9115
|
* @deprecated Use provider.assembleTx instead
|
8864
9116
|
* Check the migration guide https://docs.fuel.network/docs/fuels-ts/transactions/assemble-tx-migration-guide/ for more information.
|
8865
9117
|
*/
|
8866
|
-
async fund(request2, params) {
|
9118
|
+
async fund(request2, params, { skipAutoConsolidation } = {}) {
|
8867
9119
|
const {
|
8868
9120
|
addedSignatures,
|
8869
9121
|
estimatedPredicates,
|
@@ -8875,9 +9127,9 @@ var Account = class extends AbstractAccount {
|
|
8875
9127
|
const chainId = await this.provider.getChainId();
|
8876
9128
|
const fee = request2.maxFee;
|
8877
9129
|
const baseAssetId = await this.provider.getBaseAssetId();
|
8878
|
-
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);
|
8879
9131
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
8880
|
-
amount: (0,
|
9132
|
+
amount: (0, import_math23.bn)(fee),
|
8881
9133
|
assetId: baseAssetId,
|
8882
9134
|
coinQuantities: requiredQuantities
|
8883
9135
|
});
|
@@ -8885,7 +9137,7 @@ var Account = class extends AbstractAccount {
|
|
8885
9137
|
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
8886
9138
|
quantitiesDict[assetId] = {
|
8887
9139
|
required: amount,
|
8888
|
-
owned: (0,
|
9140
|
+
owned: (0, import_math23.bn)(0)
|
8889
9141
|
};
|
8890
9142
|
});
|
8891
9143
|
request2.inputs.filter(isRequestInputResource).forEach((input) => {
|
@@ -8909,11 +9161,12 @@ var Account = class extends AbstractAccount {
|
|
8909
9161
|
while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
|
8910
9162
|
const resources = await this.getResourcesToSpend(
|
8911
9163
|
missingQuantities,
|
8912
|
-
cacheRequestInputsResourcesFromOwner(request2.inputs, this.address)
|
9164
|
+
cacheRequestInputsResourcesFromOwner(request2.inputs, this.address),
|
9165
|
+
{ skipAutoConsolidation }
|
8913
9166
|
);
|
8914
9167
|
request2.addResources(resources);
|
8915
9168
|
request2.updatePredicateGasUsed(estimatedPredicates);
|
8916
|
-
const requestToReestimate2 = (0,
|
9169
|
+
const requestToReestimate2 = (0, import_ramda10.clone)(request2);
|
8917
9170
|
if (addedSignatures) {
|
8918
9171
|
Array.from({ length: addedSignatures }).forEach(
|
8919
9172
|
() => requestToReestimate2.addEmptyWitness()
|
@@ -8946,15 +9199,15 @@ var Account = class extends AbstractAccount {
|
|
8946
9199
|
fundingAttempts += 1;
|
8947
9200
|
}
|
8948
9201
|
if (needsToBeFunded) {
|
8949
|
-
throw new
|
8950
|
-
|
9202
|
+
throw new import_errors23.FuelError(
|
9203
|
+
import_errors23.ErrorCode.INSUFFICIENT_FUNDS,
|
8951
9204
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
8952
9205
|
);
|
8953
9206
|
}
|
8954
9207
|
request2.updateState(chainId, "funded", transactionSummary);
|
8955
9208
|
await this.provider.validateTransaction(request2);
|
8956
9209
|
request2.updatePredicateGasUsed(estimatedPredicates);
|
8957
|
-
const requestToReestimate = (0,
|
9210
|
+
const requestToReestimate = (0, import_ramda10.clone)(request2);
|
8958
9211
|
if (addedSignatures) {
|
8959
9212
|
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
8960
9213
|
}
|
@@ -8975,16 +9228,20 @@ var Account = class extends AbstractAccount {
|
|
8975
9228
|
* @param amount - The amount of coins to transfer.
|
8976
9229
|
* @param assetId - The asset ID of the coins to transfer (optional).
|
8977
9230
|
* @param txParams - The transaction parameters (optional).
|
9231
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
8978
9232
|
* @returns A promise that resolves to the prepared transaction request.
|
8979
9233
|
*/
|
8980
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
9234
|
+
async createTransfer(destination, amount, assetId, txParams = {}, { skipAutoConsolidation } = {}) {
|
8981
9235
|
let request2 = new ScriptTransactionRequest(txParams);
|
8982
9236
|
request2 = this.addTransfer(request2, {
|
8983
9237
|
destination,
|
8984
9238
|
amount,
|
8985
9239
|
assetId: assetId || await this.provider.getBaseAssetId()
|
8986
9240
|
});
|
8987
|
-
const { gasPrice, transactionRequest } = await this.assembleTx(
|
9241
|
+
const { gasPrice, transactionRequest } = await this.assembleTx({
|
9242
|
+
transactionRequest: request2,
|
9243
|
+
skipAutoConsolidation
|
9244
|
+
});
|
8988
9245
|
request2 = await setAndValidateGasAndFeeForAssembledTx({
|
8989
9246
|
gasPrice,
|
8990
9247
|
provider: this.provider,
|
@@ -9001,10 +9258,13 @@ var Account = class extends AbstractAccount {
|
|
9001
9258
|
* @param amount - The amount of coins to transfer.
|
9002
9259
|
* @param assetId - The asset ID of the coins to transfer (optional).
|
9003
9260
|
* @param txParams - The transaction parameters (optional).
|
9261
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
9004
9262
|
* @returns A promise that resolves to the transaction response.
|
9005
9263
|
*/
|
9006
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
9007
|
-
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
|
+
});
|
9008
9268
|
return this.sendTransaction(request2, { estimateTxDependencies: false });
|
9009
9269
|
}
|
9010
9270
|
/**
|
@@ -9012,12 +9272,16 @@ var Account = class extends AbstractAccount {
|
|
9012
9272
|
*
|
9013
9273
|
* @param transferParams - An array of `TransferParams` objects representing the transfers to be made.
|
9014
9274
|
* @param txParams - Optional transaction parameters.
|
9275
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
9015
9276
|
* @returns A promise that resolves to a `TransactionResponse` object representing the transaction result.
|
9016
9277
|
*/
|
9017
|
-
async batchTransfer(transferParams, txParams = {}) {
|
9278
|
+
async batchTransfer(transferParams, txParams = {}, { skipAutoConsolidation } = {}) {
|
9018
9279
|
let request2 = new ScriptTransactionRequest(txParams);
|
9019
9280
|
request2 = this.addBatchTransfer(request2, transferParams);
|
9020
|
-
const { gasPrice, transactionRequest } = await this.assembleTx(
|
9281
|
+
const { gasPrice, transactionRequest } = await this.assembleTx({
|
9282
|
+
transactionRequest: request2,
|
9283
|
+
skipAutoConsolidation
|
9284
|
+
});
|
9021
9285
|
request2 = await setAndValidateGasAndFeeForAssembledTx({
|
9022
9286
|
gasPrice,
|
9023
9287
|
provider: this.provider,
|
@@ -9037,7 +9301,7 @@ var Account = class extends AbstractAccount {
|
|
9037
9301
|
addTransfer(request2, transferParams) {
|
9038
9302
|
const { destination, amount, assetId } = transferParams;
|
9039
9303
|
this.validateTransferAmount(amount);
|
9040
|
-
request2.addCoinOutput(new
|
9304
|
+
request2.addCoinOutput(new import_address6.Address(destination), amount, assetId);
|
9041
9305
|
return request2;
|
9042
9306
|
}
|
9043
9307
|
/**
|
@@ -9064,24 +9328,27 @@ var Account = class extends AbstractAccount {
|
|
9064
9328
|
* @param amount - The amount of coins to transfer.
|
9065
9329
|
* @param assetId - The asset ID of the coins to transfer (optional).
|
9066
9330
|
* @param txParams - The transaction parameters (optional).
|
9331
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
9067
9332
|
* @returns A promise that resolves to the transaction response.
|
9068
9333
|
*/
|
9069
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
9070
|
-
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
|
+
});
|
9071
9338
|
}
|
9072
|
-
async batchTransferToContracts(contractTransferParams, txParams = {}) {
|
9339
|
+
async batchTransferToContracts(contractTransferParams, txParams = {}, { skipAutoConsolidation } = {}) {
|
9073
9340
|
let request2 = new ScriptTransactionRequest({
|
9074
9341
|
...txParams
|
9075
9342
|
});
|
9076
9343
|
const quantities = [];
|
9077
9344
|
const defaultAssetId = await this.provider.getBaseAssetId();
|
9078
9345
|
const transferParams = contractTransferParams.map((transferParam) => {
|
9079
|
-
const amount = (0,
|
9080
|
-
const contractAddress = new
|
9346
|
+
const amount = (0, import_math23.bn)(transferParam.amount);
|
9347
|
+
const contractAddress = new import_address6.Address(transferParam.contractId);
|
9081
9348
|
const assetId = transferParam.assetId ? (0, import_utils37.hexlify)(transferParam.assetId) : defaultAssetId;
|
9082
9349
|
if (amount.lte(0)) {
|
9083
|
-
throw new
|
9084
|
-
|
9350
|
+
throw new import_errors23.FuelError(
|
9351
|
+
import_errors23.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
9085
9352
|
"Transfer amount must be a positive number."
|
9086
9353
|
);
|
9087
9354
|
}
|
@@ -9096,7 +9363,11 @@ var Account = class extends AbstractAccount {
|
|
9096
9363
|
const { script, scriptData } = await assembleTransferToContractScript(transferParams);
|
9097
9364
|
request2.script = script;
|
9098
9365
|
request2.scriptData = scriptData;
|
9099
|
-
const { gasPrice, transactionRequest } = await this.assembleTx(
|
9366
|
+
const { gasPrice, transactionRequest } = await this.assembleTx({
|
9367
|
+
transactionRequest: request2,
|
9368
|
+
quantities,
|
9369
|
+
skipAutoConsolidation
|
9370
|
+
});
|
9100
9371
|
request2 = await setAndValidateGasAndFeeForAssembledTx({
|
9101
9372
|
gasPrice,
|
9102
9373
|
provider: this.provider,
|
@@ -9112,15 +9383,16 @@ var Account = class extends AbstractAccount {
|
|
9112
9383
|
* @param recipient - Address of the recipient on the base chain.
|
9113
9384
|
* @param amount - Amount of base asset.
|
9114
9385
|
* @param txParams - The transaction parameters (optional).
|
9386
|
+
* @param skipAutoConsolidation - Whether to skip the automatic consolidatation of coins process (optional).
|
9115
9387
|
* @returns A promise that resolves to the transaction response.
|
9116
9388
|
*/
|
9117
|
-
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
9118
|
-
const recipientAddress = new
|
9389
|
+
async withdrawToBaseLayer(recipient, amount, txParams = {}, { skipAutoConsolidation } = {}) {
|
9390
|
+
const recipientAddress = new import_address6.Address(recipient);
|
9119
9391
|
const recipientDataArray = (0, import_utils37.arrayify)(
|
9120
9392
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
9121
9393
|
);
|
9122
9394
|
const amountDataArray = (0, import_utils37.arrayify)(
|
9123
|
-
"0x".concat((0,
|
9395
|
+
"0x".concat((0, import_math23.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
9124
9396
|
);
|
9125
9397
|
const script = new Uint8Array([
|
9126
9398
|
...(0, import_utils37.arrayify)(withdrawScript.bytes),
|
@@ -9130,8 +9402,12 @@ var Account = class extends AbstractAccount {
|
|
9130
9402
|
const params = { script, ...txParams };
|
9131
9403
|
const baseAssetId = await this.provider.getBaseAssetId();
|
9132
9404
|
let request2 = new ScriptTransactionRequest(params);
|
9133
|
-
const quantities = [{ amount: (0,
|
9134
|
-
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
|
+
});
|
9135
9411
|
request2 = await setAndValidateGasAndFeeForAssembledTx({
|
9136
9412
|
gasPrice,
|
9137
9413
|
provider: this.provider,
|
@@ -9141,6 +9417,25 @@ var Account = class extends AbstractAccount {
|
|
9141
9417
|
});
|
9142
9418
|
return this.sendTransaction(request2);
|
9143
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
|
+
}
|
9144
9439
|
/**
|
9145
9440
|
* Consolidates base asset UTXOs into fewer, larger ones.
|
9146
9441
|
*
|
@@ -9160,6 +9455,7 @@ var Account = class extends AbstractAccount {
|
|
9160
9455
|
const isBaseAsset = baseAssetId === assetId;
|
9161
9456
|
let submitAll;
|
9162
9457
|
const consolidationParams = {
|
9458
|
+
assetId,
|
9163
9459
|
coins,
|
9164
9460
|
mode: params.mode,
|
9165
9461
|
outputNum: params.outputNum
|
@@ -9167,10 +9463,7 @@ var Account = class extends AbstractAccount {
|
|
9167
9463
|
if (isBaseAsset) {
|
9168
9464
|
({ submitAll } = await this.assembleBaseAssetConsolidationTxs(consolidationParams));
|
9169
9465
|
} else {
|
9170
|
-
|
9171
|
-
import_errors22.ErrorCode.UNSUPPORTED_FEATURE,
|
9172
|
-
"Consolidation for non-base assets is not supported yet."
|
9173
|
-
);
|
9466
|
+
({ submitAll } = await this.assembleNonBaseAssetConsolidationTxs(consolidationParams));
|
9174
9467
|
}
|
9175
9468
|
return submitAll();
|
9176
9469
|
}
|
@@ -9191,7 +9484,7 @@ var Account = class extends AbstractAccount {
|
|
9191
9484
|
this.validateConsolidationTxsCoins(coins, baseAssetId);
|
9192
9485
|
const chainInfo = await this.provider.getChain();
|
9193
9486
|
const maxInputsNumber = chainInfo.consensusParameters.txParameters.maxInputs.toNumber();
|
9194
|
-
let totalFeeCost = (0,
|
9487
|
+
let totalFeeCost = (0, import_math23.bn)(0);
|
9195
9488
|
const txs = [];
|
9196
9489
|
const coinsBatches = splitCoinsIntoBatches(coins, maxInputsNumber);
|
9197
9490
|
const gasPrice = await this.provider.estimateGasPrice(10);
|
@@ -9215,10 +9508,10 @@ var Account = class extends AbstractAccount {
|
|
9215
9508
|
});
|
9216
9509
|
request2.maxFee = fee;
|
9217
9510
|
if (consolidateMoreThanOneCoin) {
|
9218
|
-
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));
|
9219
9512
|
const amountPerNewUtxo = total.div(outputNum + 1);
|
9220
9513
|
request2.outputs.forEach((output) => {
|
9221
|
-
if (output.type ===
|
9514
|
+
if (output.type === import_transactions29.OutputType.Coin) {
|
9222
9515
|
output.amount = amountPerNewUtxo;
|
9223
9516
|
}
|
9224
9517
|
});
|
@@ -9229,6 +9522,70 @@ var Account = class extends AbstractAccount {
|
|
9229
9522
|
const submitAll = this.prepareSubmitAll({ txs, mode });
|
9230
9523
|
return { txs, totalFeeCost, submitAll };
|
9231
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
|
+
}
|
9232
9589
|
/**
|
9233
9590
|
* Prepares a function to submit all transactions either sequentially or in parallel.
|
9234
9591
|
*
|
@@ -9283,13 +9640,13 @@ var Account = class extends AbstractAccount {
|
|
9283
9640
|
* Check the migration guide https://docs.fuel.network/docs/fuels-ts/transactions/assemble-tx-migration-guide/ for more information.
|
9284
9641
|
*/
|
9285
9642
|
async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [], gasPrice } = {}) {
|
9286
|
-
const txRequestClone = (0,
|
9643
|
+
const txRequestClone = (0, import_ramda10.clone)(transactionRequestify(transactionRequestLike));
|
9287
9644
|
const baseAssetId = await this.provider.getBaseAssetId();
|
9288
9645
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
9289
9646
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
9290
|
-
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0,
|
9647
|
+
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math23.bn)("100000000000000000") }];
|
9291
9648
|
const findAssetInput = /* @__PURE__ */ __name((assetId) => txRequestClone.inputs.find((input) => {
|
9292
|
-
if (input.type ===
|
9649
|
+
if (input.type === import_transactions29.InputType.Coin) {
|
9293
9650
|
return input.assetId === assetId;
|
9294
9651
|
}
|
9295
9652
|
if (isRequestInputMessageWithoutData(input)) {
|
@@ -9335,7 +9692,7 @@ var Account = class extends AbstractAccount {
|
|
9335
9692
|
*/
|
9336
9693
|
async signMessage(message) {
|
9337
9694
|
if (!this._connector) {
|
9338
|
-
throw new
|
9695
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
9339
9696
|
}
|
9340
9697
|
return this._connector.signMessage(this.address.toString(), message);
|
9341
9698
|
}
|
@@ -9347,8 +9704,8 @@ var Account = class extends AbstractAccount {
|
|
9347
9704
|
*/
|
9348
9705
|
async signTransaction(transactionRequestLike, connectorOptions = {}) {
|
9349
9706
|
if (!this._connector) {
|
9350
|
-
throw new
|
9351
|
-
|
9707
|
+
throw new import_errors23.FuelError(
|
9708
|
+
import_errors23.ErrorCode.MISSING_CONNECTOR,
|
9352
9709
|
"A connector is required to sign transactions."
|
9353
9710
|
);
|
9354
9711
|
}
|
@@ -9415,8 +9772,8 @@ var Account = class extends AbstractAccount {
|
|
9415
9772
|
return coins.map((coin) => ({
|
9416
9773
|
id: (0, import_utils37.hexlify)((0, import_crypto2.randomBytes)(import_abi_coder9.UTXO_ID_LEN)),
|
9417
9774
|
owner: this.address,
|
9418
|
-
blockCreated: (0,
|
9419
|
-
txCreatedIdx: (0,
|
9775
|
+
blockCreated: (0, import_math23.bn)(1),
|
9776
|
+
txCreatedIdx: (0, import_math23.bn)(1),
|
9420
9777
|
...coin
|
9421
9778
|
}));
|
9422
9779
|
}
|
@@ -9443,73 +9800,50 @@ var Account = class extends AbstractAccount {
|
|
9443
9800
|
} : void 0;
|
9444
9801
|
}
|
9445
9802
|
/** @hidden * */
|
9446
|
-
async assembleTx(
|
9447
|
-
const
|
9448
|
-
transactionRequest.
|
9449
|
-
transactionRequest.
|
9450
|
-
|
9451
|
-
|
9452
|
-
|
9453
|
-
|
9454
|
-
|
9455
|
-
|
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
|
+
}
|
9456
9829
|
}
|
9457
9830
|
/** @hidden * */
|
9458
9831
|
validateTransferAmount(amount) {
|
9459
|
-
if ((0,
|
9460
|
-
throw new
|
9461
|
-
|
9832
|
+
if ((0, import_math23.bn)(amount).lte(0)) {
|
9833
|
+
throw new import_errors23.FuelError(
|
9834
|
+
import_errors23.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
9462
9835
|
"Transfer amount must be a positive number."
|
9463
9836
|
);
|
9464
9837
|
}
|
9465
9838
|
}
|
9466
9839
|
/** @hidden * */
|
9467
|
-
async estimateAndFundTransaction(transactionRequest, txParams, costParams) {
|
9468
|
-
let request2 = transactionRequest;
|
9469
|
-
const txCost = await this.getTransactionCost(request2, costParams);
|
9470
|
-
request2 = this.validateGasLimitAndMaxFee({
|
9471
|
-
transactionRequest: request2,
|
9472
|
-
gasUsed: txCost.gasUsed,
|
9473
|
-
maxFee: txCost.maxFee,
|
9474
|
-
txParams
|
9475
|
-
});
|
9476
|
-
request2 = await this.fund(request2, txCost);
|
9477
|
-
return request2;
|
9478
|
-
}
|
9479
|
-
/** @hidden * */
|
9480
|
-
validateGasLimitAndMaxFee({
|
9481
|
-
gasUsed,
|
9482
|
-
maxFee,
|
9483
|
-
transactionRequest,
|
9484
|
-
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
|
9485
|
-
}) {
|
9486
|
-
const request2 = transactionRequestify(transactionRequest);
|
9487
|
-
if (!(0, import_utils37.isDefined)(setGasLimit)) {
|
9488
|
-
request2.gasLimit = gasUsed;
|
9489
|
-
} else if (gasUsed.gt(setGasLimit)) {
|
9490
|
-
throw new import_errors22.FuelError(
|
9491
|
-
import_errors22.ErrorCode.GAS_LIMIT_TOO_LOW,
|
9492
|
-
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
9493
|
-
);
|
9494
|
-
}
|
9495
|
-
if (!(0, import_utils37.isDefined)(setMaxFee)) {
|
9496
|
-
request2.maxFee = maxFee;
|
9497
|
-
} else if (maxFee.gt(setMaxFee)) {
|
9498
|
-
throw new import_errors22.FuelError(
|
9499
|
-
import_errors22.ErrorCode.MAX_FEE_TOO_LOW,
|
9500
|
-
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
9501
|
-
);
|
9502
|
-
}
|
9503
|
-
return request2;
|
9504
|
-
}
|
9505
|
-
/** @hidden * */
|
9506
9840
|
validateConsolidationTxsCoins(coins, assetId) {
|
9507
9841
|
if (coins.length <= 1) {
|
9508
|
-
throw new
|
9842
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NO_COINS_TO_CONSOLIDATE, "No coins to consolidate.");
|
9509
9843
|
}
|
9510
9844
|
if (!coins.every((c) => c.assetId === assetId)) {
|
9511
|
-
throw new
|
9512
|
-
|
9845
|
+
throw new import_errors23.FuelError(
|
9846
|
+
import_errors23.ErrorCode.COINS_ASSET_ID_MISMATCH,
|
9513
9847
|
"All coins to consolidate must be from the same asset id."
|
9514
9848
|
);
|
9515
9849
|
}
|
@@ -9538,10 +9872,10 @@ var import_hasher4 = require("@fuel-ts/hasher");
|
|
9538
9872
|
var import_utils40 = require("@fuel-ts/utils");
|
9539
9873
|
|
9540
9874
|
// src/signer/signer.ts
|
9541
|
-
var
|
9875
|
+
var import_address7 = require("@fuel-ts/address");
|
9542
9876
|
var import_crypto3 = require("@fuel-ts/crypto");
|
9543
9877
|
var import_hasher3 = require("@fuel-ts/hasher");
|
9544
|
-
var
|
9878
|
+
var import_math24 = require("@fuel-ts/math");
|
9545
9879
|
var import_utils38 = require("@fuel-ts/utils");
|
9546
9880
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
9547
9881
|
var Signer = class _Signer {
|
@@ -9564,11 +9898,11 @@ var Signer = class _Signer {
|
|
9564
9898
|
privateKey = `0x${privateKey}`;
|
9565
9899
|
}
|
9566
9900
|
}
|
9567
|
-
const privateKeyBytes = (0,
|
9901
|
+
const privateKeyBytes = (0, import_math24.toBytes)(privateKey, 32);
|
9568
9902
|
this.privateKey = (0, import_utils38.hexlify)(privateKeyBytes);
|
9569
9903
|
this.publicKey = (0, import_utils38.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
9570
9904
|
this.compressedPublicKey = (0, import_utils38.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
9571
|
-
this.address = new
|
9905
|
+
this.address = new import_address7.Address(this.publicKey);
|
9572
9906
|
}
|
9573
9907
|
/**
|
9574
9908
|
* Sign data using the Signer instance
|
@@ -9582,8 +9916,8 @@ var Signer = class _Signer {
|
|
9582
9916
|
*/
|
9583
9917
|
sign(data) {
|
9584
9918
|
const signature = import_secp256k1.secp256k1.sign((0, import_utils38.arrayify)(data), (0, import_utils38.arrayify)(this.privateKey));
|
9585
|
-
const r = (0,
|
9586
|
-
const s = (0,
|
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);
|
9587
9921
|
s[0] |= (signature.recovery || 0) << 7;
|
9588
9922
|
return (0, import_utils38.hexlify)((0, import_utils38.concat)([r, s]));
|
9589
9923
|
}
|
@@ -9626,7 +9960,7 @@ var Signer = class _Signer {
|
|
9626
9960
|
* @returns Address from signature
|
9627
9961
|
*/
|
9628
9962
|
static recoverAddress(data, signature) {
|
9629
|
-
return new
|
9963
|
+
return new import_address7.Address(_Signer.recoverPublicKey(data, signature));
|
9630
9964
|
}
|
9631
9965
|
/**
|
9632
9966
|
* Generate a random privateKey
|
@@ -9650,9 +9984,9 @@ var Signer = class _Signer {
|
|
9650
9984
|
};
|
9651
9985
|
|
9652
9986
|
// src/wallet/keystore-wallet.ts
|
9653
|
-
var
|
9987
|
+
var import_address8 = require("@fuel-ts/address");
|
9654
9988
|
var import_crypto4 = require("@fuel-ts/crypto");
|
9655
|
-
var
|
9989
|
+
var import_errors24 = require("@fuel-ts/errors");
|
9656
9990
|
var import_utils39 = require("@fuel-ts/utils");
|
9657
9991
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
9658
9992
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -9667,7 +10001,7 @@ var removeHexPrefix = /* @__PURE__ */ __name((hexString) => {
|
|
9667
10001
|
}, "removeHexPrefix");
|
9668
10002
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
9669
10003
|
const privateKeyBuffer = (0, import_crypto4.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
9670
|
-
const ownerAddress = new
|
10004
|
+
const ownerAddress = new import_address8.Address(address);
|
9671
10005
|
const salt = (0, import_crypto4.randomBytes)(DEFAULT_KEY_SIZE);
|
9672
10006
|
const key = (0, import_crypto4.scrypt)({
|
9673
10007
|
password: (0, import_crypto4.bufferFromString)(password),
|
@@ -9730,8 +10064,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
9730
10064
|
const macHashUint8Array = (0, import_crypto4.keccak256)(data);
|
9731
10065
|
const macHash = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
|
9732
10066
|
if (mac !== macHash) {
|
9733
|
-
throw new
|
9734
|
-
|
10067
|
+
throw new import_errors24.FuelError(
|
10068
|
+
import_errors24.ErrorCode.INVALID_PASSWORD,
|
9735
10069
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
9736
10070
|
);
|
9737
10071
|
}
|
@@ -9870,14 +10204,14 @@ var BaseWalletUnlocked = class extends Account {
|
|
9870
10204
|
|
9871
10205
|
// src/hdwallet/hdwallet.ts
|
9872
10206
|
var import_crypto6 = require("@fuel-ts/crypto");
|
9873
|
-
var
|
10207
|
+
var import_errors27 = require("@fuel-ts/errors");
|
9874
10208
|
var import_hasher7 = require("@fuel-ts/hasher");
|
9875
|
-
var
|
10209
|
+
var import_math25 = require("@fuel-ts/math");
|
9876
10210
|
var import_utils44 = require("@fuel-ts/utils");
|
9877
10211
|
|
9878
10212
|
// src/mnemonic/mnemonic.ts
|
9879
10213
|
var import_crypto5 = require("@fuel-ts/crypto");
|
9880
|
-
var
|
10214
|
+
var import_errors26 = require("@fuel-ts/errors");
|
9881
10215
|
var import_hasher6 = require("@fuel-ts/hasher");
|
9882
10216
|
var import_utils42 = require("@fuel-ts/utils");
|
9883
10217
|
|
@@ -11940,7 +12274,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
11940
12274
|
})(Language || {});
|
11941
12275
|
|
11942
12276
|
// src/mnemonic/utils.ts
|
11943
|
-
var
|
12277
|
+
var import_errors25 = require("@fuel-ts/errors");
|
11944
12278
|
var import_hasher5 = require("@fuel-ts/hasher");
|
11945
12279
|
var import_utils41 = require("@fuel-ts/utils");
|
11946
12280
|
function getLowerMask(bits) {
|
@@ -11994,8 +12328,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
11994
12328
|
for (let i = 0; i < words.length; i += 1) {
|
11995
12329
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
11996
12330
|
if (index === -1) {
|
11997
|
-
throw new
|
11998
|
-
|
12331
|
+
throw new import_errors25.FuelError(
|
12332
|
+
import_errors25.ErrorCode.INVALID_MNEMONIC,
|
11999
12333
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
12000
12334
|
);
|
12001
12335
|
}
|
@@ -12011,8 +12345,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
12011
12345
|
const checksumMask = getUpperMask(checksumBits);
|
12012
12346
|
const checksum = (0, import_utils41.arrayify)((0, import_hasher5.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
12013
12347
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
12014
|
-
throw new
|
12015
|
-
|
12348
|
+
throw new import_errors25.FuelError(
|
12349
|
+
import_errors25.ErrorCode.INVALID_CHECKSUM,
|
12016
12350
|
"Checksum validation failed for the provided mnemonic."
|
12017
12351
|
);
|
12018
12352
|
}
|
@@ -12027,8 +12361,8 @@ var TestnetPRV = "0x04358394";
|
|
12027
12361
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
12028
12362
|
function assertWordList(wordlist) {
|
12029
12363
|
if (wordlist.length !== 2048) {
|
12030
|
-
throw new
|
12031
|
-
|
12364
|
+
throw new import_errors26.FuelError(
|
12365
|
+
import_errors26.ErrorCode.INVALID_WORD_LIST,
|
12032
12366
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
12033
12367
|
);
|
12034
12368
|
}
|
@@ -12036,8 +12370,8 @@ function assertWordList(wordlist) {
|
|
12036
12370
|
__name(assertWordList, "assertWordList");
|
12037
12371
|
function assertEntropy(entropy) {
|
12038
12372
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
12039
|
-
throw new
|
12040
|
-
|
12373
|
+
throw new import_errors26.FuelError(
|
12374
|
+
import_errors26.ErrorCode.INVALID_ENTROPY,
|
12041
12375
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
12042
12376
|
);
|
12043
12377
|
}
|
@@ -12048,7 +12382,7 @@ function assertMnemonic(words) {
|
|
12048
12382
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
12049
12383
|
", "
|
12050
12384
|
)}] words, but got ${words.length}.`;
|
12051
|
-
throw new
|
12385
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
12052
12386
|
}
|
12053
12387
|
}
|
12054
12388
|
__name(assertMnemonic, "assertMnemonic");
|
@@ -12170,8 +12504,8 @@ var Mnemonic = class _Mnemonic {
|
|
12170
12504
|
static masterKeysFromSeed(seed) {
|
12171
12505
|
const seedArray = (0, import_utils42.arrayify)(seed);
|
12172
12506
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
12173
|
-
throw new
|
12174
|
-
|
12507
|
+
throw new import_errors26.FuelError(
|
12508
|
+
import_errors26.ErrorCode.INVALID_SEED,
|
12175
12509
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
12176
12510
|
);
|
12177
12511
|
}
|
@@ -12252,7 +12586,7 @@ __name(isValidExtendedKey, "isValidExtendedKey");
|
|
12252
12586
|
function parsePath(path, depth = 0) {
|
12253
12587
|
const components = path.split("/");
|
12254
12588
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
12255
|
-
throw new
|
12589
|
+
throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path}`);
|
12256
12590
|
}
|
12257
12591
|
if (components[0] === "m") {
|
12258
12592
|
components.shift();
|
@@ -12285,8 +12619,8 @@ var HDWallet = class _HDWallet {
|
|
12285
12619
|
this.privateKey = (0, import_utils44.hexlify)(config.privateKey);
|
12286
12620
|
} else {
|
12287
12621
|
if (!config.publicKey) {
|
12288
|
-
throw new
|
12289
|
-
|
12622
|
+
throw new import_errors27.FuelError(
|
12623
|
+
import_errors27.ErrorCode.HD_WALLET_ERROR,
|
12290
12624
|
"Both public and private Key cannot be missing. At least one should be provided."
|
12291
12625
|
);
|
12292
12626
|
}
|
@@ -12315,8 +12649,8 @@ var HDWallet = class _HDWallet {
|
|
12315
12649
|
const data = new Uint8Array(37);
|
12316
12650
|
if (index & HARDENED_INDEX) {
|
12317
12651
|
if (!privateKey) {
|
12318
|
-
throw new
|
12319
|
-
|
12652
|
+
throw new import_errors27.FuelError(
|
12653
|
+
import_errors27.ErrorCode.HD_WALLET_ERROR,
|
12320
12654
|
"Cannot derive a hardened index without a private Key."
|
12321
12655
|
);
|
12322
12656
|
}
|
@@ -12324,13 +12658,13 @@ var HDWallet = class _HDWallet {
|
|
12324
12658
|
} else {
|
12325
12659
|
data.set((0, import_utils44.arrayify)(this.publicKey));
|
12326
12660
|
}
|
12327
|
-
data.set((0,
|
12661
|
+
data.set((0, import_math25.toBytes)(index, 4), 33);
|
12328
12662
|
const bytes = (0, import_utils44.arrayify)((0, import_crypto6.computeHmac)("sha512", chainCode, data));
|
12329
12663
|
const IL = bytes.slice(0, 32);
|
12330
12664
|
const IR = bytes.slice(32);
|
12331
12665
|
if (privateKey) {
|
12332
12666
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
12333
|
-
const ki = (0,
|
12667
|
+
const ki = (0, import_math25.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
12334
12668
|
return new _HDWallet({
|
12335
12669
|
privateKey: ki,
|
12336
12670
|
chainCode: IR,
|
@@ -12368,15 +12702,15 @@ var HDWallet = class _HDWallet {
|
|
12368
12702
|
*/
|
12369
12703
|
toExtendedKey(isPublic = false, testnet = false) {
|
12370
12704
|
if (this.depth >= 256) {
|
12371
|
-
throw new
|
12372
|
-
|
12705
|
+
throw new import_errors27.FuelError(
|
12706
|
+
import_errors27.ErrorCode.HD_WALLET_ERROR,
|
12373
12707
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
12374
12708
|
);
|
12375
12709
|
}
|
12376
12710
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
12377
12711
|
const depth = (0, import_utils44.hexlify)(Uint8Array.from([this.depth]));
|
12378
12712
|
const parentFingerprint = this.parentFingerprint;
|
12379
|
-
const index = (0,
|
12713
|
+
const index = (0, import_math25.toHex)(this.index, 4);
|
12380
12714
|
const chainCode = this.chainCode;
|
12381
12715
|
const key = this.privateKey != null && !isPublic ? (0, import_utils44.concat)(["0x00", this.privateKey]) : this.publicKey;
|
12382
12716
|
const extendedKey = (0, import_utils44.arrayify)((0, import_utils44.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
@@ -12396,14 +12730,14 @@ var HDWallet = class _HDWallet {
|
|
12396
12730
|
});
|
12397
12731
|
}
|
12398
12732
|
static fromExtendedKey(extendedKey) {
|
12399
|
-
const decoded = (0, import_utils44.hexlify)((0,
|
12733
|
+
const decoded = (0, import_utils44.hexlify)((0, import_math25.toBytes)((0, import_utils44.decodeBase58)(extendedKey)));
|
12400
12734
|
const bytes = (0, import_utils44.arrayify)(decoded);
|
12401
12735
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
12402
12736
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
12403
|
-
throw new
|
12737
|
+
throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
12404
12738
|
}
|
12405
12739
|
if (!validChecksum) {
|
12406
|
-
throw new
|
12740
|
+
throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
12407
12741
|
}
|
12408
12742
|
const depth = bytes[4];
|
12409
12743
|
const parentFingerprint = (0, import_utils44.hexlify)(bytes.slice(5, 9));
|
@@ -12411,14 +12745,14 @@ var HDWallet = class _HDWallet {
|
|
12411
12745
|
const chainCode = (0, import_utils44.hexlify)(bytes.slice(13, 45));
|
12412
12746
|
const key = bytes.slice(45, 78);
|
12413
12747
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
12414
|
-
throw new
|
12415
|
-
|
12748
|
+
throw new import_errors27.FuelError(
|
12749
|
+
import_errors27.ErrorCode.HD_WALLET_ERROR,
|
12416
12750
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
12417
12751
|
);
|
12418
12752
|
}
|
12419
12753
|
if (isPublicExtendedKey(bytes)) {
|
12420
12754
|
if (key[0] !== 3) {
|
12421
|
-
throw new
|
12755
|
+
throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
12422
12756
|
}
|
12423
12757
|
return new _HDWallet({
|
12424
12758
|
publicKey: key,
|
@@ -12429,7 +12763,7 @@ var HDWallet = class _HDWallet {
|
|
12429
12763
|
});
|
12430
12764
|
}
|
12431
12765
|
if (key[0] !== 0) {
|
12432
|
-
throw new
|
12766
|
+
throw new import_errors27.FuelError(import_errors27.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
12433
12767
|
}
|
12434
12768
|
return new _HDWallet({
|
12435
12769
|
privateKey: key.slice(1),
|
@@ -12604,9 +12938,9 @@ var Wallet = class {
|
|
12604
12938
|
};
|
12605
12939
|
|
12606
12940
|
// src/wallet-manager/wallet-manager.ts
|
12607
|
-
var
|
12941
|
+
var import_address11 = require("@fuel-ts/address");
|
12608
12942
|
var import_crypto7 = require("@fuel-ts/crypto");
|
12609
|
-
var
|
12943
|
+
var import_errors30 = require("@fuel-ts/errors");
|
12610
12944
|
var import_events = require("events");
|
12611
12945
|
|
12612
12946
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -12631,8 +12965,8 @@ var MemoryStorage = class {
|
|
12631
12965
|
};
|
12632
12966
|
|
12633
12967
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
12634
|
-
var
|
12635
|
-
var
|
12968
|
+
var import_address9 = require("@fuel-ts/address");
|
12969
|
+
var import_errors28 = require("@fuel-ts/errors");
|
12636
12970
|
var MnemonicVault = class {
|
12637
12971
|
static {
|
12638
12972
|
__name(this, "MnemonicVault");
|
@@ -12683,7 +13017,7 @@ var MnemonicVault = class {
|
|
12683
13017
|
}
|
12684
13018
|
exportAccount(address) {
|
12685
13019
|
let numberOfAccounts = 0;
|
12686
|
-
const ownerAddress = new
|
13020
|
+
const ownerAddress = new import_address9.Address(address);
|
12687
13021
|
do {
|
12688
13022
|
const wallet = Wallet.fromMnemonic(this.#secret, this.getDerivePath(numberOfAccounts));
|
12689
13023
|
if (wallet.address.equals(ownerAddress)) {
|
@@ -12691,8 +13025,8 @@ var MnemonicVault = class {
|
|
12691
13025
|
}
|
12692
13026
|
numberOfAccounts += 1;
|
12693
13027
|
} while (numberOfAccounts < this.numberOfAccounts);
|
12694
|
-
throw new
|
12695
|
-
|
13028
|
+
throw new import_errors28.FuelError(
|
13029
|
+
import_errors28.ErrorCode.WALLET_MANAGER_ERROR,
|
12696
13030
|
`Account with address '${address}' not found in derived wallets.`
|
12697
13031
|
);
|
12698
13032
|
}
|
@@ -12703,8 +13037,8 @@ var MnemonicVault = class {
|
|
12703
13037
|
};
|
12704
13038
|
|
12705
13039
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
12706
|
-
var
|
12707
|
-
var
|
13040
|
+
var import_address10 = require("@fuel-ts/address");
|
13041
|
+
var import_errors29 = require("@fuel-ts/errors");
|
12708
13042
|
var PrivateKeyVault = class {
|
12709
13043
|
static {
|
12710
13044
|
__name(this, "PrivateKeyVault");
|
@@ -12743,13 +13077,13 @@ var PrivateKeyVault = class {
|
|
12743
13077
|
return this.getPublicAccount(wallet.privateKey);
|
12744
13078
|
}
|
12745
13079
|
exportAccount(address) {
|
12746
|
-
const ownerAddress = new
|
13080
|
+
const ownerAddress = new import_address10.Address(address);
|
12747
13081
|
const privateKey = this.#privateKeys.find(
|
12748
13082
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
12749
13083
|
);
|
12750
13084
|
if (!privateKey) {
|
12751
|
-
throw new
|
12752
|
-
|
13085
|
+
throw new import_errors29.FuelError(
|
13086
|
+
import_errors29.ErrorCode.WALLET_MANAGER_ERROR,
|
12753
13087
|
`No private key found for address '${address}'.`
|
12754
13088
|
);
|
12755
13089
|
}
|
@@ -12771,7 +13105,7 @@ var ERROR_MESSAGES = {
|
|
12771
13105
|
};
|
12772
13106
|
function assert(condition, message) {
|
12773
13107
|
if (!condition) {
|
12774
|
-
throw new
|
13108
|
+
throw new import_errors30.FuelError(import_errors30.ErrorCode.WALLET_MANAGER_ERROR, message);
|
12775
13109
|
}
|
12776
13110
|
}
|
12777
13111
|
__name(assert, "assert");
|
@@ -12840,7 +13174,7 @@ var WalletManager = class _WalletManager extends import_events.EventEmitter {
|
|
12840
13174
|
* Create a Wallet instance for the specific account
|
12841
13175
|
*/
|
12842
13176
|
getWallet(address) {
|
12843
|
-
const ownerAddress = new
|
13177
|
+
const ownerAddress = new import_address11.Address(address);
|
12844
13178
|
const vaultState = this.#vaults.find(
|
12845
13179
|
(vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
|
12846
13180
|
);
|
@@ -12851,7 +13185,7 @@ var WalletManager = class _WalletManager extends import_events.EventEmitter {
|
|
12851
13185
|
* Export specific account privateKey
|
12852
13186
|
*/
|
12853
13187
|
exportPrivateKey(address) {
|
12854
|
-
const ownerAddress = new
|
13188
|
+
const ownerAddress = new import_address11.Address(address);
|
12855
13189
|
assert(!this.#isLocked, ERROR_MESSAGES.wallet_not_unlocked);
|
12856
13190
|
const vaultState = this.#vaults.find(
|
12857
13191
|
(vs) => vs.vault.getAccounts().find((a) => a.address.equals(ownerAddress))
|
@@ -12992,29 +13326,29 @@ var WalletManager = class _WalletManager extends import_events.EventEmitter {
|
|
12992
13326
|
};
|
12993
13327
|
|
12994
13328
|
// src/wallet-manager/types.ts
|
12995
|
-
var
|
13329
|
+
var import_errors31 = require("@fuel-ts/errors");
|
12996
13330
|
var Vault = class {
|
12997
13331
|
static {
|
12998
13332
|
__name(this, "Vault");
|
12999
13333
|
}
|
13000
13334
|
static type;
|
13001
13335
|
constructor(_options) {
|
13002
|
-
throw new
|
13336
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
13003
13337
|
}
|
13004
13338
|
serialize() {
|
13005
|
-
throw new
|
13339
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
13006
13340
|
}
|
13007
13341
|
getAccounts() {
|
13008
|
-
throw new
|
13342
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
13009
13343
|
}
|
13010
13344
|
addAccount() {
|
13011
|
-
throw new
|
13345
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
13012
13346
|
}
|
13013
13347
|
exportAccount(_address) {
|
13014
|
-
throw new
|
13348
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
13015
13349
|
}
|
13016
13350
|
getWallet(_address) {
|
13017
|
-
throw new
|
13351
|
+
throw new import_errors31.FuelError(import_errors31.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
13018
13352
|
}
|
13019
13353
|
};
|
13020
13354
|
var StorageAbstract = class {
|
@@ -13025,12 +13359,12 @@ var StorageAbstract = class {
|
|
13025
13359
|
|
13026
13360
|
// src/predicate/predicate.ts
|
13027
13361
|
var import_abi_coder11 = require("@fuel-ts/abi-coder");
|
13028
|
-
var
|
13029
|
-
var
|
13362
|
+
var import_address12 = require("@fuel-ts/address");
|
13363
|
+
var import_errors33 = require("@fuel-ts/errors");
|
13030
13364
|
var import_utils48 = require("@fuel-ts/utils");
|
13031
13365
|
|
13032
13366
|
// src/utils/deployScriptOrPredicate.ts
|
13033
|
-
var
|
13367
|
+
var import_errors32 = require("@fuel-ts/errors");
|
13034
13368
|
var import_utils46 = require("@fuel-ts/utils");
|
13035
13369
|
|
13036
13370
|
// src/utils/predicate-script-loader-instructions.ts
|
@@ -13237,7 +13571,7 @@ async function deployScriptOrPredicate({
|
|
13237
13571
|
throw new Error();
|
13238
13572
|
}
|
13239
13573
|
} catch (err) {
|
13240
|
-
throw new
|
13574
|
+
throw new import_errors32.FuelError(import_errors32.ErrorCode.TRANSACTION_FAILED, "Failed to deploy predicate chunk");
|
13241
13575
|
}
|
13242
13576
|
return loaderInstance;
|
13243
13577
|
}, "waitForResult");
|
@@ -13292,7 +13626,7 @@ var Predicate = class _Predicate extends Account {
|
|
13292
13626
|
abi,
|
13293
13627
|
configurableConstants
|
13294
13628
|
);
|
13295
|
-
const address = new
|
13629
|
+
const address = new import_address12.Address(getPredicateRoot(predicateBytes));
|
13296
13630
|
super(address, provider);
|
13297
13631
|
this.initialBytecode = (0, import_utils48.arrayify)(bytecode);
|
13298
13632
|
this.bytes = predicateBytes;
|
@@ -13389,8 +13723,8 @@ var Predicate = class _Predicate extends Account {
|
|
13389
13723
|
let predicateBytes = (0, import_utils48.arrayify)(bytes);
|
13390
13724
|
const abiInterface = new import_abi_coder11.Interface(jsonAbi);
|
13391
13725
|
if (abiInterface.functions.main === void 0) {
|
13392
|
-
throw new
|
13393
|
-
|
13726
|
+
throw new import_errors33.FuelError(
|
13727
|
+
import_errors33.ErrorCode.ABI_MAIN_METHOD_MISSING,
|
13394
13728
|
'Cannot use ABI without "main" function.'
|
13395
13729
|
);
|
13396
13730
|
}
|
@@ -13450,15 +13784,15 @@ var Predicate = class _Predicate extends Account {
|
|
13450
13784
|
const mutatedBytes = bytes;
|
13451
13785
|
try {
|
13452
13786
|
if (Object.keys(abiInterface.configurables).length === 0) {
|
13453
|
-
throw new
|
13454
|
-
|
13787
|
+
throw new import_errors33.FuelError(
|
13788
|
+
import_errors33.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
13455
13789
|
"Predicate has no configurable constants to be set"
|
13456
13790
|
);
|
13457
13791
|
}
|
13458
13792
|
Object.entries(configurableConstants).forEach(([key, value]) => {
|
13459
13793
|
if (!abiInterface?.configurables[key]) {
|
13460
|
-
throw new
|
13461
|
-
|
13794
|
+
throw new import_errors33.FuelError(
|
13795
|
+
import_errors33.ErrorCode.CONFIGURABLE_NOT_FOUND,
|
13462
13796
|
`No configurable constant named '${key}' found in the Predicate`
|
13463
13797
|
);
|
13464
13798
|
}
|
@@ -13467,8 +13801,8 @@ var Predicate = class _Predicate extends Account {
|
|
13467
13801
|
mutatedBytes.set(encoded, offset);
|
13468
13802
|
});
|
13469
13803
|
} catch (err) {
|
13470
|
-
throw new
|
13471
|
-
|
13804
|
+
throw new import_errors33.FuelError(
|
13805
|
+
import_errors33.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
13472
13806
|
`Error setting configurable constants: ${err.message}.`
|
13473
13807
|
);
|
13474
13808
|
}
|
@@ -13521,10 +13855,10 @@ var Predicate = class _Predicate extends Account {
|
|
13521
13855
|
};
|
13522
13856
|
|
13523
13857
|
// src/connectors/fuel.ts
|
13524
|
-
var
|
13858
|
+
var import_errors36 = require("@fuel-ts/errors");
|
13525
13859
|
|
13526
13860
|
// src/connectors/fuel-connector.ts
|
13527
|
-
var
|
13861
|
+
var import_errors34 = require("@fuel-ts/errors");
|
13528
13862
|
var import_events2 = require("events");
|
13529
13863
|
|
13530
13864
|
// src/connectors/types/connector-types.ts
|
@@ -13549,6 +13883,7 @@ var FuelConnectorMethods = /* @__PURE__ */ ((FuelConnectorMethods2) => {
|
|
13549
13883
|
FuelConnectorMethods2["addABI"] = "addABI";
|
13550
13884
|
FuelConnectorMethods2["getABI"] = "getABI";
|
13551
13885
|
FuelConnectorMethods2["hasABI"] = "hasABI";
|
13886
|
+
FuelConnectorMethods2["startConsolidation"] = "startConsolidation";
|
13552
13887
|
return FuelConnectorMethods2;
|
13553
13888
|
})(FuelConnectorMethods || {});
|
13554
13889
|
var FuelConnectorEventTypes = /* @__PURE__ */ ((FuelConnectorEventTypes2) => {
|
@@ -13561,6 +13896,7 @@ var FuelConnectorEventTypes = /* @__PURE__ */ ((FuelConnectorEventTypes2) => {
|
|
13561
13896
|
FuelConnectorEventTypes2["currentNetwork"] = "currentNetwork";
|
13562
13897
|
FuelConnectorEventTypes2["assets"] = "assets";
|
13563
13898
|
FuelConnectorEventTypes2["abis"] = "abis";
|
13899
|
+
FuelConnectorEventTypes2["consolidateCoins"] = "consolidateCoins";
|
13564
13900
|
return FuelConnectorEventTypes2;
|
13565
13901
|
})(FuelConnectorEventTypes || {});
|
13566
13902
|
var FuelConnectorEventType = "FuelConnector";
|
@@ -13606,7 +13942,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13606
13942
|
* @returns Always true.
|
13607
13943
|
*/
|
13608
13944
|
async ping() {
|
13609
|
-
throw new
|
13945
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13610
13946
|
}
|
13611
13947
|
/**
|
13612
13948
|
* Should return the current version of the connector
|
@@ -13615,7 +13951,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13615
13951
|
* @returns boolean - connection status.
|
13616
13952
|
*/
|
13617
13953
|
async version() {
|
13618
|
-
throw new
|
13954
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13619
13955
|
}
|
13620
13956
|
/**
|
13621
13957
|
* Should return true if the connector is connected
|
@@ -13624,7 +13960,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13624
13960
|
* @returns The connection status.
|
13625
13961
|
*/
|
13626
13962
|
async isConnected() {
|
13627
|
-
throw new
|
13963
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13628
13964
|
}
|
13629
13965
|
/**
|
13630
13966
|
* Should return all the accounts authorized for the
|
@@ -13633,7 +13969,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13633
13969
|
* @returns The accounts addresses strings
|
13634
13970
|
*/
|
13635
13971
|
async accounts() {
|
13636
|
-
throw new
|
13972
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13637
13973
|
}
|
13638
13974
|
/**
|
13639
13975
|
* Should start the connection process and return
|
@@ -13645,7 +13981,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13645
13981
|
* @returns boolean - connection status.
|
13646
13982
|
*/
|
13647
13983
|
async connect() {
|
13648
|
-
throw new
|
13984
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13649
13985
|
}
|
13650
13986
|
/**
|
13651
13987
|
* Should disconnect the current connection and
|
@@ -13655,7 +13991,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13655
13991
|
* @returns The connection status.
|
13656
13992
|
*/
|
13657
13993
|
async disconnect() {
|
13658
|
-
throw new
|
13994
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13659
13995
|
}
|
13660
13996
|
/**
|
13661
13997
|
* Should start the sign message process and return
|
@@ -13667,7 +14003,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13667
14003
|
* @returns Message signature
|
13668
14004
|
*/
|
13669
14005
|
async signMessage(_address, _message) {
|
13670
|
-
throw new
|
14006
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13671
14007
|
}
|
13672
14008
|
/**
|
13673
14009
|
* Should start the sign transaction process and return
|
@@ -13679,7 +14015,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13679
14015
|
* @returns Transaction signature
|
13680
14016
|
*/
|
13681
14017
|
async signTransaction(_address, _transaction, _params) {
|
13682
|
-
throw new
|
14018
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13683
14019
|
}
|
13684
14020
|
/**
|
13685
14021
|
* Should start the send transaction process and return
|
@@ -13695,7 +14031,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13695
14031
|
* @returns The transaction id or transaction response
|
13696
14032
|
*/
|
13697
14033
|
async sendTransaction(_address, _transaction, _params) {
|
13698
|
-
throw new
|
14034
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13699
14035
|
}
|
13700
14036
|
/**
|
13701
14037
|
* Should return the current account selected inside the connector, if the account
|
@@ -13706,7 +14042,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13706
14042
|
* @returns The current account selected otherwise null.
|
13707
14043
|
*/
|
13708
14044
|
async currentAccount() {
|
13709
|
-
throw new
|
14045
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13710
14046
|
}
|
13711
14047
|
/**
|
13712
14048
|
* Should add the assets metadata to the connector and return true if the asset
|
@@ -13720,7 +14056,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13720
14056
|
* @returns True if the asset was added successfully
|
13721
14057
|
*/
|
13722
14058
|
async addAssets(_assets) {
|
13723
|
-
throw new
|
14059
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13724
14060
|
}
|
13725
14061
|
/**
|
13726
14062
|
* Should add the asset metadata to the connector and return true if the asset
|
@@ -13734,7 +14070,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13734
14070
|
* @returns True if the asset was added successfully
|
13735
14071
|
*/
|
13736
14072
|
async addAsset(_asset) {
|
13737
|
-
throw new
|
14073
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13738
14074
|
}
|
13739
14075
|
/**
|
13740
14076
|
* Should return all the assets added to the connector. If a connection is already established.
|
@@ -13742,7 +14078,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13742
14078
|
* @returns Array of assets metadata from the connector vinculated to the all accounts from a specific Wallet.
|
13743
14079
|
*/
|
13744
14080
|
async assets() {
|
13745
|
-
throw new
|
14081
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13746
14082
|
}
|
13747
14083
|
/**
|
13748
14084
|
* Should start the add network process and return true if the network was added successfully.
|
@@ -13753,7 +14089,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13753
14089
|
* @returns Return true if the network was added successfully
|
13754
14090
|
*/
|
13755
14091
|
async addNetwork(_networkUrl) {
|
13756
|
-
throw new
|
14092
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13757
14093
|
}
|
13758
14094
|
/**
|
13759
14095
|
* Should start the select network process and return true if the network has change successfully.
|
@@ -13764,7 +14100,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13764
14100
|
* @returns Return true if the network was added successfully
|
13765
14101
|
*/
|
13766
14102
|
async selectNetwork(_network) {
|
13767
|
-
throw new
|
14103
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13768
14104
|
}
|
13769
14105
|
/**
|
13770
14106
|
* Should return all the networks available from the connector. If the connection is already established.
|
@@ -13772,7 +14108,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13772
14108
|
* @returns Return all the networks added to the connector.
|
13773
14109
|
*/
|
13774
14110
|
async networks() {
|
13775
|
-
throw new
|
14111
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13776
14112
|
}
|
13777
14113
|
/**
|
13778
14114
|
* Should return the current network selected inside the connector. Even if the connection is not established.
|
@@ -13780,7 +14116,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13780
14116
|
* @returns Return the current network selected inside the connector.
|
13781
14117
|
*/
|
13782
14118
|
async currentNetwork() {
|
13783
|
-
throw new
|
14119
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13784
14120
|
}
|
13785
14121
|
/**
|
13786
14122
|
* Should add the ABI to the connector and return true if the ABI was added successfully.
|
@@ -13790,7 +14126,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13790
14126
|
* @returns Return true if the ABI was added successfully.
|
13791
14127
|
*/
|
13792
14128
|
async addABI(_contractId, _abi) {
|
13793
|
-
throw new
|
14129
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13794
14130
|
}
|
13795
14131
|
/**
|
13796
14132
|
* Should return the ABI from the connector vinculated to the all accounts from a specific Wallet.
|
@@ -13799,7 +14135,7 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13799
14135
|
* @returns The ABI if it exists, otherwise return null.
|
13800
14136
|
*/
|
13801
14137
|
async getABI(_id) {
|
13802
|
-
throw new
|
14138
|
+
throw new import_errors34.FuelError(import_errors34.FuelError.CODES.NOT_IMPLEMENTED, "Method not implemented.");
|
13803
14139
|
}
|
13804
14140
|
/**
|
13805
14141
|
* Should return true if the abi exists in the connector vinculated to the all accounts from a specific Wallet.
|
@@ -13808,7 +14144,16 @@ var FuelConnector = class extends import_events2.EventEmitter {
|
|
13808
14144
|
* @returns Returns true if the abi exists or false if not.
|
13809
14145
|
*/
|
13810
14146
|
async hasABI(_id) {
|
13811
|
-
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.");
|
13812
14157
|
}
|
13813
14158
|
/**
|
13814
14159
|
* Event listener for the connector.
|
@@ -13854,7 +14199,7 @@ function dispatchFuelConnectorEvent(connector) {
|
|
13854
14199
|
__name(dispatchFuelConnectorEvent, "dispatchFuelConnectorEvent");
|
13855
14200
|
|
13856
14201
|
// src/connectors/utils/promises.ts
|
13857
|
-
var
|
14202
|
+
var import_errors35 = require("@fuel-ts/errors");
|
13858
14203
|
function deferPromise() {
|
13859
14204
|
const defer = {};
|
13860
14205
|
defer.promise = new Promise((resolve, reject) => {
|
@@ -13867,7 +14212,7 @@ __name(deferPromise, "deferPromise");
|
|
13867
14212
|
async function withTimeout(promise, timeout = 1050) {
|
13868
14213
|
const timeoutPromise = new Promise((resolve, reject) => {
|
13869
14214
|
setTimeout(() => {
|
13870
|
-
reject(new
|
14215
|
+
reject(new import_errors35.FuelError(import_errors35.FuelError.CODES.TIMEOUT_EXCEEDED, "Promise timed out"));
|
13871
14216
|
}, timeout);
|
13872
14217
|
});
|
13873
14218
|
return Promise.race([timeoutPromise, promise]);
|
@@ -13908,7 +14253,7 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
13908
14253
|
this._targetUnsubscribe = this.setupConnectorListener();
|
13909
14254
|
await connectResponse;
|
13910
14255
|
} catch (error) {
|
13911
|
-
throw new
|
14256
|
+
throw new import_errors36.FuelError(import_errors36.ErrorCode.INVALID_PROVIDER, "Error initializing Fuel Connector");
|
13912
14257
|
}
|
13913
14258
|
}
|
13914
14259
|
async init() {
|
@@ -13974,8 +14319,8 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
13974
14319
|
const hasConnector = await this.hasConnector();
|
13975
14320
|
await this.pingConnector();
|
13976
14321
|
if (!this._currentConnector || !hasConnector) {
|
13977
|
-
throw new
|
13978
|
-
|
14322
|
+
throw new import_errors36.FuelError(
|
14323
|
+
import_errors36.ErrorCode.MISSING_CONNECTOR,
|
13979
14324
|
`No connector selected for calling ${method}. Use hasConnector before executing other methods.`
|
13980
14325
|
);
|
13981
14326
|
}
|
@@ -14039,7 +14384,7 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
14039
14384
|
cacheTime: PING_CACHE_TIME
|
14040
14385
|
})();
|
14041
14386
|
} catch {
|
14042
|
-
throw new
|
14387
|
+
throw new import_errors36.FuelError(import_errors36.ErrorCode.INVALID_PROVIDER, "Current connector is not available.");
|
14043
14388
|
}
|
14044
14389
|
}
|
14045
14390
|
/**
|
@@ -14188,7 +14533,7 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
14188
14533
|
const currentNetwork = await this.currentNetwork();
|
14189
14534
|
provider = new Provider(currentNetwork.url);
|
14190
14535
|
} else {
|
14191
|
-
throw new
|
14536
|
+
throw new import_errors36.FuelError(import_errors36.ErrorCode.INVALID_PROVIDER, "Provider is not valid.");
|
14192
14537
|
}
|
14193
14538
|
return provider;
|
14194
14539
|
}
|
@@ -14299,6 +14644,8 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
14299
14644
|
calculateMinGasForTxUpload,
|
14300
14645
|
calculateTXFeeForSummary,
|
14301
14646
|
coinQuantityfy,
|
14647
|
+
consolidateCoins,
|
14648
|
+
consolidateCoinsIfRequired,
|
14302
14649
|
deferPromise,
|
14303
14650
|
deployScriptOrPredicate,
|
14304
14651
|
deserializeChain,
|
@@ -14317,6 +14664,7 @@ var Fuel = class _Fuel extends FuelConnector {
|
|
14317
14664
|
extractTxError,
|
14318
14665
|
fuelAssetsBaseUrl,
|
14319
14666
|
gasUsedByInputs,
|
14667
|
+
getAllCoins,
|
14320
14668
|
getAllDecodedLogs,
|
14321
14669
|
getAssetAmountInRequestInputs,
|
14322
14670
|
getAssetById,
|