@fuel-ts/account 0.0.0-rc-2037-20240430170043 → 0.0.0-rc-2037-20240501112942
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 +1 -1
- package/dist/account.d.ts.map +1 -1
- package/dist/index.global.js +96 -49
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +226 -176
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +229 -180
- package/dist/index.mjs.map +1 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/resource.d.ts +0 -1
- package/dist/providers/resource.d.ts.map +1 -1
- package/dist/providers/transaction-request/helpers.d.ts +4 -2
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +3 -3
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +1 -1
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils.global.js +91 -44
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +216 -168
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +226 -178
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +15 -15
package/dist/index.mjs
CHANGED
@@ -31,8 +31,8 @@ var __privateMethod = (obj, member, method) => {
|
|
31
31
|
import { Address as Address3 } from "@fuel-ts/address";
|
32
32
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
33
33
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
34
|
-
import { bn as
|
35
|
-
import { arrayify as arrayify14, isDefined } from "@fuel-ts/utils";
|
34
|
+
import { bn as bn19 } from "@fuel-ts/math";
|
35
|
+
import { arrayify as arrayify14, isDefined as isDefined2 } from "@fuel-ts/utils";
|
36
36
|
import { clone as clone4 } from "ramda";
|
37
37
|
|
38
38
|
// src/providers/coin-quantity.ts
|
@@ -73,9 +73,9 @@ var addAmountToCoinQuantities = (params) => {
|
|
73
73
|
// src/providers/provider.ts
|
74
74
|
import { Address as Address2 } from "@fuel-ts/address";
|
75
75
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
76
|
-
import { BN, bn as
|
76
|
+
import { BN, bn as bn17 } from "@fuel-ts/math";
|
77
77
|
import {
|
78
|
-
InputType as
|
78
|
+
InputType as InputType7,
|
79
79
|
TransactionType as TransactionType8,
|
80
80
|
InputMessageCoder,
|
81
81
|
TransactionCoder as TransactionCoder5
|
@@ -1245,7 +1245,7 @@ import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
|
1245
1245
|
import { Address, addressify } from "@fuel-ts/address";
|
1246
1246
|
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1247
1247
|
import { randomBytes } from "@fuel-ts/crypto";
|
1248
|
-
import { bn as
|
1248
|
+
import { bn as bn8 } from "@fuel-ts/math";
|
1249
1249
|
import {
|
1250
1250
|
PolicyType,
|
1251
1251
|
TransactionCoder,
|
@@ -1253,7 +1253,7 @@ import {
|
|
1253
1253
|
OutputType as OutputType2,
|
1254
1254
|
TransactionType
|
1255
1255
|
} from "@fuel-ts/transactions";
|
1256
|
-
import { concat, hexlify as hexlify7 } from "@fuel-ts/utils";
|
1256
|
+
import { concat, hexlify as hexlify7, isDefined } from "@fuel-ts/utils";
|
1257
1257
|
|
1258
1258
|
// src/providers/resource.ts
|
1259
1259
|
var isRawCoin = (resource) => "utxoId" in resource;
|
@@ -1628,7 +1628,7 @@ function calculateMetadataGasForTxScript({
|
|
1628
1628
|
}
|
1629
1629
|
var calculateGasFee = (params) => {
|
1630
1630
|
const { gas, gasPrice, priceFactor, tip } = params;
|
1631
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1631
|
+
return gas.mul(gasPrice).div(priceFactor).add(bn5(tip));
|
1632
1632
|
};
|
1633
1633
|
|
1634
1634
|
// src/providers/utils/json.ts
|
@@ -1774,18 +1774,28 @@ var NoWitnessByOwnerError = class extends Error {
|
|
1774
1774
|
};
|
1775
1775
|
|
1776
1776
|
// src/providers/transaction-request/helpers.ts
|
1777
|
+
import { bn as bn7 } from "@fuel-ts/math";
|
1777
1778
|
import { InputType as InputType2 } from "@fuel-ts/transactions";
|
1778
1779
|
var isRequestInputCoin = (input) => input.type === InputType2.Coin;
|
1779
1780
|
var isRequestInputMessage = (input) => input.type === InputType2.Message;
|
1780
1781
|
var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
|
1781
1782
|
var getRequestInputResourceOwner = (input) => isRequestInputCoin(input) ? input.owner : input.recipient;
|
1782
1783
|
var isRequestInputResourceFromOwner = (input, owner) => getRequestInputResourceOwner(input) === owner.toB256();
|
1783
|
-
var
|
1784
|
-
(
|
1785
|
-
|
1786
|
-
|
1784
|
+
var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
|
1785
|
+
if (isRequestInputCoin(input) && input.assetId === assetId) {
|
1786
|
+
return acc.add(input.amount);
|
1787
|
+
}
|
1788
|
+
if (isRequestInputMessage(input) && assetId === baseAsset) {
|
1789
|
+
return acc.add(input.amount);
|
1790
|
+
}
|
1791
|
+
return acc;
|
1792
|
+
}, bn7(0));
|
1793
|
+
var cacheRequestInputsResources = (inputs) => inputs.filter(isRequestInputResource).reduce(
|
1794
|
+
(cache2, input) => {
|
1795
|
+
if (isRequestInputCoin(input)) {
|
1796
|
+
cache2.utxos.push(input.id);
|
1787
1797
|
} else {
|
1788
|
-
cache2.messages.push(
|
1798
|
+
cache2.messages.push(input.nonce);
|
1789
1799
|
}
|
1790
1800
|
return cache2;
|
1791
1801
|
},
|
@@ -1794,6 +1804,20 @@ var cacheResources = (resources) => resources.reduce(
|
|
1794
1804
|
messages: []
|
1795
1805
|
}
|
1796
1806
|
);
|
1807
|
+
var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
|
1808
|
+
(acc, input) => {
|
1809
|
+
if (isRequestInputCoin(input) && input.owner === owner.toB256()) {
|
1810
|
+
acc.utxos.push(input.id);
|
1811
|
+
} else if (isRequestInputMessage(input) && input.recipient === owner.toB256()) {
|
1812
|
+
acc.messages.push(input.nonce);
|
1813
|
+
}
|
1814
|
+
return acc;
|
1815
|
+
},
|
1816
|
+
{
|
1817
|
+
utxos: [],
|
1818
|
+
messages: []
|
1819
|
+
}
|
1820
|
+
);
|
1797
1821
|
|
1798
1822
|
// src/providers/transaction-request/witness.ts
|
1799
1823
|
import { arrayify as arrayify4, hexlify as hexlify6 } from "@fuel-ts/utils";
|
@@ -1835,10 +1859,10 @@ var BaseTransactionRequest = class {
|
|
1835
1859
|
outputs,
|
1836
1860
|
witnesses
|
1837
1861
|
} = {}) {
|
1838
|
-
this.tip =
|
1839
|
-
this.maturity = maturity
|
1840
|
-
this.witnessLimit = witnessLimit ?
|
1841
|
-
this.maxFee =
|
1862
|
+
this.tip = tip ? bn8(tip) : void 0;
|
1863
|
+
this.maturity = maturity && maturity > 0 ? maturity : void 0;
|
1864
|
+
this.witnessLimit = isDefined(witnessLimit) ? bn8(witnessLimit) : void 0;
|
1865
|
+
this.maxFee = bn8(maxFee);
|
1842
1866
|
this.inputs = inputs ?? [];
|
1843
1867
|
this.outputs = outputs ?? [];
|
1844
1868
|
this.witnesses = witnesses ?? [];
|
@@ -1846,22 +1870,21 @@ var BaseTransactionRequest = class {
|
|
1846
1870
|
static getPolicyMeta(req) {
|
1847
1871
|
let policyTypes = 0;
|
1848
1872
|
const policies = [];
|
1849
|
-
|
1873
|
+
const { tip, witnessLimit, maturity } = req;
|
1874
|
+
if (bn8(tip).gt(0)) {
|
1850
1875
|
policyTypes += PolicyType.Tip;
|
1851
|
-
policies.push({ data:
|
1876
|
+
policies.push({ data: bn8(tip), type: PolicyType.Tip });
|
1852
1877
|
}
|
1853
|
-
if (
|
1878
|
+
if (isDefined(witnessLimit) && bn8(witnessLimit).gte(0)) {
|
1854
1879
|
policyTypes += PolicyType.WitnessLimit;
|
1855
|
-
policies.push({ data:
|
1880
|
+
policies.push({ data: bn8(witnessLimit), type: PolicyType.WitnessLimit });
|
1856
1881
|
}
|
1857
|
-
if (
|
1882
|
+
if (maturity && maturity > 0) {
|
1858
1883
|
policyTypes += PolicyType.Maturity;
|
1859
|
-
policies.push({ data:
|
1860
|
-
}
|
1861
|
-
if (req.maxFee) {
|
1862
|
-
policyTypes += PolicyType.MaxFee;
|
1863
|
-
policies.push({ data: req.maxFee, type: PolicyType.MaxFee });
|
1884
|
+
policies.push({ data: maturity, type: PolicyType.Maturity });
|
1864
1885
|
}
|
1886
|
+
policyTypes += PolicyType.MaxFee;
|
1887
|
+
policies.push({ data: req.maxFee, type: PolicyType.MaxFee });
|
1865
1888
|
return {
|
1866
1889
|
policyTypes,
|
1867
1890
|
policies
|
@@ -2222,7 +2245,7 @@ var BaseTransactionRequest = class {
|
|
2222
2245
|
const assetInput = findAssetInput(assetId);
|
2223
2246
|
let usedQuantity = quantity;
|
2224
2247
|
if (assetId === baseAssetId) {
|
2225
|
-
usedQuantity =
|
2248
|
+
usedQuantity = bn8("1000000000000000000");
|
2226
2249
|
}
|
2227
2250
|
if (assetInput && "assetId" in assetInput) {
|
2228
2251
|
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
@@ -2234,13 +2257,13 @@ var BaseTransactionRequest = class {
|
|
2234
2257
|
amount: usedQuantity,
|
2235
2258
|
assetId,
|
2236
2259
|
owner: resourcesOwner || Address.fromRandom(),
|
2237
|
-
blockCreated:
|
2238
|
-
txCreatedIdx:
|
2260
|
+
blockCreated: bn8(1),
|
2261
|
+
txCreatedIdx: bn8(1)
|
2239
2262
|
}
|
2240
2263
|
]);
|
2241
2264
|
}
|
2242
2265
|
};
|
2243
|
-
updateAssetInput(baseAssetId,
|
2266
|
+
updateAssetInput(baseAssetId, bn8(1e11));
|
2244
2267
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2245
2268
|
}
|
2246
2269
|
/**
|
@@ -2251,7 +2274,7 @@ var BaseTransactionRequest = class {
|
|
2251
2274
|
*/
|
2252
2275
|
getCoinOutputsQuantities() {
|
2253
2276
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
2254
|
-
amount:
|
2277
|
+
amount: bn8(amount),
|
2255
2278
|
assetId: assetId.toString()
|
2256
2279
|
}));
|
2257
2280
|
return coinsQuantities;
|
@@ -2291,7 +2314,7 @@ var BaseTransactionRequest = class {
|
|
2291
2314
|
default:
|
2292
2315
|
return;
|
2293
2316
|
}
|
2294
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput &&
|
2317
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn8(correspondingInput.predicateGasUsed).gt(0)) {
|
2295
2318
|
i.predicate = correspondingInput.predicate;
|
2296
2319
|
i.predicateData = correspondingInput.predicateData;
|
2297
2320
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2311,14 +2334,14 @@ var BaseTransactionRequest = class {
|
|
2311
2334
|
|
2312
2335
|
// src/providers/transaction-request/create-transaction-request.ts
|
2313
2336
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
2314
|
-
import { bn as
|
2337
|
+
import { bn as bn10 } from "@fuel-ts/math";
|
2315
2338
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
2316
2339
|
import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
2317
2340
|
|
2318
2341
|
// src/providers/transaction-request/hash-transaction.ts
|
2319
2342
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2320
2343
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2321
|
-
import { bn as
|
2344
|
+
import { bn as bn9 } from "@fuel-ts/math";
|
2322
2345
|
import { TransactionType as TransactionType2, InputType as InputType4, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2323
2346
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2324
2347
|
import { clone as clone2 } from "ramda";
|
@@ -2335,11 +2358,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2335
2358
|
blockHeight: 0,
|
2336
2359
|
txIndex: 0
|
2337
2360
|
};
|
2338
|
-
inputClone.predicateGasUsed =
|
2361
|
+
inputClone.predicateGasUsed = bn9(0);
|
2339
2362
|
return inputClone;
|
2340
2363
|
}
|
2341
2364
|
case InputType4.Message: {
|
2342
|
-
inputClone.predicateGasUsed =
|
2365
|
+
inputClone.predicateGasUsed = bn9(0);
|
2343
2366
|
return inputClone;
|
2344
2367
|
}
|
2345
2368
|
case InputType4.Contract: {
|
@@ -2366,12 +2389,12 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2366
2389
|
return outputClone;
|
2367
2390
|
}
|
2368
2391
|
case OutputType3.Change: {
|
2369
|
-
outputClone.amount =
|
2392
|
+
outputClone.amount = bn9(0);
|
2370
2393
|
return outputClone;
|
2371
2394
|
}
|
2372
2395
|
case OutputType3.Variable: {
|
2373
2396
|
outputClone.to = ZeroBytes325;
|
2374
|
-
outputClone.amount =
|
2397
|
+
outputClone.amount = bn9(0);
|
2375
2398
|
outputClone.assetId = ZeroBytes325;
|
2376
2399
|
return outputClone;
|
2377
2400
|
}
|
@@ -2449,7 +2472,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2449
2472
|
type: TransactionType3.Create,
|
2450
2473
|
...baseTransaction,
|
2451
2474
|
bytecodeWitnessIndex,
|
2452
|
-
storageSlotsCount:
|
2475
|
+
storageSlotsCount: bn10(storageSlots.length),
|
2453
2476
|
salt: this.salt ? hexlify9(this.salt) : ZeroBytes326,
|
2454
2477
|
storageSlots
|
2455
2478
|
};
|
@@ -2489,7 +2512,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2489
2512
|
}
|
2490
2513
|
metadataGas(gasCosts) {
|
2491
2514
|
return calculateMetadataGasForTxCreate({
|
2492
|
-
contractBytesSize:
|
2515
|
+
contractBytesSize: bn10(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2493
2516
|
gasCosts,
|
2494
2517
|
stateRootSize: this.storageSlots.length,
|
2495
2518
|
txBytesSize: this.byteSize()
|
@@ -2501,7 +2524,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2501
2524
|
import { Interface } from "@fuel-ts/abi-coder";
|
2502
2525
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2503
2526
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2504
|
-
import { bn as
|
2527
|
+
import { bn as bn11 } from "@fuel-ts/math";
|
2505
2528
|
import { InputType as InputType5, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2506
2529
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2507
2530
|
|
@@ -2555,7 +2578,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2555
2578
|
*/
|
2556
2579
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2557
2580
|
super(rest);
|
2558
|
-
this.gasLimit =
|
2581
|
+
this.gasLimit = bn11(gasLimit);
|
2559
2582
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
2560
2583
|
this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
|
2561
2584
|
this.abis = rest.abis;
|
@@ -2572,8 +2595,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2572
2595
|
type: TransactionType4.Script,
|
2573
2596
|
scriptGasLimit: this.gasLimit,
|
2574
2597
|
...super.getBaseTransaction(),
|
2575
|
-
scriptLength:
|
2576
|
-
scriptDataLength:
|
2598
|
+
scriptLength: bn11(script.length),
|
2599
|
+
scriptDataLength: bn11(scriptData.length),
|
2577
2600
|
receiptsRoot: ZeroBytes327,
|
2578
2601
|
script: hexlify10(script),
|
2579
2602
|
scriptData: hexlify10(scriptData)
|
@@ -2705,7 +2728,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2705
2728
|
|
2706
2729
|
// src/providers/transaction-request/utils.ts
|
2707
2730
|
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2708
|
-
import { TransactionType as TransactionType5
|
2731
|
+
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2709
2732
|
var transactionRequestify = (obj) => {
|
2710
2733
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2711
2734
|
return obj;
|
@@ -2723,35 +2746,20 @@ var transactionRequestify = (obj) => {
|
|
2723
2746
|
}
|
2724
2747
|
}
|
2725
2748
|
};
|
2726
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2727
|
-
(acc, input) => {
|
2728
|
-
if (input.type === InputType6.Coin && input.owner === owner) {
|
2729
|
-
acc.utxos.push(input.id);
|
2730
|
-
}
|
2731
|
-
if (input.type === InputType6.Message && input.recipient === owner) {
|
2732
|
-
acc.messages.push(input.nonce);
|
2733
|
-
}
|
2734
|
-
return acc;
|
2735
|
-
},
|
2736
|
-
{
|
2737
|
-
utxos: [],
|
2738
|
-
messages: []
|
2739
|
-
}
|
2740
|
-
);
|
2741
2749
|
|
2742
2750
|
// src/providers/transaction-response/transaction-response.ts
|
2743
2751
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2744
|
-
import { bn as
|
2752
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
2745
2753
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2746
2754
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2747
2755
|
|
2748
2756
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2749
|
-
import { bn as
|
2757
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2750
2758
|
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2751
2759
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2752
2760
|
|
2753
2761
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2754
|
-
import { bn as
|
2762
|
+
import { bn as bn12 } from "@fuel-ts/math";
|
2755
2763
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2756
2764
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2757
2765
|
var calculateTransactionFee = (params) => {
|
@@ -2761,23 +2769,23 @@ var calculateTransactionFee = (params) => {
|
|
2761
2769
|
tip,
|
2762
2770
|
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2763
2771
|
} = params;
|
2764
|
-
const gasPerByte =
|
2765
|
-
const gasPriceFactor =
|
2772
|
+
const gasPerByte = bn12(feeParams.gasPerByte);
|
2773
|
+
const gasPriceFactor = bn12(feeParams.gasPriceFactor);
|
2766
2774
|
const transactionBytes = arrayify9(rawPayload);
|
2767
2775
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2768
2776
|
if (transaction.type === TransactionType6.Mint) {
|
2769
2777
|
return {
|
2770
|
-
fee:
|
2771
|
-
minFee:
|
2772
|
-
maxFee:
|
2778
|
+
fee: bn12(0),
|
2779
|
+
minFee: bn12(0),
|
2780
|
+
maxFee: bn12(0)
|
2773
2781
|
};
|
2774
2782
|
}
|
2775
2783
|
const { type, witnesses, inputs, policies } = transaction;
|
2776
|
-
let metadataGas =
|
2777
|
-
let gasLimit =
|
2784
|
+
let metadataGas = bn12(0);
|
2785
|
+
let gasLimit = bn12(0);
|
2778
2786
|
if (type === TransactionType6.Create) {
|
2779
2787
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2780
|
-
const contractBytesSize =
|
2788
|
+
const contractBytesSize = bn12(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
|
2781
2789
|
metadataGas = calculateMetadataGasForTxCreate({
|
2782
2790
|
contractBytesSize,
|
2783
2791
|
gasCosts,
|
@@ -2796,7 +2804,7 @@ var calculateTransactionFee = (params) => {
|
|
2796
2804
|
}
|
2797
2805
|
const minGas = getMinGas({
|
2798
2806
|
gasCosts,
|
2799
|
-
gasPerByte:
|
2807
|
+
gasPerByte: bn12(gasPerByte),
|
2800
2808
|
inputs,
|
2801
2809
|
metadataGas,
|
2802
2810
|
txBytesSize: transactionBytes.length
|
@@ -2833,12 +2841,12 @@ var calculateTransactionFee = (params) => {
|
|
2833
2841
|
// src/providers/transaction-summary/operations.ts
|
2834
2842
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2835
2843
|
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
2836
|
-
import { bn as
|
2844
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2837
2845
|
import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2838
2846
|
|
2839
2847
|
// src/providers/transaction-summary/call.ts
|
2840
2848
|
import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
|
2841
|
-
import { bn as
|
2849
|
+
import { bn as bn13 } from "@fuel-ts/math";
|
2842
2850
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2843
2851
|
const abiInterface = new Interface2(abi);
|
2844
2852
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2847,7 +2855,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2847
2855
|
let encodedArgs;
|
2848
2856
|
if (functionFragment.isInputDataPointer) {
|
2849
2857
|
if (rawPayload) {
|
2850
|
-
const argsOffset =
|
2858
|
+
const argsOffset = bn13(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2851
2859
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2852
2860
|
}
|
2853
2861
|
} else {
|
@@ -2882,7 +2890,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2882
2890
|
|
2883
2891
|
// src/providers/transaction-summary/input.ts
|
2884
2892
|
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2885
|
-
import { InputType as
|
2893
|
+
import { InputType as InputType6 } from "@fuel-ts/transactions";
|
2886
2894
|
function getInputsByTypes(inputs, types) {
|
2887
2895
|
return inputs.filter((i) => types.includes(i.type));
|
2888
2896
|
}
|
@@ -2890,16 +2898,16 @@ function getInputsByType(inputs, type) {
|
|
2890
2898
|
return inputs.filter((i) => i.type === type);
|
2891
2899
|
}
|
2892
2900
|
function getInputsCoin(inputs) {
|
2893
|
-
return getInputsByType(inputs,
|
2901
|
+
return getInputsByType(inputs, InputType6.Coin);
|
2894
2902
|
}
|
2895
2903
|
function getInputsMessage(inputs) {
|
2896
|
-
return getInputsByType(inputs,
|
2904
|
+
return getInputsByType(inputs, InputType6.Message);
|
2897
2905
|
}
|
2898
2906
|
function getInputsCoinAndMessage(inputs) {
|
2899
|
-
return getInputsByTypes(inputs, [
|
2907
|
+
return getInputsByTypes(inputs, [InputType6.Coin, InputType6.Message]);
|
2900
2908
|
}
|
2901
2909
|
function getInputsContract(inputs) {
|
2902
|
-
return getInputsByType(inputs,
|
2910
|
+
return getInputsByType(inputs, InputType6.Contract);
|
2903
2911
|
}
|
2904
2912
|
function getInputFromAssetId(inputs, assetId) {
|
2905
2913
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2918,7 +2926,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2918
2926
|
if (!contractInput) {
|
2919
2927
|
return void 0;
|
2920
2928
|
}
|
2921
|
-
if (contractInput.type !==
|
2929
|
+
if (contractInput.type !== InputType6.Contract) {
|
2922
2930
|
throw new FuelError9(
|
2923
2931
|
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2924
2932
|
`Contract input should be of type 'contract'.`
|
@@ -2927,10 +2935,10 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2927
2935
|
return contractInput;
|
2928
2936
|
}
|
2929
2937
|
function getInputAccountAddress(input) {
|
2930
|
-
if (input.type ===
|
2938
|
+
if (input.type === InputType6.Coin) {
|
2931
2939
|
return input.owner.toString();
|
2932
2940
|
}
|
2933
|
-
if (input.type ===
|
2941
|
+
if (input.type === InputType6.Message) {
|
2934
2942
|
return input.recipient.toString();
|
2935
2943
|
}
|
2936
2944
|
return "";
|
@@ -3047,7 +3055,7 @@ var mergeAssets = (op1, op2) => {
|
|
3047
3055
|
if (!matchingAsset) {
|
3048
3056
|
return asset1;
|
3049
3057
|
}
|
3050
|
-
const mergedAmount =
|
3058
|
+
const mergedAmount = bn14(asset1.amount).add(matchingAsset.amount);
|
3051
3059
|
return { ...asset1, amount: mergedAmount };
|
3052
3060
|
});
|
3053
3061
|
return mergedAssets.concat(filteredAssets);
|
@@ -3456,7 +3464,7 @@ function assembleTransactionSummary(params) {
|
|
3456
3464
|
maxInputs
|
3457
3465
|
});
|
3458
3466
|
const typeName = getTransactionTypeName(transaction.type);
|
3459
|
-
const tip =
|
3467
|
+
const tip = bn15(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3460
3468
|
const { fee } = calculateTransactionFee({
|
3461
3469
|
gasPrice,
|
3462
3470
|
rawPayload,
|
@@ -3523,7 +3531,7 @@ var TransactionResponse = class {
|
|
3523
3531
|
/** Current provider */
|
3524
3532
|
provider;
|
3525
3533
|
/** Gas used on the transaction */
|
3526
|
-
gasUsed =
|
3534
|
+
gasUsed = bn16(0);
|
3527
3535
|
/** The graphql Transaction with receipts object. */
|
3528
3536
|
gqlTransaction;
|
3529
3537
|
abis;
|
@@ -3747,30 +3755,30 @@ var processGqlChain = (chain) => {
|
|
3747
3755
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3748
3756
|
return {
|
3749
3757
|
name,
|
3750
|
-
baseChainHeight:
|
3758
|
+
baseChainHeight: bn17(daHeight),
|
3751
3759
|
consensusParameters: {
|
3752
|
-
contractMaxSize:
|
3753
|
-
maxInputs:
|
3754
|
-
maxOutputs:
|
3755
|
-
maxWitnesses:
|
3756
|
-
maxGasPerTx:
|
3757
|
-
maxScriptLength:
|
3758
|
-
maxScriptDataLength:
|
3759
|
-
maxStorageSlots:
|
3760
|
-
maxPredicateLength:
|
3761
|
-
maxPredicateDataLength:
|
3762
|
-
maxGasPerPredicate:
|
3763
|
-
gasPriceFactor:
|
3764
|
-
gasPerByte:
|
3765
|
-
maxMessageDataLength:
|
3766
|
-
chainId:
|
3760
|
+
contractMaxSize: bn17(contractParams.contractMaxSize),
|
3761
|
+
maxInputs: bn17(txParams.maxInputs),
|
3762
|
+
maxOutputs: bn17(txParams.maxOutputs),
|
3763
|
+
maxWitnesses: bn17(txParams.maxWitnesses),
|
3764
|
+
maxGasPerTx: bn17(txParams.maxGasPerTx),
|
3765
|
+
maxScriptLength: bn17(scriptParams.maxScriptLength),
|
3766
|
+
maxScriptDataLength: bn17(scriptParams.maxScriptDataLength),
|
3767
|
+
maxStorageSlots: bn17(contractParams.maxStorageSlots),
|
3768
|
+
maxPredicateLength: bn17(predicateParams.maxPredicateLength),
|
3769
|
+
maxPredicateDataLength: bn17(predicateParams.maxPredicateDataLength),
|
3770
|
+
maxGasPerPredicate: bn17(predicateParams.maxGasPerPredicate),
|
3771
|
+
gasPriceFactor: bn17(feeParams.gasPriceFactor),
|
3772
|
+
gasPerByte: bn17(feeParams.gasPerByte),
|
3773
|
+
maxMessageDataLength: bn17(predicateParams.maxMessageDataLength),
|
3774
|
+
chainId: bn17(consensusParameters.chainId),
|
3767
3775
|
baseAssetId: consensusParameters.baseAssetId,
|
3768
3776
|
gasCosts
|
3769
3777
|
},
|
3770
3778
|
gasCosts,
|
3771
3779
|
latestBlock: {
|
3772
3780
|
id: latestBlock.id,
|
3773
|
-
height:
|
3781
|
+
height: bn17(latestBlock.height),
|
3774
3782
|
time: latestBlock.header.time,
|
3775
3783
|
transactions: latestBlock.transactions.map((i) => ({
|
3776
3784
|
id: i.id
|
@@ -3913,7 +3921,18 @@ var _Provider = class {
|
|
3913
3921
|
createOperations() {
|
3914
3922
|
const fetchFn = _Provider.getFetchFn(this.options);
|
3915
3923
|
const gqlClient = new GraphQLClient(this.url, {
|
3916
|
-
fetch: (url, requestInit) => fetchFn(url, requestInit, this.options)
|
3924
|
+
fetch: (url, requestInit) => fetchFn(url, requestInit, this.options),
|
3925
|
+
responseMiddleware: (response) => {
|
3926
|
+
if ("response" in response) {
|
3927
|
+
const graphQlResponse = response.response;
|
3928
|
+
if (Array.isArray(graphQlResponse?.errors)) {
|
3929
|
+
throw new FuelError13(
|
3930
|
+
FuelError13.CODES.INVALID_REQUEST,
|
3931
|
+
graphQlResponse.errors.map((err) => err.message).join("\n\n")
|
3932
|
+
);
|
3933
|
+
}
|
3934
|
+
}
|
3935
|
+
}
|
3917
3936
|
});
|
3918
3937
|
const executeQuery = (query, vars) => {
|
3919
3938
|
const opDefinition = query.definitions.find((x) => x.kind === "OperationDefinition");
|
@@ -3948,7 +3967,7 @@ var _Provider = class {
|
|
3948
3967
|
*/
|
3949
3968
|
async getBlockNumber() {
|
3950
3969
|
const { chain } = await this.operations.getChain();
|
3951
|
-
return
|
3970
|
+
return bn17(chain.latestBlock.height, 10);
|
3952
3971
|
}
|
3953
3972
|
/**
|
3954
3973
|
* Returns the chain information.
|
@@ -3958,8 +3977,8 @@ var _Provider = class {
|
|
3958
3977
|
async fetchNode() {
|
3959
3978
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3960
3979
|
const processedNodeInfo = {
|
3961
|
-
maxDepth:
|
3962
|
-
maxTx:
|
3980
|
+
maxDepth: bn17(nodeInfo.maxDepth),
|
3981
|
+
maxTx: bn17(nodeInfo.maxTx),
|
3963
3982
|
nodeVersion: nodeInfo.nodeVersion,
|
3964
3983
|
utxoValidation: nodeInfo.utxoValidation,
|
3965
3984
|
vmBacktrace: nodeInfo.vmBacktrace
|
@@ -4091,7 +4110,7 @@ var _Provider = class {
|
|
4091
4110
|
} = response;
|
4092
4111
|
if (inputs) {
|
4093
4112
|
inputs.forEach((input, index) => {
|
4094
|
-
if ("predicateGasUsed" in input &&
|
4113
|
+
if ("predicateGasUsed" in input && bn17(input.predicateGasUsed).gt(0)) {
|
4095
4114
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4096
4115
|
}
|
4097
4116
|
});
|
@@ -4249,12 +4268,12 @@ var _Provider = class {
|
|
4249
4268
|
gasPrice = await this.estimateGasPrice(10);
|
4250
4269
|
}
|
4251
4270
|
const minFee = calculateGasFee({
|
4252
|
-
gasPrice:
|
4271
|
+
gasPrice: bn17(gasPrice),
|
4253
4272
|
gas: minGas,
|
4254
4273
|
priceFactor: gasPriceFactor,
|
4255
4274
|
tip: transactionRequest.tip
|
4256
4275
|
}).add(1);
|
4257
|
-
let gasLimit =
|
4276
|
+
let gasLimit = bn17(0);
|
4258
4277
|
if (transactionRequest.type === TransactionType8.Script) {
|
4259
4278
|
gasLimit = transactionRequest.gasLimit;
|
4260
4279
|
if (transactionRequest.gasLimit.eq(0)) {
|
@@ -4267,7 +4286,7 @@ var _Provider = class {
|
|
4267
4286
|
}
|
4268
4287
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4269
4288
|
const maxFee = calculateGasFee({
|
4270
|
-
gasPrice:
|
4289
|
+
gasPrice: bn17(gasPrice),
|
4271
4290
|
gas: maxGas,
|
4272
4291
|
priceFactor: gasPriceFactor,
|
4273
4292
|
tip: transactionRequest.tip
|
@@ -4330,9 +4349,9 @@ var _Provider = class {
|
|
4330
4349
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4331
4350
|
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4332
4351
|
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
4333
|
-
txRequestClone.maxFee =
|
4352
|
+
txRequestClone.maxFee = bn17(0);
|
4334
4353
|
if (isScriptTransaction) {
|
4335
|
-
txRequestClone.gasLimit =
|
4354
|
+
txRequestClone.gasLimit = bn17(0);
|
4336
4355
|
}
|
4337
4356
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4338
4357
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -4351,7 +4370,7 @@ var _Provider = class {
|
|
4351
4370
|
let receipts = [];
|
4352
4371
|
let missingContractIds = [];
|
4353
4372
|
let outputVariables = 0;
|
4354
|
-
let gasUsed =
|
4373
|
+
let gasUsed = bn17(0);
|
4355
4374
|
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4356
4375
|
txRequestClone.maxFee = maxFee;
|
4357
4376
|
if (isScriptTransaction) {
|
@@ -4418,10 +4437,10 @@ var _Provider = class {
|
|
4418
4437
|
return coins.map((coin) => ({
|
4419
4438
|
id: coin.utxoId,
|
4420
4439
|
assetId: coin.assetId,
|
4421
|
-
amount:
|
4440
|
+
amount: bn17(coin.amount),
|
4422
4441
|
owner: Address2.fromAddressOrString(coin.owner),
|
4423
|
-
blockCreated:
|
4424
|
-
txCreatedIdx:
|
4442
|
+
blockCreated: bn17(coin.blockCreated),
|
4443
|
+
txCreatedIdx: bn17(coin.txCreatedIdx)
|
4425
4444
|
}));
|
4426
4445
|
}
|
4427
4446
|
/**
|
@@ -4458,9 +4477,9 @@ var _Provider = class {
|
|
4458
4477
|
switch (coin.__typename) {
|
4459
4478
|
case "MessageCoin":
|
4460
4479
|
return {
|
4461
|
-
amount:
|
4480
|
+
amount: bn17(coin.amount),
|
4462
4481
|
assetId: coin.assetId,
|
4463
|
-
daHeight:
|
4482
|
+
daHeight: bn17(coin.daHeight),
|
4464
4483
|
sender: Address2.fromAddressOrString(coin.sender),
|
4465
4484
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4466
4485
|
nonce: coin.nonce
|
@@ -4468,11 +4487,11 @@ var _Provider = class {
|
|
4468
4487
|
case "Coin":
|
4469
4488
|
return {
|
4470
4489
|
id: coin.utxoId,
|
4471
|
-
amount:
|
4490
|
+
amount: bn17(coin.amount),
|
4472
4491
|
assetId: coin.assetId,
|
4473
4492
|
owner: Address2.fromAddressOrString(coin.owner),
|
4474
|
-
blockCreated:
|
4475
|
-
txCreatedIdx:
|
4493
|
+
blockCreated: bn17(coin.blockCreated),
|
4494
|
+
txCreatedIdx: bn17(coin.txCreatedIdx)
|
4476
4495
|
};
|
4477
4496
|
default:
|
4478
4497
|
return null;
|
@@ -4489,13 +4508,13 @@ var _Provider = class {
|
|
4489
4508
|
async getBlock(idOrHeight) {
|
4490
4509
|
let variables;
|
4491
4510
|
if (typeof idOrHeight === "number") {
|
4492
|
-
variables = { height:
|
4511
|
+
variables = { height: bn17(idOrHeight).toString(10) };
|
4493
4512
|
} else if (idOrHeight === "latest") {
|
4494
4513
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4495
4514
|
} else if (idOrHeight.length === 66) {
|
4496
4515
|
variables = { blockId: idOrHeight };
|
4497
4516
|
} else {
|
4498
|
-
variables = { blockId:
|
4517
|
+
variables = { blockId: bn17(idOrHeight).toString(10) };
|
4499
4518
|
}
|
4500
4519
|
const { block } = await this.operations.getBlock(variables);
|
4501
4520
|
if (!block) {
|
@@ -4503,7 +4522,7 @@ var _Provider = class {
|
|
4503
4522
|
}
|
4504
4523
|
return {
|
4505
4524
|
id: block.id,
|
4506
|
-
height:
|
4525
|
+
height: bn17(block.height),
|
4507
4526
|
time: block.header.time,
|
4508
4527
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4509
4528
|
};
|
@@ -4518,7 +4537,7 @@ var _Provider = class {
|
|
4518
4537
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4519
4538
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4520
4539
|
id: block.id,
|
4521
|
-
height:
|
4540
|
+
height: bn17(block.height),
|
4522
4541
|
time: block.header.time,
|
4523
4542
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4524
4543
|
}));
|
@@ -4533,7 +4552,7 @@ var _Provider = class {
|
|
4533
4552
|
async getBlockWithTransactions(idOrHeight) {
|
4534
4553
|
let variables;
|
4535
4554
|
if (typeof idOrHeight === "number") {
|
4536
|
-
variables = { blockHeight:
|
4555
|
+
variables = { blockHeight: bn17(idOrHeight).toString(10) };
|
4537
4556
|
} else if (idOrHeight === "latest") {
|
4538
4557
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4539
4558
|
} else {
|
@@ -4545,7 +4564,7 @@ var _Provider = class {
|
|
4545
4564
|
}
|
4546
4565
|
return {
|
4547
4566
|
id: block.id,
|
4548
|
-
height:
|
4567
|
+
height: bn17(block.height, 10),
|
4549
4568
|
time: block.header.time,
|
4550
4569
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4551
4570
|
transactions: block.transactions.map(
|
@@ -4594,7 +4613,7 @@ var _Provider = class {
|
|
4594
4613
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4595
4614
|
asset: hexlify12(assetId)
|
4596
4615
|
});
|
4597
|
-
return
|
4616
|
+
return bn17(contractBalance.amount, 10);
|
4598
4617
|
}
|
4599
4618
|
/**
|
4600
4619
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4608,7 +4627,7 @@ var _Provider = class {
|
|
4608
4627
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4609
4628
|
assetId: hexlify12(assetId)
|
4610
4629
|
});
|
4611
|
-
return
|
4630
|
+
return bn17(balance.amount, 10);
|
4612
4631
|
}
|
4613
4632
|
/**
|
4614
4633
|
* Returns balances for the given owner.
|
@@ -4626,7 +4645,7 @@ var _Provider = class {
|
|
4626
4645
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4627
4646
|
return balances.map((balance) => ({
|
4628
4647
|
assetId: balance.assetId,
|
4629
|
-
amount:
|
4648
|
+
amount: bn17(balance.amount)
|
4630
4649
|
}));
|
4631
4650
|
}
|
4632
4651
|
/**
|
@@ -4648,15 +4667,15 @@ var _Provider = class {
|
|
4648
4667
|
sender: message.sender,
|
4649
4668
|
recipient: message.recipient,
|
4650
4669
|
nonce: message.nonce,
|
4651
|
-
amount:
|
4670
|
+
amount: bn17(message.amount),
|
4652
4671
|
data: message.data
|
4653
4672
|
}),
|
4654
4673
|
sender: Address2.fromAddressOrString(message.sender),
|
4655
4674
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4656
4675
|
nonce: message.nonce,
|
4657
|
-
amount:
|
4676
|
+
amount: bn17(message.amount),
|
4658
4677
|
data: InputMessageCoder.decodeData(message.data),
|
4659
|
-
daHeight:
|
4678
|
+
daHeight: bn17(message.daHeight)
|
4660
4679
|
}));
|
4661
4680
|
}
|
4662
4681
|
/**
|
@@ -4709,23 +4728,23 @@ var _Provider = class {
|
|
4709
4728
|
} = result.messageProof;
|
4710
4729
|
return {
|
4711
4730
|
messageProof: {
|
4712
|
-
proofIndex:
|
4731
|
+
proofIndex: bn17(messageProof.proofIndex),
|
4713
4732
|
proofSet: messageProof.proofSet
|
4714
4733
|
},
|
4715
4734
|
blockProof: {
|
4716
|
-
proofIndex:
|
4735
|
+
proofIndex: bn17(blockProof.proofIndex),
|
4717
4736
|
proofSet: blockProof.proofSet
|
4718
4737
|
},
|
4719
4738
|
messageBlockHeader: {
|
4720
4739
|
id: messageBlockHeader.id,
|
4721
|
-
daHeight:
|
4722
|
-
transactionsCount:
|
4740
|
+
daHeight: bn17(messageBlockHeader.daHeight),
|
4741
|
+
transactionsCount: bn17(messageBlockHeader.transactionsCount),
|
4723
4742
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4724
|
-
height:
|
4743
|
+
height: bn17(messageBlockHeader.height),
|
4725
4744
|
prevRoot: messageBlockHeader.prevRoot,
|
4726
4745
|
time: messageBlockHeader.time,
|
4727
4746
|
applicationHash: messageBlockHeader.applicationHash,
|
4728
|
-
messageReceiptCount:
|
4747
|
+
messageReceiptCount: bn17(messageBlockHeader.messageReceiptCount),
|
4729
4748
|
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4730
4749
|
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4731
4750
|
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
@@ -4733,14 +4752,14 @@ var _Provider = class {
|
|
4733
4752
|
},
|
4734
4753
|
commitBlockHeader: {
|
4735
4754
|
id: commitBlockHeader.id,
|
4736
|
-
daHeight:
|
4737
|
-
transactionsCount:
|
4755
|
+
daHeight: bn17(commitBlockHeader.daHeight),
|
4756
|
+
transactionsCount: bn17(commitBlockHeader.transactionsCount),
|
4738
4757
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4739
|
-
height:
|
4758
|
+
height: bn17(commitBlockHeader.height),
|
4740
4759
|
prevRoot: commitBlockHeader.prevRoot,
|
4741
4760
|
time: commitBlockHeader.time,
|
4742
4761
|
applicationHash: commitBlockHeader.applicationHash,
|
4743
|
-
messageReceiptCount:
|
4762
|
+
messageReceiptCount: bn17(commitBlockHeader.messageReceiptCount),
|
4744
4763
|
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4745
4764
|
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4746
4765
|
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
@@ -4749,19 +4768,19 @@ var _Provider = class {
|
|
4749
4768
|
sender: Address2.fromAddressOrString(sender),
|
4750
4769
|
recipient: Address2.fromAddressOrString(recipient),
|
4751
4770
|
nonce,
|
4752
|
-
amount:
|
4771
|
+
amount: bn17(amount),
|
4753
4772
|
data
|
4754
4773
|
};
|
4755
4774
|
}
|
4756
4775
|
async getLatestGasPrice() {
|
4757
4776
|
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4758
|
-
return
|
4777
|
+
return bn17(latestGasPrice.gasPrice);
|
4759
4778
|
}
|
4760
4779
|
async estimateGasPrice(blockHorizon) {
|
4761
4780
|
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4762
4781
|
blockHorizon: String(blockHorizon)
|
4763
4782
|
});
|
4764
|
-
return
|
4783
|
+
return bn17(estimateGasPrice.gasPrice);
|
4765
4784
|
}
|
4766
4785
|
/**
|
4767
4786
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
@@ -4782,10 +4801,10 @@ var _Provider = class {
|
|
4782
4801
|
*/
|
4783
4802
|
async produceBlocks(amount, startTime) {
|
4784
4803
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4785
|
-
blocksToProduce:
|
4804
|
+
blocksToProduce: bn17(amount).toString(10),
|
4786
4805
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4787
4806
|
});
|
4788
|
-
return
|
4807
|
+
return bn17(latestBlockHeight);
|
4789
4808
|
}
|
4790
4809
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4791
4810
|
async getTransactionResponse(transactionId) {
|
@@ -4812,7 +4831,7 @@ cacheInputs_fn = function(inputs) {
|
|
4812
4831
|
return;
|
4813
4832
|
}
|
4814
4833
|
inputs.forEach((input) => {
|
4815
|
-
if (input.type ===
|
4834
|
+
if (input.type === InputType7.Coin) {
|
4816
4835
|
this.cache?.set(input.id);
|
4817
4836
|
}
|
4818
4837
|
});
|
@@ -4822,7 +4841,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4822
4841
|
|
4823
4842
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4824
4843
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4825
|
-
import { bn as
|
4844
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
4826
4845
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4827
4846
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4828
4847
|
async function getTransactionSummary(params) {
|
@@ -4855,8 +4874,8 @@ async function getTransactionSummary(params) {
|
|
4855
4874
|
transaction: decodedTransaction,
|
4856
4875
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4857
4876
|
gqlTransactionStatus: gqlTransaction.status,
|
4858
|
-
gasPerByte:
|
4859
|
-
gasPriceFactor:
|
4877
|
+
gasPerByte: bn18(gasPerByte),
|
4878
|
+
gasPriceFactor: bn18(gasPriceFactor),
|
4860
4879
|
abiMap,
|
4861
4880
|
maxInputs,
|
4862
4881
|
gasCosts,
|
@@ -5091,6 +5110,7 @@ var assembleTransferToContractScript = async (params) => {
|
|
5091
5110
|
};
|
5092
5111
|
|
5093
5112
|
// src/account.ts
|
5113
|
+
var MAX_FUNDING_ATTEMPTS = 2;
|
5094
5114
|
var Account = class extends AbstractAccount {
|
5095
5115
|
/**
|
5096
5116
|
* The address associated with the account.
|
@@ -5248,16 +5268,17 @@ var Account = class extends AbstractAccount {
|
|
5248
5268
|
* Adds resources to the transaction enough to fund it.
|
5249
5269
|
*
|
5250
5270
|
* @param request - The transaction request.
|
5251
|
-
* @param
|
5271
|
+
* @param requiredQuantities - The coin quantities required to execute the transaction.
|
5252
5272
|
* @param fee - The estimated transaction fee.
|
5253
5273
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5254
5274
|
*/
|
5255
5275
|
async fund(request, params) {
|
5256
5276
|
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5257
5277
|
const baseAssetId = this.provider.getBaseAssetId();
|
5278
|
+
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn19(0);
|
5258
5279
|
const txRequest = request;
|
5259
5280
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5260
|
-
amount:
|
5281
|
+
amount: bn19(fee),
|
5261
5282
|
assetId: baseAssetId,
|
5262
5283
|
coinQuantities: requiredQuantities
|
5263
5284
|
});
|
@@ -5265,21 +5286,17 @@ var Account = class extends AbstractAccount {
|
|
5265
5286
|
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
5266
5287
|
quantitiesDict[assetId] = {
|
5267
5288
|
required: amount,
|
5268
|
-
owned:
|
5289
|
+
owned: bn19(0)
|
5269
5290
|
};
|
5270
5291
|
});
|
5271
|
-
|
5272
|
-
const
|
5273
|
-
if (!isResource) {
|
5274
|
-
return;
|
5275
|
-
}
|
5276
|
-
const isCoin2 = "owner" in input;
|
5292
|
+
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
5293
|
+
const isCoin2 = isRequestInputCoin(input);
|
5277
5294
|
const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
|
5278
5295
|
if (quantitiesDict[assetId]) {
|
5279
5296
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
|
5280
5297
|
}
|
5281
5298
|
});
|
5282
|
-
|
5299
|
+
let missingQuantities = [];
|
5283
5300
|
Object.entries(quantitiesDict).forEach(([assetId, { owned, required }]) => {
|
5284
5301
|
if (owned.lt(required)) {
|
5285
5302
|
missingQuantities.push({
|
@@ -5288,11 +5305,42 @@ var Account = class extends AbstractAccount {
|
|
5288
5305
|
});
|
5289
5306
|
}
|
5290
5307
|
});
|
5291
|
-
|
5292
|
-
|
5293
|
-
|
5294
|
-
const resources = await this.getResourcesToSpend(
|
5295
|
-
|
5308
|
+
let needsToBeFunded = missingQuantities.length > 0;
|
5309
|
+
let fundingAttempts = 0;
|
5310
|
+
while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
|
5311
|
+
const resources = await this.getResourcesToSpend(
|
5312
|
+
missingQuantities,
|
5313
|
+
cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
|
5314
|
+
);
|
5315
|
+
request.addResources(resources);
|
5316
|
+
txRequest.shiftPredicateData();
|
5317
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5318
|
+
const requestToReestimate2 = clone4(txRequest);
|
5319
|
+
if (addedSignatures) {
|
5320
|
+
Array.from({ length: addedSignatures }).forEach(
|
5321
|
+
() => requestToReestimate2.addEmptyWitness()
|
5322
|
+
);
|
5323
|
+
}
|
5324
|
+
const { maxFee: newFee } = await this.provider.estimateTxGasAndFee({
|
5325
|
+
transactionRequest: requestToReestimate2
|
5326
|
+
});
|
5327
|
+
const totalBaseAssetOnInputs = getAssetAmountInRequestInputs(
|
5328
|
+
request.inputs,
|
5329
|
+
baseAssetId,
|
5330
|
+
baseAssetId
|
5331
|
+
);
|
5332
|
+
const totalBaseAssetRequiredWithFee = requiredInBaseAsset.add(newFee);
|
5333
|
+
if (totalBaseAssetOnInputs.gt(totalBaseAssetRequiredWithFee)) {
|
5334
|
+
needsToBeFunded = false;
|
5335
|
+
} else {
|
5336
|
+
missingQuantities = [
|
5337
|
+
{
|
5338
|
+
amount: totalBaseAssetRequiredWithFee.sub(totalBaseAssetOnInputs),
|
5339
|
+
assetId: baseAssetId
|
5340
|
+
}
|
5341
|
+
];
|
5342
|
+
}
|
5343
|
+
fundingAttempts += 1;
|
5296
5344
|
}
|
5297
5345
|
txRequest.shiftPredicateData();
|
5298
5346
|
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
@@ -5343,7 +5391,7 @@ var Account = class extends AbstractAccount {
|
|
5343
5391
|
* @returns A promise that resolves to the transaction response.
|
5344
5392
|
*/
|
5345
5393
|
async transfer(destination, amount, assetId, txParams = {}) {
|
5346
|
-
if (
|
5394
|
+
if (bn19(amount).lte(0)) {
|
5347
5395
|
throw new FuelError15(
|
5348
5396
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5349
5397
|
"Transfer amount must be a positive number."
|
@@ -5363,7 +5411,7 @@ var Account = class extends AbstractAccount {
|
|
5363
5411
|
* @returns A promise that resolves to the transaction response.
|
5364
5412
|
*/
|
5365
5413
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5366
|
-
if (
|
5414
|
+
if (bn19(amount).lte(0)) {
|
5367
5415
|
throw new FuelError15(
|
5368
5416
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5369
5417
|
"Transfer amount must be a positive number."
|
@@ -5373,7 +5421,7 @@ var Account = class extends AbstractAccount {
|
|
5373
5421
|
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5374
5422
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5375
5423
|
hexlifiedContractId: contractAddress.toB256(),
|
5376
|
-
amountToTransfer:
|
5424
|
+
amountToTransfer: bn19(amount),
|
5377
5425
|
assetId: assetIdToTransfer
|
5378
5426
|
});
|
5379
5427
|
const request = new ScriptTransactionRequest({
|
@@ -5384,7 +5432,7 @@ var Account = class extends AbstractAccount {
|
|
5384
5432
|
request.addContractInputAndOutput(contractAddress);
|
5385
5433
|
const txCost = await this.provider.getTransactionCost(request, {
|
5386
5434
|
resourcesOwner: this,
|
5387
|
-
quantitiesToContract: [{ amount:
|
5435
|
+
quantitiesToContract: [{ amount: bn19(amount), assetId: String(assetIdToTransfer) }]
|
5388
5436
|
});
|
5389
5437
|
this.validateGasLimitAndMaxFee({
|
5390
5438
|
gasUsed: txCost.gasUsed,
|
@@ -5410,7 +5458,7 @@ var Account = class extends AbstractAccount {
|
|
5410
5458
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5411
5459
|
);
|
5412
5460
|
const amountDataArray = arrayify14(
|
5413
|
-
"0x".concat(
|
5461
|
+
"0x".concat(bn19(amount).toHex().substring(2).padStart(16, "0"))
|
5414
5462
|
);
|
5415
5463
|
const script = new Uint8Array([
|
5416
5464
|
...arrayify14(withdrawScript.bytes),
|
@@ -5420,7 +5468,7 @@ var Account = class extends AbstractAccount {
|
|
5420
5468
|
const params = { script, ...txParams };
|
5421
5469
|
const baseAssetId = this.provider.getBaseAssetId();
|
5422
5470
|
const request = new ScriptTransactionRequest(params);
|
5423
|
-
const quantitiesToContract = [{ amount:
|
5471
|
+
const quantitiesToContract = [{ amount: bn19(amount), assetId: baseAssetId }];
|
5424
5472
|
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5425
5473
|
this.validateGasLimitAndMaxFee({
|
5426
5474
|
gasUsed: txCost.gasUsed,
|
@@ -5492,13 +5540,13 @@ var Account = class extends AbstractAccount {
|
|
5492
5540
|
gasUsed,
|
5493
5541
|
maxFee
|
5494
5542
|
}) {
|
5495
|
-
if (
|
5543
|
+
if (isDefined2(setGasLimit) && gasUsed.gt(setGasLimit)) {
|
5496
5544
|
throw new FuelError15(
|
5497
5545
|
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
5498
5546
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
5499
5547
|
);
|
5500
5548
|
}
|
5501
|
-
if (
|
5549
|
+
if (isDefined2(setMaxFee) && maxFee.gt(setMaxFee)) {
|
5502
5550
|
throw new FuelError15(
|
5503
5551
|
ErrorCode15.MAX_FEE_TOO_LOW,
|
5504
5552
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
@@ -5834,7 +5882,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5834
5882
|
// src/hdwallet/hdwallet.ts
|
5835
5883
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5836
5884
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5837
|
-
import { bn as
|
5885
|
+
import { bn as bn20, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5838
5886
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5839
5887
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5840
5888
|
|
@@ -8306,7 +8354,7 @@ var HDWallet = class {
|
|
8306
8354
|
const IR = bytes.slice(32);
|
8307
8355
|
if (privateKey) {
|
8308
8356
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8309
|
-
const ki =
|
8357
|
+
const ki = bn20(IL).add(privateKey).mod(N).toBytes(32);
|
8310
8358
|
return new HDWallet({
|
8311
8359
|
privateKey: ki,
|
8312
8360
|
chainCode: IR,
|
@@ -9928,8 +9976,8 @@ export {
|
|
9928
9976
|
assets,
|
9929
9977
|
buildBlockExplorerUrl,
|
9930
9978
|
cacheFor,
|
9931
|
-
|
9932
|
-
|
9979
|
+
cacheRequestInputsResources,
|
9980
|
+
cacheRequestInputsResourcesFromOwner,
|
9933
9981
|
calculateGasFee,
|
9934
9982
|
calculateMetadataGasForTxCreate,
|
9935
9983
|
calculateMetadataGasForTxScript,
|
@@ -9942,6 +9990,7 @@ export {
|
|
9942
9990
|
extractMintedAssetsFromReceipts,
|
9943
9991
|
extractTxError,
|
9944
9992
|
gasUsedByInputs,
|
9993
|
+
getAssetAmountInRequestInputs,
|
9945
9994
|
getAssetEth,
|
9946
9995
|
getAssetFuel,
|
9947
9996
|
getAssetNetwork,
|