@fuel-ts/account 0.0.0-rc-2034-20240415163000 → 0.0.0-rc-2021-20240415193305
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 +795 -544
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +762 -507
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +642 -388
- 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 +906 -324
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +37 -27
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +8 -25
- 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.global.js +1545 -1056
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +740 -503
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +634 -397
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/index.js
CHANGED
@@ -95,7 +95,7 @@ __export(src_exports, {
|
|
95
95
|
WalletLocked: () => WalletLocked,
|
96
96
|
WalletManager: () => WalletManager,
|
97
97
|
WalletUnlocked: () => WalletUnlocked,
|
98
|
-
|
98
|
+
addAmountToCoinQuantities: () => addAmountToCoinQuantities,
|
99
99
|
addOperation: () => addOperation,
|
100
100
|
assemblePanicError: () => assemblePanicError,
|
101
101
|
assembleReceiptByType: () => assembleReceiptByType,
|
@@ -104,9 +104,10 @@ __export(src_exports, {
|
|
104
104
|
assets: () => assets,
|
105
105
|
buildBlockExplorerUrl: () => buildBlockExplorerUrl,
|
106
106
|
cacheFor: () => cacheFor,
|
107
|
+
cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
|
108
|
+
calculateGasFee: () => calculateGasFee,
|
107
109
|
calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
|
108
110
|
calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
|
109
|
-
calculatePriceWithFactor: () => calculatePriceWithFactor,
|
110
111
|
calculateTransactionFee: () => calculateTransactionFee,
|
111
112
|
coinQuantityfy: () => coinQuantityfy,
|
112
113
|
deferPromise: () => deferPromise,
|
@@ -187,8 +188,9 @@ var import_address4 = require("@fuel-ts/address");
|
|
187
188
|
var import_configs12 = require("@fuel-ts/address/configs");
|
188
189
|
var import_errors16 = require("@fuel-ts/errors");
|
189
190
|
var import_interfaces = require("@fuel-ts/interfaces");
|
190
|
-
var
|
191
|
-
var
|
191
|
+
var import_math19 = require("@fuel-ts/math");
|
192
|
+
var import_utils27 = require("@fuel-ts/utils");
|
193
|
+
var import_ramda4 = require("ramda");
|
192
194
|
|
193
195
|
// src/providers/coin-quantity.ts
|
194
196
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -214,7 +216,7 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
214
216
|
max: max2 ? (0, import_math.bn)(max2) : void 0
|
215
217
|
};
|
216
218
|
};
|
217
|
-
var
|
219
|
+
var addAmountToCoinQuantities = (params) => {
|
218
220
|
const { amount, assetId } = params;
|
219
221
|
const coinQuantities = [...params.coinQuantities];
|
220
222
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -229,11 +231,11 @@ var addAmountToAsset = (params) => {
|
|
229
231
|
// src/providers/provider.ts
|
230
232
|
var import_address3 = require("@fuel-ts/address");
|
231
233
|
var import_errors14 = require("@fuel-ts/errors");
|
232
|
-
var
|
233
|
-
var
|
234
|
-
var
|
234
|
+
var import_math16 = require("@fuel-ts/math");
|
235
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
236
|
+
var import_utils22 = require("@fuel-ts/utils");
|
235
237
|
var import_versions = require("@fuel-ts/versions");
|
236
|
-
var
|
238
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
237
239
|
var import_ethers = require("ethers");
|
238
240
|
var import_graphql_request = require("graphql-request");
|
239
241
|
var import_ramda3 = require("ramda");
|
@@ -242,14 +244,10 @@ var import_ramda3 = require("ramda");
|
|
242
244
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
243
245
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
244
246
|
fragment receiptFragment on Receipt {
|
245
|
-
|
246
|
-
id
|
247
|
-
}
|
247
|
+
id
|
248
248
|
pc
|
249
249
|
is
|
250
|
-
to
|
251
|
-
id
|
252
|
-
}
|
250
|
+
to
|
253
251
|
toAddress
|
254
252
|
amount
|
255
253
|
assetId
|
@@ -287,10 +285,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
287
285
|
id
|
288
286
|
}
|
289
287
|
time
|
288
|
+
receipts {
|
289
|
+
...receiptFragment
|
290
|
+
}
|
290
291
|
programState {
|
291
292
|
returnType
|
292
293
|
data
|
293
294
|
}
|
295
|
+
receipts {
|
296
|
+
...receiptFragment
|
297
|
+
}
|
294
298
|
}
|
295
299
|
... on FailureStatus {
|
296
300
|
block {
|
@@ -298,26 +302,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
298
302
|
}
|
299
303
|
time
|
300
304
|
reason
|
305
|
+
receipts {
|
306
|
+
...receiptFragment
|
307
|
+
}
|
301
308
|
}
|
302
309
|
... on SqueezedOutStatus {
|
303
310
|
reason
|
304
311
|
}
|
305
312
|
}
|
306
|
-
`;
|
313
|
+
${ReceiptFragmentFragmentDoc}`;
|
307
314
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
308
315
|
fragment transactionFragment on Transaction {
|
309
316
|
id
|
310
317
|
rawPayload
|
311
|
-
gasPrice
|
312
|
-
receipts {
|
313
|
-
...receiptFragment
|
314
|
-
}
|
315
318
|
status {
|
316
319
|
...transactionStatusFragment
|
317
320
|
}
|
318
321
|
}
|
319
|
-
${
|
320
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
322
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
321
323
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
322
324
|
fragment inputEstimatePredicatesFragment on Input {
|
323
325
|
... on InputCoin {
|
@@ -335,6 +337,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
335
337
|
}
|
336
338
|
}
|
337
339
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
340
|
+
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
341
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
342
|
+
reason
|
343
|
+
programState {
|
344
|
+
returnType
|
345
|
+
data
|
346
|
+
}
|
347
|
+
}
|
348
|
+
`;
|
349
|
+
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
350
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
351
|
+
programState {
|
352
|
+
returnType
|
353
|
+
data
|
354
|
+
}
|
355
|
+
}
|
356
|
+
`;
|
357
|
+
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
358
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
359
|
+
... on DryRunFailureStatus {
|
360
|
+
...dryRunFailureStatusFragment
|
361
|
+
}
|
362
|
+
... on DryRunSuccessStatus {
|
363
|
+
...dryRunSuccessStatusFragment
|
364
|
+
}
|
365
|
+
}
|
366
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
367
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
368
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
369
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
370
|
+
id
|
371
|
+
status {
|
372
|
+
...dryRunTransactionStatusFragment
|
373
|
+
}
|
374
|
+
receipts {
|
375
|
+
...receiptFragment
|
376
|
+
}
|
377
|
+
}
|
378
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
379
|
+
${ReceiptFragmentFragmentDoc}`;
|
338
380
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
339
381
|
fragment coinFragment on Coin {
|
340
382
|
__typename
|
@@ -342,7 +384,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
342
384
|
owner
|
343
385
|
amount
|
344
386
|
assetId
|
345
|
-
maturity
|
346
387
|
blockCreated
|
347
388
|
txCreatedIdx
|
348
389
|
}
|
@@ -381,26 +422,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
381
422
|
messageBlockHeader {
|
382
423
|
id
|
383
424
|
daHeight
|
425
|
+
consensusParametersVersion
|
426
|
+
stateTransitionBytecodeVersion
|
384
427
|
transactionsCount
|
428
|
+
messageReceiptCount
|
385
429
|
transactionsRoot
|
430
|
+
messageOutboxRoot
|
431
|
+
eventInboxRoot
|
386
432
|
height
|
387
433
|
prevRoot
|
388
434
|
time
|
389
435
|
applicationHash
|
390
|
-
messageReceiptRoot
|
391
|
-
messageReceiptCount
|
392
436
|
}
|
393
437
|
commitBlockHeader {
|
394
438
|
id
|
395
439
|
daHeight
|
440
|
+
consensusParametersVersion
|
441
|
+
stateTransitionBytecodeVersion
|
396
442
|
transactionsCount
|
443
|
+
messageReceiptCount
|
397
444
|
transactionsRoot
|
445
|
+
messageOutboxRoot
|
446
|
+
eventInboxRoot
|
398
447
|
height
|
399
448
|
prevRoot
|
400
449
|
time
|
401
450
|
applicationHash
|
402
|
-
messageReceiptRoot
|
403
|
-
messageReceiptCount
|
404
451
|
}
|
405
452
|
sender
|
406
453
|
recipient
|
@@ -419,8 +466,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
419
466
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
420
467
|
fragment blockFragment on Block {
|
421
468
|
id
|
469
|
+
height
|
422
470
|
header {
|
423
|
-
height
|
424
471
|
time
|
425
472
|
}
|
426
473
|
transactions {
|
@@ -478,6 +525,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
478
525
|
`;
|
479
526
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
480
527
|
fragment GasCostsFragment on GasCosts {
|
528
|
+
version {
|
529
|
+
... on Version {
|
530
|
+
value
|
531
|
+
}
|
532
|
+
}
|
481
533
|
add
|
482
534
|
addi
|
483
535
|
aloc
|
@@ -490,7 +542,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
490
542
|
cb
|
491
543
|
cfei
|
492
544
|
cfsi
|
493
|
-
croo
|
494
545
|
div
|
495
546
|
divi
|
496
547
|
ecr1
|
@@ -573,6 +624,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
573
624
|
ccp {
|
574
625
|
...DependentCostFragment
|
575
626
|
}
|
627
|
+
croo {
|
628
|
+
...DependentCostFragment
|
629
|
+
}
|
576
630
|
csiz {
|
577
631
|
...DependentCostFragment
|
578
632
|
}
|
@@ -632,6 +686,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
632
686
|
${DependentCostFragmentFragmentDoc}`;
|
633
687
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
634
688
|
fragment consensusParametersFragment on ConsensusParameters {
|
689
|
+
version {
|
690
|
+
... on Version {
|
691
|
+
value
|
692
|
+
}
|
693
|
+
}
|
635
694
|
txParams {
|
636
695
|
...TxParametersFragment
|
637
696
|
}
|
@@ -691,18 +750,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
691
750
|
fragment nodeInfoFragment on NodeInfo {
|
692
751
|
utxoValidation
|
693
752
|
vmBacktrace
|
694
|
-
minGasPrice
|
695
753
|
maxTx
|
696
754
|
maxDepth
|
697
755
|
nodeVersion
|
698
|
-
peers {
|
699
|
-
id
|
700
|
-
addresses
|
701
|
-
clientVersion
|
702
|
-
blockHeight
|
703
|
-
lastHeartbeatMs
|
704
|
-
appScore
|
705
|
-
}
|
706
756
|
}
|
707
757
|
`;
|
708
758
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -737,13 +787,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
737
787
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
738
788
|
transaction(id: $transactionId) {
|
739
789
|
...transactionFragment
|
740
|
-
receipts {
|
741
|
-
...receiptFragment
|
742
|
-
}
|
743
790
|
}
|
744
791
|
}
|
745
|
-
${TransactionFragmentFragmentDoc}
|
746
|
-
${ReceiptFragmentFragmentDoc}`;
|
792
|
+
${TransactionFragmentFragmentDoc}`;
|
747
793
|
var GetTransactionsDocument = import_graphql_tag.default`
|
748
794
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
749
795
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -871,6 +917,20 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
871
917
|
}
|
872
918
|
}
|
873
919
|
${BalanceFragmentFragmentDoc}`;
|
920
|
+
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
921
|
+
query getLatestGasPrice {
|
922
|
+
latestGasPrice {
|
923
|
+
gasPrice
|
924
|
+
}
|
925
|
+
}
|
926
|
+
`;
|
927
|
+
var EstimateGasPriceDocument = import_graphql_tag.default`
|
928
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
929
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
930
|
+
gasPrice
|
931
|
+
}
|
932
|
+
}
|
933
|
+
`;
|
874
934
|
var GetBalancesDocument = import_graphql_tag.default`
|
875
935
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
876
936
|
balances(
|
@@ -925,12 +985,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
925
985
|
}
|
926
986
|
`;
|
927
987
|
var DryRunDocument = import_graphql_tag.default`
|
928
|
-
mutation dryRun($
|
929
|
-
dryRun(
|
930
|
-
...
|
988
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
989
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
990
|
+
...dryRunTransactionExecutionStatusFragment
|
931
991
|
}
|
932
992
|
}
|
933
|
-
${
|
993
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
934
994
|
var SubmitDocument = import_graphql_tag.default`
|
935
995
|
mutation submit($encodedTransaction: HexString!) {
|
936
996
|
submit(tx: $encodedTransaction) {
|
@@ -1013,6 +1073,12 @@ function getSdk(requester) {
|
|
1013
1073
|
getBalance(variables, options) {
|
1014
1074
|
return requester(GetBalanceDocument, variables, options);
|
1015
1075
|
},
|
1076
|
+
getLatestGasPrice(variables, options) {
|
1077
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
1078
|
+
},
|
1079
|
+
estimateGasPrice(variables, options) {
|
1080
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
1081
|
+
},
|
1016
1082
|
getBalances(variables, options) {
|
1017
1083
|
return requester(GetBalancesDocument, variables, options);
|
1018
1084
|
},
|
@@ -1082,11 +1148,14 @@ var _FuelGraphqlSubscriber = class {
|
|
1082
1148
|
let data;
|
1083
1149
|
let errors;
|
1084
1150
|
try {
|
1085
|
-
|
1151
|
+
const sanitizedText = text.replace(/\s/g, "");
|
1152
|
+
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
1086
1153
|
} catch (e) {
|
1087
1154
|
throw new import_errors.FuelError(
|
1088
1155
|
import_errors.ErrorCode.STREAM_PARSING_ERROR,
|
1089
|
-
`Error while parsing stream data response: ${text}
|
1156
|
+
`Error while parsing stream data response: ${text}
|
1157
|
+
|
1158
|
+
Thrown error: ${e}`
|
1090
1159
|
);
|
1091
1160
|
}
|
1092
1161
|
if (Array.isArray(errors)) {
|
@@ -1197,10 +1266,9 @@ var inputify = (value) => {
|
|
1197
1266
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1198
1267
|
},
|
1199
1268
|
witnessIndex: value.witnessIndex,
|
1200
|
-
maturity: value.maturity ?? 0,
|
1201
1269
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1202
|
-
predicateLength: predicate.length,
|
1203
|
-
predicateDataLength: predicateData.length,
|
1270
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1271
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1204
1272
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1205
1273
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1206
1274
|
};
|
@@ -1231,8 +1299,8 @@ var inputify = (value) => {
|
|
1231
1299
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1232
1300
|
witnessIndex: value.witnessIndex,
|
1233
1301
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1234
|
-
predicateLength: predicate.length,
|
1235
|
-
predicateDataLength: predicateData.length,
|
1302
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1303
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1236
1304
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1237
1305
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1238
1306
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1351,8 +1419,8 @@ function assembleReceiptByType(receipt) {
|
|
1351
1419
|
case "CALL" /* Call */: {
|
1352
1420
|
const callReceipt = {
|
1353
1421
|
type: import_transactions3.ReceiptType.Call,
|
1354
|
-
from: hexOrZero(receipt.
|
1355
|
-
to: hexOrZero(receipt?.to
|
1422
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1423
|
+
to: hexOrZero(receipt?.to),
|
1356
1424
|
amount: (0, import_math4.bn)(receipt.amount),
|
1357
1425
|
assetId: hexOrZero(receipt.assetId),
|
1358
1426
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1366,7 +1434,7 @@ function assembleReceiptByType(receipt) {
|
|
1366
1434
|
case "RETURN" /* Return */: {
|
1367
1435
|
const returnReceipt = {
|
1368
1436
|
type: import_transactions3.ReceiptType.Return,
|
1369
|
-
id: hexOrZero(receipt.
|
1437
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1370
1438
|
val: (0, import_math4.bn)(receipt.val),
|
1371
1439
|
pc: (0, import_math4.bn)(receipt.pc),
|
1372
1440
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1376,7 +1444,7 @@ function assembleReceiptByType(receipt) {
|
|
1376
1444
|
case "RETURN_DATA" /* ReturnData */: {
|
1377
1445
|
const returnDataReceipt = {
|
1378
1446
|
type: import_transactions3.ReceiptType.ReturnData,
|
1379
|
-
id: hexOrZero(receipt.
|
1447
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1380
1448
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1381
1449
|
len: (0, import_math4.bn)(receipt.len),
|
1382
1450
|
digest: hexOrZero(receipt.digest),
|
@@ -1388,7 +1456,7 @@ function assembleReceiptByType(receipt) {
|
|
1388
1456
|
case "PANIC" /* Panic */: {
|
1389
1457
|
const panicReceipt = {
|
1390
1458
|
type: import_transactions3.ReceiptType.Panic,
|
1391
|
-
id: hexOrZero(receipt.
|
1459
|
+
id: hexOrZero(receipt.id),
|
1392
1460
|
reason: (0, import_math4.bn)(receipt.reason),
|
1393
1461
|
pc: (0, import_math4.bn)(receipt.pc),
|
1394
1462
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1399,7 +1467,7 @@ function assembleReceiptByType(receipt) {
|
|
1399
1467
|
case "REVERT" /* Revert */: {
|
1400
1468
|
const revertReceipt = {
|
1401
1469
|
type: import_transactions3.ReceiptType.Revert,
|
1402
|
-
id: hexOrZero(receipt.
|
1470
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1403
1471
|
val: (0, import_math4.bn)(receipt.ra),
|
1404
1472
|
pc: (0, import_math4.bn)(receipt.pc),
|
1405
1473
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1409,7 +1477,7 @@ function assembleReceiptByType(receipt) {
|
|
1409
1477
|
case "LOG" /* Log */: {
|
1410
1478
|
const logReceipt = {
|
1411
1479
|
type: import_transactions3.ReceiptType.Log,
|
1412
|
-
id: hexOrZero(receipt.
|
1480
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1413
1481
|
val0: (0, import_math4.bn)(receipt.ra),
|
1414
1482
|
val1: (0, import_math4.bn)(receipt.rb),
|
1415
1483
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1422,7 +1490,7 @@ function assembleReceiptByType(receipt) {
|
|
1422
1490
|
case "LOG_DATA" /* LogData */: {
|
1423
1491
|
const logDataReceipt = {
|
1424
1492
|
type: import_transactions3.ReceiptType.LogData,
|
1425
|
-
id: hexOrZero(receipt.
|
1493
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1426
1494
|
val0: (0, import_math4.bn)(receipt.ra),
|
1427
1495
|
val1: (0, import_math4.bn)(receipt.rb),
|
1428
1496
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1436,8 +1504,8 @@ function assembleReceiptByType(receipt) {
|
|
1436
1504
|
case "TRANSFER" /* Transfer */: {
|
1437
1505
|
const transferReceipt = {
|
1438
1506
|
type: import_transactions3.ReceiptType.Transfer,
|
1439
|
-
from: hexOrZero(receipt.
|
1440
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1507
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1508
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1441
1509
|
amount: (0, import_math4.bn)(receipt.amount),
|
1442
1510
|
assetId: hexOrZero(receipt.assetId),
|
1443
1511
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1448,8 +1516,8 @@ function assembleReceiptByType(receipt) {
|
|
1448
1516
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1449
1517
|
const transferOutReceipt = {
|
1450
1518
|
type: import_transactions3.ReceiptType.TransferOut,
|
1451
|
-
from: hexOrZero(receipt.
|
1452
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1519
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1520
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1453
1521
|
amount: (0, import_math4.bn)(receipt.amount),
|
1454
1522
|
assetId: hexOrZero(receipt.assetId),
|
1455
1523
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1492,7 +1560,7 @@ function assembleReceiptByType(receipt) {
|
|
1492
1560
|
return receiptMessageOut;
|
1493
1561
|
}
|
1494
1562
|
case "MINT" /* Mint */: {
|
1495
|
-
const contractId = hexOrZero(receipt.
|
1563
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1496
1564
|
const subId = hexOrZero(receipt.subId);
|
1497
1565
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1498
1566
|
const mintReceipt = {
|
@@ -1507,7 +1575,7 @@ function assembleReceiptByType(receipt) {
|
|
1507
1575
|
return mintReceipt;
|
1508
1576
|
}
|
1509
1577
|
case "BURN" /* Burn */: {
|
1510
|
-
const contractId = hexOrZero(receipt.
|
1578
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1511
1579
|
const subId = hexOrZero(receipt.subId);
|
1512
1580
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1513
1581
|
const burnReceipt = {
|
@@ -1592,7 +1660,6 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1592
1660
|
var import_math5 = require("@fuel-ts/math");
|
1593
1661
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1594
1662
|
var import_utils6 = require("@fuel-ts/utils");
|
1595
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1596
1663
|
var getGasUsedFromReceipts = (receipts) => {
|
1597
1664
|
const scriptResult = receipts.filter(
|
1598
1665
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1613,18 +1680,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1613
1680
|
}
|
1614
1681
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1615
1682
|
const witnessCache = [];
|
1616
|
-
const
|
1683
|
+
const chargeableInputs = inputs.filter((input) => {
|
1684
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1685
|
+
if (isCoinOrMessage) {
|
1686
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1687
|
+
return true;
|
1688
|
+
}
|
1689
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1690
|
+
witnessCache.push(input.witnessIndex);
|
1691
|
+
return true;
|
1692
|
+
}
|
1693
|
+
}
|
1694
|
+
return false;
|
1695
|
+
});
|
1696
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1697
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1617
1698
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1618
1699
|
return total.add(
|
1619
|
-
|
1700
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1620
1701
|
);
|
1621
1702
|
}
|
1622
|
-
|
1623
|
-
|
1624
|
-
return total.add(gasCosts.ecr1);
|
1625
|
-
}
|
1626
|
-
return total;
|
1627
|
-
}, (0, import_math5.bn)());
|
1703
|
+
return total.add(gasCosts.ecr1);
|
1704
|
+
}, (0, import_math5.bn)(0));
|
1628
1705
|
return totalGas;
|
1629
1706
|
}
|
1630
1707
|
function getMinGas(params) {
|
@@ -1636,12 +1713,20 @@ function getMinGas(params) {
|
|
1636
1713
|
return minGas;
|
1637
1714
|
}
|
1638
1715
|
function getMaxGas(params) {
|
1639
|
-
const {
|
1716
|
+
const {
|
1717
|
+
gasPerByte,
|
1718
|
+
witnessesLength,
|
1719
|
+
witnessLimit,
|
1720
|
+
minGas,
|
1721
|
+
gasLimit = (0, import_math5.bn)(0),
|
1722
|
+
maxGasPerTx
|
1723
|
+
} = params;
|
1640
1724
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1641
1725
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1642
1726
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1643
1727
|
}
|
1644
|
-
|
1728
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1729
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1645
1730
|
}
|
1646
1731
|
function calculateMetadataGasForTxCreate({
|
1647
1732
|
gasCosts,
|
@@ -1663,6 +1748,10 @@ function calculateMetadataGasForTxScript({
|
|
1663
1748
|
}) {
|
1664
1749
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1665
1750
|
}
|
1751
|
+
var calculateGasFee = (params) => {
|
1752
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1753
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1754
|
+
};
|
1666
1755
|
|
1667
1756
|
// src/providers/utils/json.ts
|
1668
1757
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1811,7 +1900,7 @@ var witnessify = (value) => {
|
|
1811
1900
|
// src/providers/transaction-request/transaction-request.ts
|
1812
1901
|
var BaseTransactionRequest = class {
|
1813
1902
|
/** Gas price for transaction */
|
1814
|
-
|
1903
|
+
tip;
|
1815
1904
|
/** Block until which tx cannot be included */
|
1816
1905
|
maturity;
|
1817
1906
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1830,7 +1919,7 @@ var BaseTransactionRequest = class {
|
|
1830
1919
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1831
1920
|
*/
|
1832
1921
|
constructor({
|
1833
|
-
|
1922
|
+
tip,
|
1834
1923
|
maturity,
|
1835
1924
|
maxFee,
|
1836
1925
|
witnessLimit,
|
@@ -1838,7 +1927,7 @@ var BaseTransactionRequest = class {
|
|
1838
1927
|
outputs,
|
1839
1928
|
witnesses
|
1840
1929
|
} = {}) {
|
1841
|
-
this.
|
1930
|
+
this.tip = (0, import_math7.bn)(tip);
|
1842
1931
|
this.maturity = maturity ?? 0;
|
1843
1932
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1844
1933
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1849,9 +1938,9 @@ var BaseTransactionRequest = class {
|
|
1849
1938
|
static getPolicyMeta(req) {
|
1850
1939
|
let policyTypes = 0;
|
1851
1940
|
const policies = [];
|
1852
|
-
if (req.
|
1853
|
-
policyTypes += import_transactions6.PolicyType.
|
1854
|
-
policies.push({ data: req.
|
1941
|
+
if (req.tip) {
|
1942
|
+
policyTypes += import_transactions6.PolicyType.Tip;
|
1943
|
+
policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
|
1855
1944
|
}
|
1856
1945
|
if (req.witnessLimit) {
|
1857
1946
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -2038,10 +2127,10 @@ var BaseTransactionRequest = class {
|
|
2038
2127
|
* @param predicate - Predicate bytes.
|
2039
2128
|
* @param predicateData - Predicate data bytes.
|
2040
2129
|
*/
|
2041
|
-
addCoinInput(coin
|
2130
|
+
addCoinInput(coin) {
|
2042
2131
|
const { assetId, owner, amount } = coin;
|
2043
2132
|
let witnessIndex;
|
2044
|
-
if (predicate) {
|
2133
|
+
if (coin.predicate) {
|
2045
2134
|
witnessIndex = 0;
|
2046
2135
|
} else {
|
2047
2136
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2056,8 +2145,7 @@ var BaseTransactionRequest = class {
|
|
2056
2145
|
amount,
|
2057
2146
|
assetId,
|
2058
2147
|
txPointer: "0x00000000000000000000000000000000",
|
2059
|
-
witnessIndex
|
2060
|
-
predicate: predicate?.bytes
|
2148
|
+
witnessIndex
|
2061
2149
|
};
|
2062
2150
|
this.pushInput(input);
|
2063
2151
|
this.addChangeOutput(owner, assetId);
|
@@ -2070,11 +2158,11 @@ var BaseTransactionRequest = class {
|
|
2070
2158
|
* @param predicate - Predicate bytes.
|
2071
2159
|
* @param predicateData - Predicate data bytes.
|
2072
2160
|
*/
|
2073
|
-
addMessageInput(message
|
2161
|
+
addMessageInput(message) {
|
2074
2162
|
const { recipient, sender, amount } = message;
|
2075
2163
|
const assetId = import_configs7.BaseAssetId;
|
2076
2164
|
let witnessIndex;
|
2077
|
-
if (predicate) {
|
2165
|
+
if (message.predicate) {
|
2078
2166
|
witnessIndex = 0;
|
2079
2167
|
} else {
|
2080
2168
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2088,8 +2176,7 @@ var BaseTransactionRequest = class {
|
|
2088
2176
|
sender: sender.toB256(),
|
2089
2177
|
recipient: recipient.toB256(),
|
2090
2178
|
amount,
|
2091
|
-
witnessIndex
|
2092
|
-
predicate: predicate?.bytes
|
2179
|
+
witnessIndex
|
2093
2180
|
};
|
2094
2181
|
this.pushInput(input);
|
2095
2182
|
this.addChangeOutput(recipient, assetId);
|
@@ -2120,32 +2207,6 @@ var BaseTransactionRequest = class {
|
|
2120
2207
|
resources.forEach((resource) => this.addResource(resource));
|
2121
2208
|
return this;
|
2122
2209
|
}
|
2123
|
-
/**
|
2124
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
2125
|
-
* outputs from the related assetIds.
|
2126
|
-
*
|
2127
|
-
* @param resources - The resources to add.
|
2128
|
-
* @returns This transaction.
|
2129
|
-
*/
|
2130
|
-
addPredicateResource(resource, predicate) {
|
2131
|
-
if (isCoin(resource)) {
|
2132
|
-
this.addCoinInput(resource, predicate);
|
2133
|
-
} else {
|
2134
|
-
this.addMessageInput(resource, predicate);
|
2135
|
-
}
|
2136
|
-
return this;
|
2137
|
-
}
|
2138
|
-
/**
|
2139
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2140
|
-
* from the related assetIds.
|
2141
|
-
*
|
2142
|
-
* @param resources - The resources to add.
|
2143
|
-
* @returns This transaction.
|
2144
|
-
*/
|
2145
|
-
addPredicateResources(resources, predicate) {
|
2146
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2147
|
-
return this;
|
2148
|
-
}
|
2149
2210
|
/**
|
2150
2211
|
* Adds a coin output to the transaction.
|
2151
2212
|
*
|
@@ -2225,7 +2286,7 @@ var BaseTransactionRequest = class {
|
|
2225
2286
|
}
|
2226
2287
|
calculateMaxGas(chainInfo, minGas) {
|
2227
2288
|
const { consensusParameters } = chainInfo;
|
2228
|
-
const { gasPerByte } = consensusParameters;
|
2289
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2229
2290
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2230
2291
|
(acc, wit) => acc + wit.dataLength,
|
2231
2292
|
0
|
@@ -2234,7 +2295,8 @@ var BaseTransactionRequest = class {
|
|
2234
2295
|
gasPerByte,
|
2235
2296
|
minGas,
|
2236
2297
|
witnessesLength,
|
2237
|
-
witnessLimit: this.witnessLimit
|
2298
|
+
witnessLimit: this.witnessLimit,
|
2299
|
+
maxGasPerTx
|
2238
2300
|
});
|
2239
2301
|
}
|
2240
2302
|
/**
|
@@ -2252,17 +2314,20 @@ var BaseTransactionRequest = class {
|
|
2252
2314
|
});
|
2253
2315
|
const updateAssetInput = (assetId, quantity) => {
|
2254
2316
|
const assetInput = findAssetInput(assetId);
|
2317
|
+
let usedQuantity = quantity;
|
2318
|
+
if (assetId === import_configs7.BaseAssetId) {
|
2319
|
+
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2320
|
+
}
|
2255
2321
|
if (assetInput && "assetId" in assetInput) {
|
2256
2322
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2257
|
-
assetInput.amount =
|
2323
|
+
assetInput.amount = usedQuantity;
|
2258
2324
|
} else {
|
2259
2325
|
this.addResources([
|
2260
2326
|
{
|
2261
2327
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2262
|
-
amount:
|
2328
|
+
amount: usedQuantity,
|
2263
2329
|
assetId,
|
2264
2330
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2265
|
-
maturity: 0,
|
2266
2331
|
blockCreated: (0, import_math7.bn)(1),
|
2267
2332
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2268
2333
|
}
|
@@ -2294,7 +2359,7 @@ var BaseTransactionRequest = class {
|
|
2294
2359
|
toJSON() {
|
2295
2360
|
return normalizeJSON(this);
|
2296
2361
|
}
|
2297
|
-
|
2362
|
+
updatePredicateGasUsed(inputs) {
|
2298
2363
|
this.inputs.forEach((i) => {
|
2299
2364
|
let correspondingInput;
|
2300
2365
|
switch (i.type) {
|
@@ -2316,6 +2381,15 @@ var BaseTransactionRequest = class {
|
|
2316
2381
|
}
|
2317
2382
|
});
|
2318
2383
|
}
|
2384
|
+
shiftPredicateData() {
|
2385
|
+
this.inputs.forEach((input) => {
|
2386
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2387
|
+
input.predicateData = input.paddPredicateData(
|
2388
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2389
|
+
);
|
2390
|
+
}
|
2391
|
+
});
|
2392
|
+
}
|
2319
2393
|
};
|
2320
2394
|
|
2321
2395
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2462,9 +2536,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2462
2536
|
return {
|
2463
2537
|
type: import_transactions8.TransactionType.Create,
|
2464
2538
|
...baseTransaction,
|
2465
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2466
2539
|
bytecodeWitnessIndex,
|
2467
|
-
storageSlotsCount: storageSlots.length,
|
2540
|
+
storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
|
2468
2541
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2469
2542
|
storageSlots
|
2470
2543
|
};
|
@@ -2587,8 +2660,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2587
2660
|
type: import_transactions9.TransactionType.Script,
|
2588
2661
|
scriptGasLimit: this.gasLimit,
|
2589
2662
|
...super.getBaseTransaction(),
|
2590
|
-
scriptLength: script.length,
|
2591
|
-
scriptDataLength: scriptData.length,
|
2663
|
+
scriptLength: (0, import_math10.bn)(script.length),
|
2664
|
+
scriptDataLength: (0, import_math10.bn)(scriptData.length),
|
2592
2665
|
receiptsRoot: import_configs10.ZeroBytes32,
|
2593
2666
|
script: (0, import_utils15.hexlify)(script),
|
2594
2667
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2652,7 +2725,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2652
2725
|
}
|
2653
2726
|
calculateMaxGas(chainInfo, minGas) {
|
2654
2727
|
const { consensusParameters } = chainInfo;
|
2655
|
-
const { gasPerByte } = consensusParameters;
|
2728
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2656
2729
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2657
2730
|
(acc, wit) => acc + wit.dataLength,
|
2658
2731
|
0
|
@@ -2662,7 +2735,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2662
2735
|
minGas,
|
2663
2736
|
witnessesLength,
|
2664
2737
|
witnessLimit: this.witnessLimit,
|
2665
|
-
gasLimit: this.gasLimit
|
2738
|
+
gasLimit: this.gasLimit,
|
2739
|
+
maxGasPerTx
|
2666
2740
|
});
|
2667
2741
|
}
|
2668
2742
|
/**
|
@@ -2737,15 +2811,32 @@ var transactionRequestify = (obj) => {
|
|
2737
2811
|
}
|
2738
2812
|
}
|
2739
2813
|
};
|
2814
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2815
|
+
(acc, input) => {
|
2816
|
+
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2817
|
+
acc.utxos.push(input.id);
|
2818
|
+
}
|
2819
|
+
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2820
|
+
acc.messages.push(input.nonce);
|
2821
|
+
}
|
2822
|
+
return acc;
|
2823
|
+
},
|
2824
|
+
{
|
2825
|
+
utxos: [],
|
2826
|
+
messages: []
|
2827
|
+
}
|
2828
|
+
);
|
2740
2829
|
|
2741
2830
|
// src/providers/transaction-response/transaction-response.ts
|
2742
2831
|
var import_errors13 = require("@fuel-ts/errors");
|
2743
|
-
var
|
2744
|
-
var
|
2745
|
-
var
|
2832
|
+
var import_math15 = require("@fuel-ts/math");
|
2833
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
2834
|
+
var import_utils20 = require("@fuel-ts/utils");
|
2746
2835
|
|
2747
2836
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2748
|
-
var
|
2837
|
+
var import_math14 = require("@fuel-ts/math");
|
2838
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2839
|
+
var import_utils18 = require("@fuel-ts/utils");
|
2749
2840
|
|
2750
2841
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2751
2842
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2753,9 +2844,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2753
2844
|
var import_utils16 = require("@fuel-ts/utils");
|
2754
2845
|
var calculateTransactionFee = (params) => {
|
2755
2846
|
const {
|
2756
|
-
|
2847
|
+
gasPrice,
|
2757
2848
|
rawPayload,
|
2758
|
-
|
2849
|
+
tip,
|
2850
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2759
2851
|
} = params;
|
2760
2852
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2761
2853
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2765,8 +2857,7 @@ var calculateTransactionFee = (params) => {
|
|
2765
2857
|
return {
|
2766
2858
|
fee: (0, import_math11.bn)(0),
|
2767
2859
|
minFee: (0, import_math11.bn)(0),
|
2768
|
-
maxFee: (0, import_math11.bn)(0)
|
2769
|
-
feeFromGasUsed: (0, import_math11.bn)(0)
|
2860
|
+
maxFee: (0, import_math11.bn)(0)
|
2770
2861
|
};
|
2771
2862
|
}
|
2772
2863
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2798,7 +2889,6 @@ var calculateTransactionFee = (params) => {
|
|
2798
2889
|
metadataGas,
|
2799
2890
|
txBytesSize: transactionBytes.length
|
2800
2891
|
});
|
2801
|
-
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2802
2892
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2803
2893
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2804
2894
|
const maxGas = getMaxGas({
|
@@ -2806,17 +2896,25 @@ var calculateTransactionFee = (params) => {
|
|
2806
2896
|
minGas,
|
2807
2897
|
witnessesLength,
|
2808
2898
|
gasLimit,
|
2809
|
-
witnessLimit
|
2899
|
+
witnessLimit,
|
2900
|
+
maxGasPerTx
|
2901
|
+
});
|
2902
|
+
const minFee = calculateGasFee({
|
2903
|
+
gasPrice,
|
2904
|
+
gas: minGas,
|
2905
|
+
priceFactor: gasPriceFactor,
|
2906
|
+
tip
|
2907
|
+
});
|
2908
|
+
const maxFee = calculateGasFee({
|
2909
|
+
gasPrice,
|
2910
|
+
gas: maxGas,
|
2911
|
+
priceFactor: gasPriceFactor,
|
2912
|
+
tip
|
2810
2913
|
});
|
2811
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2812
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2813
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2814
|
-
const fee = minFee.add(feeFromGasUsed);
|
2815
2914
|
return {
|
2816
|
-
fee,
|
2817
2915
|
minFee,
|
2818
2916
|
maxFee,
|
2819
|
-
|
2917
|
+
fee: maxFee
|
2820
2918
|
};
|
2821
2919
|
};
|
2822
2920
|
|
@@ -3430,10 +3528,12 @@ function assembleTransactionSummary(params) {
|
|
3430
3528
|
gqlTransactionStatus,
|
3431
3529
|
abiMap = {},
|
3432
3530
|
maxInputs,
|
3433
|
-
gasCosts
|
3531
|
+
gasCosts,
|
3532
|
+
maxGasPerTx,
|
3533
|
+
gasPrice
|
3434
3534
|
} = params;
|
3435
3535
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3436
|
-
const rawPayload = (0,
|
3536
|
+
const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
|
3437
3537
|
const operations = getOperations({
|
3438
3538
|
transactionType: transaction.type,
|
3439
3539
|
inputs: transaction.inputs || [],
|
@@ -3444,11 +3544,14 @@ function assembleTransactionSummary(params) {
|
|
3444
3544
|
maxInputs
|
3445
3545
|
});
|
3446
3546
|
const typeName = getTransactionTypeName(transaction.type);
|
3547
|
+
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3447
3548
|
const { fee } = calculateTransactionFee({
|
3448
|
-
|
3549
|
+
gasPrice,
|
3449
3550
|
rawPayload,
|
3551
|
+
tip,
|
3450
3552
|
consensusParameters: {
|
3451
3553
|
gasCosts,
|
3554
|
+
maxGasPerTx,
|
3452
3555
|
feeParams: {
|
3453
3556
|
gasPerByte,
|
3454
3557
|
gasPriceFactor
|
@@ -3460,7 +3563,7 @@ function assembleTransactionSummary(params) {
|
|
3460
3563
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3461
3564
|
let date;
|
3462
3565
|
if (time) {
|
3463
|
-
date =
|
3566
|
+
date = import_utils18.DateTime.fromTai64(time);
|
3464
3567
|
}
|
3465
3568
|
const transactionSummary = {
|
3466
3569
|
id,
|
@@ -3488,12 +3591,12 @@ function assembleTransactionSummary(params) {
|
|
3488
3591
|
|
3489
3592
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3490
3593
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3491
|
-
var
|
3594
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
3492
3595
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3493
3596
|
return receipts.reduce((logs, receipt) => {
|
3494
|
-
if (receipt.type ===
|
3597
|
+
if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
|
3495
3598
|
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3496
|
-
const data = receipt.type ===
|
3599
|
+
const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3497
3600
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3498
3601
|
logs.push(decodedLog);
|
3499
3602
|
}
|
@@ -3508,7 +3611,7 @@ var TransactionResponse = class {
|
|
3508
3611
|
/** Current provider */
|
3509
3612
|
provider;
|
3510
3613
|
/** Gas used on the transaction */
|
3511
|
-
gasUsed = (0,
|
3614
|
+
gasUsed = (0, import_math15.bn)(0);
|
3512
3615
|
/** The graphql Transaction with receipts object. */
|
3513
3616
|
gqlTransaction;
|
3514
3617
|
abis;
|
@@ -3566,8 +3669,8 @@ var TransactionResponse = class {
|
|
3566
3669
|
* @returns The decoded transaction.
|
3567
3670
|
*/
|
3568
3671
|
decodeTransaction(transactionWithReceipts) {
|
3569
|
-
return new
|
3570
|
-
(0,
|
3672
|
+
return new import_transactions18.TransactionCoder().decode(
|
3673
|
+
(0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
|
3571
3674
|
0
|
3572
3675
|
)?.[0];
|
3573
3676
|
}
|
@@ -3586,20 +3689,27 @@ var TransactionResponse = class {
|
|
3586
3689
|
const decodedTransaction = this.decodeTransaction(
|
3587
3690
|
transaction
|
3588
3691
|
);
|
3589
|
-
|
3590
|
-
|
3692
|
+
let txReceipts = [];
|
3693
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3694
|
+
txReceipts = transaction.status.receipts;
|
3695
|
+
}
|
3696
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3697
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3698
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3591
3699
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3592
3700
|
const transactionSummary = assembleTransactionSummary({
|
3593
3701
|
id: this.id,
|
3594
3702
|
receipts,
|
3595
3703
|
transaction: decodedTransaction,
|
3596
|
-
transactionBytes: (0,
|
3704
|
+
transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
|
3597
3705
|
gqlTransactionStatus: transaction.status,
|
3598
3706
|
gasPerByte,
|
3599
3707
|
gasPriceFactor,
|
3600
3708
|
abiMap: contractsAbiMap,
|
3601
3709
|
maxInputs,
|
3602
|
-
gasCosts
|
3710
|
+
gasCosts,
|
3711
|
+
maxGasPerTx,
|
3712
|
+
gasPrice
|
3603
3713
|
});
|
3604
3714
|
return transactionSummary;
|
3605
3715
|
}
|
@@ -3726,29 +3836,29 @@ var processGqlChain = (chain) => {
|
|
3726
3836
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3727
3837
|
return {
|
3728
3838
|
name,
|
3729
|
-
baseChainHeight: (0,
|
3839
|
+
baseChainHeight: (0, import_math16.bn)(daHeight),
|
3730
3840
|
consensusParameters: {
|
3731
|
-
contractMaxSize: (0,
|
3732
|
-
maxInputs: (0,
|
3733
|
-
maxOutputs: (0,
|
3734
|
-
maxWitnesses: (0,
|
3735
|
-
maxGasPerTx: (0,
|
3736
|
-
maxScriptLength: (0,
|
3737
|
-
maxScriptDataLength: (0,
|
3738
|
-
maxStorageSlots: (0,
|
3739
|
-
maxPredicateLength: (0,
|
3740
|
-
maxPredicateDataLength: (0,
|
3741
|
-
maxGasPerPredicate: (0,
|
3742
|
-
gasPriceFactor: (0,
|
3743
|
-
gasPerByte: (0,
|
3744
|
-
maxMessageDataLength: (0,
|
3745
|
-
chainId: (0,
|
3841
|
+
contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
|
3842
|
+
maxInputs: (0, import_math16.bn)(txParams.maxInputs),
|
3843
|
+
maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
|
3844
|
+
maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
|
3845
|
+
maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
|
3846
|
+
maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
|
3847
|
+
maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
|
3848
|
+
maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
|
3849
|
+
maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
|
3850
|
+
maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
|
3851
|
+
maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
|
3852
|
+
gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
|
3853
|
+
gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
|
3854
|
+
maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
|
3855
|
+
chainId: (0, import_math16.bn)(consensusParameters.chainId),
|
3746
3856
|
gasCosts
|
3747
3857
|
},
|
3748
3858
|
gasCosts,
|
3749
3859
|
latestBlock: {
|
3750
3860
|
id: latestBlock.id,
|
3751
|
-
height: (0,
|
3861
|
+
height: (0, import_math16.bn)(latestBlock.height),
|
3752
3862
|
time: latestBlock.header.time,
|
3753
3863
|
transactions: latestBlock.transactions.map((i) => ({
|
3754
3864
|
id: i.id
|
@@ -3842,10 +3952,8 @@ var _Provider = class {
|
|
3842
3952
|
* Returns some helpful parameters related to gas fees.
|
3843
3953
|
*/
|
3844
3954
|
getGasConfig() {
|
3845
|
-
const { minGasPrice } = this.getNode();
|
3846
3955
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3847
3956
|
return {
|
3848
|
-
minGasPrice,
|
3849
3957
|
maxGasPerTx,
|
3850
3958
|
maxGasPerPredicate,
|
3851
3959
|
gasPriceFactor,
|
@@ -3943,7 +4051,7 @@ var _Provider = class {
|
|
3943
4051
|
*/
|
3944
4052
|
async getBlockNumber() {
|
3945
4053
|
const { chain } = await this.operations.getChain();
|
3946
|
-
return (0,
|
4054
|
+
return (0, import_math16.bn)(chain.latestBlock.height, 10);
|
3947
4055
|
}
|
3948
4056
|
/**
|
3949
4057
|
* Returns the chain information.
|
@@ -3953,13 +4061,11 @@ var _Provider = class {
|
|
3953
4061
|
async fetchNode() {
|
3954
4062
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3955
4063
|
const processedNodeInfo = {
|
3956
|
-
maxDepth: (0,
|
3957
|
-
maxTx: (0,
|
3958
|
-
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
4064
|
+
maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
|
4065
|
+
maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
|
3959
4066
|
nodeVersion: nodeInfo.nodeVersion,
|
3960
4067
|
utxoValidation: nodeInfo.utxoValidation,
|
3961
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3962
|
-
peers: nodeInfo.peers
|
4068
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3963
4069
|
};
|
3964
4070
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3965
4071
|
return processedNodeInfo;
|
@@ -4001,9 +4107,9 @@ var _Provider = class {
|
|
4001
4107
|
if (estimateTxDependencies) {
|
4002
4108
|
await this.estimateTxDependencies(transactionRequest);
|
4003
4109
|
}
|
4004
|
-
const encodedTransaction = (0,
|
4110
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4005
4111
|
let abis;
|
4006
|
-
if (transactionRequest.type ===
|
4112
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4007
4113
|
abis = transactionRequest.abis;
|
4008
4114
|
}
|
4009
4115
|
if (awaitExecution) {
|
@@ -4044,15 +4150,14 @@ var _Provider = class {
|
|
4044
4150
|
if (estimateTxDependencies) {
|
4045
4151
|
return this.estimateTxDependencies(transactionRequest);
|
4046
4152
|
}
|
4047
|
-
const encodedTransaction = (0,
|
4048
|
-
const { dryRun:
|
4049
|
-
encodedTransaction,
|
4153
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4154
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4155
|
+
encodedTransactions: encodedTransaction,
|
4050
4156
|
utxoValidation: utxoValidation || false
|
4051
4157
|
});
|
4052
|
-
const receipts =
|
4053
|
-
|
4054
|
-
|
4055
|
-
};
|
4158
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
4159
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4160
|
+
return { receipts, dryrunStatus: status };
|
4056
4161
|
}
|
4057
4162
|
/**
|
4058
4163
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4063,13 +4168,13 @@ var _Provider = class {
|
|
4063
4168
|
async estimatePredicates(transactionRequest) {
|
4064
4169
|
const shouldEstimatePredicates = Boolean(
|
4065
4170
|
transactionRequest.inputs.find(
|
4066
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4171
|
+
(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()
|
4067
4172
|
)
|
4068
4173
|
);
|
4069
4174
|
if (!shouldEstimatePredicates) {
|
4070
4175
|
return transactionRequest;
|
4071
4176
|
}
|
4072
|
-
const encodedTransaction = (0,
|
4177
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4073
4178
|
const response = await this.operations.estimatePredicates({
|
4074
4179
|
encodedTransaction
|
4075
4180
|
});
|
@@ -4078,7 +4183,7 @@ var _Provider = class {
|
|
4078
4183
|
} = response;
|
4079
4184
|
if (inputs) {
|
4080
4185
|
inputs.forEach((input, index) => {
|
4081
|
-
if ("predicateGasUsed" in input && (0,
|
4186
|
+
if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
|
4082
4187
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4083
4188
|
}
|
4084
4189
|
});
|
@@ -4091,31 +4196,31 @@ var _Provider = class {
|
|
4091
4196
|
* If there are missing variable outputs,
|
4092
4197
|
* `addVariableOutputs` is called on the transaction.
|
4093
4198
|
*
|
4094
|
-
* @privateRemarks
|
4095
|
-
* TODO: Investigate support for missing contract IDs
|
4096
|
-
* TODO: Add support for missing output messages
|
4097
4199
|
*
|
4098
4200
|
* @param transactionRequest - The transaction request object.
|
4099
4201
|
* @returns A promise.
|
4100
4202
|
*/
|
4101
4203
|
async estimateTxDependencies(transactionRequest) {
|
4102
|
-
if (transactionRequest.type ===
|
4204
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Create) {
|
4103
4205
|
return {
|
4104
4206
|
receipts: [],
|
4105
4207
|
outputVariables: 0,
|
4106
4208
|
missingContractIds: []
|
4107
4209
|
};
|
4108
4210
|
}
|
4109
|
-
await this.estimatePredicates(transactionRequest);
|
4110
4211
|
let receipts = [];
|
4111
4212
|
const missingContractIds = [];
|
4112
4213
|
let outputVariables = 0;
|
4214
|
+
let dryrunStatus;
|
4113
4215
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4114
|
-
const {
|
4115
|
-
|
4216
|
+
const {
|
4217
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4218
|
+
} = await this.operations.dryRun({
|
4219
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4116
4220
|
utxoValidation: false
|
4117
4221
|
});
|
4118
|
-
receipts =
|
4222
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4223
|
+
dryrunStatus = status;
|
4119
4224
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4120
4225
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4121
4226
|
if (hasMissingOutputs) {
|
@@ -4125,6 +4230,10 @@ var _Provider = class {
|
|
4125
4230
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4126
4231
|
missingContractIds.push(contractId);
|
4127
4232
|
});
|
4233
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4234
|
+
transactionRequest
|
4235
|
+
});
|
4236
|
+
transactionRequest.maxFee = maxFee;
|
4128
4237
|
} else {
|
4129
4238
|
break;
|
4130
4239
|
}
|
@@ -4132,37 +4241,139 @@ var _Provider = class {
|
|
4132
4241
|
return {
|
4133
4242
|
receipts,
|
4134
4243
|
outputVariables,
|
4135
|
-
missingContractIds
|
4244
|
+
missingContractIds,
|
4245
|
+
dryrunStatus
|
4136
4246
|
};
|
4137
4247
|
}
|
4248
|
+
/**
|
4249
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4250
|
+
*
|
4251
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4252
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4253
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4254
|
+
*
|
4255
|
+
* @param transactionRequests - Array of transaction request objects.
|
4256
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4257
|
+
*/
|
4258
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4259
|
+
const results = transactionRequests.map(() => ({
|
4260
|
+
receipts: [],
|
4261
|
+
outputVariables: 0,
|
4262
|
+
missingContractIds: [],
|
4263
|
+
dryrunStatus: void 0
|
4264
|
+
}));
|
4265
|
+
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4266
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4267
|
+
allRequests.forEach((req, index) => {
|
4268
|
+
if (req.type === import_transactions19.TransactionType.Script) {
|
4269
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4270
|
+
}
|
4271
|
+
});
|
4272
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4273
|
+
let attempt = 0;
|
4274
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4275
|
+
const encodedTransactions = transactionsToProcess.map(
|
4276
|
+
(index) => serializedTransactionsMap.get(index)
|
4277
|
+
);
|
4278
|
+
const dryRunResults = await this.operations.dryRun({
|
4279
|
+
encodedTransactions,
|
4280
|
+
utxoValidation: false
|
4281
|
+
});
|
4282
|
+
const nextRoundTransactions = [];
|
4283
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4284
|
+
const currentResultIndex = transactionsToProcess[i];
|
4285
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4286
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4287
|
+
results[currentResultIndex].dryrunStatus = status;
|
4288
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4289
|
+
results[currentResultIndex].receipts
|
4290
|
+
);
|
4291
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4292
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4293
|
+
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4294
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4295
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4296
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4297
|
+
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4298
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4299
|
+
});
|
4300
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4301
|
+
transactionRequest: requestToProcess
|
4302
|
+
});
|
4303
|
+
requestToProcess.maxFee = maxFee;
|
4304
|
+
serializedTransactionsMap.set(
|
4305
|
+
currentResultIndex,
|
4306
|
+
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4307
|
+
);
|
4308
|
+
nextRoundTransactions.push(currentResultIndex);
|
4309
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4310
|
+
}
|
4311
|
+
}
|
4312
|
+
transactionsToProcess = nextRoundTransactions;
|
4313
|
+
attempt += 1;
|
4314
|
+
}
|
4315
|
+
return results;
|
4316
|
+
}
|
4317
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4318
|
+
if (estimateTxDependencies) {
|
4319
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4320
|
+
}
|
4321
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4322
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4323
|
+
encodedTransactions,
|
4324
|
+
utxoValidation: utxoValidation || false
|
4325
|
+
});
|
4326
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4327
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4328
|
+
return { receipts, dryrunStatus: status };
|
4329
|
+
});
|
4330
|
+
return results;
|
4331
|
+
}
|
4138
4332
|
/**
|
4139
4333
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4140
4334
|
* @param transactionRequest - The transaction request object.
|
4141
4335
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4142
4336
|
*/
|
4143
|
-
estimateTxGasAndFee(params) {
|
4337
|
+
async estimateTxGasAndFee(params) {
|
4144
4338
|
const { transactionRequest } = params;
|
4145
|
-
|
4339
|
+
let { gasPrice } = params;
|
4146
4340
|
const chainInfo = this.getChain();
|
4147
|
-
const
|
4148
|
-
transactionRequest.gasPrice = gasPrice;
|
4341
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
4149
4342
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4150
|
-
|
4151
|
-
|
4343
|
+
if (!gasPrice) {
|
4344
|
+
gasPrice = await this.estimateGasPrice(10);
|
4345
|
+
}
|
4346
|
+
const minFee = calculateGasFee({
|
4347
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4348
|
+
gas: minGas,
|
4349
|
+
priceFactor: gasPriceFactor,
|
4350
|
+
tip: transactionRequest.tip
|
4351
|
+
}).add(1);
|
4352
|
+
let gasLimit = (0, import_math16.bn)(0);
|
4353
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4354
|
+
gasLimit = transactionRequest.gasLimit;
|
4152
4355
|
if (transactionRequest.gasLimit.eq(0)) {
|
4153
4356
|
transactionRequest.gasLimit = minGas;
|
4154
4357
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4155
4358
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4156
4359
|
);
|
4360
|
+
gasLimit = transactionRequest.gasLimit;
|
4157
4361
|
}
|
4158
4362
|
}
|
4159
4363
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4160
|
-
const maxFee =
|
4364
|
+
const maxFee = calculateGasFee({
|
4365
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4366
|
+
gas: maxGas,
|
4367
|
+
priceFactor: gasPriceFactor,
|
4368
|
+
tip: transactionRequest.tip
|
4369
|
+
}).add(1);
|
4161
4370
|
return {
|
4162
4371
|
minGas,
|
4163
4372
|
minFee,
|
4164
4373
|
maxGas,
|
4165
|
-
maxFee
|
4374
|
+
maxFee,
|
4375
|
+
gasPrice,
|
4376
|
+
gasLimit
|
4166
4377
|
};
|
4167
4378
|
}
|
4168
4379
|
/**
|
@@ -4180,15 +4391,17 @@ var _Provider = class {
|
|
4180
4391
|
if (estimateTxDependencies) {
|
4181
4392
|
return this.estimateTxDependencies(transactionRequest);
|
4182
4393
|
}
|
4183
|
-
const
|
4184
|
-
const { dryRun:
|
4185
|
-
|
4394
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4395
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4396
|
+
encodedTransactions,
|
4186
4397
|
utxoValidation: true
|
4187
4398
|
});
|
4188
|
-
const
|
4189
|
-
|
4190
|
-
receipts
|
4191
|
-
|
4399
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4400
|
+
const { id, receipts, status } = dryRunStatus;
|
4401
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4402
|
+
return { id, receipts: processedReceipts, status };
|
4403
|
+
});
|
4404
|
+
return { receipts: callResult[0].receipts };
|
4192
4405
|
}
|
4193
4406
|
/**
|
4194
4407
|
* Returns a transaction cost to enable user
|
@@ -4205,77 +4418,79 @@ var _Provider = class {
|
|
4205
4418
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4206
4419
|
* @returns A promise that resolves to the transaction cost object.
|
4207
4420
|
*/
|
4208
|
-
async getTransactionCost(transactionRequestLike,
|
4209
|
-
estimateTxDependencies = true,
|
4210
|
-
estimatePredicates = true,
|
4211
|
-
resourcesOwner,
|
4212
|
-
signatureCallback
|
4213
|
-
} = {}) {
|
4421
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
4214
4422
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4215
|
-
const
|
4216
|
-
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4217
|
-
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4423
|
+
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
4218
4424
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4219
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4425
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4220
4426
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4427
|
+
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4221
4428
|
if (isScriptTransaction) {
|
4222
|
-
txRequestClone.gasLimit = (0,
|
4429
|
+
txRequestClone.gasLimit = (0, import_math16.bn)(0);
|
4223
4430
|
}
|
4224
|
-
if (
|
4225
|
-
|
4226
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4227
|
-
}
|
4228
|
-
await this.estimatePredicates(txRequestClone);
|
4431
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4432
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4229
4433
|
}
|
4434
|
+
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4435
|
+
let addedSignatures = 0;
|
4230
4436
|
if (signatureCallback && isScriptTransaction) {
|
4231
|
-
|
4437
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4438
|
+
await signatureCallback(signedRequest);
|
4439
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4232
4440
|
}
|
4233
|
-
|
4234
|
-
|
4441
|
+
await this.estimatePredicates(signedRequest);
|
4442
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4443
|
+
transactionRequest: signedRequest
|
4235
4444
|
});
|
4236
4445
|
let receipts = [];
|
4237
4446
|
let missingContractIds = [];
|
4238
4447
|
let outputVariables = 0;
|
4239
|
-
let gasUsed = (0,
|
4240
|
-
|
4241
|
-
|
4448
|
+
let gasUsed = (0, import_math16.bn)(0);
|
4449
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4450
|
+
txRequestClone.maxFee = maxFee;
|
4451
|
+
if (isScriptTransaction) {
|
4452
|
+
txRequestClone.gasLimit = gasLimit;
|
4453
|
+
if (signatureCallback) {
|
4454
|
+
await signatureCallback(txRequestClone);
|
4455
|
+
}
|
4242
4456
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4243
4457
|
receipts = result.receipts;
|
4244
4458
|
outputVariables = result.outputVariables;
|
4245
4459
|
missingContractIds = result.missingContractIds;
|
4246
4460
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4247
4461
|
txRequestClone.gasLimit = gasUsed;
|
4248
|
-
|
4249
|
-
|
4250
|
-
|
4462
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4463
|
+
transactionRequest: txRequestClone,
|
4464
|
+
gasPrice
|
4251
4465
|
}));
|
4252
4466
|
}
|
4253
4467
|
return {
|
4254
4468
|
requiredQuantities: allQuantities,
|
4255
4469
|
receipts,
|
4256
4470
|
gasUsed,
|
4257
|
-
|
4258
|
-
gasPrice: setGasPrice,
|
4471
|
+
gasPrice,
|
4259
4472
|
minGas,
|
4260
4473
|
maxGas,
|
4261
4474
|
minFee,
|
4262
4475
|
maxFee,
|
4263
|
-
estimatedInputs: txRequestClone.inputs,
|
4264
4476
|
outputVariables,
|
4265
|
-
missingContractIds
|
4477
|
+
missingContractIds,
|
4478
|
+
addedSignatures,
|
4479
|
+
estimatedPredicates: txRequestClone.inputs
|
4266
4480
|
};
|
4267
4481
|
}
|
4268
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4482
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4269
4483
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4270
4484
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4271
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4485
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4486
|
+
quantitiesToContract
|
4487
|
+
});
|
4272
4488
|
transactionRequest.addResources(
|
4273
4489
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4274
4490
|
);
|
4275
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4276
|
-
|
4277
|
-
|
4278
|
-
);
|
4491
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4492
|
+
quantitiesToContract
|
4493
|
+
});
|
4279
4494
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4280
4495
|
return {
|
4281
4496
|
resources,
|
@@ -4291,17 +4506,16 @@ var _Provider = class {
|
|
4291
4506
|
const result = await this.operations.getCoins({
|
4292
4507
|
first: 10,
|
4293
4508
|
...paginationArgs,
|
4294
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4509
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4295
4510
|
});
|
4296
4511
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4297
4512
|
return coins.map((coin) => ({
|
4298
4513
|
id: coin.utxoId,
|
4299
4514
|
assetId: coin.assetId,
|
4300
|
-
amount: (0,
|
4515
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4301
4516
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4302
|
-
|
4303
|
-
|
4304
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4517
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4518
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4305
4519
|
}));
|
4306
4520
|
}
|
4307
4521
|
/**
|
@@ -4315,19 +4529,19 @@ var _Provider = class {
|
|
4315
4529
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4316
4530
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4317
4531
|
const excludeInput = {
|
4318
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4319
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4532
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4533
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4320
4534
|
};
|
4321
4535
|
if (this.cache) {
|
4322
4536
|
const uniqueUtxos = new Set(
|
4323
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4537
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4324
4538
|
);
|
4325
4539
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4326
4540
|
}
|
4327
4541
|
const coinsQuery = {
|
4328
4542
|
owner: ownerAddress.toB256(),
|
4329
4543
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4330
|
-
assetId: (0,
|
4544
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4331
4545
|
amount: amount.toString(10),
|
4332
4546
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4333
4547
|
})),
|
@@ -4338,9 +4552,9 @@ var _Provider = class {
|
|
4338
4552
|
switch (coin.__typename) {
|
4339
4553
|
case "MessageCoin":
|
4340
4554
|
return {
|
4341
|
-
amount: (0,
|
4555
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4342
4556
|
assetId: coin.assetId,
|
4343
|
-
daHeight: (0,
|
4557
|
+
daHeight: (0, import_math16.bn)(coin.daHeight),
|
4344
4558
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4345
4559
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4346
4560
|
nonce: coin.nonce
|
@@ -4348,12 +4562,11 @@ var _Provider = class {
|
|
4348
4562
|
case "Coin":
|
4349
4563
|
return {
|
4350
4564
|
id: coin.utxoId,
|
4351
|
-
amount: (0,
|
4565
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4352
4566
|
assetId: coin.assetId,
|
4353
4567
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4354
|
-
|
4355
|
-
|
4356
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4568
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4569
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4357
4570
|
};
|
4358
4571
|
default:
|
4359
4572
|
return null;
|
@@ -4370,13 +4583,13 @@ var _Provider = class {
|
|
4370
4583
|
async getBlock(idOrHeight) {
|
4371
4584
|
let variables;
|
4372
4585
|
if (typeof idOrHeight === "number") {
|
4373
|
-
variables = { height: (0,
|
4586
|
+
variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4374
4587
|
} else if (idOrHeight === "latest") {
|
4375
4588
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4376
4589
|
} else if (idOrHeight.length === 66) {
|
4377
4590
|
variables = { blockId: idOrHeight };
|
4378
4591
|
} else {
|
4379
|
-
variables = { blockId: (0,
|
4592
|
+
variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4380
4593
|
}
|
4381
4594
|
const { block } = await this.operations.getBlock(variables);
|
4382
4595
|
if (!block) {
|
@@ -4384,7 +4597,7 @@ var _Provider = class {
|
|
4384
4597
|
}
|
4385
4598
|
return {
|
4386
4599
|
id: block.id,
|
4387
|
-
height: (0,
|
4600
|
+
height: (0, import_math16.bn)(block.height),
|
4388
4601
|
time: block.header.time,
|
4389
4602
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4390
4603
|
};
|
@@ -4399,7 +4612,7 @@ var _Provider = class {
|
|
4399
4612
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4400
4613
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4401
4614
|
id: block.id,
|
4402
|
-
height: (0,
|
4615
|
+
height: (0, import_math16.bn)(block.height),
|
4403
4616
|
time: block.header.time,
|
4404
4617
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4405
4618
|
}));
|
@@ -4414,7 +4627,7 @@ var _Provider = class {
|
|
4414
4627
|
async getBlockWithTransactions(idOrHeight) {
|
4415
4628
|
let variables;
|
4416
4629
|
if (typeof idOrHeight === "number") {
|
4417
|
-
variables = { blockHeight: (0,
|
4630
|
+
variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4418
4631
|
} else if (idOrHeight === "latest") {
|
4419
4632
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4420
4633
|
} else {
|
@@ -4426,11 +4639,11 @@ var _Provider = class {
|
|
4426
4639
|
}
|
4427
4640
|
return {
|
4428
4641
|
id: block.id,
|
4429
|
-
height: (0,
|
4642
|
+
height: (0, import_math16.bn)(block.height, 10),
|
4430
4643
|
time: block.header.time,
|
4431
4644
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4432
4645
|
transactions: block.transactions.map(
|
4433
|
-
(tx) => new
|
4646
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4434
4647
|
)
|
4435
4648
|
};
|
4436
4649
|
}
|
@@ -4445,8 +4658,8 @@ var _Provider = class {
|
|
4445
4658
|
if (!transaction) {
|
4446
4659
|
return null;
|
4447
4660
|
}
|
4448
|
-
return new
|
4449
|
-
(0,
|
4661
|
+
return new import_transactions19.TransactionCoder().decode(
|
4662
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4450
4663
|
0
|
4451
4664
|
)?.[0];
|
4452
4665
|
}
|
@@ -4473,9 +4686,9 @@ var _Provider = class {
|
|
4473
4686
|
async getContractBalance(contractId, assetId) {
|
4474
4687
|
const { contractBalance } = await this.operations.getContractBalance({
|
4475
4688
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4476
|
-
asset: (0,
|
4689
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4477
4690
|
});
|
4478
|
-
return (0,
|
4691
|
+
return (0, import_math16.bn)(contractBalance.amount, 10);
|
4479
4692
|
}
|
4480
4693
|
/**
|
4481
4694
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4487,9 +4700,9 @@ var _Provider = class {
|
|
4487
4700
|
async getBalance(owner, assetId) {
|
4488
4701
|
const { balance } = await this.operations.getBalance({
|
4489
4702
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4490
|
-
assetId: (0,
|
4703
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4491
4704
|
});
|
4492
|
-
return (0,
|
4705
|
+
return (0, import_math16.bn)(balance.amount, 10);
|
4493
4706
|
}
|
4494
4707
|
/**
|
4495
4708
|
* Returns balances for the given owner.
|
@@ -4507,7 +4720,7 @@ var _Provider = class {
|
|
4507
4720
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4508
4721
|
return balances.map((balance) => ({
|
4509
4722
|
assetId: balance.assetId,
|
4510
|
-
amount: (0,
|
4723
|
+
amount: (0, import_math16.bn)(balance.amount)
|
4511
4724
|
}));
|
4512
4725
|
}
|
4513
4726
|
/**
|
@@ -4525,19 +4738,19 @@ var _Provider = class {
|
|
4525
4738
|
});
|
4526
4739
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4527
4740
|
return messages.map((message) => ({
|
4528
|
-
messageId:
|
4741
|
+
messageId: import_transactions19.InputMessageCoder.getMessageId({
|
4529
4742
|
sender: message.sender,
|
4530
4743
|
recipient: message.recipient,
|
4531
4744
|
nonce: message.nonce,
|
4532
|
-
amount: (0,
|
4745
|
+
amount: (0, import_math16.bn)(message.amount),
|
4533
4746
|
data: message.data
|
4534
4747
|
}),
|
4535
4748
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4536
4749
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4537
4750
|
nonce: message.nonce,
|
4538
|
-
amount: (0,
|
4539
|
-
data:
|
4540
|
-
daHeight: (0,
|
4751
|
+
amount: (0, import_math16.bn)(message.amount),
|
4752
|
+
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4753
|
+
daHeight: (0, import_math16.bn)(message.daHeight)
|
4541
4754
|
}));
|
4542
4755
|
}
|
4543
4756
|
/**
|
@@ -4590,44 +4803,60 @@ var _Provider = class {
|
|
4590
4803
|
} = result.messageProof;
|
4591
4804
|
return {
|
4592
4805
|
messageProof: {
|
4593
|
-
proofIndex: (0,
|
4806
|
+
proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
|
4594
4807
|
proofSet: messageProof.proofSet
|
4595
4808
|
},
|
4596
4809
|
blockProof: {
|
4597
|
-
proofIndex: (0,
|
4810
|
+
proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
|
4598
4811
|
proofSet: blockProof.proofSet
|
4599
4812
|
},
|
4600
4813
|
messageBlockHeader: {
|
4601
4814
|
id: messageBlockHeader.id,
|
4602
|
-
daHeight: (0,
|
4603
|
-
transactionsCount: (0,
|
4815
|
+
daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
|
4816
|
+
transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
|
4604
4817
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4605
|
-
height: (0,
|
4818
|
+
height: (0, import_math16.bn)(messageBlockHeader.height),
|
4606
4819
|
prevRoot: messageBlockHeader.prevRoot,
|
4607
4820
|
time: messageBlockHeader.time,
|
4608
4821
|
applicationHash: messageBlockHeader.applicationHash,
|
4609
|
-
|
4610
|
-
|
4822
|
+
messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
|
4823
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4824
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4825
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4826
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4611
4827
|
},
|
4612
4828
|
commitBlockHeader: {
|
4613
4829
|
id: commitBlockHeader.id,
|
4614
|
-
daHeight: (0,
|
4615
|
-
transactionsCount: (0,
|
4830
|
+
daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
|
4831
|
+
transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
|
4616
4832
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4617
|
-
height: (0,
|
4833
|
+
height: (0, import_math16.bn)(commitBlockHeader.height),
|
4618
4834
|
prevRoot: commitBlockHeader.prevRoot,
|
4619
4835
|
time: commitBlockHeader.time,
|
4620
4836
|
applicationHash: commitBlockHeader.applicationHash,
|
4621
|
-
|
4622
|
-
|
4837
|
+
messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
|
4838
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4839
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4840
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4841
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4623
4842
|
},
|
4624
4843
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4625
4844
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4626
4845
|
nonce,
|
4627
|
-
amount: (0,
|
4846
|
+
amount: (0, import_math16.bn)(amount),
|
4628
4847
|
data
|
4629
4848
|
};
|
4630
4849
|
}
|
4850
|
+
async getLatestGasPrice() {
|
4851
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4852
|
+
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4853
|
+
}
|
4854
|
+
async estimateGasPrice(blockHorizon) {
|
4855
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4856
|
+
blockHorizon: String(blockHorizon)
|
4857
|
+
});
|
4858
|
+
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4859
|
+
}
|
4631
4860
|
/**
|
4632
4861
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4633
4862
|
*
|
@@ -4647,10 +4876,10 @@ var _Provider = class {
|
|
4647
4876
|
*/
|
4648
4877
|
async produceBlocks(amount, startTime) {
|
4649
4878
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4650
|
-
blocksToProduce: (0,
|
4651
|
-
startTimestamp: startTime ?
|
4879
|
+
blocksToProduce: (0, import_math16.bn)(amount).toString(10),
|
4880
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4652
4881
|
});
|
4653
|
-
return (0,
|
4882
|
+
return (0, import_math16.bn)(latestBlockHeight);
|
4654
4883
|
}
|
4655
4884
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4656
4885
|
async getTransactionResponse(transactionId) {
|
@@ -4664,7 +4893,7 @@ cacheInputs_fn = function(inputs) {
|
|
4664
4893
|
return;
|
4665
4894
|
}
|
4666
4895
|
inputs.forEach((input) => {
|
4667
|
-
if (input.type ===
|
4896
|
+
if (input.type === import_transactions19.InputType.Coin) {
|
4668
4897
|
this.cache?.set(input.id);
|
4669
4898
|
}
|
4670
4899
|
});
|
@@ -4674,9 +4903,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4674
4903
|
|
4675
4904
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4676
4905
|
var import_errors15 = require("@fuel-ts/errors");
|
4677
|
-
var
|
4678
|
-
var
|
4679
|
-
var
|
4906
|
+
var import_math17 = require("@fuel-ts/math");
|
4907
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
4908
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4680
4909
|
async function getTransactionSummary(params) {
|
4681
4910
|
const { id, provider, abiMap } = params;
|
4682
4911
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -4688,25 +4917,32 @@ async function getTransactionSummary(params) {
|
|
4688
4917
|
`Transaction not found for given id: ${id}.`
|
4689
4918
|
);
|
4690
4919
|
}
|
4691
|
-
const [decodedTransaction] = new
|
4692
|
-
(0,
|
4920
|
+
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
|
4921
|
+
(0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4693
4922
|
0
|
4694
4923
|
);
|
4695
|
-
|
4924
|
+
let txReceipts = [];
|
4925
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4926
|
+
txReceipts = gqlTransaction.status.receipts;
|
4927
|
+
}
|
4928
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4696
4929
|
const {
|
4697
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4930
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4698
4931
|
} = provider.getChain();
|
4932
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4699
4933
|
const transactionInfo = assembleTransactionSummary({
|
4700
4934
|
id: gqlTransaction.id,
|
4701
4935
|
receipts,
|
4702
4936
|
transaction: decodedTransaction,
|
4703
|
-
transactionBytes: (0,
|
4937
|
+
transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4704
4938
|
gqlTransactionStatus: gqlTransaction.status,
|
4705
|
-
gasPerByte: (0,
|
4706
|
-
gasPriceFactor: (0,
|
4939
|
+
gasPerByte: (0, import_math17.bn)(gasPerByte),
|
4940
|
+
gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
|
4707
4941
|
abiMap,
|
4708
4942
|
maxInputs,
|
4709
|
-
gasCosts
|
4943
|
+
gasCosts,
|
4944
|
+
maxGasPerTx,
|
4945
|
+
gasPrice
|
4710
4946
|
});
|
4711
4947
|
return {
|
4712
4948
|
gqlTransaction,
|
@@ -4716,10 +4952,11 @@ async function getTransactionSummary(params) {
|
|
4716
4952
|
async function getTransactionSummaryFromRequest(params) {
|
4717
4953
|
const { provider, transactionRequest, abiMap } = params;
|
4718
4954
|
const { receipts } = await provider.call(transactionRequest);
|
4719
|
-
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4955
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
|
4720
4956
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4721
4957
|
const transaction = transactionRequest.toTransaction();
|
4722
4958
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4959
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4723
4960
|
const transactionSummary = assembleTransactionSummary({
|
4724
4961
|
receipts,
|
4725
4962
|
transaction,
|
@@ -4728,7 +4965,9 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4728
4965
|
gasPerByte,
|
4729
4966
|
gasPriceFactor,
|
4730
4967
|
maxInputs,
|
4731
|
-
gasCosts
|
4968
|
+
gasCosts,
|
4969
|
+
maxGasPerTx,
|
4970
|
+
gasPrice
|
4732
4971
|
});
|
4733
4972
|
return transactionSummary;
|
4734
4973
|
}
|
@@ -4737,24 +4976,31 @@ async function getTransactionsSummaries(params) {
|
|
4737
4976
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4738
4977
|
const { edges, pageInfo } = transactionsByOwner;
|
4739
4978
|
const {
|
4740
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4979
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4741
4980
|
} = provider.getChain();
|
4981
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4742
4982
|
const transactions = edges.map((edge) => {
|
4743
4983
|
const { node: gqlTransaction } = edge;
|
4744
|
-
const { id, rawPayload,
|
4745
|
-
const [decodedTransaction] = new
|
4746
|
-
|
4984
|
+
const { id, rawPayload, status } = gqlTransaction;
|
4985
|
+
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
|
4986
|
+
let txReceipts = [];
|
4987
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4988
|
+
txReceipts = gqlTransaction.status.receipts;
|
4989
|
+
}
|
4990
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4747
4991
|
const transactionSummary = assembleTransactionSummary({
|
4748
4992
|
id,
|
4749
4993
|
receipts,
|
4750
4994
|
transaction: decodedTransaction,
|
4751
|
-
transactionBytes: (0,
|
4995
|
+
transactionBytes: (0, import_utils25.arrayify)(rawPayload),
|
4752
4996
|
gqlTransactionStatus: status,
|
4753
4997
|
abiMap,
|
4754
4998
|
gasPerByte,
|
4755
4999
|
gasPriceFactor,
|
4756
5000
|
maxInputs,
|
4757
|
-
gasCosts
|
5001
|
+
gasCosts,
|
5002
|
+
maxGasPerTx,
|
5003
|
+
gasPrice
|
4758
5004
|
});
|
4759
5005
|
const output = {
|
4760
5006
|
gqlTransaction,
|
@@ -4891,17 +5137,17 @@ var assets = [
|
|
4891
5137
|
|
4892
5138
|
// src/utils/formatTransferToContractScriptData.ts
|
4893
5139
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4894
|
-
var
|
4895
|
-
var
|
5140
|
+
var import_math18 = require("@fuel-ts/math");
|
5141
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4896
5142
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4897
5143
|
var formatTransferToContractScriptData = (params) => {
|
4898
5144
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4899
5145
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4900
|
-
const encoded = numberCoder.encode(new
|
5146
|
+
const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
|
4901
5147
|
const scriptData = Uint8Array.from([
|
4902
|
-
...(0,
|
5148
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4903
5149
|
...encoded,
|
4904
|
-
...(0,
|
5150
|
+
...(0, import_utils26.arrayify)(assetId)
|
4905
5151
|
]);
|
4906
5152
|
return scriptData;
|
4907
5153
|
};
|
@@ -5086,36 +5332,33 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5086
5332
|
* @param fee - The estimated transaction fee.
|
5087
5333
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5088
5334
|
*/
|
5089
|
-
async fund(request,
|
5090
|
-
const
|
5091
|
-
|
5335
|
+
async fund(request, params) {
|
5336
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5337
|
+
const txRequest = request;
|
5338
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5339
|
+
amount: (0, import_math19.bn)(fee),
|
5092
5340
|
assetId: import_configs12.BaseAssetId,
|
5093
|
-
coinQuantities
|
5341
|
+
coinQuantities: requiredQuantities
|
5094
5342
|
});
|
5095
5343
|
const quantitiesDict = {};
|
5096
|
-
|
5344
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
5097
5345
|
quantitiesDict[assetId] = {
|
5098
5346
|
required: amount,
|
5099
|
-
owned: (0,
|
5347
|
+
owned: (0, import_math19.bn)(0)
|
5100
5348
|
};
|
5101
5349
|
});
|
5102
|
-
|
5103
|
-
const cachedMessages = [];
|
5104
|
-
const owner = this.address.toB256();
|
5105
|
-
request.inputs.forEach((input) => {
|
5350
|
+
txRequest.inputs.forEach((input) => {
|
5106
5351
|
const isResource = "amount" in input;
|
5107
5352
|
if (isResource) {
|
5108
5353
|
const isCoin2 = "owner" in input;
|
5109
5354
|
if (isCoin2) {
|
5110
5355
|
const assetId = String(input.assetId);
|
5111
|
-
if (
|
5112
|
-
const amount = (0,
|
5356
|
+
if (quantitiesDict[assetId]) {
|
5357
|
+
const amount = (0, import_math19.bn)(input.amount);
|
5113
5358
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5114
|
-
cachedUtxos.push(input.id);
|
5115
5359
|
}
|
5116
|
-
} else if (input.
|
5360
|
+
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5117
5361
|
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
5118
|
-
cachedMessages.push(input.nonce);
|
5119
5362
|
}
|
5120
5363
|
}
|
5121
5364
|
});
|
@@ -5130,12 +5373,23 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5130
5373
|
});
|
5131
5374
|
const needsToBeFunded = missingQuantities.length;
|
5132
5375
|
if (needsToBeFunded) {
|
5133
|
-
const
|
5134
|
-
|
5135
|
-
|
5136
|
-
|
5137
|
-
|
5376
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
5377
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
5378
|
+
txRequest.addResources(resources);
|
5379
|
+
}
|
5380
|
+
txRequest.shiftPredicateData();
|
5381
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5382
|
+
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
5383
|
+
if (addedSignatures) {
|
5384
|
+
Array.from({ length: addedSignatures }).forEach(
|
5385
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
5386
|
+
);
|
5138
5387
|
}
|
5388
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5389
|
+
transactionRequest: requestToBeReEstimate
|
5390
|
+
});
|
5391
|
+
txRequest.maxFee = maxFee;
|
5392
|
+
return txRequest;
|
5139
5393
|
}
|
5140
5394
|
/**
|
5141
5395
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5143,28 +5397,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5143
5397
|
* @param destination - The address of the destination.
|
5144
5398
|
* @param amount - The amount of coins to transfer.
|
5145
5399
|
* @param assetId - The asset ID of the coins to transfer.
|
5146
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5400
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
5147
5401
|
* @returns A promise that resolves to the prepared transaction request.
|
5148
5402
|
*/
|
5149
5403
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5150
|
-
const
|
5151
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5152
|
-
const request = new ScriptTransactionRequest(params);
|
5404
|
+
const request = new ScriptTransactionRequest(txParams);
|
5153
5405
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
5154
|
-
const
|
5406
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5155
5407
|
estimateTxDependencies: true,
|
5156
5408
|
resourcesOwner: this
|
5157
5409
|
});
|
5158
|
-
|
5159
|
-
|
5160
|
-
|
5161
|
-
|
5162
|
-
|
5163
|
-
|
5164
|
-
|
5165
|
-
|
5166
|
-
await this.fund(request,
|
5167
|
-
request.updatePredicateInputs(estimatedInputs);
|
5410
|
+
if ("gasLimit" in txParams) {
|
5411
|
+
this.validateGas({
|
5412
|
+
gasUsed: txCost.gasUsed,
|
5413
|
+
gasLimit: request.gasLimit
|
5414
|
+
});
|
5415
|
+
}
|
5416
|
+
request.gasLimit = txCost.gasUsed;
|
5417
|
+
request.maxFee = txCost.maxFee;
|
5418
|
+
await this.fund(request, txCost);
|
5168
5419
|
return request;
|
5169
5420
|
}
|
5170
5421
|
/**
|
@@ -5177,7 +5428,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5177
5428
|
* @returns A promise that resolves to the transaction response.
|
5178
5429
|
*/
|
5179
5430
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5180
|
-
if ((0,
|
5431
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
5181
5432
|
throw new import_errors16.FuelError(
|
5182
5433
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5183
5434
|
"Transfer amount must be a positive number."
|
@@ -5196,38 +5447,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5196
5447
|
* @returns A promise that resolves to the transaction response.
|
5197
5448
|
*/
|
5198
5449
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5199
|
-
if ((0,
|
5450
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
5200
5451
|
throw new import_errors16.FuelError(
|
5201
5452
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5202
5453
|
"Transfer amount must be a positive number."
|
5203
5454
|
);
|
5204
5455
|
}
|
5205
5456
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5206
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5207
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
5208
5457
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5209
5458
|
hexlifiedContractId: contractAddress.toB256(),
|
5210
|
-
amountToTransfer: (0,
|
5459
|
+
amountToTransfer: (0, import_math19.bn)(amount),
|
5211
5460
|
assetId
|
5212
5461
|
});
|
5213
5462
|
const request = new ScriptTransactionRequest({
|
5214
|
-
...
|
5463
|
+
...txParams,
|
5215
5464
|
script,
|
5216
5465
|
scriptData
|
5217
5466
|
});
|
5218
5467
|
request.addContractInputAndOutput(contractAddress);
|
5219
|
-
const
|
5220
|
-
|
5221
|
-
[{ amount: (0,
|
5222
|
-
);
|
5223
|
-
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5224
|
-
this.validateGas({
|
5225
|
-
gasUsed,
|
5226
|
-
gasPrice: request.gasPrice,
|
5227
|
-
gasLimit: request.gasLimit,
|
5228
|
-
minGasPrice
|
5468
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5469
|
+
resourcesOwner: this,
|
5470
|
+
quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
|
5229
5471
|
});
|
5230
|
-
|
5472
|
+
if (txParams.gasLimit) {
|
5473
|
+
this.validateGas({
|
5474
|
+
gasUsed: txCost.gasUsed,
|
5475
|
+
gasLimit: request.gasLimit
|
5476
|
+
});
|
5477
|
+
}
|
5478
|
+
request.gasLimit = txCost.gasUsed;
|
5479
|
+
request.maxFee = txCost.maxFee;
|
5480
|
+
await this.fund(request, txCost);
|
5231
5481
|
return this.sendTransaction(request);
|
5232
5482
|
}
|
5233
5483
|
/**
|
@@ -5239,34 +5489,31 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5239
5489
|
* @returns A promise that resolves to the transaction response.
|
5240
5490
|
*/
|
5241
5491
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5242
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5243
5492
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5244
|
-
const recipientDataArray = (0,
|
5493
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
5245
5494
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5246
5495
|
);
|
5247
|
-
const amountDataArray = (0,
|
5248
|
-
"0x".concat((0,
|
5496
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5497
|
+
"0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5249
5498
|
);
|
5250
5499
|
const script = new Uint8Array([
|
5251
|
-
...(0,
|
5500
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
5252
5501
|
...recipientDataArray,
|
5253
5502
|
...amountDataArray
|
5254
5503
|
]);
|
5255
|
-
const params = { script,
|
5504
|
+
const params = { script, ...txParams };
|
5256
5505
|
const request = new ScriptTransactionRequest(params);
|
5257
|
-
const
|
5258
|
-
const
|
5259
|
-
|
5260
|
-
|
5261
|
-
|
5262
|
-
|
5263
|
-
|
5264
|
-
|
5265
|
-
|
5266
|
-
|
5267
|
-
|
5268
|
-
});
|
5269
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5506
|
+
const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5507
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5508
|
+
if (txParams.gasLimit) {
|
5509
|
+
this.validateGas({
|
5510
|
+
gasUsed: txCost.gasUsed,
|
5511
|
+
gasLimit: request.gasLimit
|
5512
|
+
});
|
5513
|
+
}
|
5514
|
+
request.maxFee = txCost.maxFee;
|
5515
|
+
request.gasLimit = txCost.gasUsed;
|
5516
|
+
await this.fund(request, txCost);
|
5270
5517
|
return this.sendTransaction(request);
|
5271
5518
|
}
|
5272
5519
|
async signMessage(message) {
|
@@ -5324,18 +5571,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5324
5571
|
}
|
5325
5572
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5326
5573
|
}
|
5327
|
-
validateGas({
|
5328
|
-
gasUsed,
|
5329
|
-
gasPrice,
|
5330
|
-
gasLimit,
|
5331
|
-
minGasPrice
|
5332
|
-
}) {
|
5333
|
-
if (minGasPrice.gt(gasPrice)) {
|
5334
|
-
throw new import_errors16.FuelError(
|
5335
|
-
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
5336
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5337
|
-
);
|
5338
|
-
}
|
5574
|
+
validateGas({ gasUsed, gasLimit }) {
|
5339
5575
|
if (gasUsed.gt(gasLimit)) {
|
5340
5576
|
throw new import_errors16.FuelError(
|
5341
5577
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5347,14 +5583,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5347
5583
|
|
5348
5584
|
// src/wallet/base-wallet-unlocked.ts
|
5349
5585
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5350
|
-
var
|
5586
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5351
5587
|
|
5352
5588
|
// src/signer/signer.ts
|
5353
5589
|
var import_address5 = require("@fuel-ts/address");
|
5354
5590
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5355
5591
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5356
|
-
var
|
5357
|
-
var
|
5592
|
+
var import_math20 = require("@fuel-ts/math");
|
5593
|
+
var import_utils28 = require("@fuel-ts/utils");
|
5358
5594
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5359
5595
|
var Signer = class {
|
5360
5596
|
address;
|
@@ -5373,10 +5609,10 @@ var Signer = class {
|
|
5373
5609
|
privateKey = `0x${privateKey}`;
|
5374
5610
|
}
|
5375
5611
|
}
|
5376
|
-
const privateKeyBytes = (0,
|
5377
|
-
this.privateKey = (0,
|
5378
|
-
this.publicKey = (0,
|
5379
|
-
this.compressedPublicKey = (0,
|
5612
|
+
const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
|
5613
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5614
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5615
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5380
5616
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5381
5617
|
}
|
5382
5618
|
/**
|
@@ -5390,11 +5626,11 @@ var Signer = class {
|
|
5390
5626
|
* @returns hashed signature
|
5391
5627
|
*/
|
5392
5628
|
sign(data) {
|
5393
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5394
|
-
const r = (0,
|
5395
|
-
const s = (0,
|
5629
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5630
|
+
const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5631
|
+
const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5396
5632
|
s[0] |= (signature.recovery || 0) << 7;
|
5397
|
-
return (0,
|
5633
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
5398
5634
|
}
|
5399
5635
|
/**
|
5400
5636
|
* Add point on the current elliptic curve
|
@@ -5403,8 +5639,8 @@ var Signer = class {
|
|
5403
5639
|
* @returns compressed point on the curve
|
5404
5640
|
*/
|
5405
5641
|
addPoint(point) {
|
5406
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5407
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5642
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5643
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
5408
5644
|
const result = p0.add(p1);
|
5409
5645
|
return `0x${result.toHex(true)}`;
|
5410
5646
|
}
|
@@ -5416,16 +5652,16 @@ var Signer = class {
|
|
5416
5652
|
* @returns public key from signature from the
|
5417
5653
|
*/
|
5418
5654
|
static recoverPublicKey(data, signature) {
|
5419
|
-
const signedMessageBytes = (0,
|
5655
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5420
5656
|
const r = signedMessageBytes.slice(0, 32);
|
5421
5657
|
const s = signedMessageBytes.slice(32, 64);
|
5422
5658
|
const recoveryParam = (s[0] & 128) >> 7;
|
5423
5659
|
s[0] &= 127;
|
5424
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5660
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5425
5661
|
recoveryParam
|
5426
5662
|
);
|
5427
|
-
const publicKey = sig.recoverPublicKey((0,
|
5428
|
-
return (0,
|
5663
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5664
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5429
5665
|
}
|
5430
5666
|
/**
|
5431
5667
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5444,7 +5680,7 @@ var Signer = class {
|
|
5444
5680
|
* @returns random 32-byte hashed
|
5445
5681
|
*/
|
5446
5682
|
static generatePrivateKey(entropy) {
|
5447
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5683
|
+
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);
|
5448
5684
|
}
|
5449
5685
|
/**
|
5450
5686
|
* Extended publicKey from a compact publicKey
|
@@ -5453,8 +5689,8 @@ var Signer = class {
|
|
5453
5689
|
* @returns extended publicKey
|
5454
5690
|
*/
|
5455
5691
|
static extendPublicKey(publicKey) {
|
5456
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5457
|
-
return (0,
|
5692
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5693
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5458
5694
|
}
|
5459
5695
|
};
|
5460
5696
|
|
@@ -5462,7 +5698,7 @@ var Signer = class {
|
|
5462
5698
|
var import_address6 = require("@fuel-ts/address");
|
5463
5699
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5464
5700
|
var import_errors17 = require("@fuel-ts/errors");
|
5465
|
-
var
|
5701
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5466
5702
|
var import_uuid = require("uuid");
|
5467
5703
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5468
5704
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5545,7 +5781,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5545
5781
|
);
|
5546
5782
|
}
|
5547
5783
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5548
|
-
const privateKey = (0,
|
5784
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5549
5785
|
return privateKey;
|
5550
5786
|
}
|
5551
5787
|
|
@@ -5590,7 +5826,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5590
5826
|
*/
|
5591
5827
|
async signMessage(message) {
|
5592
5828
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5593
|
-
return (0,
|
5829
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5594
5830
|
}
|
5595
5831
|
/**
|
5596
5832
|
* Signs a transaction with the wallet's private key.
|
@@ -5603,7 +5839,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5603
5839
|
const chainId = this.provider.getChainId();
|
5604
5840
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5605
5841
|
const signature = await this.signer().sign(hashedTransaction);
|
5606
|
-
return (0,
|
5842
|
+
return (0, import_utils30.hexlify)(signature);
|
5607
5843
|
}
|
5608
5844
|
/**
|
5609
5845
|
* Populates a transaction with the witnesses signature.
|
@@ -5623,7 +5859,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5623
5859
|
* @param transactionRequestLike - The transaction request to send.
|
5624
5860
|
* @returns A promise that resolves to the TransactionResponse object.
|
5625
5861
|
*/
|
5626
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5862
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5627
5863
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5628
5864
|
if (estimateTxDependencies) {
|
5629
5865
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5664,15 +5900,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5664
5900
|
// src/hdwallet/hdwallet.ts
|
5665
5901
|
var import_errors20 = require("@fuel-ts/errors");
|
5666
5902
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5667
|
-
var
|
5668
|
-
var
|
5903
|
+
var import_math21 = require("@fuel-ts/math");
|
5904
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5669
5905
|
var import_ethers3 = require("ethers");
|
5670
5906
|
|
5671
5907
|
// src/mnemonic/mnemonic.ts
|
5672
5908
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5673
5909
|
var import_errors19 = require("@fuel-ts/errors");
|
5674
5910
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5675
|
-
var
|
5911
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5676
5912
|
var import_ethers2 = require("ethers");
|
5677
5913
|
|
5678
5914
|
// src/wordlists/words/english.ts
|
@@ -7736,7 +7972,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7736
7972
|
// src/mnemonic/utils.ts
|
7737
7973
|
var import_errors18 = require("@fuel-ts/errors");
|
7738
7974
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7739
|
-
var
|
7975
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7740
7976
|
function toUtf8Bytes(stri) {
|
7741
7977
|
const str = stri.normalize("NFKD");
|
7742
7978
|
const result = [];
|
@@ -7803,14 +8039,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7803
8039
|
}
|
7804
8040
|
}
|
7805
8041
|
const checksumBits = entropy.length / 4;
|
7806
|
-
const checksum = (0,
|
8042
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7807
8043
|
indices[indices.length - 1] <<= checksumBits;
|
7808
8044
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7809
8045
|
return indices;
|
7810
8046
|
}
|
7811
8047
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7812
8048
|
const size = Math.ceil(11 * words.length / 8);
|
7813
|
-
const entropy = (0,
|
8049
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7814
8050
|
let offset = 0;
|
7815
8051
|
for (let i = 0; i < words.length; i += 1) {
|
7816
8052
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7830,7 +8066,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7830
8066
|
const entropyBits = 32 * words.length / 3;
|
7831
8067
|
const checksumBits = words.length / 3;
|
7832
8068
|
const checksumMask = getUpperMask(checksumBits);
|
7833
|
-
const checksum = (0,
|
8069
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7834
8070
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7835
8071
|
throw new import_errors18.FuelError(
|
7836
8072
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7905,7 +8141,7 @@ var Mnemonic = class {
|
|
7905
8141
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7906
8142
|
const words = getWords(phrase);
|
7907
8143
|
assertMnemonic(words);
|
7908
|
-
return (0,
|
8144
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7909
8145
|
}
|
7910
8146
|
/**
|
7911
8147
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7913,7 +8149,7 @@ var Mnemonic = class {
|
|
7913
8149
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7914
8150
|
*/
|
7915
8151
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7916
|
-
const entropyBytes = (0,
|
8152
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7917
8153
|
assertWordList(wordlist);
|
7918
8154
|
assertEntropy(entropyBytes);
|
7919
8155
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7982,14 +8218,14 @@ var Mnemonic = class {
|
|
7982
8218
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7983
8219
|
*/
|
7984
8220
|
static masterKeysFromSeed(seed) {
|
7985
|
-
const seedArray = (0,
|
8221
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
7986
8222
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7987
8223
|
throw new import_errors19.FuelError(
|
7988
8224
|
import_errors19.ErrorCode.INVALID_SEED,
|
7989
8225
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7990
8226
|
);
|
7991
8227
|
}
|
7992
|
-
return (0,
|
8228
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7993
8229
|
}
|
7994
8230
|
/**
|
7995
8231
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8000,22 +8236,22 @@ var Mnemonic = class {
|
|
8000
8236
|
*/
|
8001
8237
|
static seedToExtendedKey(seed, testnet = false) {
|
8002
8238
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8003
|
-
const prefix = (0,
|
8239
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8004
8240
|
const depth = "0x00";
|
8005
8241
|
const fingerprint = "0x00000000";
|
8006
8242
|
const index = "0x00000000";
|
8007
8243
|
const chainCode = masterKey.slice(32);
|
8008
8244
|
const privateKey = masterKey.slice(0, 32);
|
8009
|
-
const extendedKey = (0,
|
8245
|
+
const extendedKey = (0, import_utils32.concat)([
|
8010
8246
|
prefix,
|
8011
8247
|
depth,
|
8012
8248
|
fingerprint,
|
8013
8249
|
index,
|
8014
8250
|
chainCode,
|
8015
|
-
(0,
|
8251
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
8016
8252
|
]);
|
8017
8253
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8018
|
-
return (0, import_ethers2.encodeBase58)((0,
|
8254
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
8019
8255
|
}
|
8020
8256
|
/**
|
8021
8257
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8030,7 +8266,7 @@ var Mnemonic = class {
|
|
8030
8266
|
* @returns A randomly generated mnemonic
|
8031
8267
|
*/
|
8032
8268
|
static generate(size = 32, extraEntropy = "") {
|
8033
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8269
|
+
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);
|
8034
8270
|
return Mnemonic.entropyToMnemonic(entropy);
|
8035
8271
|
}
|
8036
8272
|
};
|
@@ -8038,12 +8274,12 @@ var mnemonic_default = Mnemonic;
|
|
8038
8274
|
|
8039
8275
|
// src/hdwallet/hdwallet.ts
|
8040
8276
|
var HARDENED_INDEX = 2147483648;
|
8041
|
-
var MainnetPRV2 = (0,
|
8042
|
-
var MainnetPUB = (0,
|
8043
|
-
var TestnetPRV2 = (0,
|
8044
|
-
var TestnetPUB = (0,
|
8277
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
8278
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
8279
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
8280
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
8045
8281
|
function base58check(data) {
|
8046
|
-
return (0, import_ethers3.encodeBase58)((0,
|
8282
|
+
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)]));
|
8047
8283
|
}
|
8048
8284
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8049
8285
|
if (isPublic) {
|
@@ -8052,11 +8288,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8052
8288
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8053
8289
|
}
|
8054
8290
|
function isPublicExtendedKey(extendedKey) {
|
8055
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8291
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
8056
8292
|
}
|
8057
8293
|
function isValidExtendedKey(extendedKey) {
|
8058
8294
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8059
|
-
(0,
|
8295
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
8060
8296
|
);
|
8061
8297
|
}
|
8062
8298
|
function parsePath(path, depth = 0) {
|
@@ -8074,8 +8310,8 @@ function parsePath(path, depth = 0) {
|
|
8074
8310
|
var HDWallet = class {
|
8075
8311
|
depth = 0;
|
8076
8312
|
index = 0;
|
8077
|
-
fingerprint = (0,
|
8078
|
-
parentFingerprint = (0,
|
8313
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8314
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8079
8315
|
privateKey;
|
8080
8316
|
publicKey;
|
8081
8317
|
chainCode;
|
@@ -8087,8 +8323,8 @@ var HDWallet = class {
|
|
8087
8323
|
constructor(config) {
|
8088
8324
|
if (config.privateKey) {
|
8089
8325
|
const signer = new Signer(config.privateKey);
|
8090
|
-
this.publicKey = (0,
|
8091
|
-
this.privateKey = (0,
|
8326
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
8327
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
8092
8328
|
} else {
|
8093
8329
|
if (!config.publicKey) {
|
8094
8330
|
throw new import_errors20.FuelError(
|
@@ -8096,7 +8332,7 @@ var HDWallet = class {
|
|
8096
8332
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8097
8333
|
);
|
8098
8334
|
}
|
8099
|
-
this.publicKey = (0,
|
8335
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
8100
8336
|
}
|
8101
8337
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8102
8338
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -8115,9 +8351,9 @@ var HDWallet = class {
|
|
8115
8351
|
* @returns A new instance of HDWallet on the derived index
|
8116
8352
|
*/
|
8117
8353
|
deriveIndex(index) {
|
8118
|
-
const privateKey = this.privateKey && (0,
|
8119
|
-
const publicKey = (0,
|
8120
|
-
const chainCode = (0,
|
8354
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
8355
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
8356
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
8121
8357
|
const data = new Uint8Array(37);
|
8122
8358
|
if (index & HARDENED_INDEX) {
|
8123
8359
|
if (!privateKey) {
|
@@ -8128,15 +8364,15 @@ var HDWallet = class {
|
|
8128
8364
|
}
|
8129
8365
|
data.set(privateKey, 1);
|
8130
8366
|
} else {
|
8131
|
-
data.set((0,
|
8367
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
8132
8368
|
}
|
8133
|
-
data.set((0,
|
8134
|
-
const bytes = (0,
|
8369
|
+
data.set((0, import_math21.toBytes)(index, 4), 33);
|
8370
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
8135
8371
|
const IL = bytes.slice(0, 32);
|
8136
8372
|
const IR = bytes.slice(32);
|
8137
8373
|
if (privateKey) {
|
8138
8374
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8139
|
-
const ki = (0,
|
8375
|
+
const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8140
8376
|
return new HDWallet({
|
8141
8377
|
privateKey: ki,
|
8142
8378
|
chainCode: IR,
|
@@ -8145,7 +8381,7 @@ var HDWallet = class {
|
|
8145
8381
|
parentFingerprint: this.fingerprint
|
8146
8382
|
});
|
8147
8383
|
}
|
8148
|
-
const signer = new Signer((0,
|
8384
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
8149
8385
|
const Ki = signer.addPoint(publicKey);
|
8150
8386
|
return new HDWallet({
|
8151
8387
|
publicKey: Ki,
|
@@ -8180,12 +8416,12 @@ var HDWallet = class {
|
|
8180
8416
|
);
|
8181
8417
|
}
|
8182
8418
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8183
|
-
const depth = (0,
|
8419
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
8184
8420
|
const parentFingerprint = this.parentFingerprint;
|
8185
|
-
const index = (0,
|
8421
|
+
const index = (0, import_math21.toHex)(this.index, 4);
|
8186
8422
|
const chainCode = this.chainCode;
|
8187
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8188
|
-
const extendedKey = (0,
|
8423
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8424
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8189
8425
|
return base58check(extendedKey);
|
8190
8426
|
}
|
8191
8427
|
/**
|
@@ -8197,13 +8433,13 @@ var HDWallet = class {
|
|
8197
8433
|
static fromSeed(seed) {
|
8198
8434
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8199
8435
|
return new HDWallet({
|
8200
|
-
chainCode: (0,
|
8201
|
-
privateKey: (0,
|
8436
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
8437
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
8202
8438
|
});
|
8203
8439
|
}
|
8204
8440
|
static fromExtendedKey(extendedKey) {
|
8205
8441
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8206
|
-
const bytes = (0,
|
8442
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
8207
8443
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8208
8444
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8209
8445
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8212,9 +8448,9 @@ var HDWallet = class {
|
|
8212
8448
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8213
8449
|
}
|
8214
8450
|
const depth = bytes[4];
|
8215
|
-
const parentFingerprint = (0,
|
8216
|
-
const index = parseInt((0,
|
8217
|
-
const chainCode = (0,
|
8451
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8452
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8453
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
8218
8454
|
const key = bytes.slice(45, 78);
|
8219
8455
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8220
8456
|
throw new import_errors20.FuelError(
|
@@ -8819,19 +9055,19 @@ var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
|
8819
9055
|
var import_address10 = require("@fuel-ts/address");
|
8820
9056
|
var import_configs13 = require("@fuel-ts/address/configs");
|
8821
9057
|
var import_errors25 = require("@fuel-ts/errors");
|
8822
|
-
var
|
8823
|
-
var
|
9058
|
+
var import_transactions21 = require("@fuel-ts/transactions");
|
9059
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8824
9060
|
|
8825
9061
|
// src/predicate/utils/getPredicateRoot.ts
|
8826
9062
|
var import_hasher7 = require("@fuel-ts/hasher");
|
8827
9063
|
var import_merkle = require("@fuel-ts/merkle");
|
8828
|
-
var
|
9064
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8829
9065
|
var getPredicateRoot = (bytecode) => {
|
8830
9066
|
const chunkSize = 16 * 1024;
|
8831
|
-
const bytes = (0,
|
8832
|
-
const chunks = (0,
|
8833
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
8834
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
9067
|
+
const bytes = (0, import_utils35.arrayify)(bytecode);
|
9068
|
+
const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
|
9069
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
|
9070
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
|
8835
9071
|
return predicateRoot;
|
8836
9072
|
};
|
8837
9073
|
|
@@ -8879,9 +9115,9 @@ var Predicate = class extends Account {
|
|
8879
9115
|
const request = transactionRequestify(transactionRequestLike);
|
8880
9116
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8881
9117
|
request.inputs?.forEach((input) => {
|
8882
|
-
if (input.type ===
|
8883
|
-
input.predicate = this.bytes;
|
8884
|
-
input.predicateData = this.getPredicateData(policies.length);
|
9118
|
+
if (input.type === import_transactions21.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
|
9119
|
+
input.predicate = (0, import_utils36.hexlify)(this.bytes);
|
9120
|
+
input.predicateData = (0, import_utils36.hexlify)(this.getPredicateData(policies.length));
|
8885
9121
|
}
|
8886
9122
|
});
|
8887
9123
|
return request;
|
@@ -8896,8 +9132,7 @@ var Predicate = class extends Account {
|
|
8896
9132
|
* @returns A promise that resolves to the prepared transaction request.
|
8897
9133
|
*/
|
8898
9134
|
async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
|
8899
|
-
|
8900
|
-
return this.populateTransactionPredicateData(request);
|
9135
|
+
return super.createTransfer(destination, amount, assetId, txParams);
|
8901
9136
|
}
|
8902
9137
|
/**
|
8903
9138
|
* Sends a transaction with the populated predicate data.
|
@@ -8905,9 +9140,9 @@ var Predicate = class extends Account {
|
|
8905
9140
|
* @param transactionRequestLike - The transaction request-like object.
|
8906
9141
|
* @returns A promise that resolves to the transaction response.
|
8907
9142
|
*/
|
8908
|
-
sendTransaction(transactionRequestLike
|
8909
|
-
const transactionRequest =
|
8910
|
-
return super.sendTransaction(transactionRequest,
|
9143
|
+
sendTransaction(transactionRequestLike) {
|
9144
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9145
|
+
return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
|
8911
9146
|
}
|
8912
9147
|
/**
|
8913
9148
|
* Simulates a transaction with the populated predicate data.
|
@@ -8916,15 +9151,15 @@ var Predicate = class extends Account {
|
|
8916
9151
|
* @returns A promise that resolves to the call result.
|
8917
9152
|
*/
|
8918
9153
|
simulateTransaction(transactionRequestLike) {
|
8919
|
-
const transactionRequest =
|
8920
|
-
return super.simulateTransaction(transactionRequest);
|
9154
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9155
|
+
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
8921
9156
|
}
|
8922
9157
|
getPredicateData(policiesLength) {
|
8923
9158
|
if (!this.predicateData.length) {
|
8924
9159
|
return new Uint8Array();
|
8925
9160
|
}
|
8926
9161
|
const mainFn = this.interface?.functions.main;
|
8927
|
-
const paddedCode = new
|
9162
|
+
const paddedCode = new import_transactions21.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
8928
9163
|
const VM_TX_MEMORY = (0, import_abi_coder7.calculateVmTxMemory)({
|
8929
9164
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
8930
9165
|
});
|
@@ -8940,7 +9175,7 @@ var Predicate = class extends Account {
|
|
8940
9175
|
* @returns An object containing the new predicate bytes and interface.
|
8941
9176
|
*/
|
8942
9177
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
8943
|
-
let predicateBytes = (0,
|
9178
|
+
let predicateBytes = (0, import_utils36.arrayify)(bytes);
|
8944
9179
|
let abiInterface;
|
8945
9180
|
if (jsonAbi) {
|
8946
9181
|
abiInterface = new import_abi_coder7.Interface(jsonAbi);
|
@@ -8963,6 +9198,25 @@ var Predicate = class extends Account {
|
|
8963
9198
|
predicateInterface: abiInterface
|
8964
9199
|
};
|
8965
9200
|
}
|
9201
|
+
/**
|
9202
|
+
* Retrieves resources satisfying the spend query for the account.
|
9203
|
+
*
|
9204
|
+
* @param quantities - IDs of coins to exclude.
|
9205
|
+
* @param excludedIds - IDs of resources to be excluded from the query.
|
9206
|
+
* @returns A promise that resolves to an array of Resources.
|
9207
|
+
*/
|
9208
|
+
async getResourcesToSpend(quantities, excludedIds) {
|
9209
|
+
const resources = await this.provider.getResourcesToSpend(
|
9210
|
+
this.address,
|
9211
|
+
quantities,
|
9212
|
+
excludedIds
|
9213
|
+
);
|
9214
|
+
return resources.map((resource) => ({
|
9215
|
+
...resource,
|
9216
|
+
predicate: (0, import_utils36.hexlify)(this.bytes),
|
9217
|
+
paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
|
9218
|
+
}));
|
9219
|
+
}
|
8966
9220
|
/**
|
8967
9221
|
* Sets the configurable constants for the predicate.
|
8968
9222
|
*
|
@@ -9712,7 +9966,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9712
9966
|
WalletLocked,
|
9713
9967
|
WalletManager,
|
9714
9968
|
WalletUnlocked,
|
9715
|
-
|
9969
|
+
addAmountToCoinQuantities,
|
9716
9970
|
addOperation,
|
9717
9971
|
assemblePanicError,
|
9718
9972
|
assembleReceiptByType,
|
@@ -9721,9 +9975,10 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9721
9975
|
assets,
|
9722
9976
|
buildBlockExplorerUrl,
|
9723
9977
|
cacheFor,
|
9978
|
+
cacheTxInputsFromOwner,
|
9979
|
+
calculateGasFee,
|
9724
9980
|
calculateMetadataGasForTxCreate,
|
9725
9981
|
calculateMetadataGasForTxScript,
|
9726
|
-
calculatePriceWithFactor,
|
9727
9982
|
calculateTransactionFee,
|
9728
9983
|
coinQuantityfy,
|
9729
9984
|
deferPromise,
|