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