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