@fuel-ts/account 0.0.0-rc-1976-20240424110729 → 0.0.0-rc-2021-20240424121206
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- 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 +861 -611
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +864 -608
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +706 -451
- 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 +822 -328
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- 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 -34
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +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 +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 -32
- 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.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1578 -1114
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +845 -609
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +699 -463
- 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,
|
@@ -184,35 +185,38 @@ module.exports = __toCommonJS(src_exports);
|
|
184
185
|
|
185
186
|
// src/account.ts
|
186
187
|
var import_address4 = require("@fuel-ts/address");
|
188
|
+
var import_configs12 = require("@fuel-ts/address/configs");
|
187
189
|
var import_errors16 = require("@fuel-ts/errors");
|
188
190
|
var import_interfaces = require("@fuel-ts/interfaces");
|
189
|
-
var
|
190
|
-
var
|
191
|
+
var import_math19 = require("@fuel-ts/math");
|
192
|
+
var import_utils27 = require("@fuel-ts/utils");
|
193
|
+
var import_ramda4 = require("ramda");
|
191
194
|
|
192
195
|
// src/providers/coin-quantity.ts
|
196
|
+
var import_configs = require("@fuel-ts/address/configs");
|
193
197
|
var import_math = require("@fuel-ts/math");
|
194
198
|
var import_utils = require("@fuel-ts/utils");
|
195
199
|
var coinQuantityfy = (coinQuantityLike) => {
|
196
200
|
let assetId;
|
197
201
|
let amount;
|
198
|
-
let
|
202
|
+
let max;
|
199
203
|
if (Array.isArray(coinQuantityLike)) {
|
200
204
|
amount = coinQuantityLike[0];
|
201
|
-
assetId = coinQuantityLike[1];
|
202
|
-
|
205
|
+
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
206
|
+
max = coinQuantityLike[2] ?? void 0;
|
203
207
|
} else {
|
204
208
|
amount = coinQuantityLike.amount;
|
205
|
-
assetId = coinQuantityLike.assetId;
|
206
|
-
|
209
|
+
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
210
|
+
max = coinQuantityLike.max ?? void 0;
|
207
211
|
}
|
208
212
|
const bnAmount = (0, import_math.bn)(amount);
|
209
213
|
return {
|
210
214
|
assetId: (0, import_utils.hexlify)(assetId),
|
211
215
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
212
|
-
max:
|
216
|
+
max: max ? (0, import_math.bn)(max) : void 0
|
213
217
|
};
|
214
218
|
};
|
215
|
-
var
|
219
|
+
var addAmountToCoinQuantities = (params) => {
|
216
220
|
const { amount, assetId } = params;
|
217
221
|
const coinQuantities = [...params.coinQuantities];
|
218
222
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -227,27 +231,51 @@ var addAmountToAsset = (params) => {
|
|
227
231
|
// src/providers/provider.ts
|
228
232
|
var import_address3 = require("@fuel-ts/address");
|
229
233
|
var import_errors14 = require("@fuel-ts/errors");
|
230
|
-
var
|
231
|
-
var
|
232
|
-
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");
|
233
237
|
var import_versions = require("@fuel-ts/versions");
|
234
|
-
var
|
238
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
235
239
|
var import_ethers = require("ethers");
|
236
240
|
var import_graphql_request = require("graphql-request");
|
237
241
|
var import_ramda3 = require("ramda");
|
238
242
|
|
239
243
|
// src/providers/__generated__/operations.ts
|
240
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 SubmittedStatus {
|
249
|
+
time
|
250
|
+
}
|
251
|
+
... on SuccessStatus {
|
252
|
+
block {
|
253
|
+
id
|
254
|
+
}
|
255
|
+
time
|
256
|
+
programState {
|
257
|
+
returnType
|
258
|
+
data
|
259
|
+
}
|
260
|
+
}
|
261
|
+
... on FailureStatus {
|
262
|
+
block {
|
263
|
+
id
|
264
|
+
}
|
265
|
+
time
|
266
|
+
reason
|
267
|
+
}
|
268
|
+
... on SqueezedOutStatus {
|
269
|
+
reason
|
270
|
+
}
|
271
|
+
}
|
272
|
+
`;
|
241
273
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
242
274
|
fragment receiptFragment on Receipt {
|
243
|
-
|
244
|
-
id
|
245
|
-
}
|
275
|
+
id
|
246
276
|
pc
|
247
277
|
is
|
248
|
-
to
|
249
|
-
id
|
250
|
-
}
|
278
|
+
to
|
251
279
|
toAddress
|
252
280
|
amount
|
253
281
|
assetId
|
@@ -285,10 +313,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
285
313
|
id
|
286
314
|
}
|
287
315
|
time
|
316
|
+
receipts {
|
317
|
+
...receiptFragment
|
318
|
+
}
|
288
319
|
programState {
|
289
320
|
returnType
|
290
321
|
data
|
291
322
|
}
|
323
|
+
receipts {
|
324
|
+
...receiptFragment
|
325
|
+
}
|
292
326
|
}
|
293
327
|
... on FailureStatus {
|
294
328
|
block {
|
@@ -296,26 +330,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
296
330
|
}
|
297
331
|
time
|
298
332
|
reason
|
333
|
+
receipts {
|
334
|
+
...receiptFragment
|
335
|
+
}
|
299
336
|
}
|
300
337
|
... on SqueezedOutStatus {
|
301
338
|
reason
|
302
339
|
}
|
303
340
|
}
|
304
|
-
`;
|
341
|
+
${ReceiptFragmentFragmentDoc}`;
|
305
342
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
306
343
|
fragment transactionFragment on Transaction {
|
307
344
|
id
|
308
345
|
rawPayload
|
309
|
-
gasPrice
|
310
|
-
receipts {
|
311
|
-
...receiptFragment
|
312
|
-
}
|
313
346
|
status {
|
314
347
|
...transactionStatusFragment
|
315
348
|
}
|
316
349
|
}
|
317
|
-
${
|
318
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
350
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
319
351
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
320
352
|
fragment inputEstimatePredicatesFragment on Input {
|
321
353
|
... on InputCoin {
|
@@ -333,6 +365,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
333
365
|
}
|
334
366
|
}
|
335
367
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
368
|
+
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
369
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
370
|
+
reason
|
371
|
+
programState {
|
372
|
+
returnType
|
373
|
+
data
|
374
|
+
}
|
375
|
+
}
|
376
|
+
`;
|
377
|
+
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
378
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
379
|
+
programState {
|
380
|
+
returnType
|
381
|
+
data
|
382
|
+
}
|
383
|
+
}
|
384
|
+
`;
|
385
|
+
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
386
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
387
|
+
... on DryRunFailureStatus {
|
388
|
+
...dryRunFailureStatusFragment
|
389
|
+
}
|
390
|
+
... on DryRunSuccessStatus {
|
391
|
+
...dryRunSuccessStatusFragment
|
392
|
+
}
|
393
|
+
}
|
394
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
395
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
396
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
397
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
398
|
+
id
|
399
|
+
status {
|
400
|
+
...dryRunTransactionStatusFragment
|
401
|
+
}
|
402
|
+
receipts {
|
403
|
+
...receiptFragment
|
404
|
+
}
|
405
|
+
}
|
406
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
407
|
+
${ReceiptFragmentFragmentDoc}`;
|
336
408
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
337
409
|
fragment coinFragment on Coin {
|
338
410
|
__typename
|
@@ -340,7 +412,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
340
412
|
owner
|
341
413
|
amount
|
342
414
|
assetId
|
343
|
-
maturity
|
344
415
|
blockCreated
|
345
416
|
txCreatedIdx
|
346
417
|
}
|
@@ -379,26 +450,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
379
450
|
messageBlockHeader {
|
380
451
|
id
|
381
452
|
daHeight
|
453
|
+
consensusParametersVersion
|
454
|
+
stateTransitionBytecodeVersion
|
382
455
|
transactionsCount
|
456
|
+
messageReceiptCount
|
383
457
|
transactionsRoot
|
458
|
+
messageOutboxRoot
|
459
|
+
eventInboxRoot
|
384
460
|
height
|
385
461
|
prevRoot
|
386
462
|
time
|
387
463
|
applicationHash
|
388
|
-
messageReceiptRoot
|
389
|
-
messageReceiptCount
|
390
464
|
}
|
391
465
|
commitBlockHeader {
|
392
466
|
id
|
393
467
|
daHeight
|
468
|
+
consensusParametersVersion
|
469
|
+
stateTransitionBytecodeVersion
|
394
470
|
transactionsCount
|
471
|
+
messageReceiptCount
|
395
472
|
transactionsRoot
|
473
|
+
messageOutboxRoot
|
474
|
+
eventInboxRoot
|
396
475
|
height
|
397
476
|
prevRoot
|
398
477
|
time
|
399
478
|
applicationHash
|
400
|
-
messageReceiptRoot
|
401
|
-
messageReceiptCount
|
402
479
|
}
|
403
480
|
sender
|
404
481
|
recipient
|
@@ -417,8 +494,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
417
494
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
418
495
|
fragment blockFragment on Block {
|
419
496
|
id
|
497
|
+
height
|
420
498
|
header {
|
421
|
-
height
|
422
499
|
time
|
423
500
|
}
|
424
501
|
transactions {
|
@@ -476,6 +553,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
476
553
|
`;
|
477
554
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
478
555
|
fragment GasCostsFragment on GasCosts {
|
556
|
+
version {
|
557
|
+
... on Version {
|
558
|
+
value
|
559
|
+
}
|
560
|
+
}
|
479
561
|
add
|
480
562
|
addi
|
481
563
|
aloc
|
@@ -488,7 +570,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
488
570
|
cb
|
489
571
|
cfei
|
490
572
|
cfsi
|
491
|
-
croo
|
492
573
|
div
|
493
574
|
divi
|
494
575
|
ecr1
|
@@ -571,6 +652,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
571
652
|
ccp {
|
572
653
|
...DependentCostFragment
|
573
654
|
}
|
655
|
+
croo {
|
656
|
+
...DependentCostFragment
|
657
|
+
}
|
574
658
|
csiz {
|
575
659
|
...DependentCostFragment
|
576
660
|
}
|
@@ -630,6 +714,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
630
714
|
${DependentCostFragmentFragmentDoc}`;
|
631
715
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
632
716
|
fragment consensusParametersFragment on ConsensusParameters {
|
717
|
+
version {
|
718
|
+
... on Version {
|
719
|
+
value
|
720
|
+
}
|
721
|
+
}
|
633
722
|
txParams {
|
634
723
|
...TxParametersFragment
|
635
724
|
}
|
@@ -689,18 +778,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
689
778
|
fragment nodeInfoFragment on NodeInfo {
|
690
779
|
utxoValidation
|
691
780
|
vmBacktrace
|
692
|
-
minGasPrice
|
693
781
|
maxTx
|
694
782
|
maxDepth
|
695
783
|
nodeVersion
|
696
|
-
peers {
|
697
|
-
id
|
698
|
-
addresses
|
699
|
-
clientVersion
|
700
|
-
blockHeight
|
701
|
-
lastHeartbeatMs
|
702
|
-
appScore
|
703
|
-
}
|
704
784
|
}
|
705
785
|
`;
|
706
786
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -735,13 +815,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
735
815
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
736
816
|
transaction(id: $transactionId) {
|
737
817
|
...transactionFragment
|
738
|
-
receipts {
|
739
|
-
...receiptFragment
|
740
|
-
}
|
741
818
|
}
|
742
819
|
}
|
743
|
-
${TransactionFragmentFragmentDoc}
|
744
|
-
${ReceiptFragmentFragmentDoc}`;
|
820
|
+
${TransactionFragmentFragmentDoc}`;
|
745
821
|
var GetTransactionsDocument = import_graphql_tag.default`
|
746
822
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
747
823
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -869,6 +945,20 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
869
945
|
}
|
870
946
|
}
|
871
947
|
${BalanceFragmentFragmentDoc}`;
|
948
|
+
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
949
|
+
query getLatestGasPrice {
|
950
|
+
latestGasPrice {
|
951
|
+
gasPrice
|
952
|
+
}
|
953
|
+
}
|
954
|
+
`;
|
955
|
+
var EstimateGasPriceDocument = import_graphql_tag.default`
|
956
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
957
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
958
|
+
gasPrice
|
959
|
+
}
|
960
|
+
}
|
961
|
+
`;
|
872
962
|
var GetBalancesDocument = import_graphql_tag.default`
|
873
963
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
874
964
|
balances(
|
@@ -923,12 +1013,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
923
1013
|
}
|
924
1014
|
`;
|
925
1015
|
var DryRunDocument = import_graphql_tag.default`
|
926
|
-
mutation dryRun($
|
927
|
-
dryRun(
|
928
|
-
...
|
1016
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
1017
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
1018
|
+
...dryRunTransactionExecutionStatusFragment
|
929
1019
|
}
|
930
1020
|
}
|
931
|
-
${
|
1021
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
932
1022
|
var SubmitDocument = import_graphql_tag.default`
|
933
1023
|
mutation submit($encodedTransaction: HexString!) {
|
934
1024
|
submit(tx: $encodedTransaction) {
|
@@ -947,17 +1037,17 @@ var ProduceBlocksDocument = import_graphql_tag.default`
|
|
947
1037
|
var SubmitAndAwaitDocument = import_graphql_tag.default`
|
948
1038
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
949
1039
|
submitAndAwait(tx: $encodedTransaction) {
|
950
|
-
...
|
1040
|
+
...transactionStatusSubscriptionFragment
|
951
1041
|
}
|
952
1042
|
}
|
953
|
-
${
|
1043
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
954
1044
|
var StatusChangeDocument = import_graphql_tag.default`
|
955
1045
|
subscription statusChange($transactionId: TransactionId!) {
|
956
1046
|
statusChange(id: $transactionId) {
|
957
|
-
...
|
1047
|
+
...transactionStatusSubscriptionFragment
|
958
1048
|
}
|
959
1049
|
}
|
960
|
-
${
|
1050
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
961
1051
|
function getSdk(requester) {
|
962
1052
|
return {
|
963
1053
|
getVersion(variables, options) {
|
@@ -1011,6 +1101,12 @@ function getSdk(requester) {
|
|
1011
1101
|
getBalance(variables, options) {
|
1012
1102
|
return requester(GetBalanceDocument, variables, options);
|
1013
1103
|
},
|
1104
|
+
getLatestGasPrice(variables, options) {
|
1105
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
1106
|
+
},
|
1107
|
+
estimateGasPrice(variables, options) {
|
1108
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
1109
|
+
},
|
1014
1110
|
getBalances(variables, options) {
|
1015
1111
|
return requester(GetBalancesDocument, variables, options);
|
1016
1112
|
},
|
@@ -1181,7 +1277,7 @@ var MemoryCache = class {
|
|
1181
1277
|
|
1182
1278
|
// src/providers/transaction-request/input.ts
|
1183
1279
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
1184
|
-
var
|
1280
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1185
1281
|
var import_errors3 = require("@fuel-ts/errors");
|
1186
1282
|
var import_math2 = require("@fuel-ts/math");
|
1187
1283
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1204,10 +1300,9 @@ var inputify = (value) => {
|
|
1204
1300
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1205
1301
|
},
|
1206
1302
|
witnessIndex: value.witnessIndex,
|
1207
|
-
maturity: value.maturity ?? 0,
|
1208
1303
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1209
|
-
predicateLength: predicate.length,
|
1210
|
-
predicateDataLength: predicateData.length,
|
1304
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1305
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1211
1306
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1212
1307
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1213
1308
|
};
|
@@ -1215,10 +1310,10 @@ var inputify = (value) => {
|
|
1215
1310
|
case import_transactions.InputType.Contract: {
|
1216
1311
|
return {
|
1217
1312
|
type: import_transactions.InputType.Contract,
|
1218
|
-
txID:
|
1313
|
+
txID: import_configs2.ZeroBytes32,
|
1219
1314
|
outputIndex: 0,
|
1220
|
-
balanceRoot:
|
1221
|
-
stateRoot:
|
1315
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1316
|
+
stateRoot: import_configs2.ZeroBytes32,
|
1222
1317
|
txPointer: {
|
1223
1318
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1224
1319
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1238,8 +1333,8 @@ var inputify = (value) => {
|
|
1238
1333
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1239
1334
|
witnessIndex: value.witnessIndex,
|
1240
1335
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1241
|
-
predicateLength: predicate.length,
|
1242
|
-
predicateDataLength: predicateData.length,
|
1336
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1337
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1243
1338
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1244
1339
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1245
1340
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1256,7 +1351,7 @@ var inputify = (value) => {
|
|
1256
1351
|
};
|
1257
1352
|
|
1258
1353
|
// src/providers/transaction-request/output.ts
|
1259
|
-
var
|
1354
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1260
1355
|
var import_errors4 = require("@fuel-ts/errors");
|
1261
1356
|
var import_math3 = require("@fuel-ts/math");
|
1262
1357
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1276,8 +1371,8 @@ var outputify = (value) => {
|
|
1276
1371
|
return {
|
1277
1372
|
type: import_transactions2.OutputType.Contract,
|
1278
1373
|
inputIndex: value.inputIndex,
|
1279
|
-
balanceRoot:
|
1280
|
-
stateRoot:
|
1374
|
+
balanceRoot: import_configs3.ZeroBytes32,
|
1375
|
+
stateRoot: import_configs3.ZeroBytes32
|
1281
1376
|
};
|
1282
1377
|
}
|
1283
1378
|
case import_transactions2.OutputType.Change: {
|
@@ -1291,9 +1386,9 @@ var outputify = (value) => {
|
|
1291
1386
|
case import_transactions2.OutputType.Variable: {
|
1292
1387
|
return {
|
1293
1388
|
type: import_transactions2.OutputType.Variable,
|
1294
|
-
to:
|
1389
|
+
to: import_configs3.ZeroBytes32,
|
1295
1390
|
amount: (0, import_math3.bn)(0),
|
1296
|
-
assetId:
|
1391
|
+
assetId: import_configs3.ZeroBytes32
|
1297
1392
|
};
|
1298
1393
|
}
|
1299
1394
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1315,7 +1410,7 @@ var outputify = (value) => {
|
|
1315
1410
|
// src/providers/transaction-request/transaction-request.ts
|
1316
1411
|
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
1317
1412
|
var import_address = require("@fuel-ts/address");
|
1318
|
-
var
|
1413
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
1319
1414
|
var import_crypto = require("@fuel-ts/crypto");
|
1320
1415
|
var import_math7 = require("@fuel-ts/math");
|
1321
1416
|
var import_transactions6 = require("@fuel-ts/transactions");
|
@@ -1328,13 +1423,13 @@ var isCoin = (resource) => "id" in resource;
|
|
1328
1423
|
var isMessage = (resource) => "recipient" in resource;
|
1329
1424
|
|
1330
1425
|
// src/providers/utils/receipts.ts
|
1331
|
-
var
|
1426
|
+
var import_configs4 = require("@fuel-ts/address/configs");
|
1332
1427
|
var import_errors5 = require("@fuel-ts/errors");
|
1333
1428
|
var import_math4 = require("@fuel-ts/math");
|
1334
1429
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1335
|
-
var
|
1430
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1336
1431
|
var import_utils5 = require("@fuel-ts/utils");
|
1337
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1432
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1338
1433
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1339
1434
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1340
1435
|
(memo, receipt) => {
|
@@ -1351,15 +1446,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1351
1446
|
missingOutputContractIds: []
|
1352
1447
|
}
|
1353
1448
|
);
|
1354
|
-
var hexOrZero = (hex) => hex ||
|
1449
|
+
var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
|
1355
1450
|
function assembleReceiptByType(receipt) {
|
1356
1451
|
const { receiptType } = receipt;
|
1357
1452
|
switch (receiptType) {
|
1358
1453
|
case "CALL" /* Call */: {
|
1359
1454
|
const callReceipt = {
|
1360
1455
|
type: import_transactions3.ReceiptType.Call,
|
1361
|
-
from: hexOrZero(receipt.
|
1362
|
-
to: hexOrZero(receipt?.to
|
1456
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1457
|
+
to: hexOrZero(receipt?.to),
|
1363
1458
|
amount: (0, import_math4.bn)(receipt.amount),
|
1364
1459
|
assetId: hexOrZero(receipt.assetId),
|
1365
1460
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1373,7 +1468,7 @@ function assembleReceiptByType(receipt) {
|
|
1373
1468
|
case "RETURN" /* Return */: {
|
1374
1469
|
const returnReceipt = {
|
1375
1470
|
type: import_transactions3.ReceiptType.Return,
|
1376
|
-
id: hexOrZero(receipt.
|
1471
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1377
1472
|
val: (0, import_math4.bn)(receipt.val),
|
1378
1473
|
pc: (0, import_math4.bn)(receipt.pc),
|
1379
1474
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1383,7 +1478,7 @@ function assembleReceiptByType(receipt) {
|
|
1383
1478
|
case "RETURN_DATA" /* ReturnData */: {
|
1384
1479
|
const returnDataReceipt = {
|
1385
1480
|
type: import_transactions3.ReceiptType.ReturnData,
|
1386
|
-
id: hexOrZero(receipt.
|
1481
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1387
1482
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1388
1483
|
len: (0, import_math4.bn)(receipt.len),
|
1389
1484
|
digest: hexOrZero(receipt.digest),
|
@@ -1395,7 +1490,7 @@ function assembleReceiptByType(receipt) {
|
|
1395
1490
|
case "PANIC" /* Panic */: {
|
1396
1491
|
const panicReceipt = {
|
1397
1492
|
type: import_transactions3.ReceiptType.Panic,
|
1398
|
-
id: hexOrZero(receipt.
|
1493
|
+
id: hexOrZero(receipt.id),
|
1399
1494
|
reason: (0, import_math4.bn)(receipt.reason),
|
1400
1495
|
pc: (0, import_math4.bn)(receipt.pc),
|
1401
1496
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1406,7 +1501,7 @@ function assembleReceiptByType(receipt) {
|
|
1406
1501
|
case "REVERT" /* Revert */: {
|
1407
1502
|
const revertReceipt = {
|
1408
1503
|
type: import_transactions3.ReceiptType.Revert,
|
1409
|
-
id: hexOrZero(receipt.
|
1504
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1410
1505
|
val: (0, import_math4.bn)(receipt.ra),
|
1411
1506
|
pc: (0, import_math4.bn)(receipt.pc),
|
1412
1507
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1416,7 +1511,7 @@ function assembleReceiptByType(receipt) {
|
|
1416
1511
|
case "LOG" /* Log */: {
|
1417
1512
|
const logReceipt = {
|
1418
1513
|
type: import_transactions3.ReceiptType.Log,
|
1419
|
-
id: hexOrZero(receipt.
|
1514
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1420
1515
|
val0: (0, import_math4.bn)(receipt.ra),
|
1421
1516
|
val1: (0, import_math4.bn)(receipt.rb),
|
1422
1517
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1429,7 +1524,7 @@ function assembleReceiptByType(receipt) {
|
|
1429
1524
|
case "LOG_DATA" /* LogData */: {
|
1430
1525
|
const logDataReceipt = {
|
1431
1526
|
type: import_transactions3.ReceiptType.LogData,
|
1432
|
-
id: hexOrZero(receipt.
|
1527
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1433
1528
|
val0: (0, import_math4.bn)(receipt.ra),
|
1434
1529
|
val1: (0, import_math4.bn)(receipt.rb),
|
1435
1530
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1443,8 +1538,8 @@ function assembleReceiptByType(receipt) {
|
|
1443
1538
|
case "TRANSFER" /* Transfer */: {
|
1444
1539
|
const transferReceipt = {
|
1445
1540
|
type: import_transactions3.ReceiptType.Transfer,
|
1446
|
-
from: hexOrZero(receipt.
|
1447
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1541
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1542
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1448
1543
|
amount: (0, import_math4.bn)(receipt.amount),
|
1449
1544
|
assetId: hexOrZero(receipt.assetId),
|
1450
1545
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1455,8 +1550,8 @@ function assembleReceiptByType(receipt) {
|
|
1455
1550
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1456
1551
|
const transferOutReceipt = {
|
1457
1552
|
type: import_transactions3.ReceiptType.TransferOut,
|
1458
|
-
from: hexOrZero(receipt.
|
1459
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1553
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1554
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1460
1555
|
amount: (0, import_math4.bn)(receipt.amount),
|
1461
1556
|
assetId: hexOrZero(receipt.assetId),
|
1462
1557
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1499,7 +1594,7 @@ function assembleReceiptByType(receipt) {
|
|
1499
1594
|
return receiptMessageOut;
|
1500
1595
|
}
|
1501
1596
|
case "MINT" /* Mint */: {
|
1502
|
-
const contractId = hexOrZero(receipt.
|
1597
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1503
1598
|
const subId = hexOrZero(receipt.subId);
|
1504
1599
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1505
1600
|
const mintReceipt = {
|
@@ -1514,7 +1609,7 @@ function assembleReceiptByType(receipt) {
|
|
1514
1609
|
return mintReceipt;
|
1515
1610
|
}
|
1516
1611
|
case "BURN" /* Burn */: {
|
1517
|
-
const contractId = hexOrZero(receipt.
|
1612
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1518
1613
|
const subId = hexOrZero(receipt.subId);
|
1519
1614
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1520
1615
|
const burnReceipt = {
|
@@ -1599,7 +1694,6 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1599
1694
|
var import_math5 = require("@fuel-ts/math");
|
1600
1695
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1601
1696
|
var import_utils6 = require("@fuel-ts/utils");
|
1602
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1603
1697
|
var getGasUsedFromReceipts = (receipts) => {
|
1604
1698
|
const scriptResult = receipts.filter(
|
1605
1699
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1620,18 +1714,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1620
1714
|
}
|
1621
1715
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1622
1716
|
const witnessCache = [];
|
1623
|
-
const
|
1717
|
+
const chargeableInputs = inputs.filter((input) => {
|
1718
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1719
|
+
if (isCoinOrMessage) {
|
1720
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1721
|
+
return true;
|
1722
|
+
}
|
1723
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1724
|
+
witnessCache.push(input.witnessIndex);
|
1725
|
+
return true;
|
1726
|
+
}
|
1727
|
+
}
|
1728
|
+
return false;
|
1729
|
+
});
|
1730
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1731
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1624
1732
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1625
1733
|
return total.add(
|
1626
|
-
|
1734
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1627
1735
|
);
|
1628
1736
|
}
|
1629
|
-
|
1630
|
-
|
1631
|
-
return total.add(gasCosts.ecr1);
|
1632
|
-
}
|
1633
|
-
return total;
|
1634
|
-
}, (0, import_math5.bn)());
|
1737
|
+
return total.add(gasCosts.ecr1);
|
1738
|
+
}, (0, import_math5.bn)(0));
|
1635
1739
|
return totalGas;
|
1636
1740
|
}
|
1637
1741
|
function getMinGas(params) {
|
@@ -1643,12 +1747,20 @@ function getMinGas(params) {
|
|
1643
1747
|
return minGas;
|
1644
1748
|
}
|
1645
1749
|
function getMaxGas(params) {
|
1646
|
-
const {
|
1750
|
+
const {
|
1751
|
+
gasPerByte,
|
1752
|
+
witnessesLength,
|
1753
|
+
witnessLimit,
|
1754
|
+
minGas,
|
1755
|
+
gasLimit = (0, import_math5.bn)(0),
|
1756
|
+
maxGasPerTx
|
1757
|
+
} = params;
|
1647
1758
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1648
1759
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1649
1760
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1650
1761
|
}
|
1651
|
-
|
1762
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1763
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1652
1764
|
}
|
1653
1765
|
function calculateMetadataGasForTxCreate({
|
1654
1766
|
gasCosts,
|
@@ -1670,6 +1782,10 @@ function calculateMetadataGasForTxScript({
|
|
1670
1782
|
}) {
|
1671
1783
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1672
1784
|
}
|
1785
|
+
var calculateGasFee = (params) => {
|
1786
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1787
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1788
|
+
};
|
1673
1789
|
|
1674
1790
|
// src/providers/utils/json.ts
|
1675
1791
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1715,16 +1831,16 @@ function sleep(time) {
|
|
1715
1831
|
var import_errors7 = require("@fuel-ts/errors");
|
1716
1832
|
var import_math6 = require("@fuel-ts/math");
|
1717
1833
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1718
|
-
var
|
1834
|
+
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1719
1835
|
var assemblePanicError = (status) => {
|
1720
1836
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1721
1837
|
const reason = status.reason;
|
1722
|
-
if (
|
1838
|
+
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1723
1839
|
errorMessage = `${errorMessage}
|
1724
1840
|
|
1725
1841
|
You can read more about this error at:
|
1726
1842
|
|
1727
|
-
${
|
1843
|
+
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1728
1844
|
}
|
1729
1845
|
return { errorMessage, reason };
|
1730
1846
|
};
|
@@ -1736,28 +1852,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1736
1852
|
if (revertReceipt) {
|
1737
1853
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1738
1854
|
switch (reasonHex) {
|
1739
|
-
case
|
1855
|
+
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1740
1856
|
reason = "require";
|
1741
1857
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1742
1858
|
break;
|
1743
1859
|
}
|
1744
|
-
case
|
1860
|
+
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1745
1861
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1746
1862
|
reason = "assert_eq";
|
1747
1863
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1748
1864
|
break;
|
1749
1865
|
}
|
1750
|
-
case
|
1866
|
+
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1751
1867
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1752
1868
|
reason = "assert_ne";
|
1753
1869
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1754
1870
|
break;
|
1755
1871
|
}
|
1756
|
-
case
|
1872
|
+
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1757
1873
|
reason = "assert";
|
1758
1874
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1759
1875
|
break;
|
1760
|
-
case
|
1876
|
+
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1761
1877
|
reason = "MissingOutputChange";
|
1762
1878
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1763
1879
|
break;
|
@@ -1818,7 +1934,7 @@ var witnessify = (value) => {
|
|
1818
1934
|
// src/providers/transaction-request/transaction-request.ts
|
1819
1935
|
var BaseTransactionRequest = class {
|
1820
1936
|
/** Gas price for transaction */
|
1821
|
-
|
1937
|
+
tip;
|
1822
1938
|
/** Block until which tx cannot be included */
|
1823
1939
|
maturity;
|
1824
1940
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1831,38 +1947,34 @@ var BaseTransactionRequest = class {
|
|
1831
1947
|
outputs = [];
|
1832
1948
|
/** List of witnesses */
|
1833
1949
|
witnesses = [];
|
1834
|
-
/** Base asset ID - should be fetched from the chain */
|
1835
|
-
baseAssetId;
|
1836
1950
|
/**
|
1837
1951
|
* Constructor for initializing a base transaction request.
|
1838
1952
|
*
|
1839
1953
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1840
1954
|
*/
|
1841
1955
|
constructor({
|
1842
|
-
|
1956
|
+
tip,
|
1843
1957
|
maturity,
|
1844
1958
|
maxFee,
|
1845
1959
|
witnessLimit,
|
1846
1960
|
inputs,
|
1847
1961
|
outputs,
|
1848
|
-
witnesses
|
1849
|
-
|
1850
|
-
|
1851
|
-
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1962
|
+
witnesses
|
1963
|
+
} = {}) {
|
1964
|
+
this.tip = (0, import_math7.bn)(tip);
|
1852
1965
|
this.maturity = maturity ?? 0;
|
1853
1966
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1854
1967
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1855
1968
|
this.inputs = inputs ?? [];
|
1856
1969
|
this.outputs = outputs ?? [];
|
1857
1970
|
this.witnesses = witnesses ?? [];
|
1858
|
-
this.baseAssetId = baseAssetId;
|
1859
1971
|
}
|
1860
1972
|
static getPolicyMeta(req) {
|
1861
1973
|
let policyTypes = 0;
|
1862
1974
|
const policies = [];
|
1863
|
-
if (req.
|
1864
|
-
policyTypes += import_transactions6.PolicyType.
|
1865
|
-
policies.push({ data: req.
|
1975
|
+
if (req.tip) {
|
1976
|
+
policyTypes += import_transactions6.PolicyType.Tip;
|
1977
|
+
policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
|
1866
1978
|
}
|
1867
1979
|
if (req.witnessLimit) {
|
1868
1980
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -1948,7 +2060,7 @@ var BaseTransactionRequest = class {
|
|
1948
2060
|
* @returns The index of the created witness.
|
1949
2061
|
*/
|
1950
2062
|
addEmptyWitness() {
|
1951
|
-
this.addWitness((0, import_utils9.concat)([
|
2063
|
+
this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
|
1952
2064
|
return this.witnesses.length - 1;
|
1953
2065
|
}
|
1954
2066
|
/**
|
@@ -2046,13 +2158,11 @@ var BaseTransactionRequest = class {
|
|
2046
2158
|
* assetId, if one it was not added yet.
|
2047
2159
|
*
|
2048
2160
|
* @param coin - Coin resource.
|
2049
|
-
* @param predicate - Predicate bytes.
|
2050
|
-
* @param predicateData - Predicate data bytes.
|
2051
2161
|
*/
|
2052
|
-
addCoinInput(coin
|
2162
|
+
addCoinInput(coin) {
|
2053
2163
|
const { assetId, owner, amount } = coin;
|
2054
2164
|
let witnessIndex;
|
2055
|
-
if (predicate) {
|
2165
|
+
if (coin.predicate) {
|
2056
2166
|
witnessIndex = 0;
|
2057
2167
|
} else {
|
2058
2168
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2067,8 +2177,7 @@ var BaseTransactionRequest = class {
|
|
2067
2177
|
amount,
|
2068
2178
|
assetId,
|
2069
2179
|
txPointer: "0x00000000000000000000000000000000",
|
2070
|
-
witnessIndex
|
2071
|
-
predicate: predicate?.bytes
|
2180
|
+
witnessIndex
|
2072
2181
|
};
|
2073
2182
|
this.pushInput(input);
|
2074
2183
|
this.addChangeOutput(owner, assetId);
|
@@ -2078,12 +2187,12 @@ var BaseTransactionRequest = class {
|
|
2078
2187
|
* baseAssetId, if one it was not added yet.
|
2079
2188
|
*
|
2080
2189
|
* @param message - Message resource.
|
2081
|
-
* @param predicate - Predicate bytes.
|
2082
2190
|
*/
|
2083
|
-
addMessageInput(message
|
2191
|
+
addMessageInput(message) {
|
2084
2192
|
const { recipient, sender, amount } = message;
|
2193
|
+
const assetId = import_configs7.BaseAssetId;
|
2085
2194
|
let witnessIndex;
|
2086
|
-
if (predicate) {
|
2195
|
+
if (message.predicate) {
|
2087
2196
|
witnessIndex = 0;
|
2088
2197
|
} else {
|
2089
2198
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2097,11 +2206,10 @@ var BaseTransactionRequest = class {
|
|
2097
2206
|
sender: sender.toB256(),
|
2098
2207
|
recipient: recipient.toB256(),
|
2099
2208
|
amount,
|
2100
|
-
witnessIndex
|
2101
|
-
predicate: predicate?.bytes
|
2209
|
+
witnessIndex
|
2102
2210
|
};
|
2103
2211
|
this.pushInput(input);
|
2104
|
-
this.addChangeOutput(recipient,
|
2212
|
+
this.addChangeOutput(recipient, assetId);
|
2105
2213
|
}
|
2106
2214
|
/**
|
2107
2215
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2129,32 +2237,6 @@ var BaseTransactionRequest = class {
|
|
2129
2237
|
resources.forEach((resource) => this.addResource(resource));
|
2130
2238
|
return this;
|
2131
2239
|
}
|
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
2240
|
/**
|
2159
2241
|
* Adds a coin output to the transaction.
|
2160
2242
|
*
|
@@ -2162,12 +2244,12 @@ var BaseTransactionRequest = class {
|
|
2162
2244
|
* @param amount - Amount of coin.
|
2163
2245
|
* @param assetId - Asset ID of coin.
|
2164
2246
|
*/
|
2165
|
-
addCoinOutput(to, amount, assetId) {
|
2247
|
+
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
2166
2248
|
this.pushOutput({
|
2167
2249
|
type: import_transactions6.OutputType.Coin,
|
2168
2250
|
to: (0, import_address.addressify)(to).toB256(),
|
2169
2251
|
amount,
|
2170
|
-
assetId
|
2252
|
+
assetId
|
2171
2253
|
});
|
2172
2254
|
return this;
|
2173
2255
|
}
|
@@ -2194,7 +2276,7 @@ var BaseTransactionRequest = class {
|
|
2194
2276
|
* @param to - Address of the owner.
|
2195
2277
|
* @param assetId - Asset ID of coin.
|
2196
2278
|
*/
|
2197
|
-
addChangeOutput(to, assetId) {
|
2279
|
+
addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
|
2198
2280
|
const changeOutput = this.getChangeOutputs().find(
|
2199
2281
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
2200
2282
|
);
|
@@ -2202,7 +2284,7 @@ var BaseTransactionRequest = class {
|
|
2202
2284
|
this.pushOutput({
|
2203
2285
|
type: import_transactions6.OutputType.Change,
|
2204
2286
|
to: (0, import_address.addressify)(to).toB256(),
|
2205
|
-
assetId
|
2287
|
+
assetId
|
2206
2288
|
});
|
2207
2289
|
}
|
2208
2290
|
}
|
@@ -2234,7 +2316,7 @@ var BaseTransactionRequest = class {
|
|
2234
2316
|
}
|
2235
2317
|
calculateMaxGas(chainInfo, minGas) {
|
2236
2318
|
const { consensusParameters } = chainInfo;
|
2237
|
-
const { gasPerByte } = consensusParameters;
|
2319
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2238
2320
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2239
2321
|
(acc, wit) => acc + wit.dataLength,
|
2240
2322
|
0
|
@@ -2243,7 +2325,8 @@ var BaseTransactionRequest = class {
|
|
2243
2325
|
gasPerByte,
|
2244
2326
|
minGas,
|
2245
2327
|
witnessesLength,
|
2246
|
-
witnessLimit: this.witnessLimit
|
2328
|
+
witnessLimit: this.witnessLimit,
|
2329
|
+
maxGasPerTx
|
2247
2330
|
});
|
2248
2331
|
}
|
2249
2332
|
/**
|
@@ -2261,24 +2344,27 @@ var BaseTransactionRequest = class {
|
|
2261
2344
|
});
|
2262
2345
|
const updateAssetInput = (assetId, quantity) => {
|
2263
2346
|
const assetInput = findAssetInput(assetId);
|
2347
|
+
let usedQuantity = quantity;
|
2348
|
+
if (assetId === import_configs7.BaseAssetId) {
|
2349
|
+
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2350
|
+
}
|
2264
2351
|
if (assetInput && "assetId" in assetInput) {
|
2265
2352
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2266
|
-
assetInput.amount =
|
2353
|
+
assetInput.amount = usedQuantity;
|
2267
2354
|
} else {
|
2268
2355
|
this.addResources([
|
2269
2356
|
{
|
2270
2357
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2271
|
-
amount:
|
2358
|
+
amount: usedQuantity,
|
2272
2359
|
assetId,
|
2273
2360
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2274
|
-
maturity: 0,
|
2275
2361
|
blockCreated: (0, import_math7.bn)(1),
|
2276
2362
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2277
2363
|
}
|
2278
2364
|
]);
|
2279
2365
|
}
|
2280
2366
|
};
|
2281
|
-
updateAssetInput(
|
2367
|
+
updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
|
2282
2368
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2283
2369
|
}
|
2284
2370
|
/**
|
@@ -2303,7 +2389,7 @@ var BaseTransactionRequest = class {
|
|
2303
2389
|
toJSON() {
|
2304
2390
|
return normalizeJSON(this);
|
2305
2391
|
}
|
2306
|
-
|
2392
|
+
updatePredicateGasUsed(inputs) {
|
2307
2393
|
this.inputs.forEach((i) => {
|
2308
2394
|
let correspondingInput;
|
2309
2395
|
switch (i.type) {
|
@@ -2325,16 +2411,25 @@ var BaseTransactionRequest = class {
|
|
2325
2411
|
}
|
2326
2412
|
});
|
2327
2413
|
}
|
2414
|
+
shiftPredicateData() {
|
2415
|
+
this.inputs.forEach((input) => {
|
2416
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2417
|
+
input.predicateData = input.paddPredicateData(
|
2418
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2419
|
+
);
|
2420
|
+
}
|
2421
|
+
});
|
2422
|
+
}
|
2328
2423
|
};
|
2329
2424
|
|
2330
2425
|
// src/providers/transaction-request/create-transaction-request.ts
|
2331
|
-
var
|
2426
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2332
2427
|
var import_math9 = require("@fuel-ts/math");
|
2333
2428
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2334
2429
|
var import_utils13 = require("@fuel-ts/utils");
|
2335
2430
|
|
2336
2431
|
// src/providers/transaction-request/hash-transaction.ts
|
2337
|
-
var
|
2432
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2338
2433
|
var import_hasher = require("@fuel-ts/hasher");
|
2339
2434
|
var import_math8 = require("@fuel-ts/math");
|
2340
2435
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2343,7 +2438,7 @@ var import_ramda2 = require("ramda");
|
|
2343
2438
|
function hashTransaction(transactionRequest, chainId) {
|
2344
2439
|
const transaction = transactionRequest.toTransaction();
|
2345
2440
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2346
|
-
transaction.receiptsRoot =
|
2441
|
+
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2347
2442
|
}
|
2348
2443
|
transaction.inputs = transaction.inputs.map((input) => {
|
2349
2444
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2365,10 +2460,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2365
2460
|
blockHeight: 0,
|
2366
2461
|
txIndex: 0
|
2367
2462
|
};
|
2368
|
-
inputClone.txID =
|
2463
|
+
inputClone.txID = import_configs8.ZeroBytes32;
|
2369
2464
|
inputClone.outputIndex = 0;
|
2370
|
-
inputClone.balanceRoot =
|
2371
|
-
inputClone.stateRoot =
|
2465
|
+
inputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2466
|
+
inputClone.stateRoot = import_configs8.ZeroBytes32;
|
2372
2467
|
return inputClone;
|
2373
2468
|
}
|
2374
2469
|
default:
|
@@ -2379,8 +2474,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2379
2474
|
const outputClone = (0, import_ramda2.clone)(output);
|
2380
2475
|
switch (outputClone.type) {
|
2381
2476
|
case import_transactions7.OutputType.Contract: {
|
2382
|
-
outputClone.balanceRoot =
|
2383
|
-
outputClone.stateRoot =
|
2477
|
+
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2478
|
+
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2384
2479
|
return outputClone;
|
2385
2480
|
}
|
2386
2481
|
case import_transactions7.OutputType.Change: {
|
@@ -2388,9 +2483,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2388
2483
|
return outputClone;
|
2389
2484
|
}
|
2390
2485
|
case import_transactions7.OutputType.Variable: {
|
2391
|
-
outputClone.to =
|
2486
|
+
outputClone.to = import_configs8.ZeroBytes32;
|
2392
2487
|
outputClone.amount = (0, import_math8.bn)(0);
|
2393
|
-
outputClone.assetId =
|
2488
|
+
outputClone.assetId = import_configs8.ZeroBytes32;
|
2394
2489
|
return outputClone;
|
2395
2490
|
}
|
2396
2491
|
default:
|
@@ -2448,10 +2543,15 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2448
2543
|
*
|
2449
2544
|
* @param createTransactionRequestLike - The initial values for the instance
|
2450
2545
|
*/
|
2451
|
-
constructor({
|
2546
|
+
constructor({
|
2547
|
+
bytecodeWitnessIndex,
|
2548
|
+
salt,
|
2549
|
+
storageSlots,
|
2550
|
+
...rest
|
2551
|
+
} = {}) {
|
2452
2552
|
super(rest);
|
2453
2553
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2454
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2554
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
|
2455
2555
|
this.storageSlots = [...storageSlots ?? []];
|
2456
2556
|
}
|
2457
2557
|
/**
|
@@ -2466,10 +2566,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2466
2566
|
return {
|
2467
2567
|
type: import_transactions8.TransactionType.Create,
|
2468
2568
|
...baseTransaction,
|
2469
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2470
2569
|
bytecodeWitnessIndex,
|
2471
|
-
storageSlotsCount: storageSlots.length,
|
2472
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2570
|
+
storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
|
2571
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2473
2572
|
storageSlots
|
2474
2573
|
};
|
2475
2574
|
}
|
@@ -2519,7 +2618,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2519
2618
|
// src/providers/transaction-request/script-transaction-request.ts
|
2520
2619
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
2521
2620
|
var import_address2 = require("@fuel-ts/address");
|
2522
|
-
var
|
2621
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2523
2622
|
var import_math10 = require("@fuel-ts/math");
|
2524
2623
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2525
2624
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2572,7 +2671,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2572
2671
|
*
|
2573
2672
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2574
2673
|
*/
|
2575
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2674
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2576
2675
|
super(rest);
|
2577
2676
|
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2578
2677
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
@@ -2591,9 +2690,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2591
2690
|
type: import_transactions9.TransactionType.Script,
|
2592
2691
|
scriptGasLimit: this.gasLimit,
|
2593
2692
|
...super.getBaseTransaction(),
|
2594
|
-
scriptLength: script.length,
|
2595
|
-
scriptDataLength: scriptData.length,
|
2596
|
-
receiptsRoot:
|
2693
|
+
scriptLength: (0, import_math10.bn)(script.length),
|
2694
|
+
scriptDataLength: (0, import_math10.bn)(scriptData.length),
|
2695
|
+
receiptsRoot: import_configs10.ZeroBytes32,
|
2597
2696
|
script: (0, import_utils15.hexlify)(script),
|
2598
2697
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2599
2698
|
};
|
@@ -2656,7 +2755,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2656
2755
|
}
|
2657
2756
|
calculateMaxGas(chainInfo, minGas) {
|
2658
2757
|
const { consensusParameters } = chainInfo;
|
2659
|
-
const { gasPerByte } = consensusParameters;
|
2758
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2660
2759
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2661
2760
|
(acc, wit) => acc + wit.dataLength,
|
2662
2761
|
0
|
@@ -2666,7 +2765,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2666
2765
|
minGas,
|
2667
2766
|
witnessesLength,
|
2668
2767
|
witnessLimit: this.witnessLimit,
|
2669
|
-
gasLimit: this.gasLimit
|
2768
|
+
gasLimit: this.gasLimit,
|
2769
|
+
maxGasPerTx
|
2670
2770
|
});
|
2671
2771
|
}
|
2672
2772
|
/**
|
@@ -2741,15 +2841,32 @@ var transactionRequestify = (obj) => {
|
|
2741
2841
|
}
|
2742
2842
|
}
|
2743
2843
|
};
|
2844
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2845
|
+
(acc, input) => {
|
2846
|
+
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2847
|
+
acc.utxos.push(input.id);
|
2848
|
+
}
|
2849
|
+
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2850
|
+
acc.messages.push(input.nonce);
|
2851
|
+
}
|
2852
|
+
return acc;
|
2853
|
+
},
|
2854
|
+
{
|
2855
|
+
utxos: [],
|
2856
|
+
messages: []
|
2857
|
+
}
|
2858
|
+
);
|
2744
2859
|
|
2745
2860
|
// src/providers/transaction-response/transaction-response.ts
|
2746
2861
|
var import_errors13 = require("@fuel-ts/errors");
|
2747
|
-
var
|
2748
|
-
var
|
2749
|
-
var
|
2862
|
+
var import_math15 = require("@fuel-ts/math");
|
2863
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
2864
|
+
var import_utils20 = require("@fuel-ts/utils");
|
2750
2865
|
|
2751
2866
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2752
|
-
var
|
2867
|
+
var import_math14 = require("@fuel-ts/math");
|
2868
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2869
|
+
var import_utils18 = require("@fuel-ts/utils");
|
2753
2870
|
|
2754
2871
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2755
2872
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2757,9 +2874,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2757
2874
|
var import_utils16 = require("@fuel-ts/utils");
|
2758
2875
|
var calculateTransactionFee = (params) => {
|
2759
2876
|
const {
|
2760
|
-
|
2877
|
+
gasPrice,
|
2761
2878
|
rawPayload,
|
2762
|
-
|
2879
|
+
tip,
|
2880
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2763
2881
|
} = params;
|
2764
2882
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2765
2883
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2769,8 +2887,7 @@ var calculateTransactionFee = (params) => {
|
|
2769
2887
|
return {
|
2770
2888
|
fee: (0, import_math11.bn)(0),
|
2771
2889
|
minFee: (0, import_math11.bn)(0),
|
2772
|
-
maxFee: (0, import_math11.bn)(0)
|
2773
|
-
feeFromGasUsed: (0, import_math11.bn)(0)
|
2890
|
+
maxFee: (0, import_math11.bn)(0)
|
2774
2891
|
};
|
2775
2892
|
}
|
2776
2893
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2802,7 +2919,6 @@ var calculateTransactionFee = (params) => {
|
|
2802
2919
|
metadataGas,
|
2803
2920
|
txBytesSize: transactionBytes.length
|
2804
2921
|
});
|
2805
|
-
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2806
2922
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2807
2923
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2808
2924
|
const maxGas = getMaxGas({
|
@@ -2810,22 +2926,30 @@ var calculateTransactionFee = (params) => {
|
|
2810
2926
|
minGas,
|
2811
2927
|
witnessesLength,
|
2812
2928
|
gasLimit,
|
2813
|
-
witnessLimit
|
2929
|
+
witnessLimit,
|
2930
|
+
maxGasPerTx
|
2931
|
+
});
|
2932
|
+
const minFee = calculateGasFee({
|
2933
|
+
gasPrice,
|
2934
|
+
gas: minGas,
|
2935
|
+
priceFactor: gasPriceFactor,
|
2936
|
+
tip
|
2937
|
+
});
|
2938
|
+
const maxFee = calculateGasFee({
|
2939
|
+
gasPrice,
|
2940
|
+
gas: maxGas,
|
2941
|
+
priceFactor: gasPriceFactor,
|
2942
|
+
tip
|
2814
2943
|
});
|
2815
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2816
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2817
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2818
|
-
const fee = minFee.add(feeFromGasUsed);
|
2819
2944
|
return {
|
2820
|
-
fee,
|
2821
2945
|
minFee,
|
2822
2946
|
maxFee,
|
2823
|
-
|
2947
|
+
fee: maxFee
|
2824
2948
|
};
|
2825
2949
|
};
|
2826
2950
|
|
2827
2951
|
// src/providers/transaction-summary/operations.ts
|
2828
|
-
var
|
2952
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
2829
2953
|
var import_errors11 = require("@fuel-ts/errors");
|
2830
2954
|
var import_math13 = require("@fuel-ts/math");
|
2831
2955
|
var import_transactions14 = require("@fuel-ts/transactions");
|
@@ -3170,7 +3294,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3170
3294
|
const { to: toAddress, assetId, amount } = receipt;
|
3171
3295
|
let { from: fromAddress } = receipt;
|
3172
3296
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3173
|
-
if (
|
3297
|
+
if (import_configs11.ZeroBytes32 === fromAddress) {
|
3174
3298
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3175
3299
|
fromAddress = change?.to || fromAddress;
|
3176
3300
|
}
|
@@ -3434,10 +3558,12 @@ function assembleTransactionSummary(params) {
|
|
3434
3558
|
gqlTransactionStatus,
|
3435
3559
|
abiMap = {},
|
3436
3560
|
maxInputs,
|
3437
|
-
gasCosts
|
3561
|
+
gasCosts,
|
3562
|
+
maxGasPerTx,
|
3563
|
+
gasPrice
|
3438
3564
|
} = params;
|
3439
3565
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3440
|
-
const rawPayload = (0,
|
3566
|
+
const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
|
3441
3567
|
const operations = getOperations({
|
3442
3568
|
transactionType: transaction.type,
|
3443
3569
|
inputs: transaction.inputs || [],
|
@@ -3448,11 +3574,14 @@ function assembleTransactionSummary(params) {
|
|
3448
3574
|
maxInputs
|
3449
3575
|
});
|
3450
3576
|
const typeName = getTransactionTypeName(transaction.type);
|
3577
|
+
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3451
3578
|
const { fee } = calculateTransactionFee({
|
3452
|
-
|
3579
|
+
gasPrice,
|
3453
3580
|
rawPayload,
|
3581
|
+
tip,
|
3454
3582
|
consensusParameters: {
|
3455
3583
|
gasCosts,
|
3584
|
+
maxGasPerTx,
|
3456
3585
|
feeParams: {
|
3457
3586
|
gasPerByte,
|
3458
3587
|
gasPriceFactor
|
@@ -3464,7 +3593,7 @@ function assembleTransactionSummary(params) {
|
|
3464
3593
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3465
3594
|
let date;
|
3466
3595
|
if (time) {
|
3467
|
-
date =
|
3596
|
+
date = import_utils18.DateTime.fromTai64(time);
|
3468
3597
|
}
|
3469
3598
|
const transactionSummary = {
|
3470
3599
|
id,
|
@@ -3492,12 +3621,12 @@ function assembleTransactionSummary(params) {
|
|
3492
3621
|
|
3493
3622
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3494
3623
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3495
|
-
var
|
3624
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
3496
3625
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3497
3626
|
return receipts.reduce((logs, receipt) => {
|
3498
|
-
if (receipt.type ===
|
3627
|
+
if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
|
3499
3628
|
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3500
|
-
const data = receipt.type ===
|
3629
|
+
const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3501
3630
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3502
3631
|
logs.push(decodedLog);
|
3503
3632
|
}
|
@@ -3512,7 +3641,7 @@ var TransactionResponse = class {
|
|
3512
3641
|
/** Current provider */
|
3513
3642
|
provider;
|
3514
3643
|
/** Gas used on the transaction */
|
3515
|
-
gasUsed = (0,
|
3644
|
+
gasUsed = (0, import_math15.bn)(0);
|
3516
3645
|
/** The graphql Transaction with receipts object. */
|
3517
3646
|
gqlTransaction;
|
3518
3647
|
abis;
|
@@ -3570,8 +3699,8 @@ var TransactionResponse = class {
|
|
3570
3699
|
* @returns The decoded transaction.
|
3571
3700
|
*/
|
3572
3701
|
decodeTransaction(transactionWithReceipts) {
|
3573
|
-
return new
|
3574
|
-
(0,
|
3702
|
+
return new import_transactions18.TransactionCoder().decode(
|
3703
|
+
(0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
|
3575
3704
|
0
|
3576
3705
|
)?.[0];
|
3577
3706
|
}
|
@@ -3590,20 +3719,27 @@ var TransactionResponse = class {
|
|
3590
3719
|
const decodedTransaction = this.decodeTransaction(
|
3591
3720
|
transaction
|
3592
3721
|
);
|
3593
|
-
|
3594
|
-
|
3722
|
+
let txReceipts = [];
|
3723
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3724
|
+
txReceipts = transaction.status.receipts;
|
3725
|
+
}
|
3726
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3727
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3728
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3595
3729
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3596
3730
|
const transactionSummary = assembleTransactionSummary({
|
3597
3731
|
id: this.id,
|
3598
3732
|
receipts,
|
3599
3733
|
transaction: decodedTransaction,
|
3600
|
-
transactionBytes: (0,
|
3734
|
+
transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
|
3601
3735
|
gqlTransactionStatus: transaction.status,
|
3602
3736
|
gasPerByte,
|
3603
3737
|
gasPriceFactor,
|
3604
3738
|
abiMap: contractsAbiMap,
|
3605
3739
|
maxInputs,
|
3606
|
-
gasCosts
|
3740
|
+
gasCosts,
|
3741
|
+
maxGasPerTx,
|
3742
|
+
gasPrice
|
3607
3743
|
});
|
3608
3744
|
return transactionSummary;
|
3609
3745
|
}
|
@@ -3730,30 +3866,29 @@ var processGqlChain = (chain) => {
|
|
3730
3866
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3731
3867
|
return {
|
3732
3868
|
name,
|
3733
|
-
baseChainHeight: (0,
|
3869
|
+
baseChainHeight: (0, import_math16.bn)(daHeight),
|
3734
3870
|
consensusParameters: {
|
3735
|
-
contractMaxSize: (0,
|
3736
|
-
maxInputs: (0,
|
3737
|
-
maxOutputs: (0,
|
3738
|
-
maxWitnesses: (0,
|
3739
|
-
maxGasPerTx: (0,
|
3740
|
-
maxScriptLength: (0,
|
3741
|
-
maxScriptDataLength: (0,
|
3742
|
-
maxStorageSlots: (0,
|
3743
|
-
maxPredicateLength: (0,
|
3744
|
-
maxPredicateDataLength: (0,
|
3745
|
-
maxGasPerPredicate: (0,
|
3746
|
-
gasPriceFactor: (0,
|
3747
|
-
gasPerByte: (0,
|
3748
|
-
maxMessageDataLength: (0,
|
3749
|
-
chainId: (0,
|
3750
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3871
|
+
contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
|
3872
|
+
maxInputs: (0, import_math16.bn)(txParams.maxInputs),
|
3873
|
+
maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
|
3874
|
+
maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
|
3875
|
+
maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
|
3876
|
+
maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
|
3877
|
+
maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
|
3878
|
+
maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
|
3879
|
+
maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
|
3880
|
+
maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
|
3881
|
+
maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
|
3882
|
+
gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
|
3883
|
+
gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
|
3884
|
+
maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
|
3885
|
+
chainId: (0, import_math16.bn)(consensusParameters.chainId),
|
3751
3886
|
gasCosts
|
3752
3887
|
},
|
3753
3888
|
gasCosts,
|
3754
3889
|
latestBlock: {
|
3755
3890
|
id: latestBlock.id,
|
3756
|
-
height: (0,
|
3891
|
+
height: (0, import_math16.bn)(latestBlock.height),
|
3757
3892
|
time: latestBlock.header.time,
|
3758
3893
|
transactions: latestBlock.transactions.map((i) => ({
|
3759
3894
|
id: i.id
|
@@ -3847,10 +3982,8 @@ var _Provider = class {
|
|
3847
3982
|
* Returns some helpful parameters related to gas fees.
|
3848
3983
|
*/
|
3849
3984
|
getGasConfig() {
|
3850
|
-
const { minGasPrice } = this.getNode();
|
3851
3985
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3852
3986
|
return {
|
3853
|
-
minGasPrice,
|
3854
3987
|
maxGasPerTx,
|
3855
3988
|
maxGasPerPredicate,
|
3856
3989
|
gasPriceFactor,
|
@@ -3948,7 +4081,7 @@ var _Provider = class {
|
|
3948
4081
|
*/
|
3949
4082
|
async getBlockNumber() {
|
3950
4083
|
const { chain } = await this.operations.getChain();
|
3951
|
-
return (0,
|
4084
|
+
return (0, import_math16.bn)(chain.latestBlock.height, 10);
|
3952
4085
|
}
|
3953
4086
|
/**
|
3954
4087
|
* Returns the chain information.
|
@@ -3958,13 +4091,11 @@ var _Provider = class {
|
|
3958
4091
|
async fetchNode() {
|
3959
4092
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3960
4093
|
const processedNodeInfo = {
|
3961
|
-
maxDepth: (0,
|
3962
|
-
maxTx: (0,
|
3963
|
-
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
4094
|
+
maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
|
4095
|
+
maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
|
3964
4096
|
nodeVersion: nodeInfo.nodeVersion,
|
3965
4097
|
utxoValidation: nodeInfo.utxoValidation,
|
3966
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3967
|
-
peers: nodeInfo.peers
|
4098
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3968
4099
|
};
|
3969
4100
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3970
4101
|
return processedNodeInfo;
|
@@ -3990,17 +4121,6 @@ var _Provider = class {
|
|
3990
4121
|
} = this.getChain();
|
3991
4122
|
return chainId.toNumber();
|
3992
4123
|
}
|
3993
|
-
/**
|
3994
|
-
* Returns the base asset ID
|
3995
|
-
*
|
3996
|
-
* @returns A promise that resolves to the base asset ID
|
3997
|
-
*/
|
3998
|
-
getBaseAssetId() {
|
3999
|
-
const {
|
4000
|
-
consensusParameters: { baseAssetId }
|
4001
|
-
} = this.getChain();
|
4002
|
-
return baseAssetId;
|
4003
|
-
}
|
4004
4124
|
/**
|
4005
4125
|
* Submits a transaction to the chain to be executed.
|
4006
4126
|
*
|
@@ -4017,9 +4137,9 @@ var _Provider = class {
|
|
4017
4137
|
if (estimateTxDependencies) {
|
4018
4138
|
await this.estimateTxDependencies(transactionRequest);
|
4019
4139
|
}
|
4020
|
-
const encodedTransaction = (0,
|
4140
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4021
4141
|
let abis;
|
4022
|
-
if (transactionRequest.type ===
|
4142
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4023
4143
|
abis = transactionRequest.abis;
|
4024
4144
|
}
|
4025
4145
|
if (awaitExecution) {
|
@@ -4060,15 +4180,14 @@ var _Provider = class {
|
|
4060
4180
|
if (estimateTxDependencies) {
|
4061
4181
|
return this.estimateTxDependencies(transactionRequest);
|
4062
4182
|
}
|
4063
|
-
const encodedTransaction = (0,
|
4064
|
-
const { dryRun:
|
4065
|
-
encodedTransaction,
|
4183
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4184
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4185
|
+
encodedTransactions: encodedTransaction,
|
4066
4186
|
utxoValidation: utxoValidation || false
|
4067
4187
|
});
|
4068
|
-
const receipts =
|
4069
|
-
|
4070
|
-
|
4071
|
-
};
|
4188
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
4189
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4190
|
+
return { receipts, dryrunStatus: status };
|
4072
4191
|
}
|
4073
4192
|
/**
|
4074
4193
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4079,13 +4198,13 @@ var _Provider = class {
|
|
4079
4198
|
async estimatePredicates(transactionRequest) {
|
4080
4199
|
const shouldEstimatePredicates = Boolean(
|
4081
4200
|
transactionRequest.inputs.find(
|
4082
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4201
|
+
(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()
|
4083
4202
|
)
|
4084
4203
|
);
|
4085
4204
|
if (!shouldEstimatePredicates) {
|
4086
4205
|
return transactionRequest;
|
4087
4206
|
}
|
4088
|
-
const encodedTransaction = (0,
|
4207
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4089
4208
|
const response = await this.operations.estimatePredicates({
|
4090
4209
|
encodedTransaction
|
4091
4210
|
});
|
@@ -4094,7 +4213,7 @@ var _Provider = class {
|
|
4094
4213
|
} = response;
|
4095
4214
|
if (inputs) {
|
4096
4215
|
inputs.forEach((input, index) => {
|
4097
|
-
if ("predicateGasUsed" in input && (0,
|
4216
|
+
if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
|
4098
4217
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4099
4218
|
}
|
4100
4219
|
});
|
@@ -4107,31 +4226,31 @@ var _Provider = class {
|
|
4107
4226
|
* If there are missing variable outputs,
|
4108
4227
|
* `addVariableOutputs` is called on the transaction.
|
4109
4228
|
*
|
4110
|
-
* @privateRemarks
|
4111
|
-
* TODO: Investigate support for missing contract IDs
|
4112
|
-
* TODO: Add support for missing output messages
|
4113
4229
|
*
|
4114
4230
|
* @param transactionRequest - The transaction request object.
|
4115
4231
|
* @returns A promise.
|
4116
4232
|
*/
|
4117
4233
|
async estimateTxDependencies(transactionRequest) {
|
4118
|
-
if (transactionRequest.type ===
|
4234
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Create) {
|
4119
4235
|
return {
|
4120
4236
|
receipts: [],
|
4121
4237
|
outputVariables: 0,
|
4122
4238
|
missingContractIds: []
|
4123
4239
|
};
|
4124
4240
|
}
|
4125
|
-
await this.estimatePredicates(transactionRequest);
|
4126
4241
|
let receipts = [];
|
4127
4242
|
const missingContractIds = [];
|
4128
4243
|
let outputVariables = 0;
|
4244
|
+
let dryrunStatus;
|
4129
4245
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4130
|
-
const {
|
4131
|
-
|
4246
|
+
const {
|
4247
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4248
|
+
} = await this.operations.dryRun({
|
4249
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4132
4250
|
utxoValidation: false
|
4133
4251
|
});
|
4134
|
-
receipts =
|
4252
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4253
|
+
dryrunStatus = status;
|
4135
4254
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4136
4255
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4137
4256
|
if (hasMissingOutputs) {
|
@@ -4141,6 +4260,10 @@ var _Provider = class {
|
|
4141
4260
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4142
4261
|
missingContractIds.push(contractId);
|
4143
4262
|
});
|
4263
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4264
|
+
transactionRequest
|
4265
|
+
});
|
4266
|
+
transactionRequest.maxFee = maxFee;
|
4144
4267
|
} else {
|
4145
4268
|
break;
|
4146
4269
|
}
|
@@ -4148,37 +4271,139 @@ var _Provider = class {
|
|
4148
4271
|
return {
|
4149
4272
|
receipts,
|
4150
4273
|
outputVariables,
|
4151
|
-
missingContractIds
|
4274
|
+
missingContractIds,
|
4275
|
+
dryrunStatus
|
4152
4276
|
};
|
4153
4277
|
}
|
4278
|
+
/**
|
4279
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4280
|
+
*
|
4281
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4282
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4283
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4284
|
+
*
|
4285
|
+
* @param transactionRequests - Array of transaction request objects.
|
4286
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4287
|
+
*/
|
4288
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4289
|
+
const results = transactionRequests.map(() => ({
|
4290
|
+
receipts: [],
|
4291
|
+
outputVariables: 0,
|
4292
|
+
missingContractIds: [],
|
4293
|
+
dryrunStatus: void 0
|
4294
|
+
}));
|
4295
|
+
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4296
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4297
|
+
allRequests.forEach((req, index) => {
|
4298
|
+
if (req.type === import_transactions19.TransactionType.Script) {
|
4299
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4300
|
+
}
|
4301
|
+
});
|
4302
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4303
|
+
let attempt = 0;
|
4304
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4305
|
+
const encodedTransactions = transactionsToProcess.map(
|
4306
|
+
(index) => serializedTransactionsMap.get(index)
|
4307
|
+
);
|
4308
|
+
const dryRunResults = await this.operations.dryRun({
|
4309
|
+
encodedTransactions,
|
4310
|
+
utxoValidation: false
|
4311
|
+
});
|
4312
|
+
const nextRoundTransactions = [];
|
4313
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4314
|
+
const currentResultIndex = transactionsToProcess[i];
|
4315
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4316
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4317
|
+
results[currentResultIndex].dryrunStatus = status;
|
4318
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4319
|
+
results[currentResultIndex].receipts
|
4320
|
+
);
|
4321
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4322
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4323
|
+
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4324
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4325
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4326
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4327
|
+
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4328
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4329
|
+
});
|
4330
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4331
|
+
transactionRequest: requestToProcess
|
4332
|
+
});
|
4333
|
+
requestToProcess.maxFee = maxFee;
|
4334
|
+
serializedTransactionsMap.set(
|
4335
|
+
currentResultIndex,
|
4336
|
+
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4337
|
+
);
|
4338
|
+
nextRoundTransactions.push(currentResultIndex);
|
4339
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4340
|
+
}
|
4341
|
+
}
|
4342
|
+
transactionsToProcess = nextRoundTransactions;
|
4343
|
+
attempt += 1;
|
4344
|
+
}
|
4345
|
+
return results;
|
4346
|
+
}
|
4347
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4348
|
+
if (estimateTxDependencies) {
|
4349
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4350
|
+
}
|
4351
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4352
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4353
|
+
encodedTransactions,
|
4354
|
+
utxoValidation: utxoValidation || false
|
4355
|
+
});
|
4356
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4357
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4358
|
+
return { receipts, dryrunStatus: status };
|
4359
|
+
});
|
4360
|
+
return results;
|
4361
|
+
}
|
4154
4362
|
/**
|
4155
4363
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4156
4364
|
* @param transactionRequest - The transaction request object.
|
4157
4365
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4158
4366
|
*/
|
4159
|
-
estimateTxGasAndFee(params) {
|
4367
|
+
async estimateTxGasAndFee(params) {
|
4160
4368
|
const { transactionRequest } = params;
|
4161
|
-
|
4369
|
+
let { gasPrice } = params;
|
4162
4370
|
const chainInfo = this.getChain();
|
4163
|
-
const
|
4164
|
-
transactionRequest.gasPrice = gasPrice;
|
4371
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
4165
4372
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4166
|
-
|
4167
|
-
|
4373
|
+
if (!gasPrice) {
|
4374
|
+
gasPrice = await this.estimateGasPrice(10);
|
4375
|
+
}
|
4376
|
+
const minFee = calculateGasFee({
|
4377
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4378
|
+
gas: minGas,
|
4379
|
+
priceFactor: gasPriceFactor,
|
4380
|
+
tip: transactionRequest.tip
|
4381
|
+
}).add(1);
|
4382
|
+
let gasLimit = (0, import_math16.bn)(0);
|
4383
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4384
|
+
gasLimit = transactionRequest.gasLimit;
|
4168
4385
|
if (transactionRequest.gasLimit.eq(0)) {
|
4169
4386
|
transactionRequest.gasLimit = minGas;
|
4170
4387
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4171
4388
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4172
4389
|
);
|
4390
|
+
gasLimit = transactionRequest.gasLimit;
|
4173
4391
|
}
|
4174
4392
|
}
|
4175
4393
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4176
|
-
const maxFee =
|
4394
|
+
const maxFee = calculateGasFee({
|
4395
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4396
|
+
gas: maxGas,
|
4397
|
+
priceFactor: gasPriceFactor,
|
4398
|
+
tip: transactionRequest.tip
|
4399
|
+
}).add(1);
|
4177
4400
|
return {
|
4178
4401
|
minGas,
|
4179
4402
|
minFee,
|
4180
4403
|
maxGas,
|
4181
|
-
maxFee
|
4404
|
+
maxFee,
|
4405
|
+
gasPrice,
|
4406
|
+
gasLimit
|
4182
4407
|
};
|
4183
4408
|
}
|
4184
4409
|
/**
|
@@ -4196,15 +4421,17 @@ var _Provider = class {
|
|
4196
4421
|
if (estimateTxDependencies) {
|
4197
4422
|
return this.estimateTxDependencies(transactionRequest);
|
4198
4423
|
}
|
4199
|
-
const
|
4200
|
-
const { dryRun:
|
4201
|
-
|
4424
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4425
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4426
|
+
encodedTransactions,
|
4202
4427
|
utxoValidation: true
|
4203
4428
|
});
|
4204
|
-
const
|
4205
|
-
|
4206
|
-
receipts
|
4207
|
-
|
4429
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4430
|
+
const { id, receipts, status } = dryRunStatus;
|
4431
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4432
|
+
return { id, receipts: processedReceipts, status };
|
4433
|
+
});
|
4434
|
+
return { receipts: callResult[0].receipts };
|
4208
4435
|
}
|
4209
4436
|
/**
|
4210
4437
|
* Returns a transaction cost to enable user
|
@@ -4221,77 +4448,79 @@ var _Provider = class {
|
|
4221
4448
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4222
4449
|
* @returns A promise that resolves to the transaction cost object.
|
4223
4450
|
*/
|
4224
|
-
async getTransactionCost(transactionRequestLike,
|
4225
|
-
estimateTxDependencies = true,
|
4226
|
-
estimatePredicates = true,
|
4227
|
-
resourcesOwner,
|
4228
|
-
signatureCallback
|
4229
|
-
} = {}) {
|
4451
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
4230
4452
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4231
|
-
const
|
4232
|
-
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4233
|
-
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4453
|
+
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
4234
4454
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4235
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4455
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4236
4456
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4457
|
+
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4237
4458
|
if (isScriptTransaction) {
|
4238
|
-
txRequestClone.gasLimit = (0,
|
4459
|
+
txRequestClone.gasLimit = (0, import_math16.bn)(0);
|
4239
4460
|
}
|
4240
|
-
if (
|
4241
|
-
|
4242
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4243
|
-
}
|
4244
|
-
await this.estimatePredicates(txRequestClone);
|
4461
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4462
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4245
4463
|
}
|
4464
|
+
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4465
|
+
let addedSignatures = 0;
|
4246
4466
|
if (signatureCallback && isScriptTransaction) {
|
4247
|
-
|
4467
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4468
|
+
await signatureCallback(signedRequest);
|
4469
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4248
4470
|
}
|
4249
|
-
|
4250
|
-
|
4471
|
+
await this.estimatePredicates(signedRequest);
|
4472
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4473
|
+
transactionRequest: signedRequest
|
4251
4474
|
});
|
4252
4475
|
let receipts = [];
|
4253
4476
|
let missingContractIds = [];
|
4254
4477
|
let outputVariables = 0;
|
4255
|
-
let gasUsed = (0,
|
4256
|
-
|
4257
|
-
|
4478
|
+
let gasUsed = (0, import_math16.bn)(0);
|
4479
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4480
|
+
txRequestClone.maxFee = maxFee;
|
4481
|
+
if (isScriptTransaction) {
|
4482
|
+
txRequestClone.gasLimit = gasLimit;
|
4483
|
+
if (signatureCallback) {
|
4484
|
+
await signatureCallback(txRequestClone);
|
4485
|
+
}
|
4258
4486
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4259
4487
|
receipts = result.receipts;
|
4260
4488
|
outputVariables = result.outputVariables;
|
4261
4489
|
missingContractIds = result.missingContractIds;
|
4262
4490
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4263
4491
|
txRequestClone.gasLimit = gasUsed;
|
4264
|
-
|
4265
|
-
|
4266
|
-
|
4492
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4493
|
+
transactionRequest: txRequestClone,
|
4494
|
+
gasPrice
|
4267
4495
|
}));
|
4268
4496
|
}
|
4269
4497
|
return {
|
4270
4498
|
requiredQuantities: allQuantities,
|
4271
4499
|
receipts,
|
4272
4500
|
gasUsed,
|
4273
|
-
|
4274
|
-
gasPrice: setGasPrice,
|
4501
|
+
gasPrice,
|
4275
4502
|
minGas,
|
4276
4503
|
maxGas,
|
4277
4504
|
minFee,
|
4278
4505
|
maxFee,
|
4279
|
-
estimatedInputs: txRequestClone.inputs,
|
4280
4506
|
outputVariables,
|
4281
|
-
missingContractIds
|
4507
|
+
missingContractIds,
|
4508
|
+
addedSignatures,
|
4509
|
+
estimatedPredicates: txRequestClone.inputs
|
4282
4510
|
};
|
4283
4511
|
}
|
4284
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4512
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4285
4513
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4286
4514
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4287
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4515
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4516
|
+
quantitiesToContract
|
4517
|
+
});
|
4288
4518
|
transactionRequest.addResources(
|
4289
4519
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4290
4520
|
);
|
4291
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4292
|
-
|
4293
|
-
|
4294
|
-
);
|
4521
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4522
|
+
quantitiesToContract
|
4523
|
+
});
|
4295
4524
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4296
4525
|
return {
|
4297
4526
|
resources,
|
@@ -4307,17 +4536,16 @@ var _Provider = class {
|
|
4307
4536
|
const result = await this.operations.getCoins({
|
4308
4537
|
first: 10,
|
4309
4538
|
...paginationArgs,
|
4310
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4539
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4311
4540
|
});
|
4312
4541
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4313
4542
|
return coins.map((coin) => ({
|
4314
4543
|
id: coin.utxoId,
|
4315
4544
|
assetId: coin.assetId,
|
4316
|
-
amount: (0,
|
4545
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4317
4546
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4318
|
-
|
4319
|
-
|
4320
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4547
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4548
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4321
4549
|
}));
|
4322
4550
|
}
|
4323
4551
|
/**
|
@@ -4331,19 +4559,19 @@ var _Provider = class {
|
|
4331
4559
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4332
4560
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4333
4561
|
const excludeInput = {
|
4334
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4335
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4562
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4563
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4336
4564
|
};
|
4337
4565
|
if (this.cache) {
|
4338
4566
|
const uniqueUtxos = new Set(
|
4339
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4567
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4340
4568
|
);
|
4341
4569
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4342
4570
|
}
|
4343
4571
|
const coinsQuery = {
|
4344
4572
|
owner: ownerAddress.toB256(),
|
4345
4573
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4346
|
-
assetId: (0,
|
4574
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4347
4575
|
amount: amount.toString(10),
|
4348
4576
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4349
4577
|
})),
|
@@ -4354,9 +4582,9 @@ var _Provider = class {
|
|
4354
4582
|
switch (coin.__typename) {
|
4355
4583
|
case "MessageCoin":
|
4356
4584
|
return {
|
4357
|
-
amount: (0,
|
4585
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4358
4586
|
assetId: coin.assetId,
|
4359
|
-
daHeight: (0,
|
4587
|
+
daHeight: (0, import_math16.bn)(coin.daHeight),
|
4360
4588
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4361
4589
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4362
4590
|
nonce: coin.nonce
|
@@ -4364,12 +4592,11 @@ var _Provider = class {
|
|
4364
4592
|
case "Coin":
|
4365
4593
|
return {
|
4366
4594
|
id: coin.utxoId,
|
4367
|
-
amount: (0,
|
4595
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4368
4596
|
assetId: coin.assetId,
|
4369
4597
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4370
|
-
|
4371
|
-
|
4372
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4598
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4599
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4373
4600
|
};
|
4374
4601
|
default:
|
4375
4602
|
return null;
|
@@ -4386,13 +4613,13 @@ var _Provider = class {
|
|
4386
4613
|
async getBlock(idOrHeight) {
|
4387
4614
|
let variables;
|
4388
4615
|
if (typeof idOrHeight === "number") {
|
4389
|
-
variables = { height: (0,
|
4616
|
+
variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4390
4617
|
} else if (idOrHeight === "latest") {
|
4391
4618
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4392
4619
|
} else if (idOrHeight.length === 66) {
|
4393
4620
|
variables = { blockId: idOrHeight };
|
4394
4621
|
} else {
|
4395
|
-
variables = { blockId: (0,
|
4622
|
+
variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4396
4623
|
}
|
4397
4624
|
const { block } = await this.operations.getBlock(variables);
|
4398
4625
|
if (!block) {
|
@@ -4400,7 +4627,7 @@ var _Provider = class {
|
|
4400
4627
|
}
|
4401
4628
|
return {
|
4402
4629
|
id: block.id,
|
4403
|
-
height: (0,
|
4630
|
+
height: (0, import_math16.bn)(block.height),
|
4404
4631
|
time: block.header.time,
|
4405
4632
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4406
4633
|
};
|
@@ -4415,7 +4642,7 @@ var _Provider = class {
|
|
4415
4642
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4416
4643
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4417
4644
|
id: block.id,
|
4418
|
-
height: (0,
|
4645
|
+
height: (0, import_math16.bn)(block.height),
|
4419
4646
|
time: block.header.time,
|
4420
4647
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4421
4648
|
}));
|
@@ -4430,7 +4657,7 @@ var _Provider = class {
|
|
4430
4657
|
async getBlockWithTransactions(idOrHeight) {
|
4431
4658
|
let variables;
|
4432
4659
|
if (typeof idOrHeight === "number") {
|
4433
|
-
variables = { blockHeight: (0,
|
4660
|
+
variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4434
4661
|
} else if (idOrHeight === "latest") {
|
4435
4662
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4436
4663
|
} else {
|
@@ -4442,11 +4669,11 @@ var _Provider = class {
|
|
4442
4669
|
}
|
4443
4670
|
return {
|
4444
4671
|
id: block.id,
|
4445
|
-
height: (0,
|
4672
|
+
height: (0, import_math16.bn)(block.height, 10),
|
4446
4673
|
time: block.header.time,
|
4447
4674
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4448
4675
|
transactions: block.transactions.map(
|
4449
|
-
(tx) => new
|
4676
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4450
4677
|
)
|
4451
4678
|
};
|
4452
4679
|
}
|
@@ -4461,8 +4688,8 @@ var _Provider = class {
|
|
4461
4688
|
if (!transaction) {
|
4462
4689
|
return null;
|
4463
4690
|
}
|
4464
|
-
return new
|
4465
|
-
(0,
|
4691
|
+
return new import_transactions19.TransactionCoder().decode(
|
4692
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4466
4693
|
0
|
4467
4694
|
)?.[0];
|
4468
4695
|
}
|
@@ -4489,9 +4716,9 @@ var _Provider = class {
|
|
4489
4716
|
async getContractBalance(contractId, assetId) {
|
4490
4717
|
const { contractBalance } = await this.operations.getContractBalance({
|
4491
4718
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4492
|
-
asset: (0,
|
4719
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4493
4720
|
});
|
4494
|
-
return (0,
|
4721
|
+
return (0, import_math16.bn)(contractBalance.amount, 10);
|
4495
4722
|
}
|
4496
4723
|
/**
|
4497
4724
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4503,9 +4730,9 @@ var _Provider = class {
|
|
4503
4730
|
async getBalance(owner, assetId) {
|
4504
4731
|
const { balance } = await this.operations.getBalance({
|
4505
4732
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4506
|
-
assetId: (0,
|
4733
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4507
4734
|
});
|
4508
|
-
return (0,
|
4735
|
+
return (0, import_math16.bn)(balance.amount, 10);
|
4509
4736
|
}
|
4510
4737
|
/**
|
4511
4738
|
* Returns balances for the given owner.
|
@@ -4523,7 +4750,7 @@ var _Provider = class {
|
|
4523
4750
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4524
4751
|
return balances.map((balance) => ({
|
4525
4752
|
assetId: balance.assetId,
|
4526
|
-
amount: (0,
|
4753
|
+
amount: (0, import_math16.bn)(balance.amount)
|
4527
4754
|
}));
|
4528
4755
|
}
|
4529
4756
|
/**
|
@@ -4541,19 +4768,19 @@ var _Provider = class {
|
|
4541
4768
|
});
|
4542
4769
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4543
4770
|
return messages.map((message) => ({
|
4544
|
-
messageId:
|
4771
|
+
messageId: import_transactions19.InputMessageCoder.getMessageId({
|
4545
4772
|
sender: message.sender,
|
4546
4773
|
recipient: message.recipient,
|
4547
4774
|
nonce: message.nonce,
|
4548
|
-
amount: (0,
|
4775
|
+
amount: (0, import_math16.bn)(message.amount),
|
4549
4776
|
data: message.data
|
4550
4777
|
}),
|
4551
4778
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4552
4779
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4553
4780
|
nonce: message.nonce,
|
4554
|
-
amount: (0,
|
4555
|
-
data:
|
4556
|
-
daHeight: (0,
|
4781
|
+
amount: (0, import_math16.bn)(message.amount),
|
4782
|
+
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4783
|
+
daHeight: (0, import_math16.bn)(message.daHeight)
|
4557
4784
|
}));
|
4558
4785
|
}
|
4559
4786
|
/**
|
@@ -4606,44 +4833,60 @@ var _Provider = class {
|
|
4606
4833
|
} = result.messageProof;
|
4607
4834
|
return {
|
4608
4835
|
messageProof: {
|
4609
|
-
proofIndex: (0,
|
4836
|
+
proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
|
4610
4837
|
proofSet: messageProof.proofSet
|
4611
4838
|
},
|
4612
4839
|
blockProof: {
|
4613
|
-
proofIndex: (0,
|
4840
|
+
proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
|
4614
4841
|
proofSet: blockProof.proofSet
|
4615
4842
|
},
|
4616
4843
|
messageBlockHeader: {
|
4617
4844
|
id: messageBlockHeader.id,
|
4618
|
-
daHeight: (0,
|
4619
|
-
transactionsCount: (0,
|
4845
|
+
daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
|
4846
|
+
transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
|
4620
4847
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4621
|
-
height: (0,
|
4848
|
+
height: (0, import_math16.bn)(messageBlockHeader.height),
|
4622
4849
|
prevRoot: messageBlockHeader.prevRoot,
|
4623
4850
|
time: messageBlockHeader.time,
|
4624
4851
|
applicationHash: messageBlockHeader.applicationHash,
|
4625
|
-
|
4626
|
-
|
4852
|
+
messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
|
4853
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4854
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4855
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4856
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4627
4857
|
},
|
4628
4858
|
commitBlockHeader: {
|
4629
4859
|
id: commitBlockHeader.id,
|
4630
|
-
daHeight: (0,
|
4631
|
-
transactionsCount: (0,
|
4860
|
+
daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
|
4861
|
+
transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
|
4632
4862
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4633
|
-
height: (0,
|
4863
|
+
height: (0, import_math16.bn)(commitBlockHeader.height),
|
4634
4864
|
prevRoot: commitBlockHeader.prevRoot,
|
4635
4865
|
time: commitBlockHeader.time,
|
4636
4866
|
applicationHash: commitBlockHeader.applicationHash,
|
4637
|
-
|
4638
|
-
|
4867
|
+
messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
|
4868
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4869
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4870
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4871
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4639
4872
|
},
|
4640
4873
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4641
4874
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4642
4875
|
nonce,
|
4643
|
-
amount: (0,
|
4876
|
+
amount: (0, import_math16.bn)(amount),
|
4644
4877
|
data
|
4645
4878
|
};
|
4646
4879
|
}
|
4880
|
+
async getLatestGasPrice() {
|
4881
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4882
|
+
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4883
|
+
}
|
4884
|
+
async estimateGasPrice(blockHorizon) {
|
4885
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4886
|
+
blockHorizon: String(blockHorizon)
|
4887
|
+
});
|
4888
|
+
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4889
|
+
}
|
4647
4890
|
/**
|
4648
4891
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4649
4892
|
*
|
@@ -4663,10 +4906,10 @@ var _Provider = class {
|
|
4663
4906
|
*/
|
4664
4907
|
async produceBlocks(amount, startTime) {
|
4665
4908
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4666
|
-
blocksToProduce: (0,
|
4667
|
-
startTimestamp: startTime ?
|
4909
|
+
blocksToProduce: (0, import_math16.bn)(amount).toString(10),
|
4910
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4668
4911
|
});
|
4669
|
-
return (0,
|
4912
|
+
return (0, import_math16.bn)(latestBlockHeight);
|
4670
4913
|
}
|
4671
4914
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4672
4915
|
async getTransactionResponse(transactionId) {
|
@@ -4680,7 +4923,7 @@ cacheInputs_fn = function(inputs) {
|
|
4680
4923
|
return;
|
4681
4924
|
}
|
4682
4925
|
inputs.forEach((input) => {
|
4683
|
-
if (input.type ===
|
4926
|
+
if (input.type === import_transactions19.InputType.Coin) {
|
4684
4927
|
this.cache?.set(input.id);
|
4685
4928
|
}
|
4686
4929
|
});
|
@@ -4690,9 +4933,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4690
4933
|
|
4691
4934
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4692
4935
|
var import_errors15 = require("@fuel-ts/errors");
|
4693
|
-
var
|
4694
|
-
var
|
4695
|
-
var
|
4936
|
+
var import_math17 = require("@fuel-ts/math");
|
4937
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
4938
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4696
4939
|
async function getTransactionSummary(params) {
|
4697
4940
|
const { id, provider, abiMap } = params;
|
4698
4941
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -4704,25 +4947,32 @@ async function getTransactionSummary(params) {
|
|
4704
4947
|
`Transaction not found for given id: ${id}.`
|
4705
4948
|
);
|
4706
4949
|
}
|
4707
|
-
const [decodedTransaction] = new
|
4708
|
-
(0,
|
4950
|
+
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
|
4951
|
+
(0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4709
4952
|
0
|
4710
4953
|
);
|
4711
|
-
|
4954
|
+
let txReceipts = [];
|
4955
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4956
|
+
txReceipts = gqlTransaction.status.receipts;
|
4957
|
+
}
|
4958
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4712
4959
|
const {
|
4713
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4960
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4714
4961
|
} = provider.getChain();
|
4962
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4715
4963
|
const transactionInfo = assembleTransactionSummary({
|
4716
4964
|
id: gqlTransaction.id,
|
4717
4965
|
receipts,
|
4718
4966
|
transaction: decodedTransaction,
|
4719
|
-
transactionBytes: (0,
|
4967
|
+
transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4720
4968
|
gqlTransactionStatus: gqlTransaction.status,
|
4721
|
-
gasPerByte: (0,
|
4722
|
-
gasPriceFactor: (0,
|
4969
|
+
gasPerByte: (0, import_math17.bn)(gasPerByte),
|
4970
|
+
gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
|
4723
4971
|
abiMap,
|
4724
4972
|
maxInputs,
|
4725
|
-
gasCosts
|
4973
|
+
gasCosts,
|
4974
|
+
maxGasPerTx,
|
4975
|
+
gasPrice
|
4726
4976
|
});
|
4727
4977
|
return {
|
4728
4978
|
gqlTransaction,
|
@@ -4732,10 +4982,11 @@ async function getTransactionSummary(params) {
|
|
4732
4982
|
async function getTransactionSummaryFromRequest(params) {
|
4733
4983
|
const { provider, transactionRequest, abiMap } = params;
|
4734
4984
|
const { receipts } = await provider.call(transactionRequest);
|
4735
|
-
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4985
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
|
4736
4986
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4737
4987
|
const transaction = transactionRequest.toTransaction();
|
4738
4988
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4989
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4739
4990
|
const transactionSummary = assembleTransactionSummary({
|
4740
4991
|
receipts,
|
4741
4992
|
transaction,
|
@@ -4744,7 +4995,9 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4744
4995
|
gasPerByte,
|
4745
4996
|
gasPriceFactor,
|
4746
4997
|
maxInputs,
|
4747
|
-
gasCosts
|
4998
|
+
gasCosts,
|
4999
|
+
maxGasPerTx,
|
5000
|
+
gasPrice
|
4748
5001
|
});
|
4749
5002
|
return transactionSummary;
|
4750
5003
|
}
|
@@ -4753,24 +5006,31 @@ async function getTransactionsSummaries(params) {
|
|
4753
5006
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4754
5007
|
const { edges, pageInfo } = transactionsByOwner;
|
4755
5008
|
const {
|
4756
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
5009
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4757
5010
|
} = provider.getChain();
|
5011
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4758
5012
|
const transactions = edges.map((edge) => {
|
4759
5013
|
const { node: gqlTransaction } = edge;
|
4760
|
-
const { id, rawPayload,
|
4761
|
-
const [decodedTransaction] = new
|
4762
|
-
|
5014
|
+
const { id, rawPayload, status } = gqlTransaction;
|
5015
|
+
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
|
5016
|
+
let txReceipts = [];
|
5017
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
5018
|
+
txReceipts = gqlTransaction.status.receipts;
|
5019
|
+
}
|
5020
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4763
5021
|
const transactionSummary = assembleTransactionSummary({
|
4764
5022
|
id,
|
4765
5023
|
receipts,
|
4766
5024
|
transaction: decodedTransaction,
|
4767
|
-
transactionBytes: (0,
|
5025
|
+
transactionBytes: (0, import_utils25.arrayify)(rawPayload),
|
4768
5026
|
gqlTransactionStatus: status,
|
4769
5027
|
abiMap,
|
4770
5028
|
gasPerByte,
|
4771
5029
|
gasPriceFactor,
|
4772
5030
|
maxInputs,
|
4773
|
-
gasCosts
|
5031
|
+
gasCosts,
|
5032
|
+
maxGasPerTx,
|
5033
|
+
gasPrice
|
4774
5034
|
});
|
4775
5035
|
const output = {
|
4776
5036
|
gqlTransaction,
|
@@ -4907,17 +5167,17 @@ var assets = [
|
|
4907
5167
|
|
4908
5168
|
// src/utils/formatTransferToContractScriptData.ts
|
4909
5169
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4910
|
-
var
|
4911
|
-
var
|
5170
|
+
var import_math18 = require("@fuel-ts/math");
|
5171
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4912
5172
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4913
5173
|
var formatTransferToContractScriptData = (params) => {
|
4914
5174
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4915
5175
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4916
|
-
const encoded = numberCoder.encode(new
|
5176
|
+
const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
|
4917
5177
|
const scriptData = Uint8Array.from([
|
4918
|
-
...(0,
|
5178
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4919
5179
|
...encoded,
|
4920
|
-
...(0,
|
5180
|
+
...(0, import_utils26.arrayify)(assetId)
|
4921
5181
|
]);
|
4922
5182
|
return scriptData;
|
4923
5183
|
};
|
@@ -5064,9 +5324,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5064
5324
|
* @param assetId - The asset ID to check the balance for.
|
5065
5325
|
* @returns A promise that resolves to the balance amount.
|
5066
5326
|
*/
|
5067
|
-
async getBalance(assetId) {
|
5068
|
-
const
|
5069
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5327
|
+
async getBalance(assetId = import_configs12.BaseAssetId) {
|
5328
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
5070
5329
|
return amount;
|
5071
5330
|
}
|
5072
5331
|
/**
|
@@ -5103,37 +5362,33 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5103
5362
|
* @param fee - The estimated transaction fee.
|
5104
5363
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5105
5364
|
*/
|
5106
|
-
async fund(request,
|
5107
|
-
const
|
5108
|
-
const
|
5109
|
-
|
5110
|
-
|
5111
|
-
|
5365
|
+
async fund(request, params) {
|
5366
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5367
|
+
const txRequest = request;
|
5368
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5369
|
+
amount: (0, import_math19.bn)(fee),
|
5370
|
+
assetId: import_configs12.BaseAssetId,
|
5371
|
+
coinQuantities: requiredQuantities
|
5112
5372
|
});
|
5113
5373
|
const quantitiesDict = {};
|
5114
|
-
|
5374
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
5115
5375
|
quantitiesDict[assetId] = {
|
5116
5376
|
required: amount,
|
5117
|
-
owned: (0,
|
5377
|
+
owned: (0, import_math19.bn)(0)
|
5118
5378
|
};
|
5119
5379
|
});
|
5120
|
-
|
5121
|
-
const cachedMessages = [];
|
5122
|
-
const owner = this.address.toB256();
|
5123
|
-
request.inputs.forEach((input) => {
|
5380
|
+
txRequest.inputs.forEach((input) => {
|
5124
5381
|
const isResource = "amount" in input;
|
5125
5382
|
if (isResource) {
|
5126
5383
|
const isCoin2 = "owner" in input;
|
5127
5384
|
if (isCoin2) {
|
5128
5385
|
const assetId = String(input.assetId);
|
5129
|
-
if (
|
5130
|
-
const amount = (0,
|
5386
|
+
if (quantitiesDict[assetId]) {
|
5387
|
+
const amount = (0, import_math19.bn)(input.amount);
|
5131
5388
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5132
|
-
cachedUtxos.push(input.id);
|
5133
5389
|
}
|
5134
|
-
} else if (input.
|
5135
|
-
quantitiesDict[
|
5136
|
-
cachedMessages.push(input.nonce);
|
5390
|
+
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5391
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
5137
5392
|
}
|
5138
5393
|
}
|
5139
5394
|
});
|
@@ -5148,12 +5403,23 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5148
5403
|
});
|
5149
5404
|
const needsToBeFunded = missingQuantities.length;
|
5150
5405
|
if (needsToBeFunded) {
|
5151
|
-
const
|
5152
|
-
|
5153
|
-
|
5154
|
-
|
5155
|
-
|
5406
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
5407
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
5408
|
+
txRequest.addResources(resources);
|
5409
|
+
}
|
5410
|
+
txRequest.shiftPredicateData();
|
5411
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5412
|
+
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
5413
|
+
if (addedSignatures) {
|
5414
|
+
Array.from({ length: addedSignatures }).forEach(
|
5415
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
5416
|
+
);
|
5156
5417
|
}
|
5418
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5419
|
+
transactionRequest: requestToBeReEstimate
|
5420
|
+
});
|
5421
|
+
txRequest.maxFee = maxFee;
|
5422
|
+
return txRequest;
|
5157
5423
|
}
|
5158
5424
|
/**
|
5159
5425
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5161,30 +5427,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5161
5427
|
* @param destination - The address of the destination.
|
5162
5428
|
* @param amount - The amount of coins to transfer.
|
5163
5429
|
* @param assetId - The asset ID of the coins to transfer.
|
5164
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5430
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
5165
5431
|
* @returns A promise that resolves to the prepared transaction request.
|
5166
5432
|
*/
|
5167
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5168
|
-
const
|
5169
|
-
|
5170
|
-
const
|
5171
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5172
|
-
const request = new ScriptTransactionRequest(params);
|
5173
|
-
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5174
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5433
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5434
|
+
const request = new ScriptTransactionRequest(txParams);
|
5435
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
5436
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5175
5437
|
estimateTxDependencies: true,
|
5176
5438
|
resourcesOwner: this
|
5177
5439
|
});
|
5178
|
-
|
5179
|
-
|
5180
|
-
|
5181
|
-
|
5182
|
-
|
5183
|
-
|
5184
|
-
|
5185
|
-
|
5186
|
-
await this.fund(request,
|
5187
|
-
request.updatePredicateInputs(estimatedInputs);
|
5440
|
+
if ("gasLimit" in txParams) {
|
5441
|
+
this.validateGas({
|
5442
|
+
gasUsed: txCost.gasUsed,
|
5443
|
+
gasLimit: request.gasLimit
|
5444
|
+
});
|
5445
|
+
}
|
5446
|
+
request.gasLimit = txCost.gasUsed;
|
5447
|
+
request.maxFee = txCost.maxFee;
|
5448
|
+
await this.fund(request, txCost);
|
5188
5449
|
return request;
|
5189
5450
|
}
|
5190
5451
|
/**
|
@@ -5196,15 +5457,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5196
5457
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5197
5458
|
* @returns A promise that resolves to the transaction response.
|
5198
5459
|
*/
|
5199
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
5200
|
-
if ((0,
|
5460
|
+
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5461
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
5201
5462
|
throw new import_errors16.FuelError(
|
5202
5463
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5203
5464
|
"Transfer amount must be a positive number."
|
5204
5465
|
);
|
5205
5466
|
}
|
5206
|
-
const
|
5207
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5467
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
5208
5468
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5209
5469
|
}
|
5210
5470
|
/**
|
@@ -5216,41 +5476,38 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5216
5476
|
* @param txParams - The optional transaction parameters.
|
5217
5477
|
* @returns A promise that resolves to the transaction response.
|
5218
5478
|
*/
|
5219
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5220
|
-
if ((0,
|
5479
|
+
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5480
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
5221
5481
|
throw new import_errors16.FuelError(
|
5222
5482
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5223
5483
|
"Transfer amount must be a positive number."
|
5224
5484
|
);
|
5225
5485
|
}
|
5226
5486
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5227
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5228
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5229
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5230
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5231
5487
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5232
5488
|
hexlifiedContractId: contractAddress.toB256(),
|
5233
|
-
amountToTransfer: (0,
|
5234
|
-
assetId
|
5489
|
+
amountToTransfer: (0, import_math19.bn)(amount),
|
5490
|
+
assetId
|
5235
5491
|
});
|
5236
5492
|
const request = new ScriptTransactionRequest({
|
5237
|
-
...
|
5493
|
+
...txParams,
|
5238
5494
|
script,
|
5239
5495
|
scriptData
|
5240
5496
|
});
|
5241
5497
|
request.addContractInputAndOutput(contractAddress);
|
5242
|
-
const
|
5243
|
-
|
5244
|
-
[{ amount: (0,
|
5245
|
-
);
|
5246
|
-
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5247
|
-
this.validateGas({
|
5248
|
-
gasUsed,
|
5249
|
-
gasPrice: request.gasPrice,
|
5250
|
-
gasLimit: request.gasLimit,
|
5251
|
-
minGasPrice
|
5498
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5499
|
+
resourcesOwner: this,
|
5500
|
+
quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
|
5252
5501
|
});
|
5253
|
-
|
5502
|
+
if (txParams.gasLimit) {
|
5503
|
+
this.validateGas({
|
5504
|
+
gasUsed: txCost.gasUsed,
|
5505
|
+
gasLimit: request.gasLimit
|
5506
|
+
});
|
5507
|
+
}
|
5508
|
+
request.gasLimit = txCost.gasUsed;
|
5509
|
+
request.maxFee = txCost.maxFee;
|
5510
|
+
await this.fund(request, txCost);
|
5254
5511
|
return this.sendTransaction(request);
|
5255
5512
|
}
|
5256
5513
|
/**
|
@@ -5262,40 +5519,31 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5262
5519
|
* @returns A promise that resolves to the transaction response.
|
5263
5520
|
*/
|
5264
5521
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5265
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5266
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5267
5522
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5268
|
-
const recipientDataArray = (0,
|
5523
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
5269
5524
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5270
5525
|
);
|
5271
|
-
const amountDataArray = (0,
|
5272
|
-
"0x".concat((0,
|
5526
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5527
|
+
"0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5273
5528
|
);
|
5274
5529
|
const script = new Uint8Array([
|
5275
|
-
...(0,
|
5530
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
5276
5531
|
...recipientDataArray,
|
5277
5532
|
...amountDataArray
|
5278
5533
|
]);
|
5279
|
-
const params = {
|
5280
|
-
script,
|
5281
|
-
gasPrice: minGasPrice,
|
5282
|
-
baseAssetId,
|
5283
|
-
...txParams
|
5284
|
-
};
|
5534
|
+
const params = { script, ...txParams };
|
5285
5535
|
const request = new ScriptTransactionRequest(params);
|
5286
|
-
const
|
5287
|
-
const
|
5288
|
-
|
5289
|
-
|
5290
|
-
|
5291
|
-
|
5292
|
-
|
5293
|
-
|
5294
|
-
|
5295
|
-
|
5296
|
-
|
5297
|
-
});
|
5298
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5536
|
+
const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5537
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5538
|
+
if (txParams.gasLimit) {
|
5539
|
+
this.validateGas({
|
5540
|
+
gasUsed: txCost.gasUsed,
|
5541
|
+
gasLimit: request.gasLimit
|
5542
|
+
});
|
5543
|
+
}
|
5544
|
+
request.maxFee = txCost.maxFee;
|
5545
|
+
request.gasLimit = txCost.gasUsed;
|
5546
|
+
await this.fund(request, txCost);
|
5299
5547
|
return this.sendTransaction(request);
|
5300
5548
|
}
|
5301
5549
|
async signMessage(message) {
|
@@ -5353,18 +5601,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5353
5601
|
}
|
5354
5602
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5355
5603
|
}
|
5356
|
-
validateGas({
|
5357
|
-
gasUsed,
|
5358
|
-
gasPrice,
|
5359
|
-
gasLimit,
|
5360
|
-
minGasPrice
|
5361
|
-
}) {
|
5362
|
-
if (minGasPrice.gt(gasPrice)) {
|
5363
|
-
throw new import_errors16.FuelError(
|
5364
|
-
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
5365
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5366
|
-
);
|
5367
|
-
}
|
5604
|
+
validateGas({ gasUsed, gasLimit }) {
|
5368
5605
|
if (gasUsed.gt(gasLimit)) {
|
5369
5606
|
throw new import_errors16.FuelError(
|
5370
5607
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5376,14 +5613,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5376
5613
|
|
5377
5614
|
// src/wallet/base-wallet-unlocked.ts
|
5378
5615
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5379
|
-
var
|
5616
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5380
5617
|
|
5381
5618
|
// src/signer/signer.ts
|
5382
5619
|
var import_address5 = require("@fuel-ts/address");
|
5383
5620
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5384
5621
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5385
|
-
var
|
5386
|
-
var
|
5622
|
+
var import_math20 = require("@fuel-ts/math");
|
5623
|
+
var import_utils28 = require("@fuel-ts/utils");
|
5387
5624
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5388
5625
|
var Signer = class {
|
5389
5626
|
address;
|
@@ -5402,10 +5639,10 @@ var Signer = class {
|
|
5402
5639
|
privateKey = `0x${privateKey}`;
|
5403
5640
|
}
|
5404
5641
|
}
|
5405
|
-
const privateKeyBytes = (0,
|
5406
|
-
this.privateKey = (0,
|
5407
|
-
this.publicKey = (0,
|
5408
|
-
this.compressedPublicKey = (0,
|
5642
|
+
const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
|
5643
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5644
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5645
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5409
5646
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5410
5647
|
}
|
5411
5648
|
/**
|
@@ -5419,11 +5656,11 @@ var Signer = class {
|
|
5419
5656
|
* @returns hashed signature
|
5420
5657
|
*/
|
5421
5658
|
sign(data) {
|
5422
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5423
|
-
const r = (0,
|
5424
|
-
const s = (0,
|
5659
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5660
|
+
const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5661
|
+
const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5425
5662
|
s[0] |= (signature.recovery || 0) << 7;
|
5426
|
-
return (0,
|
5663
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
5427
5664
|
}
|
5428
5665
|
/**
|
5429
5666
|
* Add point on the current elliptic curve
|
@@ -5432,8 +5669,8 @@ var Signer = class {
|
|
5432
5669
|
* @returns compressed point on the curve
|
5433
5670
|
*/
|
5434
5671
|
addPoint(point) {
|
5435
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5436
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5672
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5673
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
5437
5674
|
const result = p0.add(p1);
|
5438
5675
|
return `0x${result.toHex(true)}`;
|
5439
5676
|
}
|
@@ -5445,16 +5682,16 @@ var Signer = class {
|
|
5445
5682
|
* @returns public key from signature from the
|
5446
5683
|
*/
|
5447
5684
|
static recoverPublicKey(data, signature) {
|
5448
|
-
const signedMessageBytes = (0,
|
5685
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5449
5686
|
const r = signedMessageBytes.slice(0, 32);
|
5450
5687
|
const s = signedMessageBytes.slice(32, 64);
|
5451
5688
|
const recoveryParam = (s[0] & 128) >> 7;
|
5452
5689
|
s[0] &= 127;
|
5453
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5690
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5454
5691
|
recoveryParam
|
5455
5692
|
);
|
5456
|
-
const publicKey = sig.recoverPublicKey((0,
|
5457
|
-
return (0,
|
5693
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5694
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5458
5695
|
}
|
5459
5696
|
/**
|
5460
5697
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5473,7 +5710,7 @@ var Signer = class {
|
|
5473
5710
|
* @returns random 32-byte hashed
|
5474
5711
|
*/
|
5475
5712
|
static generatePrivateKey(entropy) {
|
5476
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5713
|
+
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);
|
5477
5714
|
}
|
5478
5715
|
/**
|
5479
5716
|
* Extended publicKey from a compact publicKey
|
@@ -5482,8 +5719,8 @@ var Signer = class {
|
|
5482
5719
|
* @returns extended publicKey
|
5483
5720
|
*/
|
5484
5721
|
static extendPublicKey(publicKey) {
|
5485
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5486
|
-
return (0,
|
5722
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5723
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5487
5724
|
}
|
5488
5725
|
};
|
5489
5726
|
|
@@ -5491,7 +5728,7 @@ var Signer = class {
|
|
5491
5728
|
var import_address6 = require("@fuel-ts/address");
|
5492
5729
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5493
5730
|
var import_errors17 = require("@fuel-ts/errors");
|
5494
|
-
var
|
5731
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5495
5732
|
var import_uuid = require("uuid");
|
5496
5733
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5497
5734
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5574,7 +5811,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5574
5811
|
);
|
5575
5812
|
}
|
5576
5813
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5577
|
-
const privateKey = (0,
|
5814
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5578
5815
|
return privateKey;
|
5579
5816
|
}
|
5580
5817
|
|
@@ -5619,7 +5856,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5619
5856
|
*/
|
5620
5857
|
async signMessage(message) {
|
5621
5858
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5622
|
-
return (0,
|
5859
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5623
5860
|
}
|
5624
5861
|
/**
|
5625
5862
|
* Signs a transaction with the wallet's private key.
|
@@ -5632,7 +5869,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5632
5869
|
const chainId = this.provider.getChainId();
|
5633
5870
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5634
5871
|
const signature = await this.signer().sign(hashedTransaction);
|
5635
|
-
return (0,
|
5872
|
+
return (0, import_utils30.hexlify)(signature);
|
5636
5873
|
}
|
5637
5874
|
/**
|
5638
5875
|
* Populates a transaction with the witnesses signature.
|
@@ -5652,7 +5889,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5652
5889
|
* @param transactionRequestLike - The transaction request to send.
|
5653
5890
|
* @returns A promise that resolves to the TransactionResponse object.
|
5654
5891
|
*/
|
5655
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5892
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5656
5893
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5657
5894
|
if (estimateTxDependencies) {
|
5658
5895
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5693,15 +5930,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5693
5930
|
// src/hdwallet/hdwallet.ts
|
5694
5931
|
var import_errors20 = require("@fuel-ts/errors");
|
5695
5932
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5696
|
-
var
|
5697
|
-
var
|
5933
|
+
var import_math21 = require("@fuel-ts/math");
|
5934
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5698
5935
|
var import_ethers3 = require("ethers");
|
5699
5936
|
|
5700
5937
|
// src/mnemonic/mnemonic.ts
|
5701
5938
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5702
5939
|
var import_errors19 = require("@fuel-ts/errors");
|
5703
5940
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5704
|
-
var
|
5941
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5705
5942
|
var import_ethers2 = require("ethers");
|
5706
5943
|
|
5707
5944
|
// src/wordlists/words/english.ts
|
@@ -7765,7 +8002,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7765
8002
|
// src/mnemonic/utils.ts
|
7766
8003
|
var import_errors18 = require("@fuel-ts/errors");
|
7767
8004
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7768
|
-
var
|
8005
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7769
8006
|
function toUtf8Bytes(stri) {
|
7770
8007
|
const str = stri.normalize("NFKD");
|
7771
8008
|
const result = [];
|
@@ -7832,14 +8069,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7832
8069
|
}
|
7833
8070
|
}
|
7834
8071
|
const checksumBits = entropy.length / 4;
|
7835
|
-
const checksum = (0,
|
8072
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7836
8073
|
indices[indices.length - 1] <<= checksumBits;
|
7837
8074
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7838
8075
|
return indices;
|
7839
8076
|
}
|
7840
8077
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7841
8078
|
const size = Math.ceil(11 * words.length / 8);
|
7842
|
-
const entropy = (0,
|
8079
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7843
8080
|
let offset = 0;
|
7844
8081
|
for (let i = 0; i < words.length; i += 1) {
|
7845
8082
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7859,7 +8096,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7859
8096
|
const entropyBits = 32 * words.length / 3;
|
7860
8097
|
const checksumBits = words.length / 3;
|
7861
8098
|
const checksumMask = getUpperMask(checksumBits);
|
7862
|
-
const checksum = (0,
|
8099
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7863
8100
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7864
8101
|
throw new import_errors18.FuelError(
|
7865
8102
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7934,7 +8171,7 @@ var Mnemonic = class {
|
|
7934
8171
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7935
8172
|
const words = getWords(phrase);
|
7936
8173
|
assertMnemonic(words);
|
7937
|
-
return (0,
|
8174
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7938
8175
|
}
|
7939
8176
|
/**
|
7940
8177
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7942,7 +8179,7 @@ var Mnemonic = class {
|
|
7942
8179
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7943
8180
|
*/
|
7944
8181
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7945
|
-
const entropyBytes = (0,
|
8182
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7946
8183
|
assertWordList(wordlist);
|
7947
8184
|
assertEntropy(entropyBytes);
|
7948
8185
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -8011,14 +8248,14 @@ var Mnemonic = class {
|
|
8011
8248
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8012
8249
|
*/
|
8013
8250
|
static masterKeysFromSeed(seed) {
|
8014
|
-
const seedArray = (0,
|
8251
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
8015
8252
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8016
8253
|
throw new import_errors19.FuelError(
|
8017
8254
|
import_errors19.ErrorCode.INVALID_SEED,
|
8018
8255
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8019
8256
|
);
|
8020
8257
|
}
|
8021
|
-
return (0,
|
8258
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
8022
8259
|
}
|
8023
8260
|
/**
|
8024
8261
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8029,22 +8266,22 @@ var Mnemonic = class {
|
|
8029
8266
|
*/
|
8030
8267
|
static seedToExtendedKey(seed, testnet = false) {
|
8031
8268
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8032
|
-
const prefix = (0,
|
8269
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8033
8270
|
const depth = "0x00";
|
8034
8271
|
const fingerprint = "0x00000000";
|
8035
8272
|
const index = "0x00000000";
|
8036
8273
|
const chainCode = masterKey.slice(32);
|
8037
8274
|
const privateKey = masterKey.slice(0, 32);
|
8038
|
-
const extendedKey = (0,
|
8275
|
+
const extendedKey = (0, import_utils32.concat)([
|
8039
8276
|
prefix,
|
8040
8277
|
depth,
|
8041
8278
|
fingerprint,
|
8042
8279
|
index,
|
8043
8280
|
chainCode,
|
8044
|
-
(0,
|
8281
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
8045
8282
|
]);
|
8046
8283
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8047
|
-
return (0, import_ethers2.encodeBase58)((0,
|
8284
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
8048
8285
|
}
|
8049
8286
|
/**
|
8050
8287
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8059,7 +8296,7 @@ var Mnemonic = class {
|
|
8059
8296
|
* @returns A randomly generated mnemonic
|
8060
8297
|
*/
|
8061
8298
|
static generate(size = 32, extraEntropy = "") {
|
8062
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8299
|
+
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);
|
8063
8300
|
return Mnemonic.entropyToMnemonic(entropy);
|
8064
8301
|
}
|
8065
8302
|
};
|
@@ -8067,12 +8304,12 @@ var mnemonic_default = Mnemonic;
|
|
8067
8304
|
|
8068
8305
|
// src/hdwallet/hdwallet.ts
|
8069
8306
|
var HARDENED_INDEX = 2147483648;
|
8070
|
-
var MainnetPRV2 = (0,
|
8071
|
-
var MainnetPUB = (0,
|
8072
|
-
var TestnetPRV2 = (0,
|
8073
|
-
var TestnetPUB = (0,
|
8307
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
8308
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
8309
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
8310
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
8074
8311
|
function base58check(data) {
|
8075
|
-
return (0, import_ethers3.encodeBase58)((0,
|
8312
|
+
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)]));
|
8076
8313
|
}
|
8077
8314
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8078
8315
|
if (isPublic) {
|
@@ -8081,11 +8318,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8081
8318
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8082
8319
|
}
|
8083
8320
|
function isPublicExtendedKey(extendedKey) {
|
8084
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8321
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
8085
8322
|
}
|
8086
8323
|
function isValidExtendedKey(extendedKey) {
|
8087
8324
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8088
|
-
(0,
|
8325
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
8089
8326
|
);
|
8090
8327
|
}
|
8091
8328
|
function parsePath(path, depth = 0) {
|
@@ -8103,8 +8340,8 @@ function parsePath(path, depth = 0) {
|
|
8103
8340
|
var HDWallet = class {
|
8104
8341
|
depth = 0;
|
8105
8342
|
index = 0;
|
8106
|
-
fingerprint = (0,
|
8107
|
-
parentFingerprint = (0,
|
8343
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8344
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8108
8345
|
privateKey;
|
8109
8346
|
publicKey;
|
8110
8347
|
chainCode;
|
@@ -8116,8 +8353,8 @@ var HDWallet = class {
|
|
8116
8353
|
constructor(config) {
|
8117
8354
|
if (config.privateKey) {
|
8118
8355
|
const signer = new Signer(config.privateKey);
|
8119
|
-
this.publicKey = (0,
|
8120
|
-
this.privateKey = (0,
|
8356
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
8357
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
8121
8358
|
} else {
|
8122
8359
|
if (!config.publicKey) {
|
8123
8360
|
throw new import_errors20.FuelError(
|
@@ -8125,7 +8362,7 @@ var HDWallet = class {
|
|
8125
8362
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8126
8363
|
);
|
8127
8364
|
}
|
8128
|
-
this.publicKey = (0,
|
8365
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
8129
8366
|
}
|
8130
8367
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8131
8368
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -8144,9 +8381,9 @@ var HDWallet = class {
|
|
8144
8381
|
* @returns A new instance of HDWallet on the derived index
|
8145
8382
|
*/
|
8146
8383
|
deriveIndex(index) {
|
8147
|
-
const privateKey = this.privateKey && (0,
|
8148
|
-
const publicKey = (0,
|
8149
|
-
const chainCode = (0,
|
8384
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
8385
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
8386
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
8150
8387
|
const data = new Uint8Array(37);
|
8151
8388
|
if (index & HARDENED_INDEX) {
|
8152
8389
|
if (!privateKey) {
|
@@ -8157,15 +8394,15 @@ var HDWallet = class {
|
|
8157
8394
|
}
|
8158
8395
|
data.set(privateKey, 1);
|
8159
8396
|
} else {
|
8160
|
-
data.set((0,
|
8397
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
8161
8398
|
}
|
8162
|
-
data.set((0,
|
8163
|
-
const bytes = (0,
|
8399
|
+
data.set((0, import_math21.toBytes)(index, 4), 33);
|
8400
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
8164
8401
|
const IL = bytes.slice(0, 32);
|
8165
8402
|
const IR = bytes.slice(32);
|
8166
8403
|
if (privateKey) {
|
8167
8404
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8168
|
-
const ki = (0,
|
8405
|
+
const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8169
8406
|
return new HDWallet({
|
8170
8407
|
privateKey: ki,
|
8171
8408
|
chainCode: IR,
|
@@ -8174,7 +8411,7 @@ var HDWallet = class {
|
|
8174
8411
|
parentFingerprint: this.fingerprint
|
8175
8412
|
});
|
8176
8413
|
}
|
8177
|
-
const signer = new Signer((0,
|
8414
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
8178
8415
|
const Ki = signer.addPoint(publicKey);
|
8179
8416
|
return new HDWallet({
|
8180
8417
|
publicKey: Ki,
|
@@ -8209,12 +8446,12 @@ var HDWallet = class {
|
|
8209
8446
|
);
|
8210
8447
|
}
|
8211
8448
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8212
|
-
const depth = (0,
|
8449
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
8213
8450
|
const parentFingerprint = this.parentFingerprint;
|
8214
|
-
const index = (0,
|
8451
|
+
const index = (0, import_math21.toHex)(this.index, 4);
|
8215
8452
|
const chainCode = this.chainCode;
|
8216
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8217
|
-
const extendedKey = (0,
|
8453
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8454
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8218
8455
|
return base58check(extendedKey);
|
8219
8456
|
}
|
8220
8457
|
/**
|
@@ -8226,13 +8463,13 @@ var HDWallet = class {
|
|
8226
8463
|
static fromSeed(seed) {
|
8227
8464
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8228
8465
|
return new HDWallet({
|
8229
|
-
chainCode: (0,
|
8230
|
-
privateKey: (0,
|
8466
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
8467
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
8231
8468
|
});
|
8232
8469
|
}
|
8233
8470
|
static fromExtendedKey(extendedKey) {
|
8234
8471
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8235
|
-
const bytes = (0,
|
8472
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
8236
8473
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8237
8474
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8238
8475
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8241,9 +8478,9 @@ var HDWallet = class {
|
|
8241
8478
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8242
8479
|
}
|
8243
8480
|
const depth = bytes[4];
|
8244
|
-
const parentFingerprint = (0,
|
8245
|
-
const index = parseInt((0,
|
8246
|
-
const chainCode = (0,
|
8481
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8482
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8483
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
8247
8484
|
const key = bytes.slice(45, 78);
|
8248
8485
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8249
8486
|
throw new import_errors20.FuelError(
|
@@ -8846,20 +9083,21 @@ var StorageAbstract = class {
|
|
8846
9083
|
// src/predicate/predicate.ts
|
8847
9084
|
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
8848
9085
|
var import_address10 = require("@fuel-ts/address");
|
9086
|
+
var import_configs13 = require("@fuel-ts/address/configs");
|
8849
9087
|
var import_errors25 = require("@fuel-ts/errors");
|
8850
|
-
var
|
8851
|
-
var
|
9088
|
+
var import_transactions21 = require("@fuel-ts/transactions");
|
9089
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8852
9090
|
|
8853
9091
|
// src/predicate/utils/getPredicateRoot.ts
|
8854
9092
|
var import_hasher7 = require("@fuel-ts/hasher");
|
8855
9093
|
var import_merkle = require("@fuel-ts/merkle");
|
8856
|
-
var
|
9094
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8857
9095
|
var getPredicateRoot = (bytecode) => {
|
8858
9096
|
const chunkSize = 16 * 1024;
|
8859
|
-
const bytes = (0,
|
8860
|
-
const chunks = (0,
|
8861
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
8862
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
9097
|
+
const bytes = (0, import_utils35.arrayify)(bytecode);
|
9098
|
+
const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
|
9099
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
|
9100
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
|
8863
9101
|
return predicateRoot;
|
8864
9102
|
};
|
8865
9103
|
|
@@ -8907,9 +9145,9 @@ var Predicate = class extends Account {
|
|
8907
9145
|
const request = transactionRequestify(transactionRequestLike);
|
8908
9146
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8909
9147
|
request.inputs?.forEach((input) => {
|
8910
|
-
if (input.type ===
|
8911
|
-
input.predicate = this.bytes;
|
8912
|
-
input.predicateData = this.getPredicateData(policies.length);
|
9148
|
+
if (input.type === import_transactions21.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
|
9149
|
+
input.predicate = (0, import_utils36.hexlify)(this.bytes);
|
9150
|
+
input.predicateData = (0, import_utils36.hexlify)(this.getPredicateData(policies.length));
|
8913
9151
|
}
|
8914
9152
|
});
|
8915
9153
|
return request;
|
@@ -8923,10 +9161,8 @@ var Predicate = class extends Account {
|
|
8923
9161
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8924
9162
|
* @returns A promise that resolves to the prepared transaction request.
|
8925
9163
|
*/
|
8926
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8927
|
-
|
8928
|
-
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8929
|
-
return this.populateTransactionPredicateData(request);
|
9164
|
+
async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
|
9165
|
+
return super.createTransfer(destination, amount, assetId, txParams);
|
8930
9166
|
}
|
8931
9167
|
/**
|
8932
9168
|
* Sends a transaction with the populated predicate data.
|
@@ -8934,9 +9170,9 @@ var Predicate = class extends Account {
|
|
8934
9170
|
* @param transactionRequestLike - The transaction request-like object.
|
8935
9171
|
* @returns A promise that resolves to the transaction response.
|
8936
9172
|
*/
|
8937
|
-
sendTransaction(transactionRequestLike
|
8938
|
-
const transactionRequest =
|
8939
|
-
return super.sendTransaction(transactionRequest,
|
9173
|
+
sendTransaction(transactionRequestLike) {
|
9174
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9175
|
+
return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
|
8940
9176
|
}
|
8941
9177
|
/**
|
8942
9178
|
* Simulates a transaction with the populated predicate data.
|
@@ -8945,15 +9181,15 @@ var Predicate = class extends Account {
|
|
8945
9181
|
* @returns A promise that resolves to the call result.
|
8946
9182
|
*/
|
8947
9183
|
simulateTransaction(transactionRequestLike) {
|
8948
|
-
const transactionRequest =
|
8949
|
-
return super.simulateTransaction(transactionRequest);
|
9184
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9185
|
+
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
8950
9186
|
}
|
8951
9187
|
getPredicateData(policiesLength) {
|
8952
9188
|
if (!this.predicateData.length) {
|
8953
9189
|
return new Uint8Array();
|
8954
9190
|
}
|
8955
9191
|
const mainFn = this.interface?.functions.main;
|
8956
|
-
const paddedCode = new
|
9192
|
+
const paddedCode = new import_transactions21.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
8957
9193
|
const VM_TX_MEMORY = (0, import_abi_coder7.calculateVmTxMemory)({
|
8958
9194
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
8959
9195
|
});
|
@@ -8969,7 +9205,7 @@ var Predicate = class extends Account {
|
|
8969
9205
|
* @returns An object containing the new predicate bytes and interface.
|
8970
9206
|
*/
|
8971
9207
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
8972
|
-
let predicateBytes = (0,
|
9208
|
+
let predicateBytes = (0, import_utils36.arrayify)(bytes);
|
8973
9209
|
let abiInterface;
|
8974
9210
|
if (jsonAbi) {
|
8975
9211
|
abiInterface = new import_abi_coder7.Interface(jsonAbi);
|
@@ -8992,6 +9228,25 @@ var Predicate = class extends Account {
|
|
8992
9228
|
predicateInterface: abiInterface
|
8993
9229
|
};
|
8994
9230
|
}
|
9231
|
+
/**
|
9232
|
+
* Retrieves resources satisfying the spend query for the account.
|
9233
|
+
*
|
9234
|
+
* @param quantities - IDs of coins to exclude.
|
9235
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
9236
|
+
* @returns A promise that resolves to an array of Resources.
|
9237
|
+
*/
|
9238
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
9239
|
+
const resources = await this.provider.getResourcesToSpend(
|
9240
|
+
this.address,
|
9241
|
+
quantities,
|
9242
|
+
excludedIds
|
9243
|
+
);
|
9244
|
+
return resources.map((resource) => ({
|
9245
|
+
...resource,
|
9246
|
+
predicate: (0, import_utils36.hexlify)(this.bytes),
|
9247
|
+
paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
|
9248
|
+
}));
|
9249
|
+
}
|
8995
9250
|
/**
|
8996
9251
|
* Sets the configurable constants for the predicate.
|
8997
9252
|
*
|
@@ -9741,7 +9996,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9741
9996
|
WalletLocked,
|
9742
9997
|
WalletManager,
|
9743
9998
|
WalletUnlocked,
|
9744
|
-
|
9999
|
+
addAmountToCoinQuantities,
|
9745
10000
|
addOperation,
|
9746
10001
|
assemblePanicError,
|
9747
10002
|
assembleReceiptByType,
|
@@ -9750,9 +10005,10 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9750
10005
|
assets,
|
9751
10006
|
buildBlockExplorerUrl,
|
9752
10007
|
cacheFor,
|
10008
|
+
cacheTxInputsFromOwner,
|
10009
|
+
calculateGasFee,
|
9753
10010
|
calculateMetadataGasForTxCreate,
|
9754
10011
|
calculateMetadataGasForTxScript,
|
9755
|
-
calculatePriceWithFactor,
|
9756
10012
|
calculateTransactionFee,
|
9757
10013
|
coinQuantityfy,
|
9758
10014
|
deferPromise,
|