@fuel-ts/account 0.0.0-rc-1764-20240404125616 → 0.0.0-rc-1832-20240404143349
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/README.md +1 -1
- package/dist/account.d.ts +4 -5
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +558 -772
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +511 -764
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +392 -644
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -10
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +305 -824
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +0 -3
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +24 -44
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +25 -8
- 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/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils.global.js +551 -729
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +490 -705
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +379 -594
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/index.js
CHANGED
@@ -95,7 +95,7 @@ __export(src_exports, {
|
|
95
95
|
WalletLocked: () => WalletLocked,
|
96
96
|
WalletManager: () => WalletManager,
|
97
97
|
WalletUnlocked: () => WalletUnlocked,
|
98
|
-
|
98
|
+
addAmountToAsset: () => addAmountToAsset,
|
99
99
|
addOperation: () => addOperation,
|
100
100
|
assemblePanicError: () => assemblePanicError,
|
101
101
|
assembleReceiptByType: () => assembleReceiptByType,
|
@@ -104,10 +104,9 @@ __export(src_exports, {
|
|
104
104
|
assets: () => assets,
|
105
105
|
buildBlockExplorerUrl: () => buildBlockExplorerUrl,
|
106
106
|
cacheFor: () => cacheFor,
|
107
|
-
cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
|
108
|
-
calculateGasFee: () => calculateGasFee,
|
109
107
|
calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
|
110
108
|
calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
|
109
|
+
calculatePriceWithFactor: () => calculatePriceWithFactor,
|
111
110
|
calculateTransactionFee: () => calculateTransactionFee,
|
112
111
|
coinQuantityfy: () => coinQuantityfy,
|
113
112
|
deferPromise: () => deferPromise,
|
@@ -188,9 +187,8 @@ var import_address4 = require("@fuel-ts/address");
|
|
188
187
|
var import_configs12 = require("@fuel-ts/address/configs");
|
189
188
|
var import_errors16 = require("@fuel-ts/errors");
|
190
189
|
var import_interfaces = require("@fuel-ts/interfaces");
|
191
|
-
var
|
192
|
-
var
|
193
|
-
var import_ramda4 = require("ramda");
|
190
|
+
var import_math18 = require("@fuel-ts/math");
|
191
|
+
var import_utils28 = require("@fuel-ts/utils");
|
194
192
|
|
195
193
|
// src/providers/coin-quantity.ts
|
196
194
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -199,24 +197,24 @@ var import_utils = require("@fuel-ts/utils");
|
|
199
197
|
var coinQuantityfy = (coinQuantityLike) => {
|
200
198
|
let assetId;
|
201
199
|
let amount;
|
202
|
-
let
|
200
|
+
let max2;
|
203
201
|
if (Array.isArray(coinQuantityLike)) {
|
204
202
|
amount = coinQuantityLike[0];
|
205
203
|
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
206
|
-
|
204
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
207
205
|
} else {
|
208
206
|
amount = coinQuantityLike.amount;
|
209
207
|
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
210
|
-
|
208
|
+
max2 = coinQuantityLike.max ?? void 0;
|
211
209
|
}
|
212
210
|
const bnAmount = (0, import_math.bn)(amount);
|
213
211
|
return {
|
214
212
|
assetId: (0, import_utils.hexlify)(assetId),
|
215
213
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
216
|
-
max:
|
214
|
+
max: max2 ? (0, import_math.bn)(max2) : void 0
|
217
215
|
};
|
218
216
|
};
|
219
|
-
var
|
217
|
+
var addAmountToAsset = (params) => {
|
220
218
|
const { amount, assetId } = params;
|
221
219
|
const coinQuantities = [...params.coinQuantities];
|
222
220
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -231,12 +229,12 @@ var addAmountToCoinQuantities = (params) => {
|
|
231
229
|
// src/providers/provider.ts
|
232
230
|
var import_address3 = require("@fuel-ts/address");
|
233
231
|
var import_errors14 = require("@fuel-ts/errors");
|
234
|
-
var
|
235
|
-
var
|
236
|
-
var
|
232
|
+
var import_math15 = require("@fuel-ts/math");
|
233
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
234
|
+
var import_utils23 = require("@fuel-ts/utils");
|
237
235
|
var import_versions = require("@fuel-ts/versions");
|
238
|
-
var
|
239
|
-
var
|
236
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
237
|
+
var import_ethers = require("ethers");
|
240
238
|
var import_graphql_request = require("graphql-request");
|
241
239
|
var import_ramda3 = require("ramda");
|
242
240
|
|
@@ -244,10 +242,14 @@ var import_ramda3 = require("ramda");
|
|
244
242
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
245
243
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
246
244
|
fragment receiptFragment on Receipt {
|
247
|
-
|
245
|
+
contract {
|
246
|
+
id
|
247
|
+
}
|
248
248
|
pc
|
249
249
|
is
|
250
|
-
to
|
250
|
+
to {
|
251
|
+
id
|
252
|
+
}
|
251
253
|
toAddress
|
252
254
|
amount
|
253
255
|
assetId
|
@@ -285,16 +287,10 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
285
287
|
id
|
286
288
|
}
|
287
289
|
time
|
288
|
-
receipts {
|
289
|
-
...receiptFragment
|
290
|
-
}
|
291
290
|
programState {
|
292
291
|
returnType
|
293
292
|
data
|
294
293
|
}
|
295
|
-
receipts {
|
296
|
-
...receiptFragment
|
297
|
-
}
|
298
294
|
}
|
299
295
|
... on FailureStatus {
|
300
296
|
block {
|
@@ -302,24 +298,26 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
302
298
|
}
|
303
299
|
time
|
304
300
|
reason
|
305
|
-
receipts {
|
306
|
-
...receiptFragment
|
307
|
-
}
|
308
301
|
}
|
309
302
|
... on SqueezedOutStatus {
|
310
303
|
reason
|
311
304
|
}
|
312
305
|
}
|
313
|
-
|
306
|
+
`;
|
314
307
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
315
308
|
fragment transactionFragment on Transaction {
|
316
309
|
id
|
317
310
|
rawPayload
|
311
|
+
gasPrice
|
312
|
+
receipts {
|
313
|
+
...receiptFragment
|
314
|
+
}
|
318
315
|
status {
|
319
316
|
...transactionStatusFragment
|
320
317
|
}
|
321
318
|
}
|
322
|
-
${
|
319
|
+
${ReceiptFragmentFragmentDoc}
|
320
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
323
321
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
324
322
|
fragment inputEstimatePredicatesFragment on Input {
|
325
323
|
... on InputCoin {
|
@@ -337,46 +335,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
337
335
|
}
|
338
336
|
}
|
339
337
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
340
|
-
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
341
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
342
|
-
reason
|
343
|
-
programState {
|
344
|
-
returnType
|
345
|
-
data
|
346
|
-
}
|
347
|
-
}
|
348
|
-
`;
|
349
|
-
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
350
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
351
|
-
programState {
|
352
|
-
returnType
|
353
|
-
data
|
354
|
-
}
|
355
|
-
}
|
356
|
-
`;
|
357
|
-
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
358
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
359
|
-
... on DryRunFailureStatus {
|
360
|
-
...dryRunFailureStatusFragment
|
361
|
-
}
|
362
|
-
... on DryRunSuccessStatus {
|
363
|
-
...dryRunSuccessStatusFragment
|
364
|
-
}
|
365
|
-
}
|
366
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
367
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
368
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
369
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
370
|
-
id
|
371
|
-
status {
|
372
|
-
...dryRunTransactionStatusFragment
|
373
|
-
}
|
374
|
-
receipts {
|
375
|
-
...receiptFragment
|
376
|
-
}
|
377
|
-
}
|
378
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
379
|
-
${ReceiptFragmentFragmentDoc}`;
|
380
338
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
381
339
|
fragment coinFragment on Coin {
|
382
340
|
__typename
|
@@ -384,6 +342,7 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
384
342
|
owner
|
385
343
|
amount
|
386
344
|
assetId
|
345
|
+
maturity
|
387
346
|
blockCreated
|
388
347
|
txCreatedIdx
|
389
348
|
}
|
@@ -460,8 +419,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
460
419
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
461
420
|
fragment blockFragment on Block {
|
462
421
|
id
|
463
|
-
height
|
464
422
|
header {
|
423
|
+
height
|
465
424
|
time
|
466
425
|
}
|
467
426
|
transactions {
|
@@ -531,6 +490,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
531
490
|
cb
|
532
491
|
cfei
|
533
492
|
cfsi
|
493
|
+
croo
|
534
494
|
div
|
535
495
|
divi
|
536
496
|
ecr1
|
@@ -613,9 +573,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
613
573
|
ccp {
|
614
574
|
...DependentCostFragment
|
615
575
|
}
|
616
|
-
croo {
|
617
|
-
...DependentCostFragment
|
618
|
-
}
|
619
576
|
csiz {
|
620
577
|
...DependentCostFragment
|
621
578
|
}
|
@@ -738,6 +695,14 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
738
695
|
maxTx
|
739
696
|
maxDepth
|
740
697
|
nodeVersion
|
698
|
+
peers {
|
699
|
+
id
|
700
|
+
addresses
|
701
|
+
clientVersion
|
702
|
+
blockHeight
|
703
|
+
lastHeartbeatMs
|
704
|
+
appScore
|
705
|
+
}
|
741
706
|
}
|
742
707
|
`;
|
743
708
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -772,9 +737,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
772
737
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
773
738
|
transaction(id: $transactionId) {
|
774
739
|
...transactionFragment
|
740
|
+
receipts {
|
741
|
+
...receiptFragment
|
742
|
+
}
|
775
743
|
}
|
776
744
|
}
|
777
|
-
${TransactionFragmentFragmentDoc}
|
745
|
+
${TransactionFragmentFragmentDoc}
|
746
|
+
${ReceiptFragmentFragmentDoc}`;
|
778
747
|
var GetTransactionsDocument = import_graphql_tag.default`
|
779
748
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
780
749
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -902,20 +871,6 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
902
871
|
}
|
903
872
|
}
|
904
873
|
${BalanceFragmentFragmentDoc}`;
|
905
|
-
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
906
|
-
query getLatestGasPrice {
|
907
|
-
latestGasPrice {
|
908
|
-
gasPrice
|
909
|
-
}
|
910
|
-
}
|
911
|
-
`;
|
912
|
-
var EstimateGasPriceDocument = import_graphql_tag.default`
|
913
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
914
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
915
|
-
gasPrice
|
916
|
-
}
|
917
|
-
}
|
918
|
-
`;
|
919
874
|
var GetBalancesDocument = import_graphql_tag.default`
|
920
875
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
921
876
|
balances(
|
@@ -970,12 +925,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
970
925
|
}
|
971
926
|
`;
|
972
927
|
var DryRunDocument = import_graphql_tag.default`
|
973
|
-
mutation dryRun($
|
974
|
-
dryRun(
|
975
|
-
...
|
928
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
929
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
930
|
+
...receiptFragment
|
976
931
|
}
|
977
932
|
}
|
978
|
-
${
|
933
|
+
${ReceiptFragmentFragmentDoc}`;
|
979
934
|
var SubmitDocument = import_graphql_tag.default`
|
980
935
|
mutation submit($encodedTransaction: HexString!) {
|
981
936
|
submit(tx: $encodedTransaction) {
|
@@ -1058,12 +1013,6 @@ function getSdk(requester) {
|
|
1058
1013
|
getBalance(variables, options) {
|
1059
1014
|
return requester(GetBalanceDocument, variables, options);
|
1060
1015
|
},
|
1061
|
-
getLatestGasPrice(variables, options) {
|
1062
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
1063
|
-
},
|
1064
|
-
estimateGasPrice(variables, options) {
|
1065
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
1066
|
-
},
|
1067
1016
|
getBalances(variables, options) {
|
1068
1017
|
return requester(GetBalancesDocument, variables, options);
|
1069
1018
|
},
|
@@ -1247,6 +1196,7 @@ var inputify = (value) => {
|
|
1247
1196
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1248
1197
|
},
|
1249
1198
|
witnessIndex: value.witnessIndex,
|
1199
|
+
maturity: value.maturity ?? 0,
|
1250
1200
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1251
1201
|
predicateLength: predicate.length,
|
1252
1202
|
predicateDataLength: predicateData.length,
|
@@ -1360,7 +1310,6 @@ var import_configs7 = require("@fuel-ts/address/configs");
|
|
1360
1310
|
var import_math7 = require("@fuel-ts/math");
|
1361
1311
|
var import_transactions6 = require("@fuel-ts/transactions");
|
1362
1312
|
var import_utils9 = require("@fuel-ts/utils");
|
1363
|
-
var import_ethers = require("ethers");
|
1364
1313
|
|
1365
1314
|
// src/providers/resource.ts
|
1366
1315
|
var isRawCoin = (resource) => "utxoId" in resource;
|
@@ -1399,8 +1348,8 @@ function assembleReceiptByType(receipt) {
|
|
1399
1348
|
case "CALL" /* Call */: {
|
1400
1349
|
const callReceipt = {
|
1401
1350
|
type: import_transactions3.ReceiptType.Call,
|
1402
|
-
from: hexOrZero(receipt.id
|
1403
|
-
to: hexOrZero(receipt?.to),
|
1351
|
+
from: hexOrZero(receipt.contract?.id),
|
1352
|
+
to: hexOrZero(receipt?.to?.id),
|
1404
1353
|
amount: (0, import_math4.bn)(receipt.amount),
|
1405
1354
|
assetId: hexOrZero(receipt.assetId),
|
1406
1355
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1414,7 +1363,7 @@ function assembleReceiptByType(receipt) {
|
|
1414
1363
|
case "RETURN" /* Return */: {
|
1415
1364
|
const returnReceipt = {
|
1416
1365
|
type: import_transactions3.ReceiptType.Return,
|
1417
|
-
id: hexOrZero(receipt.id
|
1366
|
+
id: hexOrZero(receipt.contract?.id),
|
1418
1367
|
val: (0, import_math4.bn)(receipt.val),
|
1419
1368
|
pc: (0, import_math4.bn)(receipt.pc),
|
1420
1369
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1424,7 +1373,7 @@ function assembleReceiptByType(receipt) {
|
|
1424
1373
|
case "RETURN_DATA" /* ReturnData */: {
|
1425
1374
|
const returnDataReceipt = {
|
1426
1375
|
type: import_transactions3.ReceiptType.ReturnData,
|
1427
|
-
id: hexOrZero(receipt.id
|
1376
|
+
id: hexOrZero(receipt.contract?.id),
|
1428
1377
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1429
1378
|
len: (0, import_math4.bn)(receipt.len),
|
1430
1379
|
digest: hexOrZero(receipt.digest),
|
@@ -1436,7 +1385,7 @@ function assembleReceiptByType(receipt) {
|
|
1436
1385
|
case "PANIC" /* Panic */: {
|
1437
1386
|
const panicReceipt = {
|
1438
1387
|
type: import_transactions3.ReceiptType.Panic,
|
1439
|
-
id: hexOrZero(receipt.id),
|
1388
|
+
id: hexOrZero(receipt.contract?.id),
|
1440
1389
|
reason: (0, import_math4.bn)(receipt.reason),
|
1441
1390
|
pc: (0, import_math4.bn)(receipt.pc),
|
1442
1391
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1447,7 +1396,7 @@ function assembleReceiptByType(receipt) {
|
|
1447
1396
|
case "REVERT" /* Revert */: {
|
1448
1397
|
const revertReceipt = {
|
1449
1398
|
type: import_transactions3.ReceiptType.Revert,
|
1450
|
-
id: hexOrZero(receipt.id
|
1399
|
+
id: hexOrZero(receipt.contract?.id),
|
1451
1400
|
val: (0, import_math4.bn)(receipt.ra),
|
1452
1401
|
pc: (0, import_math4.bn)(receipt.pc),
|
1453
1402
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1457,7 +1406,7 @@ function assembleReceiptByType(receipt) {
|
|
1457
1406
|
case "LOG" /* Log */: {
|
1458
1407
|
const logReceipt = {
|
1459
1408
|
type: import_transactions3.ReceiptType.Log,
|
1460
|
-
id: hexOrZero(receipt.id
|
1409
|
+
id: hexOrZero(receipt.contract?.id),
|
1461
1410
|
val0: (0, import_math4.bn)(receipt.ra),
|
1462
1411
|
val1: (0, import_math4.bn)(receipt.rb),
|
1463
1412
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1470,7 +1419,7 @@ function assembleReceiptByType(receipt) {
|
|
1470
1419
|
case "LOG_DATA" /* LogData */: {
|
1471
1420
|
const logDataReceipt = {
|
1472
1421
|
type: import_transactions3.ReceiptType.LogData,
|
1473
|
-
id: hexOrZero(receipt.id
|
1422
|
+
id: hexOrZero(receipt.contract?.id),
|
1474
1423
|
val0: (0, import_math4.bn)(receipt.ra),
|
1475
1424
|
val1: (0, import_math4.bn)(receipt.rb),
|
1476
1425
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1484,8 +1433,8 @@ function assembleReceiptByType(receipt) {
|
|
1484
1433
|
case "TRANSFER" /* Transfer */: {
|
1485
1434
|
const transferReceipt = {
|
1486
1435
|
type: import_transactions3.ReceiptType.Transfer,
|
1487
|
-
from: hexOrZero(receipt.id
|
1488
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1436
|
+
from: hexOrZero(receipt.contract?.id),
|
1437
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1489
1438
|
amount: (0, import_math4.bn)(receipt.amount),
|
1490
1439
|
assetId: hexOrZero(receipt.assetId),
|
1491
1440
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1496,8 +1445,8 @@ function assembleReceiptByType(receipt) {
|
|
1496
1445
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1497
1446
|
const transferOutReceipt = {
|
1498
1447
|
type: import_transactions3.ReceiptType.TransferOut,
|
1499
|
-
from: hexOrZero(receipt.id
|
1500
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1448
|
+
from: hexOrZero(receipt.contract?.id),
|
1449
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1501
1450
|
amount: (0, import_math4.bn)(receipt.amount),
|
1502
1451
|
assetId: hexOrZero(receipt.assetId),
|
1503
1452
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1540,7 +1489,7 @@ function assembleReceiptByType(receipt) {
|
|
1540
1489
|
return receiptMessageOut;
|
1541
1490
|
}
|
1542
1491
|
case "MINT" /* Mint */: {
|
1543
|
-
const contractId = hexOrZero(receipt.id
|
1492
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1544
1493
|
const subId = hexOrZero(receipt.subId);
|
1545
1494
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1546
1495
|
const mintReceipt = {
|
@@ -1555,7 +1504,7 @@ function assembleReceiptByType(receipt) {
|
|
1555
1504
|
return mintReceipt;
|
1556
1505
|
}
|
1557
1506
|
case "BURN" /* Burn */: {
|
1558
|
-
const contractId = hexOrZero(receipt.id
|
1507
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1559
1508
|
const subId = hexOrZero(receipt.subId);
|
1560
1509
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1561
1510
|
const burnReceipt = {
|
@@ -1640,6 +1589,7 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1640
1589
|
var import_math5 = require("@fuel-ts/math");
|
1641
1590
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1642
1591
|
var import_utils6 = require("@fuel-ts/utils");
|
1592
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1643
1593
|
var getGasUsedFromReceipts = (receipts) => {
|
1644
1594
|
const scriptResult = receipts.filter(
|
1645
1595
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1660,28 +1610,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1660
1610
|
}
|
1661
1611
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1662
1612
|
const witnessCache = [];
|
1663
|
-
const
|
1664
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1665
|
-
if (isCoinOrMessage) {
|
1666
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1667
|
-
return true;
|
1668
|
-
}
|
1669
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1670
|
-
witnessCache.push(input.witnessIndex);
|
1671
|
-
return true;
|
1672
|
-
}
|
1673
|
-
}
|
1674
|
-
return false;
|
1675
|
-
});
|
1676
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1677
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1613
|
+
const totalGas = inputs.reduce((total, input) => {
|
1678
1614
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1679
1615
|
return total.add(
|
1680
|
-
|
1616
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1681
1617
|
);
|
1682
1618
|
}
|
1683
|
-
|
1684
|
-
|
1619
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1620
|
+
witnessCache.push(input.witnessIndex);
|
1621
|
+
return total.add(gasCosts.ecr1);
|
1622
|
+
}
|
1623
|
+
return total;
|
1624
|
+
}, (0, import_math5.bn)());
|
1685
1625
|
return totalGas;
|
1686
1626
|
}
|
1687
1627
|
function getMinGas(params) {
|
@@ -1693,20 +1633,12 @@ function getMinGas(params) {
|
|
1693
1633
|
return minGas;
|
1694
1634
|
}
|
1695
1635
|
function getMaxGas(params) {
|
1696
|
-
const {
|
1697
|
-
gasPerByte,
|
1698
|
-
witnessesLength,
|
1699
|
-
witnessLimit,
|
1700
|
-
minGas,
|
1701
|
-
gasLimit = (0, import_math5.bn)(0),
|
1702
|
-
maxGasPerTx
|
1703
|
-
} = params;
|
1636
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
|
1704
1637
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1705
1638
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1706
1639
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1707
1640
|
}
|
1708
|
-
|
1709
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1641
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1710
1642
|
}
|
1711
1643
|
function calculateMetadataGasForTxCreate({
|
1712
1644
|
gasCosts,
|
@@ -1728,10 +1660,6 @@ function calculateMetadataGasForTxScript({
|
|
1728
1660
|
}) {
|
1729
1661
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1730
1662
|
}
|
1731
|
-
var calculateGasFee = (params) => {
|
1732
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1733
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1734
|
-
};
|
1735
1663
|
|
1736
1664
|
// src/providers/utils/json.ts
|
1737
1665
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1880,7 +1808,7 @@ var witnessify = (value) => {
|
|
1880
1808
|
// src/providers/transaction-request/transaction-request.ts
|
1881
1809
|
var BaseTransactionRequest = class {
|
1882
1810
|
/** Gas price for transaction */
|
1883
|
-
|
1811
|
+
gasPrice;
|
1884
1812
|
/** Block until which tx cannot be included */
|
1885
1813
|
maturity;
|
1886
1814
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1899,7 +1827,7 @@ var BaseTransactionRequest = class {
|
|
1899
1827
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1900
1828
|
*/
|
1901
1829
|
constructor({
|
1902
|
-
|
1830
|
+
gasPrice,
|
1903
1831
|
maturity,
|
1904
1832
|
maxFee,
|
1905
1833
|
witnessLimit,
|
@@ -1907,7 +1835,7 @@ var BaseTransactionRequest = class {
|
|
1907
1835
|
outputs,
|
1908
1836
|
witnesses
|
1909
1837
|
} = {}) {
|
1910
|
-
this.
|
1838
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1911
1839
|
this.maturity = maturity ?? 0;
|
1912
1840
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1913
1841
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1918,9 +1846,9 @@ var BaseTransactionRequest = class {
|
|
1918
1846
|
static getPolicyMeta(req) {
|
1919
1847
|
let policyTypes = 0;
|
1920
1848
|
const policies = [];
|
1921
|
-
if (req.
|
1922
|
-
policyTypes += import_transactions6.PolicyType.
|
1923
|
-
policies.push({ data: req.
|
1849
|
+
if (req.gasPrice) {
|
1850
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1851
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1924
1852
|
}
|
1925
1853
|
if (req.witnessLimit) {
|
1926
1854
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -2107,10 +2035,10 @@ var BaseTransactionRequest = class {
|
|
2107
2035
|
* @param predicate - Predicate bytes.
|
2108
2036
|
* @param predicateData - Predicate data bytes.
|
2109
2037
|
*/
|
2110
|
-
addCoinInput(coin) {
|
2038
|
+
addCoinInput(coin, predicate) {
|
2111
2039
|
const { assetId, owner, amount } = coin;
|
2112
2040
|
let witnessIndex;
|
2113
|
-
if (
|
2041
|
+
if (predicate) {
|
2114
2042
|
witnessIndex = 0;
|
2115
2043
|
} else {
|
2116
2044
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2125,7 +2053,9 @@ var BaseTransactionRequest = class {
|
|
2125
2053
|
amount,
|
2126
2054
|
assetId,
|
2127
2055
|
txPointer: "0x00000000000000000000000000000000",
|
2128
|
-
witnessIndex
|
2056
|
+
witnessIndex,
|
2057
|
+
predicate: predicate?.bytes,
|
2058
|
+
predicateData: predicate?.predicateDataBytes
|
2129
2059
|
};
|
2130
2060
|
this.pushInput(input);
|
2131
2061
|
this.addChangeOutput(owner, assetId);
|
@@ -2138,11 +2068,11 @@ var BaseTransactionRequest = class {
|
|
2138
2068
|
* @param predicate - Predicate bytes.
|
2139
2069
|
* @param predicateData - Predicate data bytes.
|
2140
2070
|
*/
|
2141
|
-
addMessageInput(message) {
|
2071
|
+
addMessageInput(message, predicate) {
|
2142
2072
|
const { recipient, sender, amount } = message;
|
2143
2073
|
const assetId = import_configs7.BaseAssetId;
|
2144
2074
|
let witnessIndex;
|
2145
|
-
if (
|
2075
|
+
if (predicate) {
|
2146
2076
|
witnessIndex = 0;
|
2147
2077
|
} else {
|
2148
2078
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2156,7 +2086,9 @@ var BaseTransactionRequest = class {
|
|
2156
2086
|
sender: sender.toB256(),
|
2157
2087
|
recipient: recipient.toB256(),
|
2158
2088
|
amount,
|
2159
|
-
witnessIndex
|
2089
|
+
witnessIndex,
|
2090
|
+
predicate: predicate?.bytes,
|
2091
|
+
predicateData: predicate?.predicateDataBytes
|
2160
2092
|
};
|
2161
2093
|
this.pushInput(input);
|
2162
2094
|
this.addChangeOutput(recipient, assetId);
|
@@ -2187,6 +2119,32 @@ var BaseTransactionRequest = class {
|
|
2187
2119
|
resources.forEach((resource) => this.addResource(resource));
|
2188
2120
|
return this;
|
2189
2121
|
}
|
2122
|
+
/**
|
2123
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
2124
|
+
* outputs from the related assetIds.
|
2125
|
+
*
|
2126
|
+
* @param resources - The resources to add.
|
2127
|
+
* @returns This transaction.
|
2128
|
+
*/
|
2129
|
+
addPredicateResource(resource, predicate) {
|
2130
|
+
if (isCoin(resource)) {
|
2131
|
+
this.addCoinInput(resource, predicate);
|
2132
|
+
} else {
|
2133
|
+
this.addMessageInput(resource, predicate);
|
2134
|
+
}
|
2135
|
+
return this;
|
2136
|
+
}
|
2137
|
+
/**
|
2138
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2139
|
+
* from the related assetIds.
|
2140
|
+
*
|
2141
|
+
* @param resources - The resources to add.
|
2142
|
+
* @returns This transaction.
|
2143
|
+
*/
|
2144
|
+
addPredicateResources(resources, predicate) {
|
2145
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2146
|
+
return this;
|
2147
|
+
}
|
2190
2148
|
/**
|
2191
2149
|
* Adds a coin output to the transaction.
|
2192
2150
|
*
|
@@ -2266,7 +2224,7 @@ var BaseTransactionRequest = class {
|
|
2266
2224
|
}
|
2267
2225
|
calculateMaxGas(chainInfo, minGas) {
|
2268
2226
|
const { consensusParameters } = chainInfo;
|
2269
|
-
const { gasPerByte
|
2227
|
+
const { gasPerByte } = consensusParameters;
|
2270
2228
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2271
2229
|
(acc, wit) => acc + wit.dataLength,
|
2272
2230
|
0
|
@@ -2275,8 +2233,7 @@ var BaseTransactionRequest = class {
|
|
2275
2233
|
gasPerByte,
|
2276
2234
|
minGas,
|
2277
2235
|
witnessesLength,
|
2278
|
-
witnessLimit: this.witnessLimit
|
2279
|
-
maxGasPerTx
|
2236
|
+
witnessLimit: this.witnessLimit
|
2280
2237
|
});
|
2281
2238
|
}
|
2282
2239
|
/**
|
@@ -2286,6 +2243,12 @@ var BaseTransactionRequest = class {
|
|
2286
2243
|
* @param quantities - CoinQuantity Array.
|
2287
2244
|
*/
|
2288
2245
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2246
|
+
let idCounter = 0;
|
2247
|
+
const generateId = () => {
|
2248
|
+
const counterString = String(idCounter++);
|
2249
|
+
const id = import_configs7.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2250
|
+
return id;
|
2251
|
+
};
|
2289
2252
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2290
2253
|
if ("assetId" in input) {
|
2291
2254
|
return input.assetId === assetId;
|
@@ -2294,20 +2257,17 @@ var BaseTransactionRequest = class {
|
|
2294
2257
|
});
|
2295
2258
|
const updateAssetInput = (assetId, quantity) => {
|
2296
2259
|
const assetInput = findAssetInput(assetId);
|
2297
|
-
let usedQuantity = quantity;
|
2298
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2299
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2300
|
-
}
|
2301
2260
|
if (assetInput && "assetId" in assetInput) {
|
2302
|
-
assetInput.id = (
|
2303
|
-
assetInput.amount =
|
2261
|
+
assetInput.id = generateId();
|
2262
|
+
assetInput.amount = quantity;
|
2304
2263
|
} else {
|
2305
2264
|
this.addResources([
|
2306
2265
|
{
|
2307
|
-
id: (
|
2308
|
-
amount:
|
2266
|
+
id: generateId(),
|
2267
|
+
amount: quantity,
|
2309
2268
|
assetId,
|
2310
2269
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2270
|
+
maturity: 0,
|
2311
2271
|
blockCreated: (0, import_math7.bn)(1),
|
2312
2272
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2313
2273
|
}
|
@@ -2339,7 +2299,7 @@ var BaseTransactionRequest = class {
|
|
2339
2299
|
toJSON() {
|
2340
2300
|
return normalizeJSON(this);
|
2341
2301
|
}
|
2342
|
-
|
2302
|
+
updatePredicateInputs(inputs) {
|
2343
2303
|
this.inputs.forEach((i) => {
|
2344
2304
|
let correspondingInput;
|
2345
2305
|
switch (i.type) {
|
@@ -2361,15 +2321,6 @@ var BaseTransactionRequest = class {
|
|
2361
2321
|
}
|
2362
2322
|
});
|
2363
2323
|
}
|
2364
|
-
shiftPredicateData() {
|
2365
|
-
this.inputs.forEach((input) => {
|
2366
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2367
|
-
input.predicateData = input.paddPredicateData(
|
2368
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2369
|
-
);
|
2370
|
-
}
|
2371
|
-
});
|
2372
|
-
}
|
2373
2324
|
};
|
2374
2325
|
|
2375
2326
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2706,7 +2657,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2706
2657
|
}
|
2707
2658
|
calculateMaxGas(chainInfo, minGas) {
|
2708
2659
|
const { consensusParameters } = chainInfo;
|
2709
|
-
const { gasPerByte
|
2660
|
+
const { gasPerByte } = consensusParameters;
|
2710
2661
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2711
2662
|
(acc, wit) => acc + wit.dataLength,
|
2712
2663
|
0
|
@@ -2716,8 +2667,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2716
2667
|
minGas,
|
2717
2668
|
witnessesLength,
|
2718
2669
|
witnessLimit: this.witnessLimit,
|
2719
|
-
gasLimit: this.gasLimit
|
2720
|
-
maxGasPerTx
|
2670
|
+
gasLimit: this.gasLimit
|
2721
2671
|
});
|
2722
2672
|
}
|
2723
2673
|
/**
|
@@ -2792,32 +2742,15 @@ var transactionRequestify = (obj) => {
|
|
2792
2742
|
}
|
2793
2743
|
}
|
2794
2744
|
};
|
2795
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2796
|
-
(acc, input) => {
|
2797
|
-
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2798
|
-
acc.utxos.push(input.id);
|
2799
|
-
}
|
2800
|
-
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2801
|
-
acc.messages.push(input.nonce);
|
2802
|
-
}
|
2803
|
-
return acc;
|
2804
|
-
},
|
2805
|
-
{
|
2806
|
-
utxos: [],
|
2807
|
-
messages: []
|
2808
|
-
}
|
2809
|
-
);
|
2810
2745
|
|
2811
2746
|
// src/providers/transaction-response/transaction-response.ts
|
2812
2747
|
var import_errors13 = require("@fuel-ts/errors");
|
2813
|
-
var
|
2814
|
-
var
|
2815
|
-
var
|
2748
|
+
var import_math14 = require("@fuel-ts/math");
|
2749
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2750
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2816
2751
|
|
2817
2752
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2818
|
-
var
|
2819
|
-
var import_transactions16 = require("@fuel-ts/transactions");
|
2820
|
-
var import_utils18 = require("@fuel-ts/utils");
|
2753
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2821
2754
|
|
2822
2755
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2823
2756
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2825,10 +2758,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2825
2758
|
var import_utils16 = require("@fuel-ts/utils");
|
2826
2759
|
var calculateTransactionFee = (params) => {
|
2827
2760
|
const {
|
2828
|
-
|
2761
|
+
gasUsed,
|
2829
2762
|
rawPayload,
|
2830
|
-
|
2831
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2763
|
+
consensusParameters: { gasCosts, feeParams }
|
2832
2764
|
} = params;
|
2833
2765
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2834
2766
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2838,7 +2770,8 @@ var calculateTransactionFee = (params) => {
|
|
2838
2770
|
return {
|
2839
2771
|
fee: (0, import_math11.bn)(0),
|
2840
2772
|
minFee: (0, import_math11.bn)(0),
|
2841
|
-
maxFee: (0, import_math11.bn)(0)
|
2773
|
+
maxFee: (0, import_math11.bn)(0),
|
2774
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2842
2775
|
};
|
2843
2776
|
}
|
2844
2777
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2870,6 +2803,7 @@ var calculateTransactionFee = (params) => {
|
|
2870
2803
|
metadataGas,
|
2871
2804
|
txBytesSize: transactionBytes.length
|
2872
2805
|
});
|
2806
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2873
2807
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2874
2808
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2875
2809
|
const maxGas = getMaxGas({
|
@@ -2877,25 +2811,17 @@ var calculateTransactionFee = (params) => {
|
|
2877
2811
|
minGas,
|
2878
2812
|
witnessesLength,
|
2879
2813
|
gasLimit,
|
2880
|
-
witnessLimit
|
2881
|
-
maxGasPerTx
|
2882
|
-
});
|
2883
|
-
const minFee = calculateGasFee({
|
2884
|
-
gasPrice,
|
2885
|
-
gas: minGas,
|
2886
|
-
priceFactor: gasPriceFactor,
|
2887
|
-
tip
|
2888
|
-
});
|
2889
|
-
const maxFee = calculateGasFee({
|
2890
|
-
gasPrice,
|
2891
|
-
gas: maxGas,
|
2892
|
-
priceFactor: gasPriceFactor,
|
2893
|
-
tip
|
2814
|
+
witnessLimit
|
2894
2815
|
});
|
2816
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2817
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2818
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2819
|
+
const fee = minFee.add(feeFromGasUsed);
|
2895
2820
|
return {
|
2821
|
+
fee,
|
2896
2822
|
minFee,
|
2897
2823
|
maxFee,
|
2898
|
-
|
2824
|
+
feeFromGasUsed
|
2899
2825
|
};
|
2900
2826
|
};
|
2901
2827
|
|
@@ -3509,12 +3435,10 @@ function assembleTransactionSummary(params) {
|
|
3509
3435
|
gqlTransactionStatus,
|
3510
3436
|
abiMap = {},
|
3511
3437
|
maxInputs,
|
3512
|
-
gasCosts
|
3513
|
-
maxGasPerTx,
|
3514
|
-
gasPrice
|
3438
|
+
gasCosts
|
3515
3439
|
} = params;
|
3516
3440
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3517
|
-
const rawPayload = (0,
|
3441
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3518
3442
|
const operations = getOperations({
|
3519
3443
|
transactionType: transaction.type,
|
3520
3444
|
inputs: transaction.inputs || [],
|
@@ -3525,14 +3449,11 @@ function assembleTransactionSummary(params) {
|
|
3525
3449
|
maxInputs
|
3526
3450
|
});
|
3527
3451
|
const typeName = getTransactionTypeName(transaction.type);
|
3528
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3529
3452
|
const { fee } = calculateTransactionFee({
|
3530
|
-
|
3453
|
+
gasUsed,
|
3531
3454
|
rawPayload,
|
3532
|
-
tip,
|
3533
3455
|
consensusParameters: {
|
3534
3456
|
gasCosts,
|
3535
|
-
maxGasPerTx,
|
3536
3457
|
feeParams: {
|
3537
3458
|
gasPerByte,
|
3538
3459
|
gasPriceFactor
|
@@ -3544,7 +3465,7 @@ function assembleTransactionSummary(params) {
|
|
3544
3465
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3545
3466
|
let date;
|
3546
3467
|
if (time) {
|
3547
|
-
date =
|
3468
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3548
3469
|
}
|
3549
3470
|
const transactionSummary = {
|
3550
3471
|
id,
|
@@ -3572,12 +3493,12 @@ function assembleTransactionSummary(params) {
|
|
3572
3493
|
|
3573
3494
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3574
3495
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3575
|
-
var
|
3496
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3576
3497
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3577
3498
|
return receipts.reduce((logs, receipt) => {
|
3578
|
-
if (receipt.type ===
|
3499
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3579
3500
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3580
|
-
const data = receipt.type ===
|
3501
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3581
3502
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3582
3503
|
logs.push(decodedLog);
|
3583
3504
|
}
|
@@ -3592,7 +3513,7 @@ var TransactionResponse = class {
|
|
3592
3513
|
/** Current provider */
|
3593
3514
|
provider;
|
3594
3515
|
/** Gas used on the transaction */
|
3595
|
-
gasUsed = (0,
|
3516
|
+
gasUsed = (0, import_math14.bn)(0);
|
3596
3517
|
/** The graphql Transaction with receipts object. */
|
3597
3518
|
gqlTransaction;
|
3598
3519
|
abis;
|
@@ -3650,8 +3571,8 @@ var TransactionResponse = class {
|
|
3650
3571
|
* @returns The decoded transaction.
|
3651
3572
|
*/
|
3652
3573
|
decodeTransaction(transactionWithReceipts) {
|
3653
|
-
return new
|
3654
|
-
(0,
|
3574
|
+
return new import_transactions17.TransactionCoder().decode(
|
3575
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3655
3576
|
0
|
3656
3577
|
)?.[0];
|
3657
3578
|
}
|
@@ -3670,27 +3591,20 @@ var TransactionResponse = class {
|
|
3670
3591
|
const decodedTransaction = this.decodeTransaction(
|
3671
3592
|
transaction
|
3672
3593
|
);
|
3673
|
-
|
3674
|
-
|
3675
|
-
txReceipts = transaction.status.receipts;
|
3676
|
-
}
|
3677
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3678
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3679
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3594
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3595
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3680
3596
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3681
3597
|
const transactionSummary = assembleTransactionSummary({
|
3682
3598
|
id: this.id,
|
3683
3599
|
receipts,
|
3684
3600
|
transaction: decodedTransaction,
|
3685
|
-
transactionBytes: (0,
|
3601
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3686
3602
|
gqlTransactionStatus: transaction.status,
|
3687
3603
|
gasPerByte,
|
3688
3604
|
gasPriceFactor,
|
3689
3605
|
abiMap: contractsAbiMap,
|
3690
3606
|
maxInputs,
|
3691
|
-
gasCosts
|
3692
|
-
maxGasPerTx,
|
3693
|
-
gasPrice
|
3607
|
+
gasCosts
|
3694
3608
|
});
|
3695
3609
|
return transactionSummary;
|
3696
3610
|
}
|
@@ -3817,29 +3731,29 @@ var processGqlChain = (chain) => {
|
|
3817
3731
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3818
3732
|
return {
|
3819
3733
|
name,
|
3820
|
-
baseChainHeight: (0,
|
3734
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3821
3735
|
consensusParameters: {
|
3822
|
-
contractMaxSize: (0,
|
3823
|
-
maxInputs: (0,
|
3824
|
-
maxOutputs: (0,
|
3825
|
-
maxWitnesses: (0,
|
3826
|
-
maxGasPerTx: (0,
|
3827
|
-
maxScriptLength: (0,
|
3828
|
-
maxScriptDataLength: (0,
|
3829
|
-
maxStorageSlots: (0,
|
3830
|
-
maxPredicateLength: (0,
|
3831
|
-
maxPredicateDataLength: (0,
|
3832
|
-
maxGasPerPredicate: (0,
|
3833
|
-
gasPriceFactor: (0,
|
3834
|
-
gasPerByte: (0,
|
3835
|
-
maxMessageDataLength: (0,
|
3836
|
-
chainId: (0,
|
3736
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3737
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3738
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3739
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3740
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3741
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3742
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3743
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3744
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3745
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3746
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3747
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3748
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3749
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3750
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3837
3751
|
gasCosts
|
3838
3752
|
},
|
3839
3753
|
gasCosts,
|
3840
3754
|
latestBlock: {
|
3841
3755
|
id: latestBlock.id,
|
3842
|
-
height: (0,
|
3756
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3843
3757
|
time: latestBlock.header.time,
|
3844
3758
|
transactions: latestBlock.transactions.map((i) => ({
|
3845
3759
|
id: i.id
|
@@ -4024,7 +3938,7 @@ var _Provider = class {
|
|
4024
3938
|
name,
|
4025
3939
|
consensusParameters: { chainId }
|
4026
3940
|
} = await this.getChain();
|
4027
|
-
const network = new
|
3941
|
+
const network = new import_ethers.Network(name, chainId.toNumber());
|
4028
3942
|
return Promise.resolve(network);
|
4029
3943
|
}
|
4030
3944
|
/**
|
@@ -4034,7 +3948,7 @@ var _Provider = class {
|
|
4034
3948
|
*/
|
4035
3949
|
async getBlockNumber() {
|
4036
3950
|
const { chain } = await this.operations.getChain();
|
4037
|
-
return (0,
|
3951
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
4038
3952
|
}
|
4039
3953
|
/**
|
4040
3954
|
* Returns the chain information.
|
@@ -4044,12 +3958,13 @@ var _Provider = class {
|
|
4044
3958
|
async fetchNode() {
|
4045
3959
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
4046
3960
|
const processedNodeInfo = {
|
4047
|
-
maxDepth: (0,
|
4048
|
-
maxTx: (0,
|
4049
|
-
minGasPrice: (0,
|
3961
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3962
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3963
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
4050
3964
|
nodeVersion: nodeInfo.nodeVersion,
|
4051
3965
|
utxoValidation: nodeInfo.utxoValidation,
|
4052
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3966
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3967
|
+
peers: nodeInfo.peers
|
4053
3968
|
};
|
4054
3969
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
4055
3970
|
return processedNodeInfo;
|
@@ -4091,9 +4006,9 @@ var _Provider = class {
|
|
4091
4006
|
if (estimateTxDependencies) {
|
4092
4007
|
await this.estimateTxDependencies(transactionRequest);
|
4093
4008
|
}
|
4094
|
-
const encodedTransaction = (0,
|
4009
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4095
4010
|
let abis;
|
4096
|
-
if (transactionRequest.type ===
|
4011
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4097
4012
|
abis = transactionRequest.abis;
|
4098
4013
|
}
|
4099
4014
|
if (awaitExecution) {
|
@@ -4134,14 +4049,15 @@ var _Provider = class {
|
|
4134
4049
|
if (estimateTxDependencies) {
|
4135
4050
|
return this.estimateTxDependencies(transactionRequest);
|
4136
4051
|
}
|
4137
|
-
const encodedTransaction = (0,
|
4138
|
-
const { dryRun:
|
4139
|
-
|
4052
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4053
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4054
|
+
encodedTransaction,
|
4140
4055
|
utxoValidation: utxoValidation || false
|
4141
4056
|
});
|
4142
|
-
const
|
4143
|
-
|
4144
|
-
|
4057
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4058
|
+
return {
|
4059
|
+
receipts
|
4060
|
+
};
|
4145
4061
|
}
|
4146
4062
|
/**
|
4147
4063
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4152,13 +4068,13 @@ var _Provider = class {
|
|
4152
4068
|
async estimatePredicates(transactionRequest) {
|
4153
4069
|
const shouldEstimatePredicates = Boolean(
|
4154
4070
|
transactionRequest.inputs.find(
|
4155
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4071
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math15.BN(input.predicateGasUsed).isZero()
|
4156
4072
|
)
|
4157
4073
|
);
|
4158
4074
|
if (!shouldEstimatePredicates) {
|
4159
4075
|
return transactionRequest;
|
4160
4076
|
}
|
4161
|
-
const encodedTransaction = (0,
|
4077
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4162
4078
|
const response = await this.operations.estimatePredicates({
|
4163
4079
|
encodedTransaction
|
4164
4080
|
});
|
@@ -4167,7 +4083,7 @@ var _Provider = class {
|
|
4167
4083
|
} = response;
|
4168
4084
|
if (inputs) {
|
4169
4085
|
inputs.forEach((input, index) => {
|
4170
|
-
if ("predicateGasUsed" in input && (0,
|
4086
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
4171
4087
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4172
4088
|
}
|
4173
4089
|
});
|
@@ -4180,31 +4096,31 @@ var _Provider = class {
|
|
4180
4096
|
* If there are missing variable outputs,
|
4181
4097
|
* `addVariableOutputs` is called on the transaction.
|
4182
4098
|
*
|
4099
|
+
* @privateRemarks
|
4100
|
+
* TODO: Investigate support for missing contract IDs
|
4101
|
+
* TODO: Add support for missing output messages
|
4183
4102
|
*
|
4184
4103
|
* @param transactionRequest - The transaction request object.
|
4185
4104
|
* @returns A promise.
|
4186
4105
|
*/
|
4187
4106
|
async estimateTxDependencies(transactionRequest) {
|
4188
|
-
if (transactionRequest.type ===
|
4107
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
4189
4108
|
return {
|
4190
4109
|
receipts: [],
|
4191
4110
|
outputVariables: 0,
|
4192
4111
|
missingContractIds: []
|
4193
4112
|
};
|
4194
4113
|
}
|
4114
|
+
await this.estimatePredicates(transactionRequest);
|
4195
4115
|
let receipts = [];
|
4196
4116
|
const missingContractIds = [];
|
4197
4117
|
let outputVariables = 0;
|
4198
|
-
let dryrunStatus;
|
4199
4118
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4200
|
-
const {
|
4201
|
-
|
4202
|
-
} = await this.operations.dryRun({
|
4203
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4119
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4120
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
4204
4121
|
utxoValidation: false
|
4205
4122
|
});
|
4206
|
-
receipts =
|
4207
|
-
dryrunStatus = status;
|
4123
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
4208
4124
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4209
4125
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4210
4126
|
if (hasMissingOutputs) {
|
@@ -4214,11 +4130,6 @@ var _Provider = class {
|
|
4214
4130
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4215
4131
|
missingContractIds.push(contractId);
|
4216
4132
|
});
|
4217
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4218
|
-
transactionRequest,
|
4219
|
-
optimizeGas: false
|
4220
|
-
});
|
4221
|
-
transactionRequest.maxFee = maxFee;
|
4222
4133
|
} else {
|
4223
4134
|
break;
|
4224
4135
|
}
|
@@ -4226,133 +4137,7 @@ var _Provider = class {
|
|
4226
4137
|
return {
|
4227
4138
|
receipts,
|
4228
4139
|
outputVariables,
|
4229
|
-
missingContractIds
|
4230
|
-
dryrunStatus
|
4231
|
-
};
|
4232
|
-
}
|
4233
|
-
/**
|
4234
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4235
|
-
*
|
4236
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4237
|
-
* further modifications are identified. The method iteratively updates these transactions
|
4238
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4239
|
-
*
|
4240
|
-
* @param transactionRequests - Array of transaction request objects.
|
4241
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4242
|
-
*/
|
4243
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4244
|
-
const results = transactionRequests.map(() => ({
|
4245
|
-
receipts: [],
|
4246
|
-
outputVariables: 0,
|
4247
|
-
missingContractIds: [],
|
4248
|
-
dryrunStatus: void 0
|
4249
|
-
}));
|
4250
|
-
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4251
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4252
|
-
allRequests.forEach((req, index) => {
|
4253
|
-
if (req.type === import_transactions19.TransactionType.Script) {
|
4254
|
-
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4255
|
-
}
|
4256
|
-
});
|
4257
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4258
|
-
let attempt = 0;
|
4259
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4260
|
-
const encodedTransactions = transactionsToProcess.map(
|
4261
|
-
(index) => serializedTransactionsMap.get(index)
|
4262
|
-
);
|
4263
|
-
const dryRunResults = await this.operations.dryRun({
|
4264
|
-
encodedTransactions,
|
4265
|
-
utxoValidation: false
|
4266
|
-
});
|
4267
|
-
const nextRoundTransactions = [];
|
4268
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4269
|
-
const currentResultIndex = transactionsToProcess[i];
|
4270
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4271
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4272
|
-
results[currentResultIndex].dryrunStatus = status;
|
4273
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4274
|
-
results[currentResultIndex].receipts
|
4275
|
-
);
|
4276
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4277
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4278
|
-
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4279
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4280
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4281
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4282
|
-
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4283
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4284
|
-
});
|
4285
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4286
|
-
transactionRequest: requestToProcess,
|
4287
|
-
optimizeGas: false
|
4288
|
-
});
|
4289
|
-
requestToProcess.maxFee = maxFee;
|
4290
|
-
serializedTransactionsMap.set(
|
4291
|
-
currentResultIndex,
|
4292
|
-
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4293
|
-
);
|
4294
|
-
nextRoundTransactions.push(currentResultIndex);
|
4295
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4296
|
-
}
|
4297
|
-
}
|
4298
|
-
transactionsToProcess = nextRoundTransactions;
|
4299
|
-
attempt += 1;
|
4300
|
-
}
|
4301
|
-
return results;
|
4302
|
-
}
|
4303
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4304
|
-
if (estimateTxDependencies) {
|
4305
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4306
|
-
}
|
4307
|
-
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4308
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4309
|
-
encodedTransactions,
|
4310
|
-
utxoValidation: utxoValidation || false
|
4311
|
-
});
|
4312
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4313
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4314
|
-
return { receipts, dryrunStatus: status };
|
4315
|
-
});
|
4316
|
-
return results;
|
4317
|
-
}
|
4318
|
-
async estimateTxGasAndFee(params) {
|
4319
|
-
const { transactionRequest, totalGasUsedByPredicates = (0, import_math16.bn)(0), optimizeGas = true } = params;
|
4320
|
-
let { gasPrice } = params;
|
4321
|
-
const chainInfo = this.getChain();
|
4322
|
-
const { gasPriceFactor } = this.getGasConfig();
|
4323
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4324
|
-
if (!gasPrice) {
|
4325
|
-
gasPrice = await this.estimateGasPrice(10);
|
4326
|
-
}
|
4327
|
-
const shouldSetGaslimit = transactionRequest.type === import_transactions19.TransactionType.Script && !optimizeGas;
|
4328
|
-
const minFee = calculateGasFee({
|
4329
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4330
|
-
gas: minGas,
|
4331
|
-
priceFactor: gasPriceFactor,
|
4332
|
-
tip: transactionRequest.tip
|
4333
|
-
}).add(1);
|
4334
|
-
if (shouldSetGaslimit) {
|
4335
|
-
transactionRequest.gasLimit = chainInfo.consensusParameters.maxGasPerTx.sub(
|
4336
|
-
minGas.add(totalGasUsedByPredicates)
|
4337
|
-
);
|
4338
|
-
}
|
4339
|
-
let maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4340
|
-
const maxFee = calculateGasFee({
|
4341
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4342
|
-
gas: maxGas,
|
4343
|
-
priceFactor: gasPriceFactor,
|
4344
|
-
tip: transactionRequest.tip
|
4345
|
-
}).add(1);
|
4346
|
-
if (shouldSetGaslimit) {
|
4347
|
-
maxGas = chainInfo.consensusParameters.maxGasPerTx.sub(maxFee);
|
4348
|
-
transactionRequest.gasLimit = maxGas;
|
4349
|
-
}
|
4350
|
-
return {
|
4351
|
-
minGas,
|
4352
|
-
minFee,
|
4353
|
-
maxGas,
|
4354
|
-
maxFee,
|
4355
|
-
gasPrice
|
4140
|
+
missingContractIds
|
4356
4141
|
};
|
4357
4142
|
}
|
4358
4143
|
/**
|
@@ -4370,17 +4155,15 @@ var _Provider = class {
|
|
4370
4155
|
if (estimateTxDependencies) {
|
4371
4156
|
return this.estimateTxDependencies(transactionRequest);
|
4372
4157
|
}
|
4373
|
-
const
|
4374
|
-
const { dryRun:
|
4375
|
-
|
4158
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4159
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4160
|
+
encodedTransaction,
|
4376
4161
|
utxoValidation: true
|
4377
4162
|
});
|
4378
|
-
const
|
4379
|
-
|
4380
|
-
|
4381
|
-
|
4382
|
-
});
|
4383
|
-
return { receipts: callResult[0].receipts };
|
4163
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4164
|
+
return {
|
4165
|
+
receipts
|
4166
|
+
};
|
4384
4167
|
}
|
4385
4168
|
/**
|
4386
4169
|
* Returns a transaction cost to enable user
|
@@ -4397,80 +4180,80 @@ var _Provider = class {
|
|
4397
4180
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4398
4181
|
* @returns A promise that resolves to the transaction cost object.
|
4399
4182
|
*/
|
4400
|
-
async getTransactionCost(transactionRequestLike,
|
4183
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
4184
|
+
estimateTxDependencies = true,
|
4185
|
+
estimatePredicates = true,
|
4186
|
+
resourcesOwner,
|
4187
|
+
signatureCallback
|
4188
|
+
} = {}) {
|
4401
4189
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4402
|
-
const
|
4190
|
+
const chainInfo = this.getChain();
|
4191
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4192
|
+
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4193
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4403
4194
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4404
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4195
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4405
4196
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4406
|
-
|
4407
|
-
|
4408
|
-
|
4409
|
-
|
4410
|
-
|
4411
|
-
|
4197
|
+
if (estimatePredicates) {
|
4198
|
+
if (isScriptTransaction) {
|
4199
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4200
|
+
}
|
4201
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4202
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4203
|
+
}
|
4204
|
+
await this.estimatePredicates(txRequestClone);
|
4412
4205
|
}
|
4413
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4414
|
-
let addedSignatures = 0;
|
4415
4206
|
if (signatureCallback && isScriptTransaction) {
|
4416
|
-
|
4417
|
-
|
4418
|
-
|
4419
|
-
|
4420
|
-
await this.estimatePredicates(signedRequest);
|
4421
|
-
let { maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4422
|
-
transactionRequest: signedRequest,
|
4423
|
-
optimizeGas: false
|
4424
|
-
});
|
4425
|
-
txRequestClone.maxFee = maxFee;
|
4207
|
+
await signatureCallback(txRequestClone);
|
4208
|
+
}
|
4209
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
4210
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4426
4211
|
let receipts = [];
|
4427
4212
|
let missingContractIds = [];
|
4428
4213
|
let outputVariables = 0;
|
4429
|
-
|
4430
|
-
|
4431
|
-
|
4432
|
-
if (signatureCallback) {
|
4433
|
-
await signatureCallback(txRequestClone);
|
4434
|
-
}
|
4435
|
-
txRequestClone.gasLimit = maxGas;
|
4214
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4215
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4216
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4436
4217
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4437
4218
|
receipts = result.receipts;
|
4438
4219
|
outputVariables = result.outputVariables;
|
4439
4220
|
missingContractIds = result.missingContractIds;
|
4440
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
4441
|
-
txRequestClone.gasLimit = gasUsed;
|
4442
|
-
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4443
|
-
transactionRequest: txRequestClone,
|
4444
|
-
gasPrice
|
4445
|
-
}));
|
4446
4221
|
}
|
4222
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
4223
|
+
const usedFee = calculatePriceWithFactor(
|
4224
|
+
gasUsed,
|
4225
|
+
gasPrice,
|
4226
|
+
gasPriceFactor
|
4227
|
+
).normalizeZeroToOne();
|
4228
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4229
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4447
4230
|
return {
|
4448
4231
|
requiredQuantities: allQuantities,
|
4449
4232
|
receipts,
|
4450
4233
|
gasUsed,
|
4234
|
+
minGasPrice,
|
4451
4235
|
gasPrice,
|
4452
4236
|
minGas,
|
4453
4237
|
maxGas,
|
4238
|
+
usedFee,
|
4454
4239
|
minFee,
|
4455
4240
|
maxFee,
|
4241
|
+
estimatedInputs: txRequestClone.inputs,
|
4456
4242
|
outputVariables,
|
4457
|
-
missingContractIds
|
4458
|
-
addedSignatures,
|
4459
|
-
estimatedPredicates: txRequestClone.inputs
|
4243
|
+
missingContractIds
|
4460
4244
|
};
|
4461
4245
|
}
|
4462
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4246
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4463
4247
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4464
4248
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4465
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4466
|
-
quantitiesToContract
|
4467
|
-
});
|
4249
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4468
4250
|
transactionRequest.addResources(
|
4469
4251
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4470
4252
|
);
|
4471
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4472
|
-
|
4473
|
-
|
4253
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4254
|
+
transactionRequest,
|
4255
|
+
forwardingQuantities
|
4256
|
+
);
|
4474
4257
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4475
4258
|
return {
|
4476
4259
|
resources,
|
@@ -4486,16 +4269,17 @@ var _Provider = class {
|
|
4486
4269
|
const result = await this.operations.getCoins({
|
4487
4270
|
first: 10,
|
4488
4271
|
...paginationArgs,
|
4489
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4272
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4490
4273
|
});
|
4491
4274
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4492
4275
|
return coins.map((coin) => ({
|
4493
4276
|
id: coin.utxoId,
|
4494
4277
|
assetId: coin.assetId,
|
4495
|
-
amount: (0,
|
4278
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4496
4279
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4497
|
-
|
4498
|
-
|
4280
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4281
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4282
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4499
4283
|
}));
|
4500
4284
|
}
|
4501
4285
|
/**
|
@@ -4509,19 +4293,19 @@ var _Provider = class {
|
|
4509
4293
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4510
4294
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4511
4295
|
const excludeInput = {
|
4512
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4513
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4296
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4297
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4514
4298
|
};
|
4515
4299
|
if (this.cache) {
|
4516
4300
|
const uniqueUtxos = new Set(
|
4517
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4301
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4518
4302
|
);
|
4519
4303
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4520
4304
|
}
|
4521
4305
|
const coinsQuery = {
|
4522
4306
|
owner: ownerAddress.toB256(),
|
4523
4307
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4524
|
-
assetId: (0,
|
4308
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4525
4309
|
amount: amount.toString(10),
|
4526
4310
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4527
4311
|
})),
|
@@ -4532,9 +4316,9 @@ var _Provider = class {
|
|
4532
4316
|
switch (coin.__typename) {
|
4533
4317
|
case "MessageCoin":
|
4534
4318
|
return {
|
4535
|
-
amount: (0,
|
4319
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4536
4320
|
assetId: coin.assetId,
|
4537
|
-
daHeight: (0,
|
4321
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4538
4322
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4539
4323
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4540
4324
|
nonce: coin.nonce
|
@@ -4542,11 +4326,12 @@ var _Provider = class {
|
|
4542
4326
|
case "Coin":
|
4543
4327
|
return {
|
4544
4328
|
id: coin.utxoId,
|
4545
|
-
amount: (0,
|
4329
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4546
4330
|
assetId: coin.assetId,
|
4547
4331
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4548
|
-
|
4549
|
-
|
4332
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4333
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4334
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4550
4335
|
};
|
4551
4336
|
default:
|
4552
4337
|
return null;
|
@@ -4563,13 +4348,13 @@ var _Provider = class {
|
|
4563
4348
|
async getBlock(idOrHeight) {
|
4564
4349
|
let variables;
|
4565
4350
|
if (typeof idOrHeight === "number") {
|
4566
|
-
variables = { height: (0,
|
4351
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4567
4352
|
} else if (idOrHeight === "latest") {
|
4568
4353
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4569
4354
|
} else if (idOrHeight.length === 66) {
|
4570
4355
|
variables = { blockId: idOrHeight };
|
4571
4356
|
} else {
|
4572
|
-
variables = { blockId: (0,
|
4357
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4573
4358
|
}
|
4574
4359
|
const { block } = await this.operations.getBlock(variables);
|
4575
4360
|
if (!block) {
|
@@ -4577,7 +4362,7 @@ var _Provider = class {
|
|
4577
4362
|
}
|
4578
4363
|
return {
|
4579
4364
|
id: block.id,
|
4580
|
-
height: (0,
|
4365
|
+
height: (0, import_math15.bn)(block.header.height),
|
4581
4366
|
time: block.header.time,
|
4582
4367
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4583
4368
|
};
|
@@ -4592,7 +4377,7 @@ var _Provider = class {
|
|
4592
4377
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4593
4378
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4594
4379
|
id: block.id,
|
4595
|
-
height: (0,
|
4380
|
+
height: (0, import_math15.bn)(block.header.height),
|
4596
4381
|
time: block.header.time,
|
4597
4382
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4598
4383
|
}));
|
@@ -4607,7 +4392,7 @@ var _Provider = class {
|
|
4607
4392
|
async getBlockWithTransactions(idOrHeight) {
|
4608
4393
|
let variables;
|
4609
4394
|
if (typeof idOrHeight === "number") {
|
4610
|
-
variables = { blockHeight: (0,
|
4395
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4611
4396
|
} else if (idOrHeight === "latest") {
|
4612
4397
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4613
4398
|
} else {
|
@@ -4619,11 +4404,11 @@ var _Provider = class {
|
|
4619
4404
|
}
|
4620
4405
|
return {
|
4621
4406
|
id: block.id,
|
4622
|
-
height: (0,
|
4407
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4623
4408
|
time: block.header.time,
|
4624
4409
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4625
4410
|
transactions: block.transactions.map(
|
4626
|
-
(tx) => new
|
4411
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4627
4412
|
)
|
4628
4413
|
};
|
4629
4414
|
}
|
@@ -4638,8 +4423,8 @@ var _Provider = class {
|
|
4638
4423
|
if (!transaction) {
|
4639
4424
|
return null;
|
4640
4425
|
}
|
4641
|
-
return new
|
4642
|
-
(0,
|
4426
|
+
return new import_transactions18.TransactionCoder().decode(
|
4427
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4643
4428
|
0
|
4644
4429
|
)?.[0];
|
4645
4430
|
}
|
@@ -4666,9 +4451,9 @@ var _Provider = class {
|
|
4666
4451
|
async getContractBalance(contractId, assetId) {
|
4667
4452
|
const { contractBalance } = await this.operations.getContractBalance({
|
4668
4453
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4669
|
-
asset: (0,
|
4454
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4670
4455
|
});
|
4671
|
-
return (0,
|
4456
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4672
4457
|
}
|
4673
4458
|
/**
|
4674
4459
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4680,9 +4465,9 @@ var _Provider = class {
|
|
4680
4465
|
async getBalance(owner, assetId) {
|
4681
4466
|
const { balance } = await this.operations.getBalance({
|
4682
4467
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4683
|
-
assetId: (0,
|
4468
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4684
4469
|
});
|
4685
|
-
return (0,
|
4470
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4686
4471
|
}
|
4687
4472
|
/**
|
4688
4473
|
* Returns balances for the given owner.
|
@@ -4700,7 +4485,7 @@ var _Provider = class {
|
|
4700
4485
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4701
4486
|
return balances.map((balance) => ({
|
4702
4487
|
assetId: balance.assetId,
|
4703
|
-
amount: (0,
|
4488
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4704
4489
|
}));
|
4705
4490
|
}
|
4706
4491
|
/**
|
@@ -4718,19 +4503,19 @@ var _Provider = class {
|
|
4718
4503
|
});
|
4719
4504
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4720
4505
|
return messages.map((message) => ({
|
4721
|
-
messageId:
|
4506
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4722
4507
|
sender: message.sender,
|
4723
4508
|
recipient: message.recipient,
|
4724
4509
|
nonce: message.nonce,
|
4725
|
-
amount: (0,
|
4510
|
+
amount: (0, import_math15.bn)(message.amount),
|
4726
4511
|
data: message.data
|
4727
4512
|
}),
|
4728
4513
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4729
4514
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4730
4515
|
nonce: message.nonce,
|
4731
|
-
amount: (0,
|
4732
|
-
data:
|
4733
|
-
daHeight: (0,
|
4516
|
+
amount: (0, import_math15.bn)(message.amount),
|
4517
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4518
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4734
4519
|
}));
|
4735
4520
|
}
|
4736
4521
|
/**
|
@@ -4783,54 +4568,44 @@ var _Provider = class {
|
|
4783
4568
|
} = result.messageProof;
|
4784
4569
|
return {
|
4785
4570
|
messageProof: {
|
4786
|
-
proofIndex: (0,
|
4571
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4787
4572
|
proofSet: messageProof.proofSet
|
4788
4573
|
},
|
4789
4574
|
blockProof: {
|
4790
|
-
proofIndex: (0,
|
4575
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4791
4576
|
proofSet: blockProof.proofSet
|
4792
4577
|
},
|
4793
4578
|
messageBlockHeader: {
|
4794
4579
|
id: messageBlockHeader.id,
|
4795
|
-
daHeight: (0,
|
4796
|
-
transactionsCount: (0,
|
4580
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4581
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4797
4582
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4798
|
-
height: (0,
|
4583
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4799
4584
|
prevRoot: messageBlockHeader.prevRoot,
|
4800
4585
|
time: messageBlockHeader.time,
|
4801
4586
|
applicationHash: messageBlockHeader.applicationHash,
|
4802
4587
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4803
|
-
messageReceiptCount: (0,
|
4588
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4804
4589
|
},
|
4805
4590
|
commitBlockHeader: {
|
4806
4591
|
id: commitBlockHeader.id,
|
4807
|
-
daHeight: (0,
|
4808
|
-
transactionsCount: (0,
|
4592
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4593
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4809
4594
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4810
|
-
height: (0,
|
4595
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4811
4596
|
prevRoot: commitBlockHeader.prevRoot,
|
4812
4597
|
time: commitBlockHeader.time,
|
4813
4598
|
applicationHash: commitBlockHeader.applicationHash,
|
4814
4599
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4815
|
-
messageReceiptCount: (0,
|
4600
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4816
4601
|
},
|
4817
4602
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4818
4603
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4819
4604
|
nonce,
|
4820
|
-
amount: (0,
|
4605
|
+
amount: (0, import_math15.bn)(amount),
|
4821
4606
|
data
|
4822
4607
|
};
|
4823
4608
|
}
|
4824
|
-
async getLatestGasPrice() {
|
4825
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4826
|
-
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4827
|
-
}
|
4828
|
-
async estimateGasPrice(blockHorizon) {
|
4829
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4830
|
-
blockHorizon: String(blockHorizon)
|
4831
|
-
});
|
4832
|
-
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4833
|
-
}
|
4834
4609
|
/**
|
4835
4610
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4836
4611
|
*
|
@@ -4850,10 +4625,10 @@ var _Provider = class {
|
|
4850
4625
|
*/
|
4851
4626
|
async produceBlocks(amount, startTime) {
|
4852
4627
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4853
|
-
blocksToProduce: (0,
|
4854
|
-
startTimestamp: startTime ?
|
4628
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4629
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4855
4630
|
});
|
4856
|
-
return (0,
|
4631
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4857
4632
|
}
|
4858
4633
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4859
4634
|
async getTransactionResponse(transactionId) {
|
@@ -4867,7 +4642,7 @@ cacheInputs_fn = function(inputs) {
|
|
4867
4642
|
return;
|
4868
4643
|
}
|
4869
4644
|
inputs.forEach((input) => {
|
4870
|
-
if (input.type ===
|
4645
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4871
4646
|
this.cache?.set(input.id);
|
4872
4647
|
}
|
4873
4648
|
});
|
@@ -4877,9 +4652,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4877
4652
|
|
4878
4653
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4879
4654
|
var import_errors15 = require("@fuel-ts/errors");
|
4880
|
-
var
|
4881
|
-
var
|
4882
|
-
var
|
4655
|
+
var import_math16 = require("@fuel-ts/math");
|
4656
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4657
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4883
4658
|
async function getTransactionSummary(params) {
|
4884
4659
|
const { id, provider, abiMap } = params;
|
4885
4660
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -4891,32 +4666,25 @@ async function getTransactionSummary(params) {
|
|
4891
4666
|
`Transaction not found for given id: ${id}.`
|
4892
4667
|
);
|
4893
4668
|
}
|
4894
|
-
const [decodedTransaction] = new
|
4895
|
-
(0,
|
4669
|
+
const [decodedTransaction] = new import_transactions19.TransactionCoder().decode(
|
4670
|
+
(0, import_utils26.arrayify)(gqlTransaction.rawPayload),
|
4896
4671
|
0
|
4897
4672
|
);
|
4898
|
-
|
4899
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4900
|
-
txReceipts = gqlTransaction.status.receipts;
|
4901
|
-
}
|
4902
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4673
|
+
const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
|
4903
4674
|
const {
|
4904
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4675
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4905
4676
|
} = provider.getChain();
|
4906
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4907
4677
|
const transactionInfo = assembleTransactionSummary({
|
4908
4678
|
id: gqlTransaction.id,
|
4909
4679
|
receipts,
|
4910
4680
|
transaction: decodedTransaction,
|
4911
|
-
transactionBytes: (0,
|
4681
|
+
transactionBytes: (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
|
4912
4682
|
gqlTransactionStatus: gqlTransaction.status,
|
4913
|
-
gasPerByte: (0,
|
4914
|
-
gasPriceFactor: (0,
|
4683
|
+
gasPerByte: (0, import_math16.bn)(gasPerByte),
|
4684
|
+
gasPriceFactor: (0, import_math16.bn)(gasPriceFactor),
|
4915
4685
|
abiMap,
|
4916
4686
|
maxInputs,
|
4917
|
-
gasCosts
|
4918
|
-
maxGasPerTx,
|
4919
|
-
gasPrice
|
4687
|
+
gasCosts
|
4920
4688
|
});
|
4921
4689
|
return {
|
4922
4690
|
gqlTransaction,
|
@@ -4926,11 +4694,10 @@ async function getTransactionSummary(params) {
|
|
4926
4694
|
async function getTransactionSummaryFromRequest(params) {
|
4927
4695
|
const { provider, transactionRequest, abiMap } = params;
|
4928
4696
|
const { receipts } = await provider.call(transactionRequest);
|
4929
|
-
const { gasPerByte, gasPriceFactor, gasCosts
|
4697
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4930
4698
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4931
4699
|
const transaction = transactionRequest.toTransaction();
|
4932
4700
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4933
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4934
4701
|
const transactionSummary = assembleTransactionSummary({
|
4935
4702
|
receipts,
|
4936
4703
|
transaction,
|
@@ -4939,9 +4706,7 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4939
4706
|
gasPerByte,
|
4940
4707
|
gasPriceFactor,
|
4941
4708
|
maxInputs,
|
4942
|
-
gasCosts
|
4943
|
-
maxGasPerTx,
|
4944
|
-
gasPrice
|
4709
|
+
gasCosts
|
4945
4710
|
});
|
4946
4711
|
return transactionSummary;
|
4947
4712
|
}
|
@@ -4950,31 +4715,24 @@ async function getTransactionsSummaries(params) {
|
|
4950
4715
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4951
4716
|
const { edges, pageInfo } = transactionsByOwner;
|
4952
4717
|
const {
|
4953
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4718
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4954
4719
|
} = provider.getChain();
|
4955
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4956
4720
|
const transactions = edges.map((edge) => {
|
4957
4721
|
const { node: gqlTransaction } = edge;
|
4958
|
-
const { id, rawPayload, status } = gqlTransaction;
|
4959
|
-
const [decodedTransaction] = new
|
4960
|
-
|
4961
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4962
|
-
txReceipts = gqlTransaction.status.receipts;
|
4963
|
-
}
|
4964
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4722
|
+
const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
|
4723
|
+
const [decodedTransaction] = new import_transactions19.TransactionCoder().decode((0, import_utils26.arrayify)(rawPayload), 0);
|
4724
|
+
const receipts = gqlReceipts?.map(processGqlReceipt) || [];
|
4965
4725
|
const transactionSummary = assembleTransactionSummary({
|
4966
4726
|
id,
|
4967
4727
|
receipts,
|
4968
4728
|
transaction: decodedTransaction,
|
4969
|
-
transactionBytes: (0,
|
4729
|
+
transactionBytes: (0, import_utils26.arrayify)(rawPayload),
|
4970
4730
|
gqlTransactionStatus: status,
|
4971
4731
|
abiMap,
|
4972
4732
|
gasPerByte,
|
4973
4733
|
gasPriceFactor,
|
4974
4734
|
maxInputs,
|
4975
|
-
gasCosts
|
4976
|
-
maxGasPerTx,
|
4977
|
-
gasPrice
|
4735
|
+
gasCosts
|
4978
4736
|
});
|
4979
4737
|
const output = {
|
4980
4738
|
gqlTransaction,
|
@@ -5111,17 +4869,17 @@ var assets = [
|
|
5111
4869
|
|
5112
4870
|
// src/utils/formatTransferToContractScriptData.ts
|
5113
4871
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
5114
|
-
var
|
5115
|
-
var
|
4872
|
+
var import_math17 = require("@fuel-ts/math");
|
4873
|
+
var import_utils27 = require("@fuel-ts/utils");
|
5116
4874
|
var asm = __toESM(require("@fuels/vm-asm"));
|
5117
4875
|
var formatTransferToContractScriptData = (params) => {
|
5118
4876
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
5119
4877
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
5120
|
-
const encoded = numberCoder.encode(new
|
4878
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
5121
4879
|
const scriptData = Uint8Array.from([
|
5122
|
-
...(0,
|
4880
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
5123
4881
|
...encoded,
|
5124
|
-
...(0,
|
4882
|
+
...(0, import_utils27.arrayify)(assetId)
|
5125
4883
|
]);
|
5126
4884
|
return scriptData;
|
5127
4885
|
};
|
@@ -5306,33 +5064,36 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5306
5064
|
* @param fee - The estimated transaction fee.
|
5307
5065
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5308
5066
|
*/
|
5309
|
-
async fund(request,
|
5310
|
-
const
|
5311
|
-
|
5312
|
-
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5313
|
-
amount: (0, import_math19.bn)(fee),
|
5067
|
+
async fund(request, coinQuantities, fee) {
|
5068
|
+
const updatedQuantities = addAmountToAsset({
|
5069
|
+
amount: (0, import_math18.bn)(fee),
|
5314
5070
|
assetId: import_configs12.BaseAssetId,
|
5315
|
-
coinQuantities
|
5071
|
+
coinQuantities
|
5316
5072
|
});
|
5317
5073
|
const quantitiesDict = {};
|
5318
|
-
|
5074
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
5319
5075
|
quantitiesDict[assetId] = {
|
5320
5076
|
required: amount,
|
5321
|
-
owned: (0,
|
5077
|
+
owned: (0, import_math18.bn)(0)
|
5322
5078
|
};
|
5323
5079
|
});
|
5324
|
-
|
5080
|
+
const cachedUtxos = [];
|
5081
|
+
const cachedMessages = [];
|
5082
|
+
const owner = this.address.toB256();
|
5083
|
+
request.inputs.forEach((input) => {
|
5325
5084
|
const isResource = "amount" in input;
|
5326
5085
|
if (isResource) {
|
5327
5086
|
const isCoin2 = "owner" in input;
|
5328
5087
|
if (isCoin2) {
|
5329
5088
|
const assetId = String(input.assetId);
|
5330
|
-
if (quantitiesDict[assetId]) {
|
5331
|
-
const amount = (0,
|
5089
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
5090
|
+
const amount = (0, import_math18.bn)(input.amount);
|
5332
5091
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5092
|
+
cachedUtxos.push(input.id);
|
5333
5093
|
}
|
5334
|
-
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5094
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5335
5095
|
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
5096
|
+
cachedMessages.push(input.nonce);
|
5336
5097
|
}
|
5337
5098
|
}
|
5338
5099
|
});
|
@@ -5347,23 +5108,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5347
5108
|
});
|
5348
5109
|
const needsToBeFunded = missingQuantities.length;
|
5349
5110
|
if (needsToBeFunded) {
|
5350
|
-
const
|
5351
|
-
|
5352
|
-
|
5353
|
-
|
5354
|
-
|
5355
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5356
|
-
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
5357
|
-
if (addedSignatures) {
|
5358
|
-
Array.from({ length: addedSignatures }).forEach(
|
5359
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
5360
|
-
);
|
5111
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
5112
|
+
messages: cachedMessages,
|
5113
|
+
utxos: cachedUtxos
|
5114
|
+
});
|
5115
|
+
request.addResources(resources);
|
5361
5116
|
}
|
5362
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5363
|
-
transactionRequest: requestToBeReEstimate
|
5364
|
-
});
|
5365
|
-
txRequest.maxFee = maxFee;
|
5366
|
-
return txRequest;
|
5367
5117
|
}
|
5368
5118
|
/**
|
5369
5119
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5371,25 +5121,28 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5371
5121
|
* @param destination - The address of the destination.
|
5372
5122
|
* @param amount - The amount of coins to transfer.
|
5373
5123
|
* @param assetId - The asset ID of the coins to transfer.
|
5374
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5124
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5375
5125
|
* @returns A promise that resolves to the prepared transaction request.
|
5376
5126
|
*/
|
5377
5127
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5378
|
-
const
|
5128
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5129
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5130
|
+
const request = new ScriptTransactionRequest(params);
|
5379
5131
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
5380
|
-
const
|
5132
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5381
5133
|
estimateTxDependencies: true,
|
5382
5134
|
resourcesOwner: this
|
5383
5135
|
});
|
5384
|
-
|
5385
|
-
|
5386
|
-
|
5387
|
-
|
5388
|
-
|
5389
|
-
|
5390
|
-
|
5391
|
-
|
5392
|
-
await this.fund(request,
|
5136
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
5137
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
5138
|
+
this.validateGas({
|
5139
|
+
gasUsed,
|
5140
|
+
gasPrice: request.gasPrice,
|
5141
|
+
gasLimit: request.gasLimit,
|
5142
|
+
minGasPrice
|
5143
|
+
});
|
5144
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5145
|
+
request.updatePredicateInputs(estimatedInputs);
|
5393
5146
|
return request;
|
5394
5147
|
}
|
5395
5148
|
/**
|
@@ -5402,7 +5155,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5402
5155
|
* @returns A promise that resolves to the transaction response.
|
5403
5156
|
*/
|
5404
5157
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5405
|
-
if ((0,
|
5158
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5406
5159
|
throw new import_errors16.FuelError(
|
5407
5160
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5408
5161
|
"Transfer amount must be a positive number."
|
@@ -5421,37 +5174,38 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5421
5174
|
* @returns A promise that resolves to the transaction response.
|
5422
5175
|
*/
|
5423
5176
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5424
|
-
if ((0,
|
5177
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5425
5178
|
throw new import_errors16.FuelError(
|
5426
5179
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5427
5180
|
"Transfer amount must be a positive number."
|
5428
5181
|
);
|
5429
5182
|
}
|
5430
5183
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5184
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5185
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5431
5186
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5432
5187
|
hexlifiedContractId: contractAddress.toB256(),
|
5433
|
-
amountToTransfer: (0,
|
5188
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
5434
5189
|
assetId
|
5435
5190
|
});
|
5436
5191
|
const request = new ScriptTransactionRequest({
|
5437
|
-
...
|
5192
|
+
...params,
|
5438
5193
|
script,
|
5439
5194
|
scriptData
|
5440
5195
|
});
|
5441
5196
|
request.addContractInputAndOutput(contractAddress);
|
5442
|
-
const
|
5443
|
-
|
5444
|
-
|
5197
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5198
|
+
request,
|
5199
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
5200
|
+
);
|
5201
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5202
|
+
this.validateGas({
|
5203
|
+
gasUsed,
|
5204
|
+
gasPrice: request.gasPrice,
|
5205
|
+
gasLimit: request.gasLimit,
|
5206
|
+
minGasPrice
|
5445
5207
|
});
|
5446
|
-
|
5447
|
-
this.validateGas({
|
5448
|
-
gasUsed: txCost.gasUsed,
|
5449
|
-
gasLimit: request.gasLimit
|
5450
|
-
});
|
5451
|
-
}
|
5452
|
-
request.gasLimit = txCost.gasUsed;
|
5453
|
-
request.maxFee = txCost.maxFee;
|
5454
|
-
await this.fund(request, txCost);
|
5208
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5455
5209
|
return this.sendTransaction(request);
|
5456
5210
|
}
|
5457
5211
|
/**
|
@@ -5463,31 +5217,34 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5463
5217
|
* @returns A promise that resolves to the transaction response.
|
5464
5218
|
*/
|
5465
5219
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5220
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5466
5221
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5467
|
-
const recipientDataArray = (0,
|
5222
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5468
5223
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5469
5224
|
);
|
5470
|
-
const amountDataArray = (0,
|
5471
|
-
"0x".concat((0,
|
5225
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
5226
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5472
5227
|
);
|
5473
5228
|
const script = new Uint8Array([
|
5474
|
-
...(0,
|
5229
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5475
5230
|
...recipientDataArray,
|
5476
5231
|
...amountDataArray
|
5477
5232
|
]);
|
5478
|
-
const params = { script, ...txParams };
|
5233
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5479
5234
|
const request = new ScriptTransactionRequest(params);
|
5480
|
-
const
|
5481
|
-
const
|
5482
|
-
|
5483
|
-
|
5484
|
-
|
5485
|
-
|
5486
|
-
|
5487
|
-
|
5488
|
-
|
5489
|
-
|
5490
|
-
|
5235
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5236
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5237
|
+
request,
|
5238
|
+
forwardingQuantities
|
5239
|
+
);
|
5240
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5241
|
+
this.validateGas({
|
5242
|
+
gasUsed,
|
5243
|
+
gasPrice: request.gasPrice,
|
5244
|
+
gasLimit: request.gasLimit,
|
5245
|
+
minGasPrice
|
5246
|
+
});
|
5247
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5491
5248
|
return this.sendTransaction(request);
|
5492
5249
|
}
|
5493
5250
|
async signMessage(message) {
|
@@ -5545,7 +5302,18 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5545
5302
|
}
|
5546
5303
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5547
5304
|
}
|
5548
|
-
validateGas({
|
5305
|
+
validateGas({
|
5306
|
+
gasUsed,
|
5307
|
+
gasPrice,
|
5308
|
+
gasLimit,
|
5309
|
+
minGasPrice
|
5310
|
+
}) {
|
5311
|
+
if (minGasPrice.gt(gasPrice)) {
|
5312
|
+
throw new import_errors16.FuelError(
|
5313
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
5314
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5315
|
+
);
|
5316
|
+
}
|
5549
5317
|
if (gasUsed.gt(gasLimit)) {
|
5550
5318
|
throw new import_errors16.FuelError(
|
5551
5319
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5557,14 +5325,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5557
5325
|
|
5558
5326
|
// src/wallet/base-wallet-unlocked.ts
|
5559
5327
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5560
|
-
var
|
5328
|
+
var import_utils31 = require("@fuel-ts/utils");
|
5561
5329
|
|
5562
5330
|
// src/signer/signer.ts
|
5563
5331
|
var import_address5 = require("@fuel-ts/address");
|
5564
5332
|
var import_crypto = require("@fuel-ts/crypto");
|
5565
5333
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5566
|
-
var
|
5567
|
-
var
|
5334
|
+
var import_math19 = require("@fuel-ts/math");
|
5335
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5568
5336
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5569
5337
|
var Signer = class {
|
5570
5338
|
address;
|
@@ -5583,10 +5351,10 @@ var Signer = class {
|
|
5583
5351
|
privateKey = `0x${privateKey}`;
|
5584
5352
|
}
|
5585
5353
|
}
|
5586
|
-
const privateKeyBytes = (0,
|
5587
|
-
this.privateKey = (0,
|
5588
|
-
this.publicKey = (0,
|
5589
|
-
this.compressedPublicKey = (0,
|
5354
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
5355
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
5356
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5357
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5590
5358
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5591
5359
|
}
|
5592
5360
|
/**
|
@@ -5600,11 +5368,11 @@ var Signer = class {
|
|
5600
5368
|
* @returns hashed signature
|
5601
5369
|
*/
|
5602
5370
|
sign(data) {
|
5603
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5604
|
-
const r = (0,
|
5605
|
-
const s = (0,
|
5371
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
5372
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5373
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5606
5374
|
s[0] |= (signature.recovery || 0) << 7;
|
5607
|
-
return (0,
|
5375
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5608
5376
|
}
|
5609
5377
|
/**
|
5610
5378
|
* Add point on the current elliptic curve
|
@@ -5613,8 +5381,8 @@ var Signer = class {
|
|
5613
5381
|
* @returns compressed point on the curve
|
5614
5382
|
*/
|
5615
5383
|
addPoint(point) {
|
5616
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5617
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5384
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
5385
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5618
5386
|
const result = p0.add(p1);
|
5619
5387
|
return `0x${result.toHex(true)}`;
|
5620
5388
|
}
|
@@ -5626,16 +5394,16 @@ var Signer = class {
|
|
5626
5394
|
* @returns public key from signature from the
|
5627
5395
|
*/
|
5628
5396
|
static recoverPublicKey(data, signature) {
|
5629
|
-
const signedMessageBytes = (0,
|
5397
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5630
5398
|
const r = signedMessageBytes.slice(0, 32);
|
5631
5399
|
const s = signedMessageBytes.slice(32, 64);
|
5632
5400
|
const recoveryParam = (s[0] & 128) >> 7;
|
5633
5401
|
s[0] &= 127;
|
5634
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5402
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5635
5403
|
recoveryParam
|
5636
5404
|
);
|
5637
|
-
const publicKey = sig.recoverPublicKey((0,
|
5638
|
-
return (0,
|
5405
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5406
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5639
5407
|
}
|
5640
5408
|
/**
|
5641
5409
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5654,7 +5422,7 @@ var Signer = class {
|
|
5654
5422
|
* @returns random 32-byte hashed
|
5655
5423
|
*/
|
5656
5424
|
static generatePrivateKey(entropy) {
|
5657
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5425
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
5658
5426
|
}
|
5659
5427
|
/**
|
5660
5428
|
* Extended publicKey from a compact publicKey
|
@@ -5663,8 +5431,8 @@ var Signer = class {
|
|
5663
5431
|
* @returns extended publicKey
|
5664
5432
|
*/
|
5665
5433
|
static extendPublicKey(publicKey) {
|
5666
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5667
|
-
return (0,
|
5434
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5435
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5668
5436
|
}
|
5669
5437
|
};
|
5670
5438
|
|
@@ -5672,7 +5440,7 @@ var Signer = class {
|
|
5672
5440
|
var import_address6 = require("@fuel-ts/address");
|
5673
5441
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5674
5442
|
var import_errors17 = require("@fuel-ts/errors");
|
5675
|
-
var
|
5443
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5676
5444
|
var import_uuid = require("uuid");
|
5677
5445
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5678
5446
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5755,7 +5523,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5755
5523
|
);
|
5756
5524
|
}
|
5757
5525
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5758
|
-
const privateKey = (0,
|
5526
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5759
5527
|
return privateKey;
|
5760
5528
|
}
|
5761
5529
|
|
@@ -5800,7 +5568,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5800
5568
|
*/
|
5801
5569
|
async signMessage(message) {
|
5802
5570
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5803
|
-
return (0,
|
5571
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5804
5572
|
}
|
5805
5573
|
/**
|
5806
5574
|
* Signs a transaction with the wallet's private key.
|
@@ -5813,7 +5581,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5813
5581
|
const chainId = this.provider.getChainId();
|
5814
5582
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5815
5583
|
const signature = await this.signer().sign(hashedTransaction);
|
5816
|
-
return (0,
|
5584
|
+
return (0, import_utils31.hexlify)(signature);
|
5817
5585
|
}
|
5818
5586
|
/**
|
5819
5587
|
* Populates a transaction with the witnesses signature.
|
@@ -5833,7 +5601,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5833
5601
|
* @param transactionRequestLike - The transaction request to send.
|
5834
5602
|
* @returns A promise that resolves to the TransactionResponse object.
|
5835
5603
|
*/
|
5836
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5604
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5837
5605
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5838
5606
|
if (estimateTxDependencies) {
|
5839
5607
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5874,16 +5642,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5874
5642
|
// src/hdwallet/hdwallet.ts
|
5875
5643
|
var import_errors20 = require("@fuel-ts/errors");
|
5876
5644
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5877
|
-
var
|
5878
|
-
var
|
5879
|
-
var
|
5645
|
+
var import_math20 = require("@fuel-ts/math");
|
5646
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5647
|
+
var import_ethers3 = require("ethers");
|
5880
5648
|
|
5881
5649
|
// src/mnemonic/mnemonic.ts
|
5882
5650
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5883
5651
|
var import_errors19 = require("@fuel-ts/errors");
|
5884
5652
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5885
|
-
var
|
5886
|
-
var
|
5653
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5654
|
+
var import_ethers2 = require("ethers");
|
5887
5655
|
|
5888
5656
|
// src/wordlists/words/english.ts
|
5889
5657
|
var english = [
|
@@ -7946,7 +7714,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7946
7714
|
// src/mnemonic/utils.ts
|
7947
7715
|
var import_errors18 = require("@fuel-ts/errors");
|
7948
7716
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7949
|
-
var
|
7717
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7950
7718
|
function toUtf8Bytes(stri) {
|
7951
7719
|
const str = stri.normalize("NFKD");
|
7952
7720
|
const result = [];
|
@@ -8013,14 +7781,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
8013
7781
|
}
|
8014
7782
|
}
|
8015
7783
|
const checksumBits = entropy.length / 4;
|
8016
|
-
const checksum = (0,
|
7784
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
8017
7785
|
indices[indices.length - 1] <<= checksumBits;
|
8018
7786
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
8019
7787
|
return indices;
|
8020
7788
|
}
|
8021
7789
|
function mnemonicWordsToEntropy(words, wordlist) {
|
8022
7790
|
const size = Math.ceil(11 * words.length / 8);
|
8023
|
-
const entropy = (0,
|
7791
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
8024
7792
|
let offset = 0;
|
8025
7793
|
for (let i = 0; i < words.length; i += 1) {
|
8026
7794
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -8040,7 +7808,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8040
7808
|
const entropyBits = 32 * words.length / 3;
|
8041
7809
|
const checksumBits = words.length / 3;
|
8042
7810
|
const checksumMask = getUpperMask(checksumBits);
|
8043
|
-
const checksum = (0,
|
7811
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
8044
7812
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
8045
7813
|
throw new import_errors18.FuelError(
|
8046
7814
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -8115,7 +7883,7 @@ var Mnemonic = class {
|
|
8115
7883
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
8116
7884
|
const words = getWords(phrase);
|
8117
7885
|
assertMnemonic(words);
|
8118
|
-
return (0,
|
7886
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
8119
7887
|
}
|
8120
7888
|
/**
|
8121
7889
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -8123,7 +7891,7 @@ var Mnemonic = class {
|
|
8123
7891
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8124
7892
|
*/
|
8125
7893
|
static entropyToMnemonic(entropy, wordlist = english) {
|
8126
|
-
const entropyBytes = (0,
|
7894
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
8127
7895
|
assertWordList(wordlist);
|
8128
7896
|
assertEntropy(entropyBytes);
|
8129
7897
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -8137,7 +7905,7 @@ var Mnemonic = class {
|
|
8137
7905
|
assertMnemonic(getWords(phrase));
|
8138
7906
|
const phraseBytes = toUtf8Bytes(getPhrase(phrase));
|
8139
7907
|
const salt = toUtf8Bytes(`mnemonic${passphrase}`);
|
8140
|
-
return (0,
|
7908
|
+
return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
8141
7909
|
}
|
8142
7910
|
/**
|
8143
7911
|
* @param phrase - Mnemonic phrase composed by words from the provided wordlist
|
@@ -8192,14 +7960,14 @@ var Mnemonic = class {
|
|
8192
7960
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8193
7961
|
*/
|
8194
7962
|
static masterKeysFromSeed(seed) {
|
8195
|
-
const seedArray = (0,
|
7963
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
8196
7964
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8197
7965
|
throw new import_errors19.FuelError(
|
8198
7966
|
import_errors19.ErrorCode.INVALID_SEED,
|
8199
7967
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8200
7968
|
);
|
8201
7969
|
}
|
8202
|
-
return (0,
|
7970
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
8203
7971
|
}
|
8204
7972
|
/**
|
8205
7973
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8210,22 +7978,22 @@ var Mnemonic = class {
|
|
8210
7978
|
*/
|
8211
7979
|
static seedToExtendedKey(seed, testnet = false) {
|
8212
7980
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8213
|
-
const prefix = (0,
|
7981
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8214
7982
|
const depth = "0x00";
|
8215
7983
|
const fingerprint = "0x00000000";
|
8216
7984
|
const index = "0x00000000";
|
8217
7985
|
const chainCode = masterKey.slice(32);
|
8218
7986
|
const privateKey = masterKey.slice(0, 32);
|
8219
|
-
const extendedKey = (0,
|
7987
|
+
const extendedKey = (0, import_utils33.concat)([
|
8220
7988
|
prefix,
|
8221
7989
|
depth,
|
8222
7990
|
fingerprint,
|
8223
7991
|
index,
|
8224
7992
|
chainCode,
|
8225
|
-
(0,
|
7993
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
8226
7994
|
]);
|
8227
|
-
const checksum = (0,
|
8228
|
-
return (0,
|
7995
|
+
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7996
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
8229
7997
|
}
|
8230
7998
|
/**
|
8231
7999
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8240,7 +8008,7 @@ var Mnemonic = class {
|
|
8240
8008
|
* @returns A randomly generated mnemonic
|
8241
8009
|
*/
|
8242
8010
|
static generate(size = 32, extraEntropy = "") {
|
8243
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8011
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
8244
8012
|
return Mnemonic.entropyToMnemonic(entropy);
|
8245
8013
|
}
|
8246
8014
|
};
|
@@ -8248,12 +8016,12 @@ var mnemonic_default = Mnemonic;
|
|
8248
8016
|
|
8249
8017
|
// src/hdwallet/hdwallet.ts
|
8250
8018
|
var HARDENED_INDEX = 2147483648;
|
8251
|
-
var MainnetPRV2 = (0,
|
8252
|
-
var MainnetPUB = (0,
|
8253
|
-
var TestnetPRV2 = (0,
|
8254
|
-
var TestnetPUB = (0,
|
8019
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
8020
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
8021
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
8022
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
8255
8023
|
function base58check(data) {
|
8256
|
-
return (0,
|
8024
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
8257
8025
|
}
|
8258
8026
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8259
8027
|
if (isPublic) {
|
@@ -8262,11 +8030,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8262
8030
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8263
8031
|
}
|
8264
8032
|
function isPublicExtendedKey(extendedKey) {
|
8265
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8033
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
8266
8034
|
}
|
8267
8035
|
function isValidExtendedKey(extendedKey) {
|
8268
8036
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8269
|
-
(0,
|
8037
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
8270
8038
|
);
|
8271
8039
|
}
|
8272
8040
|
function parsePath(path, depth = 0) {
|
@@ -8284,8 +8052,8 @@ function parsePath(path, depth = 0) {
|
|
8284
8052
|
var HDWallet = class {
|
8285
8053
|
depth = 0;
|
8286
8054
|
index = 0;
|
8287
|
-
fingerprint = (0,
|
8288
|
-
parentFingerprint = (0,
|
8055
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8056
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8289
8057
|
privateKey;
|
8290
8058
|
publicKey;
|
8291
8059
|
chainCode;
|
@@ -8297,8 +8065,8 @@ var HDWallet = class {
|
|
8297
8065
|
constructor(config) {
|
8298
8066
|
if (config.privateKey) {
|
8299
8067
|
const signer = new Signer(config.privateKey);
|
8300
|
-
this.publicKey = (0,
|
8301
|
-
this.privateKey = (0,
|
8068
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
8069
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
8302
8070
|
} else {
|
8303
8071
|
if (!config.publicKey) {
|
8304
8072
|
throw new import_errors20.FuelError(
|
@@ -8306,10 +8074,10 @@ var HDWallet = class {
|
|
8306
8074
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8307
8075
|
);
|
8308
8076
|
}
|
8309
|
-
this.publicKey = (0,
|
8077
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
8310
8078
|
}
|
8311
8079
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8312
|
-
this.fingerprint = (0,
|
8080
|
+
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
8313
8081
|
this.depth = config.depth || this.depth;
|
8314
8082
|
this.index = config.index || this.index;
|
8315
8083
|
this.chainCode = config.chainCode;
|
@@ -8325,9 +8093,9 @@ var HDWallet = class {
|
|
8325
8093
|
* @returns A new instance of HDWallet on the derived index
|
8326
8094
|
*/
|
8327
8095
|
deriveIndex(index) {
|
8328
|
-
const privateKey = this.privateKey && (0,
|
8329
|
-
const publicKey = (0,
|
8330
|
-
const chainCode = (0,
|
8096
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
8097
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
8098
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
8331
8099
|
const data = new Uint8Array(37);
|
8332
8100
|
if (index & HARDENED_INDEX) {
|
8333
8101
|
if (!privateKey) {
|
@@ -8338,15 +8106,15 @@ var HDWallet = class {
|
|
8338
8106
|
}
|
8339
8107
|
data.set(privateKey, 1);
|
8340
8108
|
} else {
|
8341
|
-
data.set((0,
|
8109
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
8342
8110
|
}
|
8343
|
-
data.set((0,
|
8344
|
-
const bytes = (0,
|
8111
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
8112
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
8345
8113
|
const IL = bytes.slice(0, 32);
|
8346
8114
|
const IR = bytes.slice(32);
|
8347
8115
|
if (privateKey) {
|
8348
8116
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8349
|
-
const ki = (0,
|
8117
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8350
8118
|
return new HDWallet({
|
8351
8119
|
privateKey: ki,
|
8352
8120
|
chainCode: IR,
|
@@ -8355,7 +8123,7 @@ var HDWallet = class {
|
|
8355
8123
|
parentFingerprint: this.fingerprint
|
8356
8124
|
});
|
8357
8125
|
}
|
8358
|
-
const signer = new Signer((0,
|
8126
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
8359
8127
|
const Ki = signer.addPoint(publicKey);
|
8360
8128
|
return new HDWallet({
|
8361
8129
|
publicKey: Ki,
|
@@ -8390,12 +8158,12 @@ var HDWallet = class {
|
|
8390
8158
|
);
|
8391
8159
|
}
|
8392
8160
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8393
|
-
const depth = (0,
|
8161
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
8394
8162
|
const parentFingerprint = this.parentFingerprint;
|
8395
|
-
const index = (0,
|
8163
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
8396
8164
|
const chainCode = this.chainCode;
|
8397
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8398
|
-
const extendedKey = (0,
|
8165
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8166
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8399
8167
|
return base58check(extendedKey);
|
8400
8168
|
}
|
8401
8169
|
/**
|
@@ -8407,13 +8175,13 @@ var HDWallet = class {
|
|
8407
8175
|
static fromSeed(seed) {
|
8408
8176
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8409
8177
|
return new HDWallet({
|
8410
|
-
chainCode: (0,
|
8411
|
-
privateKey: (0,
|
8178
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
8179
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
8412
8180
|
});
|
8413
8181
|
}
|
8414
8182
|
static fromExtendedKey(extendedKey) {
|
8415
|
-
const decoded = (0,
|
8416
|
-
const bytes = (0,
|
8183
|
+
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8184
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
8417
8185
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8418
8186
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8419
8187
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8422,9 +8190,9 @@ var HDWallet = class {
|
|
8422
8190
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8423
8191
|
}
|
8424
8192
|
const depth = bytes[4];
|
8425
|
-
const parentFingerprint = (0,
|
8426
|
-
const index = parseInt((0,
|
8427
|
-
const chainCode = (0,
|
8193
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
8194
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8195
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
8428
8196
|
const key = bytes.slice(45, 78);
|
8429
8197
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8430
8198
|
throw new import_errors20.FuelError(
|
@@ -9029,19 +8797,19 @@ var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
|
9029
8797
|
var import_address10 = require("@fuel-ts/address");
|
9030
8798
|
var import_configs13 = require("@fuel-ts/address/configs");
|
9031
8799
|
var import_errors25 = require("@fuel-ts/errors");
|
9032
|
-
var
|
9033
|
-
var
|
8800
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
8801
|
+
var import_utils37 = require("@fuel-ts/utils");
|
9034
8802
|
|
9035
8803
|
// src/predicate/utils/getPredicateRoot.ts
|
9036
8804
|
var import_hasher7 = require("@fuel-ts/hasher");
|
9037
8805
|
var import_merkle = require("@fuel-ts/merkle");
|
9038
|
-
var
|
8806
|
+
var import_utils36 = require("@fuel-ts/utils");
|
9039
8807
|
var getPredicateRoot = (bytecode) => {
|
9040
8808
|
const chunkSize = 16 * 1024;
|
9041
|
-
const bytes = (0,
|
9042
|
-
const chunks = (0,
|
9043
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
9044
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
8809
|
+
const bytes = (0, import_utils36.arrayify)(bytecode);
|
8810
|
+
const chunks = (0, import_utils36.chunkAndPadBytes)(bytes, chunkSize);
|
8811
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils36.hexlify)(c)));
|
8812
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils36.concat)(["0x4655454C", codeRoot]));
|
9045
8813
|
return predicateRoot;
|
9046
8814
|
};
|
9047
8815
|
|
@@ -9078,7 +8846,6 @@ var Predicate = class extends Account {
|
|
9078
8846
|
this.interface = predicateInterface;
|
9079
8847
|
if (inputData !== void 0 && inputData.length > 0) {
|
9080
8848
|
this.predicateData = inputData;
|
9081
|
-
this.predicateDataBytes = this.getPredicateData(0);
|
9082
8849
|
}
|
9083
8850
|
}
|
9084
8851
|
/**
|
@@ -9091,9 +8858,9 @@ var Predicate = class extends Account {
|
|
9091
8858
|
const request = transactionRequestify(transactionRequestLike);
|
9092
8859
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
9093
8860
|
request.inputs?.forEach((input) => {
|
9094
|
-
if (input.type ===
|
9095
|
-
input.predicate =
|
9096
|
-
input.predicateData =
|
8861
|
+
if (input.type === import_transactions20.InputType.Coin && (0, import_utils37.hexlify)(input.owner) === this.address.toB256()) {
|
8862
|
+
input.predicate = this.bytes;
|
8863
|
+
input.predicateData = this.getPredicateData(policies.length);
|
9097
8864
|
}
|
9098
8865
|
});
|
9099
8866
|
return request;
|
@@ -9108,7 +8875,8 @@ var Predicate = class extends Account {
|
|
9108
8875
|
* @returns A promise that resolves to the prepared transaction request.
|
9109
8876
|
*/
|
9110
8877
|
async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
|
9111
|
-
|
8878
|
+
const request = await super.createTransfer(destination, amount, assetId, txParams);
|
8879
|
+
return this.populateTransactionPredicateData(request);
|
9112
8880
|
}
|
9113
8881
|
/**
|
9114
8882
|
* Sends a transaction with the populated predicate data.
|
@@ -9116,9 +8884,9 @@ var Predicate = class extends Account {
|
|
9116
8884
|
* @param transactionRequestLike - The transaction request-like object.
|
9117
8885
|
* @returns A promise that resolves to the transaction response.
|
9118
8886
|
*/
|
9119
|
-
sendTransaction(transactionRequestLike) {
|
9120
|
-
const transactionRequest =
|
9121
|
-
return super.sendTransaction(transactionRequest,
|
8887
|
+
sendTransaction(transactionRequestLike, options) {
|
8888
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8889
|
+
return super.sendTransaction(transactionRequest, options);
|
9122
8890
|
}
|
9123
8891
|
/**
|
9124
8892
|
* Simulates a transaction with the populated predicate data.
|
@@ -9127,15 +8895,15 @@ var Predicate = class extends Account {
|
|
9127
8895
|
* @returns A promise that resolves to the call result.
|
9128
8896
|
*/
|
9129
8897
|
simulateTransaction(transactionRequestLike) {
|
9130
|
-
const transactionRequest =
|
9131
|
-
return super.simulateTransaction(transactionRequest
|
8898
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8899
|
+
return super.simulateTransaction(transactionRequest);
|
9132
8900
|
}
|
9133
8901
|
getPredicateData(policiesLength) {
|
9134
8902
|
if (!this.predicateData.length) {
|
9135
8903
|
return new Uint8Array();
|
9136
8904
|
}
|
9137
8905
|
const mainFn = this.interface?.functions.main;
|
9138
|
-
const paddedCode = new
|
8906
|
+
const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
9139
8907
|
const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
|
9140
8908
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
9141
8909
|
});
|
@@ -9151,7 +8919,7 @@ var Predicate = class extends Account {
|
|
9151
8919
|
* @returns An object containing the new predicate bytes and interface.
|
9152
8920
|
*/
|
9153
8921
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
9154
|
-
let predicateBytes = (0,
|
8922
|
+
let predicateBytes = (0, import_utils37.arrayify)(bytes);
|
9155
8923
|
let abiInterface;
|
9156
8924
|
if (jsonAbi) {
|
9157
8925
|
abiInterface = new import_abi_coder5.Interface(jsonAbi);
|
@@ -9174,26 +8942,6 @@ var Predicate = class extends Account {
|
|
9174
8942
|
predicateInterface: abiInterface
|
9175
8943
|
};
|
9176
8944
|
}
|
9177
|
-
/**
|
9178
|
-
* Retrieves resources satisfying the spend query for the account.
|
9179
|
-
*
|
9180
|
-
* @param quantities - IDs of coins to exclude.
|
9181
|
-
* @param excludedIds - IDs of resources to be excluded from the query.
|
9182
|
-
* @returns A promise that resolves to an array of Resources.
|
9183
|
-
*/
|
9184
|
-
async getResourcesToSpend(quantities, excludedIds) {
|
9185
|
-
const resources = await this.provider.getResourcesToSpend(
|
9186
|
-
this.address,
|
9187
|
-
quantities,
|
9188
|
-
excludedIds
|
9189
|
-
);
|
9190
|
-
return resources.map((resource) => ({
|
9191
|
-
...resource,
|
9192
|
-
predicate: (0, import_utils36.hexlify)(this.bytes),
|
9193
|
-
predicateData: (0, import_utils36.hexlify)(this.predicateDataBytes),
|
9194
|
-
paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
|
9195
|
-
}));
|
9196
|
-
}
|
9197
8945
|
/**
|
9198
8946
|
* Sets the configurable constants for the predicate.
|
9199
8947
|
*
|
@@ -9943,7 +9691,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9943
9691
|
WalletLocked,
|
9944
9692
|
WalletManager,
|
9945
9693
|
WalletUnlocked,
|
9946
|
-
|
9694
|
+
addAmountToAsset,
|
9947
9695
|
addOperation,
|
9948
9696
|
assemblePanicError,
|
9949
9697
|
assembleReceiptByType,
|
@@ -9952,10 +9700,9 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9952
9700
|
assets,
|
9953
9701
|
buildBlockExplorerUrl,
|
9954
9702
|
cacheFor,
|
9955
|
-
cacheTxInputsFromOwner,
|
9956
|
-
calculateGasFee,
|
9957
9703
|
calculateMetadataGasForTxCreate,
|
9958
9704
|
calculateMetadataGasForTxScript,
|
9705
|
+
calculatePriceWithFactor,
|
9959
9706
|
calculateTransactionFee,
|
9960
9707
|
coinQuantityfy,
|
9961
9708
|
deferPromise,
|