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