@fuel-ts/account 0.0.0-rc-2021-20240409151049 → 0.0.0-rc-2034-20240410011904
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 +623 -868
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +525 -759
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +406 -639
- 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 +328 -894
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -3
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +31 -36
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +25 -8
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1122 -1582
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +521 -735
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +415 -629
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/index.js
CHANGED
@@ -95,7 +95,7 @@ __export(src_exports, {
|
|
95
95
|
WalletLocked: () => WalletLocked,
|
96
96
|
WalletManager: () => WalletManager,
|
97
97
|
WalletUnlocked: () => WalletUnlocked,
|
98
|
-
|
98
|
+
addAmountToAsset: () => addAmountToAsset,
|
99
99
|
addOperation: () => addOperation,
|
100
100
|
assemblePanicError: () => assemblePanicError,
|
101
101
|
assembleReceiptByType: () => assembleReceiptByType,
|
@@ -104,10 +104,9 @@ __export(src_exports, {
|
|
104
104
|
assets: () => assets,
|
105
105
|
buildBlockExplorerUrl: () => buildBlockExplorerUrl,
|
106
106
|
cacheFor: () => cacheFor,
|
107
|
-
cacheTxInputsFromOwner: () => cacheTxInputsFromOwner,
|
108
|
-
calculateGasFee: () => calculateGasFee,
|
109
107
|
calculateMetadataGasForTxCreate: () => calculateMetadataGasForTxCreate,
|
110
108
|
calculateMetadataGasForTxScript: () => calculateMetadataGasForTxScript,
|
109
|
+
calculatePriceWithFactor: () => calculatePriceWithFactor,
|
111
110
|
calculateTransactionFee: () => calculateTransactionFee,
|
112
111
|
coinQuantityfy: () => coinQuantityfy,
|
113
112
|
deferPromise: () => deferPromise,
|
@@ -188,9 +187,8 @@ var import_address4 = require("@fuel-ts/address");
|
|
188
187
|
var import_configs12 = require("@fuel-ts/address/configs");
|
189
188
|
var import_errors16 = require("@fuel-ts/errors");
|
190
189
|
var import_interfaces = require("@fuel-ts/interfaces");
|
191
|
-
var
|
192
|
-
var
|
193
|
-
var import_ramda4 = require("ramda");
|
190
|
+
var import_math18 = require("@fuel-ts/math");
|
191
|
+
var import_utils28 = require("@fuel-ts/utils");
|
194
192
|
|
195
193
|
// src/providers/coin-quantity.ts
|
196
194
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -199,24 +197,24 @@ var import_utils = require("@fuel-ts/utils");
|
|
199
197
|
var coinQuantityfy = (coinQuantityLike) => {
|
200
198
|
let assetId;
|
201
199
|
let amount;
|
202
|
-
let
|
200
|
+
let max2;
|
203
201
|
if (Array.isArray(coinQuantityLike)) {
|
204
202
|
amount = coinQuantityLike[0];
|
205
203
|
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
206
|
-
|
204
|
+
max2 = coinQuantityLike[2] ?? void 0;
|
207
205
|
} else {
|
208
206
|
amount = coinQuantityLike.amount;
|
209
207
|
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
210
|
-
|
208
|
+
max2 = coinQuantityLike.max ?? void 0;
|
211
209
|
}
|
212
210
|
const bnAmount = (0, import_math.bn)(amount);
|
213
211
|
return {
|
214
212
|
assetId: (0, import_utils.hexlify)(assetId),
|
215
213
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
216
|
-
max:
|
214
|
+
max: max2 ? (0, import_math.bn)(max2) : void 0
|
217
215
|
};
|
218
216
|
};
|
219
|
-
var
|
217
|
+
var addAmountToAsset = (params) => {
|
220
218
|
const { amount, assetId } = params;
|
221
219
|
const coinQuantities = [...params.coinQuantities];
|
222
220
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -231,11 +229,11 @@ var addAmountToCoinQuantities = (params) => {
|
|
231
229
|
// src/providers/provider.ts
|
232
230
|
var import_address3 = require("@fuel-ts/address");
|
233
231
|
var import_errors14 = require("@fuel-ts/errors");
|
234
|
-
var
|
235
|
-
var
|
236
|
-
var
|
232
|
+
var import_math15 = require("@fuel-ts/math");
|
233
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
234
|
+
var import_utils23 = require("@fuel-ts/utils");
|
237
235
|
var import_versions = require("@fuel-ts/versions");
|
238
|
-
var
|
236
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
239
237
|
var import_ethers2 = require("ethers");
|
240
238
|
var import_graphql_request = require("graphql-request");
|
241
239
|
var import_ramda3 = require("ramda");
|
@@ -244,10 +242,14 @@ var import_ramda3 = require("ramda");
|
|
244
242
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
245
243
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
246
244
|
fragment receiptFragment on Receipt {
|
247
|
-
|
245
|
+
contract {
|
246
|
+
id
|
247
|
+
}
|
248
248
|
pc
|
249
249
|
is
|
250
|
-
to
|
250
|
+
to {
|
251
|
+
id
|
252
|
+
}
|
251
253
|
toAddress
|
252
254
|
amount
|
253
255
|
assetId
|
@@ -285,16 +287,10 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
285
287
|
id
|
286
288
|
}
|
287
289
|
time
|
288
|
-
receipts {
|
289
|
-
...receiptFragment
|
290
|
-
}
|
291
290
|
programState {
|
292
291
|
returnType
|
293
292
|
data
|
294
293
|
}
|
295
|
-
receipts {
|
296
|
-
...receiptFragment
|
297
|
-
}
|
298
294
|
}
|
299
295
|
... on FailureStatus {
|
300
296
|
block {
|
@@ -302,24 +298,26 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
302
298
|
}
|
303
299
|
time
|
304
300
|
reason
|
305
|
-
receipts {
|
306
|
-
...receiptFragment
|
307
|
-
}
|
308
301
|
}
|
309
302
|
... on SqueezedOutStatus {
|
310
303
|
reason
|
311
304
|
}
|
312
305
|
}
|
313
|
-
|
306
|
+
`;
|
314
307
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
315
308
|
fragment transactionFragment on Transaction {
|
316
309
|
id
|
317
310
|
rawPayload
|
311
|
+
gasPrice
|
312
|
+
receipts {
|
313
|
+
...receiptFragment
|
314
|
+
}
|
318
315
|
status {
|
319
316
|
...transactionStatusFragment
|
320
317
|
}
|
321
318
|
}
|
322
|
-
${
|
319
|
+
${ReceiptFragmentFragmentDoc}
|
320
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
323
321
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
324
322
|
fragment inputEstimatePredicatesFragment on Input {
|
325
323
|
... on InputCoin {
|
@@ -337,46 +335,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
337
335
|
}
|
338
336
|
}
|
339
337
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
340
|
-
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
341
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
342
|
-
reason
|
343
|
-
programState {
|
344
|
-
returnType
|
345
|
-
data
|
346
|
-
}
|
347
|
-
}
|
348
|
-
`;
|
349
|
-
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
350
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
351
|
-
programState {
|
352
|
-
returnType
|
353
|
-
data
|
354
|
-
}
|
355
|
-
}
|
356
|
-
`;
|
357
|
-
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
358
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
359
|
-
... on DryRunFailureStatus {
|
360
|
-
...dryRunFailureStatusFragment
|
361
|
-
}
|
362
|
-
... on DryRunSuccessStatus {
|
363
|
-
...dryRunSuccessStatusFragment
|
364
|
-
}
|
365
|
-
}
|
366
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
367
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
368
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
369
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
370
|
-
id
|
371
|
-
status {
|
372
|
-
...dryRunTransactionStatusFragment
|
373
|
-
}
|
374
|
-
receipts {
|
375
|
-
...receiptFragment
|
376
|
-
}
|
377
|
-
}
|
378
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
379
|
-
${ReceiptFragmentFragmentDoc}`;
|
380
338
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
381
339
|
fragment coinFragment on Coin {
|
382
340
|
__typename
|
@@ -384,6 +342,7 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
384
342
|
owner
|
385
343
|
amount
|
386
344
|
assetId
|
345
|
+
maturity
|
387
346
|
blockCreated
|
388
347
|
txCreatedIdx
|
389
348
|
}
|
@@ -428,6 +387,7 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
428
387
|
prevRoot
|
429
388
|
time
|
430
389
|
applicationHash
|
390
|
+
messageReceiptRoot
|
431
391
|
messageReceiptCount
|
432
392
|
}
|
433
393
|
commitBlockHeader {
|
@@ -439,6 +399,7 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
439
399
|
prevRoot
|
440
400
|
time
|
441
401
|
applicationHash
|
402
|
+
messageReceiptRoot
|
442
403
|
messageReceiptCount
|
443
404
|
}
|
444
405
|
sender
|
@@ -458,8 +419,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
458
419
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
459
420
|
fragment blockFragment on Block {
|
460
421
|
id
|
461
|
-
height
|
462
422
|
header {
|
423
|
+
height
|
463
424
|
time
|
464
425
|
}
|
465
426
|
transactions {
|
@@ -517,11 +478,6 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
517
478
|
`;
|
518
479
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
519
480
|
fragment GasCostsFragment on GasCosts {
|
520
|
-
version {
|
521
|
-
... on Version {
|
522
|
-
value
|
523
|
-
}
|
524
|
-
}
|
525
481
|
add
|
526
482
|
addi
|
527
483
|
aloc
|
@@ -534,6 +490,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
534
490
|
cb
|
535
491
|
cfei
|
536
492
|
cfsi
|
493
|
+
croo
|
537
494
|
div
|
538
495
|
divi
|
539
496
|
ecr1
|
@@ -616,9 +573,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
616
573
|
ccp {
|
617
574
|
...DependentCostFragment
|
618
575
|
}
|
619
|
-
croo {
|
620
|
-
...DependentCostFragment
|
621
|
-
}
|
622
576
|
csiz {
|
623
577
|
...DependentCostFragment
|
624
578
|
}
|
@@ -678,11 +632,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
678
632
|
${DependentCostFragmentFragmentDoc}`;
|
679
633
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
680
634
|
fragment consensusParametersFragment on ConsensusParameters {
|
681
|
-
version {
|
682
|
-
... on Version {
|
683
|
-
value
|
684
|
-
}
|
685
|
-
}
|
686
635
|
txParams {
|
687
636
|
...TxParametersFragment
|
688
637
|
}
|
@@ -742,9 +691,18 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
742
691
|
fragment nodeInfoFragment on NodeInfo {
|
743
692
|
utxoValidation
|
744
693
|
vmBacktrace
|
694
|
+
minGasPrice
|
745
695
|
maxTx
|
746
696
|
maxDepth
|
747
697
|
nodeVersion
|
698
|
+
peers {
|
699
|
+
id
|
700
|
+
addresses
|
701
|
+
clientVersion
|
702
|
+
blockHeight
|
703
|
+
lastHeartbeatMs
|
704
|
+
appScore
|
705
|
+
}
|
748
706
|
}
|
749
707
|
`;
|
750
708
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -779,9 +737,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
779
737
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
780
738
|
transaction(id: $transactionId) {
|
781
739
|
...transactionFragment
|
740
|
+
receipts {
|
741
|
+
...receiptFragment
|
742
|
+
}
|
782
743
|
}
|
783
744
|
}
|
784
|
-
${TransactionFragmentFragmentDoc}
|
745
|
+
${TransactionFragmentFragmentDoc}
|
746
|
+
${ReceiptFragmentFragmentDoc}`;
|
785
747
|
var GetTransactionsDocument = import_graphql_tag.default`
|
786
748
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
787
749
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -909,20 +871,6 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
909
871
|
}
|
910
872
|
}
|
911
873
|
${BalanceFragmentFragmentDoc}`;
|
912
|
-
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
913
|
-
query getLatestGasPrice {
|
914
|
-
latestGasPrice {
|
915
|
-
gasPrice
|
916
|
-
}
|
917
|
-
}
|
918
|
-
`;
|
919
|
-
var EstimateGasPriceDocument = import_graphql_tag.default`
|
920
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
921
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
922
|
-
gasPrice
|
923
|
-
}
|
924
|
-
}
|
925
|
-
`;
|
926
874
|
var GetBalancesDocument = import_graphql_tag.default`
|
927
875
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
928
876
|
balances(
|
@@ -977,12 +925,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
977
925
|
}
|
978
926
|
`;
|
979
927
|
var DryRunDocument = import_graphql_tag.default`
|
980
|
-
mutation dryRun($
|
981
|
-
dryRun(
|
982
|
-
...
|
928
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
929
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
930
|
+
...receiptFragment
|
983
931
|
}
|
984
932
|
}
|
985
|
-
${
|
933
|
+
${ReceiptFragmentFragmentDoc}`;
|
986
934
|
var SubmitDocument = import_graphql_tag.default`
|
987
935
|
mutation submit($encodedTransaction: HexString!) {
|
988
936
|
submit(tx: $encodedTransaction) {
|
@@ -1065,12 +1013,6 @@ function getSdk(requester) {
|
|
1065
1013
|
getBalance(variables, options) {
|
1066
1014
|
return requester(GetBalanceDocument, variables, options);
|
1067
1015
|
},
|
1068
|
-
getLatestGasPrice(variables, options) {
|
1069
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
1070
|
-
},
|
1071
|
-
estimateGasPrice(variables, options) {
|
1072
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
1073
|
-
},
|
1074
1016
|
getBalances(variables, options) {
|
1075
1017
|
return requester(GetBalancesDocument, variables, options);
|
1076
1018
|
},
|
@@ -1140,14 +1082,11 @@ var _FuelGraphqlSubscriber = class {
|
|
1140
1082
|
let data;
|
1141
1083
|
let errors;
|
1142
1084
|
try {
|
1143
|
-
|
1144
|
-
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
1085
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
1145
1086
|
} catch (e) {
|
1146
1087
|
throw new import_errors.FuelError(
|
1147
1088
|
import_errors.ErrorCode.STREAM_PARSING_ERROR,
|
1148
|
-
`Error while parsing stream data response: ${text}
|
1149
|
-
|
1150
|
-
Thrown error: ${e}`
|
1089
|
+
`Error while parsing stream data response: ${text}`
|
1151
1090
|
);
|
1152
1091
|
}
|
1153
1092
|
if (Array.isArray(errors)) {
|
@@ -1248,7 +1187,7 @@ var inputify = (value) => {
|
|
1248
1187
|
return {
|
1249
1188
|
type: import_transactions.InputType.Coin,
|
1250
1189
|
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
|
1251
|
-
outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(32,
|
1190
|
+
outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(32, 33)),
|
1252
1191
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1253
1192
|
amount: (0, import_math2.bn)(value.amount),
|
1254
1193
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1257,9 +1196,10 @@ var inputify = (value) => {
|
|
1257
1196
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1258
1197
|
},
|
1259
1198
|
witnessIndex: value.witnessIndex,
|
1199
|
+
maturity: value.maturity ?? 0,
|
1260
1200
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1261
|
-
predicateLength:
|
1262
|
-
predicateDataLength:
|
1201
|
+
predicateLength: predicate.length,
|
1202
|
+
predicateDataLength: predicateData.length,
|
1263
1203
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1264
1204
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1265
1205
|
};
|
@@ -1290,8 +1230,8 @@ var inputify = (value) => {
|
|
1290
1230
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1291
1231
|
witnessIndex: value.witnessIndex,
|
1292
1232
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1293
|
-
predicateLength:
|
1294
|
-
predicateDataLength:
|
1233
|
+
predicateLength: predicate.length,
|
1234
|
+
predicateDataLength: predicateData.length,
|
1295
1235
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1296
1236
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1297
1237
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1409,8 +1349,8 @@ function assembleReceiptByType(receipt) {
|
|
1409
1349
|
case "CALL" /* Call */: {
|
1410
1350
|
const callReceipt = {
|
1411
1351
|
type: import_transactions3.ReceiptType.Call,
|
1412
|
-
from: hexOrZero(receipt.id
|
1413
|
-
to: hexOrZero(receipt?.to),
|
1352
|
+
from: hexOrZero(receipt.contract?.id),
|
1353
|
+
to: hexOrZero(receipt?.to?.id),
|
1414
1354
|
amount: (0, import_math4.bn)(receipt.amount),
|
1415
1355
|
assetId: hexOrZero(receipt.assetId),
|
1416
1356
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1424,7 +1364,7 @@ function assembleReceiptByType(receipt) {
|
|
1424
1364
|
case "RETURN" /* Return */: {
|
1425
1365
|
const returnReceipt = {
|
1426
1366
|
type: import_transactions3.ReceiptType.Return,
|
1427
|
-
id: hexOrZero(receipt.id
|
1367
|
+
id: hexOrZero(receipt.contract?.id),
|
1428
1368
|
val: (0, import_math4.bn)(receipt.val),
|
1429
1369
|
pc: (0, import_math4.bn)(receipt.pc),
|
1430
1370
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1434,7 +1374,7 @@ function assembleReceiptByType(receipt) {
|
|
1434
1374
|
case "RETURN_DATA" /* ReturnData */: {
|
1435
1375
|
const returnDataReceipt = {
|
1436
1376
|
type: import_transactions3.ReceiptType.ReturnData,
|
1437
|
-
id: hexOrZero(receipt.id
|
1377
|
+
id: hexOrZero(receipt.contract?.id),
|
1438
1378
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1439
1379
|
len: (0, import_math4.bn)(receipt.len),
|
1440
1380
|
digest: hexOrZero(receipt.digest),
|
@@ -1446,7 +1386,7 @@ function assembleReceiptByType(receipt) {
|
|
1446
1386
|
case "PANIC" /* Panic */: {
|
1447
1387
|
const panicReceipt = {
|
1448
1388
|
type: import_transactions3.ReceiptType.Panic,
|
1449
|
-
id: hexOrZero(receipt.id),
|
1389
|
+
id: hexOrZero(receipt.contract?.id),
|
1450
1390
|
reason: (0, import_math4.bn)(receipt.reason),
|
1451
1391
|
pc: (0, import_math4.bn)(receipt.pc),
|
1452
1392
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1457,7 +1397,7 @@ function assembleReceiptByType(receipt) {
|
|
1457
1397
|
case "REVERT" /* Revert */: {
|
1458
1398
|
const revertReceipt = {
|
1459
1399
|
type: import_transactions3.ReceiptType.Revert,
|
1460
|
-
id: hexOrZero(receipt.id
|
1400
|
+
id: hexOrZero(receipt.contract?.id),
|
1461
1401
|
val: (0, import_math4.bn)(receipt.ra),
|
1462
1402
|
pc: (0, import_math4.bn)(receipt.pc),
|
1463
1403
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1467,7 +1407,7 @@ function assembleReceiptByType(receipt) {
|
|
1467
1407
|
case "LOG" /* Log */: {
|
1468
1408
|
const logReceipt = {
|
1469
1409
|
type: import_transactions3.ReceiptType.Log,
|
1470
|
-
id: hexOrZero(receipt.id
|
1410
|
+
id: hexOrZero(receipt.contract?.id),
|
1471
1411
|
val0: (0, import_math4.bn)(receipt.ra),
|
1472
1412
|
val1: (0, import_math4.bn)(receipt.rb),
|
1473
1413
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1480,7 +1420,7 @@ function assembleReceiptByType(receipt) {
|
|
1480
1420
|
case "LOG_DATA" /* LogData */: {
|
1481
1421
|
const logDataReceipt = {
|
1482
1422
|
type: import_transactions3.ReceiptType.LogData,
|
1483
|
-
id: hexOrZero(receipt.id
|
1423
|
+
id: hexOrZero(receipt.contract?.id),
|
1484
1424
|
val0: (0, import_math4.bn)(receipt.ra),
|
1485
1425
|
val1: (0, import_math4.bn)(receipt.rb),
|
1486
1426
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1494,8 +1434,8 @@ function assembleReceiptByType(receipt) {
|
|
1494
1434
|
case "TRANSFER" /* Transfer */: {
|
1495
1435
|
const transferReceipt = {
|
1496
1436
|
type: import_transactions3.ReceiptType.Transfer,
|
1497
|
-
from: hexOrZero(receipt.id
|
1498
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1437
|
+
from: hexOrZero(receipt.contract?.id),
|
1438
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1499
1439
|
amount: (0, import_math4.bn)(receipt.amount),
|
1500
1440
|
assetId: hexOrZero(receipt.assetId),
|
1501
1441
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1506,8 +1446,8 @@ function assembleReceiptByType(receipt) {
|
|
1506
1446
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1507
1447
|
const transferOutReceipt = {
|
1508
1448
|
type: import_transactions3.ReceiptType.TransferOut,
|
1509
|
-
from: hexOrZero(receipt.id
|
1510
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1449
|
+
from: hexOrZero(receipt.contract?.id),
|
1450
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1511
1451
|
amount: (0, import_math4.bn)(receipt.amount),
|
1512
1452
|
assetId: hexOrZero(receipt.assetId),
|
1513
1453
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1550,7 +1490,7 @@ function assembleReceiptByType(receipt) {
|
|
1550
1490
|
return receiptMessageOut;
|
1551
1491
|
}
|
1552
1492
|
case "MINT" /* Mint */: {
|
1553
|
-
const contractId = hexOrZero(receipt.id
|
1493
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1554
1494
|
const subId = hexOrZero(receipt.subId);
|
1555
1495
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1556
1496
|
const mintReceipt = {
|
@@ -1565,7 +1505,7 @@ function assembleReceiptByType(receipt) {
|
|
1565
1505
|
return mintReceipt;
|
1566
1506
|
}
|
1567
1507
|
case "BURN" /* Burn */: {
|
1568
|
-
const contractId = hexOrZero(receipt.id
|
1508
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1569
1509
|
const subId = hexOrZero(receipt.subId);
|
1570
1510
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1571
1511
|
const burnReceipt = {
|
@@ -1650,6 +1590,7 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1650
1590
|
var import_math5 = require("@fuel-ts/math");
|
1651
1591
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1652
1592
|
var import_utils6 = require("@fuel-ts/utils");
|
1593
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1653
1594
|
var getGasUsedFromReceipts = (receipts) => {
|
1654
1595
|
const scriptResult = receipts.filter(
|
1655
1596
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1670,28 +1611,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1670
1611
|
}
|
1671
1612
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1672
1613
|
const witnessCache = [];
|
1673
|
-
const
|
1674
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1675
|
-
if (isCoinOrMessage) {
|
1676
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1677
|
-
return true;
|
1678
|
-
}
|
1679
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1680
|
-
witnessCache.push(input.witnessIndex);
|
1681
|
-
return true;
|
1682
|
-
}
|
1683
|
-
}
|
1684
|
-
return false;
|
1685
|
-
});
|
1686
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1687
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1614
|
+
const totalGas = inputs.reduce((total, input) => {
|
1688
1615
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1689
1616
|
return total.add(
|
1690
|
-
|
1617
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1691
1618
|
);
|
1692
1619
|
}
|
1693
|
-
|
1694
|
-
|
1620
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1621
|
+
witnessCache.push(input.witnessIndex);
|
1622
|
+
return total.add(gasCosts.ecr1);
|
1623
|
+
}
|
1624
|
+
return total;
|
1625
|
+
}, (0, import_math5.bn)());
|
1695
1626
|
return totalGas;
|
1696
1627
|
}
|
1697
1628
|
function getMinGas(params) {
|
@@ -1703,20 +1634,12 @@ function getMinGas(params) {
|
|
1703
1634
|
return minGas;
|
1704
1635
|
}
|
1705
1636
|
function getMaxGas(params) {
|
1706
|
-
const {
|
1707
|
-
gasPerByte,
|
1708
|
-
witnessesLength,
|
1709
|
-
witnessLimit,
|
1710
|
-
minGas,
|
1711
|
-
gasLimit = (0, import_math5.bn)(0),
|
1712
|
-
maxGasPerTx
|
1713
|
-
} = params;
|
1637
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
|
1714
1638
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1715
1639
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1716
1640
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1717
1641
|
}
|
1718
|
-
|
1719
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1642
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1720
1643
|
}
|
1721
1644
|
function calculateMetadataGasForTxCreate({
|
1722
1645
|
gasCosts,
|
@@ -1738,10 +1661,6 @@ function calculateMetadataGasForTxScript({
|
|
1738
1661
|
}) {
|
1739
1662
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1740
1663
|
}
|
1741
|
-
var calculateGasFee = (params) => {
|
1742
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1743
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1744
|
-
};
|
1745
1664
|
|
1746
1665
|
// src/providers/utils/json.ts
|
1747
1666
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1890,7 +1809,7 @@ var witnessify = (value) => {
|
|
1890
1809
|
// src/providers/transaction-request/transaction-request.ts
|
1891
1810
|
var BaseTransactionRequest = class {
|
1892
1811
|
/** Gas price for transaction */
|
1893
|
-
|
1812
|
+
gasPrice;
|
1894
1813
|
/** Block until which tx cannot be included */
|
1895
1814
|
maturity;
|
1896
1815
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1909,7 +1828,7 @@ var BaseTransactionRequest = class {
|
|
1909
1828
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1910
1829
|
*/
|
1911
1830
|
constructor({
|
1912
|
-
|
1831
|
+
gasPrice,
|
1913
1832
|
maturity,
|
1914
1833
|
maxFee,
|
1915
1834
|
witnessLimit,
|
@@ -1917,7 +1836,7 @@ var BaseTransactionRequest = class {
|
|
1917
1836
|
outputs,
|
1918
1837
|
witnesses
|
1919
1838
|
} = {}) {
|
1920
|
-
this.
|
1839
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1921
1840
|
this.maturity = maturity ?? 0;
|
1922
1841
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1923
1842
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1928,9 +1847,9 @@ var BaseTransactionRequest = class {
|
|
1928
1847
|
static getPolicyMeta(req) {
|
1929
1848
|
let policyTypes = 0;
|
1930
1849
|
const policies = [];
|
1931
|
-
if (req.
|
1932
|
-
policyTypes += import_transactions6.PolicyType.
|
1933
|
-
policies.push({ data: req.
|
1850
|
+
if (req.gasPrice) {
|
1851
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1852
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1934
1853
|
}
|
1935
1854
|
if (req.witnessLimit) {
|
1936
1855
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -2117,10 +2036,10 @@ var BaseTransactionRequest = class {
|
|
2117
2036
|
* @param predicate - Predicate bytes.
|
2118
2037
|
* @param predicateData - Predicate data bytes.
|
2119
2038
|
*/
|
2120
|
-
addCoinInput(coin) {
|
2039
|
+
addCoinInput(coin, predicate) {
|
2121
2040
|
const { assetId, owner, amount } = coin;
|
2122
2041
|
let witnessIndex;
|
2123
|
-
if (
|
2042
|
+
if (predicate) {
|
2124
2043
|
witnessIndex = 0;
|
2125
2044
|
} else {
|
2126
2045
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -2135,7 +2054,9 @@ var BaseTransactionRequest = class {
|
|
2135
2054
|
amount,
|
2136
2055
|
assetId,
|
2137
2056
|
txPointer: "0x00000000000000000000000000000000",
|
2138
|
-
witnessIndex
|
2057
|
+
witnessIndex,
|
2058
|
+
predicate: predicate?.bytes,
|
2059
|
+
predicateData: predicate?.predicateDataBytes
|
2139
2060
|
};
|
2140
2061
|
this.pushInput(input);
|
2141
2062
|
this.addChangeOutput(owner, assetId);
|
@@ -2148,11 +2069,11 @@ var BaseTransactionRequest = class {
|
|
2148
2069
|
* @param predicate - Predicate bytes.
|
2149
2070
|
* @param predicateData - Predicate data bytes.
|
2150
2071
|
*/
|
2151
|
-
addMessageInput(message) {
|
2072
|
+
addMessageInput(message, predicate) {
|
2152
2073
|
const { recipient, sender, amount } = message;
|
2153
2074
|
const assetId = import_configs7.BaseAssetId;
|
2154
2075
|
let witnessIndex;
|
2155
|
-
if (
|
2076
|
+
if (predicate) {
|
2156
2077
|
witnessIndex = 0;
|
2157
2078
|
} else {
|
2158
2079
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2166,7 +2087,9 @@ var BaseTransactionRequest = class {
|
|
2166
2087
|
sender: sender.toB256(),
|
2167
2088
|
recipient: recipient.toB256(),
|
2168
2089
|
amount,
|
2169
|
-
witnessIndex
|
2090
|
+
witnessIndex,
|
2091
|
+
predicate: predicate?.bytes,
|
2092
|
+
predicateData: predicate?.predicateDataBytes
|
2170
2093
|
};
|
2171
2094
|
this.pushInput(input);
|
2172
2095
|
this.addChangeOutput(recipient, assetId);
|
@@ -2197,6 +2120,32 @@ var BaseTransactionRequest = class {
|
|
2197
2120
|
resources.forEach((resource) => this.addResource(resource));
|
2198
2121
|
return this;
|
2199
2122
|
}
|
2123
|
+
/**
|
2124
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
2125
|
+
* outputs from the related assetIds.
|
2126
|
+
*
|
2127
|
+
* @param resources - The resources to add.
|
2128
|
+
* @returns This transaction.
|
2129
|
+
*/
|
2130
|
+
addPredicateResource(resource, predicate) {
|
2131
|
+
if (isCoin(resource)) {
|
2132
|
+
this.addCoinInput(resource, predicate);
|
2133
|
+
} else {
|
2134
|
+
this.addMessageInput(resource, predicate);
|
2135
|
+
}
|
2136
|
+
return this;
|
2137
|
+
}
|
2138
|
+
/**
|
2139
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2140
|
+
* from the related assetIds.
|
2141
|
+
*
|
2142
|
+
* @param resources - The resources to add.
|
2143
|
+
* @returns This transaction.
|
2144
|
+
*/
|
2145
|
+
addPredicateResources(resources, predicate) {
|
2146
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2147
|
+
return this;
|
2148
|
+
}
|
2200
2149
|
/**
|
2201
2150
|
* Adds a coin output to the transaction.
|
2202
2151
|
*
|
@@ -2276,7 +2225,7 @@ var BaseTransactionRequest = class {
|
|
2276
2225
|
}
|
2277
2226
|
calculateMaxGas(chainInfo, minGas) {
|
2278
2227
|
const { consensusParameters } = chainInfo;
|
2279
|
-
const { gasPerByte
|
2228
|
+
const { gasPerByte } = consensusParameters;
|
2280
2229
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2281
2230
|
(acc, wit) => acc + wit.dataLength,
|
2282
2231
|
0
|
@@ -2285,8 +2234,7 @@ var BaseTransactionRequest = class {
|
|
2285
2234
|
gasPerByte,
|
2286
2235
|
minGas,
|
2287
2236
|
witnessesLength,
|
2288
|
-
witnessLimit: this.witnessLimit
|
2289
|
-
maxGasPerTx
|
2237
|
+
witnessLimit: this.witnessLimit
|
2290
2238
|
});
|
2291
2239
|
}
|
2292
2240
|
/**
|
@@ -2304,20 +2252,17 @@ var BaseTransactionRequest = class {
|
|
2304
2252
|
});
|
2305
2253
|
const updateAssetInput = (assetId, quantity) => {
|
2306
2254
|
const assetInput = findAssetInput(assetId);
|
2307
|
-
let usedQuantity = quantity;
|
2308
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2309
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2310
|
-
}
|
2311
2255
|
if (assetInput && "assetId" in assetInput) {
|
2312
|
-
assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(
|
2313
|
-
assetInput.amount =
|
2256
|
+
assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(33));
|
2257
|
+
assetInput.amount = quantity;
|
2314
2258
|
} else {
|
2315
2259
|
this.addResources([
|
2316
2260
|
{
|
2317
|
-
id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(
|
2318
|
-
amount:
|
2261
|
+
id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(33)),
|
2262
|
+
amount: quantity,
|
2319
2263
|
assetId,
|
2320
2264
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2265
|
+
maturity: 0,
|
2321
2266
|
blockCreated: (0, import_math7.bn)(1),
|
2322
2267
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2323
2268
|
}
|
@@ -2349,7 +2294,7 @@ var BaseTransactionRequest = class {
|
|
2349
2294
|
toJSON() {
|
2350
2295
|
return normalizeJSON(this);
|
2351
2296
|
}
|
2352
|
-
|
2297
|
+
updatePredicateInputs(inputs) {
|
2353
2298
|
this.inputs.forEach((i) => {
|
2354
2299
|
let correspondingInput;
|
2355
2300
|
switch (i.type) {
|
@@ -2371,15 +2316,6 @@ var BaseTransactionRequest = class {
|
|
2371
2316
|
}
|
2372
2317
|
});
|
2373
2318
|
}
|
2374
|
-
shiftPredicateData() {
|
2375
|
-
this.inputs.forEach((input) => {
|
2376
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2377
|
-
input.predicateData = input.paddPredicateData(
|
2378
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2379
|
-
);
|
2380
|
-
}
|
2381
|
-
});
|
2382
|
-
}
|
2383
2319
|
};
|
2384
2320
|
|
2385
2321
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2526,8 +2462,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2526
2462
|
return {
|
2527
2463
|
type: import_transactions8.TransactionType.Create,
|
2528
2464
|
...baseTransaction,
|
2465
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2529
2466
|
bytecodeWitnessIndex,
|
2530
|
-
storageSlotsCount:
|
2467
|
+
storageSlotsCount: storageSlots.length,
|
2531
2468
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2532
2469
|
storageSlots
|
2533
2470
|
};
|
@@ -2650,8 +2587,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2650
2587
|
type: import_transactions9.TransactionType.Script,
|
2651
2588
|
scriptGasLimit: this.gasLimit,
|
2652
2589
|
...super.getBaseTransaction(),
|
2653
|
-
scriptLength:
|
2654
|
-
scriptDataLength:
|
2590
|
+
scriptLength: script.length,
|
2591
|
+
scriptDataLength: scriptData.length,
|
2655
2592
|
receiptsRoot: import_configs10.ZeroBytes32,
|
2656
2593
|
script: (0, import_utils15.hexlify)(script),
|
2657
2594
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2715,7 +2652,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2715
2652
|
}
|
2716
2653
|
calculateMaxGas(chainInfo, minGas) {
|
2717
2654
|
const { consensusParameters } = chainInfo;
|
2718
|
-
const { gasPerByte
|
2655
|
+
const { gasPerByte } = consensusParameters;
|
2719
2656
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2720
2657
|
(acc, wit) => acc + wit.dataLength,
|
2721
2658
|
0
|
@@ -2725,8 +2662,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2725
2662
|
minGas,
|
2726
2663
|
witnessesLength,
|
2727
2664
|
witnessLimit: this.witnessLimit,
|
2728
|
-
gasLimit: this.gasLimit
|
2729
|
-
maxGasPerTx
|
2665
|
+
gasLimit: this.gasLimit
|
2730
2666
|
});
|
2731
2667
|
}
|
2732
2668
|
/**
|
@@ -2801,32 +2737,15 @@ var transactionRequestify = (obj) => {
|
|
2801
2737
|
}
|
2802
2738
|
}
|
2803
2739
|
};
|
2804
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2805
|
-
(acc, input) => {
|
2806
|
-
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2807
|
-
acc.utxos.push(input.id);
|
2808
|
-
}
|
2809
|
-
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2810
|
-
acc.messages.push(input.nonce);
|
2811
|
-
}
|
2812
|
-
return acc;
|
2813
|
-
},
|
2814
|
-
{
|
2815
|
-
utxos: [],
|
2816
|
-
messages: []
|
2817
|
-
}
|
2818
|
-
);
|
2819
2740
|
|
2820
2741
|
// src/providers/transaction-response/transaction-response.ts
|
2821
2742
|
var import_errors13 = require("@fuel-ts/errors");
|
2822
|
-
var
|
2823
|
-
var
|
2824
|
-
var
|
2743
|
+
var import_math14 = require("@fuel-ts/math");
|
2744
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2745
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2825
2746
|
|
2826
2747
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2827
|
-
var
|
2828
|
-
var import_transactions16 = require("@fuel-ts/transactions");
|
2829
|
-
var import_utils18 = require("@fuel-ts/utils");
|
2748
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2830
2749
|
|
2831
2750
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2832
2751
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2834,10 +2753,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2834
2753
|
var import_utils16 = require("@fuel-ts/utils");
|
2835
2754
|
var calculateTransactionFee = (params) => {
|
2836
2755
|
const {
|
2837
|
-
|
2756
|
+
gasUsed,
|
2838
2757
|
rawPayload,
|
2839
|
-
|
2840
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2758
|
+
consensusParameters: { gasCosts, feeParams }
|
2841
2759
|
} = params;
|
2842
2760
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2843
2761
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2847,7 +2765,8 @@ var calculateTransactionFee = (params) => {
|
|
2847
2765
|
return {
|
2848
2766
|
fee: (0, import_math11.bn)(0),
|
2849
2767
|
minFee: (0, import_math11.bn)(0),
|
2850
|
-
maxFee: (0, import_math11.bn)(0)
|
2768
|
+
maxFee: (0, import_math11.bn)(0),
|
2769
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2851
2770
|
};
|
2852
2771
|
}
|
2853
2772
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2879,6 +2798,7 @@ var calculateTransactionFee = (params) => {
|
|
2879
2798
|
metadataGas,
|
2880
2799
|
txBytesSize: transactionBytes.length
|
2881
2800
|
});
|
2801
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2882
2802
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2883
2803
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2884
2804
|
const maxGas = getMaxGas({
|
@@ -2886,25 +2806,17 @@ var calculateTransactionFee = (params) => {
|
|
2886
2806
|
minGas,
|
2887
2807
|
witnessesLength,
|
2888
2808
|
gasLimit,
|
2889
|
-
witnessLimit
|
2890
|
-
maxGasPerTx
|
2891
|
-
});
|
2892
|
-
const minFee = calculateGasFee({
|
2893
|
-
gasPrice,
|
2894
|
-
gas: minGas,
|
2895
|
-
priceFactor: gasPriceFactor,
|
2896
|
-
tip
|
2897
|
-
});
|
2898
|
-
const maxFee = calculateGasFee({
|
2899
|
-
gasPrice,
|
2900
|
-
gas: maxGas,
|
2901
|
-
priceFactor: gasPriceFactor,
|
2902
|
-
tip
|
2809
|
+
witnessLimit
|
2903
2810
|
});
|
2811
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2812
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2813
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2814
|
+
const fee = minFee.add(feeFromGasUsed);
|
2904
2815
|
return {
|
2816
|
+
fee,
|
2905
2817
|
minFee,
|
2906
2818
|
maxFee,
|
2907
|
-
|
2819
|
+
feeFromGasUsed
|
2908
2820
|
};
|
2909
2821
|
};
|
2910
2822
|
|
@@ -3518,12 +3430,10 @@ function assembleTransactionSummary(params) {
|
|
3518
3430
|
gqlTransactionStatus,
|
3519
3431
|
abiMap = {},
|
3520
3432
|
maxInputs,
|
3521
|
-
gasCosts
|
3522
|
-
maxGasPerTx,
|
3523
|
-
gasPrice
|
3433
|
+
gasCosts
|
3524
3434
|
} = params;
|
3525
3435
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3526
|
-
const rawPayload = (0,
|
3436
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3527
3437
|
const operations = getOperations({
|
3528
3438
|
transactionType: transaction.type,
|
3529
3439
|
inputs: transaction.inputs || [],
|
@@ -3534,14 +3444,11 @@ function assembleTransactionSummary(params) {
|
|
3534
3444
|
maxInputs
|
3535
3445
|
});
|
3536
3446
|
const typeName = getTransactionTypeName(transaction.type);
|
3537
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3538
3447
|
const { fee } = calculateTransactionFee({
|
3539
|
-
|
3448
|
+
gasUsed,
|
3540
3449
|
rawPayload,
|
3541
|
-
tip,
|
3542
3450
|
consensusParameters: {
|
3543
3451
|
gasCosts,
|
3544
|
-
maxGasPerTx,
|
3545
3452
|
feeParams: {
|
3546
3453
|
gasPerByte,
|
3547
3454
|
gasPriceFactor
|
@@ -3553,7 +3460,7 @@ function assembleTransactionSummary(params) {
|
|
3553
3460
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3554
3461
|
let date;
|
3555
3462
|
if (time) {
|
3556
|
-
date =
|
3463
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3557
3464
|
}
|
3558
3465
|
const transactionSummary = {
|
3559
3466
|
id,
|
@@ -3581,12 +3488,12 @@ function assembleTransactionSummary(params) {
|
|
3581
3488
|
|
3582
3489
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3583
3490
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3584
|
-
var
|
3491
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3585
3492
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3586
3493
|
return receipts.reduce((logs, receipt) => {
|
3587
|
-
if (receipt.type ===
|
3494
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3588
3495
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3589
|
-
const data = receipt.type ===
|
3496
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3590
3497
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3591
3498
|
logs.push(decodedLog);
|
3592
3499
|
}
|
@@ -3601,7 +3508,7 @@ var TransactionResponse = class {
|
|
3601
3508
|
/** Current provider */
|
3602
3509
|
provider;
|
3603
3510
|
/** Gas used on the transaction */
|
3604
|
-
gasUsed = (0,
|
3511
|
+
gasUsed = (0, import_math14.bn)(0);
|
3605
3512
|
/** The graphql Transaction with receipts object. */
|
3606
3513
|
gqlTransaction;
|
3607
3514
|
abis;
|
@@ -3659,8 +3566,8 @@ var TransactionResponse = class {
|
|
3659
3566
|
* @returns The decoded transaction.
|
3660
3567
|
*/
|
3661
3568
|
decodeTransaction(transactionWithReceipts) {
|
3662
|
-
return new
|
3663
|
-
(0,
|
3569
|
+
return new import_transactions17.TransactionCoder().decode(
|
3570
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3664
3571
|
0
|
3665
3572
|
)?.[0];
|
3666
3573
|
}
|
@@ -3679,27 +3586,20 @@ var TransactionResponse = class {
|
|
3679
3586
|
const decodedTransaction = this.decodeTransaction(
|
3680
3587
|
transaction
|
3681
3588
|
);
|
3682
|
-
|
3683
|
-
|
3684
|
-
txReceipts = transaction.status.receipts;
|
3685
|
-
}
|
3686
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3687
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3688
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3589
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3590
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3689
3591
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3690
3592
|
const transactionSummary = assembleTransactionSummary({
|
3691
3593
|
id: this.id,
|
3692
3594
|
receipts,
|
3693
3595
|
transaction: decodedTransaction,
|
3694
|
-
transactionBytes: (0,
|
3596
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3695
3597
|
gqlTransactionStatus: transaction.status,
|
3696
3598
|
gasPerByte,
|
3697
3599
|
gasPriceFactor,
|
3698
3600
|
abiMap: contractsAbiMap,
|
3699
3601
|
maxInputs,
|
3700
|
-
gasCosts
|
3701
|
-
maxGasPerTx,
|
3702
|
-
gasPrice
|
3602
|
+
gasCosts
|
3703
3603
|
});
|
3704
3604
|
return transactionSummary;
|
3705
3605
|
}
|
@@ -3826,29 +3726,29 @@ var processGqlChain = (chain) => {
|
|
3826
3726
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3827
3727
|
return {
|
3828
3728
|
name,
|
3829
|
-
baseChainHeight: (0,
|
3729
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3830
3730
|
consensusParameters: {
|
3831
|
-
contractMaxSize: (0,
|
3832
|
-
maxInputs: (0,
|
3833
|
-
maxOutputs: (0,
|
3834
|
-
maxWitnesses: (0,
|
3835
|
-
maxGasPerTx: (0,
|
3836
|
-
maxScriptLength: (0,
|
3837
|
-
maxScriptDataLength: (0,
|
3838
|
-
maxStorageSlots: (0,
|
3839
|
-
maxPredicateLength: (0,
|
3840
|
-
maxPredicateDataLength: (0,
|
3841
|
-
maxGasPerPredicate: (0,
|
3842
|
-
gasPriceFactor: (0,
|
3843
|
-
gasPerByte: (0,
|
3844
|
-
maxMessageDataLength: (0,
|
3845
|
-
chainId: (0,
|
3731
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3732
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3733
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3734
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3735
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3736
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3737
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3738
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3739
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3740
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3741
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3742
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3743
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3744
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3745
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3846
3746
|
gasCosts
|
3847
3747
|
},
|
3848
3748
|
gasCosts,
|
3849
3749
|
latestBlock: {
|
3850
3750
|
id: latestBlock.id,
|
3851
|
-
height: (0,
|
3751
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3852
3752
|
time: latestBlock.header.time,
|
3853
3753
|
transactions: latestBlock.transactions.map((i) => ({
|
3854
3754
|
id: i.id
|
@@ -3942,8 +3842,10 @@ var _Provider = class {
|
|
3942
3842
|
* Returns some helpful parameters related to gas fees.
|
3943
3843
|
*/
|
3944
3844
|
getGasConfig() {
|
3845
|
+
const { minGasPrice } = this.getNode();
|
3945
3846
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3946
3847
|
return {
|
3848
|
+
minGasPrice,
|
3947
3849
|
maxGasPerTx,
|
3948
3850
|
maxGasPerPredicate,
|
3949
3851
|
gasPriceFactor,
|
@@ -4041,7 +3943,7 @@ var _Provider = class {
|
|
4041
3943
|
*/
|
4042
3944
|
async getBlockNumber() {
|
4043
3945
|
const { chain } = await this.operations.getChain();
|
4044
|
-
return (0,
|
3946
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
4045
3947
|
}
|
4046
3948
|
/**
|
4047
3949
|
* Returns the chain information.
|
@@ -4051,11 +3953,13 @@ var _Provider = class {
|
|
4051
3953
|
async fetchNode() {
|
4052
3954
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
4053
3955
|
const processedNodeInfo = {
|
4054
|
-
maxDepth: (0,
|
4055
|
-
maxTx: (0,
|
3956
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3957
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3958
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
4056
3959
|
nodeVersion: nodeInfo.nodeVersion,
|
4057
3960
|
utxoValidation: nodeInfo.utxoValidation,
|
4058
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3961
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3962
|
+
peers: nodeInfo.peers
|
4059
3963
|
};
|
4060
3964
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
4061
3965
|
return processedNodeInfo;
|
@@ -4097,9 +4001,9 @@ var _Provider = class {
|
|
4097
4001
|
if (estimateTxDependencies) {
|
4098
4002
|
await this.estimateTxDependencies(transactionRequest);
|
4099
4003
|
}
|
4100
|
-
const encodedTransaction = (0,
|
4004
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4101
4005
|
let abis;
|
4102
|
-
if (transactionRequest.type ===
|
4006
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4103
4007
|
abis = transactionRequest.abis;
|
4104
4008
|
}
|
4105
4009
|
if (awaitExecution) {
|
@@ -4140,14 +4044,15 @@ var _Provider = class {
|
|
4140
4044
|
if (estimateTxDependencies) {
|
4141
4045
|
return this.estimateTxDependencies(transactionRequest);
|
4142
4046
|
}
|
4143
|
-
const encodedTransaction = (0,
|
4144
|
-
const { dryRun:
|
4145
|
-
|
4047
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4048
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4049
|
+
encodedTransaction,
|
4146
4050
|
utxoValidation: utxoValidation || false
|
4147
4051
|
});
|
4148
|
-
const
|
4149
|
-
|
4150
|
-
|
4052
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4053
|
+
return {
|
4054
|
+
receipts
|
4055
|
+
};
|
4151
4056
|
}
|
4152
4057
|
/**
|
4153
4058
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4158,13 +4063,13 @@ var _Provider = class {
|
|
4158
4063
|
async estimatePredicates(transactionRequest) {
|
4159
4064
|
const shouldEstimatePredicates = Boolean(
|
4160
4065
|
transactionRequest.inputs.find(
|
4161
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4066
|
+
(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()
|
4162
4067
|
)
|
4163
4068
|
);
|
4164
4069
|
if (!shouldEstimatePredicates) {
|
4165
4070
|
return transactionRequest;
|
4166
4071
|
}
|
4167
|
-
const encodedTransaction = (0,
|
4072
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4168
4073
|
const response = await this.operations.estimatePredicates({
|
4169
4074
|
encodedTransaction
|
4170
4075
|
});
|
@@ -4173,7 +4078,7 @@ var _Provider = class {
|
|
4173
4078
|
} = response;
|
4174
4079
|
if (inputs) {
|
4175
4080
|
inputs.forEach((input, index) => {
|
4176
|
-
if ("predicateGasUsed" in input && (0,
|
4081
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
4177
4082
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4178
4083
|
}
|
4179
4084
|
});
|
@@ -4186,31 +4091,31 @@ var _Provider = class {
|
|
4186
4091
|
* If there are missing variable outputs,
|
4187
4092
|
* `addVariableOutputs` is called on the transaction.
|
4188
4093
|
*
|
4094
|
+
* @privateRemarks
|
4095
|
+
* TODO: Investigate support for missing contract IDs
|
4096
|
+
* TODO: Add support for missing output messages
|
4189
4097
|
*
|
4190
4098
|
* @param transactionRequest - The transaction request object.
|
4191
4099
|
* @returns A promise.
|
4192
4100
|
*/
|
4193
4101
|
async estimateTxDependencies(transactionRequest) {
|
4194
|
-
if (transactionRequest.type ===
|
4102
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
4195
4103
|
return {
|
4196
4104
|
receipts: [],
|
4197
4105
|
outputVariables: 0,
|
4198
4106
|
missingContractIds: []
|
4199
4107
|
};
|
4200
4108
|
}
|
4109
|
+
await this.estimatePredicates(transactionRequest);
|
4201
4110
|
let receipts = [];
|
4202
4111
|
const missingContractIds = [];
|
4203
4112
|
let outputVariables = 0;
|
4204
|
-
let dryrunStatus;
|
4205
4113
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4206
|
-
const {
|
4207
|
-
|
4208
|
-
} = await this.operations.dryRun({
|
4209
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4114
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4115
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
4210
4116
|
utxoValidation: false
|
4211
4117
|
});
|
4212
|
-
receipts =
|
4213
|
-
dryrunStatus = status;
|
4118
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
4214
4119
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4215
4120
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4216
4121
|
if (hasMissingOutputs) {
|
@@ -4220,11 +4125,6 @@ var _Provider = class {
|
|
4220
4125
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4221
4126
|
missingContractIds.push(contractId);
|
4222
4127
|
});
|
4223
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4224
|
-
transactionRequest,
|
4225
|
-
optimizeGas: false
|
4226
|
-
});
|
4227
|
-
transactionRequest.maxFee = maxFee;
|
4228
4128
|
} else {
|
4229
4129
|
break;
|
4230
4130
|
}
|
@@ -4232,133 +4132,38 @@ var _Provider = class {
|
|
4232
4132
|
return {
|
4233
4133
|
receipts,
|
4234
4134
|
outputVariables,
|
4235
|
-
missingContractIds
|
4236
|
-
dryrunStatus
|
4135
|
+
missingContractIds
|
4237
4136
|
};
|
4238
4137
|
}
|
4239
4138
|
/**
|
4240
|
-
*
|
4241
|
-
*
|
4242
|
-
*
|
4243
|
-
*
|
4244
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4245
|
-
*
|
4246
|
-
* @param transactionRequests - Array of transaction request objects.
|
4247
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4139
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
4140
|
+
* @param transactionRequest - The transaction request object.
|
4141
|
+
* @param optimizeGas - Optional. Specifies whether to optimize the gas. Default is false.
|
4142
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4248
4143
|
*/
|
4249
|
-
|
4250
|
-
const
|
4251
|
-
|
4252
|
-
outputVariables: 0,
|
4253
|
-
missingContractIds: [],
|
4254
|
-
dryrunStatus: void 0
|
4255
|
-
}));
|
4256
|
-
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4257
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4258
|
-
allRequests.forEach((req, index) => {
|
4259
|
-
if (req.type === import_transactions19.TransactionType.Script) {
|
4260
|
-
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4261
|
-
}
|
4262
|
-
});
|
4263
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4264
|
-
let attempt = 0;
|
4265
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4266
|
-
const encodedTransactions = transactionsToProcess.map(
|
4267
|
-
(index) => serializedTransactionsMap.get(index)
|
4268
|
-
);
|
4269
|
-
const dryRunResults = await this.operations.dryRun({
|
4270
|
-
encodedTransactions,
|
4271
|
-
utxoValidation: false
|
4272
|
-
});
|
4273
|
-
const nextRoundTransactions = [];
|
4274
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4275
|
-
const currentResultIndex = transactionsToProcess[i];
|
4276
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4277
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4278
|
-
results[currentResultIndex].dryrunStatus = status;
|
4279
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4280
|
-
results[currentResultIndex].receipts
|
4281
|
-
);
|
4282
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4283
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4284
|
-
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4285
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4286
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4287
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4288
|
-
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4289
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4290
|
-
});
|
4291
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4292
|
-
transactionRequest: requestToProcess,
|
4293
|
-
optimizeGas: false
|
4294
|
-
});
|
4295
|
-
requestToProcess.maxFee = maxFee;
|
4296
|
-
serializedTransactionsMap.set(
|
4297
|
-
currentResultIndex,
|
4298
|
-
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4299
|
-
);
|
4300
|
-
nextRoundTransactions.push(currentResultIndex);
|
4301
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4302
|
-
}
|
4303
|
-
}
|
4304
|
-
transactionsToProcess = nextRoundTransactions;
|
4305
|
-
attempt += 1;
|
4306
|
-
}
|
4307
|
-
return results;
|
4308
|
-
}
|
4309
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4310
|
-
if (estimateTxDependencies) {
|
4311
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4312
|
-
}
|
4313
|
-
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4314
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4315
|
-
encodedTransactions,
|
4316
|
-
utxoValidation: utxoValidation || false
|
4317
|
-
});
|
4318
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4319
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4320
|
-
return { receipts, dryrunStatus: status };
|
4321
|
-
});
|
4322
|
-
return results;
|
4323
|
-
}
|
4324
|
-
async estimateTxGasAndFee(params) {
|
4325
|
-
const { transactionRequest, optimizeGas = true } = params;
|
4326
|
-
let { gasPrice } = params;
|
4144
|
+
estimateTxGasAndFee(params) {
|
4145
|
+
const { transactionRequest } = params;
|
4146
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4327
4147
|
const chainInfo = this.getChain();
|
4328
|
-
const
|
4148
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
4149
|
+
transactionRequest.gasPrice = gasPrice;
|
4329
4150
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4330
|
-
|
4331
|
-
|
4332
|
-
|
4333
|
-
const minFee = calculateGasFee({
|
4334
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4335
|
-
gas: minGas,
|
4336
|
-
priceFactor: gasPriceFactor,
|
4337
|
-
tip: transactionRequest.tip
|
4338
|
-
}).add(1);
|
4339
|
-
let gasLimit = (0, import_math16.bn)(0);
|
4340
|
-
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4341
|
-
gasLimit = transactionRequest.gasLimit;
|
4342
|
-
if (!optimizeGas) {
|
4151
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4152
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4153
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
4343
4154
|
transactionRequest.gasLimit = minGas;
|
4344
|
-
gasLimit =
|
4345
|
-
|
4155
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4156
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4157
|
+
);
|
4346
4158
|
}
|
4347
4159
|
}
|
4348
4160
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4349
|
-
const maxFee =
|
4350
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4351
|
-
gas: maxGas,
|
4352
|
-
priceFactor: gasPriceFactor,
|
4353
|
-
tip: transactionRequest.tip
|
4354
|
-
}).add(1);
|
4161
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4355
4162
|
return {
|
4356
4163
|
minGas,
|
4357
4164
|
minFee,
|
4358
4165
|
maxGas,
|
4359
|
-
maxFee
|
4360
|
-
gasPrice,
|
4361
|
-
gasLimit
|
4166
|
+
maxFee
|
4362
4167
|
};
|
4363
4168
|
}
|
4364
4169
|
/**
|
@@ -4376,17 +4181,15 @@ var _Provider = class {
|
|
4376
4181
|
if (estimateTxDependencies) {
|
4377
4182
|
return this.estimateTxDependencies(transactionRequest);
|
4378
4183
|
}
|
4379
|
-
const
|
4380
|
-
const { dryRun:
|
4381
|
-
|
4184
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4185
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4186
|
+
encodedTransaction,
|
4382
4187
|
utxoValidation: true
|
4383
4188
|
});
|
4384
|
-
const
|
4385
|
-
|
4386
|
-
|
4387
|
-
|
4388
|
-
});
|
4389
|
-
return { receipts: callResult[0].receipts };
|
4189
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4190
|
+
return {
|
4191
|
+
receipts
|
4192
|
+
};
|
4390
4193
|
}
|
4391
4194
|
/**
|
4392
4195
|
* Returns a transaction cost to enable user
|
@@ -4403,80 +4206,77 @@ var _Provider = class {
|
|
4403
4206
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4404
4207
|
* @returns A promise that resolves to the transaction cost object.
|
4405
4208
|
*/
|
4406
|
-
async getTransactionCost(transactionRequestLike,
|
4209
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
4210
|
+
estimateTxDependencies = true,
|
4211
|
+
estimatePredicates = true,
|
4212
|
+
resourcesOwner,
|
4213
|
+
signatureCallback
|
4214
|
+
} = {}) {
|
4407
4215
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4408
|
-
const
|
4216
|
+
const { minGasPrice } = this.getGasConfig();
|
4217
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4218
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4409
4219
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4410
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4220
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4411
4221
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4412
|
-
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4413
4222
|
if (isScriptTransaction) {
|
4414
|
-
txRequestClone.gasLimit = (0,
|
4223
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4415
4224
|
}
|
4416
|
-
if (
|
4417
|
-
resourcesOwner
|
4225
|
+
if (estimatePredicates) {
|
4226
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4227
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4228
|
+
}
|
4229
|
+
await this.estimatePredicates(txRequestClone);
|
4418
4230
|
}
|
4419
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4420
|
-
let addedSignatures = 0;
|
4421
4231
|
if (signatureCallback && isScriptTransaction) {
|
4422
|
-
|
4423
|
-
|
4424
|
-
|
4425
|
-
|
4426
|
-
await this.estimatePredicates(signedRequest);
|
4427
|
-
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4428
|
-
transactionRequest: signedRequest,
|
4429
|
-
optimizeGas: false
|
4232
|
+
await signatureCallback(txRequestClone);
|
4233
|
+
}
|
4234
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4235
|
+
transactionRequest: txRequestClone
|
4430
4236
|
});
|
4431
|
-
txRequestClone.maxFee = maxFee;
|
4432
4237
|
let receipts = [];
|
4433
4238
|
let missingContractIds = [];
|
4434
4239
|
let outputVariables = 0;
|
4435
|
-
let gasUsed = (0,
|
4436
|
-
|
4437
|
-
|
4438
|
-
if (signatureCallback) {
|
4439
|
-
await signatureCallback(txRequestClone);
|
4440
|
-
}
|
4441
|
-
txRequestClone.gasLimit = gasLimit;
|
4240
|
+
let gasUsed = (0, import_math15.bn)(0);
|
4241
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4242
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4442
4243
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4443
4244
|
receipts = result.receipts;
|
4444
4245
|
outputVariables = result.outputVariables;
|
4445
4246
|
missingContractIds = result.missingContractIds;
|
4446
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
4247
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4447
4248
|
txRequestClone.gasLimit = gasUsed;
|
4448
|
-
|
4449
|
-
|
4450
|
-
|
4249
|
+
txRequestClone.gasPrice = setGasPrice;
|
4250
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4251
|
+
transactionRequest: txRequestClone
|
4451
4252
|
}));
|
4452
4253
|
}
|
4453
4254
|
return {
|
4454
4255
|
requiredQuantities: allQuantities,
|
4455
4256
|
receipts,
|
4456
4257
|
gasUsed,
|
4457
|
-
|
4258
|
+
minGasPrice,
|
4259
|
+
gasPrice: setGasPrice,
|
4458
4260
|
minGas,
|
4459
4261
|
maxGas,
|
4460
4262
|
minFee,
|
4461
4263
|
maxFee,
|
4264
|
+
estimatedInputs: txRequestClone.inputs,
|
4462
4265
|
outputVariables,
|
4463
|
-
missingContractIds
|
4464
|
-
addedSignatures,
|
4465
|
-
estimatedPredicates: txRequestClone.inputs
|
4266
|
+
missingContractIds
|
4466
4267
|
};
|
4467
4268
|
}
|
4468
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4269
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4469
4270
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4470
4271
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4471
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4472
|
-
quantitiesToContract
|
4473
|
-
});
|
4272
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4474
4273
|
transactionRequest.addResources(
|
4475
4274
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4476
4275
|
);
|
4477
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4478
|
-
|
4479
|
-
|
4276
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4277
|
+
transactionRequest,
|
4278
|
+
forwardingQuantities
|
4279
|
+
);
|
4480
4280
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4481
4281
|
return {
|
4482
4282
|
resources,
|
@@ -4492,16 +4292,17 @@ var _Provider = class {
|
|
4492
4292
|
const result = await this.operations.getCoins({
|
4493
4293
|
first: 10,
|
4494
4294
|
...paginationArgs,
|
4495
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4295
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4496
4296
|
});
|
4497
4297
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4498
4298
|
return coins.map((coin) => ({
|
4499
4299
|
id: coin.utxoId,
|
4500
4300
|
assetId: coin.assetId,
|
4501
|
-
amount: (0,
|
4301
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4502
4302
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4503
|
-
|
4504
|
-
|
4303
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4304
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4305
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4505
4306
|
}));
|
4506
4307
|
}
|
4507
4308
|
/**
|
@@ -4515,19 +4316,19 @@ var _Provider = class {
|
|
4515
4316
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4516
4317
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4517
4318
|
const excludeInput = {
|
4518
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4519
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4319
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4320
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4520
4321
|
};
|
4521
4322
|
if (this.cache) {
|
4522
4323
|
const uniqueUtxos = new Set(
|
4523
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4324
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4524
4325
|
);
|
4525
4326
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4526
4327
|
}
|
4527
4328
|
const coinsQuery = {
|
4528
4329
|
owner: ownerAddress.toB256(),
|
4529
4330
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4530
|
-
assetId: (0,
|
4331
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4531
4332
|
amount: amount.toString(10),
|
4532
4333
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4533
4334
|
})),
|
@@ -4538,9 +4339,9 @@ var _Provider = class {
|
|
4538
4339
|
switch (coin.__typename) {
|
4539
4340
|
case "MessageCoin":
|
4540
4341
|
return {
|
4541
|
-
amount: (0,
|
4342
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4542
4343
|
assetId: coin.assetId,
|
4543
|
-
daHeight: (0,
|
4344
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4544
4345
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4545
4346
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4546
4347
|
nonce: coin.nonce
|
@@ -4548,11 +4349,12 @@ var _Provider = class {
|
|
4548
4349
|
case "Coin":
|
4549
4350
|
return {
|
4550
4351
|
id: coin.utxoId,
|
4551
|
-
amount: (0,
|
4352
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4552
4353
|
assetId: coin.assetId,
|
4553
4354
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4554
|
-
|
4555
|
-
|
4355
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4356
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4357
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4556
4358
|
};
|
4557
4359
|
default:
|
4558
4360
|
return null;
|
@@ -4569,13 +4371,13 @@ var _Provider = class {
|
|
4569
4371
|
async getBlock(idOrHeight) {
|
4570
4372
|
let variables;
|
4571
4373
|
if (typeof idOrHeight === "number") {
|
4572
|
-
variables = { height: (0,
|
4374
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4573
4375
|
} else if (idOrHeight === "latest") {
|
4574
4376
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4575
4377
|
} else if (idOrHeight.length === 66) {
|
4576
4378
|
variables = { blockId: idOrHeight };
|
4577
4379
|
} else {
|
4578
|
-
variables = { blockId: (0,
|
4380
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4579
4381
|
}
|
4580
4382
|
const { block } = await this.operations.getBlock(variables);
|
4581
4383
|
if (!block) {
|
@@ -4583,7 +4385,7 @@ var _Provider = class {
|
|
4583
4385
|
}
|
4584
4386
|
return {
|
4585
4387
|
id: block.id,
|
4586
|
-
height: (0,
|
4388
|
+
height: (0, import_math15.bn)(block.header.height),
|
4587
4389
|
time: block.header.time,
|
4588
4390
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4589
4391
|
};
|
@@ -4598,7 +4400,7 @@ var _Provider = class {
|
|
4598
4400
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4599
4401
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4600
4402
|
id: block.id,
|
4601
|
-
height: (0,
|
4403
|
+
height: (0, import_math15.bn)(block.header.height),
|
4602
4404
|
time: block.header.time,
|
4603
4405
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4604
4406
|
}));
|
@@ -4613,7 +4415,7 @@ var _Provider = class {
|
|
4613
4415
|
async getBlockWithTransactions(idOrHeight) {
|
4614
4416
|
let variables;
|
4615
4417
|
if (typeof idOrHeight === "number") {
|
4616
|
-
variables = { blockHeight: (0,
|
4418
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4617
4419
|
} else if (idOrHeight === "latest") {
|
4618
4420
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4619
4421
|
} else {
|
@@ -4625,11 +4427,11 @@ var _Provider = class {
|
|
4625
4427
|
}
|
4626
4428
|
return {
|
4627
4429
|
id: block.id,
|
4628
|
-
height: (0,
|
4430
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4629
4431
|
time: block.header.time,
|
4630
4432
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4631
4433
|
transactions: block.transactions.map(
|
4632
|
-
(tx) => new
|
4434
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4633
4435
|
)
|
4634
4436
|
};
|
4635
4437
|
}
|
@@ -4644,8 +4446,8 @@ var _Provider = class {
|
|
4644
4446
|
if (!transaction) {
|
4645
4447
|
return null;
|
4646
4448
|
}
|
4647
|
-
return new
|
4648
|
-
(0,
|
4449
|
+
return new import_transactions18.TransactionCoder().decode(
|
4450
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4649
4451
|
0
|
4650
4452
|
)?.[0];
|
4651
4453
|
}
|
@@ -4672,9 +4474,9 @@ var _Provider = class {
|
|
4672
4474
|
async getContractBalance(contractId, assetId) {
|
4673
4475
|
const { contractBalance } = await this.operations.getContractBalance({
|
4674
4476
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4675
|
-
asset: (0,
|
4477
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4676
4478
|
});
|
4677
|
-
return (0,
|
4479
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4678
4480
|
}
|
4679
4481
|
/**
|
4680
4482
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4686,9 +4488,9 @@ var _Provider = class {
|
|
4686
4488
|
async getBalance(owner, assetId) {
|
4687
4489
|
const { balance } = await this.operations.getBalance({
|
4688
4490
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4689
|
-
assetId: (0,
|
4491
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4690
4492
|
});
|
4691
|
-
return (0,
|
4493
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4692
4494
|
}
|
4693
4495
|
/**
|
4694
4496
|
* Returns balances for the given owner.
|
@@ -4706,7 +4508,7 @@ var _Provider = class {
|
|
4706
4508
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4707
4509
|
return balances.map((balance) => ({
|
4708
4510
|
assetId: balance.assetId,
|
4709
|
-
amount: (0,
|
4511
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4710
4512
|
}));
|
4711
4513
|
}
|
4712
4514
|
/**
|
@@ -4724,19 +4526,19 @@ var _Provider = class {
|
|
4724
4526
|
});
|
4725
4527
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4726
4528
|
return messages.map((message) => ({
|
4727
|
-
messageId:
|
4529
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4728
4530
|
sender: message.sender,
|
4729
4531
|
recipient: message.recipient,
|
4730
4532
|
nonce: message.nonce,
|
4731
|
-
amount: (0,
|
4533
|
+
amount: (0, import_math15.bn)(message.amount),
|
4732
4534
|
data: message.data
|
4733
4535
|
}),
|
4734
4536
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4735
4537
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4736
4538
|
nonce: message.nonce,
|
4737
|
-
amount: (0,
|
4738
|
-
data:
|
4739
|
-
daHeight: (0,
|
4539
|
+
amount: (0, import_math15.bn)(message.amount),
|
4540
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4541
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4740
4542
|
}));
|
4741
4543
|
}
|
4742
4544
|
/**
|
@@ -4789,52 +4591,44 @@ var _Provider = class {
|
|
4789
4591
|
} = result.messageProof;
|
4790
4592
|
return {
|
4791
4593
|
messageProof: {
|
4792
|
-
proofIndex: (0,
|
4594
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4793
4595
|
proofSet: messageProof.proofSet
|
4794
4596
|
},
|
4795
4597
|
blockProof: {
|
4796
|
-
proofIndex: (0,
|
4598
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4797
4599
|
proofSet: blockProof.proofSet
|
4798
4600
|
},
|
4799
4601
|
messageBlockHeader: {
|
4800
4602
|
id: messageBlockHeader.id,
|
4801
|
-
daHeight: (0,
|
4802
|
-
transactionsCount: (0,
|
4603
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4604
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4803
4605
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4804
|
-
height: (0,
|
4606
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4805
4607
|
prevRoot: messageBlockHeader.prevRoot,
|
4806
4608
|
time: messageBlockHeader.time,
|
4807
4609
|
applicationHash: messageBlockHeader.applicationHash,
|
4808
|
-
|
4610
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4611
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4809
4612
|
},
|
4810
4613
|
commitBlockHeader: {
|
4811
4614
|
id: commitBlockHeader.id,
|
4812
|
-
daHeight: (0,
|
4813
|
-
transactionsCount: (0,
|
4615
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4616
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4814
4617
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4815
|
-
height: (0,
|
4618
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4816
4619
|
prevRoot: commitBlockHeader.prevRoot,
|
4817
4620
|
time: commitBlockHeader.time,
|
4818
4621
|
applicationHash: commitBlockHeader.applicationHash,
|
4819
|
-
|
4622
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4623
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4820
4624
|
},
|
4821
4625
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4822
4626
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4823
4627
|
nonce,
|
4824
|
-
amount: (0,
|
4628
|
+
amount: (0, import_math15.bn)(amount),
|
4825
4629
|
data
|
4826
4630
|
};
|
4827
4631
|
}
|
4828
|
-
async getLatestGasPrice() {
|
4829
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4830
|
-
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4831
|
-
}
|
4832
|
-
async estimateGasPrice(blockHorizon) {
|
4833
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4834
|
-
blockHorizon: String(blockHorizon)
|
4835
|
-
});
|
4836
|
-
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4837
|
-
}
|
4838
4632
|
/**
|
4839
4633
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4840
4634
|
*
|
@@ -4854,10 +4648,10 @@ var _Provider = class {
|
|
4854
4648
|
*/
|
4855
4649
|
async produceBlocks(amount, startTime) {
|
4856
4650
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4857
|
-
blocksToProduce: (0,
|
4858
|
-
startTimestamp: startTime ?
|
4651
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4652
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4859
4653
|
});
|
4860
|
-
return (0,
|
4654
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4861
4655
|
}
|
4862
4656
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4863
4657
|
async getTransactionResponse(transactionId) {
|
@@ -4871,7 +4665,7 @@ cacheInputs_fn = function(inputs) {
|
|
4871
4665
|
return;
|
4872
4666
|
}
|
4873
4667
|
inputs.forEach((input) => {
|
4874
|
-
if (input.type ===
|
4668
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4875
4669
|
this.cache?.set(input.id);
|
4876
4670
|
}
|
4877
4671
|
});
|
@@ -4881,9 +4675,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4881
4675
|
|
4882
4676
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4883
4677
|
var import_errors15 = require("@fuel-ts/errors");
|
4884
|
-
var
|
4885
|
-
var
|
4886
|
-
var
|
4678
|
+
var import_math16 = require("@fuel-ts/math");
|
4679
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4680
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4887
4681
|
async function getTransactionSummary(params) {
|
4888
4682
|
const { id, provider, abiMap } = params;
|
4889
4683
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -4895,32 +4689,25 @@ async function getTransactionSummary(params) {
|
|
4895
4689
|
`Transaction not found for given id: ${id}.`
|
4896
4690
|
);
|
4897
4691
|
}
|
4898
|
-
const [decodedTransaction] = new
|
4899
|
-
(0,
|
4692
|
+
const [decodedTransaction] = new import_transactions19.TransactionCoder().decode(
|
4693
|
+
(0, import_utils26.arrayify)(gqlTransaction.rawPayload),
|
4900
4694
|
0
|
4901
4695
|
);
|
4902
|
-
|
4903
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4904
|
-
txReceipts = gqlTransaction.status.receipts;
|
4905
|
-
}
|
4906
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4696
|
+
const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
|
4907
4697
|
const {
|
4908
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4698
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4909
4699
|
} = provider.getChain();
|
4910
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4911
4700
|
const transactionInfo = assembleTransactionSummary({
|
4912
4701
|
id: gqlTransaction.id,
|
4913
4702
|
receipts,
|
4914
4703
|
transaction: decodedTransaction,
|
4915
|
-
transactionBytes: (0,
|
4704
|
+
transactionBytes: (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
|
4916
4705
|
gqlTransactionStatus: gqlTransaction.status,
|
4917
|
-
gasPerByte: (0,
|
4918
|
-
gasPriceFactor: (0,
|
4706
|
+
gasPerByte: (0, import_math16.bn)(gasPerByte),
|
4707
|
+
gasPriceFactor: (0, import_math16.bn)(gasPriceFactor),
|
4919
4708
|
abiMap,
|
4920
4709
|
maxInputs,
|
4921
|
-
gasCosts
|
4922
|
-
maxGasPerTx,
|
4923
|
-
gasPrice
|
4710
|
+
gasCosts
|
4924
4711
|
});
|
4925
4712
|
return {
|
4926
4713
|
gqlTransaction,
|
@@ -4930,11 +4717,10 @@ async function getTransactionSummary(params) {
|
|
4930
4717
|
async function getTransactionSummaryFromRequest(params) {
|
4931
4718
|
const { provider, transactionRequest, abiMap } = params;
|
4932
4719
|
const { receipts } = await provider.call(transactionRequest);
|
4933
|
-
const { gasPerByte, gasPriceFactor, gasCosts
|
4720
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4934
4721
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4935
4722
|
const transaction = transactionRequest.toTransaction();
|
4936
4723
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4937
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4938
4724
|
const transactionSummary = assembleTransactionSummary({
|
4939
4725
|
receipts,
|
4940
4726
|
transaction,
|
@@ -4943,9 +4729,7 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4943
4729
|
gasPerByte,
|
4944
4730
|
gasPriceFactor,
|
4945
4731
|
maxInputs,
|
4946
|
-
gasCosts
|
4947
|
-
maxGasPerTx,
|
4948
|
-
gasPrice
|
4732
|
+
gasCosts
|
4949
4733
|
});
|
4950
4734
|
return transactionSummary;
|
4951
4735
|
}
|
@@ -4954,31 +4738,24 @@ async function getTransactionsSummaries(params) {
|
|
4954
4738
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4955
4739
|
const { edges, pageInfo } = transactionsByOwner;
|
4956
4740
|
const {
|
4957
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4741
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4958
4742
|
} = provider.getChain();
|
4959
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4960
4743
|
const transactions = edges.map((edge) => {
|
4961
4744
|
const { node: gqlTransaction } = edge;
|
4962
|
-
const { id, rawPayload, status } = gqlTransaction;
|
4963
|
-
const [decodedTransaction] = new
|
4964
|
-
|
4965
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4966
|
-
txReceipts = gqlTransaction.status.receipts;
|
4967
|
-
}
|
4968
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4745
|
+
const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
|
4746
|
+
const [decodedTransaction] = new import_transactions19.TransactionCoder().decode((0, import_utils26.arrayify)(rawPayload), 0);
|
4747
|
+
const receipts = gqlReceipts?.map(processGqlReceipt) || [];
|
4969
4748
|
const transactionSummary = assembleTransactionSummary({
|
4970
4749
|
id,
|
4971
4750
|
receipts,
|
4972
4751
|
transaction: decodedTransaction,
|
4973
|
-
transactionBytes: (0,
|
4752
|
+
transactionBytes: (0, import_utils26.arrayify)(rawPayload),
|
4974
4753
|
gqlTransactionStatus: status,
|
4975
4754
|
abiMap,
|
4976
4755
|
gasPerByte,
|
4977
4756
|
gasPriceFactor,
|
4978
4757
|
maxInputs,
|
4979
|
-
gasCosts
|
4980
|
-
maxGasPerTx,
|
4981
|
-
gasPrice
|
4758
|
+
gasCosts
|
4982
4759
|
});
|
4983
4760
|
const output = {
|
4984
4761
|
gqlTransaction,
|
@@ -5115,17 +4892,17 @@ var assets = [
|
|
5115
4892
|
|
5116
4893
|
// src/utils/formatTransferToContractScriptData.ts
|
5117
4894
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
5118
|
-
var
|
5119
|
-
var
|
4895
|
+
var import_math17 = require("@fuel-ts/math");
|
4896
|
+
var import_utils27 = require("@fuel-ts/utils");
|
5120
4897
|
var asm = __toESM(require("@fuels/vm-asm"));
|
5121
4898
|
var formatTransferToContractScriptData = (params) => {
|
5122
4899
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
5123
4900
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
5124
|
-
const encoded = numberCoder.encode(new
|
4901
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
5125
4902
|
const scriptData = Uint8Array.from([
|
5126
|
-
...(0,
|
4903
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
5127
4904
|
...encoded,
|
5128
|
-
...(0,
|
4905
|
+
...(0, import_utils27.arrayify)(assetId)
|
5129
4906
|
]);
|
5130
4907
|
return scriptData;
|
5131
4908
|
};
|
@@ -5310,33 +5087,36 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5310
5087
|
* @param fee - The estimated transaction fee.
|
5311
5088
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5312
5089
|
*/
|
5313
|
-
async fund(request,
|
5314
|
-
const
|
5315
|
-
|
5316
|
-
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5317
|
-
amount: (0, import_math19.bn)(fee),
|
5090
|
+
async fund(request, coinQuantities, fee) {
|
5091
|
+
const updatedQuantities = addAmountToAsset({
|
5092
|
+
amount: (0, import_math18.bn)(fee),
|
5318
5093
|
assetId: import_configs12.BaseAssetId,
|
5319
|
-
coinQuantities
|
5094
|
+
coinQuantities
|
5320
5095
|
});
|
5321
5096
|
const quantitiesDict = {};
|
5322
|
-
|
5097
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
5323
5098
|
quantitiesDict[assetId] = {
|
5324
5099
|
required: amount,
|
5325
|
-
owned: (0,
|
5100
|
+
owned: (0, import_math18.bn)(0)
|
5326
5101
|
};
|
5327
5102
|
});
|
5328
|
-
|
5103
|
+
const cachedUtxos = [];
|
5104
|
+
const cachedMessages = [];
|
5105
|
+
const owner = this.address.toB256();
|
5106
|
+
request.inputs.forEach((input) => {
|
5329
5107
|
const isResource = "amount" in input;
|
5330
5108
|
if (isResource) {
|
5331
5109
|
const isCoin2 = "owner" in input;
|
5332
5110
|
if (isCoin2) {
|
5333
5111
|
const assetId = String(input.assetId);
|
5334
|
-
if (quantitiesDict[assetId]) {
|
5335
|
-
const amount = (0,
|
5112
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
5113
|
+
const amount = (0, import_math18.bn)(input.amount);
|
5336
5114
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5115
|
+
cachedUtxos.push(input.id);
|
5337
5116
|
}
|
5338
|
-
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5117
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5339
5118
|
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
5119
|
+
cachedMessages.push(input.nonce);
|
5340
5120
|
}
|
5341
5121
|
}
|
5342
5122
|
});
|
@@ -5351,23 +5131,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5351
5131
|
});
|
5352
5132
|
const needsToBeFunded = missingQuantities.length;
|
5353
5133
|
if (needsToBeFunded) {
|
5354
|
-
const
|
5355
|
-
|
5356
|
-
|
5357
|
-
|
5358
|
-
|
5359
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
5360
|
-
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
5361
|
-
if (addedSignatures) {
|
5362
|
-
Array.from({ length: addedSignatures }).forEach(
|
5363
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
5364
|
-
);
|
5134
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
5135
|
+
messages: cachedMessages,
|
5136
|
+
utxos: cachedUtxos
|
5137
|
+
});
|
5138
|
+
request.addResources(resources);
|
5365
5139
|
}
|
5366
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5367
|
-
transactionRequest: requestToBeReEstimate
|
5368
|
-
});
|
5369
|
-
txRequest.maxFee = maxFee;
|
5370
|
-
return txRequest;
|
5371
5140
|
}
|
5372
5141
|
/**
|
5373
5142
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5375,25 +5144,28 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5375
5144
|
* @param destination - The address of the destination.
|
5376
5145
|
* @param amount - The amount of coins to transfer.
|
5377
5146
|
* @param assetId - The asset ID of the coins to transfer.
|
5378
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5147
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5379
5148
|
* @returns A promise that resolves to the prepared transaction request.
|
5380
5149
|
*/
|
5381
5150
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5382
|
-
const
|
5151
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5152
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5153
|
+
const request = new ScriptTransactionRequest(params);
|
5383
5154
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
5384
|
-
const
|
5155
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5385
5156
|
estimateTxDependencies: true,
|
5386
5157
|
resourcesOwner: this
|
5387
5158
|
});
|
5388
|
-
|
5389
|
-
|
5390
|
-
|
5391
|
-
|
5392
|
-
|
5393
|
-
|
5394
|
-
|
5395
|
-
|
5396
|
-
await this.fund(request,
|
5159
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
5160
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
5161
|
+
this.validateGas({
|
5162
|
+
gasUsed,
|
5163
|
+
gasPrice: request.gasPrice,
|
5164
|
+
gasLimit: request.gasLimit,
|
5165
|
+
minGasPrice
|
5166
|
+
});
|
5167
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5168
|
+
request.updatePredicateInputs(estimatedInputs);
|
5397
5169
|
return request;
|
5398
5170
|
}
|
5399
5171
|
/**
|
@@ -5406,7 +5178,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5406
5178
|
* @returns A promise that resolves to the transaction response.
|
5407
5179
|
*/
|
5408
5180
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5409
|
-
if ((0,
|
5181
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5410
5182
|
throw new import_errors16.FuelError(
|
5411
5183
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5412
5184
|
"Transfer amount must be a positive number."
|
@@ -5425,37 +5197,38 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5425
5197
|
* @returns A promise that resolves to the transaction response.
|
5426
5198
|
*/
|
5427
5199
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5428
|
-
if ((0,
|
5200
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5429
5201
|
throw new import_errors16.FuelError(
|
5430
5202
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5431
5203
|
"Transfer amount must be a positive number."
|
5432
5204
|
);
|
5433
5205
|
}
|
5434
5206
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5207
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5208
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5435
5209
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5436
5210
|
hexlifiedContractId: contractAddress.toB256(),
|
5437
|
-
amountToTransfer: (0,
|
5211
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
5438
5212
|
assetId
|
5439
5213
|
});
|
5440
5214
|
const request = new ScriptTransactionRequest({
|
5441
|
-
...
|
5215
|
+
...params,
|
5442
5216
|
script,
|
5443
5217
|
scriptData
|
5444
5218
|
});
|
5445
5219
|
request.addContractInputAndOutput(contractAddress);
|
5446
|
-
const
|
5447
|
-
|
5448
|
-
|
5220
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5221
|
+
request,
|
5222
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
5223
|
+
);
|
5224
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5225
|
+
this.validateGas({
|
5226
|
+
gasUsed,
|
5227
|
+
gasPrice: request.gasPrice,
|
5228
|
+
gasLimit: request.gasLimit,
|
5229
|
+
minGasPrice
|
5449
5230
|
});
|
5450
|
-
|
5451
|
-
this.validateGas({
|
5452
|
-
gasUsed: txCost.gasUsed,
|
5453
|
-
gasLimit: request.gasLimit
|
5454
|
-
});
|
5455
|
-
}
|
5456
|
-
request.gasLimit = txCost.gasUsed;
|
5457
|
-
request.maxFee = txCost.maxFee;
|
5458
|
-
await this.fund(request, txCost);
|
5231
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5459
5232
|
return this.sendTransaction(request);
|
5460
5233
|
}
|
5461
5234
|
/**
|
@@ -5467,31 +5240,34 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5467
5240
|
* @returns A promise that resolves to the transaction response.
|
5468
5241
|
*/
|
5469
5242
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5243
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5470
5244
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5471
|
-
const recipientDataArray = (0,
|
5245
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5472
5246
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5473
5247
|
);
|
5474
|
-
const amountDataArray = (0,
|
5475
|
-
"0x".concat((0,
|
5248
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
5249
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5476
5250
|
);
|
5477
5251
|
const script = new Uint8Array([
|
5478
|
-
...(0,
|
5252
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5479
5253
|
...recipientDataArray,
|
5480
5254
|
...amountDataArray
|
5481
5255
|
]);
|
5482
|
-
const params = { script, ...txParams };
|
5256
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5483
5257
|
const request = new ScriptTransactionRequest(params);
|
5484
|
-
const
|
5485
|
-
const
|
5486
|
-
|
5487
|
-
|
5488
|
-
|
5489
|
-
|
5490
|
-
|
5491
|
-
|
5492
|
-
|
5493
|
-
|
5494
|
-
|
5258
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5259
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5260
|
+
request,
|
5261
|
+
forwardingQuantities
|
5262
|
+
);
|
5263
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5264
|
+
this.validateGas({
|
5265
|
+
gasUsed,
|
5266
|
+
gasPrice: request.gasPrice,
|
5267
|
+
gasLimit: request.gasLimit,
|
5268
|
+
minGasPrice
|
5269
|
+
});
|
5270
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5495
5271
|
return this.sendTransaction(request);
|
5496
5272
|
}
|
5497
5273
|
async signMessage(message) {
|
@@ -5549,7 +5325,18 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5549
5325
|
}
|
5550
5326
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5551
5327
|
}
|
5552
|
-
validateGas({
|
5328
|
+
validateGas({
|
5329
|
+
gasUsed,
|
5330
|
+
gasPrice,
|
5331
|
+
gasLimit,
|
5332
|
+
minGasPrice
|
5333
|
+
}) {
|
5334
|
+
if (minGasPrice.gt(gasPrice)) {
|
5335
|
+
throw new import_errors16.FuelError(
|
5336
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
5337
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5338
|
+
);
|
5339
|
+
}
|
5553
5340
|
if (gasUsed.gt(gasLimit)) {
|
5554
5341
|
throw new import_errors16.FuelError(
|
5555
5342
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5561,14 +5348,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5561
5348
|
|
5562
5349
|
// src/wallet/base-wallet-unlocked.ts
|
5563
5350
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5564
|
-
var
|
5351
|
+
var import_utils31 = require("@fuel-ts/utils");
|
5565
5352
|
|
5566
5353
|
// src/signer/signer.ts
|
5567
5354
|
var import_address5 = require("@fuel-ts/address");
|
5568
5355
|
var import_crypto = require("@fuel-ts/crypto");
|
5569
5356
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5570
|
-
var
|
5571
|
-
var
|
5357
|
+
var import_math19 = require("@fuel-ts/math");
|
5358
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5572
5359
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5573
5360
|
var Signer = class {
|
5574
5361
|
address;
|
@@ -5587,10 +5374,10 @@ var Signer = class {
|
|
5587
5374
|
privateKey = `0x${privateKey}`;
|
5588
5375
|
}
|
5589
5376
|
}
|
5590
|
-
const privateKeyBytes = (0,
|
5591
|
-
this.privateKey = (0,
|
5592
|
-
this.publicKey = (0,
|
5593
|
-
this.compressedPublicKey = (0,
|
5377
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
5378
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
5379
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5380
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5594
5381
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5595
5382
|
}
|
5596
5383
|
/**
|
@@ -5604,11 +5391,11 @@ var Signer = class {
|
|
5604
5391
|
* @returns hashed signature
|
5605
5392
|
*/
|
5606
5393
|
sign(data) {
|
5607
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5608
|
-
const r = (0,
|
5609
|
-
const s = (0,
|
5394
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
5395
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5396
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5610
5397
|
s[0] |= (signature.recovery || 0) << 7;
|
5611
|
-
return (0,
|
5398
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5612
5399
|
}
|
5613
5400
|
/**
|
5614
5401
|
* Add point on the current elliptic curve
|
@@ -5617,8 +5404,8 @@ var Signer = class {
|
|
5617
5404
|
* @returns compressed point on the curve
|
5618
5405
|
*/
|
5619
5406
|
addPoint(point) {
|
5620
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5621
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5407
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
5408
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5622
5409
|
const result = p0.add(p1);
|
5623
5410
|
return `0x${result.toHex(true)}`;
|
5624
5411
|
}
|
@@ -5630,16 +5417,16 @@ var Signer = class {
|
|
5630
5417
|
* @returns public key from signature from the
|
5631
5418
|
*/
|
5632
5419
|
static recoverPublicKey(data, signature) {
|
5633
|
-
const signedMessageBytes = (0,
|
5420
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5634
5421
|
const r = signedMessageBytes.slice(0, 32);
|
5635
5422
|
const s = signedMessageBytes.slice(32, 64);
|
5636
5423
|
const recoveryParam = (s[0] & 128) >> 7;
|
5637
5424
|
s[0] &= 127;
|
5638
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5425
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5639
5426
|
recoveryParam
|
5640
5427
|
);
|
5641
|
-
const publicKey = sig.recoverPublicKey((0,
|
5642
|
-
return (0,
|
5428
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5429
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5643
5430
|
}
|
5644
5431
|
/**
|
5645
5432
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5658,7 +5445,7 @@ var Signer = class {
|
|
5658
5445
|
* @returns random 32-byte hashed
|
5659
5446
|
*/
|
5660
5447
|
static generatePrivateKey(entropy) {
|
5661
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5448
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
5662
5449
|
}
|
5663
5450
|
/**
|
5664
5451
|
* Extended publicKey from a compact publicKey
|
@@ -5667,8 +5454,8 @@ var Signer = class {
|
|
5667
5454
|
* @returns extended publicKey
|
5668
5455
|
*/
|
5669
5456
|
static extendPublicKey(publicKey) {
|
5670
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5671
|
-
return (0,
|
5457
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5458
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5672
5459
|
}
|
5673
5460
|
};
|
5674
5461
|
|
@@ -5676,7 +5463,7 @@ var Signer = class {
|
|
5676
5463
|
var import_address6 = require("@fuel-ts/address");
|
5677
5464
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5678
5465
|
var import_errors17 = require("@fuel-ts/errors");
|
5679
|
-
var
|
5466
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5680
5467
|
var import_uuid = require("uuid");
|
5681
5468
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5682
5469
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5759,7 +5546,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5759
5546
|
);
|
5760
5547
|
}
|
5761
5548
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5762
|
-
const privateKey = (0,
|
5549
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5763
5550
|
return privateKey;
|
5764
5551
|
}
|
5765
5552
|
|
@@ -5804,7 +5591,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5804
5591
|
*/
|
5805
5592
|
async signMessage(message) {
|
5806
5593
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5807
|
-
return (0,
|
5594
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5808
5595
|
}
|
5809
5596
|
/**
|
5810
5597
|
* Signs a transaction with the wallet's private key.
|
@@ -5817,7 +5604,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5817
5604
|
const chainId = this.provider.getChainId();
|
5818
5605
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5819
5606
|
const signature = await this.signer().sign(hashedTransaction);
|
5820
|
-
return (0,
|
5607
|
+
return (0, import_utils31.hexlify)(signature);
|
5821
5608
|
}
|
5822
5609
|
/**
|
5823
5610
|
* Populates a transaction with the witnesses signature.
|
@@ -5837,7 +5624,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5837
5624
|
* @param transactionRequestLike - The transaction request to send.
|
5838
5625
|
* @returns A promise that resolves to the TransactionResponse object.
|
5839
5626
|
*/
|
5840
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5627
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5841
5628
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5842
5629
|
if (estimateTxDependencies) {
|
5843
5630
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5878,15 +5665,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5878
5665
|
// src/hdwallet/hdwallet.ts
|
5879
5666
|
var import_errors20 = require("@fuel-ts/errors");
|
5880
5667
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5881
|
-
var
|
5882
|
-
var
|
5668
|
+
var import_math20 = require("@fuel-ts/math");
|
5669
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5883
5670
|
var import_ethers4 = require("ethers");
|
5884
5671
|
|
5885
5672
|
// src/mnemonic/mnemonic.ts
|
5886
5673
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5887
5674
|
var import_errors19 = require("@fuel-ts/errors");
|
5888
5675
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5889
|
-
var
|
5676
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5890
5677
|
var import_ethers3 = require("ethers");
|
5891
5678
|
|
5892
5679
|
// src/wordlists/words/english.ts
|
@@ -7950,7 +7737,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7950
7737
|
// src/mnemonic/utils.ts
|
7951
7738
|
var import_errors18 = require("@fuel-ts/errors");
|
7952
7739
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7953
|
-
var
|
7740
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7954
7741
|
function toUtf8Bytes(stri) {
|
7955
7742
|
const str = stri.normalize("NFKD");
|
7956
7743
|
const result = [];
|
@@ -8017,14 +7804,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
8017
7804
|
}
|
8018
7805
|
}
|
8019
7806
|
const checksumBits = entropy.length / 4;
|
8020
|
-
const checksum = (0,
|
7807
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
8021
7808
|
indices[indices.length - 1] <<= checksumBits;
|
8022
7809
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
8023
7810
|
return indices;
|
8024
7811
|
}
|
8025
7812
|
function mnemonicWordsToEntropy(words, wordlist) {
|
8026
7813
|
const size = Math.ceil(11 * words.length / 8);
|
8027
|
-
const entropy = (0,
|
7814
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
8028
7815
|
let offset = 0;
|
8029
7816
|
for (let i = 0; i < words.length; i += 1) {
|
8030
7817
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -8044,7 +7831,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8044
7831
|
const entropyBits = 32 * words.length / 3;
|
8045
7832
|
const checksumBits = words.length / 3;
|
8046
7833
|
const checksumMask = getUpperMask(checksumBits);
|
8047
|
-
const checksum = (0,
|
7834
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
8048
7835
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
8049
7836
|
throw new import_errors18.FuelError(
|
8050
7837
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -8119,7 +7906,7 @@ var Mnemonic = class {
|
|
8119
7906
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
8120
7907
|
const words = getWords(phrase);
|
8121
7908
|
assertMnemonic(words);
|
8122
|
-
return (0,
|
7909
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
8123
7910
|
}
|
8124
7911
|
/**
|
8125
7912
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -8127,7 +7914,7 @@ var Mnemonic = class {
|
|
8127
7914
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8128
7915
|
*/
|
8129
7916
|
static entropyToMnemonic(entropy, wordlist = english) {
|
8130
|
-
const entropyBytes = (0,
|
7917
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
8131
7918
|
assertWordList(wordlist);
|
8132
7919
|
assertEntropy(entropyBytes);
|
8133
7920
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -8196,14 +7983,14 @@ var Mnemonic = class {
|
|
8196
7983
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8197
7984
|
*/
|
8198
7985
|
static masterKeysFromSeed(seed) {
|
8199
|
-
const seedArray = (0,
|
7986
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
8200
7987
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8201
7988
|
throw new import_errors19.FuelError(
|
8202
7989
|
import_errors19.ErrorCode.INVALID_SEED,
|
8203
7990
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8204
7991
|
);
|
8205
7992
|
}
|
8206
|
-
return (0,
|
7993
|
+
return (0, import_utils33.arrayify)((0, import_ethers3.computeHmac)("sha512", MasterSecret, seedArray));
|
8207
7994
|
}
|
8208
7995
|
/**
|
8209
7996
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8214,22 +8001,22 @@ var Mnemonic = class {
|
|
8214
8001
|
*/
|
8215
8002
|
static seedToExtendedKey(seed, testnet = false) {
|
8216
8003
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8217
|
-
const prefix = (0,
|
8004
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8218
8005
|
const depth = "0x00";
|
8219
8006
|
const fingerprint = "0x00000000";
|
8220
8007
|
const index = "0x00000000";
|
8221
8008
|
const chainCode = masterKey.slice(32);
|
8222
8009
|
const privateKey = masterKey.slice(0, 32);
|
8223
|
-
const extendedKey = (0,
|
8010
|
+
const extendedKey = (0, import_utils33.concat)([
|
8224
8011
|
prefix,
|
8225
8012
|
depth,
|
8226
8013
|
fingerprint,
|
8227
8014
|
index,
|
8228
8015
|
chainCode,
|
8229
|
-
(0,
|
8016
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
8230
8017
|
]);
|
8231
8018
|
const checksum = (0, import_ethers3.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8232
|
-
return (0, import_ethers3.encodeBase58)((0,
|
8019
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
8233
8020
|
}
|
8234
8021
|
/**
|
8235
8022
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8244,7 +8031,7 @@ var Mnemonic = class {
|
|
8244
8031
|
* @returns A randomly generated mnemonic
|
8245
8032
|
*/
|
8246
8033
|
static generate(size = 32, extraEntropy = "") {
|
8247
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8034
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
8248
8035
|
return Mnemonic.entropyToMnemonic(entropy);
|
8249
8036
|
}
|
8250
8037
|
};
|
@@ -8252,12 +8039,12 @@ var mnemonic_default = Mnemonic;
|
|
8252
8039
|
|
8253
8040
|
// src/hdwallet/hdwallet.ts
|
8254
8041
|
var HARDENED_INDEX = 2147483648;
|
8255
|
-
var MainnetPRV2 = (0,
|
8256
|
-
var MainnetPUB = (0,
|
8257
|
-
var TestnetPRV2 = (0,
|
8258
|
-
var TestnetPUB = (0,
|
8042
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
8043
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
8044
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
8045
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
8259
8046
|
function base58check(data) {
|
8260
|
-
return (0, import_ethers4.encodeBase58)((0,
|
8047
|
+
return (0, import_ethers4.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers4.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
8261
8048
|
}
|
8262
8049
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8263
8050
|
if (isPublic) {
|
@@ -8266,11 +8053,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8266
8053
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8267
8054
|
}
|
8268
8055
|
function isPublicExtendedKey(extendedKey) {
|
8269
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8056
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
8270
8057
|
}
|
8271
8058
|
function isValidExtendedKey(extendedKey) {
|
8272
8059
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8273
|
-
(0,
|
8060
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
8274
8061
|
);
|
8275
8062
|
}
|
8276
8063
|
function parsePath(path, depth = 0) {
|
@@ -8288,8 +8075,8 @@ function parsePath(path, depth = 0) {
|
|
8288
8075
|
var HDWallet = class {
|
8289
8076
|
depth = 0;
|
8290
8077
|
index = 0;
|
8291
|
-
fingerprint = (0,
|
8292
|
-
parentFingerprint = (0,
|
8078
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8079
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8293
8080
|
privateKey;
|
8294
8081
|
publicKey;
|
8295
8082
|
chainCode;
|
@@ -8301,8 +8088,8 @@ var HDWallet = class {
|
|
8301
8088
|
constructor(config) {
|
8302
8089
|
if (config.privateKey) {
|
8303
8090
|
const signer = new Signer(config.privateKey);
|
8304
|
-
this.publicKey = (0,
|
8305
|
-
this.privateKey = (0,
|
8091
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
8092
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
8306
8093
|
} else {
|
8307
8094
|
if (!config.publicKey) {
|
8308
8095
|
throw new import_errors20.FuelError(
|
@@ -8310,7 +8097,7 @@ var HDWallet = class {
|
|
8310
8097
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8311
8098
|
);
|
8312
8099
|
}
|
8313
|
-
this.publicKey = (0,
|
8100
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
8314
8101
|
}
|
8315
8102
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8316
8103
|
this.fingerprint = (0, import_ethers4.dataSlice)((0, import_ethers4.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -8329,9 +8116,9 @@ var HDWallet = class {
|
|
8329
8116
|
* @returns A new instance of HDWallet on the derived index
|
8330
8117
|
*/
|
8331
8118
|
deriveIndex(index) {
|
8332
|
-
const privateKey = this.privateKey && (0,
|
8333
|
-
const publicKey = (0,
|
8334
|
-
const chainCode = (0,
|
8119
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
8120
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
8121
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
8335
8122
|
const data = new Uint8Array(37);
|
8336
8123
|
if (index & HARDENED_INDEX) {
|
8337
8124
|
if (!privateKey) {
|
@@ -8342,15 +8129,15 @@ var HDWallet = class {
|
|
8342
8129
|
}
|
8343
8130
|
data.set(privateKey, 1);
|
8344
8131
|
} else {
|
8345
|
-
data.set((0,
|
8132
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
8346
8133
|
}
|
8347
|
-
data.set((0,
|
8348
|
-
const bytes = (0,
|
8134
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
8135
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers4.computeHmac)("sha512", chainCode, data));
|
8349
8136
|
const IL = bytes.slice(0, 32);
|
8350
8137
|
const IR = bytes.slice(32);
|
8351
8138
|
if (privateKey) {
|
8352
8139
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8353
|
-
const ki = (0,
|
8140
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8354
8141
|
return new HDWallet({
|
8355
8142
|
privateKey: ki,
|
8356
8143
|
chainCode: IR,
|
@@ -8359,7 +8146,7 @@ var HDWallet = class {
|
|
8359
8146
|
parentFingerprint: this.fingerprint
|
8360
8147
|
});
|
8361
8148
|
}
|
8362
|
-
const signer = new Signer((0,
|
8149
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
8363
8150
|
const Ki = signer.addPoint(publicKey);
|
8364
8151
|
return new HDWallet({
|
8365
8152
|
publicKey: Ki,
|
@@ -8394,12 +8181,12 @@ var HDWallet = class {
|
|
8394
8181
|
);
|
8395
8182
|
}
|
8396
8183
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8397
|
-
const depth = (0,
|
8184
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
8398
8185
|
const parentFingerprint = this.parentFingerprint;
|
8399
|
-
const index = (0,
|
8186
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
8400
8187
|
const chainCode = this.chainCode;
|
8401
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8402
|
-
const extendedKey = (0,
|
8188
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8189
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8403
8190
|
return base58check(extendedKey);
|
8404
8191
|
}
|
8405
8192
|
/**
|
@@ -8411,13 +8198,13 @@ var HDWallet = class {
|
|
8411
8198
|
static fromSeed(seed) {
|
8412
8199
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8413
8200
|
return new HDWallet({
|
8414
|
-
chainCode: (0,
|
8415
|
-
privateKey: (0,
|
8201
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
8202
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
8416
8203
|
});
|
8417
8204
|
}
|
8418
8205
|
static fromExtendedKey(extendedKey) {
|
8419
8206
|
const decoded = (0, import_ethers4.toBeHex)((0, import_ethers4.decodeBase58)(extendedKey));
|
8420
|
-
const bytes = (0,
|
8207
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
8421
8208
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8422
8209
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8423
8210
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8426,9 +8213,9 @@ var HDWallet = class {
|
|
8426
8213
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8427
8214
|
}
|
8428
8215
|
const depth = bytes[4];
|
8429
|
-
const parentFingerprint = (0,
|
8430
|
-
const index = parseInt((0,
|
8431
|
-
const chainCode = (0,
|
8216
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
8217
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8218
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
8432
8219
|
const key = bytes.slice(45, 78);
|
8433
8220
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8434
8221
|
throw new import_errors20.FuelError(
|
@@ -9033,19 +8820,19 @@ var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
|
9033
8820
|
var import_address10 = require("@fuel-ts/address");
|
9034
8821
|
var import_configs13 = require("@fuel-ts/address/configs");
|
9035
8822
|
var import_errors25 = require("@fuel-ts/errors");
|
9036
|
-
var
|
9037
|
-
var
|
8823
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
8824
|
+
var import_utils37 = require("@fuel-ts/utils");
|
9038
8825
|
|
9039
8826
|
// src/predicate/utils/getPredicateRoot.ts
|
9040
8827
|
var import_hasher7 = require("@fuel-ts/hasher");
|
9041
8828
|
var import_merkle = require("@fuel-ts/merkle");
|
9042
|
-
var
|
8829
|
+
var import_utils36 = require("@fuel-ts/utils");
|
9043
8830
|
var getPredicateRoot = (bytecode) => {
|
9044
8831
|
const chunkSize = 16 * 1024;
|
9045
|
-
const bytes = (0,
|
9046
|
-
const chunks = (0,
|
9047
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
9048
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
8832
|
+
const bytes = (0, import_utils36.arrayify)(bytecode);
|
8833
|
+
const chunks = (0, import_utils36.chunkAndPadBytes)(bytes, chunkSize);
|
8834
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils36.hexlify)(c)));
|
8835
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils36.concat)(["0x4655454C", codeRoot]));
|
9049
8836
|
return predicateRoot;
|
9050
8837
|
};
|
9051
8838
|
|
@@ -9082,7 +8869,6 @@ var Predicate = class extends Account {
|
|
9082
8869
|
this.interface = predicateInterface;
|
9083
8870
|
if (inputData !== void 0 && inputData.length > 0) {
|
9084
8871
|
this.predicateData = inputData;
|
9085
|
-
this.predicateDataBytes = this.getPredicateData(0);
|
9086
8872
|
}
|
9087
8873
|
}
|
9088
8874
|
/**
|
@@ -9095,9 +8881,9 @@ var Predicate = class extends Account {
|
|
9095
8881
|
const request = transactionRequestify(transactionRequestLike);
|
9096
8882
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
9097
8883
|
request.inputs?.forEach((input) => {
|
9098
|
-
if (input.type ===
|
9099
|
-
input.predicate =
|
9100
|
-
input.predicateData =
|
8884
|
+
if (input.type === import_transactions20.InputType.Coin && (0, import_utils37.hexlify)(input.owner) === this.address.toB256()) {
|
8885
|
+
input.predicate = this.bytes;
|
8886
|
+
input.predicateData = this.getPredicateData(policies.length);
|
9101
8887
|
}
|
9102
8888
|
});
|
9103
8889
|
return request;
|
@@ -9112,7 +8898,8 @@ var Predicate = class extends Account {
|
|
9112
8898
|
* @returns A promise that resolves to the prepared transaction request.
|
9113
8899
|
*/
|
9114
8900
|
async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
|
9115
|
-
|
8901
|
+
const request = await super.createTransfer(destination, amount, assetId, txParams);
|
8902
|
+
return this.populateTransactionPredicateData(request);
|
9116
8903
|
}
|
9117
8904
|
/**
|
9118
8905
|
* Sends a transaction with the populated predicate data.
|
@@ -9120,9 +8907,9 @@ var Predicate = class extends Account {
|
|
9120
8907
|
* @param transactionRequestLike - The transaction request-like object.
|
9121
8908
|
* @returns A promise that resolves to the transaction response.
|
9122
8909
|
*/
|
9123
|
-
sendTransaction(transactionRequestLike) {
|
9124
|
-
const transactionRequest =
|
9125
|
-
return super.sendTransaction(transactionRequest,
|
8910
|
+
sendTransaction(transactionRequestLike, options) {
|
8911
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8912
|
+
return super.sendTransaction(transactionRequest, options);
|
9126
8913
|
}
|
9127
8914
|
/**
|
9128
8915
|
* Simulates a transaction with the populated predicate data.
|
@@ -9131,15 +8918,15 @@ var Predicate = class extends Account {
|
|
9131
8918
|
* @returns A promise that resolves to the call result.
|
9132
8919
|
*/
|
9133
8920
|
simulateTransaction(transactionRequestLike) {
|
9134
|
-
const transactionRequest =
|
9135
|
-
return super.simulateTransaction(transactionRequest
|
8921
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8922
|
+
return super.simulateTransaction(transactionRequest);
|
9136
8923
|
}
|
9137
8924
|
getPredicateData(policiesLength) {
|
9138
8925
|
if (!this.predicateData.length) {
|
9139
8926
|
return new Uint8Array();
|
9140
8927
|
}
|
9141
8928
|
const mainFn = this.interface?.functions.main;
|
9142
|
-
const paddedCode = new
|
8929
|
+
const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
9143
8930
|
const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
|
9144
8931
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
9145
8932
|
});
|
@@ -9155,7 +8942,7 @@ var Predicate = class extends Account {
|
|
9155
8942
|
* @returns An object containing the new predicate bytes and interface.
|
9156
8943
|
*/
|
9157
8944
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
9158
|
-
let predicateBytes = (0,
|
8945
|
+
let predicateBytes = (0, import_utils37.arrayify)(bytes);
|
9159
8946
|
let abiInterface;
|
9160
8947
|
if (jsonAbi) {
|
9161
8948
|
abiInterface = new import_abi_coder5.Interface(jsonAbi);
|
@@ -9178,26 +8965,6 @@ var Predicate = class extends Account {
|
|
9178
8965
|
predicateInterface: abiInterface
|
9179
8966
|
};
|
9180
8967
|
}
|
9181
|
-
/**
|
9182
|
-
* Retrieves resources satisfying the spend query for the account.
|
9183
|
-
*
|
9184
|
-
* @param quantities - IDs of coins to exclude.
|
9185
|
-
* @param excludedIds - IDs of resources to be excluded from the query.
|
9186
|
-
* @returns A promise that resolves to an array of Resources.
|
9187
|
-
*/
|
9188
|
-
async getResourcesToSpend(quantities, excludedIds) {
|
9189
|
-
const resources = await this.provider.getResourcesToSpend(
|
9190
|
-
this.address,
|
9191
|
-
quantities,
|
9192
|
-
excludedIds
|
9193
|
-
);
|
9194
|
-
return resources.map((resource) => ({
|
9195
|
-
...resource,
|
9196
|
-
predicate: (0, import_utils36.hexlify)(this.bytes),
|
9197
|
-
predicateData: (0, import_utils36.hexlify)(this.predicateDataBytes),
|
9198
|
-
paddPredicateData: (policiesLength) => (0, import_utils36.hexlify)(this.getPredicateData(policiesLength))
|
9199
|
-
}));
|
9200
|
-
}
|
9201
8968
|
/**
|
9202
8969
|
* Sets the configurable constants for the predicate.
|
9203
8970
|
*
|
@@ -9947,7 +9714,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9947
9714
|
WalletLocked,
|
9948
9715
|
WalletManager,
|
9949
9716
|
WalletUnlocked,
|
9950
|
-
|
9717
|
+
addAmountToAsset,
|
9951
9718
|
addOperation,
|
9952
9719
|
assemblePanicError,
|
9953
9720
|
assembleReceiptByType,
|
@@ -9956,10 +9723,9 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9956
9723
|
assets,
|
9957
9724
|
buildBlockExplorerUrl,
|
9958
9725
|
cacheFor,
|
9959
|
-
cacheTxInputsFromOwner,
|
9960
|
-
calculateGasFee,
|
9961
9726
|
calculateMetadataGasForTxCreate,
|
9962
9727
|
calculateMetadataGasForTxScript,
|
9728
|
+
calculatePriceWithFactor,
|
9963
9729
|
calculateTransactionFee,
|
9964
9730
|
coinQuantityfy,
|
9965
9731
|
deferPromise,
|