@fuel-ts/account 0.0.0-rc-1976-20240403225009 → 0.0.0-rc-1895-20240404023124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +171 -63
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +578 -513
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +356 -286
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +2 -2
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +0 -7
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +2 -5
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts +36 -0
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +172 -65
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +537 -479
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +326 -260
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.mjs
CHANGED
@@ -24,12 +24,14 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
24
24
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
|
-
import {
|
27
|
+
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
28
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
|
-
import { bn as
|
30
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
30
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
31
32
|
|
32
33
|
// src/providers/coin-quantity.ts
|
34
|
+
import { BaseAssetId } from "@fuel-ts/address/configs";
|
33
35
|
import { bn } from "@fuel-ts/math";
|
34
36
|
import { hexlify } from "@fuel-ts/utils";
|
35
37
|
var coinQuantityfy = (coinQuantityLike) => {
|
@@ -38,11 +40,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
38
40
|
let max2;
|
39
41
|
if (Array.isArray(coinQuantityLike)) {
|
40
42
|
amount = coinQuantityLike[0];
|
41
|
-
assetId = coinQuantityLike[1];
|
42
|
-
max2 = coinQuantityLike[2];
|
43
|
+
assetId = coinQuantityLike[1] ?? BaseAssetId;
|
44
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
43
45
|
} else {
|
44
46
|
amount = coinQuantityLike.amount;
|
45
|
-
assetId = coinQuantityLike.assetId;
|
47
|
+
assetId = coinQuantityLike.assetId ?? BaseAssetId;
|
46
48
|
max2 = coinQuantityLike.max ?? void 0;
|
47
49
|
}
|
48
50
|
const bnAmount = bn(amount);
|
@@ -66,8 +68,8 @@ var addAmountToAsset = (params) => {
|
|
66
68
|
|
67
69
|
// src/providers/provider.ts
|
68
70
|
import { Address as Address2 } from "@fuel-ts/address";
|
69
|
-
import { ErrorCode as
|
70
|
-
import { BN, bn as
|
71
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
72
|
+
import { BN, bn as bn15, max } from "@fuel-ts/math";
|
71
73
|
import {
|
72
74
|
InputType as InputType6,
|
73
75
|
TransactionType as TransactionType8,
|
@@ -1149,8 +1151,8 @@ var outputify = (value) => {
|
|
1149
1151
|
|
1150
1152
|
// src/providers/transaction-request/transaction-request.ts
|
1151
1153
|
import { Address, addressify } from "@fuel-ts/address";
|
1152
|
-
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1153
|
-
import { bn as
|
1154
|
+
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1155
|
+
import { bn as bn7 } from "@fuel-ts/math";
|
1154
1156
|
import {
|
1155
1157
|
PolicyType,
|
1156
1158
|
TransactionCoder,
|
@@ -1493,6 +1495,86 @@ function sleep(time) {
|
|
1493
1495
|
});
|
1494
1496
|
}
|
1495
1497
|
|
1498
|
+
// src/providers/utils/extract-tx-error.ts
|
1499
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1500
|
+
import { bn as bn6 } from "@fuel-ts/math";
|
1501
|
+
import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
|
1502
|
+
import {
|
1503
|
+
FAILED_REQUIRE_SIGNAL,
|
1504
|
+
FAILED_ASSERT_EQ_SIGNAL,
|
1505
|
+
FAILED_ASSERT_NE_SIGNAL,
|
1506
|
+
FAILED_ASSERT_SIGNAL,
|
1507
|
+
FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
|
1508
|
+
PANIC_REASONS,
|
1509
|
+
PANIC_DOC_URL
|
1510
|
+
} from "@fuel-ts/transactions/configs";
|
1511
|
+
var assemblePanicError = (status) => {
|
1512
|
+
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1513
|
+
const reason = status.reason;
|
1514
|
+
if (PANIC_REASONS.includes(status.reason)) {
|
1515
|
+
errorMessage = `${errorMessage}
|
1516
|
+
|
1517
|
+
You can read more about this error at:
|
1518
|
+
|
1519
|
+
${PANIC_DOC_URL}#variant.${status.reason}`;
|
1520
|
+
}
|
1521
|
+
return { errorMessage, reason };
|
1522
|
+
};
|
1523
|
+
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1524
|
+
var assembleRevertError = (receipts, logs) => {
|
1525
|
+
let errorMessage = "The transaction reverted with an unknown reason.";
|
1526
|
+
const revertReceipt = receipts.find(({ type }) => type === ReceiptType3.Revert);
|
1527
|
+
let reason = "";
|
1528
|
+
if (revertReceipt) {
|
1529
|
+
const reasonHex = bn6(revertReceipt.val).toHex();
|
1530
|
+
switch (reasonHex) {
|
1531
|
+
case FAILED_REQUIRE_SIGNAL: {
|
1532
|
+
reason = "require";
|
1533
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1534
|
+
break;
|
1535
|
+
}
|
1536
|
+
case FAILED_ASSERT_EQ_SIGNAL: {
|
1537
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1538
|
+
reason = "assert_eq";
|
1539
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1540
|
+
break;
|
1541
|
+
}
|
1542
|
+
case FAILED_ASSERT_NE_SIGNAL: {
|
1543
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1544
|
+
reason = "assert_ne";
|
1545
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1546
|
+
break;
|
1547
|
+
}
|
1548
|
+
case FAILED_ASSERT_SIGNAL:
|
1549
|
+
reason = "assert";
|
1550
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1551
|
+
break;
|
1552
|
+
case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
|
1553
|
+
reason = "MissingOutputChange";
|
1554
|
+
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1555
|
+
break;
|
1556
|
+
default:
|
1557
|
+
reason = "unknown";
|
1558
|
+
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1559
|
+
}
|
1560
|
+
}
|
1561
|
+
return { errorMessage, reason };
|
1562
|
+
};
|
1563
|
+
var extractTxError = (params) => {
|
1564
|
+
const { receipts, status, logs } = params;
|
1565
|
+
const isPanic = receipts.some(({ type }) => type === ReceiptType3.Panic);
|
1566
|
+
const isRevert = receipts.some(({ type }) => type === ReceiptType3.Revert);
|
1567
|
+
const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1568
|
+
const metadata = {
|
1569
|
+
logs,
|
1570
|
+
receipts,
|
1571
|
+
panic: isPanic,
|
1572
|
+
revert: isRevert,
|
1573
|
+
reason
|
1574
|
+
};
|
1575
|
+
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, metadata);
|
1576
|
+
};
|
1577
|
+
|
1496
1578
|
// src/providers/transaction-request/errors.ts
|
1497
1579
|
var NoWitnessAtIndexError = class extends Error {
|
1498
1580
|
constructor(index) {
|
@@ -1529,8 +1611,6 @@ var BaseTransactionRequest = class {
|
|
1529
1611
|
outputs = [];
|
1530
1612
|
/** List of witnesses */
|
1531
1613
|
witnesses = [];
|
1532
|
-
/** Base asset ID - should be fetched from the chain */
|
1533
|
-
baseAssetId = ZeroBytes324;
|
1534
1614
|
/**
|
1535
1615
|
* Constructor for initializing a base transaction request.
|
1536
1616
|
*
|
@@ -1543,17 +1623,15 @@ var BaseTransactionRequest = class {
|
|
1543
1623
|
witnessLimit,
|
1544
1624
|
inputs,
|
1545
1625
|
outputs,
|
1546
|
-
witnesses
|
1547
|
-
baseAssetId
|
1626
|
+
witnesses
|
1548
1627
|
} = {}) {
|
1549
|
-
this.gasPrice =
|
1628
|
+
this.gasPrice = bn7(gasPrice);
|
1550
1629
|
this.maturity = maturity ?? 0;
|
1551
|
-
this.witnessLimit = witnessLimit ?
|
1552
|
-
this.maxFee = maxFee ?
|
1630
|
+
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1631
|
+
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1553
1632
|
this.inputs = inputs ?? [];
|
1554
1633
|
this.outputs = outputs ?? [];
|
1555
1634
|
this.witnesses = witnesses ?? [];
|
1556
|
-
this.baseAssetId = baseAssetId ?? ZeroBytes324;
|
1557
1635
|
}
|
1558
1636
|
static getPolicyMeta(req) {
|
1559
1637
|
let policyTypes = 0;
|
@@ -1778,9 +1856,11 @@ var BaseTransactionRequest = class {
|
|
1778
1856
|
*
|
1779
1857
|
* @param message - Message resource.
|
1780
1858
|
* @param predicate - Predicate bytes.
|
1859
|
+
* @param predicateData - Predicate data bytes.
|
1781
1860
|
*/
|
1782
1861
|
addMessageInput(message, predicate) {
|
1783
1862
|
const { recipient, sender, amount } = message;
|
1863
|
+
const assetId = BaseAssetId2;
|
1784
1864
|
let witnessIndex;
|
1785
1865
|
if (predicate) {
|
1786
1866
|
witnessIndex = 0;
|
@@ -1801,7 +1881,7 @@ var BaseTransactionRequest = class {
|
|
1801
1881
|
predicateData: predicate?.predicateDataBytes
|
1802
1882
|
};
|
1803
1883
|
this.pushInput(input);
|
1804
|
-
this.addChangeOutput(recipient,
|
1884
|
+
this.addChangeOutput(recipient, assetId);
|
1805
1885
|
}
|
1806
1886
|
/**
|
1807
1887
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1862,12 +1942,12 @@ var BaseTransactionRequest = class {
|
|
1862
1942
|
* @param amount - Amount of coin.
|
1863
1943
|
* @param assetId - Asset ID of coin.
|
1864
1944
|
*/
|
1865
|
-
addCoinOutput(to, amount, assetId) {
|
1945
|
+
addCoinOutput(to, amount, assetId = BaseAssetId2) {
|
1866
1946
|
this.pushOutput({
|
1867
1947
|
type: OutputType2.Coin,
|
1868
1948
|
to: addressify(to).toB256(),
|
1869
1949
|
amount,
|
1870
|
-
assetId
|
1950
|
+
assetId
|
1871
1951
|
});
|
1872
1952
|
return this;
|
1873
1953
|
}
|
@@ -1894,7 +1974,7 @@ var BaseTransactionRequest = class {
|
|
1894
1974
|
* @param to - Address of the owner.
|
1895
1975
|
* @param assetId - Asset ID of coin.
|
1896
1976
|
*/
|
1897
|
-
addChangeOutput(to, assetId) {
|
1977
|
+
addChangeOutput(to, assetId = BaseAssetId2) {
|
1898
1978
|
const changeOutput = this.getChangeOutputs().find(
|
1899
1979
|
(output) => hexlify7(output.assetId) === assetId
|
1900
1980
|
);
|
@@ -1902,7 +1982,7 @@ var BaseTransactionRequest = class {
|
|
1902
1982
|
this.pushOutput({
|
1903
1983
|
type: OutputType2.Change,
|
1904
1984
|
to: addressify(to).toB256(),
|
1905
|
-
assetId
|
1985
|
+
assetId
|
1906
1986
|
});
|
1907
1987
|
}
|
1908
1988
|
}
|
@@ -1978,13 +2058,13 @@ var BaseTransactionRequest = class {
|
|
1978
2058
|
assetId,
|
1979
2059
|
owner: resourcesOwner || Address.fromRandom(),
|
1980
2060
|
maturity: 0,
|
1981
|
-
blockCreated:
|
1982
|
-
txCreatedIdx:
|
2061
|
+
blockCreated: bn7(1),
|
2062
|
+
txCreatedIdx: bn7(1)
|
1983
2063
|
}
|
1984
2064
|
]);
|
1985
2065
|
}
|
1986
2066
|
};
|
1987
|
-
updateAssetInput(
|
2067
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
1988
2068
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
1989
2069
|
}
|
1990
2070
|
/**
|
@@ -1995,7 +2075,7 @@ var BaseTransactionRequest = class {
|
|
1995
2075
|
*/
|
1996
2076
|
getCoinOutputsQuantities() {
|
1997
2077
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
1998
|
-
amount:
|
2078
|
+
amount: bn7(amount),
|
1999
2079
|
assetId: assetId.toString()
|
2000
2080
|
}));
|
2001
2081
|
return coinsQuantities;
|
@@ -2024,7 +2104,7 @@ var BaseTransactionRequest = class {
|
|
2024
2104
|
default:
|
2025
2105
|
return;
|
2026
2106
|
}
|
2027
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput &&
|
2107
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn7(correspondingInput.predicateGasUsed).gt(0)) {
|
2028
2108
|
i.predicate = correspondingInput.predicate;
|
2029
2109
|
i.predicateData = correspondingInput.predicateData;
|
2030
2110
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2035,14 +2115,14 @@ var BaseTransactionRequest = class {
|
|
2035
2115
|
|
2036
2116
|
// src/providers/transaction-request/create-transaction-request.ts
|
2037
2117
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
2038
|
-
import { bn as
|
2118
|
+
import { bn as bn9 } from "@fuel-ts/math";
|
2039
2119
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
2040
2120
|
import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
2041
2121
|
|
2042
2122
|
// src/providers/transaction-request/hash-transaction.ts
|
2043
2123
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2044
2124
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2045
|
-
import { bn as
|
2125
|
+
import { bn as bn8 } from "@fuel-ts/math";
|
2046
2126
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2047
2127
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2048
2128
|
import { clone as clone2 } from "ramda";
|
@@ -2059,11 +2139,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2059
2139
|
blockHeight: 0,
|
2060
2140
|
txIndex: 0
|
2061
2141
|
};
|
2062
|
-
inputClone.predicateGasUsed =
|
2142
|
+
inputClone.predicateGasUsed = bn8(0);
|
2063
2143
|
return inputClone;
|
2064
2144
|
}
|
2065
2145
|
case InputType3.Message: {
|
2066
|
-
inputClone.predicateGasUsed =
|
2146
|
+
inputClone.predicateGasUsed = bn8(0);
|
2067
2147
|
return inputClone;
|
2068
2148
|
}
|
2069
2149
|
case InputType3.Contract: {
|
@@ -2090,12 +2170,12 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2090
2170
|
return outputClone;
|
2091
2171
|
}
|
2092
2172
|
case OutputType3.Change: {
|
2093
|
-
outputClone.amount =
|
2173
|
+
outputClone.amount = bn8(0);
|
2094
2174
|
return outputClone;
|
2095
2175
|
}
|
2096
2176
|
case OutputType3.Variable: {
|
2097
2177
|
outputClone.to = ZeroBytes325;
|
2098
|
-
outputClone.amount =
|
2178
|
+
outputClone.amount = bn8(0);
|
2099
2179
|
outputClone.assetId = ZeroBytes325;
|
2100
2180
|
return outputClone;
|
2101
2181
|
}
|
@@ -2219,7 +2299,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2219
2299
|
}
|
2220
2300
|
metadataGas(gasCosts) {
|
2221
2301
|
return calculateMetadataGasForTxCreate({
|
2222
|
-
contractBytesSize:
|
2302
|
+
contractBytesSize: bn9(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2223
2303
|
gasCosts,
|
2224
2304
|
stateRootSize: this.storageSlots.length,
|
2225
2305
|
txBytesSize: this.byteSize()
|
@@ -2231,7 +2311,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2231
2311
|
import { Interface } from "@fuel-ts/abi-coder";
|
2232
2312
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2233
2313
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2234
|
-
import { bn as
|
2314
|
+
import { bn as bn10 } from "@fuel-ts/math";
|
2235
2315
|
import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2236
2316
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2237
2317
|
|
@@ -2285,7 +2365,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2285
2365
|
*/
|
2286
2366
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2287
2367
|
super(rest);
|
2288
|
-
this.gasLimit =
|
2368
|
+
this.gasLimit = bn10(gasLimit);
|
2289
2369
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
2290
2370
|
this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
|
2291
2371
|
this.abis = rest.abis;
|
@@ -2433,7 +2513,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2433
2513
|
};
|
2434
2514
|
|
2435
2515
|
// src/providers/transaction-request/utils.ts
|
2436
|
-
import { ErrorCode as
|
2516
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2437
2517
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2438
2518
|
var transactionRequestify = (obj) => {
|
2439
2519
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2448,14 +2528,14 @@ var transactionRequestify = (obj) => {
|
|
2448
2528
|
return CreateTransactionRequest.from(obj);
|
2449
2529
|
}
|
2450
2530
|
default: {
|
2451
|
-
throw new
|
2531
|
+
throw new FuelError8(ErrorCode8.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2452
2532
|
}
|
2453
2533
|
}
|
2454
2534
|
};
|
2455
2535
|
|
2456
2536
|
// src/providers/transaction-response/transaction-response.ts
|
2457
|
-
import { ErrorCode as
|
2458
|
-
import { bn as
|
2537
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2538
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2459
2539
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2460
2540
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2461
2541
|
|
@@ -2463,7 +2543,7 @@ import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
|
2463
2543
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2464
2544
|
|
2465
2545
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2466
|
-
import { bn as
|
2546
|
+
import { bn as bn11 } from "@fuel-ts/math";
|
2467
2547
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2468
2548
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2469
2549
|
var calculateTransactionFee = (params) => {
|
@@ -2472,24 +2552,24 @@ var calculateTransactionFee = (params) => {
|
|
2472
2552
|
rawPayload,
|
2473
2553
|
consensusParameters: { gasCosts, feeParams }
|
2474
2554
|
} = params;
|
2475
|
-
const gasPerByte =
|
2476
|
-
const gasPriceFactor =
|
2555
|
+
const gasPerByte = bn11(feeParams.gasPerByte);
|
2556
|
+
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
2477
2557
|
const transactionBytes = arrayify9(rawPayload);
|
2478
2558
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2479
2559
|
if (transaction.type === TransactionType6.Mint) {
|
2480
2560
|
return {
|
2481
|
-
fee:
|
2482
|
-
minFee:
|
2483
|
-
maxFee:
|
2484
|
-
feeFromGasUsed:
|
2561
|
+
fee: bn11(0),
|
2562
|
+
minFee: bn11(0),
|
2563
|
+
maxFee: bn11(0),
|
2564
|
+
feeFromGasUsed: bn11(0)
|
2485
2565
|
};
|
2486
2566
|
}
|
2487
2567
|
const { type, witnesses, inputs, policies } = transaction;
|
2488
|
-
let metadataGas =
|
2489
|
-
let gasLimit =
|
2568
|
+
let metadataGas = bn11(0);
|
2569
|
+
let gasLimit = bn11(0);
|
2490
2570
|
if (type === TransactionType6.Create) {
|
2491
2571
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2492
|
-
const contractBytesSize =
|
2572
|
+
const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
|
2493
2573
|
metadataGas = calculateMetadataGasForTxCreate({
|
2494
2574
|
contractBytesSize,
|
2495
2575
|
gasCosts,
|
@@ -2508,12 +2588,12 @@ var calculateTransactionFee = (params) => {
|
|
2508
2588
|
}
|
2509
2589
|
const minGas = getMinGas({
|
2510
2590
|
gasCosts,
|
2511
|
-
gasPerByte:
|
2591
|
+
gasPerByte: bn11(gasPerByte),
|
2512
2592
|
inputs,
|
2513
2593
|
metadataGas,
|
2514
2594
|
txBytesSize: transactionBytes.length
|
2515
2595
|
});
|
2516
|
-
const gasPrice =
|
2596
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2517
2597
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2518
2598
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2519
2599
|
const maxGas = getMaxGas({
|
@@ -2537,13 +2617,13 @@ var calculateTransactionFee = (params) => {
|
|
2537
2617
|
|
2538
2618
|
// src/providers/transaction-summary/operations.ts
|
2539
2619
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2540
|
-
import { ErrorCode as
|
2541
|
-
import { bn as
|
2542
|
-
import { ReceiptType as
|
2620
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
2621
|
+
import { bn as bn13 } from "@fuel-ts/math";
|
2622
|
+
import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2543
2623
|
|
2544
2624
|
// src/providers/transaction-summary/call.ts
|
2545
2625
|
import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
|
2546
|
-
import { bn as
|
2626
|
+
import { bn as bn12 } from "@fuel-ts/math";
|
2547
2627
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2548
2628
|
const abiInterface = new Interface2(abi);
|
2549
2629
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2552,7 +2632,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2552
2632
|
let encodedArgs;
|
2553
2633
|
if (functionFragment.isInputDataPointer) {
|
2554
2634
|
if (rawPayload) {
|
2555
|
-
const argsOffset =
|
2635
|
+
const argsOffset = bn12(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2556
2636
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2557
2637
|
}
|
2558
2638
|
} else {
|
@@ -2586,7 +2666,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2586
2666
|
};
|
2587
2667
|
|
2588
2668
|
// src/providers/transaction-summary/input.ts
|
2589
|
-
import { ErrorCode as
|
2669
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2590
2670
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2591
2671
|
function getInputsByTypes(inputs, types) {
|
2592
2672
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2624,8 +2704,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2624
2704
|
return void 0;
|
2625
2705
|
}
|
2626
2706
|
if (contractInput.type !== InputType5.Contract) {
|
2627
|
-
throw new
|
2628
|
-
|
2707
|
+
throw new FuelError9(
|
2708
|
+
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2629
2709
|
`Contract input should be of type 'contract'.`
|
2630
2710
|
);
|
2631
2711
|
}
|
@@ -2672,8 +2752,8 @@ function getTransactionTypeName(transactionType) {
|
|
2672
2752
|
case TransactionType7.Script:
|
2673
2753
|
return "Script" /* Script */;
|
2674
2754
|
default:
|
2675
|
-
throw new
|
2676
|
-
|
2755
|
+
throw new FuelError10(
|
2756
|
+
ErrorCode10.INVALID_TRANSACTION_TYPE,
|
2677
2757
|
`Invalid transaction type: ${transactionType}.`
|
2678
2758
|
);
|
2679
2759
|
}
|
@@ -2692,10 +2772,10 @@ function isTypeScript(transactionType) {
|
|
2692
2772
|
return isType(transactionType, "Script" /* Script */);
|
2693
2773
|
}
|
2694
2774
|
function getReceiptsCall(receipts) {
|
2695
|
-
return getReceiptsByType(receipts,
|
2775
|
+
return getReceiptsByType(receipts, ReceiptType4.Call);
|
2696
2776
|
}
|
2697
2777
|
function getReceiptsMessageOut(receipts) {
|
2698
|
-
return getReceiptsByType(receipts,
|
2778
|
+
return getReceiptsByType(receipts, ReceiptType4.MessageOut);
|
2699
2779
|
}
|
2700
2780
|
var mergeAssets = (op1, op2) => {
|
2701
2781
|
const assets1 = op1.assetsSent || [];
|
@@ -2708,7 +2788,7 @@ var mergeAssets = (op1, op2) => {
|
|
2708
2788
|
if (!matchingAsset) {
|
2709
2789
|
return asset1;
|
2710
2790
|
}
|
2711
|
-
const mergedAmount =
|
2791
|
+
const mergedAmount = bn13(asset1.amount).add(matchingAsset.amount);
|
2712
2792
|
return { ...asset1, amount: mergedAmount };
|
2713
2793
|
});
|
2714
2794
|
return mergedAssets.concat(filteredAssets);
|
@@ -2891,11 +2971,11 @@ function getTransferOperations({
|
|
2891
2971
|
});
|
2892
2972
|
const transferReceipts = getReceiptsByType(
|
2893
2973
|
receipts,
|
2894
|
-
|
2974
|
+
ReceiptType4.Transfer
|
2895
2975
|
);
|
2896
2976
|
const transferOutReceipts = getReceiptsByType(
|
2897
2977
|
receipts,
|
2898
|
-
|
2978
|
+
ReceiptType4.TransferOut
|
2899
2979
|
);
|
2900
2980
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2901
2981
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -2980,17 +3060,17 @@ function getOperations({
|
|
2980
3060
|
}
|
2981
3061
|
|
2982
3062
|
// src/providers/transaction-summary/receipt.ts
|
2983
|
-
import { ReceiptType as
|
3063
|
+
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
2984
3064
|
var processGqlReceipt = (gqlReceipt) => {
|
2985
3065
|
const receipt = assembleReceiptByType(gqlReceipt);
|
2986
3066
|
switch (receipt.type) {
|
2987
|
-
case
|
3067
|
+
case ReceiptType5.ReturnData: {
|
2988
3068
|
return {
|
2989
3069
|
...receipt,
|
2990
3070
|
data: gqlReceipt.data || "0x"
|
2991
3071
|
};
|
2992
3072
|
}
|
2993
|
-
case
|
3073
|
+
case ReceiptType5.LogData: {
|
2994
3074
|
return {
|
2995
3075
|
...receipt,
|
2996
3076
|
data: gqlReceipt.data || "0x"
|
@@ -3003,7 +3083,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3003
3083
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3004
3084
|
const mintedAssets = [];
|
3005
3085
|
receipts.forEach((receipt) => {
|
3006
|
-
if (receipt.type ===
|
3086
|
+
if (receipt.type === ReceiptType5.Mint) {
|
3007
3087
|
mintedAssets.push({
|
3008
3088
|
subId: receipt.subId,
|
3009
3089
|
contractId: receipt.contractId,
|
@@ -3017,7 +3097,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3017
3097
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3018
3098
|
const burnedAssets = [];
|
3019
3099
|
receipts.forEach((receipt) => {
|
3020
|
-
if (receipt.type ===
|
3100
|
+
if (receipt.type === ReceiptType5.Burn) {
|
3021
3101
|
burnedAssets.push({
|
3022
3102
|
subId: receipt.subId,
|
3023
3103
|
contractId: receipt.contractId,
|
@@ -3030,7 +3110,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3030
3110
|
};
|
3031
3111
|
|
3032
3112
|
// src/providers/transaction-summary/status.ts
|
3033
|
-
import { ErrorCode as
|
3113
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
3034
3114
|
var getTransactionStatusName = (gqlStatus) => {
|
3035
3115
|
switch (gqlStatus) {
|
3036
3116
|
case "FailureStatus":
|
@@ -3042,8 +3122,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3042
3122
|
case "SqueezedOutStatus":
|
3043
3123
|
return "squeezedout" /* squeezedout */;
|
3044
3124
|
default:
|
3045
|
-
throw new
|
3046
|
-
|
3125
|
+
throw new FuelError11(
|
3126
|
+
ErrorCode11.INVALID_TRANSACTION_STATUS,
|
3047
3127
|
`Invalid transaction status: ${gqlStatus}.`
|
3048
3128
|
);
|
3049
3129
|
}
|
@@ -3156,12 +3236,12 @@ function assembleTransactionSummary(params) {
|
|
3156
3236
|
|
3157
3237
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3158
3238
|
import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
|
3159
|
-
import { ReceiptType as
|
3239
|
+
import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
|
3160
3240
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3161
3241
|
return receipts.reduce((logs, receipt) => {
|
3162
|
-
if (receipt.type ===
|
3242
|
+
if (receipt.type === ReceiptType6.LogData || receipt.type === ReceiptType6.Log) {
|
3163
3243
|
const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
|
3164
|
-
const data = receipt.type ===
|
3244
|
+
const data = receipt.type === ReceiptType6.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3165
3245
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3166
3246
|
logs.push(decodedLog);
|
3167
3247
|
}
|
@@ -3176,7 +3256,7 @@ var TransactionResponse = class {
|
|
3176
3256
|
/** Current provider */
|
3177
3257
|
provider;
|
3178
3258
|
/** Gas used on the transaction */
|
3179
|
-
gasUsed =
|
3259
|
+
gasUsed = bn14(0);
|
3180
3260
|
/** The graphql Transaction with receipts object. */
|
3181
3261
|
gqlTransaction;
|
3182
3262
|
abis;
|
@@ -3281,8 +3361,8 @@ var TransactionResponse = class {
|
|
3281
3361
|
});
|
3282
3362
|
for await (const { statusChange } of subscription) {
|
3283
3363
|
if (statusChange.type === "SqueezedOutStatus") {
|
3284
|
-
throw new
|
3285
|
-
|
3364
|
+
throw new FuelError12(
|
3365
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3286
3366
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3287
3367
|
);
|
3288
3368
|
}
|
@@ -3304,14 +3384,26 @@ var TransactionResponse = class {
|
|
3304
3384
|
gqlTransaction: this.gqlTransaction,
|
3305
3385
|
...transactionSummary
|
3306
3386
|
};
|
3387
|
+
let logs = [];
|
3307
3388
|
if (this.abis) {
|
3308
|
-
|
3389
|
+
logs = getDecodedLogs(
|
3309
3390
|
transactionSummary.receipts,
|
3310
3391
|
this.abis.main,
|
3311
3392
|
this.abis.otherContractsAbis
|
3312
3393
|
);
|
3313
3394
|
transactionResult.logs = logs;
|
3314
3395
|
}
|
3396
|
+
if (transactionResult.isStatusFailure) {
|
3397
|
+
const {
|
3398
|
+
receipts,
|
3399
|
+
gqlTransaction: { status }
|
3400
|
+
} = transactionResult;
|
3401
|
+
throw extractTxError({
|
3402
|
+
receipts,
|
3403
|
+
status,
|
3404
|
+
logs
|
3405
|
+
});
|
3406
|
+
}
|
3315
3407
|
return transactionResult;
|
3316
3408
|
}
|
3317
3409
|
/**
|
@@ -3320,14 +3412,7 @@ var TransactionResponse = class {
|
|
3320
3412
|
* @param contractsAbiMap - The contracts ABI map.
|
3321
3413
|
*/
|
3322
3414
|
async wait(contractsAbiMap) {
|
3323
|
-
|
3324
|
-
if (result.isStatusFailure) {
|
3325
|
-
throw new FuelError11(
|
3326
|
-
ErrorCode11.TRANSACTION_FAILED,
|
3327
|
-
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3328
|
-
);
|
3329
|
-
}
|
3330
|
-
return result;
|
3415
|
+
return this.waitForResult(contractsAbiMap);
|
3331
3416
|
}
|
3332
3417
|
};
|
3333
3418
|
|
@@ -3389,30 +3474,29 @@ var processGqlChain = (chain) => {
|
|
3389
3474
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3390
3475
|
return {
|
3391
3476
|
name,
|
3392
|
-
baseChainHeight:
|
3477
|
+
baseChainHeight: bn15(daHeight),
|
3393
3478
|
consensusParameters: {
|
3394
|
-
contractMaxSize:
|
3395
|
-
maxInputs:
|
3396
|
-
maxOutputs:
|
3397
|
-
maxWitnesses:
|
3398
|
-
maxGasPerTx:
|
3399
|
-
maxScriptLength:
|
3400
|
-
maxScriptDataLength:
|
3401
|
-
maxStorageSlots:
|
3402
|
-
maxPredicateLength:
|
3403
|
-
maxPredicateDataLength:
|
3404
|
-
maxGasPerPredicate:
|
3405
|
-
gasPriceFactor:
|
3406
|
-
gasPerByte:
|
3407
|
-
maxMessageDataLength:
|
3408
|
-
chainId:
|
3409
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3479
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3480
|
+
maxInputs: bn15(txParams.maxInputs),
|
3481
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3482
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3483
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3484
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3485
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3486
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3487
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3488
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3489
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3490
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3491
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3492
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3493
|
+
chainId: bn15(consensusParameters.chainId),
|
3410
3494
|
gasCosts
|
3411
3495
|
},
|
3412
3496
|
gasCosts,
|
3413
3497
|
latestBlock: {
|
3414
3498
|
id: latestBlock.id,
|
3415
|
-
height:
|
3499
|
+
height: bn15(latestBlock.header.height),
|
3416
3500
|
time: latestBlock.header.time,
|
3417
3501
|
transactions: latestBlock.transactions.map((i) => ({
|
3418
3502
|
id: i.id
|
@@ -3482,8 +3566,8 @@ var _Provider = class {
|
|
3482
3566
|
getChain() {
|
3483
3567
|
const chain = _Provider.chainInfoCache[this.url];
|
3484
3568
|
if (!chain) {
|
3485
|
-
throw new
|
3486
|
-
|
3569
|
+
throw new FuelError13(
|
3570
|
+
ErrorCode13.CHAIN_INFO_CACHE_EMPTY,
|
3487
3571
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3488
3572
|
);
|
3489
3573
|
}
|
@@ -3495,8 +3579,8 @@ var _Provider = class {
|
|
3495
3579
|
getNode() {
|
3496
3580
|
const node = _Provider.nodeInfoCache[this.url];
|
3497
3581
|
if (!node) {
|
3498
|
-
throw new
|
3499
|
-
|
3582
|
+
throw new FuelError13(
|
3583
|
+
ErrorCode13.NODE_INFO_CACHE_EMPTY,
|
3500
3584
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3501
3585
|
);
|
3502
3586
|
}
|
@@ -3543,8 +3627,8 @@ var _Provider = class {
|
|
3543
3627
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3544
3628
|
const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
|
3545
3629
|
if (!isMajorSupported || !isMinorSupported) {
|
3546
|
-
throw new
|
3547
|
-
|
3630
|
+
throw new FuelError13(
|
3631
|
+
FuelError13.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3548
3632
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3549
3633
|
);
|
3550
3634
|
}
|
@@ -3607,7 +3691,7 @@ var _Provider = class {
|
|
3607
3691
|
*/
|
3608
3692
|
async getBlockNumber() {
|
3609
3693
|
const { chain } = await this.operations.getChain();
|
3610
|
-
return
|
3694
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3611
3695
|
}
|
3612
3696
|
/**
|
3613
3697
|
* Returns the chain information.
|
@@ -3617,9 +3701,9 @@ var _Provider = class {
|
|
3617
3701
|
async fetchNode() {
|
3618
3702
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3619
3703
|
const processedNodeInfo = {
|
3620
|
-
maxDepth:
|
3621
|
-
maxTx:
|
3622
|
-
minGasPrice:
|
3704
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3705
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3706
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3623
3707
|
nodeVersion: nodeInfo.nodeVersion,
|
3624
3708
|
utxoValidation: nodeInfo.utxoValidation,
|
3625
3709
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3649,17 +3733,6 @@ var _Provider = class {
|
|
3649
3733
|
} = this.getChain();
|
3650
3734
|
return chainId.toNumber();
|
3651
3735
|
}
|
3652
|
-
/**
|
3653
|
-
* Returns the base asset ID
|
3654
|
-
*
|
3655
|
-
* @returns A promise that resolves to the base asset ID
|
3656
|
-
*/
|
3657
|
-
getBaseAssetId() {
|
3658
|
-
const {
|
3659
|
-
consensusParameters: { baseAssetId }
|
3660
|
-
} = this.getChain();
|
3661
|
-
return baseAssetId;
|
3662
|
-
}
|
3663
3736
|
/**
|
3664
3737
|
* Submits a transaction to the chain to be executed.
|
3665
3738
|
*
|
@@ -3685,8 +3758,8 @@ var _Provider = class {
|
|
3685
3758
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3686
3759
|
for await (const { submitAndAwait } of subscription) {
|
3687
3760
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3688
|
-
throw new
|
3689
|
-
|
3761
|
+
throw new FuelError13(
|
3762
|
+
ErrorCode13.TRANSACTION_SQUEEZED_OUT,
|
3690
3763
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3691
3764
|
);
|
3692
3765
|
}
|
@@ -3753,7 +3826,7 @@ var _Provider = class {
|
|
3753
3826
|
} = response;
|
3754
3827
|
if (inputs) {
|
3755
3828
|
inputs.forEach((input, index) => {
|
3756
|
-
if ("predicateGasUsed" in input &&
|
3829
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3757
3830
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3758
3831
|
}
|
3759
3832
|
});
|
@@ -3866,7 +3939,7 @@ var _Provider = class {
|
|
3866
3939
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3867
3940
|
if (estimatePredicates) {
|
3868
3941
|
if (isScriptTransaction) {
|
3869
|
-
txRequestClone.gasLimit =
|
3942
|
+
txRequestClone.gasLimit = bn15(0);
|
3870
3943
|
}
|
3871
3944
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3872
3945
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -3882,8 +3955,8 @@ var _Provider = class {
|
|
3882
3955
|
let missingContractIds = [];
|
3883
3956
|
let outputVariables = 0;
|
3884
3957
|
if (isScriptTransaction && estimateTxDependencies) {
|
3885
|
-
txRequestClone.gasPrice =
|
3886
|
-
txRequestClone.gasLimit =
|
3958
|
+
txRequestClone.gasPrice = bn15(0);
|
3959
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3887
3960
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3888
3961
|
receipts = result.receipts;
|
3889
3962
|
outputVariables = result.outputVariables;
|
@@ -3945,11 +4018,11 @@ var _Provider = class {
|
|
3945
4018
|
return coins.map((coin) => ({
|
3946
4019
|
id: coin.utxoId,
|
3947
4020
|
assetId: coin.assetId,
|
3948
|
-
amount:
|
4021
|
+
amount: bn15(coin.amount),
|
3949
4022
|
owner: Address2.fromAddressOrString(coin.owner),
|
3950
|
-
maturity:
|
3951
|
-
blockCreated:
|
3952
|
-
txCreatedIdx:
|
4023
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4024
|
+
blockCreated: bn15(coin.blockCreated),
|
4025
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
3953
4026
|
}));
|
3954
4027
|
}
|
3955
4028
|
/**
|
@@ -3986,9 +4059,9 @@ var _Provider = class {
|
|
3986
4059
|
switch (coin.__typename) {
|
3987
4060
|
case "MessageCoin":
|
3988
4061
|
return {
|
3989
|
-
amount:
|
4062
|
+
amount: bn15(coin.amount),
|
3990
4063
|
assetId: coin.assetId,
|
3991
|
-
daHeight:
|
4064
|
+
daHeight: bn15(coin.daHeight),
|
3992
4065
|
sender: Address2.fromAddressOrString(coin.sender),
|
3993
4066
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
3994
4067
|
nonce: coin.nonce
|
@@ -3996,12 +4069,12 @@ var _Provider = class {
|
|
3996
4069
|
case "Coin":
|
3997
4070
|
return {
|
3998
4071
|
id: coin.utxoId,
|
3999
|
-
amount:
|
4072
|
+
amount: bn15(coin.amount),
|
4000
4073
|
assetId: coin.assetId,
|
4001
4074
|
owner: Address2.fromAddressOrString(coin.owner),
|
4002
|
-
maturity:
|
4003
|
-
blockCreated:
|
4004
|
-
txCreatedIdx:
|
4075
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4076
|
+
blockCreated: bn15(coin.blockCreated),
|
4077
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4005
4078
|
};
|
4006
4079
|
default:
|
4007
4080
|
return null;
|
@@ -4018,13 +4091,13 @@ var _Provider = class {
|
|
4018
4091
|
async getBlock(idOrHeight) {
|
4019
4092
|
let variables;
|
4020
4093
|
if (typeof idOrHeight === "number") {
|
4021
|
-
variables = { height:
|
4094
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4022
4095
|
} else if (idOrHeight === "latest") {
|
4023
4096
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4024
4097
|
} else if (idOrHeight.length === 66) {
|
4025
4098
|
variables = { blockId: idOrHeight };
|
4026
4099
|
} else {
|
4027
|
-
variables = { blockId:
|
4100
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4028
4101
|
}
|
4029
4102
|
const { block } = await this.operations.getBlock(variables);
|
4030
4103
|
if (!block) {
|
@@ -4032,7 +4105,7 @@ var _Provider = class {
|
|
4032
4105
|
}
|
4033
4106
|
return {
|
4034
4107
|
id: block.id,
|
4035
|
-
height:
|
4108
|
+
height: bn15(block.header.height),
|
4036
4109
|
time: block.header.time,
|
4037
4110
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4038
4111
|
};
|
@@ -4047,7 +4120,7 @@ var _Provider = class {
|
|
4047
4120
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4048
4121
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4049
4122
|
id: block.id,
|
4050
|
-
height:
|
4123
|
+
height: bn15(block.header.height),
|
4051
4124
|
time: block.header.time,
|
4052
4125
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4053
4126
|
}));
|
@@ -4062,7 +4135,7 @@ var _Provider = class {
|
|
4062
4135
|
async getBlockWithTransactions(idOrHeight) {
|
4063
4136
|
let variables;
|
4064
4137
|
if (typeof idOrHeight === "number") {
|
4065
|
-
variables = { blockHeight:
|
4138
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4066
4139
|
} else if (idOrHeight === "latest") {
|
4067
4140
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4068
4141
|
} else {
|
@@ -4074,7 +4147,7 @@ var _Provider = class {
|
|
4074
4147
|
}
|
4075
4148
|
return {
|
4076
4149
|
id: block.id,
|
4077
|
-
height:
|
4150
|
+
height: bn15(block.header.height, 10),
|
4078
4151
|
time: block.header.time,
|
4079
4152
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4080
4153
|
transactions: block.transactions.map(
|
@@ -4123,7 +4196,7 @@ var _Provider = class {
|
|
4123
4196
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4124
4197
|
asset: hexlify12(assetId)
|
4125
4198
|
});
|
4126
|
-
return
|
4199
|
+
return bn15(contractBalance.amount, 10);
|
4127
4200
|
}
|
4128
4201
|
/**
|
4129
4202
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4137,7 +4210,7 @@ var _Provider = class {
|
|
4137
4210
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4138
4211
|
assetId: hexlify12(assetId)
|
4139
4212
|
});
|
4140
|
-
return
|
4213
|
+
return bn15(balance.amount, 10);
|
4141
4214
|
}
|
4142
4215
|
/**
|
4143
4216
|
* Returns balances for the given owner.
|
@@ -4155,7 +4228,7 @@ var _Provider = class {
|
|
4155
4228
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4156
4229
|
return balances.map((balance) => ({
|
4157
4230
|
assetId: balance.assetId,
|
4158
|
-
amount:
|
4231
|
+
amount: bn15(balance.amount)
|
4159
4232
|
}));
|
4160
4233
|
}
|
4161
4234
|
/**
|
@@ -4177,15 +4250,15 @@ var _Provider = class {
|
|
4177
4250
|
sender: message.sender,
|
4178
4251
|
recipient: message.recipient,
|
4179
4252
|
nonce: message.nonce,
|
4180
|
-
amount:
|
4253
|
+
amount: bn15(message.amount),
|
4181
4254
|
data: message.data
|
4182
4255
|
}),
|
4183
4256
|
sender: Address2.fromAddressOrString(message.sender),
|
4184
4257
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4185
4258
|
nonce: message.nonce,
|
4186
|
-
amount:
|
4259
|
+
amount: bn15(message.amount),
|
4187
4260
|
data: InputMessageCoder.decodeData(message.data),
|
4188
|
-
daHeight:
|
4261
|
+
daHeight: bn15(message.daHeight)
|
4189
4262
|
}));
|
4190
4263
|
}
|
4191
4264
|
/**
|
@@ -4203,8 +4276,8 @@ var _Provider = class {
|
|
4203
4276
|
nonce
|
4204
4277
|
};
|
4205
4278
|
if (commitBlockId && commitBlockHeight) {
|
4206
|
-
throw new
|
4207
|
-
|
4279
|
+
throw new FuelError13(
|
4280
|
+
ErrorCode13.INVALID_INPUT_PARAMETERS,
|
4208
4281
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4209
4282
|
);
|
4210
4283
|
}
|
@@ -4238,41 +4311,41 @@ var _Provider = class {
|
|
4238
4311
|
} = result.messageProof;
|
4239
4312
|
return {
|
4240
4313
|
messageProof: {
|
4241
|
-
proofIndex:
|
4314
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4242
4315
|
proofSet: messageProof.proofSet
|
4243
4316
|
},
|
4244
4317
|
blockProof: {
|
4245
|
-
proofIndex:
|
4318
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4246
4319
|
proofSet: blockProof.proofSet
|
4247
4320
|
},
|
4248
4321
|
messageBlockHeader: {
|
4249
4322
|
id: messageBlockHeader.id,
|
4250
|
-
daHeight:
|
4251
|
-
transactionsCount:
|
4323
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4324
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4252
4325
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4253
|
-
height:
|
4326
|
+
height: bn15(messageBlockHeader.height),
|
4254
4327
|
prevRoot: messageBlockHeader.prevRoot,
|
4255
4328
|
time: messageBlockHeader.time,
|
4256
4329
|
applicationHash: messageBlockHeader.applicationHash,
|
4257
4330
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4258
|
-
messageReceiptCount:
|
4331
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4259
4332
|
},
|
4260
4333
|
commitBlockHeader: {
|
4261
4334
|
id: commitBlockHeader.id,
|
4262
|
-
daHeight:
|
4263
|
-
transactionsCount:
|
4335
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4336
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4264
4337
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4265
|
-
height:
|
4338
|
+
height: bn15(commitBlockHeader.height),
|
4266
4339
|
prevRoot: commitBlockHeader.prevRoot,
|
4267
4340
|
time: commitBlockHeader.time,
|
4268
4341
|
applicationHash: commitBlockHeader.applicationHash,
|
4269
4342
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4270
|
-
messageReceiptCount:
|
4343
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4271
4344
|
},
|
4272
4345
|
sender: Address2.fromAddressOrString(sender),
|
4273
4346
|
recipient: Address2.fromAddressOrString(recipient),
|
4274
4347
|
nonce,
|
4275
|
-
amount:
|
4348
|
+
amount: bn15(amount),
|
4276
4349
|
data
|
4277
4350
|
};
|
4278
4351
|
}
|
@@ -4295,10 +4368,10 @@ var _Provider = class {
|
|
4295
4368
|
*/
|
4296
4369
|
async produceBlocks(amount, startTime) {
|
4297
4370
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4298
|
-
blocksToProduce:
|
4371
|
+
blocksToProduce: bn15(amount).toString(10),
|
4299
4372
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4300
4373
|
});
|
4301
|
-
return
|
4374
|
+
return bn15(latestBlockHeight);
|
4302
4375
|
}
|
4303
4376
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4304
4377
|
async getTransactionResponse(transactionId) {
|
@@ -4321,8 +4394,8 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4321
4394
|
__publicField(Provider, "nodeInfoCache", {});
|
4322
4395
|
|
4323
4396
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4324
|
-
import { ErrorCode as
|
4325
|
-
import { bn as
|
4397
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4398
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4326
4399
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4327
4400
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4328
4401
|
|
@@ -4439,7 +4512,7 @@ var Account = class extends AbstractAccount {
|
|
4439
4512
|
*/
|
4440
4513
|
get provider() {
|
4441
4514
|
if (!this._provider) {
|
4442
|
-
throw new
|
4515
|
+
throw new FuelError15(ErrorCode15.MISSING_PROVIDER, "Provider not set");
|
4443
4516
|
}
|
4444
4517
|
return this._provider;
|
4445
4518
|
}
|
@@ -4491,8 +4564,8 @@ var Account = class extends AbstractAccount {
|
|
4491
4564
|
if (!hasNextPage) {
|
4492
4565
|
break;
|
4493
4566
|
}
|
4494
|
-
throw new
|
4495
|
-
|
4567
|
+
throw new FuelError15(
|
4568
|
+
ErrorCode15.NOT_SUPPORTED,
|
4496
4569
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4497
4570
|
);
|
4498
4571
|
}
|
@@ -4517,8 +4590,8 @@ var Account = class extends AbstractAccount {
|
|
4517
4590
|
if (!hasNextPage) {
|
4518
4591
|
break;
|
4519
4592
|
}
|
4520
|
-
throw new
|
4521
|
-
|
4593
|
+
throw new FuelError15(
|
4594
|
+
ErrorCode15.NOT_SUPPORTED,
|
4522
4595
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4523
4596
|
);
|
4524
4597
|
}
|
@@ -4530,9 +4603,8 @@ var Account = class extends AbstractAccount {
|
|
4530
4603
|
* @param assetId - The asset ID to check the balance for.
|
4531
4604
|
* @returns A promise that resolves to the balance amount.
|
4532
4605
|
*/
|
4533
|
-
async getBalance(assetId) {
|
4534
|
-
const
|
4535
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4606
|
+
async getBalance(assetId = BaseAssetId3) {
|
4607
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4536
4608
|
return amount;
|
4537
4609
|
}
|
4538
4610
|
/**
|
@@ -4554,8 +4626,8 @@ var Account = class extends AbstractAccount {
|
|
4554
4626
|
if (!hasNextPage) {
|
4555
4627
|
break;
|
4556
4628
|
}
|
4557
|
-
throw new
|
4558
|
-
|
4629
|
+
throw new FuelError15(
|
4630
|
+
ErrorCode15.NOT_SUPPORTED,
|
4559
4631
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4560
4632
|
);
|
4561
4633
|
}
|
@@ -4570,17 +4642,16 @@ var Account = class extends AbstractAccount {
|
|
4570
4642
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4571
4643
|
*/
|
4572
4644
|
async fund(request, coinQuantities, fee) {
|
4573
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4574
4645
|
const updatedQuantities = addAmountToAsset({
|
4575
|
-
amount:
|
4576
|
-
assetId:
|
4646
|
+
amount: bn17(fee),
|
4647
|
+
assetId: BaseAssetId3,
|
4577
4648
|
coinQuantities
|
4578
4649
|
});
|
4579
4650
|
const quantitiesDict = {};
|
4580
4651
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4581
4652
|
quantitiesDict[assetId] = {
|
4582
4653
|
required: amount,
|
4583
|
-
owned:
|
4654
|
+
owned: bn17(0)
|
4584
4655
|
};
|
4585
4656
|
});
|
4586
4657
|
const cachedUtxos = [];
|
@@ -4593,12 +4664,12 @@ var Account = class extends AbstractAccount {
|
|
4593
4664
|
if (isCoin2) {
|
4594
4665
|
const assetId = String(input.assetId);
|
4595
4666
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4596
|
-
const amount =
|
4667
|
+
const amount = bn17(input.amount);
|
4597
4668
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4598
4669
|
cachedUtxos.push(input.id);
|
4599
4670
|
}
|
4600
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4601
|
-
quantitiesDict[
|
4671
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[BaseAssetId3]) {
|
4672
|
+
quantitiesDict[BaseAssetId3].owned = quantitiesDict[BaseAssetId3].owned.add(input.amount);
|
4602
4673
|
cachedMessages.push(input.nonce);
|
4603
4674
|
}
|
4604
4675
|
}
|
@@ -4630,18 +4701,17 @@ var Account = class extends AbstractAccount {
|
|
4630
4701
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4631
4702
|
* @returns A promise that resolves to the prepared transaction request.
|
4632
4703
|
*/
|
4633
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4704
|
+
async createTransfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4634
4705
|
const { minGasPrice } = this.provider.getGasConfig();
|
4635
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4636
4706
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4637
4707
|
const request = new ScriptTransactionRequest(params);
|
4638
|
-
request.addCoinOutput(Address3.fromAddressOrString(destination), amount,
|
4708
|
+
request.addCoinOutput(Address3.fromAddressOrString(destination), amount, assetId);
|
4639
4709
|
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4640
4710
|
estimateTxDependencies: true,
|
4641
4711
|
resourcesOwner: this
|
4642
4712
|
});
|
4643
|
-
request.gasPrice =
|
4644
|
-
request.gasLimit =
|
4713
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
4714
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4645
4715
|
this.validateGas({
|
4646
4716
|
gasUsed,
|
4647
4717
|
gasPrice: request.gasPrice,
|
@@ -4661,15 +4731,14 @@ var Account = class extends AbstractAccount {
|
|
4661
4731
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4662
4732
|
* @returns A promise that resolves to the transaction response.
|
4663
4733
|
*/
|
4664
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4665
|
-
if (
|
4666
|
-
throw new
|
4667
|
-
|
4734
|
+
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4735
|
+
if (bn17(amount).lte(0)) {
|
4736
|
+
throw new FuelError15(
|
4737
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4668
4738
|
"Transfer amount must be a positive number."
|
4669
4739
|
);
|
4670
4740
|
}
|
4671
|
-
const
|
4672
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4741
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4673
4742
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4674
4743
|
}
|
4675
4744
|
/**
|
@@ -4681,21 +4750,20 @@ var Account = class extends AbstractAccount {
|
|
4681
4750
|
* @param txParams - The optional transaction parameters.
|
4682
4751
|
* @returns A promise that resolves to the transaction response.
|
4683
4752
|
*/
|
4684
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4685
|
-
if (
|
4686
|
-
throw new
|
4687
|
-
|
4753
|
+
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4754
|
+
if (bn17(amount).lte(0)) {
|
4755
|
+
throw new FuelError15(
|
4756
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4688
4757
|
"Transfer amount must be a positive number."
|
4689
4758
|
);
|
4690
4759
|
}
|
4691
4760
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4692
4761
|
const { minGasPrice } = this.provider.getGasConfig();
|
4693
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4694
4762
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4695
4763
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4696
4764
|
hexlifiedContractId: contractAddress.toB256(),
|
4697
|
-
amountToTransfer:
|
4698
|
-
assetId
|
4765
|
+
amountToTransfer: bn17(amount),
|
4766
|
+
assetId
|
4699
4767
|
});
|
4700
4768
|
const request = new ScriptTransactionRequest({
|
4701
4769
|
...params,
|
@@ -4705,9 +4773,9 @@ var Account = class extends AbstractAccount {
|
|
4705
4773
|
request.addContractInputAndOutput(contractAddress);
|
4706
4774
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4707
4775
|
request,
|
4708
|
-
[{ amount:
|
4776
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
4709
4777
|
);
|
4710
|
-
request.gasLimit =
|
4778
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4711
4779
|
this.validateGas({
|
4712
4780
|
gasUsed,
|
4713
4781
|
gasPrice: request.gasPrice,
|
@@ -4727,13 +4795,12 @@ var Account = class extends AbstractAccount {
|
|
4727
4795
|
*/
|
4728
4796
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4729
4797
|
const { minGasPrice } = this.provider.getGasConfig();
|
4730
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4731
4798
|
const recipientAddress = Address3.fromAddressOrString(recipient);
|
4732
4799
|
const recipientDataArray = arrayify14(
|
4733
4800
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4734
4801
|
);
|
4735
4802
|
const amountDataArray = arrayify14(
|
4736
|
-
"0x".concat(
|
4803
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
4737
4804
|
);
|
4738
4805
|
const script = new Uint8Array([
|
4739
4806
|
...arrayify14(withdrawScript.bytes),
|
@@ -4742,12 +4809,12 @@ var Account = class extends AbstractAccount {
|
|
4742
4809
|
]);
|
4743
4810
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4744
4811
|
const request = new ScriptTransactionRequest(params);
|
4745
|
-
const forwardingQuantities = [{ amount:
|
4812
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
4746
4813
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4747
4814
|
request,
|
4748
4815
|
forwardingQuantities
|
4749
4816
|
);
|
4750
|
-
request.gasLimit =
|
4817
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4751
4818
|
this.validateGas({
|
4752
4819
|
gasUsed,
|
4753
4820
|
gasPrice: request.gasPrice,
|
@@ -4759,7 +4826,7 @@ var Account = class extends AbstractAccount {
|
|
4759
4826
|
}
|
4760
4827
|
async signMessage(message) {
|
4761
4828
|
if (!this._connector) {
|
4762
|
-
throw new
|
4829
|
+
throw new FuelError15(ErrorCode15.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4763
4830
|
}
|
4764
4831
|
return this._connector.signMessage(this.address.toString(), message);
|
4765
4832
|
}
|
@@ -4771,8 +4838,8 @@ var Account = class extends AbstractAccount {
|
|
4771
4838
|
*/
|
4772
4839
|
async signTransaction(transactionRequestLike) {
|
4773
4840
|
if (!this._connector) {
|
4774
|
-
throw new
|
4775
|
-
|
4841
|
+
throw new FuelError15(
|
4842
|
+
ErrorCode15.MISSING_CONNECTOR,
|
4776
4843
|
"A connector is required to sign transactions."
|
4777
4844
|
);
|
4778
4845
|
}
|
@@ -4819,14 +4886,14 @@ var Account = class extends AbstractAccount {
|
|
4819
4886
|
minGasPrice
|
4820
4887
|
}) {
|
4821
4888
|
if (minGasPrice.gt(gasPrice)) {
|
4822
|
-
throw new
|
4823
|
-
|
4889
|
+
throw new FuelError15(
|
4890
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4824
4891
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4825
4892
|
);
|
4826
4893
|
}
|
4827
4894
|
if (gasUsed.gt(gasLimit)) {
|
4828
|
-
throw new
|
4829
|
-
|
4895
|
+
throw new FuelError15(
|
4896
|
+
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
4830
4897
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4831
4898
|
);
|
4832
4899
|
}
|
@@ -4953,7 +5020,7 @@ import {
|
|
4953
5020
|
decryptJsonWalletData,
|
4954
5021
|
encryptJsonWalletData
|
4955
5022
|
} from "@fuel-ts/crypto";
|
4956
|
-
import { ErrorCode as
|
5023
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
4957
5024
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
4958
5025
|
import { v4 as uuidv4 } from "uuid";
|
4959
5026
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -5031,8 +5098,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5031
5098
|
const macHashUint8Array = keccak256(data);
|
5032
5099
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
5033
5100
|
if (mac !== macHash) {
|
5034
|
-
throw new
|
5035
|
-
|
5101
|
+
throw new FuelError16(
|
5102
|
+
ErrorCode16.INVALID_PASSWORD,
|
5036
5103
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5037
5104
|
);
|
5038
5105
|
}
|
@@ -5154,15 +5221,15 @@ var BaseWalletUnlocked = class extends Account {
|
|
5154
5221
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5155
5222
|
|
5156
5223
|
// src/hdwallet/hdwallet.ts
|
5157
|
-
import { ErrorCode as
|
5224
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5158
5225
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5159
|
-
import { bn as
|
5226
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5160
5227
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5161
5228
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5162
5229
|
|
5163
5230
|
// src/mnemonic/mnemonic.ts
|
5164
5231
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5165
|
-
import { ErrorCode as
|
5232
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5166
5233
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5167
5234
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5168
5235
|
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
@@ -7220,7 +7287,7 @@ var english = [
|
|
7220
7287
|
];
|
7221
7288
|
|
7222
7289
|
// src/mnemonic/utils.ts
|
7223
|
-
import { ErrorCode as
|
7290
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
7224
7291
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7225
7292
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7226
7293
|
function toUtf8Bytes(stri) {
|
@@ -7237,8 +7304,8 @@ function toUtf8Bytes(stri) {
|
|
7237
7304
|
i += 1;
|
7238
7305
|
const c2 = str.charCodeAt(i);
|
7239
7306
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7240
|
-
throw new
|
7241
|
-
|
7307
|
+
throw new FuelError17(
|
7308
|
+
ErrorCode17.INVALID_INPUT_PARAMETERS,
|
7242
7309
|
"Invalid UTF-8 in the input string."
|
7243
7310
|
);
|
7244
7311
|
}
|
@@ -7301,8 +7368,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7301
7368
|
for (let i = 0; i < words.length; i += 1) {
|
7302
7369
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7303
7370
|
if (index === -1) {
|
7304
|
-
throw new
|
7305
|
-
|
7371
|
+
throw new FuelError17(
|
7372
|
+
ErrorCode17.INVALID_MNEMONIC,
|
7306
7373
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7307
7374
|
);
|
7308
7375
|
}
|
@@ -7318,8 +7385,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7318
7385
|
const checksumMask = getUpperMask(checksumBits);
|
7319
7386
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7320
7387
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7321
|
-
throw new
|
7322
|
-
|
7388
|
+
throw new FuelError17(
|
7389
|
+
ErrorCode17.INVALID_CHECKSUM,
|
7323
7390
|
"Checksum validation failed for the provided mnemonic."
|
7324
7391
|
);
|
7325
7392
|
}
|
@@ -7333,16 +7400,16 @@ var TestnetPRV = "0x04358394";
|
|
7333
7400
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7334
7401
|
function assertWordList(wordlist) {
|
7335
7402
|
if (wordlist.length !== 2048) {
|
7336
|
-
throw new
|
7337
|
-
|
7403
|
+
throw new FuelError18(
|
7404
|
+
ErrorCode18.INVALID_WORD_LIST,
|
7338
7405
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7339
7406
|
);
|
7340
7407
|
}
|
7341
7408
|
}
|
7342
7409
|
function assertEntropy(entropy) {
|
7343
7410
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7344
|
-
throw new
|
7345
|
-
|
7411
|
+
throw new FuelError18(
|
7412
|
+
ErrorCode18.INVALID_ENTROPY,
|
7346
7413
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7347
7414
|
);
|
7348
7415
|
}
|
@@ -7352,7 +7419,7 @@ function assertMnemonic(words) {
|
|
7352
7419
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7353
7420
|
", "
|
7354
7421
|
)}] words, but got ${words.length}.`;
|
7355
|
-
throw new
|
7422
|
+
throw new FuelError18(ErrorCode18.INVALID_MNEMONIC, errorMsg);
|
7356
7423
|
}
|
7357
7424
|
}
|
7358
7425
|
var Mnemonic = class {
|
@@ -7470,8 +7537,8 @@ var Mnemonic = class {
|
|
7470
7537
|
static masterKeysFromSeed(seed) {
|
7471
7538
|
const seedArray = arrayify17(seed);
|
7472
7539
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7473
|
-
throw new
|
7474
|
-
|
7540
|
+
throw new FuelError18(
|
7541
|
+
ErrorCode18.INVALID_SEED,
|
7475
7542
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7476
7543
|
);
|
7477
7544
|
}
|
@@ -7548,7 +7615,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7548
7615
|
function parsePath(path2, depth = 0) {
|
7549
7616
|
const components = path2.split("/");
|
7550
7617
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7551
|
-
throw new
|
7618
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7552
7619
|
}
|
7553
7620
|
if (components[0] === "m") {
|
7554
7621
|
components.shift();
|
@@ -7577,8 +7644,8 @@ var HDWallet = class {
|
|
7577
7644
|
this.privateKey = hexlify17(config.privateKey);
|
7578
7645
|
} else {
|
7579
7646
|
if (!config.publicKey) {
|
7580
|
-
throw new
|
7581
|
-
|
7647
|
+
throw new FuelError19(
|
7648
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7582
7649
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7583
7650
|
);
|
7584
7651
|
}
|
@@ -7607,8 +7674,8 @@ var HDWallet = class {
|
|
7607
7674
|
const data = new Uint8Array(37);
|
7608
7675
|
if (index & HARDENED_INDEX) {
|
7609
7676
|
if (!privateKey) {
|
7610
|
-
throw new
|
7611
|
-
|
7677
|
+
throw new FuelError19(
|
7678
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7612
7679
|
"Cannot derive a hardened index without a private Key."
|
7613
7680
|
);
|
7614
7681
|
}
|
@@ -7622,7 +7689,7 @@ var HDWallet = class {
|
|
7622
7689
|
const IR = bytes.slice(32);
|
7623
7690
|
if (privateKey) {
|
7624
7691
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7625
|
-
const ki =
|
7692
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7626
7693
|
return new HDWallet({
|
7627
7694
|
privateKey: ki,
|
7628
7695
|
chainCode: IR,
|
@@ -7660,8 +7727,8 @@ var HDWallet = class {
|
|
7660
7727
|
*/
|
7661
7728
|
toExtendedKey(isPublic = false, testnet = false) {
|
7662
7729
|
if (this.depth >= 256) {
|
7663
|
-
throw new
|
7664
|
-
|
7730
|
+
throw new FuelError19(
|
7731
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7665
7732
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7666
7733
|
);
|
7667
7734
|
}
|
@@ -7692,10 +7759,10 @@ var HDWallet = class {
|
|
7692
7759
|
const bytes = arrayify18(decoded);
|
7693
7760
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7694
7761
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7695
|
-
throw new
|
7762
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7696
7763
|
}
|
7697
7764
|
if (!validChecksum) {
|
7698
|
-
throw new
|
7765
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7699
7766
|
}
|
7700
7767
|
const depth = bytes[4];
|
7701
7768
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -7703,14 +7770,14 @@ var HDWallet = class {
|
|
7703
7770
|
const chainCode = hexlify17(bytes.slice(13, 45));
|
7704
7771
|
const key = bytes.slice(45, 78);
|
7705
7772
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7706
|
-
throw new
|
7707
|
-
|
7773
|
+
throw new FuelError19(
|
7774
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7708
7775
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7709
7776
|
);
|
7710
7777
|
}
|
7711
7778
|
if (isPublicExtendedKey(bytes)) {
|
7712
7779
|
if (key[0] !== 3) {
|
7713
|
-
throw new
|
7780
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid public extended key.");
|
7714
7781
|
}
|
7715
7782
|
return new HDWallet({
|
7716
7783
|
publicKey: key,
|
@@ -7721,7 +7788,7 @@ var HDWallet = class {
|
|
7721
7788
|
});
|
7722
7789
|
}
|
7723
7790
|
if (key[0] !== 0) {
|
7724
|
-
throw new
|
7791
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid private extended key.");
|
7725
7792
|
}
|
7726
7793
|
return new HDWallet({
|
7727
7794
|
privateKey: key.slice(1),
|
@@ -7914,7 +7981,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7914
7981
|
};
|
7915
7982
|
|
7916
7983
|
// src/test-utils/launchNode.ts
|
7917
|
-
import {
|
7984
|
+
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
7918
7985
|
import { toHex as toHex2 } from "@fuel-ts/math";
|
7919
7986
|
import { defaultChainConfig, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
7920
7987
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
@@ -8014,7 +8081,7 @@ var launchNode = async ({
|
|
8014
8081
|
{
|
8015
8082
|
owner: signer.address.toHexString(),
|
8016
8083
|
amount: toHex2(1e9),
|
8017
|
-
asset_id:
|
8084
|
+
asset_id: BaseAssetId4
|
8018
8085
|
}
|
8019
8086
|
]
|
8020
8087
|
}
|
@@ -8080,10 +8147,9 @@ var launchNode = async ({
|
|
8080
8147
|
})
|
8081
8148
|
);
|
8082
8149
|
var generateWallets = async (count, provider) => {
|
8083
|
-
const baseAssetId = provider.getBaseAssetId();
|
8084
8150
|
const wallets = [];
|
8085
8151
|
for (let i = 0; i < count; i += 1) {
|
8086
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8152
|
+
const wallet = await generateTestWallet(provider, [[1e3, BaseAssetId4]]);
|
8087
8153
|
wallets.push(wallet);
|
8088
8154
|
}
|
8089
8155
|
return wallets;
|