@fuel-ts/account 0.0.0-rc-1976-20240419101644 → 0.0.0-rc-2021-20240419145341
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +830 -604
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +833 -601
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +675 -444
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +906 -324
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +37 -34
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +9 -29
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1579 -1118
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +811 -600
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +667 -456
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/index.js
CHANGED
@@ -95,7 +95,7 @@ __export(src_exports, {
|
|
95
95
|
WalletLocked: () => WalletLocked,
|
96
96
|
WalletManager: () => WalletManager,
|
97
97
|
WalletUnlocked: () => WalletUnlocked,
|
98
|
-
|
98
|
+
addAmountToCoinQuantities: () => addAmountToCoinQuantities,
|
99
99
|
addOperation: () => addOperation,
|
100
100
|
assemblePanicError: () => assemblePanicError,
|
101
101
|
assembleReceiptByType: () => assembleReceiptByType,
|
@@ -104,9 +104,10 @@ __export(src_exports, {
|
|
104
104
|
assets: () => assets,
|
105
105
|
buildBlockExplorerUrl: () => buildBlockExplorerUrl,
|
106
106
|
cacheFor: () => cacheFor,
|
107
|
+
cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
|
108
|
+
calculateGasFee: () => calculateGasFee,
|
107
109
|
calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
|
108
110
|
calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
|
109
|
-
calculatePriceWithFactor: () => calculatePriceWithFactor,
|
110
111
|
calculateTransactionFee: () => calculateTransactionFee,
|
111
112
|
coinQuantityfy: () => coinQuantityfy,
|
112
113
|
deferPromise: () => deferPromise,
|
@@ -184,35 +185,38 @@ module.exports = __toCommonJS(src_exports);
|
|
184
185
|
|
185
186
|
// src/account.ts
|
186
187
|
var import_address4 = require("@fuel-ts/address");
|
188
|
+
var import_configs12 = require("@fuel-ts/address/configs");
|
187
189
|
var import_errors16 = require("@fuel-ts/errors");
|
188
190
|
var import_interfaces = require("@fuel-ts/interfaces");
|
189
|
-
var
|
190
|
-
var
|
191
|
+
var import_math19 = require("@fuel-ts/math");
|
192
|
+
var import_utils27 = require("@fuel-ts/utils");
|
193
|
+
var import_ramda4 = require("ramda");
|
191
194
|
|
192
195
|
// src/providers/coin-quantity.ts
|
196
|
+
var import_configs = require("@fuel-ts/address/configs");
|
193
197
|
var import_math = require("@fuel-ts/math");
|
194
198
|
var import_utils = require("@fuel-ts/utils");
|
195
199
|
var coinQuantityfy = (coinQuantityLike) => {
|
196
200
|
let assetId;
|
197
201
|
let amount;
|
198
|
-
let
|
202
|
+
let max;
|
199
203
|
if (Array.isArray(coinQuantityLike)) {
|
200
204
|
amount = coinQuantityLike[0];
|
201
|
-
assetId = coinQuantityLike[1];
|
202
|
-
|
205
|
+
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
206
|
+
max = coinQuantityLike[2] ?? void 0;
|
203
207
|
} else {
|
204
208
|
amount = coinQuantityLike.amount;
|
205
|
-
assetId = coinQuantityLike.assetId;
|
206
|
-
|
209
|
+
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
210
|
+
max = coinQuantityLike.max ?? void 0;
|
207
211
|
}
|
208
212
|
const bnAmount = (0, import_math.bn)(amount);
|
209
213
|
return {
|
210
214
|
assetId: (0, import_utils.hexlify)(assetId),
|
211
215
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
212
|
-
max:
|
216
|
+
max: max ? (0, import_math.bn)(max) : void 0
|
213
217
|
};
|
214
218
|
};
|
215
|
-
var
|
219
|
+
var addAmountToCoinQuantities = (params) => {
|
216
220
|
const { amount, assetId } = params;
|
217
221
|
const coinQuantities = [...params.coinQuantities];
|
218
222
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -227,11 +231,11 @@ var addAmountToAsset = (params) => {
|
|
227
231
|
// src/providers/provider.ts
|
228
232
|
var import_address3 = require("@fuel-ts/address");
|
229
233
|
var import_errors14 = require("@fuel-ts/errors");
|
230
|
-
var
|
231
|
-
var
|
232
|
-
var
|
234
|
+
var import_math16 = require("@fuel-ts/math");
|
235
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
236
|
+
var import_utils22 = require("@fuel-ts/utils");
|
233
237
|
var import_versions = require("@fuel-ts/versions");
|
234
|
-
var
|
238
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
235
239
|
var import_ethers = require("ethers");
|
236
240
|
var import_graphql_request = require("graphql-request");
|
237
241
|
var import_ramda3 = require("ramda");
|
@@ -240,14 +244,10 @@ var import_ramda3 = require("ramda");
|
|
240
244
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
241
245
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
242
246
|
fragment receiptFragment on Receipt {
|
243
|
-
|
244
|
-
id
|
245
|
-
}
|
247
|
+
id
|
246
248
|
pc
|
247
249
|
is
|
248
|
-
to
|
249
|
-
id
|
250
|
-
}
|
250
|
+
to
|
251
251
|
toAddress
|
252
252
|
amount
|
253
253
|
assetId
|
@@ -285,10 +285,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
285
285
|
id
|
286
286
|
}
|
287
287
|
time
|
288
|
+
receipts {
|
289
|
+
...receiptFragment
|
290
|
+
}
|
288
291
|
programState {
|
289
292
|
returnType
|
290
293
|
data
|
291
294
|
}
|
295
|
+
receipts {
|
296
|
+
...receiptFragment
|
297
|
+
}
|
292
298
|
}
|
293
299
|
... on FailureStatus {
|
294
300
|
block {
|
@@ -296,26 +302,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
296
302
|
}
|
297
303
|
time
|
298
304
|
reason
|
305
|
+
receipts {
|
306
|
+
...receiptFragment
|
307
|
+
}
|
299
308
|
}
|
300
309
|
... on SqueezedOutStatus {
|
301
310
|
reason
|
302
311
|
}
|
303
312
|
}
|
304
|
-
`;
|
313
|
+
${ReceiptFragmentFragmentDoc}`;
|
305
314
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
306
315
|
fragment transactionFragment on Transaction {
|
307
316
|
id
|
308
317
|
rawPayload
|
309
|
-
gasPrice
|
310
|
-
receipts {
|
311
|
-
...receiptFragment
|
312
|
-
}
|
313
318
|
status {
|
314
319
|
...transactionStatusFragment
|
315
320
|
}
|
316
321
|
}
|
317
|
-
${
|
318
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
322
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
319
323
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
320
324
|
fragment inputEstimatePredicatesFragment on Input {
|
321
325
|
... on InputCoin {
|
@@ -333,6 +337,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
333
337
|
}
|
334
338
|
}
|
335
339
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
340
|
+
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
341
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
342
|
+
reason
|
343
|
+
programState {
|
344
|
+
returnType
|
345
|
+
data
|
346
|
+
}
|
347
|
+
}
|
348
|
+
`;
|
349
|
+
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
350
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
351
|
+
programState {
|
352
|
+
returnType
|
353
|
+
data
|
354
|
+
}
|
355
|
+
}
|
356
|
+
`;
|
357
|
+
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
358
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
359
|
+
... on DryRunFailureStatus {
|
360
|
+
...dryRunFailureStatusFragment
|
361
|
+
}
|
362
|
+
... on DryRunSuccessStatus {
|
363
|
+
...dryRunSuccessStatusFragment
|
364
|
+
}
|
365
|
+
}
|
366
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
367
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
368
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
369
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
370
|
+
id
|
371
|
+
status {
|
372
|
+
...dryRunTransactionStatusFragment
|
373
|
+
}
|
374
|
+
receipts {
|
375
|
+
...receiptFragment
|
376
|
+
}
|
377
|
+
}
|
378
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
379
|
+
${ReceiptFragmentFragmentDoc}`;
|
336
380
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
337
381
|
fragment coinFragment on Coin {
|
338
382
|
__typename
|
@@ -340,7 +384,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
340
384
|
owner
|
341
385
|
amount
|
342
386
|
assetId
|
343
|
-
maturity
|
344
387
|
blockCreated
|
345
388
|
txCreatedIdx
|
346
389
|
}
|
@@ -379,26 +422,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
379
422
|
messageBlockHeader {
|
380
423
|
id
|
381
424
|
daHeight
|
425
|
+
consensusParametersVersion
|
426
|
+
stateTransitionBytecodeVersion
|
382
427
|
transactionsCount
|
428
|
+
messageReceiptCount
|
383
429
|
transactionsRoot
|
430
|
+
messageOutboxRoot
|
431
|
+
eventInboxRoot
|
384
432
|
height
|
385
433
|
prevRoot
|
386
434
|
time
|
387
435
|
applicationHash
|
388
|
-
messageReceiptRoot
|
389
|
-
messageReceiptCount
|
390
436
|
}
|
391
437
|
commitBlockHeader {
|
392
438
|
id
|
393
439
|
daHeight
|
440
|
+
consensusParametersVersion
|
441
|
+
stateTransitionBytecodeVersion
|
394
442
|
transactionsCount
|
443
|
+
messageReceiptCount
|
395
444
|
transactionsRoot
|
445
|
+
messageOutboxRoot
|
446
|
+
eventInboxRoot
|
396
447
|
height
|
397
448
|
prevRoot
|
398
449
|
time
|
399
450
|
applicationHash
|
400
|
-
messageReceiptRoot
|
401
|
-
messageReceiptCount
|
402
451
|
}
|
403
452
|
sender
|
404
453
|
recipient
|
@@ -417,8 +466,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
417
466
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
418
467
|
fragment blockFragment on Block {
|
419
468
|
id
|
469
|
+
height
|
420
470
|
header {
|
421
|
-
height
|
422
471
|
time
|
423
472
|
}
|
424
473
|
transactions {
|
@@ -476,6 +525,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
476
525
|
`;
|
477
526
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
478
527
|
fragment GasCostsFragment on GasCosts {
|
528
|
+
version {
|
529
|
+
... on Version {
|
530
|
+
value
|
531
|
+
}
|
532
|
+
}
|
479
533
|
add
|
480
534
|
addi
|
481
535
|
aloc
|
@@ -488,7 +542,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
488
542
|
cb
|
489
543
|
cfei
|
490
544
|
cfsi
|
491
|
-
croo
|
492
545
|
div
|
493
546
|
divi
|
494
547
|
ecr1
|
@@ -571,6 +624,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
571
624
|
ccp {
|
572
625
|
...DependentCostFragment
|
573
626
|
}
|
627
|
+
croo {
|
628
|
+
...DependentCostFragment
|
629
|
+
}
|
574
630
|
csiz {
|
575
631
|
...DependentCostFragment
|
576
632
|
}
|
@@ -630,6 +686,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
630
686
|
${DependentCostFragmentFragmentDoc}`;
|
631
687
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
632
688
|
fragment consensusParametersFragment on ConsensusParameters {
|
689
|
+
version {
|
690
|
+
... on Version {
|
691
|
+
value
|
692
|
+
}
|
693
|
+
}
|
633
694
|
txParams {
|
634
695
|
...TxParametersFragment
|
635
696
|
}
|
@@ -689,18 +750,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
689
750
|
fragment nodeInfoFragment on NodeInfo {
|
690
751
|
utxoValidation
|
691
752
|
vmBacktrace
|
692
|
-
minGasPrice
|
693
753
|
maxTx
|
694
754
|
maxDepth
|
695
755
|
nodeVersion
|
696
|
-
peers {
|
697
|
-
id
|
698
|
-
addresses
|
699
|
-
clientVersion
|
700
|
-
blockHeight
|
701
|
-
lastHeartbeatMs
|
702
|
-
appScore
|
703
|
-
}
|
704
756
|
}
|
705
757
|
`;
|
706
758
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -735,13 +787,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
735
787
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
736
788
|
transaction(id: $transactionId) {
|
737
789
|
...transactionFragment
|
738
|
-
receipts {
|
739
|
-
...receiptFragment
|
740
|
-
}
|
741
790
|
}
|
742
791
|
}
|
743
|
-
${TransactionFragmentFragmentDoc}
|
744
|
-
${ReceiptFragmentFragmentDoc}`;
|
792
|
+
${TransactionFragmentFragmentDoc}`;
|
745
793
|
var GetTransactionsDocument = import_graphql_tag.default`
|
746
794
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
747
795
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -869,6 +917,20 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
869
917
|
}
|
870
918
|
}
|
871
919
|
${BalanceFragmentFragmentDoc}`;
|
920
|
+
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
921
|
+
query getLatestGasPrice {
|
922
|
+
latestGasPrice {
|
923
|
+
gasPrice
|
924
|
+
}
|
925
|
+
}
|
926
|
+
`;
|
927
|
+
var EstimateGasPriceDocument = import_graphql_tag.default`
|
928
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
929
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
930
|
+
gasPrice
|
931
|
+
}
|
932
|
+
}
|
933
|
+
`;
|
872
934
|
var GetBalancesDocument = import_graphql_tag.default`
|
873
935
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
874
936
|
balances(
|
@@ -923,12 +985,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
923
985
|
}
|
924
986
|
`;
|
925
987
|
var DryRunDocument = import_graphql_tag.default`
|
926
|
-
mutation dryRun($
|
927
|
-
dryRun(
|
928
|
-
...
|
988
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
989
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
990
|
+
...dryRunTransactionExecutionStatusFragment
|
929
991
|
}
|
930
992
|
}
|
931
|
-
${
|
993
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
932
994
|
var SubmitDocument = import_graphql_tag.default`
|
933
995
|
mutation submit($encodedTransaction: HexString!) {
|
934
996
|
submit(tx: $encodedTransaction) {
|
@@ -1011,6 +1073,12 @@ function getSdk(requester) {
|
|
1011
1073
|
getBalance(variables, options) {
|
1012
1074
|
return requester(GetBalanceDocument, variables, options);
|
1013
1075
|
},
|
1076
|
+
getLatestGasPrice(variables, options) {
|
1077
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
1078
|
+
},
|
1079
|
+
estimateGasPrice(variables, options) {
|
1080
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
1081
|
+
},
|
1014
1082
|
getBalances(variables, options) {
|
1015
1083
|
return requester(GetBalancesDocument, variables, options);
|
1016
1084
|
},
|
@@ -1181,7 +1249,7 @@ var MemoryCache = class {
|
|
1181
1249
|
|
1182
1250
|
// src/providers/transaction-request/input.ts
|
1183
1251
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
1184
|
-
var
|
1252
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1185
1253
|
var import_errors3 = require("@fuel-ts/errors");
|
1186
1254
|
var import_math2 = require("@fuel-ts/math");
|
1187
1255
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1204,10 +1272,9 @@ var inputify = (value) => {
|
|
1204
1272
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1205
1273
|
},
|
1206
1274
|
witnessIndex: value.witnessIndex,
|
1207
|
-
maturity: value.maturity ?? 0,
|
1208
1275
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1209
|
-
predicateLength: predicate.length,
|
1210
|
-
predicateDataLength: predicateData.length,
|
1276
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1277
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1211
1278
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1212
1279
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1213
1280
|
};
|
@@ -1215,10 +1282,10 @@ var inputify = (value) => {
|
|
1215
1282
|
case import_transactions.InputType.Contract: {
|
1216
1283
|
return {
|
1217
1284
|
type: import_transactions.InputType.Contract,
|
1218
|
-
txID:
|
1285
|
+
txID: import_configs2.ZeroBytes32,
|
1219
1286
|
outputIndex: 0,
|
1220
|
-
balanceRoot:
|
1221
|
-
stateRoot:
|
1287
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1288
|
+
stateRoot: import_configs2.ZeroBytes32,
|
1222
1289
|
txPointer: {
|
1223
1290
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1224
1291
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1238,8 +1305,8 @@ var inputify = (value) => {
|
|
1238
1305
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1239
1306
|
witnessIndex: value.witnessIndex,
|
1240
1307
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1241
|
-
predicateLength: predicate.length,
|
1242
|
-
predicateDataLength: predicateData.length,
|
1308
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1309
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1243
1310
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1244
1311
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1245
1312
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1256,7 +1323,7 @@ var inputify = (value) => {
|
|
1256
1323
|
};
|
1257
1324
|
|
1258
1325
|
// src/providers/transaction-request/output.ts
|
1259
|
-
var
|
1326
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1260
1327
|
var import_errors4 = require("@fuel-ts/errors");
|
1261
1328
|
var import_math3 = require("@fuel-ts/math");
|
1262
1329
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1276,8 +1343,8 @@ var outputify = (value) => {
|
|
1276
1343
|
return {
|
1277
1344
|
type: import_transactions2.OutputType.Contract,
|
1278
1345
|
inputIndex: value.inputIndex,
|
1279
|
-
balanceRoot:
|
1280
|
-
stateRoot:
|
1346
|
+
balanceRoot: import_configs3.ZeroBytes32,
|
1347
|
+
stateRoot: import_configs3.ZeroBytes32
|
1281
1348
|
};
|
1282
1349
|
}
|
1283
1350
|
case import_transactions2.OutputType.Change: {
|
@@ -1291,9 +1358,9 @@ var outputify = (value) => {
|
|
1291
1358
|
case import_transactions2.OutputType.Variable: {
|
1292
1359
|
return {
|
1293
1360
|
type: import_transactions2.OutputType.Variable,
|
1294
|
-
to:
|
1361
|
+
to: import_configs3.ZeroBytes32,
|
1295
1362
|
amount: (0, import_math3.bn)(0),
|
1296
|
-
assetId:
|
1363
|
+
assetId: import_configs3.ZeroBytes32
|
1297
1364
|
};
|
1298
1365
|
}
|
1299
1366
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1315,7 +1382,7 @@ var outputify = (value) => {
|
|
1315
1382
|
// src/providers/transaction-request/transaction-request.ts
|
1316
1383
|
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
1317
1384
|
var import_address = require("@fuel-ts/address");
|
1318
|
-
var
|
1385
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
1319
1386
|
var import_crypto = require("@fuel-ts/crypto");
|
1320
1387
|
var import_math7 = require("@fuel-ts/math");
|
1321
1388
|
var import_transactions6 = require("@fuel-ts/transactions");
|
@@ -1328,13 +1395,13 @@ var isCoin = (resource) => "id" in resource;
|
|
1328
1395
|
var isMessage = (resource) => "recipient" in resource;
|
1329
1396
|
|
1330
1397
|
// src/providers/utils/receipts.ts
|
1331
|
-
var
|
1398
|
+
var import_configs4 = require("@fuel-ts/address/configs");
|
1332
1399
|
var import_errors5 = require("@fuel-ts/errors");
|
1333
1400
|
var import_math4 = require("@fuel-ts/math");
|
1334
1401
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1335
|
-
var
|
1402
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1336
1403
|
var import_utils5 = require("@fuel-ts/utils");
|
1337
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1404
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1338
1405
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1339
1406
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1340
1407
|
(memo, receipt) => {
|
@@ -1351,15 +1418,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1351
1418
|
missingOutputContractIds: []
|
1352
1419
|
}
|
1353
1420
|
);
|
1354
|
-
var hexOrZero = (hex) => hex ||
|
1421
|
+
var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
|
1355
1422
|
function assembleReceiptByType(receipt) {
|
1356
1423
|
const { receiptType } = receipt;
|
1357
1424
|
switch (receiptType) {
|
1358
1425
|
case "CALL" /* Call */: {
|
1359
1426
|
const callReceipt = {
|
1360
1427
|
type: import_transactions3.ReceiptType.Call,
|
1361
|
-
from: hexOrZero(receipt.
|
1362
|
-
to: hexOrZero(receipt?.to
|
1428
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1429
|
+
to: hexOrZero(receipt?.to),
|
1363
1430
|
amount: (0, import_math4.bn)(receipt.amount),
|
1364
1431
|
assetId: hexOrZero(receipt.assetId),
|
1365
1432
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1373,7 +1440,7 @@ function assembleReceiptByType(receipt) {
|
|
1373
1440
|
case "RETURN" /* Return */: {
|
1374
1441
|
const returnReceipt = {
|
1375
1442
|
type: import_transactions3.ReceiptType.Return,
|
1376
|
-
id: hexOrZero(receipt.
|
1443
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1377
1444
|
val: (0, import_math4.bn)(receipt.val),
|
1378
1445
|
pc: (0, import_math4.bn)(receipt.pc),
|
1379
1446
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1383,7 +1450,7 @@ function assembleReceiptByType(receipt) {
|
|
1383
1450
|
case "RETURN_DATA" /* ReturnData */: {
|
1384
1451
|
const returnDataReceipt = {
|
1385
1452
|
type: import_transactions3.ReceiptType.ReturnData,
|
1386
|
-
id: hexOrZero(receipt.
|
1453
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1387
1454
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1388
1455
|
len: (0, import_math4.bn)(receipt.len),
|
1389
1456
|
digest: hexOrZero(receipt.digest),
|
@@ -1395,7 +1462,7 @@ function assembleReceiptByType(receipt) {
|
|
1395
1462
|
case "PANIC" /* Panic */: {
|
1396
1463
|
const panicReceipt = {
|
1397
1464
|
type: import_transactions3.ReceiptType.Panic,
|
1398
|
-
id: hexOrZero(receipt.
|
1465
|
+
id: hexOrZero(receipt.id),
|
1399
1466
|
reason: (0, import_math4.bn)(receipt.reason),
|
1400
1467
|
pc: (0, import_math4.bn)(receipt.pc),
|
1401
1468
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1406,7 +1473,7 @@ function assembleReceiptByType(receipt) {
|
|
1406
1473
|
case "REVERT" /* Revert */: {
|
1407
1474
|
const revertReceipt = {
|
1408
1475
|
type: import_transactions3.ReceiptType.Revert,
|
1409
|
-
id: hexOrZero(receipt.
|
1476
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1410
1477
|
val: (0, import_math4.bn)(receipt.ra),
|
1411
1478
|
pc: (0, import_math4.bn)(receipt.pc),
|
1412
1479
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1416,7 +1483,7 @@ function assembleReceiptByType(receipt) {
|
|
1416
1483
|
case "LOG" /* Log */: {
|
1417
1484
|
const logReceipt = {
|
1418
1485
|
type: import_transactions3.ReceiptType.Log,
|
1419
|
-
id: hexOrZero(receipt.
|
1486
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1420
1487
|
val0: (0, import_math4.bn)(receipt.ra),
|
1421
1488
|
val1: (0, import_math4.bn)(receipt.rb),
|
1422
1489
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1429,7 +1496,7 @@ function assembleReceiptByType(receipt) {
|
|
1429
1496
|
case "LOG_DATA" /* LogData */: {
|
1430
1497
|
const logDataReceipt = {
|
1431
1498
|
type: import_transactions3.ReceiptType.LogData,
|
1432
|
-
id: hexOrZero(receipt.
|
1499
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1433
1500
|
val0: (0, import_math4.bn)(receipt.ra),
|
1434
1501
|
val1: (0, import_math4.bn)(receipt.rb),
|
1435
1502
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1443,8 +1510,8 @@ function assembleReceiptByType(receipt) {
|
|
1443
1510
|
case "TRANSFER" /* Transfer */: {
|
1444
1511
|
const transferReceipt = {
|
1445
1512
|
type: import_transactions3.ReceiptType.Transfer,
|
1446
|
-
from: hexOrZero(receipt.
|
1447
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1513
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1514
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1448
1515
|
amount: (0, import_math4.bn)(receipt.amount),
|
1449
1516
|
assetId: hexOrZero(receipt.assetId),
|
1450
1517
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1455,8 +1522,8 @@ function assembleReceiptByType(receipt) {
|
|
1455
1522
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1456
1523
|
const transferOutReceipt = {
|
1457
1524
|
type: import_transactions3.ReceiptType.TransferOut,
|
1458
|
-
from: hexOrZero(receipt.
|
1459
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1525
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1526
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1460
1527
|
amount: (0, import_math4.bn)(receipt.amount),
|
1461
1528
|
assetId: hexOrZero(receipt.assetId),
|
1462
1529
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1499,7 +1566,7 @@ function assembleReceiptByType(receipt) {
|
|
1499
1566
|
return receiptMessageOut;
|
1500
1567
|
}
|
1501
1568
|
case "MINT" /* Mint */: {
|
1502
|
-
const contractId = hexOrZero(receipt.
|
1569
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1503
1570
|
const subId = hexOrZero(receipt.subId);
|
1504
1571
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1505
1572
|
const mintReceipt = {
|
@@ -1514,7 +1581,7 @@ function assembleReceiptByType(receipt) {
|
|
1514
1581
|
return mintReceipt;
|
1515
1582
|
}
|
1516
1583
|
case "BURN" /* Burn */: {
|
1517
|
-
const contractId = hexOrZero(receipt.
|
1584
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1518
1585
|
const subId = hexOrZero(receipt.subId);
|
1519
1586
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1520
1587
|
const burnReceipt = {
|
@@ -1599,7 +1666,6 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1599
1666
|
var import_math5 = require("@fuel-ts/math");
|
1600
1667
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1601
1668
|
var import_utils6 = require("@fuel-ts/utils");
|
1602
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1603
1669
|
var getGasUsedFromReceipts = (receipts) => {
|
1604
1670
|
const scriptResult = receipts.filter(
|
1605
1671
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1620,18 +1686,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1620
1686
|
}
|
1621
1687
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1622
1688
|
const witnessCache = [];
|
1623
|
-
const
|
1689
|
+
const chargeableInputs = inputs.filter((input) => {
|
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) => {
|
1624
1704
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1625
1705
|
return total.add(
|
1626
|
-
|
1706
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1627
1707
|
);
|
1628
1708
|
}
|
1629
|
-
|
1630
|
-
|
1631
|
-
return total.add(gasCosts.ecr1);
|
1632
|
-
}
|
1633
|
-
return total;
|
1634
|
-
}, (0, import_math5.bn)());
|
1709
|
+
return total.add(gasCosts.ecr1);
|
1710
|
+
}, (0, import_math5.bn)(0));
|
1635
1711
|
return totalGas;
|
1636
1712
|
}
|
1637
1713
|
function getMinGas(params) {
|
@@ -1643,12 +1719,20 @@ function getMinGas(params) {
|
|
1643
1719
|
return minGas;
|
1644
1720
|
}
|
1645
1721
|
function getMaxGas(params) {
|
1646
|
-
const {
|
1722
|
+
const {
|
1723
|
+
gasPerByte,
|
1724
|
+
witnessesLength,
|
1725
|
+
witnessLimit,
|
1726
|
+
minGas,
|
1727
|
+
gasLimit = (0, import_math5.bn)(0),
|
1728
|
+
maxGasPerTx
|
1729
|
+
} = params;
|
1647
1730
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1648
1731
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1649
1732
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1650
1733
|
}
|
1651
|
-
|
1734
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1735
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1652
1736
|
}
|
1653
1737
|
function calculateMetadataGasForTxCreate({
|
1654
1738
|
gasCosts,
|
@@ -1670,6 +1754,10 @@ function calculateMetadataGasForTxScript({
|
|
1670
1754
|
}) {
|
1671
1755
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1672
1756
|
}
|
1757
|
+
var calculateGasFee = (params) => {
|
1758
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1759
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1760
|
+
};
|
1673
1761
|
|
1674
1762
|
// src/providers/utils/json.ts
|
1675
1763
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1715,16 +1803,16 @@ function sleep(time) {
|
|
1715
1803
|
var import_errors7 = require("@fuel-ts/errors");
|
1716
1804
|
var import_math6 = require("@fuel-ts/math");
|
1717
1805
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1718
|
-
var
|
1806
|
+
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1719
1807
|
var assemblePanicError = (status) => {
|
1720
1808
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1721
1809
|
const reason = status.reason;
|
1722
|
-
if (
|
1810
|
+
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1723
1811
|
errorMessage = `${errorMessage}
|
1724
1812
|
|
1725
1813
|
You can read more about this error at:
|
1726
1814
|
|
1727
|
-
${
|
1815
|
+
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1728
1816
|
}
|
1729
1817
|
return { errorMessage, reason };
|
1730
1818
|
};
|
@@ -1736,28 +1824,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1736
1824
|
if (revertReceipt) {
|
1737
1825
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1738
1826
|
switch (reasonHex) {
|
1739
|
-
case
|
1827
|
+
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1740
1828
|
reason = "require";
|
1741
1829
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1742
1830
|
break;
|
1743
1831
|
}
|
1744
|
-
case
|
1832
|
+
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1745
1833
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1746
1834
|
reason = "assert_eq";
|
1747
1835
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1748
1836
|
break;
|
1749
1837
|
}
|
1750
|
-
case
|
1838
|
+
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1751
1839
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1752
1840
|
reason = "assert_ne";
|
1753
1841
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1754
1842
|
break;
|
1755
1843
|
}
|
1756
|
-
case
|
1844
|
+
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1757
1845
|
reason = "assert";
|
1758
1846
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1759
1847
|
break;
|
1760
|
-
case
|
1848
|
+
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1761
1849
|
reason = "MissingOutputChange";
|
1762
1850
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1763
1851
|
break;
|
@@ -1818,7 +1906,7 @@ var witnessify = (value) => {
|
|
1818
1906
|
// src/providers/transaction-request/transaction-request.ts
|
1819
1907
|
var BaseTransactionRequest = class {
|
1820
1908
|
/** Gas price for transaction */
|
1821
|
-
|
1909
|
+
tip;
|
1822
1910
|
/** Block until which tx cannot be included */
|
1823
1911
|
maturity;
|
1824
1912
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1831,38 +1919,34 @@ var BaseTransactionRequest = class {
|
|
1831
1919
|
outputs = [];
|
1832
1920
|
/** List of witnesses */
|
1833
1921
|
witnesses = [];
|
1834
|
-
/** Base asset ID - should be fetched from the chain */
|
1835
|
-
baseAssetId;
|
1836
1922
|
/**
|
1837
1923
|
* Constructor for initializing a base transaction request.
|
1838
1924
|
*
|
1839
1925
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1840
1926
|
*/
|
1841
1927
|
constructor({
|
1842
|
-
|
1928
|
+
tip,
|
1843
1929
|
maturity,
|
1844
1930
|
maxFee,
|
1845
1931
|
witnessLimit,
|
1846
1932
|
inputs,
|
1847
1933
|
outputs,
|
1848
|
-
witnesses
|
1849
|
-
|
1850
|
-
|
1851
|
-
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1934
|
+
witnesses
|
1935
|
+
} = {}) {
|
1936
|
+
this.tip = (0, import_math7.bn)(tip);
|
1852
1937
|
this.maturity = maturity ?? 0;
|
1853
1938
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1854
1939
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1855
1940
|
this.inputs = inputs ?? [];
|
1856
1941
|
this.outputs = outputs ?? [];
|
1857
1942
|
this.witnesses = witnesses ?? [];
|
1858
|
-
this.baseAssetId = baseAssetId;
|
1859
1943
|
}
|
1860
1944
|
static getPolicyMeta(req) {
|
1861
1945
|
let policyTypes = 0;
|
1862
1946
|
const policies = [];
|
1863
|
-
if (req.
|
1864
|
-
policyTypes += import_transactions6.PolicyType.
|
1865
|
-
policies.push({ data: req.
|
1947
|
+
if (req.tip) {
|
1948
|
+
policyTypes += import_transactions6.PolicyType.Tip;
|
1949
|
+
policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
|
1866
1950
|
}
|
1867
1951
|
if (req.witnessLimit) {
|
1868
1952
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -1948,7 +2032,7 @@ var BaseTransactionRequest = class {
|
|
1948
2032
|
* @returns The index of the created witness.
|
1949
2033
|
*/
|
1950
2034
|
addEmptyWitness() {
|
1951
|
-
this.addWitness((0, import_utils9.concat)([
|
2035
|
+
this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
|
1952
2036
|
return this.witnesses.length - 1;
|
1953
2037
|
}
|
1954
2038
|
/**
|
@@ -2049,10 +2133,10 @@ var BaseTransactionRequest = class {
|
|
2049
2133
|
* @param predicate - Predicate bytes.
|
2050
2134
|
* @param predicateData - Predicate data bytes.
|
2051
2135
|
*/
|
2052
|
-
addCoinInput(coin
|
2136
|
+
addCoinInput(coin) {
|
2053
2137
|
const { assetId, owner, amount } = coin;
|
2054
2138
|
let witnessIndex;
|
2055
|
-
if (predicate) {
|
2139
|
+
if (coin.predicate) {
|
2056
2140
|
witnessIndex = 0;
|
2057
2141
|
} else {
|
2058
2142
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2067,8 +2151,7 @@ var BaseTransactionRequest = class {
|
|
2067
2151
|
amount,
|
2068
2152
|
assetId,
|
2069
2153
|
txPointer: "0x00000000000000000000000000000000",
|
2070
|
-
witnessIndex
|
2071
|
-
predicate: predicate?.bytes
|
2154
|
+
witnessIndex
|
2072
2155
|
};
|
2073
2156
|
this.pushInput(input);
|
2074
2157
|
this.addChangeOutput(owner, assetId);
|
@@ -2079,11 +2162,13 @@ var BaseTransactionRequest = class {
|
|
2079
2162
|
*
|
2080
2163
|
* @param message - Message resource.
|
2081
2164
|
* @param predicate - Predicate bytes.
|
2165
|
+
* @param predicateData - Predicate data bytes.
|
2082
2166
|
*/
|
2083
|
-
addMessageInput(message
|
2167
|
+
addMessageInput(message) {
|
2084
2168
|
const { recipient, sender, amount } = message;
|
2169
|
+
const assetId = import_configs7.BaseAssetId;
|
2085
2170
|
let witnessIndex;
|
2086
|
-
if (predicate) {
|
2171
|
+
if (message.predicate) {
|
2087
2172
|
witnessIndex = 0;
|
2088
2173
|
} else {
|
2089
2174
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2097,11 +2182,10 @@ var BaseTransactionRequest = class {
|
|
2097
2182
|
sender: sender.toB256(),
|
2098
2183
|
recipient: recipient.toB256(),
|
2099
2184
|
amount,
|
2100
|
-
witnessIndex
|
2101
|
-
predicate: predicate?.bytes
|
2185
|
+
witnessIndex
|
2102
2186
|
};
|
2103
2187
|
this.pushInput(input);
|
2104
|
-
this.addChangeOutput(recipient,
|
2188
|
+
this.addChangeOutput(recipient, assetId);
|
2105
2189
|
}
|
2106
2190
|
/**
|
2107
2191
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2129,32 +2213,6 @@ var BaseTransactionRequest = class {
|
|
2129
2213
|
resources.forEach((resource) => this.addResource(resource));
|
2130
2214
|
return this;
|
2131
2215
|
}
|
2132
|
-
/**
|
2133
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
2134
|
-
* outputs from the related assetIds.
|
2135
|
-
*
|
2136
|
-
* @param resources - The resources to add.
|
2137
|
-
* @returns This transaction.
|
2138
|
-
*/
|
2139
|
-
addPredicateResource(resource, predicate) {
|
2140
|
-
if (isCoin(resource)) {
|
2141
|
-
this.addCoinInput(resource, predicate);
|
2142
|
-
} else {
|
2143
|
-
this.addMessageInput(resource, predicate);
|
2144
|
-
}
|
2145
|
-
return this;
|
2146
|
-
}
|
2147
|
-
/**
|
2148
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2149
|
-
* from the related assetIds.
|
2150
|
-
*
|
2151
|
-
* @param resources - The resources to add.
|
2152
|
-
* @returns This transaction.
|
2153
|
-
*/
|
2154
|
-
addPredicateResources(resources, predicate) {
|
2155
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2156
|
-
return this;
|
2157
|
-
}
|
2158
2216
|
/**
|
2159
2217
|
* Adds a coin output to the transaction.
|
2160
2218
|
*
|
@@ -2162,12 +2220,12 @@ var BaseTransactionRequest = class {
|
|
2162
2220
|
* @param amount - Amount of coin.
|
2163
2221
|
* @param assetId - Asset ID of coin.
|
2164
2222
|
*/
|
2165
|
-
addCoinOutput(to, amount, assetId) {
|
2223
|
+
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
2166
2224
|
this.pushOutput({
|
2167
2225
|
type: import_transactions6.OutputType.Coin,
|
2168
2226
|
to: (0, import_address.addressify)(to).toB256(),
|
2169
2227
|
amount,
|
2170
|
-
assetId
|
2228
|
+
assetId
|
2171
2229
|
});
|
2172
2230
|
return this;
|
2173
2231
|
}
|
@@ -2194,7 +2252,7 @@ var BaseTransactionRequest = class {
|
|
2194
2252
|
* @param to - Address of the owner.
|
2195
2253
|
* @param assetId - Asset ID of coin.
|
2196
2254
|
*/
|
2197
|
-
addChangeOutput(to, assetId) {
|
2255
|
+
addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
|
2198
2256
|
const changeOutput = this.getChangeOutputs().find(
|
2199
2257
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
2200
2258
|
);
|
@@ -2202,7 +2260,7 @@ var BaseTransactionRequest = class {
|
|
2202
2260
|
this.pushOutput({
|
2203
2261
|
type: import_transactions6.OutputType.Change,
|
2204
2262
|
to: (0, import_address.addressify)(to).toB256(),
|
2205
|
-
assetId
|
2263
|
+
assetId
|
2206
2264
|
});
|
2207
2265
|
}
|
2208
2266
|
}
|
@@ -2234,7 +2292,7 @@ var BaseTransactionRequest = class {
|
|
2234
2292
|
}
|
2235
2293
|
calculateMaxGas(chainInfo, minGas) {
|
2236
2294
|
const { consensusParameters } = chainInfo;
|
2237
|
-
const { gasPerByte } = consensusParameters;
|
2295
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2238
2296
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2239
2297
|
(acc, wit) => acc + wit.dataLength,
|
2240
2298
|
0
|
@@ -2243,7 +2301,8 @@ var BaseTransactionRequest = class {
|
|
2243
2301
|
gasPerByte,
|
2244
2302
|
minGas,
|
2245
2303
|
witnessesLength,
|
2246
|
-
witnessLimit: this.witnessLimit
|
2304
|
+
witnessLimit: this.witnessLimit,
|
2305
|
+
maxGasPerTx
|
2247
2306
|
});
|
2248
2307
|
}
|
2249
2308
|
/**
|
@@ -2261,24 +2320,27 @@ var BaseTransactionRequest = class {
|
|
2261
2320
|
});
|
2262
2321
|
const updateAssetInput = (assetId, quantity) => {
|
2263
2322
|
const assetInput = findAssetInput(assetId);
|
2323
|
+
let usedQuantity = quantity;
|
2324
|
+
if (assetId === import_configs7.BaseAssetId) {
|
2325
|
+
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2326
|
+
}
|
2264
2327
|
if (assetInput && "assetId" in assetInput) {
|
2265
2328
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2266
|
-
assetInput.amount =
|
2329
|
+
assetInput.amount = usedQuantity;
|
2267
2330
|
} else {
|
2268
2331
|
this.addResources([
|
2269
2332
|
{
|
2270
2333
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2271
|
-
amount:
|
2334
|
+
amount: usedQuantity,
|
2272
2335
|
assetId,
|
2273
2336
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2274
|
-
maturity: 0,
|
2275
2337
|
blockCreated: (0, import_math7.bn)(1),
|
2276
2338
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2277
2339
|
}
|
2278
2340
|
]);
|
2279
2341
|
}
|
2280
2342
|
};
|
2281
|
-
updateAssetInput(
|
2343
|
+
updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
|
2282
2344
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2283
2345
|
}
|
2284
2346
|
/**
|
@@ -2303,7 +2365,7 @@ var BaseTransactionRequest = class {
|
|
2303
2365
|
toJSON() {
|
2304
2366
|
return normalizeJSON(this);
|
2305
2367
|
}
|
2306
|
-
|
2368
|
+
updatePredicateGasUsed(inputs) {
|
2307
2369
|
this.inputs.forEach((i) => {
|
2308
2370
|
let correspondingInput;
|
2309
2371
|
switch (i.type) {
|
@@ -2325,16 +2387,25 @@ var BaseTransactionRequest = class {
|
|
2325
2387
|
}
|
2326
2388
|
});
|
2327
2389
|
}
|
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
|
+
}
|
2328
2399
|
};
|
2329
2400
|
|
2330
2401
|
// src/providers/transaction-request/create-transaction-request.ts
|
2331
|
-
var
|
2402
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2332
2403
|
var import_math9 = require("@fuel-ts/math");
|
2333
2404
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2334
2405
|
var import_utils13 = require("@fuel-ts/utils");
|
2335
2406
|
|
2336
2407
|
// src/providers/transaction-request/hash-transaction.ts
|
2337
|
-
var
|
2408
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2338
2409
|
var import_hasher = require("@fuel-ts/hasher");
|
2339
2410
|
var import_math8 = require("@fuel-ts/math");
|
2340
2411
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2343,7 +2414,7 @@ var import_ramda2 = require("ramda");
|
|
2343
2414
|
function hashTransaction(transactionRequest, chainId) {
|
2344
2415
|
const transaction = transactionRequest.toTransaction();
|
2345
2416
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2346
|
-
transaction.receiptsRoot =
|
2417
|
+
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2347
2418
|
}
|
2348
2419
|
transaction.inputs = transaction.inputs.map((input) => {
|
2349
2420
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2365,10 +2436,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2365
2436
|
blockHeight: 0,
|
2366
2437
|
txIndex: 0
|
2367
2438
|
};
|
2368
|
-
inputClone.txID =
|
2439
|
+
inputClone.txID = import_configs8.ZeroBytes32;
|
2369
2440
|
inputClone.outputIndex = 0;
|
2370
|
-
inputClone.balanceRoot =
|
2371
|
-
inputClone.stateRoot =
|
2441
|
+
inputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2442
|
+
inputClone.stateRoot = import_configs8.ZeroBytes32;
|
2372
2443
|
return inputClone;
|
2373
2444
|
}
|
2374
2445
|
default:
|
@@ -2379,8 +2450,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2379
2450
|
const outputClone = (0, import_ramda2.clone)(output);
|
2380
2451
|
switch (outputClone.type) {
|
2381
2452
|
case import_transactions7.OutputType.Contract: {
|
2382
|
-
outputClone.balanceRoot =
|
2383
|
-
outputClone.stateRoot =
|
2453
|
+
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2454
|
+
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2384
2455
|
return outputClone;
|
2385
2456
|
}
|
2386
2457
|
case import_transactions7.OutputType.Change: {
|
@@ -2388,9 +2459,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2388
2459
|
return outputClone;
|
2389
2460
|
}
|
2390
2461
|
case import_transactions7.OutputType.Variable: {
|
2391
|
-
outputClone.to =
|
2462
|
+
outputClone.to = import_configs8.ZeroBytes32;
|
2392
2463
|
outputClone.amount = (0, import_math8.bn)(0);
|
2393
|
-
outputClone.assetId =
|
2464
|
+
outputClone.assetId = import_configs8.ZeroBytes32;
|
2394
2465
|
return outputClone;
|
2395
2466
|
}
|
2396
2467
|
default:
|
@@ -2448,10 +2519,15 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2448
2519
|
*
|
2449
2520
|
* @param createTransactionRequestLike - The initial values for the instance
|
2450
2521
|
*/
|
2451
|
-
constructor({
|
2522
|
+
constructor({
|
2523
|
+
bytecodeWitnessIndex,
|
2524
|
+
salt,
|
2525
|
+
storageSlots,
|
2526
|
+
...rest
|
2527
|
+
} = {}) {
|
2452
2528
|
super(rest);
|
2453
2529
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2454
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2530
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
|
2455
2531
|
this.storageSlots = [...storageSlots ?? []];
|
2456
2532
|
}
|
2457
2533
|
/**
|
@@ -2466,10 +2542,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2466
2542
|
return {
|
2467
2543
|
type: import_transactions8.TransactionType.Create,
|
2468
2544
|
...baseTransaction,
|
2469
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2470
2545
|
bytecodeWitnessIndex,
|
2471
|
-
storageSlotsCount: storageSlots.length,
|
2472
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2546
|
+
storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
|
2547
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2473
2548
|
storageSlots
|
2474
2549
|
};
|
2475
2550
|
}
|
@@ -2519,7 +2594,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2519
2594
|
// src/providers/transaction-request/script-transaction-request.ts
|
2520
2595
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
2521
2596
|
var import_address2 = require("@fuel-ts/address");
|
2522
|
-
var
|
2597
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2523
2598
|
var import_math10 = require("@fuel-ts/math");
|
2524
2599
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2525
2600
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2572,7 +2647,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2572
2647
|
*
|
2573
2648
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2574
2649
|
*/
|
2575
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2650
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2576
2651
|
super(rest);
|
2577
2652
|
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2578
2653
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
@@ -2591,9 +2666,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2591
2666
|
type: import_transactions9.TransactionType.Script,
|
2592
2667
|
scriptGasLimit: this.gasLimit,
|
2593
2668
|
...super.getBaseTransaction(),
|
2594
|
-
scriptLength: script.length,
|
2595
|
-
scriptDataLength: scriptData.length,
|
2596
|
-
receiptsRoot:
|
2669
|
+
scriptLength: (0, import_math10.bn)(script.length),
|
2670
|
+
scriptDataLength: (0, import_math10.bn)(scriptData.length),
|
2671
|
+
receiptsRoot: import_configs10.ZeroBytes32,
|
2597
2672
|
script: (0, import_utils15.hexlify)(script),
|
2598
2673
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2599
2674
|
};
|
@@ -2656,7 +2731,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2656
2731
|
}
|
2657
2732
|
calculateMaxGas(chainInfo, minGas) {
|
2658
2733
|
const { consensusParameters } = chainInfo;
|
2659
|
-
const { gasPerByte } = consensusParameters;
|
2734
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2660
2735
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2661
2736
|
(acc, wit) => acc + wit.dataLength,
|
2662
2737
|
0
|
@@ -2666,7 +2741,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2666
2741
|
minGas,
|
2667
2742
|
witnessesLength,
|
2668
2743
|
witnessLimit: this.witnessLimit,
|
2669
|
-
gasLimit: this.gasLimit
|
2744
|
+
gasLimit: this.gasLimit,
|
2745
|
+
maxGasPerTx
|
2670
2746
|
});
|
2671
2747
|
}
|
2672
2748
|
/**
|
@@ -2741,15 +2817,32 @@ var transactionRequestify = (obj) => {
|
|
2741
2817
|
}
|
2742
2818
|
}
|
2743
2819
|
};
|
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
|
+
);
|
2744
2835
|
|
2745
2836
|
// src/providers/transaction-response/transaction-response.ts
|
2746
2837
|
var import_errors13 = require("@fuel-ts/errors");
|
2747
|
-
var
|
2748
|
-
var
|
2749
|
-
var
|
2838
|
+
var import_math15 = require("@fuel-ts/math");
|
2839
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
2840
|
+
var import_utils20 = require("@fuel-ts/utils");
|
2750
2841
|
|
2751
2842
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2752
|
-
var
|
2843
|
+
var import_math14 = require("@fuel-ts/math");
|
2844
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2845
|
+
var import_utils18 = require("@fuel-ts/utils");
|
2753
2846
|
|
2754
2847
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2755
2848
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2757,9 +2850,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2757
2850
|
var import_utils16 = require("@fuel-ts/utils");
|
2758
2851
|
var calculateTransactionFee = (params) => {
|
2759
2852
|
const {
|
2760
|
-
|
2853
|
+
gasPrice,
|
2761
2854
|
rawPayload,
|
2762
|
-
|
2855
|
+
tip,
|
2856
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2763
2857
|
} = params;
|
2764
2858
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2765
2859
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2769,8 +2863,7 @@ var calculateTransactionFee = (params) => {
|
|
2769
2863
|
return {
|
2770
2864
|
fee: (0, import_math11.bn)(0),
|
2771
2865
|
minFee: (0, import_math11.bn)(0),
|
2772
|
-
maxFee: (0, import_math11.bn)(0)
|
2773
|
-
feeFromGasUsed: (0, import_math11.bn)(0)
|
2866
|
+
maxFee: (0, import_math11.bn)(0)
|
2774
2867
|
};
|
2775
2868
|
}
|
2776
2869
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2802,7 +2895,6 @@ var calculateTransactionFee = (params) => {
|
|
2802
2895
|
metadataGas,
|
2803
2896
|
txBytesSize: transactionBytes.length
|
2804
2897
|
});
|
2805
|
-
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2806
2898
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2807
2899
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2808
2900
|
const maxGas = getMaxGas({
|
@@ -2810,22 +2902,30 @@ var calculateTransactionFee = (params) => {
|
|
2810
2902
|
minGas,
|
2811
2903
|
witnessesLength,
|
2812
2904
|
gasLimit,
|
2813
|
-
witnessLimit
|
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
|
2814
2919
|
});
|
2815
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2816
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2817
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2818
|
-
const fee = minFee.add(feeFromGasUsed);
|
2819
2920
|
return {
|
2820
|
-
fee,
|
2821
2921
|
minFee,
|
2822
2922
|
maxFee,
|
2823
|
-
|
2923
|
+
fee: maxFee
|
2824
2924
|
};
|
2825
2925
|
};
|
2826
2926
|
|
2827
2927
|
// src/providers/transaction-summary/operations.ts
|
2828
|
-
var
|
2928
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
2829
2929
|
var import_errors11 = require("@fuel-ts/errors");
|
2830
2930
|
var import_math13 = require("@fuel-ts/math");
|
2831
2931
|
var import_transactions14 = require("@fuel-ts/transactions");
|
@@ -3170,7 +3270,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3170
3270
|
const { to: toAddress, assetId, amount } = receipt;
|
3171
3271
|
let { from: fromAddress } = receipt;
|
3172
3272
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3173
|
-
if (
|
3273
|
+
if (import_configs11.ZeroBytes32 === fromAddress) {
|
3174
3274
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3175
3275
|
fromAddress = change?.to || fromAddress;
|
3176
3276
|
}
|
@@ -3434,10 +3534,12 @@ function assembleTransactionSummary(params) {
|
|
3434
3534
|
gqlTransactionStatus,
|
3435
3535
|
abiMap = {},
|
3436
3536
|
maxInputs,
|
3437
|
-
gasCosts
|
3537
|
+
gasCosts,
|
3538
|
+
maxGasPerTx,
|
3539
|
+
gasPrice
|
3438
3540
|
} = params;
|
3439
3541
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3440
|
-
const rawPayload = (0,
|
3542
|
+
const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
|
3441
3543
|
const operations = getOperations({
|
3442
3544
|
transactionType: transaction.type,
|
3443
3545
|
inputs: transaction.inputs || [],
|
@@ -3448,11 +3550,14 @@ function assembleTransactionSummary(params) {
|
|
3448
3550
|
maxInputs
|
3449
3551
|
});
|
3450
3552
|
const typeName = getTransactionTypeName(transaction.type);
|
3553
|
+
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3451
3554
|
const { fee } = calculateTransactionFee({
|
3452
|
-
|
3555
|
+
gasPrice,
|
3453
3556
|
rawPayload,
|
3557
|
+
tip,
|
3454
3558
|
consensusParameters: {
|
3455
3559
|
gasCosts,
|
3560
|
+
maxGasPerTx,
|
3456
3561
|
feeParams: {
|
3457
3562
|
gasPerByte,
|
3458
3563
|
gasPriceFactor
|
@@ -3464,7 +3569,7 @@ function assembleTransactionSummary(params) {
|
|
3464
3569
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3465
3570
|
let date;
|
3466
3571
|
if (time) {
|
3467
|
-
date =
|
3572
|
+
date = import_utils18.DateTime.fromTai64(time);
|
3468
3573
|
}
|
3469
3574
|
const transactionSummary = {
|
3470
3575
|
id,
|
@@ -3492,12 +3597,12 @@ function assembleTransactionSummary(params) {
|
|
3492
3597
|
|
3493
3598
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3494
3599
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3495
|
-
var
|
3600
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
3496
3601
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3497
3602
|
return receipts.reduce((logs, receipt) => {
|
3498
|
-
if (receipt.type ===
|
3603
|
+
if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
|
3499
3604
|
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3500
|
-
const data = receipt.type ===
|
3605
|
+
const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3501
3606
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3502
3607
|
logs.push(decodedLog);
|
3503
3608
|
}
|
@@ -3512,7 +3617,7 @@ var TransactionResponse = class {
|
|
3512
3617
|
/** Current provider */
|
3513
3618
|
provider;
|
3514
3619
|
/** Gas used on the transaction */
|
3515
|
-
gasUsed = (0,
|
3620
|
+
gasUsed = (0, import_math15.bn)(0);
|
3516
3621
|
/** The graphql Transaction with receipts object. */
|
3517
3622
|
gqlTransaction;
|
3518
3623
|
abis;
|
@@ -3570,8 +3675,8 @@ var TransactionResponse = class {
|
|
3570
3675
|
* @returns The decoded transaction.
|
3571
3676
|
*/
|
3572
3677
|
decodeTransaction(transactionWithReceipts) {
|
3573
|
-
return new
|
3574
|
-
(0,
|
3678
|
+
return new import_transactions18.TransactionCoder().decode(
|
3679
|
+
(0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
|
3575
3680
|
0
|
3576
3681
|
)?.[0];
|
3577
3682
|
}
|
@@ -3590,20 +3695,27 @@ var TransactionResponse = class {
|
|
3590
3695
|
const decodedTransaction = this.decodeTransaction(
|
3591
3696
|
transaction
|
3592
3697
|
);
|
3593
|
-
|
3594
|
-
|
3698
|
+
let txReceipts = [];
|
3699
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
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();
|
3595
3705
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3596
3706
|
const transactionSummary = assembleTransactionSummary({
|
3597
3707
|
id: this.id,
|
3598
3708
|
receipts,
|
3599
3709
|
transaction: decodedTransaction,
|
3600
|
-
transactionBytes: (0,
|
3710
|
+
transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
|
3601
3711
|
gqlTransactionStatus: transaction.status,
|
3602
3712
|
gasPerByte,
|
3603
3713
|
gasPriceFactor,
|
3604
3714
|
abiMap: contractsAbiMap,
|
3605
3715
|
maxInputs,
|
3606
|
-
gasCosts
|
3716
|
+
gasCosts,
|
3717
|
+
maxGasPerTx,
|
3718
|
+
gasPrice
|
3607
3719
|
});
|
3608
3720
|
return transactionSummary;
|
3609
3721
|
}
|
@@ -3730,30 +3842,29 @@ var processGqlChain = (chain) => {
|
|
3730
3842
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3731
3843
|
return {
|
3732
3844
|
name,
|
3733
|
-
baseChainHeight: (0,
|
3845
|
+
baseChainHeight: (0, import_math16.bn)(daHeight),
|
3734
3846
|
consensusParameters: {
|
3735
|
-
contractMaxSize: (0,
|
3736
|
-
maxInputs: (0,
|
3737
|
-
maxOutputs: (0,
|
3738
|
-
maxWitnesses: (0,
|
3739
|
-
maxGasPerTx: (0,
|
3740
|
-
maxScriptLength: (0,
|
3741
|
-
maxScriptDataLength: (0,
|
3742
|
-
maxStorageSlots: (0,
|
3743
|
-
maxPredicateLength: (0,
|
3744
|
-
maxPredicateDataLength: (0,
|
3745
|
-
maxGasPerPredicate: (0,
|
3746
|
-
gasPriceFactor: (0,
|
3747
|
-
gasPerByte: (0,
|
3748
|
-
maxMessageDataLength: (0,
|
3749
|
-
chainId: (0,
|
3750
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3847
|
+
contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
|
3848
|
+
maxInputs: (0, import_math16.bn)(txParams.maxInputs),
|
3849
|
+
maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
|
3850
|
+
maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
|
3851
|
+
maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
|
3852
|
+
maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
|
3853
|
+
maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
|
3854
|
+
maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
|
3855
|
+
maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
|
3856
|
+
maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
|
3857
|
+
maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
|
3858
|
+
gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
|
3859
|
+
gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
|
3860
|
+
maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
|
3861
|
+
chainId: (0, import_math16.bn)(consensusParameters.chainId),
|
3751
3862
|
gasCosts
|
3752
3863
|
},
|
3753
3864
|
gasCosts,
|
3754
3865
|
latestBlock: {
|
3755
3866
|
id: latestBlock.id,
|
3756
|
-
height: (0,
|
3867
|
+
height: (0, import_math16.bn)(latestBlock.height),
|
3757
3868
|
time: latestBlock.header.time,
|
3758
3869
|
transactions: latestBlock.transactions.map((i) => ({
|
3759
3870
|
id: i.id
|
@@ -3847,10 +3958,8 @@ var _Provider = class {
|
|
3847
3958
|
* Returns some helpful parameters related to gas fees.
|
3848
3959
|
*/
|
3849
3960
|
getGasConfig() {
|
3850
|
-
const { minGasPrice } = this.getNode();
|
3851
3961
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3852
3962
|
return {
|
3853
|
-
minGasPrice,
|
3854
3963
|
maxGasPerTx,
|
3855
3964
|
maxGasPerPredicate,
|
3856
3965
|
gasPriceFactor,
|
@@ -3948,7 +4057,7 @@ var _Provider = class {
|
|
3948
4057
|
*/
|
3949
4058
|
async getBlockNumber() {
|
3950
4059
|
const { chain } = await this.operations.getChain();
|
3951
|
-
return (0,
|
4060
|
+
return (0, import_math16.bn)(chain.latestBlock.height, 10);
|
3952
4061
|
}
|
3953
4062
|
/**
|
3954
4063
|
* Returns the chain information.
|
@@ -3958,13 +4067,11 @@ var _Provider = class {
|
|
3958
4067
|
async fetchNode() {
|
3959
4068
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3960
4069
|
const processedNodeInfo = {
|
3961
|
-
maxDepth: (0,
|
3962
|
-
maxTx: (0,
|
3963
|
-
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
4070
|
+
maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
|
4071
|
+
maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
|
3964
4072
|
nodeVersion: nodeInfo.nodeVersion,
|
3965
4073
|
utxoValidation: nodeInfo.utxoValidation,
|
3966
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3967
|
-
peers: nodeInfo.peers
|
4074
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3968
4075
|
};
|
3969
4076
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3970
4077
|
return processedNodeInfo;
|
@@ -3990,17 +4097,6 @@ var _Provider = class {
|
|
3990
4097
|
} = this.getChain();
|
3991
4098
|
return chainId.toNumber();
|
3992
4099
|
}
|
3993
|
-
/**
|
3994
|
-
* Returns the base asset ID
|
3995
|
-
*
|
3996
|
-
* @returns A promise that resolves to the base asset ID
|
3997
|
-
*/
|
3998
|
-
getBaseAssetId() {
|
3999
|
-
const {
|
4000
|
-
consensusParameters: { baseAssetId }
|
4001
|
-
} = this.getChain();
|
4002
|
-
return baseAssetId;
|
4003
|
-
}
|
4004
4100
|
/**
|
4005
4101
|
* Submits a transaction to the chain to be executed.
|
4006
4102
|
*
|
@@ -4017,9 +4113,9 @@ var _Provider = class {
|
|
4017
4113
|
if (estimateTxDependencies) {
|
4018
4114
|
await this.estimateTxDependencies(transactionRequest);
|
4019
4115
|
}
|
4020
|
-
const encodedTransaction = (0,
|
4116
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4021
4117
|
let abis;
|
4022
|
-
if (transactionRequest.type ===
|
4118
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4023
4119
|
abis = transactionRequest.abis;
|
4024
4120
|
}
|
4025
4121
|
if (awaitExecution) {
|
@@ -4060,15 +4156,14 @@ var _Provider = class {
|
|
4060
4156
|
if (estimateTxDependencies) {
|
4061
4157
|
return this.estimateTxDependencies(transactionRequest);
|
4062
4158
|
}
|
4063
|
-
const encodedTransaction = (0,
|
4064
|
-
const { dryRun:
|
4065
|
-
encodedTransaction,
|
4159
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4160
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4161
|
+
encodedTransactions: encodedTransaction,
|
4066
4162
|
utxoValidation: utxoValidation || false
|
4067
4163
|
});
|
4068
|
-
const receipts =
|
4069
|
-
|
4070
|
-
|
4071
|
-
};
|
4164
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
4165
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4166
|
+
return { receipts, dryrunStatus: status };
|
4072
4167
|
}
|
4073
4168
|
/**
|
4074
4169
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4079,13 +4174,13 @@ var _Provider = class {
|
|
4079
4174
|
async estimatePredicates(transactionRequest) {
|
4080
4175
|
const shouldEstimatePredicates = Boolean(
|
4081
4176
|
transactionRequest.inputs.find(
|
4082
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4177
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math16.BN(input.predicateGasUsed).isZero()
|
4083
4178
|
)
|
4084
4179
|
);
|
4085
4180
|
if (!shouldEstimatePredicates) {
|
4086
4181
|
return transactionRequest;
|
4087
4182
|
}
|
4088
|
-
const encodedTransaction = (0,
|
4183
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4089
4184
|
const response = await this.operations.estimatePredicates({
|
4090
4185
|
encodedTransaction
|
4091
4186
|
});
|
@@ -4094,7 +4189,7 @@ var _Provider = class {
|
|
4094
4189
|
} = response;
|
4095
4190
|
if (inputs) {
|
4096
4191
|
inputs.forEach((input, index) => {
|
4097
|
-
if ("predicateGasUsed" in input && (0,
|
4192
|
+
if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
|
4098
4193
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4099
4194
|
}
|
4100
4195
|
});
|
@@ -4107,31 +4202,31 @@ var _Provider = class {
|
|
4107
4202
|
* If there are missing variable outputs,
|
4108
4203
|
* `addVariableOutputs` is called on the transaction.
|
4109
4204
|
*
|
4110
|
-
* @privateRemarks
|
4111
|
-
* TODO: Investigate support for missing contract IDs
|
4112
|
-
* TODO: Add support for missing output messages
|
4113
4205
|
*
|
4114
4206
|
* @param transactionRequest - The transaction request object.
|
4115
4207
|
* @returns A promise.
|
4116
4208
|
*/
|
4117
4209
|
async estimateTxDependencies(transactionRequest) {
|
4118
|
-
if (transactionRequest.type ===
|
4210
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Create) {
|
4119
4211
|
return {
|
4120
4212
|
receipts: [],
|
4121
4213
|
outputVariables: 0,
|
4122
4214
|
missingContractIds: []
|
4123
4215
|
};
|
4124
4216
|
}
|
4125
|
-
await this.estimatePredicates(transactionRequest);
|
4126
4217
|
let receipts = [];
|
4127
4218
|
const missingContractIds = [];
|
4128
4219
|
let outputVariables = 0;
|
4220
|
+
let dryrunStatus;
|
4129
4221
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4130
|
-
const {
|
4131
|
-
|
4222
|
+
const {
|
4223
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
4224
|
+
} = await this.operations.dryRun({
|
4225
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4132
4226
|
utxoValidation: false
|
4133
4227
|
});
|
4134
|
-
receipts =
|
4228
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
4229
|
+
dryrunStatus = status;
|
4135
4230
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4136
4231
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4137
4232
|
if (hasMissingOutputs) {
|
@@ -4141,6 +4236,10 @@ var _Provider = class {
|
|
4141
4236
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4142
4237
|
missingContractIds.push(contractId);
|
4143
4238
|
});
|
4239
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4240
|
+
transactionRequest
|
4241
|
+
});
|
4242
|
+
transactionRequest.maxFee = maxFee;
|
4144
4243
|
} else {
|
4145
4244
|
break;
|
4146
4245
|
}
|
@@ -4148,37 +4247,139 @@ var _Provider = class {
|
|
4148
4247
|
return {
|
4149
4248
|
receipts,
|
4150
4249
|
outputVariables,
|
4151
|
-
missingContractIds
|
4250
|
+
missingContractIds,
|
4251
|
+
dryrunStatus
|
4152
4252
|
};
|
4153
4253
|
}
|
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
|
+
}
|
4154
4338
|
/**
|
4155
4339
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4156
4340
|
* @param transactionRequest - The transaction request object.
|
4157
4341
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4158
4342
|
*/
|
4159
|
-
estimateTxGasAndFee(params) {
|
4343
|
+
async estimateTxGasAndFee(params) {
|
4160
4344
|
const { transactionRequest } = params;
|
4161
|
-
|
4345
|
+
let { gasPrice } = params;
|
4162
4346
|
const chainInfo = this.getChain();
|
4163
|
-
const
|
4164
|
-
transactionRequest.gasPrice = gasPrice;
|
4347
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
4165
4348
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4166
|
-
|
4167
|
-
|
4349
|
+
if (!gasPrice) {
|
4350
|
+
gasPrice = await this.estimateGasPrice(10);
|
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;
|
4168
4361
|
if (transactionRequest.gasLimit.eq(0)) {
|
4169
4362
|
transactionRequest.gasLimit = minGas;
|
4170
4363
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4171
4364
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4172
4365
|
);
|
4366
|
+
gasLimit = transactionRequest.gasLimit;
|
4173
4367
|
}
|
4174
4368
|
}
|
4175
4369
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4176
|
-
const maxFee =
|
4370
|
+
const maxFee = calculateGasFee({
|
4371
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4372
|
+
gas: maxGas,
|
4373
|
+
priceFactor: gasPriceFactor,
|
4374
|
+
tip: transactionRequest.tip
|
4375
|
+
}).add(1);
|
4177
4376
|
return {
|
4178
4377
|
minGas,
|
4179
4378
|
minFee,
|
4180
4379
|
maxGas,
|
4181
|
-
maxFee
|
4380
|
+
maxFee,
|
4381
|
+
gasPrice,
|
4382
|
+
gasLimit
|
4182
4383
|
};
|
4183
4384
|
}
|
4184
4385
|
/**
|
@@ -4196,15 +4397,17 @@ var _Provider = class {
|
|
4196
4397
|
if (estimateTxDependencies) {
|
4197
4398
|
return this.estimateTxDependencies(transactionRequest);
|
4198
4399
|
}
|
4199
|
-
const
|
4200
|
-
const { dryRun:
|
4201
|
-
|
4400
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4401
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4402
|
+
encodedTransactions,
|
4202
4403
|
utxoValidation: true
|
4203
4404
|
});
|
4204
|
-
const
|
4205
|
-
|
4206
|
-
receipts
|
4207
|
-
|
4405
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4406
|
+
const { id, receipts, status } = dryRunStatus;
|
4407
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4408
|
+
return { id, receipts: processedReceipts, status };
|
4409
|
+
});
|
4410
|
+
return { receipts: callResult[0].receipts };
|
4208
4411
|
}
|
4209
4412
|
/**
|
4210
4413
|
* Returns a transaction cost to enable user
|
@@ -4221,77 +4424,79 @@ var _Provider = class {
|
|
4221
4424
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4222
4425
|
* @returns A promise that resolves to the transaction cost object.
|
4223
4426
|
*/
|
4224
|
-
async getTransactionCost(transactionRequestLike,
|
4225
|
-
estimateTxDependencies = true,
|
4226
|
-
estimatePredicates = true,
|
4227
|
-
resourcesOwner,
|
4228
|
-
signatureCallback
|
4229
|
-
} = {}) {
|
4427
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
4230
4428
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4231
|
-
const
|
4232
|
-
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4233
|
-
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4429
|
+
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
4234
4430
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4235
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4431
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4236
4432
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4433
|
+
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4237
4434
|
if (isScriptTransaction) {
|
4238
|
-
txRequestClone.gasLimit = (0,
|
4435
|
+
txRequestClone.gasLimit = (0, import_math16.bn)(0);
|
4239
4436
|
}
|
4240
|
-
if (
|
4241
|
-
|
4242
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4243
|
-
}
|
4244
|
-
await this.estimatePredicates(txRequestClone);
|
4437
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4438
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4245
4439
|
}
|
4440
|
+
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4441
|
+
let addedSignatures = 0;
|
4246
4442
|
if (signatureCallback && isScriptTransaction) {
|
4247
|
-
|
4443
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4444
|
+
await signatureCallback(signedRequest);
|
4445
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4248
4446
|
}
|
4249
|
-
|
4250
|
-
|
4447
|
+
await this.estimatePredicates(signedRequest);
|
4448
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4449
|
+
transactionRequest: signedRequest
|
4251
4450
|
});
|
4252
4451
|
let receipts = [];
|
4253
4452
|
let missingContractIds = [];
|
4254
4453
|
let outputVariables = 0;
|
4255
|
-
let gasUsed = (0,
|
4256
|
-
|
4257
|
-
|
4454
|
+
let gasUsed = (0, import_math16.bn)(0);
|
4455
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4456
|
+
txRequestClone.maxFee = maxFee;
|
4457
|
+
if (isScriptTransaction) {
|
4458
|
+
txRequestClone.gasLimit = gasLimit;
|
4459
|
+
if (signatureCallback) {
|
4460
|
+
await signatureCallback(txRequestClone);
|
4461
|
+
}
|
4258
4462
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4259
4463
|
receipts = result.receipts;
|
4260
4464
|
outputVariables = result.outputVariables;
|
4261
4465
|
missingContractIds = result.missingContractIds;
|
4262
4466
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4263
4467
|
txRequestClone.gasLimit = gasUsed;
|
4264
|
-
|
4265
|
-
|
4266
|
-
|
4468
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4469
|
+
transactionRequest: txRequestClone,
|
4470
|
+
gasPrice
|
4267
4471
|
}));
|
4268
4472
|
}
|
4269
4473
|
return {
|
4270
4474
|
requiredQuantities: allQuantities,
|
4271
4475
|
receipts,
|
4272
4476
|
gasUsed,
|
4273
|
-
|
4274
|
-
gasPrice: setGasPrice,
|
4477
|
+
gasPrice,
|
4275
4478
|
minGas,
|
4276
4479
|
maxGas,
|
4277
4480
|
minFee,
|
4278
4481
|
maxFee,
|
4279
|
-
estimatedInputs: txRequestClone.inputs,
|
4280
4482
|
outputVariables,
|
4281
|
-
missingContractIds
|
4483
|
+
missingContractIds,
|
4484
|
+
addedSignatures,
|
4485
|
+
estimatedPredicates: txRequestClone.inputs
|
4282
4486
|
};
|
4283
4487
|
}
|
4284
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4488
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4285
4489
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4286
4490
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4287
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4491
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4492
|
+
quantitiesToContract
|
4493
|
+
});
|
4288
4494
|
transactionRequest.addResources(
|
4289
4495
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4290
4496
|
);
|
4291
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4292
|
-
|
4293
|
-
|
4294
|
-
);
|
4497
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4498
|
+
quantitiesToContract
|
4499
|
+
});
|
4295
4500
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4296
4501
|
return {
|
4297
4502
|
resources,
|
@@ -4307,17 +4512,16 @@ var _Provider = class {
|
|
4307
4512
|
const result = await this.operations.getCoins({
|
4308
4513
|
first: 10,
|
4309
4514
|
...paginationArgs,
|
4310
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4515
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4311
4516
|
});
|
4312
4517
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4313
4518
|
return coins.map((coin) => ({
|
4314
4519
|
id: coin.utxoId,
|
4315
4520
|
assetId: coin.assetId,
|
4316
|
-
amount: (0,
|
4521
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4317
4522
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4318
|
-
|
4319
|
-
|
4320
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4523
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4524
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4321
4525
|
}));
|
4322
4526
|
}
|
4323
4527
|
/**
|
@@ -4331,19 +4535,19 @@ var _Provider = class {
|
|
4331
4535
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4332
4536
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4333
4537
|
const excludeInput = {
|
4334
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4335
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4538
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4539
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4336
4540
|
};
|
4337
4541
|
if (this.cache) {
|
4338
4542
|
const uniqueUtxos = new Set(
|
4339
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4543
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4340
4544
|
);
|
4341
4545
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4342
4546
|
}
|
4343
4547
|
const coinsQuery = {
|
4344
4548
|
owner: ownerAddress.toB256(),
|
4345
4549
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4346
|
-
assetId: (0,
|
4550
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4347
4551
|
amount: amount.toString(10),
|
4348
4552
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4349
4553
|
})),
|
@@ -4354,9 +4558,9 @@ var _Provider = class {
|
|
4354
4558
|
switch (coin.__typename) {
|
4355
4559
|
case "MessageCoin":
|
4356
4560
|
return {
|
4357
|
-
amount: (0,
|
4561
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4358
4562
|
assetId: coin.assetId,
|
4359
|
-
daHeight: (0,
|
4563
|
+
daHeight: (0, import_math16.bn)(coin.daHeight),
|
4360
4564
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4361
4565
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4362
4566
|
nonce: coin.nonce
|
@@ -4364,12 +4568,11 @@ var _Provider = class {
|
|
4364
4568
|
case "Coin":
|
4365
4569
|
return {
|
4366
4570
|
id: coin.utxoId,
|
4367
|
-
amount: (0,
|
4571
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4368
4572
|
assetId: coin.assetId,
|
4369
4573
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4370
|
-
|
4371
|
-
|
4372
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4574
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4575
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4373
4576
|
};
|
4374
4577
|
default:
|
4375
4578
|
return null;
|
@@ -4386,13 +4589,13 @@ var _Provider = class {
|
|
4386
4589
|
async getBlock(idOrHeight) {
|
4387
4590
|
let variables;
|
4388
4591
|
if (typeof idOrHeight === "number") {
|
4389
|
-
variables = { height: (0,
|
4592
|
+
variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4390
4593
|
} else if (idOrHeight === "latest") {
|
4391
4594
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4392
4595
|
} else if (idOrHeight.length === 66) {
|
4393
4596
|
variables = { blockId: idOrHeight };
|
4394
4597
|
} else {
|
4395
|
-
variables = { blockId: (0,
|
4598
|
+
variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4396
4599
|
}
|
4397
4600
|
const { block } = await this.operations.getBlock(variables);
|
4398
4601
|
if (!block) {
|
@@ -4400,7 +4603,7 @@ var _Provider = class {
|
|
4400
4603
|
}
|
4401
4604
|
return {
|
4402
4605
|
id: block.id,
|
4403
|
-
height: (0,
|
4606
|
+
height: (0, import_math16.bn)(block.height),
|
4404
4607
|
time: block.header.time,
|
4405
4608
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4406
4609
|
};
|
@@ -4415,7 +4618,7 @@ var _Provider = class {
|
|
4415
4618
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4416
4619
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4417
4620
|
id: block.id,
|
4418
|
-
height: (0,
|
4621
|
+
height: (0, import_math16.bn)(block.height),
|
4419
4622
|
time: block.header.time,
|
4420
4623
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4421
4624
|
}));
|
@@ -4430,7 +4633,7 @@ var _Provider = class {
|
|
4430
4633
|
async getBlockWithTransactions(idOrHeight) {
|
4431
4634
|
let variables;
|
4432
4635
|
if (typeof idOrHeight === "number") {
|
4433
|
-
variables = { blockHeight: (0,
|
4636
|
+
variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4434
4637
|
} else if (idOrHeight === "latest") {
|
4435
4638
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4436
4639
|
} else {
|
@@ -4442,11 +4645,11 @@ var _Provider = class {
|
|
4442
4645
|
}
|
4443
4646
|
return {
|
4444
4647
|
id: block.id,
|
4445
|
-
height: (0,
|
4648
|
+
height: (0, import_math16.bn)(block.height, 10),
|
4446
4649
|
time: block.header.time,
|
4447
4650
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4448
4651
|
transactions: block.transactions.map(
|
4449
|
-
(tx) => new
|
4652
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4450
4653
|
)
|
4451
4654
|
};
|
4452
4655
|
}
|
@@ -4461,8 +4664,8 @@ var _Provider = class {
|
|
4461
4664
|
if (!transaction) {
|
4462
4665
|
return null;
|
4463
4666
|
}
|
4464
|
-
return new
|
4465
|
-
(0,
|
4667
|
+
return new import_transactions19.TransactionCoder().decode(
|
4668
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4466
4669
|
0
|
4467
4670
|
)?.[0];
|
4468
4671
|
}
|
@@ -4489,9 +4692,9 @@ var _Provider = class {
|
|
4489
4692
|
async getContractBalance(contractId, assetId) {
|
4490
4693
|
const { contractBalance } = await this.operations.getContractBalance({
|
4491
4694
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4492
|
-
asset: (0,
|
4695
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4493
4696
|
});
|
4494
|
-
return (0,
|
4697
|
+
return (0, import_math16.bn)(contractBalance.amount, 10);
|
4495
4698
|
}
|
4496
4699
|
/**
|
4497
4700
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4503,9 +4706,9 @@ var _Provider = class {
|
|
4503
4706
|
async getBalance(owner, assetId) {
|
4504
4707
|
const { balance } = await this.operations.getBalance({
|
4505
4708
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4506
|
-
assetId: (0,
|
4709
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4507
4710
|
});
|
4508
|
-
return (0,
|
4711
|
+
return (0, import_math16.bn)(balance.amount, 10);
|
4509
4712
|
}
|
4510
4713
|
/**
|
4511
4714
|
* Returns balances for the given owner.
|
@@ -4523,7 +4726,7 @@ var _Provider = class {
|
|
4523
4726
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4524
4727
|
return balances.map((balance) => ({
|
4525
4728
|
assetId: balance.assetId,
|
4526
|
-
amount: (0,
|
4729
|
+
amount: (0, import_math16.bn)(balance.amount)
|
4527
4730
|
}));
|
4528
4731
|
}
|
4529
4732
|
/**
|
@@ -4541,19 +4744,19 @@ var _Provider = class {
|
|
4541
4744
|
});
|
4542
4745
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4543
4746
|
return messages.map((message) => ({
|
4544
|
-
messageId:
|
4747
|
+
messageId: import_transactions19.InputMessageCoder.getMessageId({
|
4545
4748
|
sender: message.sender,
|
4546
4749
|
recipient: message.recipient,
|
4547
4750
|
nonce: message.nonce,
|
4548
|
-
amount: (0,
|
4751
|
+
amount: (0, import_math16.bn)(message.amount),
|
4549
4752
|
data: message.data
|
4550
4753
|
}),
|
4551
4754
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4552
4755
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4553
4756
|
nonce: message.nonce,
|
4554
|
-
amount: (0,
|
4555
|
-
data:
|
4556
|
-
daHeight: (0,
|
4757
|
+
amount: (0, import_math16.bn)(message.amount),
|
4758
|
+
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4759
|
+
daHeight: (0, import_math16.bn)(message.daHeight)
|
4557
4760
|
}));
|
4558
4761
|
}
|
4559
4762
|
/**
|
@@ -4606,44 +4809,60 @@ var _Provider = class {
|
|
4606
4809
|
} = result.messageProof;
|
4607
4810
|
return {
|
4608
4811
|
messageProof: {
|
4609
|
-
proofIndex: (0,
|
4812
|
+
proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
|
4610
4813
|
proofSet: messageProof.proofSet
|
4611
4814
|
},
|
4612
4815
|
blockProof: {
|
4613
|
-
proofIndex: (0,
|
4816
|
+
proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
|
4614
4817
|
proofSet: blockProof.proofSet
|
4615
4818
|
},
|
4616
4819
|
messageBlockHeader: {
|
4617
4820
|
id: messageBlockHeader.id,
|
4618
|
-
daHeight: (0,
|
4619
|
-
transactionsCount: (0,
|
4821
|
+
daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
|
4822
|
+
transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
|
4620
4823
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4621
|
-
height: (0,
|
4824
|
+
height: (0, import_math16.bn)(messageBlockHeader.height),
|
4622
4825
|
prevRoot: messageBlockHeader.prevRoot,
|
4623
4826
|
time: messageBlockHeader.time,
|
4624
4827
|
applicationHash: messageBlockHeader.applicationHash,
|
4625
|
-
|
4626
|
-
|
4828
|
+
messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
|
4829
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4830
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4831
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4832
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4627
4833
|
},
|
4628
4834
|
commitBlockHeader: {
|
4629
4835
|
id: commitBlockHeader.id,
|
4630
|
-
daHeight: (0,
|
4631
|
-
transactionsCount: (0,
|
4836
|
+
daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
|
4837
|
+
transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
|
4632
4838
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4633
|
-
height: (0,
|
4839
|
+
height: (0, import_math16.bn)(commitBlockHeader.height),
|
4634
4840
|
prevRoot: commitBlockHeader.prevRoot,
|
4635
4841
|
time: commitBlockHeader.time,
|
4636
4842
|
applicationHash: commitBlockHeader.applicationHash,
|
4637
|
-
|
4638
|
-
|
4843
|
+
messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
|
4844
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4845
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4846
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4847
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4639
4848
|
},
|
4640
4849
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4641
4850
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4642
4851
|
nonce,
|
4643
|
-
amount: (0,
|
4852
|
+
amount: (0, import_math16.bn)(amount),
|
4644
4853
|
data
|
4645
4854
|
};
|
4646
4855
|
}
|
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
|
+
}
|
4647
4866
|
/**
|
4648
4867
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4649
4868
|
*
|
@@ -4663,10 +4882,10 @@ var _Provider = class {
|
|
4663
4882
|
*/
|
4664
4883
|
async produceBlocks(amount, startTime) {
|
4665
4884
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4666
|
-
blocksToProduce: (0,
|
4667
|
-
startTimestamp: startTime ?
|
4885
|
+
blocksToProduce: (0, import_math16.bn)(amount).toString(10),
|
4886
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4668
4887
|
});
|
4669
|
-
return (0,
|
4888
|
+
return (0, import_math16.bn)(latestBlockHeight);
|
4670
4889
|
}
|
4671
4890
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4672
4891
|
async getTransactionResponse(transactionId) {
|
@@ -4680,7 +4899,7 @@ cacheInputs_fn = function(inputs) {
|
|
4680
4899
|
return;
|
4681
4900
|
}
|
4682
4901
|
inputs.forEach((input) => {
|
4683
|
-
if (input.type ===
|
4902
|
+
if (input.type === import_transactions19.InputType.Coin) {
|
4684
4903
|
this.cache?.set(input.id);
|
4685
4904
|
}
|
4686
4905
|
});
|
@@ -4690,9 +4909,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4690
4909
|
|
4691
4910
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4692
4911
|
var import_errors15 = require("@fuel-ts/errors");
|
4693
|
-
var
|
4694
|
-
var
|
4695
|
-
var
|
4912
|
+
var import_math17 = require("@fuel-ts/math");
|
4913
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
4914
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4696
4915
|
async function getTransactionSummary(params) {
|
4697
4916
|
const { id, provider, abiMap } = params;
|
4698
4917
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -4704,25 +4923,32 @@ async function getTransactionSummary(params) {
|
|
4704
4923
|
`Transaction not found for given id: ${id}.`
|
4705
4924
|
);
|
4706
4925
|
}
|
4707
|
-
const [decodedTransaction] = new
|
4708
|
-
(0,
|
4926
|
+
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode(
|
4927
|
+
(0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4709
4928
|
0
|
4710
4929
|
);
|
4711
|
-
|
4930
|
+
let txReceipts = [];
|
4931
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4932
|
+
txReceipts = gqlTransaction.status.receipts;
|
4933
|
+
}
|
4934
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4712
4935
|
const {
|
4713
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4936
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4714
4937
|
} = provider.getChain();
|
4938
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4715
4939
|
const transactionInfo = assembleTransactionSummary({
|
4716
4940
|
id: gqlTransaction.id,
|
4717
4941
|
receipts,
|
4718
4942
|
transaction: decodedTransaction,
|
4719
|
-
transactionBytes: (0,
|
4943
|
+
transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4720
4944
|
gqlTransactionStatus: gqlTransaction.status,
|
4721
|
-
gasPerByte: (0,
|
4722
|
-
gasPriceFactor: (0,
|
4945
|
+
gasPerByte: (0, import_math17.bn)(gasPerByte),
|
4946
|
+
gasPriceFactor: (0, import_math17.bn)(gasPriceFactor),
|
4723
4947
|
abiMap,
|
4724
4948
|
maxInputs,
|
4725
|
-
gasCosts
|
4949
|
+
gasCosts,
|
4950
|
+
maxGasPerTx,
|
4951
|
+
gasPrice
|
4726
4952
|
});
|
4727
4953
|
return {
|
4728
4954
|
gqlTransaction,
|
@@ -4732,10 +4958,11 @@ async function getTransactionSummary(params) {
|
|
4732
4958
|
async function getTransactionSummaryFromRequest(params) {
|
4733
4959
|
const { provider, transactionRequest, abiMap } = params;
|
4734
4960
|
const { receipts } = await provider.call(transactionRequest);
|
4735
|
-
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4961
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = provider.getGasConfig();
|
4736
4962
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4737
4963
|
const transaction = transactionRequest.toTransaction();
|
4738
4964
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4965
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4739
4966
|
const transactionSummary = assembleTransactionSummary({
|
4740
4967
|
receipts,
|
4741
4968
|
transaction,
|
@@ -4744,7 +4971,9 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4744
4971
|
gasPerByte,
|
4745
4972
|
gasPriceFactor,
|
4746
4973
|
maxInputs,
|
4747
|
-
gasCosts
|
4974
|
+
gasCosts,
|
4975
|
+
maxGasPerTx,
|
4976
|
+
gasPrice
|
4748
4977
|
});
|
4749
4978
|
return transactionSummary;
|
4750
4979
|
}
|
@@ -4753,24 +4982,31 @@ async function getTransactionsSummaries(params) {
|
|
4753
4982
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4754
4983
|
const { edges, pageInfo } = transactionsByOwner;
|
4755
4984
|
const {
|
4756
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4985
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts, maxGasPerTx }
|
4757
4986
|
} = provider.getChain();
|
4987
|
+
const gasPrice = await provider.getLatestGasPrice();
|
4758
4988
|
const transactions = edges.map((edge) => {
|
4759
4989
|
const { node: gqlTransaction } = edge;
|
4760
|
-
const { id, rawPayload,
|
4761
|
-
const [decodedTransaction] = new
|
4762
|
-
|
4990
|
+
const { id, rawPayload, status } = gqlTransaction;
|
4991
|
+
const [decodedTransaction] = new import_transactions20.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
|
4992
|
+
let txReceipts = [];
|
4993
|
+
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4994
|
+
txReceipts = gqlTransaction.status.receipts;
|
4995
|
+
}
|
4996
|
+
const receipts = txReceipts.map(processGqlReceipt);
|
4763
4997
|
const transactionSummary = assembleTransactionSummary({
|
4764
4998
|
id,
|
4765
4999
|
receipts,
|
4766
5000
|
transaction: decodedTransaction,
|
4767
|
-
transactionBytes: (0,
|
5001
|
+
transactionBytes: (0, import_utils25.arrayify)(rawPayload),
|
4768
5002
|
gqlTransactionStatus: status,
|
4769
5003
|
abiMap,
|
4770
5004
|
gasPerByte,
|
4771
5005
|
gasPriceFactor,
|
4772
5006
|
maxInputs,
|
4773
|
-
gasCosts
|
5007
|
+
gasCosts,
|
5008
|
+
maxGasPerTx,
|
5009
|
+
gasPrice
|
4774
5010
|
});
|
4775
5011
|
const output = {
|
4776
5012
|
gqlTransaction,
|
@@ -4907,17 +5143,17 @@ var assets = [
|
|
4907
5143
|
|
4908
5144
|
// src/utils/formatTransferToContractScriptData.ts
|
4909
5145
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4910
|
-
var
|
4911
|
-
var
|
5146
|
+
var import_math18 = require("@fuel-ts/math");
|
5147
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4912
5148
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4913
5149
|
var formatTransferToContractScriptData = (params) => {
|
4914
5150
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4915
5151
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4916
|
-
const encoded = numberCoder.encode(new
|
5152
|
+
const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
|
4917
5153
|
const scriptData = Uint8Array.from([
|
4918
|
-
...(0,
|
5154
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4919
5155
|
...encoded,
|
4920
|
-
...(0,
|
5156
|
+
...(0, import_utils26.arrayify)(assetId)
|
4921
5157
|
]);
|
4922
5158
|
return scriptData;
|
4923
5159
|
};
|
@@ -5064,9 +5300,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5064
5300
|
* @param assetId - The asset ID to check the balance for.
|
5065
5301
|
* @returns A promise that resolves to the balance amount.
|
5066
5302
|
*/
|
5067
|
-
async getBalance(assetId) {
|
5068
|
-
const
|
5069
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
5303
|
+
async getBalance(assetId = import_configs12.BaseAssetId) {
|
5304
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
5070
5305
|
return amount;
|
5071
5306
|
}
|
5072
5307
|
/**
|
@@ -5103,37 +5338,33 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5103
5338
|
* @param fee - The estimated transaction fee.
|
5104
5339
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5105
5340
|
*/
|
5106
|
-
async fund(request,
|
5107
|
-
const
|
5108
|
-
const
|
5109
|
-
|
5110
|
-
|
5111
|
-
|
5341
|
+
async fund(request, params) {
|
5342
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
5343
|
+
const txRequest = request;
|
5344
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5345
|
+
amount: (0, import_math19.bn)(fee),
|
5346
|
+
assetId: import_configs12.BaseAssetId,
|
5347
|
+
coinQuantities: requiredQuantities
|
5112
5348
|
});
|
5113
5349
|
const quantitiesDict = {};
|
5114
|
-
|
5350
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
5115
5351
|
quantitiesDict[assetId] = {
|
5116
5352
|
required: amount,
|
5117
|
-
owned: (0,
|
5353
|
+
owned: (0, import_math19.bn)(0)
|
5118
5354
|
};
|
5119
5355
|
});
|
5120
|
-
|
5121
|
-
const cachedMessages = [];
|
5122
|
-
const owner = this.address.toB256();
|
5123
|
-
request.inputs.forEach((input) => {
|
5356
|
+
txRequest.inputs.forEach((input) => {
|
5124
5357
|
const isResource = "amount" in input;
|
5125
5358
|
if (isResource) {
|
5126
5359
|
const isCoin2 = "owner" in input;
|
5127
5360
|
if (isCoin2) {
|
5128
5361
|
const assetId = String(input.assetId);
|
5129
|
-
if (
|
5130
|
-
const amount = (0,
|
5362
|
+
if (quantitiesDict[assetId]) {
|
5363
|
+
const amount = (0, import_math19.bn)(input.amount);
|
5131
5364
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5132
|
-
cachedUtxos.push(input.id);
|
5133
5365
|
}
|
5134
|
-
} else if (input.
|
5135
|
-
quantitiesDict[
|
5136
|
-
cachedMessages.push(input.nonce);
|
5366
|
+
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5367
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
5137
5368
|
}
|
5138
5369
|
}
|
5139
5370
|
});
|
@@ -5148,12 +5379,23 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5148
5379
|
});
|
5149
5380
|
const needsToBeFunded = missingQuantities.length;
|
5150
5381
|
if (needsToBeFunded) {
|
5151
|
-
const
|
5152
|
-
|
5153
|
-
|
5154
|
-
|
5155
|
-
|
5382
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
5383
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
5384
|
+
txRequest.addResources(resources);
|
5385
|
+
}
|
5386
|
+
txRequest.shiftPredicateData();
|
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
|
+
);
|
5156
5393
|
}
|
5394
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5395
|
+
transactionRequest: requestToBeReEstimate
|
5396
|
+
});
|
5397
|
+
txRequest.maxFee = maxFee;
|
5398
|
+
return txRequest;
|
5157
5399
|
}
|
5158
5400
|
/**
|
5159
5401
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5161,30 +5403,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5161
5403
|
* @param destination - The address of the destination.
|
5162
5404
|
* @param amount - The amount of coins to transfer.
|
5163
5405
|
* @param assetId - The asset ID of the coins to transfer.
|
5164
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5406
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
5165
5407
|
* @returns A promise that resolves to the prepared transaction request.
|
5166
5408
|
*/
|
5167
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
5168
|
-
const
|
5169
|
-
|
5170
|
-
const
|
5171
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5172
|
-
const request = new ScriptTransactionRequest(params);
|
5173
|
-
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
|
5174
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5409
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5410
|
+
const request = new ScriptTransactionRequest(txParams);
|
5411
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
5412
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5175
5413
|
estimateTxDependencies: true,
|
5176
5414
|
resourcesOwner: this
|
5177
5415
|
});
|
5178
|
-
|
5179
|
-
|
5180
|
-
|
5181
|
-
|
5182
|
-
|
5183
|
-
|
5184
|
-
|
5185
|
-
|
5186
|
-
await this.fund(request,
|
5187
|
-
request.updatePredicateInputs(estimatedInputs);
|
5416
|
+
if ("gasLimit" in txParams) {
|
5417
|
+
this.validateGas({
|
5418
|
+
gasUsed: txCost.gasUsed,
|
5419
|
+
gasLimit: request.gasLimit
|
5420
|
+
});
|
5421
|
+
}
|
5422
|
+
request.gasLimit = txCost.gasUsed;
|
5423
|
+
request.maxFee = txCost.maxFee;
|
5424
|
+
await this.fund(request, txCost);
|
5188
5425
|
return request;
|
5189
5426
|
}
|
5190
5427
|
/**
|
@@ -5196,15 +5433,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5196
5433
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5197
5434
|
* @returns A promise that resolves to the transaction response.
|
5198
5435
|
*/
|
5199
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
5200
|
-
if ((0,
|
5436
|
+
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5437
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
5201
5438
|
throw new import_errors16.FuelError(
|
5202
5439
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5203
5440
|
"Transfer amount must be a positive number."
|
5204
5441
|
);
|
5205
5442
|
}
|
5206
|
-
const
|
5207
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5443
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
5208
5444
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5209
5445
|
}
|
5210
5446
|
/**
|
@@ -5216,41 +5452,38 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5216
5452
|
* @param txParams - The optional transaction parameters.
|
5217
5453
|
* @returns A promise that resolves to the transaction response.
|
5218
5454
|
*/
|
5219
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5220
|
-
if ((0,
|
5455
|
+
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5456
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
5221
5457
|
throw new import_errors16.FuelError(
|
5222
5458
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5223
5459
|
"Transfer amount must be a positive number."
|
5224
5460
|
);
|
5225
5461
|
}
|
5226
5462
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5227
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5228
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5229
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5230
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5231
5463
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5232
5464
|
hexlifiedContractId: contractAddress.toB256(),
|
5233
|
-
amountToTransfer: (0,
|
5234
|
-
assetId
|
5465
|
+
amountToTransfer: (0, import_math19.bn)(amount),
|
5466
|
+
assetId
|
5235
5467
|
});
|
5236
5468
|
const request = new ScriptTransactionRequest({
|
5237
|
-
...
|
5469
|
+
...txParams,
|
5238
5470
|
script,
|
5239
5471
|
scriptData
|
5240
5472
|
});
|
5241
5473
|
request.addContractInputAndOutput(contractAddress);
|
5242
|
-
const
|
5243
|
-
|
5244
|
-
[{ amount: (0,
|
5245
|
-
);
|
5246
|
-
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5247
|
-
this.validateGas({
|
5248
|
-
gasUsed,
|
5249
|
-
gasPrice: request.gasPrice,
|
5250
|
-
gasLimit: request.gasLimit,
|
5251
|
-
minGasPrice
|
5474
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5475
|
+
resourcesOwner: this,
|
5476
|
+
quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
|
5252
5477
|
});
|
5253
|
-
|
5478
|
+
if (txParams.gasLimit) {
|
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);
|
5254
5487
|
return this.sendTransaction(request);
|
5255
5488
|
}
|
5256
5489
|
/**
|
@@ -5262,40 +5495,31 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5262
5495
|
* @returns A promise that resolves to the transaction response.
|
5263
5496
|
*/
|
5264
5497
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5265
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
5266
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
5267
5498
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5268
|
-
const recipientDataArray = (0,
|
5499
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
5269
5500
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5270
5501
|
);
|
5271
|
-
const amountDataArray = (0,
|
5272
|
-
"0x".concat((0,
|
5502
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5503
|
+
"0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5273
5504
|
);
|
5274
5505
|
const script = new Uint8Array([
|
5275
|
-
...(0,
|
5506
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
5276
5507
|
...recipientDataArray,
|
5277
5508
|
...amountDataArray
|
5278
5509
|
]);
|
5279
|
-
const params = {
|
5280
|
-
script,
|
5281
|
-
gasPrice: minGasPrice,
|
5282
|
-
baseAssetId,
|
5283
|
-
...txParams
|
5284
|
-
};
|
5510
|
+
const params = { script, ...txParams };
|
5285
5511
|
const request = new ScriptTransactionRequest(params);
|
5286
|
-
const
|
5287
|
-
const
|
5288
|
-
|
5289
|
-
|
5290
|
-
|
5291
|
-
|
5292
|
-
|
5293
|
-
|
5294
|
-
|
5295
|
-
|
5296
|
-
|
5297
|
-
});
|
5298
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5512
|
+
const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5513
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5514
|
+
if (txParams.gasLimit) {
|
5515
|
+
this.validateGas({
|
5516
|
+
gasUsed: txCost.gasUsed,
|
5517
|
+
gasLimit: request.gasLimit
|
5518
|
+
});
|
5519
|
+
}
|
5520
|
+
request.maxFee = txCost.maxFee;
|
5521
|
+
request.gasLimit = txCost.gasUsed;
|
5522
|
+
await this.fund(request, txCost);
|
5299
5523
|
return this.sendTransaction(request);
|
5300
5524
|
}
|
5301
5525
|
async signMessage(message) {
|
@@ -5353,18 +5577,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5353
5577
|
}
|
5354
5578
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5355
5579
|
}
|
5356
|
-
validateGas({
|
5357
|
-
gasUsed,
|
5358
|
-
gasPrice,
|
5359
|
-
gasLimit,
|
5360
|
-
minGasPrice
|
5361
|
-
}) {
|
5362
|
-
if (minGasPrice.gt(gasPrice)) {
|
5363
|
-
throw new import_errors16.FuelError(
|
5364
|
-
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
5365
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5366
|
-
);
|
5367
|
-
}
|
5580
|
+
validateGas({ gasUsed, gasLimit }) {
|
5368
5581
|
if (gasUsed.gt(gasLimit)) {
|
5369
5582
|
throw new import_errors16.FuelError(
|
5370
5583
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5376,14 +5589,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5376
5589
|
|
5377
5590
|
// src/wallet/base-wallet-unlocked.ts
|
5378
5591
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5379
|
-
var
|
5592
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5380
5593
|
|
5381
5594
|
// src/signer/signer.ts
|
5382
5595
|
var import_address5 = require("@fuel-ts/address");
|
5383
5596
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5384
5597
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5385
|
-
var
|
5386
|
-
var
|
5598
|
+
var import_math20 = require("@fuel-ts/math");
|
5599
|
+
var import_utils28 = require("@fuel-ts/utils");
|
5387
5600
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5388
5601
|
var Signer = class {
|
5389
5602
|
address;
|
@@ -5402,10 +5615,10 @@ var Signer = class {
|
|
5402
5615
|
privateKey = `0x${privateKey}`;
|
5403
5616
|
}
|
5404
5617
|
}
|
5405
|
-
const privateKeyBytes = (0,
|
5406
|
-
this.privateKey = (0,
|
5407
|
-
this.publicKey = (0,
|
5408
|
-
this.compressedPublicKey = (0,
|
5618
|
+
const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
|
5619
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5620
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5621
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5409
5622
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5410
5623
|
}
|
5411
5624
|
/**
|
@@ -5419,11 +5632,11 @@ var Signer = class {
|
|
5419
5632
|
* @returns hashed signature
|
5420
5633
|
*/
|
5421
5634
|
sign(data) {
|
5422
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5423
|
-
const r = (0,
|
5424
|
-
const s = (0,
|
5635
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5636
|
+
const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5637
|
+
const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5425
5638
|
s[0] |= (signature.recovery || 0) << 7;
|
5426
|
-
return (0,
|
5639
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
5427
5640
|
}
|
5428
5641
|
/**
|
5429
5642
|
* Add point on the current elliptic curve
|
@@ -5432,8 +5645,8 @@ var Signer = class {
|
|
5432
5645
|
* @returns compressed point on the curve
|
5433
5646
|
*/
|
5434
5647
|
addPoint(point) {
|
5435
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5436
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5648
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5649
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
5437
5650
|
const result = p0.add(p1);
|
5438
5651
|
return `0x${result.toHex(true)}`;
|
5439
5652
|
}
|
@@ -5445,16 +5658,16 @@ var Signer = class {
|
|
5445
5658
|
* @returns public key from signature from the
|
5446
5659
|
*/
|
5447
5660
|
static recoverPublicKey(data, signature) {
|
5448
|
-
const signedMessageBytes = (0,
|
5661
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5449
5662
|
const r = signedMessageBytes.slice(0, 32);
|
5450
5663
|
const s = signedMessageBytes.slice(32, 64);
|
5451
5664
|
const recoveryParam = (s[0] & 128) >> 7;
|
5452
5665
|
s[0] &= 127;
|
5453
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5666
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5454
5667
|
recoveryParam
|
5455
5668
|
);
|
5456
|
-
const publicKey = sig.recoverPublicKey((0,
|
5457
|
-
return (0,
|
5669
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5670
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5458
5671
|
}
|
5459
5672
|
/**
|
5460
5673
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5473,7 +5686,7 @@ var Signer = class {
|
|
5473
5686
|
* @returns random 32-byte hashed
|
5474
5687
|
*/
|
5475
5688
|
static generatePrivateKey(entropy) {
|
5476
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5689
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5477
5690
|
}
|
5478
5691
|
/**
|
5479
5692
|
* Extended publicKey from a compact publicKey
|
@@ -5482,8 +5695,8 @@ var Signer = class {
|
|
5482
5695
|
* @returns extended publicKey
|
5483
5696
|
*/
|
5484
5697
|
static extendPublicKey(publicKey) {
|
5485
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5486
|
-
return (0,
|
5698
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5699
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5487
5700
|
}
|
5488
5701
|
};
|
5489
5702
|
|
@@ -5491,7 +5704,7 @@ var Signer = class {
|
|
5491
5704
|
var import_address6 = require("@fuel-ts/address");
|
5492
5705
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5493
5706
|
var import_errors17 = require("@fuel-ts/errors");
|
5494
|
-
var
|
5707
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5495
5708
|
var import_uuid = require("uuid");
|
5496
5709
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5497
5710
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5574,7 +5787,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5574
5787
|
);
|
5575
5788
|
}
|
5576
5789
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5577
|
-
const privateKey = (0,
|
5790
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5578
5791
|
return privateKey;
|
5579
5792
|
}
|
5580
5793
|
|
@@ -5619,7 +5832,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5619
5832
|
*/
|
5620
5833
|
async signMessage(message) {
|
5621
5834
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5622
|
-
return (0,
|
5835
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5623
5836
|
}
|
5624
5837
|
/**
|
5625
5838
|
* Signs a transaction with the wallet's private key.
|
@@ -5632,7 +5845,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5632
5845
|
const chainId = this.provider.getChainId();
|
5633
5846
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5634
5847
|
const signature = await this.signer().sign(hashedTransaction);
|
5635
|
-
return (0,
|
5848
|
+
return (0, import_utils30.hexlify)(signature);
|
5636
5849
|
}
|
5637
5850
|
/**
|
5638
5851
|
* Populates a transaction with the witnesses signature.
|
@@ -5652,7 +5865,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5652
5865
|
* @param transactionRequestLike - The transaction request to send.
|
5653
5866
|
* @returns A promise that resolves to the TransactionResponse object.
|
5654
5867
|
*/
|
5655
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5868
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5656
5869
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5657
5870
|
if (estimateTxDependencies) {
|
5658
5871
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5693,15 +5906,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5693
5906
|
// src/hdwallet/hdwallet.ts
|
5694
5907
|
var import_errors20 = require("@fuel-ts/errors");
|
5695
5908
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5696
|
-
var
|
5697
|
-
var
|
5909
|
+
var import_math21 = require("@fuel-ts/math");
|
5910
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5698
5911
|
var import_ethers3 = require("ethers");
|
5699
5912
|
|
5700
5913
|
// src/mnemonic/mnemonic.ts
|
5701
5914
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5702
5915
|
var import_errors19 = require("@fuel-ts/errors");
|
5703
5916
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5704
|
-
var
|
5917
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5705
5918
|
var import_ethers2 = require("ethers");
|
5706
5919
|
|
5707
5920
|
// src/wordlists/words/english.ts
|
@@ -7765,7 +7978,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7765
7978
|
// src/mnemonic/utils.ts
|
7766
7979
|
var import_errors18 = require("@fuel-ts/errors");
|
7767
7980
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7768
|
-
var
|
7981
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7769
7982
|
function toUtf8Bytes(stri) {
|
7770
7983
|
const str = stri.normalize("NFKD");
|
7771
7984
|
const result = [];
|
@@ -7832,14 +8045,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7832
8045
|
}
|
7833
8046
|
}
|
7834
8047
|
const checksumBits = entropy.length / 4;
|
7835
|
-
const checksum = (0,
|
8048
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7836
8049
|
indices[indices.length - 1] <<= checksumBits;
|
7837
8050
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7838
8051
|
return indices;
|
7839
8052
|
}
|
7840
8053
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7841
8054
|
const size = Math.ceil(11 * words.length / 8);
|
7842
|
-
const entropy = (0,
|
8055
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7843
8056
|
let offset = 0;
|
7844
8057
|
for (let i = 0; i < words.length; i += 1) {
|
7845
8058
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7859,7 +8072,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7859
8072
|
const entropyBits = 32 * words.length / 3;
|
7860
8073
|
const checksumBits = words.length / 3;
|
7861
8074
|
const checksumMask = getUpperMask(checksumBits);
|
7862
|
-
const checksum = (0,
|
8075
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7863
8076
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7864
8077
|
throw new import_errors18.FuelError(
|
7865
8078
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7934,7 +8147,7 @@ var Mnemonic = class {
|
|
7934
8147
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7935
8148
|
const words = getWords(phrase);
|
7936
8149
|
assertMnemonic(words);
|
7937
|
-
return (0,
|
8150
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7938
8151
|
}
|
7939
8152
|
/**
|
7940
8153
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7942,7 +8155,7 @@ var Mnemonic = class {
|
|
7942
8155
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7943
8156
|
*/
|
7944
8157
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7945
|
-
const entropyBytes = (0,
|
8158
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7946
8159
|
assertWordList(wordlist);
|
7947
8160
|
assertEntropy(entropyBytes);
|
7948
8161
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -8011,14 +8224,14 @@ var Mnemonic = class {
|
|
8011
8224
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8012
8225
|
*/
|
8013
8226
|
static masterKeysFromSeed(seed) {
|
8014
|
-
const seedArray = (0,
|
8227
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
8015
8228
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8016
8229
|
throw new import_errors19.FuelError(
|
8017
8230
|
import_errors19.ErrorCode.INVALID_SEED,
|
8018
8231
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8019
8232
|
);
|
8020
8233
|
}
|
8021
|
-
return (0,
|
8234
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
8022
8235
|
}
|
8023
8236
|
/**
|
8024
8237
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8029,22 +8242,22 @@ var Mnemonic = class {
|
|
8029
8242
|
*/
|
8030
8243
|
static seedToExtendedKey(seed, testnet = false) {
|
8031
8244
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8032
|
-
const prefix = (0,
|
8245
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8033
8246
|
const depth = "0x00";
|
8034
8247
|
const fingerprint = "0x00000000";
|
8035
8248
|
const index = "0x00000000";
|
8036
8249
|
const chainCode = masterKey.slice(32);
|
8037
8250
|
const privateKey = masterKey.slice(0, 32);
|
8038
|
-
const extendedKey = (0,
|
8251
|
+
const extendedKey = (0, import_utils32.concat)([
|
8039
8252
|
prefix,
|
8040
8253
|
depth,
|
8041
8254
|
fingerprint,
|
8042
8255
|
index,
|
8043
8256
|
chainCode,
|
8044
|
-
(0,
|
8257
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
8045
8258
|
]);
|
8046
8259
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8047
|
-
return (0, import_ethers2.encodeBase58)((0,
|
8260
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
8048
8261
|
}
|
8049
8262
|
/**
|
8050
8263
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8059,7 +8272,7 @@ var Mnemonic = class {
|
|
8059
8272
|
* @returns A randomly generated mnemonic
|
8060
8273
|
*/
|
8061
8274
|
static generate(size = 32, extraEntropy = "") {
|
8062
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8275
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
8063
8276
|
return Mnemonic.entropyToMnemonic(entropy);
|
8064
8277
|
}
|
8065
8278
|
};
|
@@ -8067,12 +8280,12 @@ var mnemonic_default = Mnemonic;
|
|
8067
8280
|
|
8068
8281
|
// src/hdwallet/hdwallet.ts
|
8069
8282
|
var HARDENED_INDEX = 2147483648;
|
8070
|
-
var MainnetPRV2 = (0,
|
8071
|
-
var MainnetPUB = (0,
|
8072
|
-
var TestnetPRV2 = (0,
|
8073
|
-
var TestnetPUB = (0,
|
8283
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
8284
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
8285
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
8286
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
8074
8287
|
function base58check(data) {
|
8075
|
-
return (0, import_ethers3.encodeBase58)((0,
|
8288
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
8076
8289
|
}
|
8077
8290
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8078
8291
|
if (isPublic) {
|
@@ -8081,11 +8294,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8081
8294
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8082
8295
|
}
|
8083
8296
|
function isPublicExtendedKey(extendedKey) {
|
8084
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8297
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
8085
8298
|
}
|
8086
8299
|
function isValidExtendedKey(extendedKey) {
|
8087
8300
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8088
|
-
(0,
|
8301
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
8089
8302
|
);
|
8090
8303
|
}
|
8091
8304
|
function parsePath(path, depth = 0) {
|
@@ -8103,8 +8316,8 @@ function parsePath(path, depth = 0) {
|
|
8103
8316
|
var HDWallet = class {
|
8104
8317
|
depth = 0;
|
8105
8318
|
index = 0;
|
8106
|
-
fingerprint = (0,
|
8107
|
-
parentFingerprint = (0,
|
8319
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8320
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8108
8321
|
privateKey;
|
8109
8322
|
publicKey;
|
8110
8323
|
chainCode;
|
@@ -8116,8 +8329,8 @@ var HDWallet = class {
|
|
8116
8329
|
constructor(config) {
|
8117
8330
|
if (config.privateKey) {
|
8118
8331
|
const signer = new Signer(config.privateKey);
|
8119
|
-
this.publicKey = (0,
|
8120
|
-
this.privateKey = (0,
|
8332
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
8333
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
8121
8334
|
} else {
|
8122
8335
|
if (!config.publicKey) {
|
8123
8336
|
throw new import_errors20.FuelError(
|
@@ -8125,7 +8338,7 @@ var HDWallet = class {
|
|
8125
8338
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8126
8339
|
);
|
8127
8340
|
}
|
8128
|
-
this.publicKey = (0,
|
8341
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
8129
8342
|
}
|
8130
8343
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8131
8344
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -8144,9 +8357,9 @@ var HDWallet = class {
|
|
8144
8357
|
* @returns A new instance of HDWallet on the derived index
|
8145
8358
|
*/
|
8146
8359
|
deriveIndex(index) {
|
8147
|
-
const privateKey = this.privateKey && (0,
|
8148
|
-
const publicKey = (0,
|
8149
|
-
const chainCode = (0,
|
8360
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
8361
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
8362
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
8150
8363
|
const data = new Uint8Array(37);
|
8151
8364
|
if (index & HARDENED_INDEX) {
|
8152
8365
|
if (!privateKey) {
|
@@ -8157,15 +8370,15 @@ var HDWallet = class {
|
|
8157
8370
|
}
|
8158
8371
|
data.set(privateKey, 1);
|
8159
8372
|
} else {
|
8160
|
-
data.set((0,
|
8373
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
8161
8374
|
}
|
8162
|
-
data.set((0,
|
8163
|
-
const bytes = (0,
|
8375
|
+
data.set((0, import_math21.toBytes)(index, 4), 33);
|
8376
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
8164
8377
|
const IL = bytes.slice(0, 32);
|
8165
8378
|
const IR = bytes.slice(32);
|
8166
8379
|
if (privateKey) {
|
8167
8380
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8168
|
-
const ki = (0,
|
8381
|
+
const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8169
8382
|
return new HDWallet({
|
8170
8383
|
privateKey: ki,
|
8171
8384
|
chainCode: IR,
|
@@ -8174,7 +8387,7 @@ var HDWallet = class {
|
|
8174
8387
|
parentFingerprint: this.fingerprint
|
8175
8388
|
});
|
8176
8389
|
}
|
8177
|
-
const signer = new Signer((0,
|
8390
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
8178
8391
|
const Ki = signer.addPoint(publicKey);
|
8179
8392
|
return new HDWallet({
|
8180
8393
|
publicKey: Ki,
|
@@ -8209,12 +8422,12 @@ var HDWallet = class {
|
|
8209
8422
|
);
|
8210
8423
|
}
|
8211
8424
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8212
|
-
const depth = (0,
|
8425
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
8213
8426
|
const parentFingerprint = this.parentFingerprint;
|
8214
|
-
const index = (0,
|
8427
|
+
const index = (0, import_math21.toHex)(this.index, 4);
|
8215
8428
|
const chainCode = this.chainCode;
|
8216
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8217
|
-
const extendedKey = (0,
|
8429
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8430
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8218
8431
|
return base58check(extendedKey);
|
8219
8432
|
}
|
8220
8433
|
/**
|
@@ -8226,13 +8439,13 @@ var HDWallet = class {
|
|
8226
8439
|
static fromSeed(seed) {
|
8227
8440
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8228
8441
|
return new HDWallet({
|
8229
|
-
chainCode: (0,
|
8230
|
-
privateKey: (0,
|
8442
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
8443
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
8231
8444
|
});
|
8232
8445
|
}
|
8233
8446
|
static fromExtendedKey(extendedKey) {
|
8234
8447
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8235
|
-
const bytes = (0,
|
8448
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
8236
8449
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8237
8450
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8238
8451
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8241,9 +8454,9 @@ var HDWallet = class {
|
|
8241
8454
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8242
8455
|
}
|
8243
8456
|
const depth = bytes[4];
|
8244
|
-
const parentFingerprint = (0,
|
8245
|
-
const index = parseInt((0,
|
8246
|
-
const chainCode = (0,
|
8457
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8458
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8459
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
8247
8460
|
const key = bytes.slice(45, 78);
|
8248
8461
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8249
8462
|
throw new import_errors20.FuelError(
|
@@ -8846,20 +9059,21 @@ var StorageAbstract = class {
|
|
8846
9059
|
// src/predicate/predicate.ts
|
8847
9060
|
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
8848
9061
|
var import_address10 = require("@fuel-ts/address");
|
9062
|
+
var import_configs13 = require("@fuel-ts/address/configs");
|
8849
9063
|
var import_errors25 = require("@fuel-ts/errors");
|
8850
|
-
var
|
8851
|
-
var
|
9064
|
+
var import_transactions21 = require("@fuel-ts/transactions");
|
9065
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8852
9066
|
|
8853
9067
|
// src/predicate/utils/getPredicateRoot.ts
|
8854
9068
|
var import_hasher7 = require("@fuel-ts/hasher");
|
8855
9069
|
var import_merkle = require("@fuel-ts/merkle");
|
8856
|
-
var
|
9070
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8857
9071
|
var getPredicateRoot = (bytecode) => {
|
8858
9072
|
const chunkSize = 16 * 1024;
|
8859
|
-
const bytes = (0,
|
8860
|
-
const chunks = (0,
|
8861
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
8862
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
9073
|
+
const bytes = (0, import_utils35.arrayify)(bytecode);
|
9074
|
+
const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
|
9075
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
|
9076
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
|
8863
9077
|
return predicateRoot;
|
8864
9078
|
};
|
8865
9079
|
|
@@ -8907,9 +9121,9 @@ var Predicate = class extends Account {
|
|
8907
9121
|
const request = transactionRequestify(transactionRequestLike);
|
8908
9122
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8909
9123
|
request.inputs?.forEach((input) => {
|
8910
|
-
if (input.type ===
|
8911
|
-
input.predicate = this.bytes;
|
8912
|
-
input.predicateData = this.getPredicateData(policies.length);
|
9124
|
+
if (input.type === import_transactions21.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
|
9125
|
+
input.predicate = (0, import_utils36.hexlify)(this.bytes);
|
9126
|
+
input.predicateData = (0, import_utils36.hexlify)(this.getPredicateData(policies.length));
|
8913
9127
|
}
|
8914
9128
|
});
|
8915
9129
|
return request;
|
@@ -8923,10 +9137,8 @@ var Predicate = class extends Account {
|
|
8923
9137
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8924
9138
|
* @returns A promise that resolves to the prepared transaction request.
|
8925
9139
|
*/
|
8926
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
8927
|
-
|
8928
|
-
const request = await super.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
8929
|
-
return this.populateTransactionPredicateData(request);
|
9140
|
+
async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
|
9141
|
+
return super.createTransfer(destination, amount, assetId, txParams);
|
8930
9142
|
}
|
8931
9143
|
/**
|
8932
9144
|
* Sends a transaction with the populated predicate data.
|
@@ -8934,9 +9146,9 @@ var Predicate = class extends Account {
|
|
8934
9146
|
* @param transactionRequestLike - The transaction request-like object.
|
8935
9147
|
* @returns A promise that resolves to the transaction response.
|
8936
9148
|
*/
|
8937
|
-
sendTransaction(transactionRequestLike
|
8938
|
-
const transactionRequest =
|
8939
|
-
return super.sendTransaction(transactionRequest,
|
9149
|
+
sendTransaction(transactionRequestLike) {
|
9150
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9151
|
+
return super.sendTransaction(transactionRequest, { estimateTxDependencies: false });
|
8940
9152
|
}
|
8941
9153
|
/**
|
8942
9154
|
* Simulates a transaction with the populated predicate data.
|
@@ -8945,15 +9157,15 @@ var Predicate = class extends Account {
|
|
8945
9157
|
* @returns A promise that resolves to the call result.
|
8946
9158
|
*/
|
8947
9159
|
simulateTransaction(transactionRequestLike) {
|
8948
|
-
const transactionRequest =
|
8949
|
-
return super.simulateTransaction(transactionRequest);
|
9160
|
+
const transactionRequest = transactionRequestify(transactionRequestLike);
|
9161
|
+
return super.simulateTransaction(transactionRequest, { estimateTxDependencies: false });
|
8950
9162
|
}
|
8951
9163
|
getPredicateData(policiesLength) {
|
8952
9164
|
if (!this.predicateData.length) {
|
8953
9165
|
return new Uint8Array();
|
8954
9166
|
}
|
8955
9167
|
const mainFn = this.interface?.functions.main;
|
8956
|
-
const paddedCode = new
|
9168
|
+
const paddedCode = new import_transactions21.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
8957
9169
|
const VM_TX_MEMORY = (0, import_abi_coder7.calculateVmTxMemory)({
|
8958
9170
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
8959
9171
|
});
|
@@ -8969,7 +9181,7 @@ var Predicate = class extends Account {
|
|
8969
9181
|
* @returns An object containing the new predicate bytes and interface.
|
8970
9182
|
*/
|
8971
9183
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
8972
|
-
let predicateBytes = (0,
|
9184
|
+
let predicateBytes = (0, import_utils36.arrayify)(bytes);
|
8973
9185
|
let abiInterface;
|
8974
9186
|
if (jsonAbi) {
|
8975
9187
|
abiInterface = new import_abi_coder7.Interface(jsonAbi);
|
@@ -8992,6 +9204,25 @@ var Predicate = class extends Account {
|
|
8992
9204
|
predicateInterface: abiInterface
|
8993
9205
|
};
|
8994
9206
|
}
|
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
|
+
}
|
8995
9226
|
/**
|
8996
9227
|
* Sets the configurable constants for the predicate.
|
8997
9228
|
*
|
@@ -9741,7 +9972,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9741
9972
|
WalletLocked,
|
9742
9973
|
WalletManager,
|
9743
9974
|
WalletUnlocked,
|
9744
|
-
|
9975
|
+
addAmountToCoinQuantities,
|
9745
9976
|
addOperation,
|
9746
9977
|
assemblePanicError,
|
9747
9978
|
assembleReceiptByType,
|
@@ -9750,9 +9981,10 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9750
9981
|
assets,
|
9751
9982
|
buildBlockExplorerUrl,
|
9752
9983
|
cacheFor,
|
9984
|
+
cacheTxInputsFromOwner,
|
9985
|
+
calculateGasFee,
|
9753
9986
|
calculateMetadataGasForTxCreate,
|
9754
9987
|
calculateMetadataGasForTxScript,
|
9755
|
-
calculatePriceWithFactor,
|
9756
9988
|
calculateTransactionFee,
|
9757
9989
|
coinQuantityfy,
|
9758
9990
|
deferPromise,
|