@fuel-ts/account 0.0.0-rc-2143-20240424161332 → 0.0.0-rc-2021-20240424162616
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 +6 -5
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +808 -553
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +769 -514
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +650 -396
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +810 -359
- 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 +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +37 -27
- 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 +8 -29
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- 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 +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- 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 +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +2 -4
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1527 -1056
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +751 -514
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +644 -407
- 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
|
+
addAmountToCoinQuantities: () => addAmountToCoinQuantities,
|
99
99
|
addOperation: () => addOperation,
|
100
100
|
assemblePanicError: () => assemblePanicError,
|
101
101
|
assembleReceiptByType: () => assembleReceiptByType,
|
@@ -104,9 +104,10 @@ __export(src_exports, {
|
|
104
104
|
assets: () => assets,
|
105
105
|
buildBlockExplorerUrl: () => buildBlockExplorerUrl,
|
106
106
|
cacheFor: () => cacheFor,
|
107
|
+
cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
|
108
|
+
calculateGasFee: () => calculateGasFee,
|
107
109
|
calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
|
108
110
|
calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
|
109
|
-
calculatePriceWithFactor: () => calculatePriceWithFactor,
|
110
111
|
calculateTransactionFee: () => calculateTransactionFee,
|
111
112
|
coinQuantityfy: () => coinQuantityfy,
|
112
113
|
deferPromise: () => deferPromise,
|
@@ -187,8 +188,9 @@ var import_address4 = require("@fuel-ts/address");
|
|
187
188
|
var import_configs12 = require("@fuel-ts/address/configs");
|
188
189
|
var import_errors16 = require("@fuel-ts/errors");
|
189
190
|
var import_interfaces = require("@fuel-ts/interfaces");
|
190
|
-
var
|
191
|
-
var
|
191
|
+
var import_math19 = require("@fuel-ts/math");
|
192
|
+
var import_utils27 = require("@fuel-ts/utils");
|
193
|
+
var import_ramda4 = require("ramda");
|
192
194
|
|
193
195
|
// src/providers/coin-quantity.ts
|
194
196
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -197,24 +199,24 @@ var import_utils = require("@fuel-ts/utils");
|
|
197
199
|
var coinQuantityfy = (coinQuantityLike) => {
|
198
200
|
let assetId;
|
199
201
|
let amount;
|
200
|
-
let
|
202
|
+
let max;
|
201
203
|
if (Array.isArray(coinQuantityLike)) {
|
202
204
|
amount = coinQuantityLike[0];
|
203
205
|
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
204
|
-
|
206
|
+
max = coinQuantityLike[2] ?? void 0;
|
205
207
|
} else {
|
206
208
|
amount = coinQuantityLike.amount;
|
207
209
|
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
208
|
-
|
210
|
+
max = coinQuantityLike.max ?? void 0;
|
209
211
|
}
|
210
212
|
const bnAmount = (0, import_math.bn)(amount);
|
211
213
|
return {
|
212
214
|
assetId: (0, import_utils.hexlify)(assetId),
|
213
215
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
214
|
-
max:
|
216
|
+
max: max ? (0, import_math.bn)(max) : void 0
|
215
217
|
};
|
216
218
|
};
|
217
|
-
var
|
219
|
+
var addAmountToCoinQuantities = (params) => {
|
218
220
|
const { amount, assetId } = params;
|
219
221
|
const coinQuantities = [...params.coinQuantities];
|
220
222
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -229,27 +231,31 @@ var addAmountToAsset = (params) => {
|
|
229
231
|
// src/providers/provider.ts
|
230
232
|
var import_address3 = require("@fuel-ts/address");
|
231
233
|
var import_errors14 = require("@fuel-ts/errors");
|
232
|
-
var
|
233
|
-
var
|
234
|
-
var
|
234
|
+
var import_math16 = require("@fuel-ts/math");
|
235
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
236
|
+
var import_utils22 = require("@fuel-ts/utils");
|
235
237
|
var import_versions = require("@fuel-ts/versions");
|
236
|
-
var
|
238
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
237
239
|
var import_ethers = require("ethers");
|
238
240
|
var import_graphql_request = require("graphql-request");
|
239
241
|
var import_ramda3 = require("ramda");
|
240
242
|
|
241
243
|
// src/providers/__generated__/operations.ts
|
242
244
|
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 SqueezedOutStatus {
|
249
|
+
reason
|
250
|
+
}
|
251
|
+
}
|
252
|
+
`;
|
243
253
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
244
254
|
fragment receiptFragment on Receipt {
|
245
|
-
|
246
|
-
id
|
247
|
-
}
|
255
|
+
id
|
248
256
|
pc
|
249
257
|
is
|
250
|
-
to
|
251
|
-
id
|
252
|
-
}
|
258
|
+
to
|
253
259
|
toAddress
|
254
260
|
amount
|
255
261
|
assetId
|
@@ -287,10 +293,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
287
293
|
id
|
288
294
|
}
|
289
295
|
time
|
296
|
+
receipts {
|
297
|
+
...receiptFragment
|
298
|
+
}
|
290
299
|
programState {
|
291
300
|
returnType
|
292
301
|
data
|
293
302
|
}
|
303
|
+
receipts {
|
304
|
+
...receiptFragment
|
305
|
+
}
|
294
306
|
}
|
295
307
|
... on FailureStatus {
|
296
308
|
block {
|
@@ -298,26 +310,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
298
310
|
}
|
299
311
|
time
|
300
312
|
reason
|
313
|
+
receipts {
|
314
|
+
...receiptFragment
|
315
|
+
}
|
301
316
|
}
|
302
317
|
... on SqueezedOutStatus {
|
303
318
|
reason
|
304
319
|
}
|
305
320
|
}
|
306
|
-
`;
|
321
|
+
${ReceiptFragmentFragmentDoc}`;
|
307
322
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
308
323
|
fragment transactionFragment on Transaction {
|
309
324
|
id
|
310
325
|
rawPayload
|
311
|
-
gasPrice
|
312
|
-
receipts {
|
313
|
-
...receiptFragment
|
314
|
-
}
|
315
326
|
status {
|
316
327
|
...transactionStatusFragment
|
317
328
|
}
|
318
329
|
}
|
319
|
-
${
|
320
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
330
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
321
331
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
322
332
|
fragment inputEstimatePredicatesFragment on Input {
|
323
333
|
... on InputCoin {
|
@@ -335,6 +345,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
335
345
|
}
|
336
346
|
}
|
337
347
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
348
|
+
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
349
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
350
|
+
reason
|
351
|
+
programState {
|
352
|
+
returnType
|
353
|
+
data
|
354
|
+
}
|
355
|
+
}
|
356
|
+
`;
|
357
|
+
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
358
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
359
|
+
programState {
|
360
|
+
returnType
|
361
|
+
data
|
362
|
+
}
|
363
|
+
}
|
364
|
+
`;
|
365
|
+
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
366
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
367
|
+
... on DryRunFailureStatus {
|
368
|
+
...dryRunFailureStatusFragment
|
369
|
+
}
|
370
|
+
... on DryRunSuccessStatus {
|
371
|
+
...dryRunSuccessStatusFragment
|
372
|
+
}
|
373
|
+
}
|
374
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
375
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
376
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
377
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
378
|
+
id
|
379
|
+
status {
|
380
|
+
...dryRunTransactionStatusFragment
|
381
|
+
}
|
382
|
+
receipts {
|
383
|
+
...receiptFragment
|
384
|
+
}
|
385
|
+
}
|
386
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
387
|
+
${ReceiptFragmentFragmentDoc}`;
|
338
388
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
339
389
|
fragment coinFragment on Coin {
|
340
390
|
__typename
|
@@ -342,7 +392,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
342
392
|
owner
|
343
393
|
amount
|
344
394
|
assetId
|
345
|
-
maturity
|
346
395
|
blockCreated
|
347
396
|
txCreatedIdx
|
348
397
|
}
|
@@ -381,26 +430,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
381
430
|
messageBlockHeader {
|
382
431
|
id
|
383
432
|
daHeight
|
433
|
+
consensusParametersVersion
|
434
|
+
stateTransitionBytecodeVersion
|
384
435
|
transactionsCount
|
436
|
+
messageReceiptCount
|
385
437
|
transactionsRoot
|
438
|
+
messageOutboxRoot
|
439
|
+
eventInboxRoot
|
386
440
|
height
|
387
441
|
prevRoot
|
388
442
|
time
|
389
443
|
applicationHash
|
390
|
-
messageReceiptRoot
|
391
|
-
messageReceiptCount
|
392
444
|
}
|
393
445
|
commitBlockHeader {
|
394
446
|
id
|
395
447
|
daHeight
|
448
|
+
consensusParametersVersion
|
449
|
+
stateTransitionBytecodeVersion
|
396
450
|
transactionsCount
|
451
|
+
messageReceiptCount
|
397
452
|
transactionsRoot
|
453
|
+
messageOutboxRoot
|
454
|
+
eventInboxRoot
|
398
455
|
height
|
399
456
|
prevRoot
|
400
457
|
time
|
401
458
|
applicationHash
|
402
|
-
messageReceiptRoot
|
403
|
-
messageReceiptCount
|
404
459
|
}
|
405
460
|
sender
|
406
461
|
recipient
|
@@ -419,8 +474,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
419
474
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
420
475
|
fragment blockFragment on Block {
|
421
476
|
id
|
477
|
+
height
|
422
478
|
header {
|
423
|
-
height
|
424
479
|
time
|
425
480
|
}
|
426
481
|
transactions {
|
@@ -430,6 +485,7 @@ var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
|
430
485
|
`;
|
431
486
|
var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
|
432
487
|
fragment TxParametersFragment on TxParameters {
|
488
|
+
version
|
433
489
|
maxInputs
|
434
490
|
maxOutputs
|
435
491
|
maxWitnesses
|
@@ -439,6 +495,7 @@ var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
|
|
439
495
|
`;
|
440
496
|
var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
|
441
497
|
fragment PredicateParametersFragment on PredicateParameters {
|
498
|
+
version
|
442
499
|
maxPredicateLength
|
443
500
|
maxPredicateDataLength
|
444
501
|
maxGasPerPredicate
|
@@ -447,18 +504,21 @@ var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
|
|
447
504
|
`;
|
448
505
|
var ScriptParametersFragmentFragmentDoc = import_graphql_tag.default`
|
449
506
|
fragment ScriptParametersFragment on ScriptParameters {
|
507
|
+
version
|
450
508
|
maxScriptLength
|
451
509
|
maxScriptDataLength
|
452
510
|
}
|
453
511
|
`;
|
454
512
|
var ContractParametersFragmentFragmentDoc = import_graphql_tag.default`
|
455
513
|
fragment ContractParametersFragment on ContractParameters {
|
514
|
+
version
|
456
515
|
contractMaxSize
|
457
516
|
maxStorageSlots
|
458
517
|
}
|
459
518
|
`;
|
460
519
|
var FeeParametersFragmentFragmentDoc = import_graphql_tag.default`
|
461
520
|
fragment FeeParametersFragment on FeeParameters {
|
521
|
+
version
|
462
522
|
gasPriceFactor
|
463
523
|
gasPerByte
|
464
524
|
}
|
@@ -478,6 +538,7 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
478
538
|
`;
|
479
539
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
480
540
|
fragment GasCostsFragment on GasCosts {
|
541
|
+
version
|
481
542
|
add
|
482
543
|
addi
|
483
544
|
aloc
|
@@ -490,7 +551,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
490
551
|
cb
|
491
552
|
cfei
|
492
553
|
cfsi
|
493
|
-
croo
|
494
554
|
div
|
495
555
|
divi
|
496
556
|
ecr1
|
@@ -573,6 +633,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
573
633
|
ccp {
|
574
634
|
...DependentCostFragment
|
575
635
|
}
|
636
|
+
croo {
|
637
|
+
...DependentCostFragment
|
638
|
+
}
|
576
639
|
csiz {
|
577
640
|
...DependentCostFragment
|
578
641
|
}
|
@@ -632,6 +695,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
632
695
|
${DependentCostFragmentFragmentDoc}`;
|
633
696
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
634
697
|
fragment consensusParametersFragment on ConsensusParameters {
|
698
|
+
version
|
635
699
|
txParams {
|
636
700
|
...TxParametersFragment
|
637
701
|
}
|
@@ -691,18 +755,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
691
755
|
fragment nodeInfoFragment on NodeInfo {
|
692
756
|
utxoValidation
|
693
757
|
vmBacktrace
|
694
|
-
minGasPrice
|
695
758
|
maxTx
|
696
759
|
maxDepth
|
697
760
|
nodeVersion
|
698
|
-
peers {
|
699
|
-
id
|
700
|
-
addresses
|
701
|
-
clientVersion
|
702
|
-
blockHeight
|
703
|
-
lastHeartbeatMs
|
704
|
-
appScore
|
705
|
-
}
|
706
761
|
}
|
707
762
|
`;
|
708
763
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -737,13 +792,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
737
792
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
738
793
|
transaction(id: $transactionId) {
|
739
794
|
...transactionFragment
|
740
|
-
receipts {
|
741
|
-
...receiptFragment
|
742
|
-
}
|
743
795
|
}
|
744
796
|
}
|
745
|
-
${TransactionFragmentFragmentDoc}
|
746
|
-
${ReceiptFragmentFragmentDoc}`;
|
797
|
+
${TransactionFragmentFragmentDoc}`;
|
747
798
|
var GetTransactionsDocument = import_graphql_tag.default`
|
748
799
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
749
800
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -871,6 +922,20 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
871
922
|
}
|
872
923
|
}
|
873
924
|
${BalanceFragmentFragmentDoc}`;
|
925
|
+
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
926
|
+
query getLatestGasPrice {
|
927
|
+
latestGasPrice {
|
928
|
+
gasPrice
|
929
|
+
}
|
930
|
+
}
|
931
|
+
`;
|
932
|
+
var EstimateGasPriceDocument = import_graphql_tag.default`
|
933
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
934
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
935
|
+
gasPrice
|
936
|
+
}
|
937
|
+
}
|
938
|
+
`;
|
874
939
|
var GetBalancesDocument = import_graphql_tag.default`
|
875
940
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
876
941
|
balances(
|
@@ -925,12 +990,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
925
990
|
}
|
926
991
|
`;
|
927
992
|
var DryRunDocument = import_graphql_tag.default`
|
928
|
-
mutation dryRun($
|
929
|
-
dryRun(
|
930
|
-
...
|
993
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
994
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
995
|
+
...dryRunTransactionExecutionStatusFragment
|
931
996
|
}
|
932
997
|
}
|
933
|
-
${
|
998
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
934
999
|
var SubmitDocument = import_graphql_tag.default`
|
935
1000
|
mutation submit($encodedTransaction: HexString!) {
|
936
1001
|
submit(tx: $encodedTransaction) {
|
@@ -949,17 +1014,17 @@ var ProduceBlocksDocument = import_graphql_tag.default`
|
|
949
1014
|
var SubmitAndAwaitDocument = import_graphql_tag.default`
|
950
1015
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
951
1016
|
submitAndAwait(tx: $encodedTransaction) {
|
952
|
-
...
|
1017
|
+
...transactionStatusSubscriptionFragment
|
953
1018
|
}
|
954
1019
|
}
|
955
|
-
${
|
1020
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
956
1021
|
var StatusChangeDocument = import_graphql_tag.default`
|
957
1022
|
subscription statusChange($transactionId: TransactionId!) {
|
958
1023
|
statusChange(id: $transactionId) {
|
959
|
-
...
|
1024
|
+
...transactionStatusSubscriptionFragment
|
960
1025
|
}
|
961
1026
|
}
|
962
|
-
${
|
1027
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
963
1028
|
function getSdk(requester) {
|
964
1029
|
return {
|
965
1030
|
getVersion(variables, options) {
|
@@ -1013,6 +1078,12 @@ function getSdk(requester) {
|
|
1013
1078
|
getBalance(variables, options) {
|
1014
1079
|
return requester(GetBalanceDocument, variables, options);
|
1015
1080
|
},
|
1081
|
+
getLatestGasPrice(variables, options) {
|
1082
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
1083
|
+
},
|
1084
|
+
estimateGasPrice(variables, options) {
|
1085
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
1086
|
+
},
|
1016
1087
|
getBalances(variables, options) {
|
1017
1088
|
return requester(GetBalancesDocument, variables, options);
|
1018
1089
|
},
|
@@ -1206,10 +1277,9 @@ var inputify = (value) => {
|
|
1206
1277
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1207
1278
|
},
|
1208
1279
|
witnessIndex: value.witnessIndex,
|
1209
|
-
maturity: value.maturity ?? 0,
|
1210
1280
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1211
|
-
predicateLength: predicate.length,
|
1212
|
-
predicateDataLength: predicateData.length,
|
1281
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1282
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1213
1283
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1214
1284
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1215
1285
|
};
|
@@ -1240,8 +1310,8 @@ var inputify = (value) => {
|
|
1240
1310
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1241
1311
|
witnessIndex: value.witnessIndex,
|
1242
1312
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1243
|
-
predicateLength: predicate.length,
|
1244
|
-
predicateDataLength: predicateData.length,
|
1313
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1314
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1245
1315
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1246
1316
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1247
1317
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1360,8 +1430,8 @@ function assembleReceiptByType(receipt) {
|
|
1360
1430
|
case "CALL" /* Call */: {
|
1361
1431
|
const callReceipt = {
|
1362
1432
|
type: import_transactions3.ReceiptType.Call,
|
1363
|
-
from: hexOrZero(receipt.
|
1364
|
-
to: hexOrZero(receipt?.to
|
1433
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1434
|
+
to: hexOrZero(receipt?.to),
|
1365
1435
|
amount: (0, import_math4.bn)(receipt.amount),
|
1366
1436
|
assetId: hexOrZero(receipt.assetId),
|
1367
1437
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1375,7 +1445,7 @@ function assembleReceiptByType(receipt) {
|
|
1375
1445
|
case "RETURN" /* Return */: {
|
1376
1446
|
const returnReceipt = {
|
1377
1447
|
type: import_transactions3.ReceiptType.Return,
|
1378
|
-
id: hexOrZero(receipt.
|
1448
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1379
1449
|
val: (0, import_math4.bn)(receipt.val),
|
1380
1450
|
pc: (0, import_math4.bn)(receipt.pc),
|
1381
1451
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1385,7 +1455,7 @@ function assembleReceiptByType(receipt) {
|
|
1385
1455
|
case "RETURN_DATA" /* ReturnData */: {
|
1386
1456
|
const returnDataReceipt = {
|
1387
1457
|
type: import_transactions3.ReceiptType.ReturnData,
|
1388
|
-
id: hexOrZero(receipt.
|
1458
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1389
1459
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1390
1460
|
len: (0, import_math4.bn)(receipt.len),
|
1391
1461
|
digest: hexOrZero(receipt.digest),
|
@@ -1397,7 +1467,7 @@ function assembleReceiptByType(receipt) {
|
|
1397
1467
|
case "PANIC" /* Panic */: {
|
1398
1468
|
const panicReceipt = {
|
1399
1469
|
type: import_transactions3.ReceiptType.Panic,
|
1400
|
-
id: hexOrZero(receipt.
|
1470
|
+
id: hexOrZero(receipt.id),
|
1401
1471
|
reason: (0, import_math4.bn)(receipt.reason),
|
1402
1472
|
pc: (0, import_math4.bn)(receipt.pc),
|
1403
1473
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1408,7 +1478,7 @@ function assembleReceiptByType(receipt) {
|
|
1408
1478
|
case "REVERT" /* Revert */: {
|
1409
1479
|
const revertReceipt = {
|
1410
1480
|
type: import_transactions3.ReceiptType.Revert,
|
1411
|
-
id: hexOrZero(receipt.
|
1481
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1412
1482
|
val: (0, import_math4.bn)(receipt.ra),
|
1413
1483
|
pc: (0, import_math4.bn)(receipt.pc),
|
1414
1484
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1418,7 +1488,7 @@ function assembleReceiptByType(receipt) {
|
|
1418
1488
|
case "LOG" /* Log */: {
|
1419
1489
|
const logReceipt = {
|
1420
1490
|
type: import_transactions3.ReceiptType.Log,
|
1421
|
-
id: hexOrZero(receipt.
|
1491
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1422
1492
|
val0: (0, import_math4.bn)(receipt.ra),
|
1423
1493
|
val1: (0, import_math4.bn)(receipt.rb),
|
1424
1494
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1431,7 +1501,7 @@ function assembleReceiptByType(receipt) {
|
|
1431
1501
|
case "LOG_DATA" /* LogData */: {
|
1432
1502
|
const logDataReceipt = {
|
1433
1503
|
type: import_transactions3.ReceiptType.LogData,
|
1434
|
-
id: hexOrZero(receipt.
|
1504
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1435
1505
|
val0: (0, import_math4.bn)(receipt.ra),
|
1436
1506
|
val1: (0, import_math4.bn)(receipt.rb),
|
1437
1507
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1445,8 +1515,8 @@ function assembleReceiptByType(receipt) {
|
|
1445
1515
|
case "TRANSFER" /* Transfer */: {
|
1446
1516
|
const transferReceipt = {
|
1447
1517
|
type: import_transactions3.ReceiptType.Transfer,
|
1448
|
-
from: hexOrZero(receipt.
|
1449
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1518
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1519
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1450
1520
|
amount: (0, import_math4.bn)(receipt.amount),
|
1451
1521
|
assetId: hexOrZero(receipt.assetId),
|
1452
1522
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1457,8 +1527,8 @@ function assembleReceiptByType(receipt) {
|
|
1457
1527
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1458
1528
|
const transferOutReceipt = {
|
1459
1529
|
type: import_transactions3.ReceiptType.TransferOut,
|
1460
|
-
from: hexOrZero(receipt.
|
1461
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1530
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1531
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1462
1532
|
amount: (0, import_math4.bn)(receipt.amount),
|
1463
1533
|
assetId: hexOrZero(receipt.assetId),
|
1464
1534
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1501,7 +1571,7 @@ function assembleReceiptByType(receipt) {
|
|
1501
1571
|
return receiptMessageOut;
|
1502
1572
|
}
|
1503
1573
|
case "MINT" /* Mint */: {
|
1504
|
-
const contractId = hexOrZero(receipt.
|
1574
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1505
1575
|
const subId = hexOrZero(receipt.subId);
|
1506
1576
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1507
1577
|
const mintReceipt = {
|
@@ -1516,7 +1586,7 @@ function assembleReceiptByType(receipt) {
|
|
1516
1586
|
return mintReceipt;
|
1517
1587
|
}
|
1518
1588
|
case "BURN" /* Burn */: {
|
1519
|
-
const contractId = hexOrZero(receipt.
|
1589
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1520
1590
|
const subId = hexOrZero(receipt.subId);
|
1521
1591
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1522
1592
|
const burnReceipt = {
|
@@ -1601,7 +1671,6 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1601
1671
|
var import_math5 = require("@fuel-ts/math");
|
1602
1672
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1603
1673
|
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()));
|
1605
1674
|
var getGasUsedFromReceipts = (receipts) => {
|
1606
1675
|
const scriptResult = receipts.filter(
|
1607
1676
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1622,18 +1691,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1622
1691
|
}
|
1623
1692
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1624
1693
|
const witnessCache = [];
|
1625
|
-
const
|
1694
|
+
const chargeableInputs = inputs.filter((input) => {
|
1695
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1696
|
+
if (isCoinOrMessage) {
|
1697
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1698
|
+
return true;
|
1699
|
+
}
|
1700
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1701
|
+
witnessCache.push(input.witnessIndex);
|
1702
|
+
return true;
|
1703
|
+
}
|
1704
|
+
}
|
1705
|
+
return false;
|
1706
|
+
});
|
1707
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1708
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1626
1709
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1627
1710
|
return total.add(
|
1628
|
-
|
1711
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1629
1712
|
);
|
1630
1713
|
}
|
1631
|
-
|
1632
|
-
|
1633
|
-
return total.add(gasCosts.ecr1);
|
1634
|
-
}
|
1635
|
-
return total;
|
1636
|
-
}, (0, import_math5.bn)());
|
1714
|
+
return total.add(gasCosts.ecr1);
|
1715
|
+
}, (0, import_math5.bn)(0));
|
1637
1716
|
return totalGas;
|
1638
1717
|
}
|
1639
1718
|
function getMinGas(params) {
|
@@ -1645,12 +1724,20 @@ function getMinGas(params) {
|
|
1645
1724
|
return minGas;
|
1646
1725
|
}
|
1647
1726
|
function getMaxGas(params) {
|
1648
|
-
const {
|
1727
|
+
const {
|
1728
|
+
gasPerByte,
|
1729
|
+
witnessesLength,
|
1730
|
+
witnessLimit,
|
1731
|
+
minGas,
|
1732
|
+
gasLimit = (0, import_math5.bn)(0),
|
1733
|
+
maxGasPerTx
|
1734
|
+
} = params;
|
1649
1735
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1650
1736
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1651
1737
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1652
1738
|
}
|
1653
|
-
|
1739
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1740
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1654
1741
|
}
|
1655
1742
|
function calculateMetadataGasForTxCreate({
|
1656
1743
|
gasCosts,
|
@@ -1672,6 +1759,10 @@ function calculateMetadataGasForTxScript({
|
|
1672
1759
|
}) {
|
1673
1760
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1674
1761
|
}
|
1762
|
+
var calculateGasFee = (params) => {
|
1763
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1764
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1765
|
+
};
|
1675
1766
|
|
1676
1767
|
// src/providers/utils/json.ts
|
1677
1768
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1820,7 +1911,7 @@ var witnessify = (value) => {
|
|
1820
1911
|
// src/providers/transaction-request/transaction-request.ts
|
1821
1912
|
var BaseTransactionRequest = class {
|
1822
1913
|
/** Gas price for transaction */
|
1823
|
-
|
1914
|
+
tip;
|
1824
1915
|
/** Block until which tx cannot be included */
|
1825
1916
|
maturity;
|
1826
1917
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1839,7 +1930,7 @@ var BaseTransactionRequest = class {
|
|
1839
1930
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1840
1931
|
*/
|
1841
1932
|
constructor({
|
1842
|
-
|
1933
|
+
tip,
|
1843
1934
|
maturity,
|
1844
1935
|
maxFee,
|
1845
1936
|
witnessLimit,
|
@@ -1847,7 +1938,7 @@ var BaseTransactionRequest = class {
|
|
1847
1938
|
outputs,
|
1848
1939
|
witnesses
|
1849
1940
|
} = {}) {
|
1850
|
-
this.
|
1941
|
+
this.tip = (0, import_math7.bn)(tip);
|
1851
1942
|
this.maturity = maturity ?? 0;
|
1852
1943
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1853
1944
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1858,9 +1949,9 @@ var BaseTransactionRequest = class {
|
|
1858
1949
|
static getPolicyMeta(req) {
|
1859
1950
|
let policyTypes = 0;
|
1860
1951
|
const policies = [];
|
1861
|
-
if (req.
|
1862
|
-
policyTypes += import_transactions6.PolicyType.
|
1863
|
-
policies.push({ data: req.
|
1952
|
+
if (req.tip) {
|
1953
|
+
policyTypes += import_transactions6.PolicyType.Tip;
|
1954
|
+
policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
|
1864
1955
|
}
|
1865
1956
|
if (req.witnessLimit) {
|
1866
1957
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -2044,13 +2135,11 @@ var BaseTransactionRequest = class {
|
|
2044
2135
|
* assetId, if one it was not added yet.
|
2045
2136
|
*
|
2046
2137
|
* @param coin - Coin resource.
|
2047
|
-
* @param predicate - Predicate bytes.
|
2048
|
-
* @param predicateData - Predicate data bytes.
|
2049
2138
|
*/
|
2050
|
-
addCoinInput(coin
|
2139
|
+
addCoinInput(coin) {
|
2051
2140
|
const { assetId, owner, amount } = coin;
|
2052
2141
|
let witnessIndex;
|
2053
|
-
if (predicate) {
|
2142
|
+
if (coin.predicate) {
|
2054
2143
|
witnessIndex = 0;
|
2055
2144
|
} else {
|
2056
2145
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2065,8 +2154,7 @@ var BaseTransactionRequest = class {
|
|
2065
2154
|
amount,
|
2066
2155
|
assetId,
|
2067
2156
|
txPointer: "0x00000000000000000000000000000000",
|
2068
|
-
witnessIndex
|
2069
|
-
predicate: predicate?.bytes
|
2157
|
+
witnessIndex
|
2070
2158
|
};
|
2071
2159
|
this.pushInput(input);
|
2072
2160
|
this.addChangeOutput(owner, assetId);
|
@@ -2076,14 +2164,12 @@ var BaseTransactionRequest = class {
|
|
2076
2164
|
* baseAssetId, if one it was not added yet.
|
2077
2165
|
*
|
2078
2166
|
* @param message - Message resource.
|
2079
|
-
* @param predicate - Predicate bytes.
|
2080
|
-
* @param predicateData - Predicate data bytes.
|
2081
2167
|
*/
|
2082
|
-
addMessageInput(message
|
2168
|
+
addMessageInput(message) {
|
2083
2169
|
const { recipient, sender, amount } = message;
|
2084
2170
|
const assetId = import_configs7.BaseAssetId;
|
2085
2171
|
let witnessIndex;
|
2086
|
-
if (predicate) {
|
2172
|
+
if (message.predicate) {
|
2087
2173
|
witnessIndex = 0;
|
2088
2174
|
} else {
|
2089
2175
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2097,8 +2183,7 @@ var BaseTransactionRequest = class {
|
|
2097
2183
|
sender: sender.toB256(),
|
2098
2184
|
recipient: recipient.toB256(),
|
2099
2185
|
amount,
|
2100
|
-
witnessIndex
|
2101
|
-
predicate: predicate?.bytes
|
2186
|
+
witnessIndex
|
2102
2187
|
};
|
2103
2188
|
this.pushInput(input);
|
2104
2189
|
this.addChangeOutput(recipient, assetId);
|
@@ -2129,32 +2214,6 @@ var BaseTransactionRequest = class {
|
|
2129
2214
|
resources.forEach((resource) => this.addResource(resource));
|
2130
2215
|
return this;
|
2131
2216
|
}
|
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
|
-
}
|
2158
2217
|
/**
|
2159
2218
|
* Adds a coin output to the transaction.
|
2160
2219
|
*
|
@@ -2234,7 +2293,7 @@ var BaseTransactionRequest = class {
|
|
2234
2293
|
}
|
2235
2294
|
calculateMaxGas(chainInfo, minGas) {
|
2236
2295
|
const { consensusParameters } = chainInfo;
|
2237
|
-
const { gasPerByte } = consensusParameters;
|
2296
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2238
2297
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2239
2298
|
(acc, wit) => acc + wit.dataLength,
|
2240
2299
|
0
|
@@ -2243,7 +2302,8 @@ var BaseTransactionRequest = class {
|
|
2243
2302
|
gasPerByte,
|
2244
2303
|
minGas,
|
2245
2304
|
witnessesLength,
|
2246
|
-
witnessLimit: this.witnessLimit
|
2305
|
+
witnessLimit: this.witnessLimit,
|
2306
|
+
maxGasPerTx
|
2247
2307
|
});
|
2248
2308
|
}
|
2249
2309
|
/**
|
@@ -2261,17 +2321,20 @@ var BaseTransactionRequest = class {
|
|
2261
2321
|
});
|
2262
2322
|
const updateAssetInput = (assetId, quantity) => {
|
2263
2323
|
const assetInput = findAssetInput(assetId);
|
2324
|
+
let usedQuantity = quantity;
|
2325
|
+
if (assetId === import_configs7.BaseAssetId) {
|
2326
|
+
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2327
|
+
}
|
2264
2328
|
if (assetInput && "assetId" in assetInput) {
|
2265
2329
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2266
|
-
assetInput.amount =
|
2330
|
+
assetInput.amount = usedQuantity;
|
2267
2331
|
} else {
|
2268
2332
|
this.addResources([
|
2269
2333
|
{
|
2270
2334
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2271
|
-
amount:
|
2335
|
+
amount: usedQuantity,
|
2272
2336
|
assetId,
|
2273
2337
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2274
|
-
maturity: 0,
|
2275
2338
|
blockCreated: (0, import_math7.bn)(1),
|
2276
2339
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2277
2340
|
}
|
@@ -2303,7 +2366,7 @@ var BaseTransactionRequest = class {
|
|
2303
2366
|
toJSON() {
|
2304
2367
|
return normalizeJSON(this);
|
2305
2368
|
}
|
2306
|
-
|
2369
|
+
updatePredicateGasUsed(inputs) {
|
2307
2370
|
this.inputs.forEach((i) => {
|
2308
2371
|
let correspondingInput;
|
2309
2372
|
switch (i.type) {
|
@@ -2325,6 +2388,15 @@ var BaseTransactionRequest = class {
|
|
2325
2388
|
}
|
2326
2389
|
});
|
2327
2390
|
}
|
2391
|
+
shiftPredicateData() {
|
2392
|
+
this.inputs.forEach((input) => {
|
2393
|
+
if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
|
2394
|
+
input.predicateData = input.padPredicateData(
|
2395
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2396
|
+
);
|
2397
|
+
}
|
2398
|
+
});
|
2399
|
+
}
|
2328
2400
|
};
|
2329
2401
|
|
2330
2402
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2471,9 +2543,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2471
2543
|
return {
|
2472
2544
|
type: import_transactions8.TransactionType.Create,
|
2473
2545
|
...baseTransaction,
|
2474
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2475
2546
|
bytecodeWitnessIndex,
|
2476
|
-
storageSlotsCount: storageSlots.length,
|
2547
|
+
storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
|
2477
2548
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2478
2549
|
storageSlots
|
2479
2550
|
};
|
@@ -2596,8 +2667,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2596
2667
|
type: import_transactions9.TransactionType.Script,
|
2597
2668
|
scriptGasLimit: this.gasLimit,
|
2598
2669
|
...super.getBaseTransaction(),
|
2599
|
-
scriptLength: script.length,
|
2600
|
-
scriptDataLength: scriptData.length,
|
2670
|
+
scriptLength: (0, import_math10.bn)(script.length),
|
2671
|
+
scriptDataLength: (0, import_math10.bn)(scriptData.length),
|
2601
2672
|
receiptsRoot: import_configs10.ZeroBytes32,
|
2602
2673
|
script: (0, import_utils15.hexlify)(script),
|
2603
2674
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2661,7 +2732,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2661
2732
|
}
|
2662
2733
|
calculateMaxGas(chainInfo, minGas) {
|
2663
2734
|
const { consensusParameters } = chainInfo;
|
2664
|
-
const { gasPerByte } = consensusParameters;
|
2735
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2665
2736
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2666
2737
|
(acc, wit) => acc + wit.dataLength,
|
2667
2738
|
0
|
@@ -2671,7 +2742,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2671
2742
|
minGas,
|
2672
2743
|
witnessesLength,
|
2673
2744
|
witnessLimit: this.witnessLimit,
|
2674
|
-
gasLimit: this.gasLimit
|
2745
|
+
gasLimit: this.gasLimit,
|
2746
|
+
maxGasPerTx
|
2675
2747
|
});
|
2676
2748
|
}
|
2677
2749
|
/**
|
@@ -2746,15 +2818,32 @@ var transactionRequestify = (obj) => {
|
|
2746
2818
|
}
|
2747
2819
|
}
|
2748
2820
|
};
|
2821
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2822
|
+
(acc, input) => {
|
2823
|
+
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2824
|
+
acc.utxos.push(input.id);
|
2825
|
+
}
|
2826
|
+
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2827
|
+
acc.messages.push(input.nonce);
|
2828
|
+
}
|
2829
|
+
return acc;
|
2830
|
+
},
|
2831
|
+
{
|
2832
|
+
utxos: [],
|
2833
|
+
messages: []
|
2834
|
+
}
|
2835
|
+
);
|
2749
2836
|
|
2750
2837
|
// src/providers/transaction-response/transaction-response.ts
|
2751
2838
|
var import_errors13 = require("@fuel-ts/errors");
|
2752
|
-
var
|
2753
|
-
var
|
2754
|
-
var
|
2839
|
+
var import_math15 = require("@fuel-ts/math");
|
2840
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
2841
|
+
var import_utils20 = require("@fuel-ts/utils");
|
2755
2842
|
|
2756
2843
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2757
|
-
var
|
2844
|
+
var import_math14 = require("@fuel-ts/math");
|
2845
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2846
|
+
var import_utils18 = require("@fuel-ts/utils");
|
2758
2847
|
|
2759
2848
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2760
2849
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2762,9 +2851,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2762
2851
|
var import_utils16 = require("@fuel-ts/utils");
|
2763
2852
|
var calculateTransactionFee = (params) => {
|
2764
2853
|
const {
|
2765
|
-
|
2854
|
+
gasPrice,
|
2766
2855
|
rawPayload,
|
2767
|
-
|
2856
|
+
tip,
|
2857
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2768
2858
|
} = params;
|
2769
2859
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2770
2860
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2774,8 +2864,7 @@ var calculateTransactionFee = (params) => {
|
|
2774
2864
|
return {
|
2775
2865
|
fee: (0, import_math11.bn)(0),
|
2776
2866
|
minFee: (0, import_math11.bn)(0),
|
2777
|
-
maxFee: (0, import_math11.bn)(0)
|
2778
|
-
feeFromGasUsed: (0, import_math11.bn)(0)
|
2867
|
+
maxFee: (0, import_math11.bn)(0)
|
2779
2868
|
};
|
2780
2869
|
}
|
2781
2870
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2807,7 +2896,6 @@ var calculateTransactionFee = (params) => {
|
|
2807
2896
|
metadataGas,
|
2808
2897
|
txBytesSize: transactionBytes.length
|
2809
2898
|
});
|
2810
|
-
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2811
2899
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2812
2900
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2813
2901
|
const maxGas = getMaxGas({
|
@@ -2815,17 +2903,25 @@ var calculateTransactionFee = (params) => {
|
|
2815
2903
|
minGas,
|
2816
2904
|
witnessesLength,
|
2817
2905
|
gasLimit,
|
2818
|
-
witnessLimit
|
2906
|
+
witnessLimit,
|
2907
|
+
maxGasPerTx
|
2908
|
+
});
|
2909
|
+
const minFee = calculateGasFee({
|
2910
|
+
gasPrice,
|
2911
|
+
gas: minGas,
|
2912
|
+
priceFactor: gasPriceFactor,
|
2913
|
+
tip
|
2914
|
+
});
|
2915
|
+
const maxFee = calculateGasFee({
|
2916
|
+
gasPrice,
|
2917
|
+
gas: maxGas,
|
2918
|
+
priceFactor: gasPriceFactor,
|
2919
|
+
tip
|
2819
2920
|
});
|
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);
|
2824
2921
|
return {
|
2825
|
-
fee,
|
2826
2922
|
minFee,
|
2827
2923
|
maxFee,
|
2828
|
-
|
2924
|
+
fee: maxFee
|
2829
2925
|
};
|
2830
2926
|
};
|
2831
2927
|
|
@@ -3439,10 +3535,12 @@ function assembleTransactionSummary(params) {
|
|
3439
3535
|
gqlTransactionStatus,
|
3440
3536
|
abiMap = {},
|
3441
3537
|
maxInputs,
|
3442
|
-
gasCosts
|
3538
|
+
gasCosts,
|
3539
|
+
maxGasPerTx,
|
3540
|
+
gasPrice
|
3443
3541
|
} = params;
|
3444
3542
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3445
|
-
const rawPayload = (0,
|
3543
|
+
const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
|
3446
3544
|
const operations = getOperations({
|
3447
3545
|
transactionType: transaction.type,
|
3448
3546
|
inputs: transaction.inputs || [],
|
@@ -3453,11 +3551,14 @@ function assembleTransactionSummary(params) {
|
|
3453
3551
|
maxInputs
|
3454
3552
|
});
|
3455
3553
|
const typeName = getTransactionTypeName(transaction.type);
|
3554
|
+
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3456
3555
|
const { fee } = calculateTransactionFee({
|
3457
|
-
|
3556
|
+
gasPrice,
|
3458
3557
|
rawPayload,
|
3558
|
+
tip,
|
3459
3559
|
consensusParameters: {
|
3460
3560
|
gasCosts,
|
3561
|
+
maxGasPerTx,
|
3461
3562
|
feeParams: {
|
3462
3563
|
gasPerByte,
|
3463
3564
|
gasPriceFactor
|
@@ -3469,7 +3570,7 @@ function assembleTransactionSummary(params) {
|
|
3469
3570
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3470
3571
|
let date;
|
3471
3572
|
if (time) {
|
3472
|
-
date =
|
3573
|
+
date = import_utils18.DateTime.fromTai64(time);
|
3473
3574
|
}
|
3474
3575
|
const transactionSummary = {
|
3475
3576
|
id,
|
@@ -3497,12 +3598,12 @@ function assembleTransactionSummary(params) {
|
|
3497
3598
|
|
3498
3599
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3499
3600
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3500
|
-
var
|
3601
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
3501
3602
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3502
3603
|
return receipts.reduce((logs, receipt) => {
|
3503
|
-
if (receipt.type ===
|
3604
|
+
if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
|
3504
3605
|
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3505
|
-
const data = receipt.type ===
|
3606
|
+
const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3506
3607
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3507
3608
|
logs.push(decodedLog);
|
3508
3609
|
}
|
@@ -3517,7 +3618,7 @@ var TransactionResponse = class {
|
|
3517
3618
|
/** Current provider */
|
3518
3619
|
provider;
|
3519
3620
|
/** Gas used on the transaction */
|
3520
|
-
gasUsed = (0,
|
3621
|
+
gasUsed = (0, import_math15.bn)(0);
|
3521
3622
|
/** The graphql Transaction with receipts object. */
|
3522
3623
|
gqlTransaction;
|
3523
3624
|
abis;
|
@@ -3575,8 +3676,8 @@ var TransactionResponse = class {
|
|
3575
3676
|
* @returns The decoded transaction.
|
3576
3677
|
*/
|
3577
3678
|
decodeTransaction(transactionWithReceipts) {
|
3578
|
-
return new
|
3579
|
-
(0,
|
3679
|
+
return new import_transactions18.TransactionCoder().decode(
|
3680
|
+
(0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
|
3580
3681
|
0
|
3581
3682
|
)?.[0];
|
3582
3683
|
}
|
@@ -3595,20 +3696,27 @@ var TransactionResponse = class {
|
|
3595
3696
|
const decodedTransaction = this.decodeTransaction(
|
3596
3697
|
transaction
|
3597
3698
|
);
|
3598
|
-
|
3599
|
-
|
3699
|
+
let txReceipts = [];
|
3700
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3701
|
+
txReceipts = transaction.status.receipts;
|
3702
|
+
}
|
3703
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3704
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3705
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3600
3706
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3601
3707
|
const transactionSummary = assembleTransactionSummary({
|
3602
3708
|
id: this.id,
|
3603
3709
|
receipts,
|
3604
3710
|
transaction: decodedTransaction,
|
3605
|
-
transactionBytes: (0,
|
3711
|
+
transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
|
3606
3712
|
gqlTransactionStatus: transaction.status,
|
3607
3713
|
gasPerByte,
|
3608
3714
|
gasPriceFactor,
|
3609
3715
|
abiMap: contractsAbiMap,
|
3610
3716
|
maxInputs,
|
3611
|
-
gasCosts
|
3717
|
+
gasCosts,
|
3718
|
+
maxGasPerTx,
|
3719
|
+
gasPrice
|
3612
3720
|
});
|
3613
3721
|
return transactionSummary;
|
3614
3722
|
}
|
@@ -3735,29 +3843,29 @@ var processGqlChain = (chain) => {
|
|
3735
3843
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3736
3844
|
return {
|
3737
3845
|
name,
|
3738
|
-
baseChainHeight: (0,
|
3846
|
+
baseChainHeight: (0, import_math16.bn)(daHeight),
|
3739
3847
|
consensusParameters: {
|
3740
|
-
contractMaxSize: (0,
|
3741
|
-
maxInputs: (0,
|
3742
|
-
maxOutputs: (0,
|
3743
|
-
maxWitnesses: (0,
|
3744
|
-
maxGasPerTx: (0,
|
3745
|
-
maxScriptLength: (0,
|
3746
|
-
maxScriptDataLength: (0,
|
3747
|
-
maxStorageSlots: (0,
|
3748
|
-
maxPredicateLength: (0,
|
3749
|
-
maxPredicateDataLength: (0,
|
3750
|
-
maxGasPerPredicate: (0,
|
3751
|
-
gasPriceFactor: (0,
|
3752
|
-
gasPerByte: (0,
|
3753
|
-
maxMessageDataLength: (0,
|
3754
|
-
chainId: (0,
|
3848
|
+
contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
|
3849
|
+
maxInputs: (0, import_math16.bn)(txParams.maxInputs),
|
3850
|
+
maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
|
3851
|
+
maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
|
3852
|
+
maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
|
3853
|
+
maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
|
3854
|
+
maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
|
3855
|
+
maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
|
3856
|
+
maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
|
3857
|
+
maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
|
3858
|
+
maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
|
3859
|
+
gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
|
3860
|
+
gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
|
3861
|
+
maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
|
3862
|
+
chainId: (0, import_math16.bn)(consensusParameters.chainId),
|
3755
3863
|
gasCosts
|
3756
3864
|
},
|
3757
3865
|
gasCosts,
|
3758
3866
|
latestBlock: {
|
3759
3867
|
id: latestBlock.id,
|
3760
|
-
height: (0,
|
3868
|
+
height: (0, import_math16.bn)(latestBlock.height),
|
3761
3869
|
time: latestBlock.header.time,
|
3762
3870
|
transactions: latestBlock.transactions.map((i) => ({
|
3763
3871
|
id: i.id
|
@@ -3851,10 +3959,8 @@ var _Provider = class {
|
|
3851
3959
|
* Returns some helpful parameters related to gas fees.
|
3852
3960
|
*/
|
3853
3961
|
getGasConfig() {
|
3854
|
-
const { minGasPrice } = this.getNode();
|
3855
3962
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3856
3963
|
return {
|
3857
|
-
minGasPrice,
|
3858
3964
|
maxGasPerTx,
|
3859
3965
|
maxGasPerPredicate,
|
3860
3966
|
gasPriceFactor,
|
@@ -3952,7 +4058,7 @@ var _Provider = class {
|
|
3952
4058
|
*/
|
3953
4059
|
async getBlockNumber() {
|
3954
4060
|
const { chain } = await this.operations.getChain();
|
3955
|
-
return (0,
|
4061
|
+
return (0, import_math16.bn)(chain.latestBlock.height, 10);
|
3956
4062
|
}
|
3957
4063
|
/**
|
3958
4064
|
* Returns the chain information.
|
@@ -3962,13 +4068,11 @@ var _Provider = class {
|
|
3962
4068
|
async fetchNode() {
|
3963
4069
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3964
4070
|
const processedNodeInfo = {
|
3965
|
-
maxDepth: (0,
|
3966
|
-
maxTx: (0,
|
3967
|
-
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
4071
|
+
maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
|
4072
|
+
maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
|
3968
4073
|
nodeVersion: nodeInfo.nodeVersion,
|
3969
4074
|
utxoValidation: nodeInfo.utxoValidation,
|
3970
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3971
|
-
peers: nodeInfo.peers
|
4075
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3972
4076
|
};
|
3973
4077
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3974
4078
|
return processedNodeInfo;
|
@@ -4010,9 +4114,9 @@ var _Provider = class {
|
|
4010
4114
|
if (estimateTxDependencies) {
|
4011
4115
|
await this.estimateTxDependencies(transactionRequest);
|
4012
4116
|
}
|
4013
|
-
const encodedTransaction = (0,
|
4117
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4014
4118
|
let abis;
|
4015
|
-
if (transactionRequest.type ===
|
4119
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4016
4120
|
abis = transactionRequest.abis;
|
4017
4121
|
}
|
4018
4122
|
if (awaitExecution) {
|
@@ -4053,15 +4157,14 @@ var _Provider = class {
|
|
4053
4157
|
if (estimateTxDependencies) {
|
4054
4158
|
return this.estimateTxDependencies(transactionRequest);
|
4055
4159
|
}
|
4056
|
-
const encodedTransaction = (0,
|
4057
|
-
const { dryRun:
|
4058
|
-
encodedTransaction,
|
4160
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4161
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4162
|
+
encodedTransactions: encodedTransaction,
|
4059
4163
|
utxoValidation: utxoValidation || false
|
4060
4164
|
});
|
4061
|
-
const receipts =
|
4062
|
-
|
4063
|
-
|
4064
|
-
};
|
4165
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
4166
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4167
|
+
return { receipts, dryrunStatus: status };
|
4065
4168
|
}
|
4066
4169
|
/**
|
4067
4170
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4072,13 +4175,13 @@ var _Provider = class {
|
|
4072
4175
|
async estimatePredicates(transactionRequest) {
|
4073
4176
|
const shouldEstimatePredicates = Boolean(
|
4074
4177
|
transactionRequest.inputs.find(
|
4075
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4178
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math16.BN(input.predicateGasUsed).isZero()
|
4076
4179
|
)
|
4077
4180
|
);
|
4078
4181
|
if (!shouldEstimatePredicates) {
|
4079
4182
|
return transactionRequest;
|
4080
4183
|
}
|
4081
|
-
const encodedTransaction = (0,
|
4184
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4082
4185
|
const response = await this.operations.estimatePredicates({
|
4083
4186
|
encodedTransaction
|
4084
4187
|
});
|
@@ -4087,7 +4190,7 @@ var _Provider = class {
|
|
4087
4190
|
} = response;
|
4088
4191
|
if (inputs) {
|
4089
4192
|
inputs.forEach((input, index) => {
|
4090
|
-
if ("predicateGasUsed" in input && (0,
|
4193
|
+
if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
|
4091
4194
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4092
4195
|
}
|
4093
4196
|
});
|
@@ -4100,31 +4203,31 @@ var _Provider = class {
|
|
4100
4203
|
* If there are missing variable outputs,
|
4101
4204
|
* `addVariableOutputs` is called on the transaction.
|
4102
4205
|
*
|
4103
|
-
* @privateRemarks
|
4104
|
-
* TODO: Investigate support for missing contract IDs
|
4105
|
-
* TODO: Add support for missing output messages
|
4106
4206
|
*
|
4107
4207
|
* @param transactionRequest - The transaction request object.
|
4108
4208
|
* @returns A promise.
|
4109
4209
|
*/
|
4110
4210
|
async estimateTxDependencies(transactionRequest) {
|
4111
|
-
if (transactionRequest.type ===
|
4211
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Create) {
|
4112
4212
|
return {
|
4113
4213
|
receipts: [],
|
4114
4214
|
outputVariables: 0,
|
4115
4215
|
missingContractIds: []
|
4116
4216
|
};
|
4117
4217
|
}
|
4118
|
-
await this.estimatePredicates(transactionRequest);
|
4119
4218
|
let receipts = [];
|
4120
4219
|
const missingContractIds = [];
|
4121
4220
|
let outputVariables = 0;
|
4221
|
+
let dryrunStatus;
|
4122
4222
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4123
|
-
const {
|
4124
|
-
|
4223
|
+
const {
|
4224
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4225
|
+
} = await this.operations.dryRun({
|
4226
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4125
4227
|
utxoValidation: false
|
4126
4228
|
});
|
4127
|
-
receipts =
|
4229
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4230
|
+
dryrunStatus = status;
|
4128
4231
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4129
4232
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4130
4233
|
if (hasMissingOutputs) {
|
@@ -4134,6 +4237,10 @@ var _Provider = class {
|
|
4134
4237
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4135
4238
|
missingContractIds.push(contractId);
|
4136
4239
|
});
|
4240
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4241
|
+
transactionRequest
|
4242
|
+
});
|
4243
|
+
transactionRequest.maxFee = maxFee;
|
4137
4244
|
} else {
|
4138
4245
|
break;
|
4139
4246
|
}
|
@@ -4141,37 +4248,136 @@ var _Provider = class {
|
|
4141
4248
|
return {
|
4142
4249
|
receipts,
|
4143
4250
|
outputVariables,
|
4144
|
-
missingContractIds
|
4251
|
+
missingContractIds,
|
4252
|
+
dryrunStatus
|
4145
4253
|
};
|
4146
4254
|
}
|
4255
|
+
/**
|
4256
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4257
|
+
*
|
4258
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4259
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4260
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4261
|
+
*
|
4262
|
+
* @param transactionRequests - Array of transaction request objects.
|
4263
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4264
|
+
*/
|
4265
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4266
|
+
const results = transactionRequests.map(() => ({
|
4267
|
+
receipts: [],
|
4268
|
+
outputVariables: 0,
|
4269
|
+
missingContractIds: [],
|
4270
|
+
dryrunStatus: void 0
|
4271
|
+
}));
|
4272
|
+
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4273
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4274
|
+
allRequests.forEach((req, index) => {
|
4275
|
+
if (req.type === import_transactions19.TransactionType.Script) {
|
4276
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4277
|
+
}
|
4278
|
+
});
|
4279
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4280
|
+
let attempt = 0;
|
4281
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4282
|
+
const encodedTransactions = transactionsToProcess.map(
|
4283
|
+
(index) => serializedTransactionsMap.get(index)
|
4284
|
+
);
|
4285
|
+
const dryRunResults = await this.operations.dryRun({
|
4286
|
+
encodedTransactions,
|
4287
|
+
utxoValidation: false
|
4288
|
+
});
|
4289
|
+
const nextRoundTransactions = [];
|
4290
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4291
|
+
const requestIdx = transactionsToProcess[i];
|
4292
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4293
|
+
const result = results[requestIdx];
|
4294
|
+
result.receipts = rawReceipts.map(processGqlReceipt);
|
4295
|
+
result.dryrunStatus = status;
|
4296
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4297
|
+
result.receipts
|
4298
|
+
);
|
4299
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4300
|
+
const request = allRequests[requestIdx];
|
4301
|
+
if (hasMissingOutputs && request?.type === import_transactions19.TransactionType.Script) {
|
4302
|
+
result.outputVariables += missingOutputVariables.length;
|
4303
|
+
request.addVariableOutputs(missingOutputVariables.length);
|
4304
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4305
|
+
request.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4306
|
+
result.missingContractIds.push(contractId);
|
4307
|
+
});
|
4308
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4309
|
+
transactionRequest: request
|
4310
|
+
});
|
4311
|
+
request.maxFee = maxFee;
|
4312
|
+
serializedTransactionsMap.set(requestIdx, (0, import_utils22.hexlify)(request.toTransactionBytes()));
|
4313
|
+
nextRoundTransactions.push(requestIdx);
|
4314
|
+
}
|
4315
|
+
}
|
4316
|
+
transactionsToProcess = nextRoundTransactions;
|
4317
|
+
attempt += 1;
|
4318
|
+
}
|
4319
|
+
return results;
|
4320
|
+
}
|
4321
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4322
|
+
if (estimateTxDependencies) {
|
4323
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4324
|
+
}
|
4325
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4326
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4327
|
+
encodedTransactions,
|
4328
|
+
utxoValidation: utxoValidation || false
|
4329
|
+
});
|
4330
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4331
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4332
|
+
return { receipts, dryrunStatus: status };
|
4333
|
+
});
|
4334
|
+
return results;
|
4335
|
+
}
|
4147
4336
|
/**
|
4148
4337
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4149
4338
|
* @param transactionRequest - The transaction request object.
|
4150
4339
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4151
4340
|
*/
|
4152
|
-
estimateTxGasAndFee(params) {
|
4341
|
+
async estimateTxGasAndFee(params) {
|
4153
4342
|
const { transactionRequest } = params;
|
4154
|
-
|
4343
|
+
let { gasPrice } = params;
|
4155
4344
|
const chainInfo = this.getChain();
|
4156
|
-
const
|
4157
|
-
transactionRequest.gasPrice = gasPrice;
|
4345
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
4158
4346
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4159
|
-
|
4160
|
-
|
4347
|
+
if (!gasPrice) {
|
4348
|
+
gasPrice = await this.estimateGasPrice(10);
|
4349
|
+
}
|
4350
|
+
const minFee = calculateGasFee({
|
4351
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4352
|
+
gas: minGas,
|
4353
|
+
priceFactor: gasPriceFactor,
|
4354
|
+
tip: transactionRequest.tip
|
4355
|
+
}).add(1);
|
4356
|
+
let gasLimit = (0, import_math16.bn)(0);
|
4357
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4358
|
+
gasLimit = transactionRequest.gasLimit;
|
4161
4359
|
if (transactionRequest.gasLimit.eq(0)) {
|
4162
4360
|
transactionRequest.gasLimit = minGas;
|
4163
4361
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4164
4362
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4165
4363
|
);
|
4364
|
+
gasLimit = transactionRequest.gasLimit;
|
4166
4365
|
}
|
4167
4366
|
}
|
4168
4367
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4169
|
-
const maxFee =
|
4368
|
+
const maxFee = calculateGasFee({
|
4369
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4370
|
+
gas: maxGas,
|
4371
|
+
priceFactor: gasPriceFactor,
|
4372
|
+
tip: transactionRequest.tip
|
4373
|
+
}).add(1);
|
4170
4374
|
return {
|
4171
4375
|
minGas,
|
4172
4376
|
minFee,
|
4173
4377
|
maxGas,
|
4174
|
-
maxFee
|
4378
|
+
maxFee,
|
4379
|
+
gasPrice,
|
4380
|
+
gasLimit
|
4175
4381
|
};
|
4176
4382
|
}
|
4177
4383
|
/**
|
@@ -4189,15 +4395,17 @@ var _Provider = class {
|
|
4189
4395
|
if (estimateTxDependencies) {
|
4190
4396
|
return this.estimateTxDependencies(transactionRequest);
|
4191
4397
|
}
|
4192
|
-
const
|
4193
|
-
const { dryRun:
|
4194
|
-
|
4398
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4399
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4400
|
+
encodedTransactions,
|
4195
4401
|
utxoValidation: true
|
4196
4402
|
});
|
4197
|
-
const
|
4198
|
-
|
4199
|
-
receipts
|
4200
|
-
|
4403
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4404
|
+
const { id, receipts, status } = dryRunStatus;
|
4405
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4406
|
+
return { id, receipts: processedReceipts, status };
|
4407
|
+
});
|
4408
|
+
return { receipts: callResult[0].receipts };
|
4201
4409
|
}
|
4202
4410
|
/**
|
4203
4411
|
* Returns a transaction cost to enable user
|
@@ -4214,77 +4422,79 @@ var _Provider = class {
|
|
4214
4422
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4215
4423
|
* @returns A promise that resolves to the transaction cost object.
|
4216
4424
|
*/
|
4217
|
-
async getTransactionCost(transactionRequestLike,
|
4218
|
-
estimateTxDependencies = true,
|
4219
|
-
estimatePredicates = true,
|
4220
|
-
resourcesOwner,
|
4221
|
-
signatureCallback
|
4222
|
-
} = {}) {
|
4425
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
4223
4426
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4224
|
-
const
|
4225
|
-
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4226
|
-
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4427
|
+
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
4227
4428
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4228
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4429
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4229
4430
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4431
|
+
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4230
4432
|
if (isScriptTransaction) {
|
4231
|
-
txRequestClone.gasLimit = (0,
|
4433
|
+
txRequestClone.gasLimit = (0, import_math16.bn)(0);
|
4232
4434
|
}
|
4233
|
-
if (
|
4234
|
-
|
4235
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4236
|
-
}
|
4237
|
-
await this.estimatePredicates(txRequestClone);
|
4435
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4436
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4238
4437
|
}
|
4438
|
+
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4439
|
+
let addedSignatures = 0;
|
4239
4440
|
if (signatureCallback && isScriptTransaction) {
|
4240
|
-
|
4441
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4442
|
+
await signatureCallback(signedRequest);
|
4443
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4241
4444
|
}
|
4242
|
-
|
4243
|
-
|
4445
|
+
await this.estimatePredicates(signedRequest);
|
4446
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4447
|
+
transactionRequest: signedRequest
|
4244
4448
|
});
|
4245
4449
|
let receipts = [];
|
4246
4450
|
let missingContractIds = [];
|
4247
4451
|
let outputVariables = 0;
|
4248
|
-
let gasUsed = (0,
|
4249
|
-
|
4250
|
-
|
4452
|
+
let gasUsed = (0, import_math16.bn)(0);
|
4453
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4454
|
+
txRequestClone.maxFee = maxFee;
|
4455
|
+
if (isScriptTransaction) {
|
4456
|
+
txRequestClone.gasLimit = gasLimit;
|
4457
|
+
if (signatureCallback) {
|
4458
|
+
await signatureCallback(txRequestClone);
|
4459
|
+
}
|
4251
4460
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4252
4461
|
receipts = result.receipts;
|
4253
4462
|
outputVariables = result.outputVariables;
|
4254
4463
|
missingContractIds = result.missingContractIds;
|
4255
4464
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4256
4465
|
txRequestClone.gasLimit = gasUsed;
|
4257
|
-
|
4258
|
-
|
4259
|
-
|
4466
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4467
|
+
transactionRequest: txRequestClone,
|
4468
|
+
gasPrice
|
4260
4469
|
}));
|
4261
4470
|
}
|
4262
4471
|
return {
|
4263
4472
|
requiredQuantities: allQuantities,
|
4264
4473
|
receipts,
|
4265
4474
|
gasUsed,
|
4266
|
-
|
4267
|
-
gasPrice: setGasPrice,
|
4475
|
+
gasPrice,
|
4268
4476
|
minGas,
|
4269
4477
|
maxGas,
|
4270
4478
|
minFee,
|
4271
4479
|
maxFee,
|
4272
|
-
estimatedInputs: txRequestClone.inputs,
|
4273
4480
|
outputVariables,
|
4274
|
-
missingContractIds
|
4481
|
+
missingContractIds,
|
4482
|
+
addedSignatures,
|
4483
|
+
estimatedPredicates: txRequestClone.inputs
|
4275
4484
|
};
|
4276
4485
|
}
|
4277
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4486
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4278
4487
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4279
4488
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4280
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4489
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4490
|
+
quantitiesToContract
|
4491
|
+
});
|
4281
4492
|
transactionRequest.addResources(
|
4282
4493
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4283
4494
|
);
|
4284
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4285
|
-
|
4286
|
-
|
4287
|
-
);
|
4495
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4496
|
+
quantitiesToContract
|
4497
|
+
});
|
4288
4498
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4289
4499
|
return {
|
4290
4500
|
resources,
|
@@ -4300,17 +4510,16 @@ var _Provider = class {
|
|
4300
4510
|
const result = await this.operations.getCoins({
|
4301
4511
|
first: 10,
|
4302
4512
|
...paginationArgs,
|
4303
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4513
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4304
4514
|
});
|
4305
4515
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4306
4516
|
return coins.map((coin) => ({
|
4307
4517
|
id: coin.utxoId,
|
4308
4518
|
assetId: coin.assetId,
|
4309
|
-
amount: (0,
|
4519
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4310
4520
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4311
|
-
|
4312
|
-
|
4313
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4521
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4522
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4314
4523
|
}));
|
4315
4524
|
}
|
4316
4525
|
/**
|
@@ -4324,19 +4533,19 @@ var _Provider = class {
|
|
4324
4533
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4325
4534
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4326
4535
|
const excludeInput = {
|
4327
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4328
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4536
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4537
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4329
4538
|
};
|
4330
4539
|
if (this.cache) {
|
4331
4540
|
const uniqueUtxos = new Set(
|
4332
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4541
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4333
4542
|
);
|
4334
4543
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4335
4544
|
}
|
4336
4545
|
const coinsQuery = {
|
4337
4546
|
owner: ownerAddress.toB256(),
|
4338
4547
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4339
|
-
assetId: (0,
|
4548
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4340
4549
|
amount: amount.toString(10),
|
4341
4550
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4342
4551
|
})),
|
@@ -4347,9 +4556,9 @@ var _Provider = class {
|
|
4347
4556
|
switch (coin.__typename) {
|
4348
4557
|
case "MessageCoin":
|
4349
4558
|
return {
|
4350
|
-
amount: (0,
|
4559
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4351
4560
|
assetId: coin.assetId,
|
4352
|
-
daHeight: (0,
|
4561
|
+
daHeight: (0, import_math16.bn)(coin.daHeight),
|
4353
4562
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4354
4563
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4355
4564
|
nonce: coin.nonce
|
@@ -4357,12 +4566,11 @@ var _Provider = class {
|
|
4357
4566
|
case "Coin":
|
4358
4567
|
return {
|
4359
4568
|
id: coin.utxoId,
|
4360
|
-
amount: (0,
|
4569
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4361
4570
|
assetId: coin.assetId,
|
4362
4571
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4363
|
-
|
4364
|
-
|
4365
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4572
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4573
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4366
4574
|
};
|
4367
4575
|
default:
|
4368
4576
|
return null;
|
@@ -4379,13 +4587,13 @@ var _Provider = class {
|
|
4379
4587
|
async getBlock(idOrHeight) {
|
4380
4588
|
let variables;
|
4381
4589
|
if (typeof idOrHeight === "number") {
|
4382
|
-
variables = { height: (0,
|
4590
|
+
variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4383
4591
|
} else if (idOrHeight === "latest") {
|
4384
4592
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4385
4593
|
} else if (idOrHeight.length === 66) {
|
4386
4594
|
variables = { blockId: idOrHeight };
|
4387
4595
|
} else {
|
4388
|
-
variables = { blockId: (0,
|
4596
|
+
variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4389
4597
|
}
|
4390
4598
|
const { block } = await this.operations.getBlock(variables);
|
4391
4599
|
if (!block) {
|
@@ -4393,7 +4601,7 @@ var _Provider = class {
|
|
4393
4601
|
}
|
4394
4602
|
return {
|
4395
4603
|
id: block.id,
|
4396
|
-
height: (0,
|
4604
|
+
height: (0, import_math16.bn)(block.height),
|
4397
4605
|
time: block.header.time,
|
4398
4606
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4399
4607
|
};
|
@@ -4408,7 +4616,7 @@ var _Provider = class {
|
|
4408
4616
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4409
4617
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4410
4618
|
id: block.id,
|
4411
|
-
height: (0,
|
4619
|
+
height: (0, import_math16.bn)(block.height),
|
4412
4620
|
time: block.header.time,
|
4413
4621
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4414
4622
|
}));
|
@@ -4423,7 +4631,7 @@ var _Provider = class {
|
|
4423
4631
|
async getBlockWithTransactions(idOrHeight) {
|
4424
4632
|
let variables;
|
4425
4633
|
if (typeof idOrHeight === "number") {
|
4426
|
-
variables = { blockHeight: (0,
|
4634
|
+
variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4427
4635
|
} else if (idOrHeight === "latest") {
|
4428
4636
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4429
4637
|
} else {
|
@@ -4435,11 +4643,11 @@ var _Provider = class {
|
|
4435
4643
|
}
|
4436
4644
|
return {
|
4437
4645
|
id: block.id,
|
4438
|
-
height: (0,
|
4646
|
+
height: (0, import_math16.bn)(block.height, 10),
|
4439
4647
|
time: block.header.time,
|
4440
4648
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4441
4649
|
transactions: block.transactions.map(
|
4442
|
-
(tx) => new
|
4650
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4443
4651
|
)
|
4444
4652
|
};
|
4445
4653
|
}
|
@@ -4454,8 +4662,8 @@ var _Provider = class {
|
|
4454
4662
|
if (!transaction) {
|
4455
4663
|
return null;
|
4456
4664
|
}
|
4457
|
-
return new
|
4458
|
-
(0,
|
4665
|
+
return new import_transactions19.TransactionCoder().decode(
|
4666
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4459
4667
|
0
|
4460
4668
|
)?.[0];
|
4461
4669
|
}
|
@@ -4482,9 +4690,9 @@ var _Provider = class {
|
|
4482
4690
|
async getContractBalance(contractId, assetId) {
|
4483
4691
|
const { contractBalance } = await this.operations.getContractBalance({
|
4484
4692
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4485
|
-
asset: (0,
|
4693
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4486
4694
|
});
|
4487
|
-
return (0,
|
4695
|
+
return (0, import_math16.bn)(contractBalance.amount, 10);
|
4488
4696
|
}
|
4489
4697
|
/**
|
4490
4698
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4496,9 +4704,9 @@ var _Provider = class {
|
|
4496
4704
|
async getBalance(owner, assetId) {
|
4497
4705
|
const { balance } = await this.operations.getBalance({
|
4498
4706
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4499
|
-
assetId: (0,
|
4707
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4500
4708
|
});
|
4501
|
-
return (0,
|
4709
|
+
return (0, import_math16.bn)(balance.amount, 10);
|
4502
4710
|
}
|
4503
4711
|
/**
|
4504
4712
|
* Returns balances for the given owner.
|
@@ -4516,7 +4724,7 @@ var _Provider = class {
|
|
4516
4724
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4517
4725
|
return balances.map((balance) => ({
|
4518
4726
|
assetId: balance.assetId,
|
4519
|
-
amount: (0,
|
4727
|
+
amount: (0, import_math16.bn)(balance.amount)
|
4520
4728
|
}));
|
4521
4729
|
}
|
4522
4730
|
/**
|
@@ -4534,19 +4742,19 @@ var _Provider = class {
|
|
4534
4742
|
});
|
4535
4743
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4536
4744
|
return messages.map((message) => ({
|
4537
|
-
messageId:
|
4745
|
+
messageId: import_transactions19.InputMessageCoder.getMessageId({
|
4538
4746
|
sender: message.sender,
|
4539
4747
|
recipient: message.recipient,
|
4540
4748
|
nonce: message.nonce,
|
4541
|
-
amount: (0,
|
4749
|
+
amount: (0, import_math16.bn)(message.amount),
|
4542
4750
|
data: message.data
|
4543
4751
|
}),
|
4544
4752
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4545
4753
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4546
4754
|
nonce: message.nonce,
|
4547
|
-
amount: (0,
|
4548
|
-
data:
|
4549
|
-
daHeight: (0,
|
4755
|
+
amount: (0, import_math16.bn)(message.amount),
|
4756
|
+
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4757
|
+
daHeight: (0, import_math16.bn)(message.daHeight)
|
4550
4758
|
}));
|
4551
4759
|
}
|
4552
4760
|
/**
|
@@ -4599,44 +4807,60 @@ var _Provider = class {
|
|
4599
4807
|
} = result.messageProof;
|
4600
4808
|
return {
|
4601
4809
|
messageProof: {
|
4602
|
-
proofIndex: (0,
|
4810
|
+
proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
|
4603
4811
|
proofSet: messageProof.proofSet
|
4604
4812
|
},
|
4605
4813
|
blockProof: {
|
4606
|
-
proofIndex: (0,
|
4814
|
+
proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
|
4607
4815
|
proofSet: blockProof.proofSet
|
4608
4816
|
},
|
4609
4817
|
messageBlockHeader: {
|
4610
4818
|
id: messageBlockHeader.id,
|
4611
|
-
daHeight: (0,
|
4612
|
-
transactionsCount: (0,
|
4819
|
+
daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
|
4820
|
+
transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
|
4613
4821
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4614
|
-
height: (0,
|
4822
|
+
height: (0, import_math16.bn)(messageBlockHeader.height),
|
4615
4823
|
prevRoot: messageBlockHeader.prevRoot,
|
4616
4824
|
time: messageBlockHeader.time,
|
4617
4825
|
applicationHash: messageBlockHeader.applicationHash,
|
4618
|
-
|
4619
|
-
|
4826
|
+
messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
|
4827
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4828
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4829
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4830
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4620
4831
|
},
|
4621
4832
|
commitBlockHeader: {
|
4622
4833
|
id: commitBlockHeader.id,
|
4623
|
-
daHeight: (0,
|
4624
|
-
transactionsCount: (0,
|
4834
|
+
daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
|
4835
|
+
transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
|
4625
4836
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4626
|
-
height: (0,
|
4837
|
+
height: (0, import_math16.bn)(commitBlockHeader.height),
|
4627
4838
|
prevRoot: commitBlockHeader.prevRoot,
|
4628
4839
|
time: commitBlockHeader.time,
|
4629
4840
|
applicationHash: commitBlockHeader.applicationHash,
|
4630
|
-
|
4631
|
-
|
4841
|
+
messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
|
4842
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4843
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4844
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4845
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4632
4846
|
},
|
4633
4847
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4634
4848
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4635
4849
|
nonce,
|
4636
|
-
amount: (0,
|
4850
|
+
amount: (0, import_math16.bn)(amount),
|
4637
4851
|
data
|
4638
4852
|
};
|
4639
4853
|
}
|
4854
|
+
async getLatestGasPrice() {
|
4855
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4856
|
+
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4857
|
+
}
|
4858
|
+
async estimateGasPrice(blockHorizon) {
|
4859
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4860
|
+
blockHorizon: String(blockHorizon)
|
4861
|
+
});
|
4862
|
+
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4863
|
+
}
|
4640
4864
|
/**
|
4641
4865
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4642
4866
|
*
|
@@ -4656,10 +4880,10 @@ var _Provider = class {
|
|
4656
4880
|
*/
|
4657
4881
|
async produceBlocks(amount, startTime) {
|
4658
4882
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4659
|
-
blocksToProduce: (0,
|
4660
|
-
startTimestamp: startTime ?
|
4883
|
+
blocksToProduce: (0, import_math16.bn)(amount).toString(10),
|
4884
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4661
4885
|
});
|
4662
|
-
return (0,
|
4886
|
+
return (0, import_math16.bn)(latestBlockHeight);
|
4663
4887
|
}
|
4664
4888
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4665
4889
|
async getTransactionResponse(transactionId) {
|
@@ -4673,7 +4897,7 @@ cacheInputs_fn = function(inputs) {
|
|
4673
4897
|
return;
|
4674
4898
|
}
|
4675
4899
|
inputs.forEach((input) => {
|
4676
|
-
if (input.type ===
|
4900
|
+
if (input.type === import_transactions19.InputType.Coin) {
|
4677
4901
|
this.cache?.set(input.id);
|
4678
4902
|
}
|
4679
4903
|
});
|
@@ -4683,9 +4907,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4683
4907
|
|
4684
4908
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4685
4909
|
var import_errors15 = require("@fuel-ts/errors");
|
4686
|
-
var
|
4687
|
-
var
|
4688
|
-
var
|
4910
|
+
var import_math17 = require("@fuel-ts/math");
|
4911
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
4912
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4689
4913
|
async function getTransactionSummary(params) {
|
4690
4914
|
const { id, provider, abiMap } = params;
|
4691
4915
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -4697,25 +4921,32 @@ async function getTransactionSummary(params) {
|
|
4697
4921
|
`Transaction not found for given id: ${id}.`
|
4698
4922
|
);
|
4699
4923
|
}
|
4700
|
-
const [decodedTransaction] = new
|
4701
|
-
(0,
|
4924
|
+
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
|
4925
|
+
(0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4702
4926
|
0
|
4703
4927
|
);
|
4704
|
-
|
4928
|
+
let txReceipts = [];
|
4929
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4930
|
+
txReceipts = gqlTransaction.status.receipts;
|
4931
|
+
}
|
4932
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4705
4933
|
const {
|
4706
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4934
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4707
4935
|
} = provider.getChain();
|
4936
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4708
4937
|
const transactionInfo = assembleTransactionSummary({
|
4709
4938
|
id: gqlTransaction.id,
|
4710
4939
|
receipts,
|
4711
4940
|
transaction: decodedTransaction,
|
4712
|
-
transactionBytes: (0,
|
4941
|
+
transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4713
4942
|
gqlTransactionStatus: gqlTransaction.status,
|
4714
|
-
gasPerByte: (0,
|
4715
|
-
gasPriceFactor: (0,
|
4943
|
+
gasPerByte: (0, import_math17.bn)(gasPerByte),
|
4944
|
+
gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
|
4716
4945
|
abiMap,
|
4717
4946
|
maxInputs,
|
4718
|
-
gasCosts
|
4947
|
+
gasCosts,
|
4948
|
+
maxGasPerTx,
|
4949
|
+
gasPrice
|
4719
4950
|
});
|
4720
4951
|
return {
|
4721
4952
|
gqlTransaction,
|
@@ -4725,10 +4956,11 @@ async function getTransactionSummary(params) {
|
|
4725
4956
|
async function getTransactionSummaryFromRequest(params) {
|
4726
4957
|
const { provider, transactionRequest, abiMap } = params;
|
4727
4958
|
const { receipts } = await provider.call(transactionRequest);
|
4728
|
-
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4959
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
|
4729
4960
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4730
4961
|
const transaction = transactionRequest.toTransaction();
|
4731
4962
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4963
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4732
4964
|
const transactionSummary = assembleTransactionSummary({
|
4733
4965
|
receipts,
|
4734
4966
|
transaction,
|
@@ -4737,7 +4969,9 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4737
4969
|
gasPerByte,
|
4738
4970
|
gasPriceFactor,
|
4739
4971
|
maxInputs,
|
4740
|
-
gasCosts
|
4972
|
+
gasCosts,
|
4973
|
+
maxGasPerTx,
|
4974
|
+
gasPrice
|
4741
4975
|
});
|
4742
4976
|
return transactionSummary;
|
4743
4977
|
}
|
@@ -4746,24 +4980,31 @@ async function getTransactionsSummaries(params) {
|
|
4746
4980
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4747
4981
|
const { edges, pageInfo } = transactionsByOwner;
|
4748
4982
|
const {
|
4749
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4983
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4750
4984
|
} = provider.getChain();
|
4985
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4751
4986
|
const transactions = edges.map((edge) => {
|
4752
4987
|
const { node: gqlTransaction } = edge;
|
4753
|
-
const { id, rawPayload,
|
4754
|
-
const [decodedTransaction] = new
|
4755
|
-
|
4988
|
+
const { id, rawPayload, status } = gqlTransaction;
|
4989
|
+
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
|
4990
|
+
let txReceipts = [];
|
4991
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4992
|
+
txReceipts = gqlTransaction.status.receipts;
|
4993
|
+
}
|
4994
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4756
4995
|
const transactionSummary = assembleTransactionSummary({
|
4757
4996
|
id,
|
4758
4997
|
receipts,
|
4759
4998
|
transaction: decodedTransaction,
|
4760
|
-
transactionBytes: (0,
|
4999
|
+
transactionBytes: (0, import_utils25.arrayify)(rawPayload),
|
4761
5000
|
gqlTransactionStatus: status,
|
4762
5001
|
abiMap,
|
4763
5002
|
gasPerByte,
|
4764
5003
|
gasPriceFactor,
|
4765
5004
|
maxInputs,
|
4766
|
-
gasCosts
|
5005
|
+
gasCosts,
|
5006
|
+
maxGasPerTx,
|
5007
|
+
gasPrice
|
4767
5008
|
});
|
4768
5009
|
const output = {
|
4769
5010
|
gqlTransaction,
|
@@ -4900,17 +5141,17 @@ var assets = [
|
|
4900
5141
|
|
4901
5142
|
// src/utils/formatTransferToContractScriptData.ts
|
4902
5143
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4903
|
-
var
|
4904
|
-
var
|
5144
|
+
var import_math18 = require("@fuel-ts/math");
|
5145
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4905
5146
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4906
5147
|
var formatTransferToContractScriptData = (params) => {
|
4907
5148
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4908
5149
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4909
|
-
const encoded = numberCoder.encode(new
|
5150
|
+
const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
|
4910
5151
|
const scriptData = Uint8Array.from([
|
4911
|
-
...(0,
|
5152
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4912
5153
|
...encoded,
|
4913
|
-
...(0,
|
5154
|
+
...(0, import_utils26.arrayify)(assetId)
|
4914
5155
|
]);
|
4915
5156
|
return scriptData;
|
4916
5157
|
};
|
@@ -5095,36 +5336,33 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5095
5336
|
* @param fee - The estimated transaction fee.
|
5096
5337
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5097
5338
|
*/
|
5098
|
-
async fund(request,
|
5099
|
-
const
|
5100
|
-
|
5339
|
+
async fund(request, params) {
|
5340
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5341
|
+
const txRequest = request;
|
5342
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5343
|
+
amount: (0, import_math19.bn)(fee),
|
5101
5344
|
assetId: import_configs12.BaseAssetId,
|
5102
|
-
coinQuantities
|
5345
|
+
coinQuantities: requiredQuantities
|
5103
5346
|
});
|
5104
5347
|
const quantitiesDict = {};
|
5105
|
-
|
5348
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
5106
5349
|
quantitiesDict[assetId] = {
|
5107
5350
|
required: amount,
|
5108
|
-
owned: (0,
|
5351
|
+
owned: (0, import_math19.bn)(0)
|
5109
5352
|
};
|
5110
5353
|
});
|
5111
|
-
|
5112
|
-
const cachedMessages = [];
|
5113
|
-
const owner = this.address.toB256();
|
5114
|
-
request.inputs.forEach((input) => {
|
5354
|
+
txRequest.inputs.forEach((input) => {
|
5115
5355
|
const isResource = "amount" in input;
|
5116
5356
|
if (isResource) {
|
5117
5357
|
const isCoin2 = "owner" in input;
|
5118
5358
|
if (isCoin2) {
|
5119
5359
|
const assetId = String(input.assetId);
|
5120
|
-
if (
|
5121
|
-
const amount = (0,
|
5360
|
+
if (quantitiesDict[assetId]) {
|
5361
|
+
const amount = (0, import_math19.bn)(input.amount);
|
5122
5362
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5123
|
-
cachedUtxos.push(input.id);
|
5124
5363
|
}
|
5125
|
-
} else if (input.
|
5364
|
+
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5126
5365
|
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
5127
|
-
cachedMessages.push(input.nonce);
|
5128
5366
|
}
|
5129
5367
|
}
|
5130
5368
|
});
|
@@ -5139,12 +5377,21 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5139
5377
|
});
|
5140
5378
|
const needsToBeFunded = missingQuantities.length;
|
5141
5379
|
if (needsToBeFunded) {
|
5142
|
-
const
|
5143
|
-
|
5144
|
-
|
5145
|
-
|
5146
|
-
|
5147
|
-
|
5380
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
5381
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
5382
|
+
txRequest.addResources(resources);
|
5383
|
+
}
|
5384
|
+
txRequest.shiftPredicateData();
|
5385
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5386
|
+
const requestToReestimate = (0, import_ramda4.clone)(txRequest);
|
5387
|
+
if (addedSignatures) {
|
5388
|
+
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
5389
|
+
}
|
5390
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5391
|
+
transactionRequest: requestToReestimate
|
5392
|
+
});
|
5393
|
+
txRequest.maxFee = maxFee;
|
5394
|
+
return txRequest;
|
5148
5395
|
}
|
5149
5396
|
/**
|
5150
5397
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5152,28 +5399,24 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5152
5399
|
* @param destination - The address of the destination.
|
5153
5400
|
* @param amount - The amount of coins to transfer.
|
5154
5401
|
* @param assetId - The asset ID of the coins to transfer.
|
5155
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5402
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
5156
5403
|
* @returns A promise that resolves to the prepared transaction request.
|
5157
5404
|
*/
|
5158
5405
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5159
|
-
const
|
5160
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5161
|
-
const request = new ScriptTransactionRequest(params);
|
5406
|
+
const request = new ScriptTransactionRequest(txParams);
|
5162
5407
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
5163
|
-
const
|
5408
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5164
5409
|
estimateTxDependencies: true,
|
5165
5410
|
resourcesOwner: this
|
5166
5411
|
});
|
5167
|
-
|
5168
|
-
|
5169
|
-
|
5170
|
-
|
5171
|
-
gasPrice: request.gasPrice,
|
5172
|
-
gasLimit: request.gasLimit,
|
5173
|
-
minGasPrice
|
5412
|
+
this.validateGasLimitAndMaxFee({
|
5413
|
+
gasUsed: txCost.gasUsed,
|
5414
|
+
maxFee: txCost.maxFee,
|
5415
|
+
txParams
|
5174
5416
|
});
|
5175
|
-
|
5176
|
-
request.
|
5417
|
+
request.gasLimit = txCost.gasUsed;
|
5418
|
+
request.maxFee = txCost.maxFee;
|
5419
|
+
await this.fund(request, txCost);
|
5177
5420
|
return request;
|
5178
5421
|
}
|
5179
5422
|
/**
|
@@ -5186,7 +5429,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5186
5429
|
* @returns A promise that resolves to the transaction response.
|
5187
5430
|
*/
|
5188
5431
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5189
|
-
if ((0,
|
5432
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
5190
5433
|
throw new import_errors16.FuelError(
|
5191
5434
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5192
5435
|
"Transfer amount must be a positive number."
|
@@ -5205,38 +5448,36 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5205
5448
|
* @returns A promise that resolves to the transaction response.
|
5206
5449
|
*/
|
5207
5450
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5208
|
-
if ((0,
|
5451
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
5209
5452
|
throw new import_errors16.FuelError(
|
5210
5453
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5211
5454
|
"Transfer amount must be a positive number."
|
5212
5455
|
);
|
5213
5456
|
}
|
5214
5457
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5215
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5216
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5217
5458
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5218
5459
|
hexlifiedContractId: contractAddress.toB256(),
|
5219
|
-
amountToTransfer: (0,
|
5460
|
+
amountToTransfer: (0, import_math19.bn)(amount),
|
5220
5461
|
assetId
|
5221
5462
|
});
|
5222
5463
|
const request = new ScriptTransactionRequest({
|
5223
|
-
...
|
5464
|
+
...txParams,
|
5224
5465
|
script,
|
5225
5466
|
scriptData
|
5226
5467
|
});
|
5227
5468
|
request.addContractInputAndOutput(contractAddress);
|
5228
|
-
const
|
5229
|
-
|
5230
|
-
[{ amount: (0,
|
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
|
5469
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5470
|
+
resourcesOwner: this,
|
5471
|
+
quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
|
5238
5472
|
});
|
5239
|
-
|
5473
|
+
this.validateGasLimitAndMaxFee({
|
5474
|
+
gasUsed: txCost.gasUsed,
|
5475
|
+
maxFee: txCost.maxFee,
|
5476
|
+
txParams
|
5477
|
+
});
|
5478
|
+
request.gasLimit = txCost.gasUsed;
|
5479
|
+
request.maxFee = txCost.maxFee;
|
5480
|
+
await this.fund(request, txCost);
|
5240
5481
|
return this.sendTransaction(request);
|
5241
5482
|
}
|
5242
5483
|
/**
|
@@ -5248,34 +5489,30 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5248
5489
|
* @returns A promise that resolves to the transaction response.
|
5249
5490
|
*/
|
5250
5491
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5251
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5252
5492
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5253
|
-
const recipientDataArray = (0,
|
5493
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
5254
5494
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5255
5495
|
);
|
5256
|
-
const amountDataArray = (0,
|
5257
|
-
"0x".concat((0,
|
5496
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5497
|
+
"0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5258
5498
|
);
|
5259
5499
|
const script = new Uint8Array([
|
5260
|
-
...(0,
|
5500
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
5261
5501
|
...recipientDataArray,
|
5262
5502
|
...amountDataArray
|
5263
5503
|
]);
|
5264
|
-
const params = { script,
|
5504
|
+
const params = { script, ...txParams };
|
5265
5505
|
const request = new ScriptTransactionRequest(params);
|
5266
|
-
const
|
5267
|
-
const
|
5268
|
-
|
5269
|
-
|
5270
|
-
|
5271
|
-
|
5272
|
-
this.validateGas({
|
5273
|
-
gasUsed,
|
5274
|
-
gasPrice: request.gasPrice,
|
5275
|
-
gasLimit: request.gasLimit,
|
5276
|
-
minGasPrice
|
5506
|
+
const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5507
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5508
|
+
this.validateGasLimitAndMaxFee({
|
5509
|
+
gasUsed: txCost.gasUsed,
|
5510
|
+
maxFee: txCost.maxFee,
|
5511
|
+
txParams
|
5277
5512
|
});
|
5278
|
-
|
5513
|
+
request.maxFee = txCost.maxFee;
|
5514
|
+
request.gasLimit = txCost.gasUsed;
|
5515
|
+
await this.fund(request, txCost);
|
5279
5516
|
return this.sendTransaction(request);
|
5280
5517
|
}
|
5281
5518
|
async signMessage(message) {
|
@@ -5333,22 +5570,21 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5333
5570
|
}
|
5334
5571
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5335
5572
|
}
|
5336
|
-
|
5573
|
+
validateGasLimitAndMaxFee({
|
5574
|
+
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
|
5337
5575
|
gasUsed,
|
5338
|
-
|
5339
|
-
gasLimit,
|
5340
|
-
minGasPrice
|
5576
|
+
maxFee
|
5341
5577
|
}) {
|
5342
|
-
if (
|
5578
|
+
if ((0, import_utils27.isDefined)(setGasLimit) && gasUsed.gt(setGasLimit)) {
|
5343
5579
|
throw new import_errors16.FuelError(
|
5344
|
-
import_errors16.ErrorCode.
|
5345
|
-
`Gas
|
5580
|
+
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
5581
|
+
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
5346
5582
|
);
|
5347
5583
|
}
|
5348
|
-
if (
|
5584
|
+
if ((0, import_utils27.isDefined)(setMaxFee) && maxFee.gt(setMaxFee)) {
|
5349
5585
|
throw new import_errors16.FuelError(
|
5350
|
-
import_errors16.ErrorCode.
|
5351
|
-
`
|
5586
|
+
import_errors16.ErrorCode.MAX_FEE_TOO_LOW,
|
5587
|
+
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
5352
5588
|
);
|
5353
5589
|
}
|
5354
5590
|
}
|
@@ -5356,14 +5592,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5356
5592
|
|
5357
5593
|
// src/wallet/base-wallet-unlocked.ts
|
5358
5594
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5359
|
-
var
|
5595
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5360
5596
|
|
5361
5597
|
// src/signer/signer.ts
|
5362
5598
|
var import_address5 = require("@fuel-ts/address");
|
5363
5599
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5364
5600
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5365
|
-
var
|
5366
|
-
var
|
5601
|
+
var import_math20 = require("@fuel-ts/math");
|
5602
|
+
var import_utils28 = require("@fuel-ts/utils");
|
5367
5603
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5368
5604
|
var Signer = class {
|
5369
5605
|
address;
|
@@ -5382,10 +5618,10 @@ var Signer = class {
|
|
5382
5618
|
privateKey = `0x${privateKey}`;
|
5383
5619
|
}
|
5384
5620
|
}
|
5385
|
-
const privateKeyBytes = (0,
|
5386
|
-
this.privateKey = (0,
|
5387
|
-
this.publicKey = (0,
|
5388
|
-
this.compressedPublicKey = (0,
|
5621
|
+
const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
|
5622
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5623
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5624
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5389
5625
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5390
5626
|
}
|
5391
5627
|
/**
|
@@ -5399,11 +5635,11 @@ var Signer = class {
|
|
5399
5635
|
* @returns hashed signature
|
5400
5636
|
*/
|
5401
5637
|
sign(data) {
|
5402
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5403
|
-
const r = (0,
|
5404
|
-
const s = (0,
|
5638
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5639
|
+
const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5640
|
+
const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5405
5641
|
s[0] |= (signature.recovery || 0) << 7;
|
5406
|
-
return (0,
|
5642
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
5407
5643
|
}
|
5408
5644
|
/**
|
5409
5645
|
* Add point on the current elliptic curve
|
@@ -5412,8 +5648,8 @@ var Signer = class {
|
|
5412
5648
|
* @returns compressed point on the curve
|
5413
5649
|
*/
|
5414
5650
|
addPoint(point) {
|
5415
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5416
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5651
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5652
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
5417
5653
|
const result = p0.add(p1);
|
5418
5654
|
return `0x${result.toHex(true)}`;
|
5419
5655
|
}
|
@@ -5425,16 +5661,16 @@ var Signer = class {
|
|
5425
5661
|
* @returns public key from signature from the
|
5426
5662
|
*/
|
5427
5663
|
static recoverPublicKey(data, signature) {
|
5428
|
-
const signedMessageBytes = (0,
|
5664
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5429
5665
|
const r = signedMessageBytes.slice(0, 32);
|
5430
5666
|
const s = signedMessageBytes.slice(32, 64);
|
5431
5667
|
const recoveryParam = (s[0] & 128) >> 7;
|
5432
5668
|
s[0] &= 127;
|
5433
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5669
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5434
5670
|
recoveryParam
|
5435
5671
|
);
|
5436
|
-
const publicKey = sig.recoverPublicKey((0,
|
5437
|
-
return (0,
|
5672
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5673
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5438
5674
|
}
|
5439
5675
|
/**
|
5440
5676
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5453,7 +5689,7 @@ var Signer = class {
|
|
5453
5689
|
* @returns random 32-byte hashed
|
5454
5690
|
*/
|
5455
5691
|
static generatePrivateKey(entropy) {
|
5456
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5692
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5457
5693
|
}
|
5458
5694
|
/**
|
5459
5695
|
* Extended publicKey from a compact publicKey
|
@@ -5462,8 +5698,8 @@ var Signer = class {
|
|
5462
5698
|
* @returns extended publicKey
|
5463
5699
|
*/
|
5464
5700
|
static extendPublicKey(publicKey) {
|
5465
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5466
|
-
return (0,
|
5701
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5702
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5467
5703
|
}
|
5468
5704
|
};
|
5469
5705
|
|
@@ -5471,7 +5707,7 @@ var Signer = class {
|
|
5471
5707
|
var import_address6 = require("@fuel-ts/address");
|
5472
5708
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5473
5709
|
var import_errors17 = require("@fuel-ts/errors");
|
5474
|
-
var
|
5710
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5475
5711
|
var import_uuid = require("uuid");
|
5476
5712
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5477
5713
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5554,7 +5790,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5554
5790
|
);
|
5555
5791
|
}
|
5556
5792
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5557
|
-
const privateKey = (0,
|
5793
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5558
5794
|
return privateKey;
|
5559
5795
|
}
|
5560
5796
|
|
@@ -5599,7 +5835,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5599
5835
|
*/
|
5600
5836
|
async signMessage(message) {
|
5601
5837
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5602
|
-
return (0,
|
5838
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5603
5839
|
}
|
5604
5840
|
/**
|
5605
5841
|
* Signs a transaction with the wallet's private key.
|
@@ -5612,7 +5848,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5612
5848
|
const chainId = this.provider.getChainId();
|
5613
5849
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5614
5850
|
const signature = await this.signer().sign(hashedTransaction);
|
5615
|
-
return (0,
|
5851
|
+
return (0, import_utils30.hexlify)(signature);
|
5616
5852
|
}
|
5617
5853
|
/**
|
5618
5854
|
* Populates a transaction with the witnesses signature.
|
@@ -5632,7 +5868,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5632
5868
|
* @param transactionRequestLike - The transaction request to send.
|
5633
5869
|
* @returns A promise that resolves to the TransactionResponse object.
|
5634
5870
|
*/
|
5635
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5871
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5636
5872
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5637
5873
|
if (estimateTxDependencies) {
|
5638
5874
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5673,15 +5909,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5673
5909
|
// src/hdwallet/hdwallet.ts
|
5674
5910
|
var import_errors20 = require("@fuel-ts/errors");
|
5675
5911
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5676
|
-
var
|
5677
|
-
var
|
5912
|
+
var import_math21 = require("@fuel-ts/math");
|
5913
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5678
5914
|
var import_ethers3 = require("ethers");
|
5679
5915
|
|
5680
5916
|
// src/mnemonic/mnemonic.ts
|
5681
5917
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5682
5918
|
var import_errors19 = require("@fuel-ts/errors");
|
5683
5919
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5684
|
-
var
|
5920
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5685
5921
|
var import_ethers2 = require("ethers");
|
5686
5922
|
|
5687
5923
|
// src/wordlists/words/english.ts
|
@@ -7745,7 +7981,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7745
7981
|
// src/mnemonic/utils.ts
|
7746
7982
|
var import_errors18 = require("@fuel-ts/errors");
|
7747
7983
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7748
|
-
var
|
7984
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7749
7985
|
function toUtf8Bytes(stri) {
|
7750
7986
|
const str = stri.normalize("NFKD");
|
7751
7987
|
const result = [];
|
@@ -7812,14 +8048,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7812
8048
|
}
|
7813
8049
|
}
|
7814
8050
|
const checksumBits = entropy.length / 4;
|
7815
|
-
const checksum = (0,
|
8051
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7816
8052
|
indices[indices.length - 1] <<= checksumBits;
|
7817
8053
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7818
8054
|
return indices;
|
7819
8055
|
}
|
7820
8056
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7821
8057
|
const size = Math.ceil(11 * words.length / 8);
|
7822
|
-
const entropy = (0,
|
8058
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7823
8059
|
let offset = 0;
|
7824
8060
|
for (let i = 0; i < words.length; i += 1) {
|
7825
8061
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7839,7 +8075,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7839
8075
|
const entropyBits = 32 * words.length / 3;
|
7840
8076
|
const checksumBits = words.length / 3;
|
7841
8077
|
const checksumMask = getUpperMask(checksumBits);
|
7842
|
-
const checksum = (0,
|
8078
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7843
8079
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7844
8080
|
throw new import_errors18.FuelError(
|
7845
8081
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7914,7 +8150,7 @@ var Mnemonic = class {
|
|
7914
8150
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7915
8151
|
const words = getWords(phrase);
|
7916
8152
|
assertMnemonic(words);
|
7917
|
-
return (0,
|
8153
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7918
8154
|
}
|
7919
8155
|
/**
|
7920
8156
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7922,7 +8158,7 @@ var Mnemonic = class {
|
|
7922
8158
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7923
8159
|
*/
|
7924
8160
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7925
|
-
const entropyBytes = (0,
|
8161
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7926
8162
|
assertWordList(wordlist);
|
7927
8163
|
assertEntropy(entropyBytes);
|
7928
8164
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7991,14 +8227,14 @@ var Mnemonic = class {
|
|
7991
8227
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7992
8228
|
*/
|
7993
8229
|
static masterKeysFromSeed(seed) {
|
7994
|
-
const seedArray = (0,
|
8230
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
7995
8231
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7996
8232
|
throw new import_errors19.FuelError(
|
7997
8233
|
import_errors19.ErrorCode.INVALID_SEED,
|
7998
8234
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7999
8235
|
);
|
8000
8236
|
}
|
8001
|
-
return (0,
|
8237
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
8002
8238
|
}
|
8003
8239
|
/**
|
8004
8240
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8009,22 +8245,22 @@ var Mnemonic = class {
|
|
8009
8245
|
*/
|
8010
8246
|
static seedToExtendedKey(seed, testnet = false) {
|
8011
8247
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8012
|
-
const prefix = (0,
|
8248
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8013
8249
|
const depth = "0x00";
|
8014
8250
|
const fingerprint = "0x00000000";
|
8015
8251
|
const index = "0x00000000";
|
8016
8252
|
const chainCode = masterKey.slice(32);
|
8017
8253
|
const privateKey = masterKey.slice(0, 32);
|
8018
|
-
const extendedKey = (0,
|
8254
|
+
const extendedKey = (0, import_utils32.concat)([
|
8019
8255
|
prefix,
|
8020
8256
|
depth,
|
8021
8257
|
fingerprint,
|
8022
8258
|
index,
|
8023
8259
|
chainCode,
|
8024
|
-
(0,
|
8260
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
8025
8261
|
]);
|
8026
8262
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8027
|
-
return (0, import_ethers2.encodeBase58)((0,
|
8263
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
8028
8264
|
}
|
8029
8265
|
/**
|
8030
8266
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8039,7 +8275,7 @@ var Mnemonic = class {
|
|
8039
8275
|
* @returns A randomly generated mnemonic
|
8040
8276
|
*/
|
8041
8277
|
static generate(size = 32, extraEntropy = "") {
|
8042
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8278
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
8043
8279
|
return Mnemonic.entropyToMnemonic(entropy);
|
8044
8280
|
}
|
8045
8281
|
};
|
@@ -8047,12 +8283,12 @@ var mnemonic_default = Mnemonic;
|
|
8047
8283
|
|
8048
8284
|
// src/hdwallet/hdwallet.ts
|
8049
8285
|
var HARDENED_INDEX = 2147483648;
|
8050
|
-
var MainnetPRV2 = (0,
|
8051
|
-
var MainnetPUB = (0,
|
8052
|
-
var TestnetPRV2 = (0,
|
8053
|
-
var TestnetPUB = (0,
|
8286
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
8287
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
8288
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
8289
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
8054
8290
|
function base58check(data) {
|
8055
|
-
return (0, import_ethers3.encodeBase58)((0,
|
8291
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
8056
8292
|
}
|
8057
8293
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8058
8294
|
if (isPublic) {
|
@@ -8061,11 +8297,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8061
8297
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8062
8298
|
}
|
8063
8299
|
function isPublicExtendedKey(extendedKey) {
|
8064
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8300
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
8065
8301
|
}
|
8066
8302
|
function isValidExtendedKey(extendedKey) {
|
8067
8303
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8068
|
-
(0,
|
8304
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
8069
8305
|
);
|
8070
8306
|
}
|
8071
8307
|
function parsePath(path, depth = 0) {
|
@@ -8083,8 +8319,8 @@ function parsePath(path, depth = 0) {
|
|
8083
8319
|
var HDWallet = class {
|
8084
8320
|
depth = 0;
|
8085
8321
|
index = 0;
|
8086
|
-
fingerprint = (0,
|
8087
|
-
parentFingerprint = (0,
|
8322
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8323
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8088
8324
|
privateKey;
|
8089
8325
|
publicKey;
|
8090
8326
|
chainCode;
|
@@ -8096,8 +8332,8 @@ var HDWallet = class {
|
|
8096
8332
|
constructor(config) {
|
8097
8333
|
if (config.privateKey) {
|
8098
8334
|
const signer = new Signer(config.privateKey);
|
8099
|
-
this.publicKey = (0,
|
8100
|
-
this.privateKey = (0,
|
8335
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
8336
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
8101
8337
|
} else {
|
8102
8338
|
if (!config.publicKey) {
|
8103
8339
|
throw new import_errors20.FuelError(
|
@@ -8105,7 +8341,7 @@ var HDWallet = class {
|
|
8105
8341
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8106
8342
|
);
|
8107
8343
|
}
|
8108
|
-
this.publicKey = (0,
|
8344
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
8109
8345
|
}
|
8110
8346
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8111
8347
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -8124,9 +8360,9 @@ var HDWallet = class {
|
|
8124
8360
|
* @returns A new instance of HDWallet on the derived index
|
8125
8361
|
*/
|
8126
8362
|
deriveIndex(index) {
|
8127
|
-
const privateKey = this.privateKey && (0,
|
8128
|
-
const publicKey = (0,
|
8129
|
-
const chainCode = (0,
|
8363
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
8364
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
8365
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
8130
8366
|
const data = new Uint8Array(37);
|
8131
8367
|
if (index & HARDENED_INDEX) {
|
8132
8368
|
if (!privateKey) {
|
@@ -8137,15 +8373,15 @@ var HDWallet = class {
|
|
8137
8373
|
}
|
8138
8374
|
data.set(privateKey, 1);
|
8139
8375
|
} else {
|
8140
|
-
data.set((0,
|
8376
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
8141
8377
|
}
|
8142
|
-
data.set((0,
|
8143
|
-
const bytes = (0,
|
8378
|
+
data.set((0, import_math21.toBytes)(index, 4), 33);
|
8379
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
8144
8380
|
const IL = bytes.slice(0, 32);
|
8145
8381
|
const IR = bytes.slice(32);
|
8146
8382
|
if (privateKey) {
|
8147
8383
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8148
|
-
const ki = (0,
|
8384
|
+
const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8149
8385
|
return new HDWallet({
|
8150
8386
|
privateKey: ki,
|
8151
8387
|
chainCode: IR,
|
@@ -8154,7 +8390,7 @@ var HDWallet = class {
|
|
8154
8390
|
parentFingerprint: this.fingerprint
|
8155
8391
|
});
|
8156
8392
|
}
|
8157
|
-
const signer = new Signer((0,
|
8393
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
8158
8394
|
const Ki = signer.addPoint(publicKey);
|
8159
8395
|
return new HDWallet({
|
8160
8396
|
publicKey: Ki,
|
@@ -8189,12 +8425,12 @@ var HDWallet = class {
|
|
8189
8425
|
);
|
8190
8426
|
}
|
8191
8427
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8192
|
-
const depth = (0,
|
8428
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
8193
8429
|
const parentFingerprint = this.parentFingerprint;
|
8194
|
-
const index = (0,
|
8430
|
+
const index = (0, import_math21.toHex)(this.index, 4);
|
8195
8431
|
const chainCode = this.chainCode;
|
8196
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8197
|
-
const extendedKey = (0,
|
8432
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8433
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8198
8434
|
return base58check(extendedKey);
|
8199
8435
|
}
|
8200
8436
|
/**
|
@@ -8206,13 +8442,13 @@ var HDWallet = class {
|
|
8206
8442
|
static fromSeed(seed) {
|
8207
8443
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8208
8444
|
return new HDWallet({
|
8209
|
-
chainCode: (0,
|
8210
|
-
privateKey: (0,
|
8445
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
8446
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
8211
8447
|
});
|
8212
8448
|
}
|
8213
8449
|
static fromExtendedKey(extendedKey) {
|
8214
8450
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8215
|
-
const bytes = (0,
|
8451
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
8216
8452
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8217
8453
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8218
8454
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8221,9 +8457,9 @@ var HDWallet = class {
|
|
8221
8457
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8222
8458
|
}
|
8223
8459
|
const depth = bytes[4];
|
8224
|
-
const parentFingerprint = (0,
|
8225
|
-
const index = parseInt((0,
|
8226
|
-
const chainCode = (0,
|
8460
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8461
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8462
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
8227
8463
|
const key = bytes.slice(45, 78);
|
8228
8464
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8229
8465
|
throw new import_errors20.FuelError(
|
@@ -8828,19 +9064,19 @@ var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
|
8828
9064
|
var import_address10 = require("@fuel-ts/address");
|
8829
9065
|
var import_configs13 = require("@fuel-ts/address/configs");
|
8830
9066
|
var import_errors25 = require("@fuel-ts/errors");
|
8831
|
-
var
|
8832
|
-
var
|
9067
|
+
var import_transactions21 = require("@fuel-ts/transactions");
|
9068
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8833
9069
|
|
8834
9070
|
// src/predicate/utils/getPredicateRoot.ts
|
8835
9071
|
var import_hasher7 = require("@fuel-ts/hasher");
|
8836
9072
|
var import_merkle = require("@fuel-ts/merkle");
|
8837
|
-
var
|
9073
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8838
9074
|
var getPredicateRoot = (bytecode) => {
|
8839
9075
|
const chunkSize = 16 * 1024;
|
8840
|
-
const bytes = (0,
|
8841
|
-
const chunks = (0,
|
8842
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
8843
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
9076
|
+
const bytes = (0, import_utils35.arrayify)(bytecode);
|
9077
|
+
const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
|
9078
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
|
9079
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
|
8844
9080
|
return predicateRoot;
|
8845
9081
|
};
|
8846
9082
|
|
@@ -8888,9 +9124,9 @@ var Predicate = class extends Account {
|
|
8888
9124
|
const request = transactionRequestify(transactionRequestLike);
|
8889
9125
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8890
9126
|
request.inputs?.forEach((input) => {
|
8891
|
-
if (input.type ===
|
8892
|
-
input.predicate = this.bytes;
|
8893
|
-
input.predicateData = this.getPredicateData(policies.length);
|
9127
|
+
if (input.type === import_transactions21.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
|
9128
|
+
input.predicate = (0, import_utils36.hexlify)(this.bytes);
|
9129
|
+
input.predicateData = (0, import_utils36.hexlify)(this.getPredicateData(policies.length));
|
8894
9130
|
}
|
8895
9131
|
});
|
8896
9132
|
return request;
|
@@ -8905,8 +9141,7 @@ var Predicate = class extends Account {
|
|
8905
9141
|
* @returns A promise that resolves to the prepared transaction request.
|
8906
9142
|
*/
|
8907
9143
|
async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
|
8908
|
-
|
8909
|
-
return this.populateTransactionPredicateData(request);
|
9144
|
+
return super.createTransfer(destination, amount, assetId, txParams);
|
8910
9145
|
}
|
8911
9146
|
/**
|
8912
9147
|
* Sends a transaction with the populated predicate data.
|
@@ -8914,9 +9149,9 @@ var Predicate = class extends Account {
|
|
8914
9149
|
* @param transactionRequestLike - The transaction request-like object.
|
8915
9150
|
* @returns A promise that resolves to the transaction response.
|
8916
9151
|
*/
|
8917
|
-
sendTransaction(transactionRequestLike
|
8918
|
-
const transactionRequest =
|
8919
|
-
return super.sendTransaction(transactionRequest,
|
9152
|
+
sendTransaction(transactionRequestLike) {
|
9153
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9154
|
+
return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
|
8920
9155
|
}
|
8921
9156
|
/**
|
8922
9157
|
* Simulates a transaction with the populated predicate data.
|
@@ -8925,15 +9160,15 @@ var Predicate = class extends Account {
|
|
8925
9160
|
* @returns A promise that resolves to the call result.
|
8926
9161
|
*/
|
8927
9162
|
simulateTransaction(transactionRequestLike) {
|
8928
|
-
const transactionRequest =
|
8929
|
-
return super.simulateTransaction(transactionRequest);
|
9163
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9164
|
+
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
8930
9165
|
}
|
8931
9166
|
getPredicateData(policiesLength) {
|
8932
9167
|
if (!this.predicateData.length) {
|
8933
9168
|
return new Uint8Array();
|
8934
9169
|
}
|
8935
9170
|
const mainFn = this.interface?.functions.main;
|
8936
|
-
const paddedCode = new
|
9171
|
+
const paddedCode = new import_transactions21.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
8937
9172
|
const VM_TX_MEMORY = (0, import_abi_coder7.calculateVmTxMemory)({
|
8938
9173
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
8939
9174
|
});
|
@@ -8949,7 +9184,7 @@ var Predicate = class extends Account {
|
|
8949
9184
|
* @returns An object containing the new predicate bytes and interface.
|
8950
9185
|
*/
|
8951
9186
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
8952
|
-
let predicateBytes = (0,
|
9187
|
+
let predicateBytes = (0, import_utils36.arrayify)(bytes);
|
8953
9188
|
let abiInterface;
|
8954
9189
|
if (jsonAbi) {
|
8955
9190
|
abiInterface = new import_abi_coder7.Interface(jsonAbi);
|
@@ -8972,6 +9207,25 @@ var Predicate = class extends Account {
|
|
8972
9207
|
predicateInterface: abiInterface
|
8973
9208
|
};
|
8974
9209
|
}
|
9210
|
+
/**
|
9211
|
+
* Retrieves resources satisfying the spend query for the account.
|
9212
|
+
*
|
9213
|
+
* @param quantities - IDs of coins to exclude.
|
9214
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
9215
|
+
* @returns A promise that resolves to an array of Resources.
|
9216
|
+
*/
|
9217
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
9218
|
+
const resources = await this.provider.getResourcesToSpend(
|
9219
|
+
this.address,
|
9220
|
+
quantities,
|
9221
|
+
excludedIds
|
9222
|
+
);
|
9223
|
+
return resources.map((resource) => ({
|
9224
|
+
...resource,
|
9225
|
+
predicate: (0, import_utils36.hexlify)(this.bytes),
|
9226
|
+
padPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
|
9227
|
+
}));
|
9228
|
+
}
|
8975
9229
|
/**
|
8976
9230
|
* Sets the configurable constants for the predicate.
|
8977
9231
|
*
|
@@ -9721,7 +9975,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9721
9975
|
WalletLocked,
|
9722
9976
|
WalletManager,
|
9723
9977
|
WalletUnlocked,
|
9724
|
-
|
9978
|
+
addAmountToCoinQuantities,
|
9725
9979
|
addOperation,
|
9726
9980
|
assemblePanicError,
|
9727
9981
|
assembleReceiptByType,
|
@@ -9730,9 +9984,10 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9730
9984
|
assets,
|
9731
9985
|
buildBlockExplorerUrl,
|
9732
9986
|
cacheFor,
|
9987
|
+
cacheTxInputsFromOwner,
|
9988
|
+
calculateGasFee,
|
9733
9989
|
calculateMetadataGasForTxCreate,
|
9734
9990
|
calculateMetadataGasForTxScript,
|
9735
|
-
calculatePriceWithFactor,
|
9736
9991
|
calculateTransactionFee,
|
9737
9992
|
coinQuantityfy,
|
9738
9993
|
deferPromise,
|