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