@fuel-ts/account 0.0.0-rc-2021-20240424160726 → 0.0.0-rc-2143-20240424161332
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 +5 -6
- 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 +583 -863
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +513 -793
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +395 -674
- 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 +326 -828
- 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/message.d.ts +1 -7
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +27 -37
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.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 +29 -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/launchNode.d.ts +4 -2
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1055 -1551
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +513 -775
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +406 -668
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
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,51 +229,27 @@ 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
|
236
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
239
237
|
var import_ethers = require("ethers");
|
240
238
|
var import_graphql_request = require("graphql-request");
|
241
239
|
var import_ramda3 = require("ramda");
|
242
240
|
|
243
241
|
// src/providers/__generated__/operations.ts
|
244
242
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
245
|
-
var TransactionStatusSubscriptionFragmentFragmentDoc = import_graphql_tag.default`
|
246
|
-
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
247
|
-
type: __typename
|
248
|
-
... on SubmittedStatus {
|
249
|
-
time
|
250
|
-
}
|
251
|
-
... on SuccessStatus {
|
252
|
-
block {
|
253
|
-
id
|
254
|
-
}
|
255
|
-
time
|
256
|
-
programState {
|
257
|
-
returnType
|
258
|
-
data
|
259
|
-
}
|
260
|
-
}
|
261
|
-
... on FailureStatus {
|
262
|
-
block {
|
263
|
-
id
|
264
|
-
}
|
265
|
-
time
|
266
|
-
reason
|
267
|
-
}
|
268
|
-
... on SqueezedOutStatus {
|
269
|
-
reason
|
270
|
-
}
|
271
|
-
}
|
272
|
-
`;
|
273
243
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
274
244
|
fragment receiptFragment on Receipt {
|
275
|
-
|
245
|
+
contract {
|
246
|
+
id
|
247
|
+
}
|
276
248
|
pc
|
277
249
|
is
|
278
|
-
to
|
250
|
+
to {
|
251
|
+
id
|
252
|
+
}
|
279
253
|
toAddress
|
280
254
|
amount
|
281
255
|
assetId
|
@@ -313,16 +287,10 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
313
287
|
id
|
314
288
|
}
|
315
289
|
time
|
316
|
-
receipts {
|
317
|
-
...receiptFragment
|
318
|
-
}
|
319
290
|
programState {
|
320
291
|
returnType
|
321
292
|
data
|
322
293
|
}
|
323
|
-
receipts {
|
324
|
-
...receiptFragment
|
325
|
-
}
|
326
294
|
}
|
327
295
|
... on FailureStatus {
|
328
296
|
block {
|
@@ -330,24 +298,26 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
330
298
|
}
|
331
299
|
time
|
332
300
|
reason
|
333
|
-
receipts {
|
334
|
-
...receiptFragment
|
335
|
-
}
|
336
301
|
}
|
337
302
|
... on SqueezedOutStatus {
|
338
303
|
reason
|
339
304
|
}
|
340
305
|
}
|
341
|
-
|
306
|
+
`;
|
342
307
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
343
308
|
fragment transactionFragment on Transaction {
|
344
309
|
id
|
345
310
|
rawPayload
|
311
|
+
gasPrice
|
312
|
+
receipts {
|
313
|
+
...receiptFragment
|
314
|
+
}
|
346
315
|
status {
|
347
316
|
...transactionStatusFragment
|
348
317
|
}
|
349
318
|
}
|
350
|
-
${
|
319
|
+
${ReceiptFragmentFragmentDoc}
|
320
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
351
321
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
352
322
|
fragment inputEstimatePredicatesFragment on Input {
|
353
323
|
... on InputCoin {
|
@@ -365,46 +335,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
365
335
|
}
|
366
336
|
}
|
367
337
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
368
|
-
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
369
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
370
|
-
reason
|
371
|
-
programState {
|
372
|
-
returnType
|
373
|
-
data
|
374
|
-
}
|
375
|
-
}
|
376
|
-
`;
|
377
|
-
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
378
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
379
|
-
programState {
|
380
|
-
returnType
|
381
|
-
data
|
382
|
-
}
|
383
|
-
}
|
384
|
-
`;
|
385
|
-
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
386
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
387
|
-
... on DryRunFailureStatus {
|
388
|
-
...dryRunFailureStatusFragment
|
389
|
-
}
|
390
|
-
... on DryRunSuccessStatus {
|
391
|
-
...dryRunSuccessStatusFragment
|
392
|
-
}
|
393
|
-
}
|
394
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
395
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
396
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
397
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
398
|
-
id
|
399
|
-
status {
|
400
|
-
...dryRunTransactionStatusFragment
|
401
|
-
}
|
402
|
-
receipts {
|
403
|
-
...receiptFragment
|
404
|
-
}
|
405
|
-
}
|
406
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
407
|
-
${ReceiptFragmentFragmentDoc}`;
|
408
338
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
409
339
|
fragment coinFragment on Coin {
|
410
340
|
__typename
|
@@ -412,6 +342,7 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
412
342
|
owner
|
413
343
|
amount
|
414
344
|
assetId
|
345
|
+
maturity
|
415
346
|
blockCreated
|
416
347
|
txCreatedIdx
|
417
348
|
}
|
@@ -450,32 +381,26 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
450
381
|
messageBlockHeader {
|
451
382
|
id
|
452
383
|
daHeight
|
453
|
-
consensusParametersVersion
|
454
|
-
stateTransitionBytecodeVersion
|
455
384
|
transactionsCount
|
456
|
-
messageReceiptCount
|
457
385
|
transactionsRoot
|
458
|
-
messageOutboxRoot
|
459
|
-
eventInboxRoot
|
460
386
|
height
|
461
387
|
prevRoot
|
462
388
|
time
|
463
389
|
applicationHash
|
390
|
+
messageReceiptRoot
|
391
|
+
messageReceiptCount
|
464
392
|
}
|
465
393
|
commitBlockHeader {
|
466
394
|
id
|
467
395
|
daHeight
|
468
|
-
consensusParametersVersion
|
469
|
-
stateTransitionBytecodeVersion
|
470
396
|
transactionsCount
|
471
|
-
messageReceiptCount
|
472
397
|
transactionsRoot
|
473
|
-
messageOutboxRoot
|
474
|
-
eventInboxRoot
|
475
398
|
height
|
476
399
|
prevRoot
|
477
400
|
time
|
478
401
|
applicationHash
|
402
|
+
messageReceiptRoot
|
403
|
+
messageReceiptCount
|
479
404
|
}
|
480
405
|
sender
|
481
406
|
recipient
|
@@ -494,8 +419,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
494
419
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
495
420
|
fragment blockFragment on Block {
|
496
421
|
id
|
497
|
-
height
|
498
422
|
header {
|
423
|
+
height
|
499
424
|
time
|
500
425
|
}
|
501
426
|
transactions {
|
@@ -505,7 +430,6 @@ var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
|
505
430
|
`;
|
506
431
|
var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
|
507
432
|
fragment TxParametersFragment on TxParameters {
|
508
|
-
version
|
509
433
|
maxInputs
|
510
434
|
maxOutputs
|
511
435
|
maxWitnesses
|
@@ -515,7 +439,6 @@ var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
|
|
515
439
|
`;
|
516
440
|
var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
|
517
441
|
fragment PredicateParametersFragment on PredicateParameters {
|
518
|
-
version
|
519
442
|
maxPredicateLength
|
520
443
|
maxPredicateDataLength
|
521
444
|
maxGasPerPredicate
|
@@ -524,21 +447,18 @@ var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
|
|
524
447
|
`;
|
525
448
|
var ScriptParametersFragmentFragmentDoc = import_graphql_tag.default`
|
526
449
|
fragment ScriptParametersFragment on ScriptParameters {
|
527
|
-
version
|
528
450
|
maxScriptLength
|
529
451
|
maxScriptDataLength
|
530
452
|
}
|
531
453
|
`;
|
532
454
|
var ContractParametersFragmentFragmentDoc = import_graphql_tag.default`
|
533
455
|
fragment ContractParametersFragment on ContractParameters {
|
534
|
-
version
|
535
456
|
contractMaxSize
|
536
457
|
maxStorageSlots
|
537
458
|
}
|
538
459
|
`;
|
539
460
|
var FeeParametersFragmentFragmentDoc = import_graphql_tag.default`
|
540
461
|
fragment FeeParametersFragment on FeeParameters {
|
541
|
-
version
|
542
462
|
gasPriceFactor
|
543
463
|
gasPerByte
|
544
464
|
}
|
@@ -558,7 +478,6 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
558
478
|
`;
|
559
479
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
560
480
|
fragment GasCostsFragment on GasCosts {
|
561
|
-
version
|
562
481
|
add
|
563
482
|
addi
|
564
483
|
aloc
|
@@ -571,6 +490,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
571
490
|
cb
|
572
491
|
cfei
|
573
492
|
cfsi
|
493
|
+
croo
|
574
494
|
div
|
575
495
|
divi
|
576
496
|
ecr1
|
@@ -653,9 +573,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
653
573
|
ccp {
|
654
574
|
...DependentCostFragment
|
655
575
|
}
|
656
|
-
croo {
|
657
|
-
...DependentCostFragment
|
658
|
-
}
|
659
576
|
csiz {
|
660
577
|
...DependentCostFragment
|
661
578
|
}
|
@@ -715,7 +632,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
715
632
|
${DependentCostFragmentFragmentDoc}`;
|
716
633
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
717
634
|
fragment consensusParametersFragment on ConsensusParameters {
|
718
|
-
version
|
719
635
|
txParams {
|
720
636
|
...TxParametersFragment
|
721
637
|
}
|
@@ -775,9 +691,18 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
775
691
|
fragment nodeInfoFragment on NodeInfo {
|
776
692
|
utxoValidation
|
777
693
|
vmBacktrace
|
694
|
+
minGasPrice
|
778
695
|
maxTx
|
779
696
|
maxDepth
|
780
697
|
nodeVersion
|
698
|
+
peers {
|
699
|
+
id
|
700
|
+
addresses
|
701
|
+
clientVersion
|
702
|
+
blockHeight
|
703
|
+
lastHeartbeatMs
|
704
|
+
appScore
|
705
|
+
}
|
781
706
|
}
|
782
707
|
`;
|
783
708
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -812,9 +737,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
812
737
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
813
738
|
transaction(id: $transactionId) {
|
814
739
|
...transactionFragment
|
740
|
+
receipts {
|
741
|
+
...receiptFragment
|
742
|
+
}
|
815
743
|
}
|
816
744
|
}
|
817
|
-
${TransactionFragmentFragmentDoc}
|
745
|
+
${TransactionFragmentFragmentDoc}
|
746
|
+
${ReceiptFragmentFragmentDoc}`;
|
818
747
|
var GetTransactionsDocument = import_graphql_tag.default`
|
819
748
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
820
749
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -942,20 +871,6 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
942
871
|
}
|
943
872
|
}
|
944
873
|
${BalanceFragmentFragmentDoc}`;
|
945
|
-
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
946
|
-
query getLatestGasPrice {
|
947
|
-
latestGasPrice {
|
948
|
-
gasPrice
|
949
|
-
}
|
950
|
-
}
|
951
|
-
`;
|
952
|
-
var EstimateGasPriceDocument = import_graphql_tag.default`
|
953
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
954
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
955
|
-
gasPrice
|
956
|
-
}
|
957
|
-
}
|
958
|
-
`;
|
959
874
|
var GetBalancesDocument = import_graphql_tag.default`
|
960
875
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
961
876
|
balances(
|
@@ -1010,12 +925,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
1010
925
|
}
|
1011
926
|
`;
|
1012
927
|
var DryRunDocument = import_graphql_tag.default`
|
1013
|
-
mutation dryRun($
|
1014
|
-
dryRun(
|
1015
|
-
...
|
928
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
929
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
930
|
+
...receiptFragment
|
1016
931
|
}
|
1017
932
|
}
|
1018
|
-
${
|
933
|
+
${ReceiptFragmentFragmentDoc}`;
|
1019
934
|
var SubmitDocument = import_graphql_tag.default`
|
1020
935
|
mutation submit($encodedTransaction: HexString!) {
|
1021
936
|
submit(tx: $encodedTransaction) {
|
@@ -1034,17 +949,17 @@ var ProduceBlocksDocument = import_graphql_tag.default`
|
|
1034
949
|
var SubmitAndAwaitDocument = import_graphql_tag.default`
|
1035
950
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
1036
951
|
submitAndAwait(tx: $encodedTransaction) {
|
1037
|
-
...
|
952
|
+
...transactionStatusFragment
|
1038
953
|
}
|
1039
954
|
}
|
1040
|
-
${
|
955
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
1041
956
|
var StatusChangeDocument = import_graphql_tag.default`
|
1042
957
|
subscription statusChange($transactionId: TransactionId!) {
|
1043
958
|
statusChange(id: $transactionId) {
|
1044
|
-
...
|
959
|
+
...transactionStatusFragment
|
1045
960
|
}
|
1046
961
|
}
|
1047
|
-
${
|
962
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
1048
963
|
function getSdk(requester) {
|
1049
964
|
return {
|
1050
965
|
getVersion(variables, options) {
|
@@ -1098,12 +1013,6 @@ function getSdk(requester) {
|
|
1098
1013
|
getBalance(variables, options) {
|
1099
1014
|
return requester(GetBalanceDocument, variables, options);
|
1100
1015
|
},
|
1101
|
-
getLatestGasPrice(variables, options) {
|
1102
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
1103
|
-
},
|
1104
|
-
estimateGasPrice(variables, options) {
|
1105
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
1106
|
-
},
|
1107
1016
|
getBalances(variables, options) {
|
1108
1017
|
return requester(GetBalancesDocument, variables, options);
|
1109
1018
|
},
|
@@ -1297,9 +1206,10 @@ var inputify = (value) => {
|
|
1297
1206
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1298
1207
|
},
|
1299
1208
|
witnessIndex: value.witnessIndex,
|
1209
|
+
maturity: value.maturity ?? 0,
|
1300
1210
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1301
|
-
predicateLength:
|
1302
|
-
predicateDataLength:
|
1211
|
+
predicateLength: predicate.length,
|
1212
|
+
predicateDataLength: predicateData.length,
|
1303
1213
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1304
1214
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1305
1215
|
};
|
@@ -1330,8 +1240,8 @@ var inputify = (value) => {
|
|
1330
1240
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1331
1241
|
witnessIndex: value.witnessIndex,
|
1332
1242
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1333
|
-
predicateLength:
|
1334
|
-
predicateDataLength:
|
1243
|
+
predicateLength: predicate.length,
|
1244
|
+
predicateDataLength: predicateData.length,
|
1335
1245
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1336
1246
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1337
1247
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1450,8 +1360,8 @@ function assembleReceiptByType(receipt) {
|
|
1450
1360
|
case "CALL" /* Call */: {
|
1451
1361
|
const callReceipt = {
|
1452
1362
|
type: import_transactions3.ReceiptType.Call,
|
1453
|
-
from: hexOrZero(receipt.id
|
1454
|
-
to: hexOrZero(receipt?.to),
|
1363
|
+
from: hexOrZero(receipt.contract?.id),
|
1364
|
+
to: hexOrZero(receipt?.to?.id),
|
1455
1365
|
amount: (0, import_math4.bn)(receipt.amount),
|
1456
1366
|
assetId: hexOrZero(receipt.assetId),
|
1457
1367
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1465,7 +1375,7 @@ function assembleReceiptByType(receipt) {
|
|
1465
1375
|
case "RETURN" /* Return */: {
|
1466
1376
|
const returnReceipt = {
|
1467
1377
|
type: import_transactions3.ReceiptType.Return,
|
1468
|
-
id: hexOrZero(receipt.id
|
1378
|
+
id: hexOrZero(receipt.contract?.id),
|
1469
1379
|
val: (0, import_math4.bn)(receipt.val),
|
1470
1380
|
pc: (0, import_math4.bn)(receipt.pc),
|
1471
1381
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1475,7 +1385,7 @@ function assembleReceiptByType(receipt) {
|
|
1475
1385
|
case "RETURN_DATA" /* ReturnData */: {
|
1476
1386
|
const returnDataReceipt = {
|
1477
1387
|
type: import_transactions3.ReceiptType.ReturnData,
|
1478
|
-
id: hexOrZero(receipt.id
|
1388
|
+
id: hexOrZero(receipt.contract?.id),
|
1479
1389
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1480
1390
|
len: (0, import_math4.bn)(receipt.len),
|
1481
1391
|
digest: hexOrZero(receipt.digest),
|
@@ -1487,7 +1397,7 @@ function assembleReceiptByType(receipt) {
|
|
1487
1397
|
case "PANIC" /* Panic */: {
|
1488
1398
|
const panicReceipt = {
|
1489
1399
|
type: import_transactions3.ReceiptType.Panic,
|
1490
|
-
id: hexOrZero(receipt.id),
|
1400
|
+
id: hexOrZero(receipt.contract?.id),
|
1491
1401
|
reason: (0, import_math4.bn)(receipt.reason),
|
1492
1402
|
pc: (0, import_math4.bn)(receipt.pc),
|
1493
1403
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1498,7 +1408,7 @@ function assembleReceiptByType(receipt) {
|
|
1498
1408
|
case "REVERT" /* Revert */: {
|
1499
1409
|
const revertReceipt = {
|
1500
1410
|
type: import_transactions3.ReceiptType.Revert,
|
1501
|
-
id: hexOrZero(receipt.id
|
1411
|
+
id: hexOrZero(receipt.contract?.id),
|
1502
1412
|
val: (0, import_math4.bn)(receipt.ra),
|
1503
1413
|
pc: (0, import_math4.bn)(receipt.pc),
|
1504
1414
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1508,7 +1418,7 @@ function assembleReceiptByType(receipt) {
|
|
1508
1418
|
case "LOG" /* Log */: {
|
1509
1419
|
const logReceipt = {
|
1510
1420
|
type: import_transactions3.ReceiptType.Log,
|
1511
|
-
id: hexOrZero(receipt.id
|
1421
|
+
id: hexOrZero(receipt.contract?.id),
|
1512
1422
|
val0: (0, import_math4.bn)(receipt.ra),
|
1513
1423
|
val1: (0, import_math4.bn)(receipt.rb),
|
1514
1424
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1521,7 +1431,7 @@ function assembleReceiptByType(receipt) {
|
|
1521
1431
|
case "LOG_DATA" /* LogData */: {
|
1522
1432
|
const logDataReceipt = {
|
1523
1433
|
type: import_transactions3.ReceiptType.LogData,
|
1524
|
-
id: hexOrZero(receipt.id
|
1434
|
+
id: hexOrZero(receipt.contract?.id),
|
1525
1435
|
val0: (0, import_math4.bn)(receipt.ra),
|
1526
1436
|
val1: (0, import_math4.bn)(receipt.rb),
|
1527
1437
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1535,8 +1445,8 @@ function assembleReceiptByType(receipt) {
|
|
1535
1445
|
case "TRANSFER" /* Transfer */: {
|
1536
1446
|
const transferReceipt = {
|
1537
1447
|
type: import_transactions3.ReceiptType.Transfer,
|
1538
|
-
from: hexOrZero(receipt.id
|
1539
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1448
|
+
from: hexOrZero(receipt.contract?.id),
|
1449
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1540
1450
|
amount: (0, import_math4.bn)(receipt.amount),
|
1541
1451
|
assetId: hexOrZero(receipt.assetId),
|
1542
1452
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1547,8 +1457,8 @@ function assembleReceiptByType(receipt) {
|
|
1547
1457
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1548
1458
|
const transferOutReceipt = {
|
1549
1459
|
type: import_transactions3.ReceiptType.TransferOut,
|
1550
|
-
from: hexOrZero(receipt.id
|
1551
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1460
|
+
from: hexOrZero(receipt.contract?.id),
|
1461
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1552
1462
|
amount: (0, import_math4.bn)(receipt.amount),
|
1553
1463
|
assetId: hexOrZero(receipt.assetId),
|
1554
1464
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1591,7 +1501,7 @@ function assembleReceiptByType(receipt) {
|
|
1591
1501
|
return receiptMessageOut;
|
1592
1502
|
}
|
1593
1503
|
case "MINT" /* Mint */: {
|
1594
|
-
const contractId = hexOrZero(receipt.id
|
1504
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1595
1505
|
const subId = hexOrZero(receipt.subId);
|
1596
1506
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1597
1507
|
const mintReceipt = {
|
@@ -1606,7 +1516,7 @@ function assembleReceiptByType(receipt) {
|
|
1606
1516
|
return mintReceipt;
|
1607
1517
|
}
|
1608
1518
|
case "BURN" /* Burn */: {
|
1609
|
-
const contractId = hexOrZero(receipt.id
|
1519
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1610
1520
|
const subId = hexOrZero(receipt.subId);
|
1611
1521
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1612
1522
|
const burnReceipt = {
|
@@ -1691,6 +1601,7 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1691
1601
|
var import_math5 = require("@fuel-ts/math");
|
1692
1602
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1693
1603
|
var import_utils6 = require("@fuel-ts/utils");
|
1604
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1694
1605
|
var getGasUsedFromReceipts = (receipts) => {
|
1695
1606
|
const scriptResult = receipts.filter(
|
1696
1607
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1711,28 +1622,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1711
1622
|
}
|
1712
1623
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1713
1624
|
const witnessCache = [];
|
1714
|
-
const
|
1715
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1716
|
-
if (isCoinOrMessage) {
|
1717
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1718
|
-
return true;
|
1719
|
-
}
|
1720
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1721
|
-
witnessCache.push(input.witnessIndex);
|
1722
|
-
return true;
|
1723
|
-
}
|
1724
|
-
}
|
1725
|
-
return false;
|
1726
|
-
});
|
1727
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1728
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1625
|
+
const totalGas = inputs.reduce((total, input) => {
|
1729
1626
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1730
1627
|
return total.add(
|
1731
|
-
|
1628
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1732
1629
|
);
|
1733
1630
|
}
|
1734
|
-
|
1735
|
-
|
1631
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1632
|
+
witnessCache.push(input.witnessIndex);
|
1633
|
+
return total.add(gasCosts.ecr1);
|
1634
|
+
}
|
1635
|
+
return total;
|
1636
|
+
}, (0, import_math5.bn)());
|
1736
1637
|
return totalGas;
|
1737
1638
|
}
|
1738
1639
|
function getMinGas(params) {
|
@@ -1744,20 +1645,12 @@ function getMinGas(params) {
|
|
1744
1645
|
return minGas;
|
1745
1646
|
}
|
1746
1647
|
function getMaxGas(params) {
|
1747
|
-
const {
|
1748
|
-
gasPerByte,
|
1749
|
-
witnessesLength,
|
1750
|
-
witnessLimit,
|
1751
|
-
minGas,
|
1752
|
-
gasLimit = (0, import_math5.bn)(0),
|
1753
|
-
maxGasPerTx
|
1754
|
-
} = params;
|
1648
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
|
1755
1649
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1756
1650
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1757
1651
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1758
1652
|
}
|
1759
|
-
|
1760
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1653
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1761
1654
|
}
|
1762
1655
|
function calculateMetadataGasForTxCreate({
|
1763
1656
|
gasCosts,
|
@@ -1779,10 +1672,6 @@ function calculateMetadataGasForTxScript({
|
|
1779
1672
|
}) {
|
1780
1673
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1781
1674
|
}
|
1782
|
-
var calculateGasFee = (params) => {
|
1783
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1784
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1785
|
-
};
|
1786
1675
|
|
1787
1676
|
// src/providers/utils/json.ts
|
1788
1677
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1931,7 +1820,7 @@ var witnessify = (value) => {
|
|
1931
1820
|
// src/providers/transaction-request/transaction-request.ts
|
1932
1821
|
var BaseTransactionRequest = class {
|
1933
1822
|
/** Gas price for transaction */
|
1934
|
-
|
1823
|
+
gasPrice;
|
1935
1824
|
/** Block until which tx cannot be included */
|
1936
1825
|
maturity;
|
1937
1826
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1950,7 +1839,7 @@ var BaseTransactionRequest = class {
|
|
1950
1839
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1951
1840
|
*/
|
1952
1841
|
constructor({
|
1953
|
-
|
1842
|
+
gasPrice,
|
1954
1843
|
maturity,
|
1955
1844
|
maxFee,
|
1956
1845
|
witnessLimit,
|
@@ -1958,7 +1847,7 @@ var BaseTransactionRequest = class {
|
|
1958
1847
|
outputs,
|
1959
1848
|
witnesses
|
1960
1849
|
} = {}) {
|
1961
|
-
this.
|
1850
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1962
1851
|
this.maturity = maturity ?? 0;
|
1963
1852
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1964
1853
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1969,9 +1858,9 @@ var BaseTransactionRequest = class {
|
|
1969
1858
|
static getPolicyMeta(req) {
|
1970
1859
|
let policyTypes = 0;
|
1971
1860
|
const policies = [];
|
1972
|
-
if (req.
|
1973
|
-
policyTypes += import_transactions6.PolicyType.
|
1974
|
-
policies.push({ data: req.
|
1861
|
+
if (req.gasPrice) {
|
1862
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1863
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1975
1864
|
}
|
1976
1865
|
if (req.witnessLimit) {
|
1977
1866
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -2155,11 +2044,13 @@ var BaseTransactionRequest = class {
|
|
2155
2044
|
* assetId, if one it was not added yet.
|
2156
2045
|
*
|
2157
2046
|
* @param coin - Coin resource.
|
2047
|
+
* @param predicate - Predicate bytes.
|
2048
|
+
* @param predicateData - Predicate data bytes.
|
2158
2049
|
*/
|
2159
|
-
addCoinInput(coin) {
|
2050
|
+
addCoinInput(coin, predicate) {
|
2160
2051
|
const { assetId, owner, amount } = coin;
|
2161
2052
|
let witnessIndex;
|
2162
|
-
if (
|
2053
|
+
if (predicate) {
|
2163
2054
|
witnessIndex = 0;
|
2164
2055
|
} else {
|
2165
2056
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2174,7 +2065,8 @@ var BaseTransactionRequest = class {
|
|
2174
2065
|
amount,
|
2175
2066
|
assetId,
|
2176
2067
|
txPointer: "0x00000000000000000000000000000000",
|
2177
|
-
witnessIndex
|
2068
|
+
witnessIndex,
|
2069
|
+
predicate: predicate?.bytes
|
2178
2070
|
};
|
2179
2071
|
this.pushInput(input);
|
2180
2072
|
this.addChangeOutput(owner, assetId);
|
@@ -2184,12 +2076,14 @@ var BaseTransactionRequest = class {
|
|
2184
2076
|
* baseAssetId, if one it was not added yet.
|
2185
2077
|
*
|
2186
2078
|
* @param message - Message resource.
|
2079
|
+
* @param predicate - Predicate bytes.
|
2080
|
+
* @param predicateData - Predicate data bytes.
|
2187
2081
|
*/
|
2188
|
-
addMessageInput(message) {
|
2082
|
+
addMessageInput(message, predicate) {
|
2189
2083
|
const { recipient, sender, amount } = message;
|
2190
2084
|
const assetId = import_configs7.BaseAssetId;
|
2191
2085
|
let witnessIndex;
|
2192
|
-
if (
|
2086
|
+
if (predicate) {
|
2193
2087
|
witnessIndex = 0;
|
2194
2088
|
} else {
|
2195
2089
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2203,7 +2097,8 @@ var BaseTransactionRequest = class {
|
|
2203
2097
|
sender: sender.toB256(),
|
2204
2098
|
recipient: recipient.toB256(),
|
2205
2099
|
amount,
|
2206
|
-
witnessIndex
|
2100
|
+
witnessIndex,
|
2101
|
+
predicate: predicate?.bytes
|
2207
2102
|
};
|
2208
2103
|
this.pushInput(input);
|
2209
2104
|
this.addChangeOutput(recipient, assetId);
|
@@ -2234,6 +2129,32 @@ var BaseTransactionRequest = class {
|
|
2234
2129
|
resources.forEach((resource) => this.addResource(resource));
|
2235
2130
|
return this;
|
2236
2131
|
}
|
2132
|
+
/**
|
2133
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
2134
|
+
* outputs from the related assetIds.
|
2135
|
+
*
|
2136
|
+
* @param resources - The resources to add.
|
2137
|
+
* @returns This transaction.
|
2138
|
+
*/
|
2139
|
+
addPredicateResource(resource, predicate) {
|
2140
|
+
if (isCoin(resource)) {
|
2141
|
+
this.addCoinInput(resource, predicate);
|
2142
|
+
} else {
|
2143
|
+
this.addMessageInput(resource, predicate);
|
2144
|
+
}
|
2145
|
+
return this;
|
2146
|
+
}
|
2147
|
+
/**
|
2148
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2149
|
+
* from the related assetIds.
|
2150
|
+
*
|
2151
|
+
* @param resources - The resources to add.
|
2152
|
+
* @returns This transaction.
|
2153
|
+
*/
|
2154
|
+
addPredicateResources(resources, predicate) {
|
2155
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2156
|
+
return this;
|
2157
|
+
}
|
2237
2158
|
/**
|
2238
2159
|
* Adds a coin output to the transaction.
|
2239
2160
|
*
|
@@ -2313,7 +2234,7 @@ var BaseTransactionRequest = class {
|
|
2313
2234
|
}
|
2314
2235
|
calculateMaxGas(chainInfo, minGas) {
|
2315
2236
|
const { consensusParameters } = chainInfo;
|
2316
|
-
const { gasPerByte
|
2237
|
+
const { gasPerByte } = consensusParameters;
|
2317
2238
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2318
2239
|
(acc, wit) => acc + wit.dataLength,
|
2319
2240
|
0
|
@@ -2322,8 +2243,7 @@ var BaseTransactionRequest = class {
|
|
2322
2243
|
gasPerByte,
|
2323
2244
|
minGas,
|
2324
2245
|
witnessesLength,
|
2325
|
-
witnessLimit: this.witnessLimit
|
2326
|
-
maxGasPerTx
|
2246
|
+
witnessLimit: this.witnessLimit
|
2327
2247
|
});
|
2328
2248
|
}
|
2329
2249
|
/**
|
@@ -2341,20 +2261,17 @@ var BaseTransactionRequest = class {
|
|
2341
2261
|
});
|
2342
2262
|
const updateAssetInput = (assetId, quantity) => {
|
2343
2263
|
const assetInput = findAssetInput(assetId);
|
2344
|
-
let usedQuantity = quantity;
|
2345
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2346
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2347
|
-
}
|
2348
2264
|
if (assetInput && "assetId" in assetInput) {
|
2349
2265
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2350
|
-
assetInput.amount =
|
2266
|
+
assetInput.amount = quantity;
|
2351
2267
|
} else {
|
2352
2268
|
this.addResources([
|
2353
2269
|
{
|
2354
2270
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2355
|
-
amount:
|
2271
|
+
amount: quantity,
|
2356
2272
|
assetId,
|
2357
2273
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2274
|
+
maturity: 0,
|
2358
2275
|
blockCreated: (0, import_math7.bn)(1),
|
2359
2276
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2360
2277
|
}
|
@@ -2386,7 +2303,7 @@ var BaseTransactionRequest = class {
|
|
2386
2303
|
toJSON() {
|
2387
2304
|
return normalizeJSON(this);
|
2388
2305
|
}
|
2389
|
-
|
2306
|
+
updatePredicateInputs(inputs) {
|
2390
2307
|
this.inputs.forEach((i) => {
|
2391
2308
|
let correspondingInput;
|
2392
2309
|
switch (i.type) {
|
@@ -2408,15 +2325,6 @@ var BaseTransactionRequest = class {
|
|
2408
2325
|
}
|
2409
2326
|
});
|
2410
2327
|
}
|
2411
|
-
shiftPredicateData() {
|
2412
|
-
this.inputs.forEach((input) => {
|
2413
|
-
if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
|
2414
|
-
input.predicateData = input.padPredicateData(
|
2415
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2416
|
-
);
|
2417
|
-
}
|
2418
|
-
});
|
2419
|
-
}
|
2420
2328
|
};
|
2421
2329
|
|
2422
2330
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2563,8 +2471,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2563
2471
|
return {
|
2564
2472
|
type: import_transactions8.TransactionType.Create,
|
2565
2473
|
...baseTransaction,
|
2474
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2566
2475
|
bytecodeWitnessIndex,
|
2567
|
-
storageSlotsCount:
|
2476
|
+
storageSlotsCount: storageSlots.length,
|
2568
2477
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2569
2478
|
storageSlots
|
2570
2479
|
};
|
@@ -2687,8 +2596,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2687
2596
|
type: import_transactions9.TransactionType.Script,
|
2688
2597
|
scriptGasLimit: this.gasLimit,
|
2689
2598
|
...super.getBaseTransaction(),
|
2690
|
-
scriptLength:
|
2691
|
-
scriptDataLength:
|
2599
|
+
scriptLength: script.length,
|
2600
|
+
scriptDataLength: scriptData.length,
|
2692
2601
|
receiptsRoot: import_configs10.ZeroBytes32,
|
2693
2602
|
script: (0, import_utils15.hexlify)(script),
|
2694
2603
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2752,7 +2661,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2752
2661
|
}
|
2753
2662
|
calculateMaxGas(chainInfo, minGas) {
|
2754
2663
|
const { consensusParameters } = chainInfo;
|
2755
|
-
const { gasPerByte
|
2664
|
+
const { gasPerByte } = consensusParameters;
|
2756
2665
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2757
2666
|
(acc, wit) => acc + wit.dataLength,
|
2758
2667
|
0
|
@@ -2762,8 +2671,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2762
2671
|
minGas,
|
2763
2672
|
witnessesLength,
|
2764
2673
|
witnessLimit: this.witnessLimit,
|
2765
|
-
gasLimit: this.gasLimit
|
2766
|
-
maxGasPerTx
|
2674
|
+
gasLimit: this.gasLimit
|
2767
2675
|
});
|
2768
2676
|
}
|
2769
2677
|
/**
|
@@ -2838,32 +2746,15 @@ var transactionRequestify = (obj) => {
|
|
2838
2746
|
}
|
2839
2747
|
}
|
2840
2748
|
};
|
2841
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2842
|
-
(acc, input) => {
|
2843
|
-
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2844
|
-
acc.utxos.push(input.id);
|
2845
|
-
}
|
2846
|
-
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2847
|
-
acc.messages.push(input.nonce);
|
2848
|
-
}
|
2849
|
-
return acc;
|
2850
|
-
},
|
2851
|
-
{
|
2852
|
-
utxos: [],
|
2853
|
-
messages: []
|
2854
|
-
}
|
2855
|
-
);
|
2856
2749
|
|
2857
2750
|
// src/providers/transaction-response/transaction-response.ts
|
2858
2751
|
var import_errors13 = require("@fuel-ts/errors");
|
2859
|
-
var
|
2860
|
-
var
|
2861
|
-
var
|
2752
|
+
var import_math14 = require("@fuel-ts/math");
|
2753
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2754
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2862
2755
|
|
2863
2756
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2864
|
-
var
|
2865
|
-
var import_transactions16 = require("@fuel-ts/transactions");
|
2866
|
-
var import_utils18 = require("@fuel-ts/utils");
|
2757
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2867
2758
|
|
2868
2759
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2869
2760
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2871,10 +2762,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2871
2762
|
var import_utils16 = require("@fuel-ts/utils");
|
2872
2763
|
var calculateTransactionFee = (params) => {
|
2873
2764
|
const {
|
2874
|
-
|
2765
|
+
gasUsed,
|
2875
2766
|
rawPayload,
|
2876
|
-
|
2877
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2767
|
+
consensusParameters: { gasCosts, feeParams }
|
2878
2768
|
} = params;
|
2879
2769
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2880
2770
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2884,7 +2774,8 @@ var calculateTransactionFee = (params) => {
|
|
2884
2774
|
return {
|
2885
2775
|
fee: (0, import_math11.bn)(0),
|
2886
2776
|
minFee: (0, import_math11.bn)(0),
|
2887
|
-
maxFee: (0, import_math11.bn)(0)
|
2777
|
+
maxFee: (0, import_math11.bn)(0),
|
2778
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2888
2779
|
};
|
2889
2780
|
}
|
2890
2781
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2916,6 +2807,7 @@ var calculateTransactionFee = (params) => {
|
|
2916
2807
|
metadataGas,
|
2917
2808
|
txBytesSize: transactionBytes.length
|
2918
2809
|
});
|
2810
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2919
2811
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2920
2812
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2921
2813
|
const maxGas = getMaxGas({
|
@@ -2923,25 +2815,17 @@ var calculateTransactionFee = (params) => {
|
|
2923
2815
|
minGas,
|
2924
2816
|
witnessesLength,
|
2925
2817
|
gasLimit,
|
2926
|
-
witnessLimit
|
2927
|
-
maxGasPerTx
|
2928
|
-
});
|
2929
|
-
const minFee = calculateGasFee({
|
2930
|
-
gasPrice,
|
2931
|
-
gas: minGas,
|
2932
|
-
priceFactor: gasPriceFactor,
|
2933
|
-
tip
|
2934
|
-
});
|
2935
|
-
const maxFee = calculateGasFee({
|
2936
|
-
gasPrice,
|
2937
|
-
gas: maxGas,
|
2938
|
-
priceFactor: gasPriceFactor,
|
2939
|
-
tip
|
2818
|
+
witnessLimit
|
2940
2819
|
});
|
2820
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2821
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2822
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2823
|
+
const fee = minFee.add(feeFromGasUsed);
|
2941
2824
|
return {
|
2825
|
+
fee,
|
2942
2826
|
minFee,
|
2943
2827
|
maxFee,
|
2944
|
-
|
2828
|
+
feeFromGasUsed
|
2945
2829
|
};
|
2946
2830
|
};
|
2947
2831
|
|
@@ -3555,12 +3439,10 @@ function assembleTransactionSummary(params) {
|
|
3555
3439
|
gqlTransactionStatus,
|
3556
3440
|
abiMap = {},
|
3557
3441
|
maxInputs,
|
3558
|
-
gasCosts
|
3559
|
-
maxGasPerTx,
|
3560
|
-
gasPrice
|
3442
|
+
gasCosts
|
3561
3443
|
} = params;
|
3562
3444
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3563
|
-
const rawPayload = (0,
|
3445
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3564
3446
|
const operations = getOperations({
|
3565
3447
|
transactionType: transaction.type,
|
3566
3448
|
inputs: transaction.inputs || [],
|
@@ -3571,14 +3453,11 @@ function assembleTransactionSummary(params) {
|
|
3571
3453
|
maxInputs
|
3572
3454
|
});
|
3573
3455
|
const typeName = getTransactionTypeName(transaction.type);
|
3574
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3575
3456
|
const { fee } = calculateTransactionFee({
|
3576
|
-
|
3457
|
+
gasUsed,
|
3577
3458
|
rawPayload,
|
3578
|
-
tip,
|
3579
3459
|
consensusParameters: {
|
3580
3460
|
gasCosts,
|
3581
|
-
maxGasPerTx,
|
3582
3461
|
feeParams: {
|
3583
3462
|
gasPerByte,
|
3584
3463
|
gasPriceFactor
|
@@ -3590,7 +3469,7 @@ function assembleTransactionSummary(params) {
|
|
3590
3469
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3591
3470
|
let date;
|
3592
3471
|
if (time) {
|
3593
|
-
date =
|
3472
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3594
3473
|
}
|
3595
3474
|
const transactionSummary = {
|
3596
3475
|
id,
|
@@ -3618,12 +3497,12 @@ function assembleTransactionSummary(params) {
|
|
3618
3497
|
|
3619
3498
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3620
3499
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3621
|
-
var
|
3500
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3622
3501
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3623
3502
|
return receipts.reduce((logs, receipt) => {
|
3624
|
-
if (receipt.type ===
|
3503
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3625
3504
|
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3626
|
-
const data = receipt.type ===
|
3505
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3627
3506
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3628
3507
|
logs.push(decodedLog);
|
3629
3508
|
}
|
@@ -3638,7 +3517,7 @@ var TransactionResponse = class {
|
|
3638
3517
|
/** Current provider */
|
3639
3518
|
provider;
|
3640
3519
|
/** Gas used on the transaction */
|
3641
|
-
gasUsed = (0,
|
3520
|
+
gasUsed = (0, import_math14.bn)(0);
|
3642
3521
|
/** The graphql Transaction with receipts object. */
|
3643
3522
|
gqlTransaction;
|
3644
3523
|
abis;
|
@@ -3696,8 +3575,8 @@ var TransactionResponse = class {
|
|
3696
3575
|
* @returns The decoded transaction.
|
3697
3576
|
*/
|
3698
3577
|
decodeTransaction(transactionWithReceipts) {
|
3699
|
-
return new
|
3700
|
-
(0,
|
3578
|
+
return new import_transactions17.TransactionCoder().decode(
|
3579
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3701
3580
|
0
|
3702
3581
|
)?.[0];
|
3703
3582
|
}
|
@@ -3716,27 +3595,20 @@ var TransactionResponse = class {
|
|
3716
3595
|
const decodedTransaction = this.decodeTransaction(
|
3717
3596
|
transaction
|
3718
3597
|
);
|
3719
|
-
|
3720
|
-
|
3721
|
-
txReceipts = transaction.status.receipts;
|
3722
|
-
}
|
3723
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3724
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3725
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3598
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3599
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3726
3600
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3727
3601
|
const transactionSummary = assembleTransactionSummary({
|
3728
3602
|
id: this.id,
|
3729
3603
|
receipts,
|
3730
3604
|
transaction: decodedTransaction,
|
3731
|
-
transactionBytes: (0,
|
3605
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3732
3606
|
gqlTransactionStatus: transaction.status,
|
3733
3607
|
gasPerByte,
|
3734
3608
|
gasPriceFactor,
|
3735
3609
|
abiMap: contractsAbiMap,
|
3736
3610
|
maxInputs,
|
3737
|
-
gasCosts
|
3738
|
-
maxGasPerTx,
|
3739
|
-
gasPrice
|
3611
|
+
gasCosts
|
3740
3612
|
});
|
3741
3613
|
return transactionSummary;
|
3742
3614
|
}
|
@@ -3863,29 +3735,29 @@ var processGqlChain = (chain) => {
|
|
3863
3735
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3864
3736
|
return {
|
3865
3737
|
name,
|
3866
|
-
baseChainHeight: (0,
|
3738
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3867
3739
|
consensusParameters: {
|
3868
|
-
contractMaxSize: (0,
|
3869
|
-
maxInputs: (0,
|
3870
|
-
maxOutputs: (0,
|
3871
|
-
maxWitnesses: (0,
|
3872
|
-
maxGasPerTx: (0,
|
3873
|
-
maxScriptLength: (0,
|
3874
|
-
maxScriptDataLength: (0,
|
3875
|
-
maxStorageSlots: (0,
|
3876
|
-
maxPredicateLength: (0,
|
3877
|
-
maxPredicateDataLength: (0,
|
3878
|
-
maxGasPerPredicate: (0,
|
3879
|
-
gasPriceFactor: (0,
|
3880
|
-
gasPerByte: (0,
|
3881
|
-
maxMessageDataLength: (0,
|
3882
|
-
chainId: (0,
|
3740
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3741
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3742
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3743
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3744
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3745
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3746
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3747
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3748
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3749
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3750
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3751
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3752
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3753
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3754
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3883
3755
|
gasCosts
|
3884
3756
|
},
|
3885
3757
|
gasCosts,
|
3886
3758
|
latestBlock: {
|
3887
3759
|
id: latestBlock.id,
|
3888
|
-
height: (0,
|
3760
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3889
3761
|
time: latestBlock.header.time,
|
3890
3762
|
transactions: latestBlock.transactions.map((i) => ({
|
3891
3763
|
id: i.id
|
@@ -3979,8 +3851,10 @@ var _Provider = class {
|
|
3979
3851
|
* Returns some helpful parameters related to gas fees.
|
3980
3852
|
*/
|
3981
3853
|
getGasConfig() {
|
3854
|
+
const { minGasPrice } = this.getNode();
|
3982
3855
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3983
3856
|
return {
|
3857
|
+
minGasPrice,
|
3984
3858
|
maxGasPerTx,
|
3985
3859
|
maxGasPerPredicate,
|
3986
3860
|
gasPriceFactor,
|
@@ -4078,7 +3952,7 @@ var _Provider = class {
|
|
4078
3952
|
*/
|
4079
3953
|
async getBlockNumber() {
|
4080
3954
|
const { chain } = await this.operations.getChain();
|
4081
|
-
return (0,
|
3955
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
4082
3956
|
}
|
4083
3957
|
/**
|
4084
3958
|
* Returns the chain information.
|
@@ -4088,11 +3962,13 @@ var _Provider = class {
|
|
4088
3962
|
async fetchNode() {
|
4089
3963
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
4090
3964
|
const processedNodeInfo = {
|
4091
|
-
maxDepth: (0,
|
4092
|
-
maxTx: (0,
|
3965
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3966
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3967
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
4093
3968
|
nodeVersion: nodeInfo.nodeVersion,
|
4094
3969
|
utxoValidation: nodeInfo.utxoValidation,
|
4095
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3970
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3971
|
+
peers: nodeInfo.peers
|
4096
3972
|
};
|
4097
3973
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
4098
3974
|
return processedNodeInfo;
|
@@ -4134,9 +4010,9 @@ var _Provider = class {
|
|
4134
4010
|
if (estimateTxDependencies) {
|
4135
4011
|
await this.estimateTxDependencies(transactionRequest);
|
4136
4012
|
}
|
4137
|
-
const encodedTransaction = (0,
|
4013
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4138
4014
|
let abis;
|
4139
|
-
if (transactionRequest.type ===
|
4015
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4140
4016
|
abis = transactionRequest.abis;
|
4141
4017
|
}
|
4142
4018
|
if (awaitExecution) {
|
@@ -4177,14 +4053,15 @@ var _Provider = class {
|
|
4177
4053
|
if (estimateTxDependencies) {
|
4178
4054
|
return this.estimateTxDependencies(transactionRequest);
|
4179
4055
|
}
|
4180
|
-
const encodedTransaction = (0,
|
4181
|
-
const { dryRun:
|
4182
|
-
|
4056
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4057
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4058
|
+
encodedTransaction,
|
4183
4059
|
utxoValidation: utxoValidation || false
|
4184
4060
|
});
|
4185
|
-
const
|
4186
|
-
|
4187
|
-
|
4061
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4062
|
+
return {
|
4063
|
+
receipts
|
4064
|
+
};
|
4188
4065
|
}
|
4189
4066
|
/**
|
4190
4067
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4195,13 +4072,13 @@ var _Provider = class {
|
|
4195
4072
|
async estimatePredicates(transactionRequest) {
|
4196
4073
|
const shouldEstimatePredicates = Boolean(
|
4197
4074
|
transactionRequest.inputs.find(
|
4198
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4075
|
+
(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()
|
4199
4076
|
)
|
4200
4077
|
);
|
4201
4078
|
if (!shouldEstimatePredicates) {
|
4202
4079
|
return transactionRequest;
|
4203
4080
|
}
|
4204
|
-
const encodedTransaction = (0,
|
4081
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4205
4082
|
const response = await this.operations.estimatePredicates({
|
4206
4083
|
encodedTransaction
|
4207
4084
|
});
|
@@ -4210,7 +4087,7 @@ var _Provider = class {
|
|
4210
4087
|
} = response;
|
4211
4088
|
if (inputs) {
|
4212
4089
|
inputs.forEach((input, index) => {
|
4213
|
-
if ("predicateGasUsed" in input && (0,
|
4090
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
4214
4091
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4215
4092
|
}
|
4216
4093
|
});
|
@@ -4223,31 +4100,31 @@ var _Provider = class {
|
|
4223
4100
|
* If there are missing variable outputs,
|
4224
4101
|
* `addVariableOutputs` is called on the transaction.
|
4225
4102
|
*
|
4103
|
+
* @privateRemarks
|
4104
|
+
* TODO: Investigate support for missing contract IDs
|
4105
|
+
* TODO: Add support for missing output messages
|
4226
4106
|
*
|
4227
4107
|
* @param transactionRequest - The transaction request object.
|
4228
4108
|
* @returns A promise.
|
4229
4109
|
*/
|
4230
4110
|
async estimateTxDependencies(transactionRequest) {
|
4231
|
-
if (transactionRequest.type ===
|
4111
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
4232
4112
|
return {
|
4233
4113
|
receipts: [],
|
4234
4114
|
outputVariables: 0,
|
4235
4115
|
missingContractIds: []
|
4236
4116
|
};
|
4237
4117
|
}
|
4118
|
+
await this.estimatePredicates(transactionRequest);
|
4238
4119
|
let receipts = [];
|
4239
4120
|
const missingContractIds = [];
|
4240
4121
|
let outputVariables = 0;
|
4241
|
-
let dryrunStatus;
|
4242
4122
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4243
|
-
const {
|
4244
|
-
|
4245
|
-
} = await this.operations.dryRun({
|
4246
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4123
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4124
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
4247
4125
|
utxoValidation: false
|
4248
4126
|
});
|
4249
|
-
receipts =
|
4250
|
-
dryrunStatus = status;
|
4127
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
4251
4128
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4252
4129
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4253
4130
|
if (hasMissingOutputs) {
|
@@ -4257,10 +4134,6 @@ var _Provider = class {
|
|
4257
4134
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4258
4135
|
missingContractIds.push(contractId);
|
4259
4136
|
});
|
4260
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4261
|
-
transactionRequest
|
4262
|
-
});
|
4263
|
-
transactionRequest.maxFee = maxFee;
|
4264
4137
|
} else {
|
4265
4138
|
break;
|
4266
4139
|
}
|
@@ -4268,139 +4141,37 @@ var _Provider = class {
|
|
4268
4141
|
return {
|
4269
4142
|
receipts,
|
4270
4143
|
outputVariables,
|
4271
|
-
missingContractIds
|
4272
|
-
dryrunStatus
|
4144
|
+
missingContractIds
|
4273
4145
|
};
|
4274
4146
|
}
|
4275
|
-
/**
|
4276
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4277
|
-
*
|
4278
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4279
|
-
* further modifications are identified. The method iteratively updates these transactions
|
4280
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4281
|
-
*
|
4282
|
-
* @param transactionRequests - Array of transaction request objects.
|
4283
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4284
|
-
*/
|
4285
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4286
|
-
const results = transactionRequests.map(() => ({
|
4287
|
-
receipts: [],
|
4288
|
-
outputVariables: 0,
|
4289
|
-
missingContractIds: [],
|
4290
|
-
dryrunStatus: void 0
|
4291
|
-
}));
|
4292
|
-
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4293
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4294
|
-
allRequests.forEach((req, index) => {
|
4295
|
-
if (req.type === import_transactions19.TransactionType.Script) {
|
4296
|
-
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4297
|
-
}
|
4298
|
-
});
|
4299
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4300
|
-
let attempt = 0;
|
4301
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4302
|
-
const encodedTransactions = transactionsToProcess.map(
|
4303
|
-
(index) => serializedTransactionsMap.get(index)
|
4304
|
-
);
|
4305
|
-
const dryRunResults = await this.operations.dryRun({
|
4306
|
-
encodedTransactions,
|
4307
|
-
utxoValidation: false
|
4308
|
-
});
|
4309
|
-
const nextRoundTransactions = [];
|
4310
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4311
|
-
const currentResultIndex = transactionsToProcess[i];
|
4312
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4313
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4314
|
-
results[currentResultIndex].dryrunStatus = status;
|
4315
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4316
|
-
results[currentResultIndex].receipts
|
4317
|
-
);
|
4318
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4319
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4320
|
-
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4321
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4322
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4323
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4324
|
-
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4325
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4326
|
-
});
|
4327
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4328
|
-
transactionRequest: requestToProcess
|
4329
|
-
});
|
4330
|
-
requestToProcess.maxFee = maxFee;
|
4331
|
-
serializedTransactionsMap.set(
|
4332
|
-
currentResultIndex,
|
4333
|
-
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4334
|
-
);
|
4335
|
-
nextRoundTransactions.push(currentResultIndex);
|
4336
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4337
|
-
}
|
4338
|
-
}
|
4339
|
-
transactionsToProcess = nextRoundTransactions;
|
4340
|
-
attempt += 1;
|
4341
|
-
}
|
4342
|
-
return results;
|
4343
|
-
}
|
4344
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4345
|
-
if (estimateTxDependencies) {
|
4346
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4347
|
-
}
|
4348
|
-
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4349
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4350
|
-
encodedTransactions,
|
4351
|
-
utxoValidation: utxoValidation || false
|
4352
|
-
});
|
4353
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4354
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4355
|
-
return { receipts, dryrunStatus: status };
|
4356
|
-
});
|
4357
|
-
return results;
|
4358
|
-
}
|
4359
4147
|
/**
|
4360
4148
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4361
4149
|
* @param transactionRequest - The transaction request object.
|
4362
4150
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4363
4151
|
*/
|
4364
|
-
|
4152
|
+
estimateTxGasAndFee(params) {
|
4365
4153
|
const { transactionRequest } = params;
|
4366
|
-
|
4154
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4367
4155
|
const chainInfo = this.getChain();
|
4368
|
-
const
|
4156
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
4157
|
+
transactionRequest.gasPrice = gasPrice;
|
4369
4158
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4370
|
-
|
4371
|
-
|
4372
|
-
}
|
4373
|
-
const minFee = calculateGasFee({
|
4374
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4375
|
-
gas: minGas,
|
4376
|
-
priceFactor: gasPriceFactor,
|
4377
|
-
tip: transactionRequest.tip
|
4378
|
-
}).add(1);
|
4379
|
-
let gasLimit = (0, import_math16.bn)(0);
|
4380
|
-
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4381
|
-
gasLimit = transactionRequest.gasLimit;
|
4159
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4160
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4382
4161
|
if (transactionRequest.gasLimit.eq(0)) {
|
4383
4162
|
transactionRequest.gasLimit = minGas;
|
4384
4163
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4385
4164
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4386
4165
|
);
|
4387
|
-
gasLimit = transactionRequest.gasLimit;
|
4388
4166
|
}
|
4389
4167
|
}
|
4390
4168
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4391
|
-
const maxFee =
|
4392
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4393
|
-
gas: maxGas,
|
4394
|
-
priceFactor: gasPriceFactor,
|
4395
|
-
tip: transactionRequest.tip
|
4396
|
-
}).add(1);
|
4169
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4397
4170
|
return {
|
4398
4171
|
minGas,
|
4399
4172
|
minFee,
|
4400
4173
|
maxGas,
|
4401
|
-
maxFee
|
4402
|
-
gasPrice,
|
4403
|
-
gasLimit
|
4174
|
+
maxFee
|
4404
4175
|
};
|
4405
4176
|
}
|
4406
4177
|
/**
|
@@ -4418,17 +4189,15 @@ var _Provider = class {
|
|
4418
4189
|
if (estimateTxDependencies) {
|
4419
4190
|
return this.estimateTxDependencies(transactionRequest);
|
4420
4191
|
}
|
4421
|
-
const
|
4422
|
-
const { dryRun:
|
4423
|
-
|
4192
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4193
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4194
|
+
encodedTransaction,
|
4424
4195
|
utxoValidation: true
|
4425
4196
|
});
|
4426
|
-
const
|
4427
|
-
|
4428
|
-
|
4429
|
-
|
4430
|
-
});
|
4431
|
-
return { receipts: callResult[0].receipts };
|
4197
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4198
|
+
return {
|
4199
|
+
receipts
|
4200
|
+
};
|
4432
4201
|
}
|
4433
4202
|
/**
|
4434
4203
|
* Returns a transaction cost to enable user
|
@@ -4445,79 +4214,77 @@ var _Provider = class {
|
|
4445
4214
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4446
4215
|
* @returns A promise that resolves to the transaction cost object.
|
4447
4216
|
*/
|
4448
|
-
async getTransactionCost(transactionRequestLike,
|
4217
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
4218
|
+
estimateTxDependencies = true,
|
4219
|
+
estimatePredicates = true,
|
4220
|
+
resourcesOwner,
|
4221
|
+
signatureCallback
|
4222
|
+
} = {}) {
|
4449
4223
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4450
|
-
const
|
4224
|
+
const { minGasPrice } = this.getGasConfig();
|
4225
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4226
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4451
4227
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4452
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4228
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4453
4229
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4454
|
-
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4455
4230
|
if (isScriptTransaction) {
|
4456
|
-
txRequestClone.gasLimit = (0,
|
4231
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4457
4232
|
}
|
4458
|
-
if (
|
4459
|
-
resourcesOwner
|
4233
|
+
if (estimatePredicates) {
|
4234
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4235
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4236
|
+
}
|
4237
|
+
await this.estimatePredicates(txRequestClone);
|
4460
4238
|
}
|
4461
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4462
|
-
let addedSignatures = 0;
|
4463
4239
|
if (signatureCallback && isScriptTransaction) {
|
4464
|
-
|
4465
|
-
await signatureCallback(signedRequest);
|
4466
|
-
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4240
|
+
await signatureCallback(txRequestClone);
|
4467
4241
|
}
|
4468
|
-
|
4469
|
-
|
4470
|
-
transactionRequest: signedRequest
|
4242
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4243
|
+
transactionRequest: txRequestClone
|
4471
4244
|
});
|
4472
4245
|
let receipts = [];
|
4473
4246
|
let missingContractIds = [];
|
4474
4247
|
let outputVariables = 0;
|
4475
|
-
let gasUsed = (0,
|
4476
|
-
|
4477
|
-
|
4478
|
-
if (isScriptTransaction) {
|
4479
|
-
txRequestClone.gasLimit = gasLimit;
|
4480
|
-
if (signatureCallback) {
|
4481
|
-
await signatureCallback(txRequestClone);
|
4482
|
-
}
|
4248
|
+
let gasUsed = (0, import_math15.bn)(0);
|
4249
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4250
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4483
4251
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4484
4252
|
receipts = result.receipts;
|
4485
4253
|
outputVariables = result.outputVariables;
|
4486
4254
|
missingContractIds = result.missingContractIds;
|
4487
4255
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4488
4256
|
txRequestClone.gasLimit = gasUsed;
|
4489
|
-
|
4490
|
-
|
4491
|
-
|
4257
|
+
txRequestClone.gasPrice = setGasPrice;
|
4258
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4259
|
+
transactionRequest: txRequestClone
|
4492
4260
|
}));
|
4493
4261
|
}
|
4494
4262
|
return {
|
4495
4263
|
requiredQuantities: allQuantities,
|
4496
4264
|
receipts,
|
4497
4265
|
gasUsed,
|
4498
|
-
|
4266
|
+
minGasPrice,
|
4267
|
+
gasPrice: setGasPrice,
|
4499
4268
|
minGas,
|
4500
4269
|
maxGas,
|
4501
4270
|
minFee,
|
4502
4271
|
maxFee,
|
4272
|
+
estimatedInputs: txRequestClone.inputs,
|
4503
4273
|
outputVariables,
|
4504
|
-
missingContractIds
|
4505
|
-
addedSignatures,
|
4506
|
-
estimatedPredicates: txRequestClone.inputs
|
4274
|
+
missingContractIds
|
4507
4275
|
};
|
4508
4276
|
}
|
4509
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4277
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4510
4278
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4511
4279
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4512
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4513
|
-
quantitiesToContract
|
4514
|
-
});
|
4280
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4515
4281
|
transactionRequest.addResources(
|
4516
4282
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4517
4283
|
);
|
4518
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4519
|
-
|
4520
|
-
|
4284
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4285
|
+
transactionRequest,
|
4286
|
+
forwardingQuantities
|
4287
|
+
);
|
4521
4288
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4522
4289
|
return {
|
4523
4290
|
resources,
|
@@ -4533,16 +4300,17 @@ var _Provider = class {
|
|
4533
4300
|
const result = await this.operations.getCoins({
|
4534
4301
|
first: 10,
|
4535
4302
|
...paginationArgs,
|
4536
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4303
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4537
4304
|
});
|
4538
4305
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4539
4306
|
return coins.map((coin) => ({
|
4540
4307
|
id: coin.utxoId,
|
4541
4308
|
assetId: coin.assetId,
|
4542
|
-
amount: (0,
|
4309
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4543
4310
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4544
|
-
|
4545
|
-
|
4311
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4312
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4313
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4546
4314
|
}));
|
4547
4315
|
}
|
4548
4316
|
/**
|
@@ -4556,19 +4324,19 @@ var _Provider = class {
|
|
4556
4324
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4557
4325
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4558
4326
|
const excludeInput = {
|
4559
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4560
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4327
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4328
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4561
4329
|
};
|
4562
4330
|
if (this.cache) {
|
4563
4331
|
const uniqueUtxos = new Set(
|
4564
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4332
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4565
4333
|
);
|
4566
4334
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4567
4335
|
}
|
4568
4336
|
const coinsQuery = {
|
4569
4337
|
owner: ownerAddress.toB256(),
|
4570
4338
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4571
|
-
assetId: (0,
|
4339
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4572
4340
|
amount: amount.toString(10),
|
4573
4341
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4574
4342
|
})),
|
@@ -4579,9 +4347,9 @@ var _Provider = class {
|
|
4579
4347
|
switch (coin.__typename) {
|
4580
4348
|
case "MessageCoin":
|
4581
4349
|
return {
|
4582
|
-
amount: (0,
|
4350
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4583
4351
|
assetId: coin.assetId,
|
4584
|
-
daHeight: (0,
|
4352
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4585
4353
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4586
4354
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4587
4355
|
nonce: coin.nonce
|
@@ -4589,11 +4357,12 @@ var _Provider = class {
|
|
4589
4357
|
case "Coin":
|
4590
4358
|
return {
|
4591
4359
|
id: coin.utxoId,
|
4592
|
-
amount: (0,
|
4360
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4593
4361
|
assetId: coin.assetId,
|
4594
4362
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4595
|
-
|
4596
|
-
|
4363
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4364
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4365
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4597
4366
|
};
|
4598
4367
|
default:
|
4599
4368
|
return null;
|
@@ -4610,13 +4379,13 @@ var _Provider = class {
|
|
4610
4379
|
async getBlock(idOrHeight) {
|
4611
4380
|
let variables;
|
4612
4381
|
if (typeof idOrHeight === "number") {
|
4613
|
-
variables = { height: (0,
|
4382
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4614
4383
|
} else if (idOrHeight === "latest") {
|
4615
4384
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4616
4385
|
} else if (idOrHeight.length === 66) {
|
4617
4386
|
variables = { blockId: idOrHeight };
|
4618
4387
|
} else {
|
4619
|
-
variables = { blockId: (0,
|
4388
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4620
4389
|
}
|
4621
4390
|
const { block } = await this.operations.getBlock(variables);
|
4622
4391
|
if (!block) {
|
@@ -4624,7 +4393,7 @@ var _Provider = class {
|
|
4624
4393
|
}
|
4625
4394
|
return {
|
4626
4395
|
id: block.id,
|
4627
|
-
height: (0,
|
4396
|
+
height: (0, import_math15.bn)(block.header.height),
|
4628
4397
|
time: block.header.time,
|
4629
4398
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4630
4399
|
};
|
@@ -4639,7 +4408,7 @@ var _Provider = class {
|
|
4639
4408
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4640
4409
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4641
4410
|
id: block.id,
|
4642
|
-
height: (0,
|
4411
|
+
height: (0, import_math15.bn)(block.header.height),
|
4643
4412
|
time: block.header.time,
|
4644
4413
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4645
4414
|
}));
|
@@ -4654,7 +4423,7 @@ var _Provider = class {
|
|
4654
4423
|
async getBlockWithTransactions(idOrHeight) {
|
4655
4424
|
let variables;
|
4656
4425
|
if (typeof idOrHeight === "number") {
|
4657
|
-
variables = { blockHeight: (0,
|
4426
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4658
4427
|
} else if (idOrHeight === "latest") {
|
4659
4428
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4660
4429
|
} else {
|
@@ -4666,11 +4435,11 @@ var _Provider = class {
|
|
4666
4435
|
}
|
4667
4436
|
return {
|
4668
4437
|
id: block.id,
|
4669
|
-
height: (0,
|
4438
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4670
4439
|
time: block.header.time,
|
4671
4440
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4672
4441
|
transactions: block.transactions.map(
|
4673
|
-
(tx) => new
|
4442
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4674
4443
|
)
|
4675
4444
|
};
|
4676
4445
|
}
|
@@ -4685,8 +4454,8 @@ var _Provider = class {
|
|
4685
4454
|
if (!transaction) {
|
4686
4455
|
return null;
|
4687
4456
|
}
|
4688
|
-
return new
|
4689
|
-
(0,
|
4457
|
+
return new import_transactions18.TransactionCoder().decode(
|
4458
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4690
4459
|
0
|
4691
4460
|
)?.[0];
|
4692
4461
|
}
|
@@ -4713,9 +4482,9 @@ var _Provider = class {
|
|
4713
4482
|
async getContractBalance(contractId, assetId) {
|
4714
4483
|
const { contractBalance } = await this.operations.getContractBalance({
|
4715
4484
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4716
|
-
asset: (0,
|
4485
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4717
4486
|
});
|
4718
|
-
return (0,
|
4487
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4719
4488
|
}
|
4720
4489
|
/**
|
4721
4490
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4727,9 +4496,9 @@ var _Provider = class {
|
|
4727
4496
|
async getBalance(owner, assetId) {
|
4728
4497
|
const { balance } = await this.operations.getBalance({
|
4729
4498
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4730
|
-
assetId: (0,
|
4499
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4731
4500
|
});
|
4732
|
-
return (0,
|
4501
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4733
4502
|
}
|
4734
4503
|
/**
|
4735
4504
|
* Returns balances for the given owner.
|
@@ -4747,7 +4516,7 @@ var _Provider = class {
|
|
4747
4516
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4748
4517
|
return balances.map((balance) => ({
|
4749
4518
|
assetId: balance.assetId,
|
4750
|
-
amount: (0,
|
4519
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4751
4520
|
}));
|
4752
4521
|
}
|
4753
4522
|
/**
|
@@ -4765,19 +4534,19 @@ var _Provider = class {
|
|
4765
4534
|
});
|
4766
4535
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4767
4536
|
return messages.map((message) => ({
|
4768
|
-
messageId:
|
4537
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4769
4538
|
sender: message.sender,
|
4770
4539
|
recipient: message.recipient,
|
4771
4540
|
nonce: message.nonce,
|
4772
|
-
amount: (0,
|
4541
|
+
amount: (0, import_math15.bn)(message.amount),
|
4773
4542
|
data: message.data
|
4774
4543
|
}),
|
4775
4544
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4776
4545
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4777
4546
|
nonce: message.nonce,
|
4778
|
-
amount: (0,
|
4779
|
-
data:
|
4780
|
-
daHeight: (0,
|
4547
|
+
amount: (0, import_math15.bn)(message.amount),
|
4548
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4549
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4781
4550
|
}));
|
4782
4551
|
}
|
4783
4552
|
/**
|
@@ -4830,60 +4599,44 @@ var _Provider = class {
|
|
4830
4599
|
} = result.messageProof;
|
4831
4600
|
return {
|
4832
4601
|
messageProof: {
|
4833
|
-
proofIndex: (0,
|
4602
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4834
4603
|
proofSet: messageProof.proofSet
|
4835
4604
|
},
|
4836
4605
|
blockProof: {
|
4837
|
-
proofIndex: (0,
|
4606
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4838
4607
|
proofSet: blockProof.proofSet
|
4839
4608
|
},
|
4840
4609
|
messageBlockHeader: {
|
4841
4610
|
id: messageBlockHeader.id,
|
4842
|
-
daHeight: (0,
|
4843
|
-
transactionsCount: (0,
|
4611
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4612
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4844
4613
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4845
|
-
height: (0,
|
4614
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4846
4615
|
prevRoot: messageBlockHeader.prevRoot,
|
4847
4616
|
time: messageBlockHeader.time,
|
4848
4617
|
applicationHash: messageBlockHeader.applicationHash,
|
4849
|
-
|
4850
|
-
|
4851
|
-
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4852
|
-
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4853
|
-
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4618
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4619
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4854
4620
|
},
|
4855
4621
|
commitBlockHeader: {
|
4856
4622
|
id: commitBlockHeader.id,
|
4857
|
-
daHeight: (0,
|
4858
|
-
transactionsCount: (0,
|
4623
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4624
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4859
4625
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4860
|
-
height: (0,
|
4626
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4861
4627
|
prevRoot: commitBlockHeader.prevRoot,
|
4862
4628
|
time: commitBlockHeader.time,
|
4863
4629
|
applicationHash: commitBlockHeader.applicationHash,
|
4864
|
-
|
4865
|
-
|
4866
|
-
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4867
|
-
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4868
|
-
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4630
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4631
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4869
4632
|
},
|
4870
4633
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4871
4634
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4872
4635
|
nonce,
|
4873
|
-
amount: (0,
|
4636
|
+
amount: (0, import_math15.bn)(amount),
|
4874
4637
|
data
|
4875
4638
|
};
|
4876
4639
|
}
|
4877
|
-
async getLatestGasPrice() {
|
4878
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4879
|
-
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4880
|
-
}
|
4881
|
-
async estimateGasPrice(blockHorizon) {
|
4882
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4883
|
-
blockHorizon: String(blockHorizon)
|
4884
|
-
});
|
4885
|
-
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4886
|
-
}
|
4887
4640
|
/**
|
4888
4641
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4889
4642
|
*
|
@@ -4903,10 +4656,10 @@ var _Provider = class {
|
|
4903
4656
|
*/
|
4904
4657
|
async produceBlocks(amount, startTime) {
|
4905
4658
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4906
|
-
blocksToProduce: (0,
|
4907
|
-
startTimestamp: startTime ?
|
4659
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4660
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4908
4661
|
});
|
4909
|
-
return (0,
|
4662
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4910
4663
|
}
|
4911
4664
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4912
4665
|
async getTransactionResponse(transactionId) {
|
@@ -4920,7 +4673,7 @@ cacheInputs_fn = function(inputs) {
|
|
4920
4673
|
return;
|
4921
4674
|
}
|
4922
4675
|
inputs.forEach((input) => {
|
4923
|
-
if (input.type ===
|
4676
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4924
4677
|
this.cache?.set(input.id);
|
4925
4678
|
}
|
4926
4679
|
});
|
@@ -4930,9 +4683,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4930
4683
|
|
4931
4684
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4932
4685
|
var import_errors15 = require("@fuel-ts/errors");
|
4933
|
-
var
|
4934
|
-
var
|
4935
|
-
var
|
4686
|
+
var import_math16 = require("@fuel-ts/math");
|
4687
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4688
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4936
4689
|
async function getTransactionSummary(params) {
|
4937
4690
|
const { id, provider, abiMap } = params;
|
4938
4691
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -4944,32 +4697,25 @@ async function getTransactionSummary(params) {
|
|
4944
4697
|
`Transaction not found for given id: ${id}.`
|
4945
4698
|
);
|
4946
4699
|
}
|
4947
|
-
const [decodedTransaction] = new
|
4948
|
-
(0,
|
4700
|
+
const [decodedTransaction] = new import_transactions19.TransactionCoder().decode(
|
4701
|
+
(0, import_utils26.arrayify)(gqlTransaction.rawPayload),
|
4949
4702
|
0
|
4950
4703
|
);
|
4951
|
-
|
4952
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4953
|
-
txReceipts = gqlTransaction.status.receipts;
|
4954
|
-
}
|
4955
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4704
|
+
const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
|
4956
4705
|
const {
|
4957
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4706
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4958
4707
|
} = provider.getChain();
|
4959
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4960
4708
|
const transactionInfo = assembleTransactionSummary({
|
4961
4709
|
id: gqlTransaction.id,
|
4962
4710
|
receipts,
|
4963
4711
|
transaction: decodedTransaction,
|
4964
|
-
transactionBytes: (0,
|
4712
|
+
transactionBytes: (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
|
4965
4713
|
gqlTransactionStatus: gqlTransaction.status,
|
4966
|
-
gasPerByte: (0,
|
4967
|
-
gasPriceFactor: (0,
|
4714
|
+
gasPerByte: (0, import_math16.bn)(gasPerByte),
|
4715
|
+
gasPriceFactor: (0, import_math16.bn)(gasPriceFactor),
|
4968
4716
|
abiMap,
|
4969
4717
|
maxInputs,
|
4970
|
-
gasCosts
|
4971
|
-
maxGasPerTx,
|
4972
|
-
gasPrice
|
4718
|
+
gasCosts
|
4973
4719
|
});
|
4974
4720
|
return {
|
4975
4721
|
gqlTransaction,
|
@@ -4979,11 +4725,10 @@ async function getTransactionSummary(params) {
|
|
4979
4725
|
async function getTransactionSummaryFromRequest(params) {
|
4980
4726
|
const { provider, transactionRequest, abiMap } = params;
|
4981
4727
|
const { receipts } = await provider.call(transactionRequest);
|
4982
|
-
const { gasPerByte, gasPriceFactor, gasCosts
|
4728
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4983
4729
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4984
4730
|
const transaction = transactionRequest.toTransaction();
|
4985
4731
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4986
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4987
4732
|
const transactionSummary = assembleTransactionSummary({
|
4988
4733
|
receipts,
|
4989
4734
|
transaction,
|
@@ -4992,9 +4737,7 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4992
4737
|
gasPerByte,
|
4993
4738
|
gasPriceFactor,
|
4994
4739
|
maxInputs,
|
4995
|
-
gasCosts
|
4996
|
-
maxGasPerTx,
|
4997
|
-
gasPrice
|
4740
|
+
gasCosts
|
4998
4741
|
});
|
4999
4742
|
return transactionSummary;
|
5000
4743
|
}
|
@@ -5003,31 +4746,24 @@ async function getTransactionsSummaries(params) {
|
|
5003
4746
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
5004
4747
|
const { edges, pageInfo } = transactionsByOwner;
|
5005
4748
|
const {
|
5006
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4749
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
5007
4750
|
} = provider.getChain();
|
5008
|
-
const gasPrice = await provider.getLatestGasPrice();
|
5009
4751
|
const transactions = edges.map((edge) => {
|
5010
4752
|
const { node: gqlTransaction } = edge;
|
5011
|
-
const { id, rawPayload, status } = gqlTransaction;
|
5012
|
-
const [decodedTransaction] = new
|
5013
|
-
|
5014
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
5015
|
-
txReceipts = gqlTransaction.status.receipts;
|
5016
|
-
}
|
5017
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4753
|
+
const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
|
4754
|
+
const [decodedTransaction] = new import_transactions19.TransactionCoder().decode((0, import_utils26.arrayify)(rawPayload), 0);
|
4755
|
+
const receipts = gqlReceipts?.map(processGqlReceipt) || [];
|
5018
4756
|
const transactionSummary = assembleTransactionSummary({
|
5019
4757
|
id,
|
5020
4758
|
receipts,
|
5021
4759
|
transaction: decodedTransaction,
|
5022
|
-
transactionBytes: (0,
|
4760
|
+
transactionBytes: (0, import_utils26.arrayify)(rawPayload),
|
5023
4761
|
gqlTransactionStatus: status,
|
5024
4762
|
abiMap,
|
5025
4763
|
gasPerByte,
|
5026
4764
|
gasPriceFactor,
|
5027
4765
|
maxInputs,
|
5028
|
-
gasCosts
|
5029
|
-
maxGasPerTx,
|
5030
|
-
gasPrice
|
4766
|
+
gasCosts
|
5031
4767
|
});
|
5032
4768
|
const output = {
|
5033
4769
|
gqlTransaction,
|
@@ -5164,17 +4900,17 @@ var assets = [
|
|
5164
4900
|
|
5165
4901
|
// src/utils/formatTransferToContractScriptData.ts
|
5166
4902
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
5167
|
-
var
|
5168
|
-
var
|
4903
|
+
var import_math17 = require("@fuel-ts/math");
|
4904
|
+
var import_utils27 = require("@fuel-ts/utils");
|
5169
4905
|
var asm = __toESM(require("@fuels/vm-asm"));
|
5170
4906
|
var formatTransferToContractScriptData = (params) => {
|
5171
4907
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
5172
4908
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
5173
|
-
const encoded = numberCoder.encode(new
|
4909
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
5174
4910
|
const scriptData = Uint8Array.from([
|
5175
|
-
...(0,
|
4911
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
5176
4912
|
...encoded,
|
5177
|
-
...(0,
|
4913
|
+
...(0, import_utils27.arrayify)(assetId)
|
5178
4914
|
]);
|
5179
4915
|
return scriptData;
|
5180
4916
|
};
|
@@ -5359,33 +5095,36 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5359
5095
|
* @param fee - The estimated transaction fee.
|
5360
5096
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5361
5097
|
*/
|
5362
|
-
async fund(request,
|
5363
|
-
const
|
5364
|
-
|
5365
|
-
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5366
|
-
amount: (0, import_math19.bn)(fee),
|
5098
|
+
async fund(request, coinQuantities, fee) {
|
5099
|
+
const updatedQuantities = addAmountToAsset({
|
5100
|
+
amount: (0, import_math18.bn)(fee),
|
5367
5101
|
assetId: import_configs12.BaseAssetId,
|
5368
|
-
coinQuantities
|
5102
|
+
coinQuantities
|
5369
5103
|
});
|
5370
5104
|
const quantitiesDict = {};
|
5371
|
-
|
5105
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
5372
5106
|
quantitiesDict[assetId] = {
|
5373
5107
|
required: amount,
|
5374
|
-
owned: (0,
|
5108
|
+
owned: (0, import_math18.bn)(0)
|
5375
5109
|
};
|
5376
5110
|
});
|
5377
|
-
|
5111
|
+
const cachedUtxos = [];
|
5112
|
+
const cachedMessages = [];
|
5113
|
+
const owner = this.address.toB256();
|
5114
|
+
request.inputs.forEach((input) => {
|
5378
5115
|
const isResource = "amount" in input;
|
5379
5116
|
if (isResource) {
|
5380
5117
|
const isCoin2 = "owner" in input;
|
5381
5118
|
if (isCoin2) {
|
5382
5119
|
const assetId = String(input.assetId);
|
5383
|
-
if (quantitiesDict[assetId]) {
|
5384
|
-
const amount = (0,
|
5120
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
5121
|
+
const amount = (0, import_math18.bn)(input.amount);
|
5385
5122
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5123
|
+
cachedUtxos.push(input.id);
|
5386
5124
|
}
|
5387
|
-
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5125
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5388
5126
|
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
5127
|
+
cachedMessages.push(input.nonce);
|
5389
5128
|
}
|
5390
5129
|
}
|
5391
5130
|
});
|
@@ -5400,23 +5139,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5400
5139
|
});
|
5401
5140
|
const needsToBeFunded = missingQuantities.length;
|
5402
5141
|
if (needsToBeFunded) {
|
5403
|
-
const
|
5404
|
-
|
5405
|
-
|
5406
|
-
|
5407
|
-
|
5408
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5409
|
-
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
5410
|
-
if (addedSignatures) {
|
5411
|
-
Array.from({ length: addedSignatures }).forEach(
|
5412
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
5413
|
-
);
|
5142
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
5143
|
+
messages: cachedMessages,
|
5144
|
+
utxos: cachedUtxos
|
5145
|
+
});
|
5146
|
+
request.addResources(resources);
|
5414
5147
|
}
|
5415
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5416
|
-
transactionRequest: requestToBeReEstimate
|
5417
|
-
});
|
5418
|
-
txRequest.maxFee = maxFee;
|
5419
|
-
return txRequest;
|
5420
5148
|
}
|
5421
5149
|
/**
|
5422
5150
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5424,24 +5152,28 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5424
5152
|
* @param destination - The address of the destination.
|
5425
5153
|
* @param amount - The amount of coins to transfer.
|
5426
5154
|
* @param assetId - The asset ID of the coins to transfer.
|
5427
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5155
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5428
5156
|
* @returns A promise that resolves to the prepared transaction request.
|
5429
5157
|
*/
|
5430
5158
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5431
|
-
const
|
5159
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5160
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5161
|
+
const request = new ScriptTransactionRequest(params);
|
5432
5162
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
5433
|
-
const
|
5163
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5434
5164
|
estimateTxDependencies: true,
|
5435
5165
|
resourcesOwner: this
|
5436
5166
|
});
|
5437
|
-
|
5438
|
-
|
5439
|
-
|
5440
|
-
|
5167
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
5168
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
5169
|
+
this.validateGas({
|
5170
|
+
gasUsed,
|
5171
|
+
gasPrice: request.gasPrice,
|
5172
|
+
gasLimit: request.gasLimit,
|
5173
|
+
minGasPrice
|
5441
5174
|
});
|
5442
|
-
request
|
5443
|
-
request.
|
5444
|
-
await this.fund(request, txCost);
|
5175
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5176
|
+
request.updatePredicateInputs(estimatedInputs);
|
5445
5177
|
return request;
|
5446
5178
|
}
|
5447
5179
|
/**
|
@@ -5454,7 +5186,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5454
5186
|
* @returns A promise that resolves to the transaction response.
|
5455
5187
|
*/
|
5456
5188
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5457
|
-
if ((0,
|
5189
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5458
5190
|
throw new import_errors16.FuelError(
|
5459
5191
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5460
5192
|
"Transfer amount must be a positive number."
|
@@ -5473,36 +5205,38 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5473
5205
|
* @returns A promise that resolves to the transaction response.
|
5474
5206
|
*/
|
5475
5207
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5476
|
-
if ((0,
|
5208
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5477
5209
|
throw new import_errors16.FuelError(
|
5478
5210
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5479
5211
|
"Transfer amount must be a positive number."
|
5480
5212
|
);
|
5481
5213
|
}
|
5482
5214
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5215
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5216
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5483
5217
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5484
5218
|
hexlifiedContractId: contractAddress.toB256(),
|
5485
|
-
amountToTransfer: (0,
|
5219
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
5486
5220
|
assetId
|
5487
5221
|
});
|
5488
5222
|
const request = new ScriptTransactionRequest({
|
5489
|
-
...
|
5223
|
+
...params,
|
5490
5224
|
script,
|
5491
5225
|
scriptData
|
5492
5226
|
});
|
5493
5227
|
request.addContractInputAndOutput(contractAddress);
|
5494
|
-
const
|
5495
|
-
|
5496
|
-
|
5497
|
-
|
5498
|
-
|
5499
|
-
|
5500
|
-
|
5501
|
-
|
5228
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5229
|
+
request,
|
5230
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
5231
|
+
);
|
5232
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5233
|
+
this.validateGas({
|
5234
|
+
gasUsed,
|
5235
|
+
gasPrice: request.gasPrice,
|
5236
|
+
gasLimit: request.gasLimit,
|
5237
|
+
minGasPrice
|
5502
5238
|
});
|
5503
|
-
request
|
5504
|
-
request.maxFee = txCost.maxFee;
|
5505
|
-
await this.fund(request, txCost);
|
5239
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5506
5240
|
return this.sendTransaction(request);
|
5507
5241
|
}
|
5508
5242
|
/**
|
@@ -5514,30 +5248,34 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5514
5248
|
* @returns A promise that resolves to the transaction response.
|
5515
5249
|
*/
|
5516
5250
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5251
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5517
5252
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5518
|
-
const recipientDataArray = (0,
|
5253
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5519
5254
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5520
5255
|
);
|
5521
|
-
const amountDataArray = (0,
|
5522
|
-
"0x".concat((0,
|
5256
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
5257
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5523
5258
|
);
|
5524
5259
|
const script = new Uint8Array([
|
5525
|
-
...(0,
|
5260
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5526
5261
|
...recipientDataArray,
|
5527
5262
|
...amountDataArray
|
5528
5263
|
]);
|
5529
|
-
const params = { script, ...txParams };
|
5264
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5530
5265
|
const request = new ScriptTransactionRequest(params);
|
5531
|
-
const
|
5532
|
-
const
|
5533
|
-
|
5534
|
-
|
5535
|
-
|
5536
|
-
|
5266
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5267
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5268
|
+
request,
|
5269
|
+
forwardingQuantities
|
5270
|
+
);
|
5271
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5272
|
+
this.validateGas({
|
5273
|
+
gasUsed,
|
5274
|
+
gasPrice: request.gasPrice,
|
5275
|
+
gasLimit: request.gasLimit,
|
5276
|
+
minGasPrice
|
5537
5277
|
});
|
5538
|
-
request
|
5539
|
-
request.gasLimit = txCost.gasUsed;
|
5540
|
-
await this.fund(request, txCost);
|
5278
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5541
5279
|
return this.sendTransaction(request);
|
5542
5280
|
}
|
5543
5281
|
async signMessage(message) {
|
@@ -5595,21 +5333,22 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5595
5333
|
}
|
5596
5334
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5597
5335
|
}
|
5598
|
-
|
5599
|
-
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
|
5336
|
+
validateGas({
|
5600
5337
|
gasUsed,
|
5601
|
-
|
5338
|
+
gasPrice,
|
5339
|
+
gasLimit,
|
5340
|
+
minGasPrice
|
5602
5341
|
}) {
|
5603
|
-
if (
|
5342
|
+
if (minGasPrice.gt(gasPrice)) {
|
5604
5343
|
throw new import_errors16.FuelError(
|
5605
|
-
import_errors16.ErrorCode.
|
5606
|
-
`Gas
|
5344
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
5345
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5607
5346
|
);
|
5608
5347
|
}
|
5609
|
-
if (
|
5348
|
+
if (gasUsed.gt(gasLimit)) {
|
5610
5349
|
throw new import_errors16.FuelError(
|
5611
|
-
import_errors16.ErrorCode.
|
5612
|
-
`
|
5350
|
+
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
5351
|
+
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5613
5352
|
);
|
5614
5353
|
}
|
5615
5354
|
}
|
@@ -5617,14 +5356,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5617
5356
|
|
5618
5357
|
// src/wallet/base-wallet-unlocked.ts
|
5619
5358
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5620
|
-
var
|
5359
|
+
var import_utils31 = require("@fuel-ts/utils");
|
5621
5360
|
|
5622
5361
|
// src/signer/signer.ts
|
5623
5362
|
var import_address5 = require("@fuel-ts/address");
|
5624
5363
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5625
5364
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5626
|
-
var
|
5627
|
-
var
|
5365
|
+
var import_math19 = require("@fuel-ts/math");
|
5366
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5628
5367
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5629
5368
|
var Signer = class {
|
5630
5369
|
address;
|
@@ -5643,10 +5382,10 @@ var Signer = class {
|
|
5643
5382
|
privateKey = `0x${privateKey}`;
|
5644
5383
|
}
|
5645
5384
|
}
|
5646
|
-
const privateKeyBytes = (0,
|
5647
|
-
this.privateKey = (0,
|
5648
|
-
this.publicKey = (0,
|
5649
|
-
this.compressedPublicKey = (0,
|
5385
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
5386
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
5387
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5388
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5650
5389
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5651
5390
|
}
|
5652
5391
|
/**
|
@@ -5660,11 +5399,11 @@ var Signer = class {
|
|
5660
5399
|
* @returns hashed signature
|
5661
5400
|
*/
|
5662
5401
|
sign(data) {
|
5663
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5664
|
-
const r = (0,
|
5665
|
-
const s = (0,
|
5402
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
5403
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5404
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5666
5405
|
s[0] |= (signature.recovery || 0) << 7;
|
5667
|
-
return (0,
|
5406
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5668
5407
|
}
|
5669
5408
|
/**
|
5670
5409
|
* Add point on the current elliptic curve
|
@@ -5673,8 +5412,8 @@ var Signer = class {
|
|
5673
5412
|
* @returns compressed point on the curve
|
5674
5413
|
*/
|
5675
5414
|
addPoint(point) {
|
5676
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5677
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5415
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
5416
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5678
5417
|
const result = p0.add(p1);
|
5679
5418
|
return `0x${result.toHex(true)}`;
|
5680
5419
|
}
|
@@ -5686,16 +5425,16 @@ var Signer = class {
|
|
5686
5425
|
* @returns public key from signature from the
|
5687
5426
|
*/
|
5688
5427
|
static recoverPublicKey(data, signature) {
|
5689
|
-
const signedMessageBytes = (0,
|
5428
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5690
5429
|
const r = signedMessageBytes.slice(0, 32);
|
5691
5430
|
const s = signedMessageBytes.slice(32, 64);
|
5692
5431
|
const recoveryParam = (s[0] & 128) >> 7;
|
5693
5432
|
s[0] &= 127;
|
5694
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5433
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5695
5434
|
recoveryParam
|
5696
5435
|
);
|
5697
|
-
const publicKey = sig.recoverPublicKey((0,
|
5698
|
-
return (0,
|
5436
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5437
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5699
5438
|
}
|
5700
5439
|
/**
|
5701
5440
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5714,7 +5453,7 @@ var Signer = class {
|
|
5714
5453
|
* @returns random 32-byte hashed
|
5715
5454
|
*/
|
5716
5455
|
static generatePrivateKey(entropy) {
|
5717
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5456
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5718
5457
|
}
|
5719
5458
|
/**
|
5720
5459
|
* Extended publicKey from a compact publicKey
|
@@ -5723,8 +5462,8 @@ var Signer = class {
|
|
5723
5462
|
* @returns extended publicKey
|
5724
5463
|
*/
|
5725
5464
|
static extendPublicKey(publicKey) {
|
5726
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5727
|
-
return (0,
|
5465
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5466
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5728
5467
|
}
|
5729
5468
|
};
|
5730
5469
|
|
@@ -5732,7 +5471,7 @@ var Signer = class {
|
|
5732
5471
|
var import_address6 = require("@fuel-ts/address");
|
5733
5472
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5734
5473
|
var import_errors17 = require("@fuel-ts/errors");
|
5735
|
-
var
|
5474
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5736
5475
|
var import_uuid = require("uuid");
|
5737
5476
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5738
5477
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5815,7 +5554,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5815
5554
|
);
|
5816
5555
|
}
|
5817
5556
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5818
|
-
const privateKey = (0,
|
5557
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5819
5558
|
return privateKey;
|
5820
5559
|
}
|
5821
5560
|
|
@@ -5860,7 +5599,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5860
5599
|
*/
|
5861
5600
|
async signMessage(message) {
|
5862
5601
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5863
|
-
return (0,
|
5602
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5864
5603
|
}
|
5865
5604
|
/**
|
5866
5605
|
* Signs a transaction with the wallet's private key.
|
@@ -5873,7 +5612,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5873
5612
|
const chainId = this.provider.getChainId();
|
5874
5613
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5875
5614
|
const signature = await this.signer().sign(hashedTransaction);
|
5876
|
-
return (0,
|
5615
|
+
return (0, import_utils31.hexlify)(signature);
|
5877
5616
|
}
|
5878
5617
|
/**
|
5879
5618
|
* Populates a transaction with the witnesses signature.
|
@@ -5893,7 +5632,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5893
5632
|
* @param transactionRequestLike - The transaction request to send.
|
5894
5633
|
* @returns A promise that resolves to the TransactionResponse object.
|
5895
5634
|
*/
|
5896
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5635
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5897
5636
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5898
5637
|
if (estimateTxDependencies) {
|
5899
5638
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5934,15 +5673,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5934
5673
|
// src/hdwallet/hdwallet.ts
|
5935
5674
|
var import_errors20 = require("@fuel-ts/errors");
|
5936
5675
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5937
|
-
var
|
5938
|
-
var
|
5676
|
+
var import_math20 = require("@fuel-ts/math");
|
5677
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5939
5678
|
var import_ethers3 = require("ethers");
|
5940
5679
|
|
5941
5680
|
// src/mnemonic/mnemonic.ts
|
5942
5681
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5943
5682
|
var import_errors19 = require("@fuel-ts/errors");
|
5944
5683
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5945
|
-
var
|
5684
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5946
5685
|
var import_ethers2 = require("ethers");
|
5947
5686
|
|
5948
5687
|
// src/wordlists/words/english.ts
|
@@ -8006,7 +7745,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
8006
7745
|
// src/mnemonic/utils.ts
|
8007
7746
|
var import_errors18 = require("@fuel-ts/errors");
|
8008
7747
|
var import_hasher4 = require("@fuel-ts/hasher");
|
8009
|
-
var
|
7748
|
+
var import_utils32 = require("@fuel-ts/utils");
|
8010
7749
|
function toUtf8Bytes(stri) {
|
8011
7750
|
const str = stri.normalize("NFKD");
|
8012
7751
|
const result = [];
|
@@ -8073,14 +7812,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
8073
7812
|
}
|
8074
7813
|
}
|
8075
7814
|
const checksumBits = entropy.length / 4;
|
8076
|
-
const checksum = (0,
|
7815
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
8077
7816
|
indices[indices.length - 1] <<= checksumBits;
|
8078
7817
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
8079
7818
|
return indices;
|
8080
7819
|
}
|
8081
7820
|
function mnemonicWordsToEntropy(words, wordlist) {
|
8082
7821
|
const size = Math.ceil(11 * words.length / 8);
|
8083
|
-
const entropy = (0,
|
7822
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
8084
7823
|
let offset = 0;
|
8085
7824
|
for (let i = 0; i < words.length; i += 1) {
|
8086
7825
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -8100,7 +7839,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8100
7839
|
const entropyBits = 32 * words.length / 3;
|
8101
7840
|
const checksumBits = words.length / 3;
|
8102
7841
|
const checksumMask = getUpperMask(checksumBits);
|
8103
|
-
const checksum = (0,
|
7842
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
8104
7843
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
8105
7844
|
throw new import_errors18.FuelError(
|
8106
7845
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -8175,7 +7914,7 @@ var Mnemonic = class {
|
|
8175
7914
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
8176
7915
|
const words = getWords(phrase);
|
8177
7916
|
assertMnemonic(words);
|
8178
|
-
return (0,
|
7917
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
8179
7918
|
}
|
8180
7919
|
/**
|
8181
7920
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -8183,7 +7922,7 @@ var Mnemonic = class {
|
|
8183
7922
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8184
7923
|
*/
|
8185
7924
|
static entropyToMnemonic(entropy, wordlist = english) {
|
8186
|
-
const entropyBytes = (0,
|
7925
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
8187
7926
|
assertWordList(wordlist);
|
8188
7927
|
assertEntropy(entropyBytes);
|
8189
7928
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -8252,14 +7991,14 @@ var Mnemonic = class {
|
|
8252
7991
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8253
7992
|
*/
|
8254
7993
|
static masterKeysFromSeed(seed) {
|
8255
|
-
const seedArray = (0,
|
7994
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
8256
7995
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8257
7996
|
throw new import_errors19.FuelError(
|
8258
7997
|
import_errors19.ErrorCode.INVALID_SEED,
|
8259
7998
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8260
7999
|
);
|
8261
8000
|
}
|
8262
|
-
return (0,
|
8001
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
8263
8002
|
}
|
8264
8003
|
/**
|
8265
8004
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8270,22 +8009,22 @@ var Mnemonic = class {
|
|
8270
8009
|
*/
|
8271
8010
|
static seedToExtendedKey(seed, testnet = false) {
|
8272
8011
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8273
|
-
const prefix = (0,
|
8012
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8274
8013
|
const depth = "0x00";
|
8275
8014
|
const fingerprint = "0x00000000";
|
8276
8015
|
const index = "0x00000000";
|
8277
8016
|
const chainCode = masterKey.slice(32);
|
8278
8017
|
const privateKey = masterKey.slice(0, 32);
|
8279
|
-
const extendedKey = (0,
|
8018
|
+
const extendedKey = (0, import_utils33.concat)([
|
8280
8019
|
prefix,
|
8281
8020
|
depth,
|
8282
8021
|
fingerprint,
|
8283
8022
|
index,
|
8284
8023
|
chainCode,
|
8285
|
-
(0,
|
8024
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
8286
8025
|
]);
|
8287
8026
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8288
|
-
return (0, import_ethers2.encodeBase58)((0,
|
8027
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
8289
8028
|
}
|
8290
8029
|
/**
|
8291
8030
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8300,7 +8039,7 @@ var Mnemonic = class {
|
|
8300
8039
|
* @returns A randomly generated mnemonic
|
8301
8040
|
*/
|
8302
8041
|
static generate(size = 32, extraEntropy = "") {
|
8303
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8042
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
8304
8043
|
return Mnemonic.entropyToMnemonic(entropy);
|
8305
8044
|
}
|
8306
8045
|
};
|
@@ -8308,12 +8047,12 @@ var mnemonic_default = Mnemonic;
|
|
8308
8047
|
|
8309
8048
|
// src/hdwallet/hdwallet.ts
|
8310
8049
|
var HARDENED_INDEX = 2147483648;
|
8311
|
-
var MainnetPRV2 = (0,
|
8312
|
-
var MainnetPUB = (0,
|
8313
|
-
var TestnetPRV2 = (0,
|
8314
|
-
var TestnetPUB = (0,
|
8050
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
8051
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
8052
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
8053
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
8315
8054
|
function base58check(data) {
|
8316
|
-
return (0, import_ethers3.encodeBase58)((0,
|
8055
|
+
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)]));
|
8317
8056
|
}
|
8318
8057
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8319
8058
|
if (isPublic) {
|
@@ -8322,11 +8061,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8322
8061
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8323
8062
|
}
|
8324
8063
|
function isPublicExtendedKey(extendedKey) {
|
8325
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8064
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
8326
8065
|
}
|
8327
8066
|
function isValidExtendedKey(extendedKey) {
|
8328
8067
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8329
|
-
(0,
|
8068
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
8330
8069
|
);
|
8331
8070
|
}
|
8332
8071
|
function parsePath(path, depth = 0) {
|
@@ -8344,8 +8083,8 @@ function parsePath(path, depth = 0) {
|
|
8344
8083
|
var HDWallet = class {
|
8345
8084
|
depth = 0;
|
8346
8085
|
index = 0;
|
8347
|
-
fingerprint = (0,
|
8348
|
-
parentFingerprint = (0,
|
8086
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8087
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8349
8088
|
privateKey;
|
8350
8089
|
publicKey;
|
8351
8090
|
chainCode;
|
@@ -8357,8 +8096,8 @@ var HDWallet = class {
|
|
8357
8096
|
constructor(config) {
|
8358
8097
|
if (config.privateKey) {
|
8359
8098
|
const signer = new Signer(config.privateKey);
|
8360
|
-
this.publicKey = (0,
|
8361
|
-
this.privateKey = (0,
|
8099
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
8100
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
8362
8101
|
} else {
|
8363
8102
|
if (!config.publicKey) {
|
8364
8103
|
throw new import_errors20.FuelError(
|
@@ -8366,7 +8105,7 @@ var HDWallet = class {
|
|
8366
8105
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8367
8106
|
);
|
8368
8107
|
}
|
8369
|
-
this.publicKey = (0,
|
8108
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
8370
8109
|
}
|
8371
8110
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8372
8111
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -8385,9 +8124,9 @@ var HDWallet = class {
|
|
8385
8124
|
* @returns A new instance of HDWallet on the derived index
|
8386
8125
|
*/
|
8387
8126
|
deriveIndex(index) {
|
8388
|
-
const privateKey = this.privateKey && (0,
|
8389
|
-
const publicKey = (0,
|
8390
|
-
const chainCode = (0,
|
8127
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
8128
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
8129
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
8391
8130
|
const data = new Uint8Array(37);
|
8392
8131
|
if (index & HARDENED_INDEX) {
|
8393
8132
|
if (!privateKey) {
|
@@ -8398,15 +8137,15 @@ var HDWallet = class {
|
|
8398
8137
|
}
|
8399
8138
|
data.set(privateKey, 1);
|
8400
8139
|
} else {
|
8401
|
-
data.set((0,
|
8140
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
8402
8141
|
}
|
8403
|
-
data.set((0,
|
8404
|
-
const bytes = (0,
|
8142
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
8143
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
8405
8144
|
const IL = bytes.slice(0, 32);
|
8406
8145
|
const IR = bytes.slice(32);
|
8407
8146
|
if (privateKey) {
|
8408
8147
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8409
|
-
const ki = (0,
|
8148
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8410
8149
|
return new HDWallet({
|
8411
8150
|
privateKey: ki,
|
8412
8151
|
chainCode: IR,
|
@@ -8415,7 +8154,7 @@ var HDWallet = class {
|
|
8415
8154
|
parentFingerprint: this.fingerprint
|
8416
8155
|
});
|
8417
8156
|
}
|
8418
|
-
const signer = new Signer((0,
|
8157
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
8419
8158
|
const Ki = signer.addPoint(publicKey);
|
8420
8159
|
return new HDWallet({
|
8421
8160
|
publicKey: Ki,
|
@@ -8450,12 +8189,12 @@ var HDWallet = class {
|
|
8450
8189
|
);
|
8451
8190
|
}
|
8452
8191
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8453
|
-
const depth = (0,
|
8192
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
8454
8193
|
const parentFingerprint = this.parentFingerprint;
|
8455
|
-
const index = (0,
|
8194
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
8456
8195
|
const chainCode = this.chainCode;
|
8457
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8458
|
-
const extendedKey = (0,
|
8196
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8197
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8459
8198
|
return base58check(extendedKey);
|
8460
8199
|
}
|
8461
8200
|
/**
|
@@ -8467,13 +8206,13 @@ var HDWallet = class {
|
|
8467
8206
|
static fromSeed(seed) {
|
8468
8207
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8469
8208
|
return new HDWallet({
|
8470
|
-
chainCode: (0,
|
8471
|
-
privateKey: (0,
|
8209
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
8210
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
8472
8211
|
});
|
8473
8212
|
}
|
8474
8213
|
static fromExtendedKey(extendedKey) {
|
8475
8214
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8476
|
-
const bytes = (0,
|
8215
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
8477
8216
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8478
8217
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8479
8218
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8482,9 +8221,9 @@ var HDWallet = class {
|
|
8482
8221
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8483
8222
|
}
|
8484
8223
|
const depth = bytes[4];
|
8485
|
-
const parentFingerprint = (0,
|
8486
|
-
const index = parseInt((0,
|
8487
|
-
const chainCode = (0,
|
8224
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
8225
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8226
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
8488
8227
|
const key = bytes.slice(45, 78);
|
8489
8228
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8490
8229
|
throw new import_errors20.FuelError(
|
@@ -9089,19 +8828,19 @@ var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
|
9089
8828
|
var import_address10 = require("@fuel-ts/address");
|
9090
8829
|
var import_configs13 = require("@fuel-ts/address/configs");
|
9091
8830
|
var import_errors25 = require("@fuel-ts/errors");
|
9092
|
-
var
|
9093
|
-
var
|
8831
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
8832
|
+
var import_utils37 = require("@fuel-ts/utils");
|
9094
8833
|
|
9095
8834
|
// src/predicate/utils/getPredicateRoot.ts
|
9096
8835
|
var import_hasher7 = require("@fuel-ts/hasher");
|
9097
8836
|
var import_merkle = require("@fuel-ts/merkle");
|
9098
|
-
var
|
8837
|
+
var import_utils36 = require("@fuel-ts/utils");
|
9099
8838
|
var getPredicateRoot = (bytecode) => {
|
9100
8839
|
const chunkSize = 16 * 1024;
|
9101
|
-
const bytes = (0,
|
9102
|
-
const chunks = (0,
|
9103
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
9104
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
8840
|
+
const bytes = (0, import_utils36.arrayify)(bytecode);
|
8841
|
+
const chunks = (0, import_utils36.chunkAndPadBytes)(bytes, chunkSize);
|
8842
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils36.hexlify)(c)));
|
8843
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils36.concat)(["0x4655454C", codeRoot]));
|
9105
8844
|
return predicateRoot;
|
9106
8845
|
};
|
9107
8846
|
|
@@ -9149,9 +8888,9 @@ var Predicate = class extends Account {
|
|
9149
8888
|
const request = transactionRequestify(transactionRequestLike);
|
9150
8889
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
9151
8890
|
request.inputs?.forEach((input) => {
|
9152
|
-
if (input.type ===
|
9153
|
-
input.predicate =
|
9154
|
-
input.predicateData =
|
8891
|
+
if (input.type === import_transactions20.InputType.Coin && (0, import_utils37.hexlify)(input.owner) === this.address.toB256()) {
|
8892
|
+
input.predicate = this.bytes;
|
8893
|
+
input.predicateData = this.getPredicateData(policies.length);
|
9155
8894
|
}
|
9156
8895
|
});
|
9157
8896
|
return request;
|
@@ -9166,7 +8905,8 @@ var Predicate = class extends Account {
|
|
9166
8905
|
* @returns A promise that resolves to the prepared transaction request.
|
9167
8906
|
*/
|
9168
8907
|
async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
|
9169
|
-
|
8908
|
+
const request = await super.createTransfer(destination, amount, assetId, txParams);
|
8909
|
+
return this.populateTransactionPredicateData(request);
|
9170
8910
|
}
|
9171
8911
|
/**
|
9172
8912
|
* Sends a transaction with the populated predicate data.
|
@@ -9174,9 +8914,9 @@ var Predicate = class extends Account {
|
|
9174
8914
|
* @param transactionRequestLike - The transaction request-like object.
|
9175
8915
|
* @returns A promise that resolves to the transaction response.
|
9176
8916
|
*/
|
9177
|
-
sendTransaction(transactionRequestLike) {
|
9178
|
-
const transactionRequest =
|
9179
|
-
return super.sendTransaction(transactionRequest,
|
8917
|
+
sendTransaction(transactionRequestLike, options) {
|
8918
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8919
|
+
return super.sendTransaction(transactionRequest, options);
|
9180
8920
|
}
|
9181
8921
|
/**
|
9182
8922
|
* Simulates a transaction with the populated predicate data.
|
@@ -9185,15 +8925,15 @@ var Predicate = class extends Account {
|
|
9185
8925
|
* @returns A promise that resolves to the call result.
|
9186
8926
|
*/
|
9187
8927
|
simulateTransaction(transactionRequestLike) {
|
9188
|
-
const transactionRequest =
|
9189
|
-
return super.simulateTransaction(transactionRequest
|
8928
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8929
|
+
return super.simulateTransaction(transactionRequest);
|
9190
8930
|
}
|
9191
8931
|
getPredicateData(policiesLength) {
|
9192
8932
|
if (!this.predicateData.length) {
|
9193
8933
|
return new Uint8Array();
|
9194
8934
|
}
|
9195
8935
|
const mainFn = this.interface?.functions.main;
|
9196
|
-
const paddedCode = new
|
8936
|
+
const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
9197
8937
|
const VM_TX_MEMORY = (0, import_abi_coder7.calculateVmTxMemory)({
|
9198
8938
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
9199
8939
|
});
|
@@ -9209,7 +8949,7 @@ var Predicate = class extends Account {
|
|
9209
8949
|
* @returns An object containing the new predicate bytes and interface.
|
9210
8950
|
*/
|
9211
8951
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
9212
|
-
let predicateBytes = (0,
|
8952
|
+
let predicateBytes = (0, import_utils37.arrayify)(bytes);
|
9213
8953
|
let abiInterface;
|
9214
8954
|
if (jsonAbi) {
|
9215
8955
|
abiInterface = new import_abi_coder7.Interface(jsonAbi);
|
@@ -9232,25 +8972,6 @@ var Predicate = class extends Account {
|
|
9232
8972
|
predicateInterface: abiInterface
|
9233
8973
|
};
|
9234
8974
|
}
|
9235
|
-
/**
|
9236
|
-
* Retrieves resources satisfying the spend query for the account.
|
9237
|
-
*
|
9238
|
-
* @param quantities - IDs of coins to exclude.
|
9239
|
-
* @param excludedIds - IDs of resources to be excluded from the query.
|
9240
|
-
* @returns A promise that resolves to an array of Resources.
|
9241
|
-
*/
|
9242
|
-
async getResourcesToSpend(quantities, excludedIds) {
|
9243
|
-
const resources = await this.provider.getResourcesToSpend(
|
9244
|
-
this.address,
|
9245
|
-
quantities,
|
9246
|
-
excludedIds
|
9247
|
-
);
|
9248
|
-
return resources.map((resource) => ({
|
9249
|
-
...resource,
|
9250
|
-
predicate: (0, import_utils36.hexlify)(this.bytes),
|
9251
|
-
padPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
|
9252
|
-
}));
|
9253
|
-
}
|
9254
8975
|
/**
|
9255
8976
|
* Sets the configurable constants for the predicate.
|
9256
8977
|
*
|
@@ -10000,7 +9721,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
10000
9721
|
WalletLocked,
|
10001
9722
|
WalletManager,
|
10002
9723
|
WalletUnlocked,
|
10003
|
-
|
9724
|
+
addAmountToAsset,
|
10004
9725
|
addOperation,
|
10005
9726
|
assemblePanicError,
|
10006
9727
|
assembleReceiptByType,
|
@@ -10009,10 +9730,9 @@ __publicField(Fuel, "defaultConfig", {});
|
|
10009
9730
|
assets,
|
10010
9731
|
buildBlockExplorerUrl,
|
10011
9732
|
cacheFor,
|
10012
|
-
cacheTxInputsFromOwner,
|
10013
|
-
calculateGasFee,
|
10014
9733
|
calculateMetadataGasForTxCreate,
|
10015
9734
|
calculateMetadataGasForTxScript,
|
9735
|
+
calculatePriceWithFactor,
|
10016
9736
|
calculateTransactionFee,
|
10017
9737
|
coinQuantityfy,
|
10018
9738
|
deferPromise,
|