@fuel-ts/account 0.0.0-rc-2021-20240410132122 → 0.0.0-rc-2034-20240410133013
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 +560 -793
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +523 -760
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +404 -640
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -11
- 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 +1059 -1506
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +519 -735
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +413 -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,8 @@ var BaseTransactionRequest = class {
|
|
2135
2054
|
amount,
|
2136
2055
|
assetId,
|
2137
2056
|
txPointer: "0x00000000000000000000000000000000",
|
2138
|
-
witnessIndex
|
2057
|
+
witnessIndex,
|
2058
|
+
predicate: predicate?.bytes
|
2139
2059
|
};
|
2140
2060
|
this.pushInput(input);
|
2141
2061
|
this.addChangeOutput(owner, assetId);
|
@@ -2148,11 +2068,11 @@ var BaseTransactionRequest = class {
|
|
2148
2068
|
* @param predicate - Predicate bytes.
|
2149
2069
|
* @param predicateData - Predicate data bytes.
|
2150
2070
|
*/
|
2151
|
-
addMessageInput(message) {
|
2071
|
+
addMessageInput(message, predicate) {
|
2152
2072
|
const { recipient, sender, amount } = message;
|
2153
2073
|
const assetId = import_configs7.BaseAssetId;
|
2154
2074
|
let witnessIndex;
|
2155
|
-
if (
|
2075
|
+
if (predicate) {
|
2156
2076
|
witnessIndex = 0;
|
2157
2077
|
} else {
|
2158
2078
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -2166,7 +2086,8 @@ var BaseTransactionRequest = class {
|
|
2166
2086
|
sender: sender.toB256(),
|
2167
2087
|
recipient: recipient.toB256(),
|
2168
2088
|
amount,
|
2169
|
-
witnessIndex
|
2089
|
+
witnessIndex,
|
2090
|
+
predicate: predicate?.bytes
|
2170
2091
|
};
|
2171
2092
|
this.pushInput(input);
|
2172
2093
|
this.addChangeOutput(recipient, assetId);
|
@@ -2197,6 +2118,32 @@ var BaseTransactionRequest = class {
|
|
2197
2118
|
resources.forEach((resource) => this.addResource(resource));
|
2198
2119
|
return this;
|
2199
2120
|
}
|
2121
|
+
/**
|
2122
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
2123
|
+
* outputs from the related assetIds.
|
2124
|
+
*
|
2125
|
+
* @param resources - The resources to add.
|
2126
|
+
* @returns This transaction.
|
2127
|
+
*/
|
2128
|
+
addPredicateResource(resource, predicate) {
|
2129
|
+
if (isCoin(resource)) {
|
2130
|
+
this.addCoinInput(resource, predicate);
|
2131
|
+
} else {
|
2132
|
+
this.addMessageInput(resource, predicate);
|
2133
|
+
}
|
2134
|
+
return this;
|
2135
|
+
}
|
2136
|
+
/**
|
2137
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
2138
|
+
* from the related assetIds.
|
2139
|
+
*
|
2140
|
+
* @param resources - The resources to add.
|
2141
|
+
* @returns This transaction.
|
2142
|
+
*/
|
2143
|
+
addPredicateResources(resources, predicate) {
|
2144
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
2145
|
+
return this;
|
2146
|
+
}
|
2200
2147
|
/**
|
2201
2148
|
* Adds a coin output to the transaction.
|
2202
2149
|
*
|
@@ -2276,7 +2223,7 @@ var BaseTransactionRequest = class {
|
|
2276
2223
|
}
|
2277
2224
|
calculateMaxGas(chainInfo, minGas) {
|
2278
2225
|
const { consensusParameters } = chainInfo;
|
2279
|
-
const { gasPerByte
|
2226
|
+
const { gasPerByte } = consensusParameters;
|
2280
2227
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2281
2228
|
(acc, wit) => acc + wit.dataLength,
|
2282
2229
|
0
|
@@ -2285,8 +2232,7 @@ var BaseTransactionRequest = class {
|
|
2285
2232
|
gasPerByte,
|
2286
2233
|
minGas,
|
2287
2234
|
witnessesLength,
|
2288
|
-
witnessLimit: this.witnessLimit
|
2289
|
-
maxGasPerTx
|
2235
|
+
witnessLimit: this.witnessLimit
|
2290
2236
|
});
|
2291
2237
|
}
|
2292
2238
|
/**
|
@@ -2304,20 +2250,17 @@ var BaseTransactionRequest = class {
|
|
2304
2250
|
});
|
2305
2251
|
const updateAssetInput = (assetId, quantity) => {
|
2306
2252
|
const assetInput = findAssetInput(assetId);
|
2307
|
-
let usedQuantity = quantity;
|
2308
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2309
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2310
|
-
}
|
2311
2253
|
if (assetInput && "assetId" in assetInput) {
|
2312
|
-
assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(
|
2313
|
-
assetInput.amount =
|
2254
|
+
assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(33));
|
2255
|
+
assetInput.amount = quantity;
|
2314
2256
|
} else {
|
2315
2257
|
this.addResources([
|
2316
2258
|
{
|
2317
|
-
id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(
|
2318
|
-
amount:
|
2259
|
+
id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(33)),
|
2260
|
+
amount: quantity,
|
2319
2261
|
assetId,
|
2320
2262
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2263
|
+
maturity: 0,
|
2321
2264
|
blockCreated: (0, import_math7.bn)(1),
|
2322
2265
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2323
2266
|
}
|
@@ -2349,7 +2292,7 @@ var BaseTransactionRequest = class {
|
|
2349
2292
|
toJSON() {
|
2350
2293
|
return normalizeJSON(this);
|
2351
2294
|
}
|
2352
|
-
|
2295
|
+
updatePredicateInputs(inputs) {
|
2353
2296
|
this.inputs.forEach((i) => {
|
2354
2297
|
let correspondingInput;
|
2355
2298
|
switch (i.type) {
|
@@ -2371,15 +2314,6 @@ var BaseTransactionRequest = class {
|
|
2371
2314
|
}
|
2372
2315
|
});
|
2373
2316
|
}
|
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
2317
|
};
|
2384
2318
|
|
2385
2319
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2526,8 +2460,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2526
2460
|
return {
|
2527
2461
|
type: import_transactions8.TransactionType.Create,
|
2528
2462
|
...baseTransaction,
|
2463
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2529
2464
|
bytecodeWitnessIndex,
|
2530
|
-
storageSlotsCount:
|
2465
|
+
storageSlotsCount: storageSlots.length,
|
2531
2466
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2532
2467
|
storageSlots
|
2533
2468
|
};
|
@@ -2650,8 +2585,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2650
2585
|
type: import_transactions9.TransactionType.Script,
|
2651
2586
|
scriptGasLimit: this.gasLimit,
|
2652
2587
|
...super.getBaseTransaction(),
|
2653
|
-
scriptLength:
|
2654
|
-
scriptDataLength:
|
2588
|
+
scriptLength: script.length,
|
2589
|
+
scriptDataLength: scriptData.length,
|
2655
2590
|
receiptsRoot: import_configs10.ZeroBytes32,
|
2656
2591
|
script: (0, import_utils15.hexlify)(script),
|
2657
2592
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2715,7 +2650,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2715
2650
|
}
|
2716
2651
|
calculateMaxGas(chainInfo, minGas) {
|
2717
2652
|
const { consensusParameters } = chainInfo;
|
2718
|
-
const { gasPerByte
|
2653
|
+
const { gasPerByte } = consensusParameters;
|
2719
2654
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2720
2655
|
(acc, wit) => acc + wit.dataLength,
|
2721
2656
|
0
|
@@ -2725,8 +2660,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2725
2660
|
minGas,
|
2726
2661
|
witnessesLength,
|
2727
2662
|
witnessLimit: this.witnessLimit,
|
2728
|
-
gasLimit: this.gasLimit
|
2729
|
-
maxGasPerTx
|
2663
|
+
gasLimit: this.gasLimit
|
2730
2664
|
});
|
2731
2665
|
}
|
2732
2666
|
/**
|
@@ -2801,32 +2735,15 @@ var transactionRequestify = (obj) => {
|
|
2801
2735
|
}
|
2802
2736
|
}
|
2803
2737
|
};
|
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
2738
|
|
2820
2739
|
// src/providers/transaction-response/transaction-response.ts
|
2821
2740
|
var import_errors13 = require("@fuel-ts/errors");
|
2822
|
-
var
|
2823
|
-
var
|
2824
|
-
var
|
2741
|
+
var import_math14 = require("@fuel-ts/math");
|
2742
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2743
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2825
2744
|
|
2826
2745
|
// 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");
|
2746
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2830
2747
|
|
2831
2748
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2832
2749
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2834,10 +2751,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2834
2751
|
var import_utils16 = require("@fuel-ts/utils");
|
2835
2752
|
var calculateTransactionFee = (params) => {
|
2836
2753
|
const {
|
2837
|
-
|
2754
|
+
gasUsed,
|
2838
2755
|
rawPayload,
|
2839
|
-
|
2840
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2756
|
+
consensusParameters: { gasCosts, feeParams }
|
2841
2757
|
} = params;
|
2842
2758
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2843
2759
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2847,7 +2763,8 @@ var calculateTransactionFee = (params) => {
|
|
2847
2763
|
return {
|
2848
2764
|
fee: (0, import_math11.bn)(0),
|
2849
2765
|
minFee: (0, import_math11.bn)(0),
|
2850
|
-
maxFee: (0, import_math11.bn)(0)
|
2766
|
+
maxFee: (0, import_math11.bn)(0),
|
2767
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2851
2768
|
};
|
2852
2769
|
}
|
2853
2770
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2879,6 +2796,7 @@ var calculateTransactionFee = (params) => {
|
|
2879
2796
|
metadataGas,
|
2880
2797
|
txBytesSize: transactionBytes.length
|
2881
2798
|
});
|
2799
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2882
2800
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2883
2801
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2884
2802
|
const maxGas = getMaxGas({
|
@@ -2886,25 +2804,17 @@ var calculateTransactionFee = (params) => {
|
|
2886
2804
|
minGas,
|
2887
2805
|
witnessesLength,
|
2888
2806
|
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
|
2807
|
+
witnessLimit
|
2903
2808
|
});
|
2809
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2810
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2811
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2812
|
+
const fee = minFee.add(feeFromGasUsed);
|
2904
2813
|
return {
|
2814
|
+
fee,
|
2905
2815
|
minFee,
|
2906
2816
|
maxFee,
|
2907
|
-
|
2817
|
+
feeFromGasUsed
|
2908
2818
|
};
|
2909
2819
|
};
|
2910
2820
|
|
@@ -3518,12 +3428,10 @@ function assembleTransactionSummary(params) {
|
|
3518
3428
|
gqlTransactionStatus,
|
3519
3429
|
abiMap = {},
|
3520
3430
|
maxInputs,
|
3521
|
-
gasCosts
|
3522
|
-
maxGasPerTx,
|
3523
|
-
gasPrice
|
3431
|
+
gasCosts
|
3524
3432
|
} = params;
|
3525
3433
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3526
|
-
const rawPayload = (0,
|
3434
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3527
3435
|
const operations = getOperations({
|
3528
3436
|
transactionType: transaction.type,
|
3529
3437
|
inputs: transaction.inputs || [],
|
@@ -3534,14 +3442,11 @@ function assembleTransactionSummary(params) {
|
|
3534
3442
|
maxInputs
|
3535
3443
|
});
|
3536
3444
|
const typeName = getTransactionTypeName(transaction.type);
|
3537
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3538
3445
|
const { fee } = calculateTransactionFee({
|
3539
|
-
|
3446
|
+
gasUsed,
|
3540
3447
|
rawPayload,
|
3541
|
-
tip,
|
3542
3448
|
consensusParameters: {
|
3543
3449
|
gasCosts,
|
3544
|
-
maxGasPerTx,
|
3545
3450
|
feeParams: {
|
3546
3451
|
gasPerByte,
|
3547
3452
|
gasPriceFactor
|
@@ -3553,7 +3458,7 @@ function assembleTransactionSummary(params) {
|
|
3553
3458
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3554
3459
|
let date;
|
3555
3460
|
if (time) {
|
3556
|
-
date =
|
3461
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3557
3462
|
}
|
3558
3463
|
const transactionSummary = {
|
3559
3464
|
id,
|
@@ -3581,12 +3486,12 @@ function assembleTransactionSummary(params) {
|
|
3581
3486
|
|
3582
3487
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3583
3488
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3584
|
-
var
|
3489
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3585
3490
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3586
3491
|
return receipts.reduce((logs, receipt) => {
|
3587
|
-
if (receipt.type ===
|
3492
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3588
3493
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3589
|
-
const data = receipt.type ===
|
3494
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3590
3495
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3591
3496
|
logs.push(decodedLog);
|
3592
3497
|
}
|
@@ -3601,7 +3506,7 @@ var TransactionResponse = class {
|
|
3601
3506
|
/** Current provider */
|
3602
3507
|
provider;
|
3603
3508
|
/** Gas used on the transaction */
|
3604
|
-
gasUsed = (0,
|
3509
|
+
gasUsed = (0, import_math14.bn)(0);
|
3605
3510
|
/** The graphql Transaction with receipts object. */
|
3606
3511
|
gqlTransaction;
|
3607
3512
|
abis;
|
@@ -3659,8 +3564,8 @@ var TransactionResponse = class {
|
|
3659
3564
|
* @returns The decoded transaction.
|
3660
3565
|
*/
|
3661
3566
|
decodeTransaction(transactionWithReceipts) {
|
3662
|
-
return new
|
3663
|
-
(0,
|
3567
|
+
return new import_transactions17.TransactionCoder().decode(
|
3568
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3664
3569
|
0
|
3665
3570
|
)?.[0];
|
3666
3571
|
}
|
@@ -3679,27 +3584,20 @@ var TransactionResponse = class {
|
|
3679
3584
|
const decodedTransaction = this.decodeTransaction(
|
3680
3585
|
transaction
|
3681
3586
|
);
|
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();
|
3587
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3588
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3689
3589
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3690
3590
|
const transactionSummary = assembleTransactionSummary({
|
3691
3591
|
id: this.id,
|
3692
3592
|
receipts,
|
3693
3593
|
transaction: decodedTransaction,
|
3694
|
-
transactionBytes: (0,
|
3594
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3695
3595
|
gqlTransactionStatus: transaction.status,
|
3696
3596
|
gasPerByte,
|
3697
3597
|
gasPriceFactor,
|
3698
3598
|
abiMap: contractsAbiMap,
|
3699
3599
|
maxInputs,
|
3700
|
-
gasCosts
|
3701
|
-
maxGasPerTx,
|
3702
|
-
gasPrice
|
3600
|
+
gasCosts
|
3703
3601
|
});
|
3704
3602
|
return transactionSummary;
|
3705
3603
|
}
|
@@ -3826,29 +3724,29 @@ var processGqlChain = (chain) => {
|
|
3826
3724
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3827
3725
|
return {
|
3828
3726
|
name,
|
3829
|
-
baseChainHeight: (0,
|
3727
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3830
3728
|
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,
|
3729
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3730
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3731
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3732
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3733
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3734
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3735
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3736
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3737
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3738
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3739
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3740
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3741
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3742
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3743
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3846
3744
|
gasCosts
|
3847
3745
|
},
|
3848
3746
|
gasCosts,
|
3849
3747
|
latestBlock: {
|
3850
3748
|
id: latestBlock.id,
|
3851
|
-
height: (0,
|
3749
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3852
3750
|
time: latestBlock.header.time,
|
3853
3751
|
transactions: latestBlock.transactions.map((i) => ({
|
3854
3752
|
id: i.id
|
@@ -3942,8 +3840,10 @@ var _Provider = class {
|
|
3942
3840
|
* Returns some helpful parameters related to gas fees.
|
3943
3841
|
*/
|
3944
3842
|
getGasConfig() {
|
3843
|
+
const { minGasPrice } = this.getNode();
|
3945
3844
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3946
3845
|
return {
|
3846
|
+
minGasPrice,
|
3947
3847
|
maxGasPerTx,
|
3948
3848
|
maxGasPerPredicate,
|
3949
3849
|
gasPriceFactor,
|
@@ -4041,7 +3941,7 @@ var _Provider = class {
|
|
4041
3941
|
*/
|
4042
3942
|
async getBlockNumber() {
|
4043
3943
|
const { chain } = await this.operations.getChain();
|
4044
|
-
return (0,
|
3944
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
4045
3945
|
}
|
4046
3946
|
/**
|
4047
3947
|
* Returns the chain information.
|
@@ -4051,11 +3951,13 @@ var _Provider = class {
|
|
4051
3951
|
async fetchNode() {
|
4052
3952
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
4053
3953
|
const processedNodeInfo = {
|
4054
|
-
maxDepth: (0,
|
4055
|
-
maxTx: (0,
|
3954
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3955
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3956
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
4056
3957
|
nodeVersion: nodeInfo.nodeVersion,
|
4057
3958
|
utxoValidation: nodeInfo.utxoValidation,
|
4058
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3959
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3960
|
+
peers: nodeInfo.peers
|
4059
3961
|
};
|
4060
3962
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
4061
3963
|
return processedNodeInfo;
|
@@ -4097,9 +3999,9 @@ var _Provider = class {
|
|
4097
3999
|
if (estimateTxDependencies) {
|
4098
4000
|
await this.estimateTxDependencies(transactionRequest);
|
4099
4001
|
}
|
4100
|
-
const encodedTransaction = (0,
|
4002
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4101
4003
|
let abis;
|
4102
|
-
if (transactionRequest.type ===
|
4004
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4103
4005
|
abis = transactionRequest.abis;
|
4104
4006
|
}
|
4105
4007
|
if (awaitExecution) {
|
@@ -4140,14 +4042,15 @@ var _Provider = class {
|
|
4140
4042
|
if (estimateTxDependencies) {
|
4141
4043
|
return this.estimateTxDependencies(transactionRequest);
|
4142
4044
|
}
|
4143
|
-
const encodedTransaction = (0,
|
4144
|
-
const { dryRun:
|
4145
|
-
|
4045
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4046
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4047
|
+
encodedTransaction,
|
4146
4048
|
utxoValidation: utxoValidation || false
|
4147
4049
|
});
|
4148
|
-
const
|
4149
|
-
|
4150
|
-
|
4050
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4051
|
+
return {
|
4052
|
+
receipts
|
4053
|
+
};
|
4151
4054
|
}
|
4152
4055
|
/**
|
4153
4056
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -4158,13 +4061,13 @@ var _Provider = class {
|
|
4158
4061
|
async estimatePredicates(transactionRequest) {
|
4159
4062
|
const shouldEstimatePredicates = Boolean(
|
4160
4063
|
transactionRequest.inputs.find(
|
4161
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4064
|
+
(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
4065
|
)
|
4163
4066
|
);
|
4164
4067
|
if (!shouldEstimatePredicates) {
|
4165
4068
|
return transactionRequest;
|
4166
4069
|
}
|
4167
|
-
const encodedTransaction = (0,
|
4070
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4168
4071
|
const response = await this.operations.estimatePredicates({
|
4169
4072
|
encodedTransaction
|
4170
4073
|
});
|
@@ -4173,7 +4076,7 @@ var _Provider = class {
|
|
4173
4076
|
} = response;
|
4174
4077
|
if (inputs) {
|
4175
4078
|
inputs.forEach((input, index) => {
|
4176
|
-
if ("predicateGasUsed" in input && (0,
|
4079
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
4177
4080
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4178
4081
|
}
|
4179
4082
|
});
|
@@ -4186,31 +4089,31 @@ var _Provider = class {
|
|
4186
4089
|
* If there are missing variable outputs,
|
4187
4090
|
* `addVariableOutputs` is called on the transaction.
|
4188
4091
|
*
|
4092
|
+
* @privateRemarks
|
4093
|
+
* TODO: Investigate support for missing contract IDs
|
4094
|
+
* TODO: Add support for missing output messages
|
4189
4095
|
*
|
4190
4096
|
* @param transactionRequest - The transaction request object.
|
4191
4097
|
* @returns A promise.
|
4192
4098
|
*/
|
4193
4099
|
async estimateTxDependencies(transactionRequest) {
|
4194
|
-
if (transactionRequest.type ===
|
4100
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
4195
4101
|
return {
|
4196
4102
|
receipts: [],
|
4197
4103
|
outputVariables: 0,
|
4198
4104
|
missingContractIds: []
|
4199
4105
|
};
|
4200
4106
|
}
|
4107
|
+
await this.estimatePredicates(transactionRequest);
|
4201
4108
|
let receipts = [];
|
4202
4109
|
const missingContractIds = [];
|
4203
4110
|
let outputVariables = 0;
|
4204
|
-
let dryrunStatus;
|
4205
4111
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4206
|
-
const {
|
4207
|
-
|
4208
|
-
} = await this.operations.dryRun({
|
4209
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
4112
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4113
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
4210
4114
|
utxoValidation: false
|
4211
4115
|
});
|
4212
|
-
receipts =
|
4213
|
-
dryrunStatus = status;
|
4116
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
4214
4117
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
4215
4118
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
4216
4119
|
if (hasMissingOutputs) {
|
@@ -4220,11 +4123,6 @@ var _Provider = class {
|
|
4220
4123
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4221
4124
|
missingContractIds.push(contractId);
|
4222
4125
|
});
|
4223
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4224
|
-
transactionRequest,
|
4225
|
-
optimizeGas: false
|
4226
|
-
});
|
4227
|
-
transactionRequest.maxFee = maxFee;
|
4228
4126
|
} else {
|
4229
4127
|
break;
|
4230
4128
|
}
|
@@ -4232,133 +4130,38 @@ var _Provider = class {
|
|
4232
4130
|
return {
|
4233
4131
|
receipts,
|
4234
4132
|
outputVariables,
|
4235
|
-
missingContractIds
|
4236
|
-
dryrunStatus
|
4133
|
+
missingContractIds
|
4237
4134
|
};
|
4238
4135
|
}
|
4239
4136
|
/**
|
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.
|
4137
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
4138
|
+
* @param transactionRequest - The transaction request object.
|
4139
|
+
* @param optimizeGas - Optional. Specifies whether to optimize the gas. Default is false.
|
4140
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4248
4141
|
*/
|
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;
|
4142
|
+
estimateTxGasAndFee(params) {
|
4143
|
+
const { transactionRequest } = params;
|
4144
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4327
4145
|
const chainInfo = this.getChain();
|
4328
|
-
const
|
4146
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
4147
|
+
transactionRequest.gasPrice = gasPrice;
|
4329
4148
|
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) {
|
4149
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4150
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4151
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
4343
4152
|
transactionRequest.gasLimit = minGas;
|
4344
|
-
gasLimit =
|
4345
|
-
|
4153
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4154
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4155
|
+
);
|
4346
4156
|
}
|
4347
4157
|
}
|
4348
4158
|
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);
|
4159
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4355
4160
|
return {
|
4356
4161
|
minGas,
|
4357
4162
|
minFee,
|
4358
4163
|
maxGas,
|
4359
|
-
maxFee
|
4360
|
-
gasPrice,
|
4361
|
-
gasLimit
|
4164
|
+
maxFee
|
4362
4165
|
};
|
4363
4166
|
}
|
4364
4167
|
/**
|
@@ -4376,17 +4179,15 @@ var _Provider = class {
|
|
4376
4179
|
if (estimateTxDependencies) {
|
4377
4180
|
return this.estimateTxDependencies(transactionRequest);
|
4378
4181
|
}
|
4379
|
-
const
|
4380
|
-
const { dryRun:
|
4381
|
-
|
4182
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
4183
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4184
|
+
encodedTransaction,
|
4382
4185
|
utxoValidation: true
|
4383
4186
|
});
|
4384
|
-
const
|
4385
|
-
|
4386
|
-
|
4387
|
-
|
4388
|
-
});
|
4389
|
-
return { receipts: callResult[0].receipts };
|
4187
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
4188
|
+
return {
|
4189
|
+
receipts
|
4190
|
+
};
|
4390
4191
|
}
|
4391
4192
|
/**
|
4392
4193
|
* Returns a transaction cost to enable user
|
@@ -4403,80 +4204,77 @@ var _Provider = class {
|
|
4403
4204
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4404
4205
|
* @returns A promise that resolves to the transaction cost object.
|
4405
4206
|
*/
|
4406
|
-
async getTransactionCost(transactionRequestLike,
|
4207
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
4208
|
+
estimateTxDependencies = true,
|
4209
|
+
estimatePredicates = true,
|
4210
|
+
resourcesOwner,
|
4211
|
+
signatureCallback
|
4212
|
+
} = {}) {
|
4407
4213
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4408
|
-
const
|
4214
|
+
const { minGasPrice } = this.getGasConfig();
|
4215
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
4216
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4409
4217
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4410
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4218
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4411
4219
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4412
|
-
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4413
4220
|
if (isScriptTransaction) {
|
4414
|
-
txRequestClone.gasLimit = (0,
|
4221
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4415
4222
|
}
|
4416
|
-
if (
|
4417
|
-
resourcesOwner
|
4223
|
+
if (estimatePredicates) {
|
4224
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4225
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
4226
|
+
}
|
4227
|
+
await this.estimatePredicates(txRequestClone);
|
4418
4228
|
}
|
4419
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4420
|
-
let addedSignatures = 0;
|
4421
4229
|
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
|
4230
|
+
await signatureCallback(txRequestClone);
|
4231
|
+
}
|
4232
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4233
|
+
transactionRequest: txRequestClone
|
4430
4234
|
});
|
4431
|
-
txRequestClone.maxFee = maxFee;
|
4432
4235
|
let receipts = [];
|
4433
4236
|
let missingContractIds = [];
|
4434
4237
|
let outputVariables = 0;
|
4435
|
-
let gasUsed = (0,
|
4436
|
-
|
4437
|
-
|
4438
|
-
if (signatureCallback) {
|
4439
|
-
await signatureCallback(txRequestClone);
|
4440
|
-
}
|
4441
|
-
txRequestClone.gasLimit = gasLimit;
|
4238
|
+
let gasUsed = (0, import_math15.bn)(0);
|
4239
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4240
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4442
4241
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4443
4242
|
receipts = result.receipts;
|
4444
4243
|
outputVariables = result.outputVariables;
|
4445
4244
|
missingContractIds = result.missingContractIds;
|
4446
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
4245
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4447
4246
|
txRequestClone.gasLimit = gasUsed;
|
4448
|
-
|
4449
|
-
|
4450
|
-
|
4247
|
+
txRequestClone.gasPrice = setGasPrice;
|
4248
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4249
|
+
transactionRequest: txRequestClone
|
4451
4250
|
}));
|
4452
4251
|
}
|
4453
4252
|
return {
|
4454
4253
|
requiredQuantities: allQuantities,
|
4455
4254
|
receipts,
|
4456
4255
|
gasUsed,
|
4457
|
-
|
4256
|
+
minGasPrice,
|
4257
|
+
gasPrice: setGasPrice,
|
4458
4258
|
minGas,
|
4459
4259
|
maxGas,
|
4460
4260
|
minFee,
|
4461
4261
|
maxFee,
|
4262
|
+
estimatedInputs: txRequestClone.inputs,
|
4462
4263
|
outputVariables,
|
4463
|
-
missingContractIds
|
4464
|
-
addedSignatures,
|
4465
|
-
estimatedPredicates: txRequestClone.inputs
|
4264
|
+
missingContractIds
|
4466
4265
|
};
|
4467
4266
|
}
|
4468
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4267
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4469
4268
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4470
4269
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4471
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4472
|
-
quantitiesToContract
|
4473
|
-
});
|
4270
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4474
4271
|
transactionRequest.addResources(
|
4475
4272
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4476
4273
|
);
|
4477
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4478
|
-
|
4479
|
-
|
4274
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4275
|
+
transactionRequest,
|
4276
|
+
forwardingQuantities
|
4277
|
+
);
|
4480
4278
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4481
4279
|
return {
|
4482
4280
|
resources,
|
@@ -4492,16 +4290,17 @@ var _Provider = class {
|
|
4492
4290
|
const result = await this.operations.getCoins({
|
4493
4291
|
first: 10,
|
4494
4292
|
...paginationArgs,
|
4495
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4293
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4496
4294
|
});
|
4497
4295
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4498
4296
|
return coins.map((coin) => ({
|
4499
4297
|
id: coin.utxoId,
|
4500
4298
|
assetId: coin.assetId,
|
4501
|
-
amount: (0,
|
4299
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4502
4300
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4503
|
-
|
4504
|
-
|
4301
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4302
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4303
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4505
4304
|
}));
|
4506
4305
|
}
|
4507
4306
|
/**
|
@@ -4515,19 +4314,19 @@ var _Provider = class {
|
|
4515
4314
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4516
4315
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4517
4316
|
const excludeInput = {
|
4518
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4519
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4317
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4318
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4520
4319
|
};
|
4521
4320
|
if (this.cache) {
|
4522
4321
|
const uniqueUtxos = new Set(
|
4523
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4322
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4524
4323
|
);
|
4525
4324
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4526
4325
|
}
|
4527
4326
|
const coinsQuery = {
|
4528
4327
|
owner: ownerAddress.toB256(),
|
4529
4328
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4530
|
-
assetId: (0,
|
4329
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4531
4330
|
amount: amount.toString(10),
|
4532
4331
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4533
4332
|
})),
|
@@ -4538,9 +4337,9 @@ var _Provider = class {
|
|
4538
4337
|
switch (coin.__typename) {
|
4539
4338
|
case "MessageCoin":
|
4540
4339
|
return {
|
4541
|
-
amount: (0,
|
4340
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4542
4341
|
assetId: coin.assetId,
|
4543
|
-
daHeight: (0,
|
4342
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4544
4343
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4545
4344
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4546
4345
|
nonce: coin.nonce
|
@@ -4548,11 +4347,12 @@ var _Provider = class {
|
|
4548
4347
|
case "Coin":
|
4549
4348
|
return {
|
4550
4349
|
id: coin.utxoId,
|
4551
|
-
amount: (0,
|
4350
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4552
4351
|
assetId: coin.assetId,
|
4553
4352
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4554
|
-
|
4555
|
-
|
4353
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4354
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4355
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4556
4356
|
};
|
4557
4357
|
default:
|
4558
4358
|
return null;
|
@@ -4569,13 +4369,13 @@ var _Provider = class {
|
|
4569
4369
|
async getBlock(idOrHeight) {
|
4570
4370
|
let variables;
|
4571
4371
|
if (typeof idOrHeight === "number") {
|
4572
|
-
variables = { height: (0,
|
4372
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4573
4373
|
} else if (idOrHeight === "latest") {
|
4574
4374
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4575
4375
|
} else if (idOrHeight.length === 66) {
|
4576
4376
|
variables = { blockId: idOrHeight };
|
4577
4377
|
} else {
|
4578
|
-
variables = { blockId: (0,
|
4378
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4579
4379
|
}
|
4580
4380
|
const { block } = await this.operations.getBlock(variables);
|
4581
4381
|
if (!block) {
|
@@ -4583,7 +4383,7 @@ var _Provider = class {
|
|
4583
4383
|
}
|
4584
4384
|
return {
|
4585
4385
|
id: block.id,
|
4586
|
-
height: (0,
|
4386
|
+
height: (0, import_math15.bn)(block.header.height),
|
4587
4387
|
time: block.header.time,
|
4588
4388
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4589
4389
|
};
|
@@ -4598,7 +4398,7 @@ var _Provider = class {
|
|
4598
4398
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4599
4399
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4600
4400
|
id: block.id,
|
4601
|
-
height: (0,
|
4401
|
+
height: (0, import_math15.bn)(block.header.height),
|
4602
4402
|
time: block.header.time,
|
4603
4403
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4604
4404
|
}));
|
@@ -4613,7 +4413,7 @@ var _Provider = class {
|
|
4613
4413
|
async getBlockWithTransactions(idOrHeight) {
|
4614
4414
|
let variables;
|
4615
4415
|
if (typeof idOrHeight === "number") {
|
4616
|
-
variables = { blockHeight: (0,
|
4416
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4617
4417
|
} else if (idOrHeight === "latest") {
|
4618
4418
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4619
4419
|
} else {
|
@@ -4625,11 +4425,11 @@ var _Provider = class {
|
|
4625
4425
|
}
|
4626
4426
|
return {
|
4627
4427
|
id: block.id,
|
4628
|
-
height: (0,
|
4428
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4629
4429
|
time: block.header.time,
|
4630
4430
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4631
4431
|
transactions: block.transactions.map(
|
4632
|
-
(tx) => new
|
4432
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4633
4433
|
)
|
4634
4434
|
};
|
4635
4435
|
}
|
@@ -4644,8 +4444,8 @@ var _Provider = class {
|
|
4644
4444
|
if (!transaction) {
|
4645
4445
|
return null;
|
4646
4446
|
}
|
4647
|
-
return new
|
4648
|
-
(0,
|
4447
|
+
return new import_transactions18.TransactionCoder().decode(
|
4448
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4649
4449
|
0
|
4650
4450
|
)?.[0];
|
4651
4451
|
}
|
@@ -4672,9 +4472,9 @@ var _Provider = class {
|
|
4672
4472
|
async getContractBalance(contractId, assetId) {
|
4673
4473
|
const { contractBalance } = await this.operations.getContractBalance({
|
4674
4474
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4675
|
-
asset: (0,
|
4475
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4676
4476
|
});
|
4677
|
-
return (0,
|
4477
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4678
4478
|
}
|
4679
4479
|
/**
|
4680
4480
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4686,9 +4486,9 @@ var _Provider = class {
|
|
4686
4486
|
async getBalance(owner, assetId) {
|
4687
4487
|
const { balance } = await this.operations.getBalance({
|
4688
4488
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4689
|
-
assetId: (0,
|
4489
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4690
4490
|
});
|
4691
|
-
return (0,
|
4491
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4692
4492
|
}
|
4693
4493
|
/**
|
4694
4494
|
* Returns balances for the given owner.
|
@@ -4706,7 +4506,7 @@ var _Provider = class {
|
|
4706
4506
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4707
4507
|
return balances.map((balance) => ({
|
4708
4508
|
assetId: balance.assetId,
|
4709
|
-
amount: (0,
|
4509
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4710
4510
|
}));
|
4711
4511
|
}
|
4712
4512
|
/**
|
@@ -4724,19 +4524,19 @@ var _Provider = class {
|
|
4724
4524
|
});
|
4725
4525
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4726
4526
|
return messages.map((message) => ({
|
4727
|
-
messageId:
|
4527
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4728
4528
|
sender: message.sender,
|
4729
4529
|
recipient: message.recipient,
|
4730
4530
|
nonce: message.nonce,
|
4731
|
-
amount: (0,
|
4531
|
+
amount: (0, import_math15.bn)(message.amount),
|
4732
4532
|
data: message.data
|
4733
4533
|
}),
|
4734
4534
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4735
4535
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4736
4536
|
nonce: message.nonce,
|
4737
|
-
amount: (0,
|
4738
|
-
data:
|
4739
|
-
daHeight: (0,
|
4537
|
+
amount: (0, import_math15.bn)(message.amount),
|
4538
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4539
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4740
4540
|
}));
|
4741
4541
|
}
|
4742
4542
|
/**
|
@@ -4789,52 +4589,44 @@ var _Provider = class {
|
|
4789
4589
|
} = result.messageProof;
|
4790
4590
|
return {
|
4791
4591
|
messageProof: {
|
4792
|
-
proofIndex: (0,
|
4592
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4793
4593
|
proofSet: messageProof.proofSet
|
4794
4594
|
},
|
4795
4595
|
blockProof: {
|
4796
|
-
proofIndex: (0,
|
4596
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4797
4597
|
proofSet: blockProof.proofSet
|
4798
4598
|
},
|
4799
4599
|
messageBlockHeader: {
|
4800
4600
|
id: messageBlockHeader.id,
|
4801
|
-
daHeight: (0,
|
4802
|
-
transactionsCount: (0,
|
4601
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4602
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4803
4603
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4804
|
-
height: (0,
|
4604
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4805
4605
|
prevRoot: messageBlockHeader.prevRoot,
|
4806
4606
|
time: messageBlockHeader.time,
|
4807
4607
|
applicationHash: messageBlockHeader.applicationHash,
|
4808
|
-
|
4608
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4609
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4809
4610
|
},
|
4810
4611
|
commitBlockHeader: {
|
4811
4612
|
id: commitBlockHeader.id,
|
4812
|
-
daHeight: (0,
|
4813
|
-
transactionsCount: (0,
|
4613
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4614
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4814
4615
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4815
|
-
height: (0,
|
4616
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4816
4617
|
prevRoot: commitBlockHeader.prevRoot,
|
4817
4618
|
time: commitBlockHeader.time,
|
4818
4619
|
applicationHash: commitBlockHeader.applicationHash,
|
4819
|
-
|
4620
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4621
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4820
4622
|
},
|
4821
4623
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4822
4624
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4823
4625
|
nonce,
|
4824
|
-
amount: (0,
|
4626
|
+
amount: (0, import_math15.bn)(amount),
|
4825
4627
|
data
|
4826
4628
|
};
|
4827
4629
|
}
|
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
4630
|
/**
|
4839
4631
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4840
4632
|
*
|
@@ -4854,10 +4646,10 @@ var _Provider = class {
|
|
4854
4646
|
*/
|
4855
4647
|
async produceBlocks(amount, startTime) {
|
4856
4648
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4857
|
-
blocksToProduce: (0,
|
4858
|
-
startTimestamp: startTime ?
|
4649
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4650
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4859
4651
|
});
|
4860
|
-
return (0,
|
4652
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4861
4653
|
}
|
4862
4654
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4863
4655
|
async getTransactionResponse(transactionId) {
|
@@ -4871,7 +4663,7 @@ cacheInputs_fn = function(inputs) {
|
|
4871
4663
|
return;
|
4872
4664
|
}
|
4873
4665
|
inputs.forEach((input) => {
|
4874
|
-
if (input.type ===
|
4666
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4875
4667
|
this.cache?.set(input.id);
|
4876
4668
|
}
|
4877
4669
|
});
|
@@ -4881,9 +4673,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4881
4673
|
|
4882
4674
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4883
4675
|
var import_errors15 = require("@fuel-ts/errors");
|
4884
|
-
var
|
4885
|
-
var
|
4886
|
-
var
|
4676
|
+
var import_math16 = require("@fuel-ts/math");
|
4677
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4678
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4887
4679
|
async function getTransactionSummary(params) {
|
4888
4680
|
const { id, provider, abiMap } = params;
|
4889
4681
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
@@ -4895,32 +4687,25 @@ async function getTransactionSummary(params) {
|
|
4895
4687
|
`Transaction not found for given id: ${id}.`
|
4896
4688
|
);
|
4897
4689
|
}
|
4898
|
-
const [decodedTransaction] = new
|
4899
|
-
(0,
|
4690
|
+
const [decodedTransaction] = new import_transactions19.TransactionCoder().decode(
|
4691
|
+
(0, import_utils26.arrayify)(gqlTransaction.rawPayload),
|
4900
4692
|
0
|
4901
4693
|
);
|
4902
|
-
|
4903
|
-
if (gqlTransaction?.status && "receipts" in gqlTransaction.status) {
|
4904
|
-
txReceipts = gqlTransaction.status.receipts;
|
4905
|
-
}
|
4906
|
-
const receipts = txReceipts.map(processGqlReceipt);
|
4694
|
+
const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
|
4907
4695
|
const {
|
4908
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4696
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4909
4697
|
} = provider.getChain();
|
4910
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4911
4698
|
const transactionInfo = assembleTransactionSummary({
|
4912
4699
|
id: gqlTransaction.id,
|
4913
4700
|
receipts,
|
4914
4701
|
transaction: decodedTransaction,
|
4915
|
-
transactionBytes: (0,
|
4702
|
+
transactionBytes: (0, import_utils26.arrayify)(gqlTransaction.rawPayload),
|
4916
4703
|
gqlTransactionStatus: gqlTransaction.status,
|
4917
|
-
gasPerByte: (0,
|
4918
|
-
gasPriceFactor: (0,
|
4704
|
+
gasPerByte: (0, import_math16.bn)(gasPerByte),
|
4705
|
+
gasPriceFactor: (0, import_math16.bn)(gasPriceFactor),
|
4919
4706
|
abiMap,
|
4920
4707
|
maxInputs,
|
4921
|
-
gasCosts
|
4922
|
-
maxGasPerTx,
|
4923
|
-
gasPrice
|
4708
|
+
gasCosts
|
4924
4709
|
});
|
4925
4710
|
return {
|
4926
4711
|
gqlTransaction,
|
@@ -4930,11 +4715,10 @@ async function getTransactionSummary(params) {
|
|
4930
4715
|
async function getTransactionSummaryFromRequest(params) {
|
4931
4716
|
const { provider, transactionRequest, abiMap } = params;
|
4932
4717
|
const { receipts } = await provider.call(transactionRequest);
|
4933
|
-
const { gasPerByte, gasPriceFactor, gasCosts
|
4718
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = provider.getGasConfig();
|
4934
4719
|
const maxInputs = provider.getChain().consensusParameters.maxInputs;
|
4935
4720
|
const transaction = transactionRequest.toTransaction();
|
4936
4721
|
const transactionBytes = transactionRequest.toTransactionBytes();
|
4937
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4938
4722
|
const transactionSummary = assembleTransactionSummary({
|
4939
4723
|
receipts,
|
4940
4724
|
transaction,
|
@@ -4943,9 +4727,7 @@ async function getTransactionSummaryFromRequest(params) {
|
|
4943
4727
|
gasPerByte,
|
4944
4728
|
gasPriceFactor,
|
4945
4729
|
maxInputs,
|
4946
|
-
gasCosts
|
4947
|
-
maxGasPerTx,
|
4948
|
-
gasPrice
|
4730
|
+
gasCosts
|
4949
4731
|
});
|
4950
4732
|
return transactionSummary;
|
4951
4733
|
}
|
@@ -4954,31 +4736,24 @@ async function getTransactionsSummaries(params) {
|
|
4954
4736
|
const { transactionsByOwner } = await provider.operations.getTransactionsByOwner(filters);
|
4955
4737
|
const { edges, pageInfo } = transactionsByOwner;
|
4956
4738
|
const {
|
4957
|
-
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts
|
4739
|
+
consensusParameters: { gasPerByte, gasPriceFactor, maxInputs, gasCosts }
|
4958
4740
|
} = provider.getChain();
|
4959
|
-
const gasPrice = await provider.getLatestGasPrice();
|
4960
4741
|
const transactions = edges.map((edge) => {
|
4961
4742
|
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);
|
4743
|
+
const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
|
4744
|
+
const [decodedTransaction] = new import_transactions19.TransactionCoder().decode((0, import_utils26.arrayify)(rawPayload), 0);
|
4745
|
+
const receipts = gqlReceipts?.map(processGqlReceipt) || [];
|
4969
4746
|
const transactionSummary = assembleTransactionSummary({
|
4970
4747
|
id,
|
4971
4748
|
receipts,
|
4972
4749
|
transaction: decodedTransaction,
|
4973
|
-
transactionBytes: (0,
|
4750
|
+
transactionBytes: (0, import_utils26.arrayify)(rawPayload),
|
4974
4751
|
gqlTransactionStatus: status,
|
4975
4752
|
abiMap,
|
4976
4753
|
gasPerByte,
|
4977
4754
|
gasPriceFactor,
|
4978
4755
|
maxInputs,
|
4979
|
-
gasCosts
|
4980
|
-
maxGasPerTx,
|
4981
|
-
gasPrice
|
4756
|
+
gasCosts
|
4982
4757
|
});
|
4983
4758
|
const output = {
|
4984
4759
|
gqlTransaction,
|
@@ -5115,17 +4890,17 @@ var assets = [
|
|
5115
4890
|
|
5116
4891
|
// src/utils/formatTransferToContractScriptData.ts
|
5117
4892
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
5118
|
-
var
|
5119
|
-
var
|
4893
|
+
var import_math17 = require("@fuel-ts/math");
|
4894
|
+
var import_utils27 = require("@fuel-ts/utils");
|
5120
4895
|
var asm = __toESM(require("@fuels/vm-asm"));
|
5121
4896
|
var formatTransferToContractScriptData = (params) => {
|
5122
4897
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
5123
4898
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
5124
|
-
const encoded = numberCoder.encode(new
|
4899
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
5125
4900
|
const scriptData = Uint8Array.from([
|
5126
|
-
...(0,
|
4901
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
5127
4902
|
...encoded,
|
5128
|
-
...(0,
|
4903
|
+
...(0, import_utils27.arrayify)(assetId)
|
5129
4904
|
]);
|
5130
4905
|
return scriptData;
|
5131
4906
|
};
|
@@ -5310,33 +5085,36 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5310
5085
|
* @param fee - The estimated transaction fee.
|
5311
5086
|
* @returns A promise that resolves when the resources are added to the transaction.
|
5312
5087
|
*/
|
5313
|
-
async fund(request,
|
5314
|
-
const
|
5315
|
-
|
5316
|
-
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5317
|
-
amount: (0, import_math19.bn)(fee),
|
5088
|
+
async fund(request, coinQuantities, fee) {
|
5089
|
+
const updatedQuantities = addAmountToAsset({
|
5090
|
+
amount: (0, import_math18.bn)(fee),
|
5318
5091
|
assetId: import_configs12.BaseAssetId,
|
5319
|
-
coinQuantities
|
5092
|
+
coinQuantities
|
5320
5093
|
});
|
5321
5094
|
const quantitiesDict = {};
|
5322
|
-
|
5095
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
5323
5096
|
quantitiesDict[assetId] = {
|
5324
5097
|
required: amount,
|
5325
|
-
owned: (0,
|
5098
|
+
owned: (0, import_math18.bn)(0)
|
5326
5099
|
};
|
5327
5100
|
});
|
5328
|
-
|
5101
|
+
const cachedUtxos = [];
|
5102
|
+
const cachedMessages = [];
|
5103
|
+
const owner = this.address.toB256();
|
5104
|
+
request.inputs.forEach((input) => {
|
5329
5105
|
const isResource = "amount" in input;
|
5330
5106
|
if (isResource) {
|
5331
5107
|
const isCoin2 = "owner" in input;
|
5332
5108
|
if (isCoin2) {
|
5333
5109
|
const assetId = String(input.assetId);
|
5334
|
-
if (quantitiesDict[assetId]) {
|
5335
|
-
const amount = (0,
|
5110
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
5111
|
+
const amount = (0, import_math18.bn)(input.amount);
|
5336
5112
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5113
|
+
cachedUtxos.push(input.id);
|
5337
5114
|
}
|
5338
|
-
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5115
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
5339
5116
|
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
5117
|
+
cachedMessages.push(input.nonce);
|
5340
5118
|
}
|
5341
5119
|
}
|
5342
5120
|
});
|
@@ -5351,23 +5129,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5351
5129
|
});
|
5352
5130
|
const needsToBeFunded = missingQuantities.length;
|
5353
5131
|
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
|
-
);
|
5132
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
5133
|
+
messages: cachedMessages,
|
5134
|
+
utxos: cachedUtxos
|
5135
|
+
});
|
5136
|
+
request.addResources(resources);
|
5365
5137
|
}
|
5366
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
5367
|
-
transactionRequest: requestToBeReEstimate
|
5368
|
-
});
|
5369
|
-
txRequest.maxFee = maxFee;
|
5370
|
-
return txRequest;
|
5371
5138
|
}
|
5372
5139
|
/**
|
5373
5140
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -5375,25 +5142,28 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5375
5142
|
* @param destination - The address of the destination.
|
5376
5143
|
* @param amount - The amount of coins to transfer.
|
5377
5144
|
* @param assetId - The asset ID of the coins to transfer.
|
5378
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5145
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5379
5146
|
* @returns A promise that resolves to the prepared transaction request.
|
5380
5147
|
*/
|
5381
5148
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5382
|
-
const
|
5149
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5150
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5151
|
+
const request = new ScriptTransactionRequest(params);
|
5383
5152
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
5384
|
-
const
|
5153
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
5385
5154
|
estimateTxDependencies: true,
|
5386
5155
|
resourcesOwner: this
|
5387
5156
|
});
|
5388
|
-
|
5389
|
-
|
5390
|
-
|
5391
|
-
|
5392
|
-
|
5393
|
-
|
5394
|
-
|
5395
|
-
|
5396
|
-
await this.fund(request,
|
5157
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
5158
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
5159
|
+
this.validateGas({
|
5160
|
+
gasUsed,
|
5161
|
+
gasPrice: request.gasPrice,
|
5162
|
+
gasLimit: request.gasLimit,
|
5163
|
+
minGasPrice
|
5164
|
+
});
|
5165
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5166
|
+
request.updatePredicateInputs(estimatedInputs);
|
5397
5167
|
return request;
|
5398
5168
|
}
|
5399
5169
|
/**
|
@@ -5406,7 +5176,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5406
5176
|
* @returns A promise that resolves to the transaction response.
|
5407
5177
|
*/
|
5408
5178
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5409
|
-
if ((0,
|
5179
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5410
5180
|
throw new import_errors16.FuelError(
|
5411
5181
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5412
5182
|
"Transfer amount must be a positive number."
|
@@ -5425,37 +5195,38 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5425
5195
|
* @returns A promise that resolves to the transaction response.
|
5426
5196
|
*/
|
5427
5197
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5428
|
-
if ((0,
|
5198
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5429
5199
|
throw new import_errors16.FuelError(
|
5430
5200
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5431
5201
|
"Transfer amount must be a positive number."
|
5432
5202
|
);
|
5433
5203
|
}
|
5434
5204
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
5205
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5206
|
+
const params = { gasPrice: minGasPrice, ...txParams };
|
5435
5207
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5436
5208
|
hexlifiedContractId: contractAddress.toB256(),
|
5437
|
-
amountToTransfer: (0,
|
5209
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
5438
5210
|
assetId
|
5439
5211
|
});
|
5440
5212
|
const request = new ScriptTransactionRequest({
|
5441
|
-
...
|
5213
|
+
...params,
|
5442
5214
|
script,
|
5443
5215
|
scriptData
|
5444
5216
|
});
|
5445
5217
|
request.addContractInputAndOutput(contractAddress);
|
5446
|
-
const
|
5447
|
-
|
5448
|
-
|
5218
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5219
|
+
request,
|
5220
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
5221
|
+
);
|
5222
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5223
|
+
this.validateGas({
|
5224
|
+
gasUsed,
|
5225
|
+
gasPrice: request.gasPrice,
|
5226
|
+
gasLimit: request.gasLimit,
|
5227
|
+
minGasPrice
|
5449
5228
|
});
|
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);
|
5229
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5459
5230
|
return this.sendTransaction(request);
|
5460
5231
|
}
|
5461
5232
|
/**
|
@@ -5467,31 +5238,34 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5467
5238
|
* @returns A promise that resolves to the transaction response.
|
5468
5239
|
*/
|
5469
5240
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5241
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
5470
5242
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5471
|
-
const recipientDataArray = (0,
|
5243
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5472
5244
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5473
5245
|
);
|
5474
|
-
const amountDataArray = (0,
|
5475
|
-
"0x".concat((0,
|
5246
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
5247
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5476
5248
|
);
|
5477
5249
|
const script = new Uint8Array([
|
5478
|
-
...(0,
|
5250
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5479
5251
|
...recipientDataArray,
|
5480
5252
|
...amountDataArray
|
5481
5253
|
]);
|
5482
|
-
const params = { script, ...txParams };
|
5254
|
+
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5483
5255
|
const request = new ScriptTransactionRequest(params);
|
5484
|
-
const
|
5485
|
-
const
|
5486
|
-
|
5487
|
-
|
5488
|
-
|
5489
|
-
|
5490
|
-
|
5491
|
-
|
5492
|
-
|
5493
|
-
|
5494
|
-
|
5256
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5257
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5258
|
+
request,
|
5259
|
+
forwardingQuantities
|
5260
|
+
);
|
5261
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
5262
|
+
this.validateGas({
|
5263
|
+
gasUsed,
|
5264
|
+
gasPrice: request.gasPrice,
|
5265
|
+
gasLimit: request.gasLimit,
|
5266
|
+
minGasPrice
|
5267
|
+
});
|
5268
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5495
5269
|
return this.sendTransaction(request);
|
5496
5270
|
}
|
5497
5271
|
async signMessage(message) {
|
@@ -5549,7 +5323,18 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5549
5323
|
}
|
5550
5324
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5551
5325
|
}
|
5552
|
-
validateGas({
|
5326
|
+
validateGas({
|
5327
|
+
gasUsed,
|
5328
|
+
gasPrice,
|
5329
|
+
gasLimit,
|
5330
|
+
minGasPrice
|
5331
|
+
}) {
|
5332
|
+
if (minGasPrice.gt(gasPrice)) {
|
5333
|
+
throw new import_errors16.FuelError(
|
5334
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
5335
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5336
|
+
);
|
5337
|
+
}
|
5553
5338
|
if (gasUsed.gt(gasLimit)) {
|
5554
5339
|
throw new import_errors16.FuelError(
|
5555
5340
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5561,14 +5346,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5561
5346
|
|
5562
5347
|
// src/wallet/base-wallet-unlocked.ts
|
5563
5348
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5564
|
-
var
|
5349
|
+
var import_utils31 = require("@fuel-ts/utils");
|
5565
5350
|
|
5566
5351
|
// src/signer/signer.ts
|
5567
5352
|
var import_address5 = require("@fuel-ts/address");
|
5568
5353
|
var import_crypto = require("@fuel-ts/crypto");
|
5569
5354
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5570
|
-
var
|
5571
|
-
var
|
5355
|
+
var import_math19 = require("@fuel-ts/math");
|
5356
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5572
5357
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5573
5358
|
var Signer = class {
|
5574
5359
|
address;
|
@@ -5587,10 +5372,10 @@ var Signer = class {
|
|
5587
5372
|
privateKey = `0x${privateKey}`;
|
5588
5373
|
}
|
5589
5374
|
}
|
5590
|
-
const privateKeyBytes = (0,
|
5591
|
-
this.privateKey = (0,
|
5592
|
-
this.publicKey = (0,
|
5593
|
-
this.compressedPublicKey = (0,
|
5375
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
5376
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
5377
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5378
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5594
5379
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5595
5380
|
}
|
5596
5381
|
/**
|
@@ -5604,11 +5389,11 @@ var Signer = class {
|
|
5604
5389
|
* @returns hashed signature
|
5605
5390
|
*/
|
5606
5391
|
sign(data) {
|
5607
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5608
|
-
const r = (0,
|
5609
|
-
const s = (0,
|
5392
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
5393
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5394
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5610
5395
|
s[0] |= (signature.recovery || 0) << 7;
|
5611
|
-
return (0,
|
5396
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5612
5397
|
}
|
5613
5398
|
/**
|
5614
5399
|
* Add point on the current elliptic curve
|
@@ -5617,8 +5402,8 @@ var Signer = class {
|
|
5617
5402
|
* @returns compressed point on the curve
|
5618
5403
|
*/
|
5619
5404
|
addPoint(point) {
|
5620
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5621
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5405
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
5406
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5622
5407
|
const result = p0.add(p1);
|
5623
5408
|
return `0x${result.toHex(true)}`;
|
5624
5409
|
}
|
@@ -5630,16 +5415,16 @@ var Signer = class {
|
|
5630
5415
|
* @returns public key from signature from the
|
5631
5416
|
*/
|
5632
5417
|
static recoverPublicKey(data, signature) {
|
5633
|
-
const signedMessageBytes = (0,
|
5418
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5634
5419
|
const r = signedMessageBytes.slice(0, 32);
|
5635
5420
|
const s = signedMessageBytes.slice(32, 64);
|
5636
5421
|
const recoveryParam = (s[0] & 128) >> 7;
|
5637
5422
|
s[0] &= 127;
|
5638
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5423
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5639
5424
|
recoveryParam
|
5640
5425
|
);
|
5641
|
-
const publicKey = sig.recoverPublicKey((0,
|
5642
|
-
return (0,
|
5426
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5427
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5643
5428
|
}
|
5644
5429
|
/**
|
5645
5430
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5658,7 +5443,7 @@ var Signer = class {
|
|
5658
5443
|
* @returns random 32-byte hashed
|
5659
5444
|
*/
|
5660
5445
|
static generatePrivateKey(entropy) {
|
5661
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5446
|
+
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
5447
|
}
|
5663
5448
|
/**
|
5664
5449
|
* Extended publicKey from a compact publicKey
|
@@ -5667,8 +5452,8 @@ var Signer = class {
|
|
5667
5452
|
* @returns extended publicKey
|
5668
5453
|
*/
|
5669
5454
|
static extendPublicKey(publicKey) {
|
5670
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5671
|
-
return (0,
|
5455
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5456
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5672
5457
|
}
|
5673
5458
|
};
|
5674
5459
|
|
@@ -5676,7 +5461,7 @@ var Signer = class {
|
|
5676
5461
|
var import_address6 = require("@fuel-ts/address");
|
5677
5462
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5678
5463
|
var import_errors17 = require("@fuel-ts/errors");
|
5679
|
-
var
|
5464
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5680
5465
|
var import_uuid = require("uuid");
|
5681
5466
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5682
5467
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5759,7 +5544,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5759
5544
|
);
|
5760
5545
|
}
|
5761
5546
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5762
|
-
const privateKey = (0,
|
5547
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5763
5548
|
return privateKey;
|
5764
5549
|
}
|
5765
5550
|
|
@@ -5804,7 +5589,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5804
5589
|
*/
|
5805
5590
|
async signMessage(message) {
|
5806
5591
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5807
|
-
return (0,
|
5592
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5808
5593
|
}
|
5809
5594
|
/**
|
5810
5595
|
* Signs a transaction with the wallet's private key.
|
@@ -5817,7 +5602,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5817
5602
|
const chainId = this.provider.getChainId();
|
5818
5603
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5819
5604
|
const signature = await this.signer().sign(hashedTransaction);
|
5820
|
-
return (0,
|
5605
|
+
return (0, import_utils31.hexlify)(signature);
|
5821
5606
|
}
|
5822
5607
|
/**
|
5823
5608
|
* Populates a transaction with the witnesses signature.
|
@@ -5837,7 +5622,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5837
5622
|
* @param transactionRequestLike - The transaction request to send.
|
5838
5623
|
* @returns A promise that resolves to the TransactionResponse object.
|
5839
5624
|
*/
|
5840
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5625
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5841
5626
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5842
5627
|
if (estimateTxDependencies) {
|
5843
5628
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5878,15 +5663,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5878
5663
|
// src/hdwallet/hdwallet.ts
|
5879
5664
|
var import_errors20 = require("@fuel-ts/errors");
|
5880
5665
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5881
|
-
var
|
5882
|
-
var
|
5666
|
+
var import_math20 = require("@fuel-ts/math");
|
5667
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5883
5668
|
var import_ethers4 = require("ethers");
|
5884
5669
|
|
5885
5670
|
// src/mnemonic/mnemonic.ts
|
5886
5671
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5887
5672
|
var import_errors19 = require("@fuel-ts/errors");
|
5888
5673
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5889
|
-
var
|
5674
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5890
5675
|
var import_ethers3 = require("ethers");
|
5891
5676
|
|
5892
5677
|
// src/wordlists/words/english.ts
|
@@ -7950,7 +7735,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7950
7735
|
// src/mnemonic/utils.ts
|
7951
7736
|
var import_errors18 = require("@fuel-ts/errors");
|
7952
7737
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7953
|
-
var
|
7738
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7954
7739
|
function toUtf8Bytes(stri) {
|
7955
7740
|
const str = stri.normalize("NFKD");
|
7956
7741
|
const result = [];
|
@@ -8017,14 +7802,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
8017
7802
|
}
|
8018
7803
|
}
|
8019
7804
|
const checksumBits = entropy.length / 4;
|
8020
|
-
const checksum = (0,
|
7805
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
8021
7806
|
indices[indices.length - 1] <<= checksumBits;
|
8022
7807
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
8023
7808
|
return indices;
|
8024
7809
|
}
|
8025
7810
|
function mnemonicWordsToEntropy(words, wordlist) {
|
8026
7811
|
const size = Math.ceil(11 * words.length / 8);
|
8027
|
-
const entropy = (0,
|
7812
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
8028
7813
|
let offset = 0;
|
8029
7814
|
for (let i = 0; i < words.length; i += 1) {
|
8030
7815
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -8044,7 +7829,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
8044
7829
|
const entropyBits = 32 * words.length / 3;
|
8045
7830
|
const checksumBits = words.length / 3;
|
8046
7831
|
const checksumMask = getUpperMask(checksumBits);
|
8047
|
-
const checksum = (0,
|
7832
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
8048
7833
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
8049
7834
|
throw new import_errors18.FuelError(
|
8050
7835
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -8119,7 +7904,7 @@ var Mnemonic = class {
|
|
8119
7904
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
8120
7905
|
const words = getWords(phrase);
|
8121
7906
|
assertMnemonic(words);
|
8122
|
-
return (0,
|
7907
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
8123
7908
|
}
|
8124
7909
|
/**
|
8125
7910
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -8127,7 +7912,7 @@ var Mnemonic = class {
|
|
8127
7912
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8128
7913
|
*/
|
8129
7914
|
static entropyToMnemonic(entropy, wordlist = english) {
|
8130
|
-
const entropyBytes = (0,
|
7915
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
8131
7916
|
assertWordList(wordlist);
|
8132
7917
|
assertEntropy(entropyBytes);
|
8133
7918
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -8196,14 +7981,14 @@ var Mnemonic = class {
|
|
8196
7981
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
8197
7982
|
*/
|
8198
7983
|
static masterKeysFromSeed(seed) {
|
8199
|
-
const seedArray = (0,
|
7984
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
8200
7985
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
8201
7986
|
throw new import_errors19.FuelError(
|
8202
7987
|
import_errors19.ErrorCode.INVALID_SEED,
|
8203
7988
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
8204
7989
|
);
|
8205
7990
|
}
|
8206
|
-
return (0,
|
7991
|
+
return (0, import_utils33.arrayify)((0, import_ethers3.computeHmac)("sha512", MasterSecret, seedArray));
|
8207
7992
|
}
|
8208
7993
|
/**
|
8209
7994
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -8214,22 +7999,22 @@ var Mnemonic = class {
|
|
8214
7999
|
*/
|
8215
8000
|
static seedToExtendedKey(seed, testnet = false) {
|
8216
8001
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
8217
|
-
const prefix = (0,
|
8002
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8218
8003
|
const depth = "0x00";
|
8219
8004
|
const fingerprint = "0x00000000";
|
8220
8005
|
const index = "0x00000000";
|
8221
8006
|
const chainCode = masterKey.slice(32);
|
8222
8007
|
const privateKey = masterKey.slice(0, 32);
|
8223
|
-
const extendedKey = (0,
|
8008
|
+
const extendedKey = (0, import_utils33.concat)([
|
8224
8009
|
prefix,
|
8225
8010
|
depth,
|
8226
8011
|
fingerprint,
|
8227
8012
|
index,
|
8228
8013
|
chainCode,
|
8229
|
-
(0,
|
8014
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
8230
8015
|
]);
|
8231
8016
|
const checksum = (0, import_ethers3.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8232
|
-
return (0, import_ethers3.encodeBase58)((0,
|
8017
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
8233
8018
|
}
|
8234
8019
|
/**
|
8235
8020
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8244,7 +8029,7 @@ var Mnemonic = class {
|
|
8244
8029
|
* @returns A randomly generated mnemonic
|
8245
8030
|
*/
|
8246
8031
|
static generate(size = 32, extraEntropy = "") {
|
8247
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
8032
|
+
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
8033
|
return Mnemonic.entropyToMnemonic(entropy);
|
8249
8034
|
}
|
8250
8035
|
};
|
@@ -8252,12 +8037,12 @@ var mnemonic_default = Mnemonic;
|
|
8252
8037
|
|
8253
8038
|
// src/hdwallet/hdwallet.ts
|
8254
8039
|
var HARDENED_INDEX = 2147483648;
|
8255
|
-
var MainnetPRV2 = (0,
|
8256
|
-
var MainnetPUB = (0,
|
8257
|
-
var TestnetPRV2 = (0,
|
8258
|
-
var TestnetPUB = (0,
|
8040
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
8041
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
8042
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
8043
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
8259
8044
|
function base58check(data) {
|
8260
|
-
return (0, import_ethers4.encodeBase58)((0,
|
8045
|
+
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
8046
|
}
|
8262
8047
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8263
8048
|
if (isPublic) {
|
@@ -8266,11 +8051,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8266
8051
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8267
8052
|
}
|
8268
8053
|
function isPublicExtendedKey(extendedKey) {
|
8269
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
8054
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
8270
8055
|
}
|
8271
8056
|
function isValidExtendedKey(extendedKey) {
|
8272
8057
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8273
|
-
(0,
|
8058
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
8274
8059
|
);
|
8275
8060
|
}
|
8276
8061
|
function parsePath(path, depth = 0) {
|
@@ -8288,8 +8073,8 @@ function parsePath(path, depth = 0) {
|
|
8288
8073
|
var HDWallet = class {
|
8289
8074
|
depth = 0;
|
8290
8075
|
index = 0;
|
8291
|
-
fingerprint = (0,
|
8292
|
-
parentFingerprint = (0,
|
8076
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8077
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
8293
8078
|
privateKey;
|
8294
8079
|
publicKey;
|
8295
8080
|
chainCode;
|
@@ -8301,8 +8086,8 @@ var HDWallet = class {
|
|
8301
8086
|
constructor(config) {
|
8302
8087
|
if (config.privateKey) {
|
8303
8088
|
const signer = new Signer(config.privateKey);
|
8304
|
-
this.publicKey = (0,
|
8305
|
-
this.privateKey = (0,
|
8089
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
8090
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
8306
8091
|
} else {
|
8307
8092
|
if (!config.publicKey) {
|
8308
8093
|
throw new import_errors20.FuelError(
|
@@ -8310,7 +8095,7 @@ var HDWallet = class {
|
|
8310
8095
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8311
8096
|
);
|
8312
8097
|
}
|
8313
|
-
this.publicKey = (0,
|
8098
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
8314
8099
|
}
|
8315
8100
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8316
8101
|
this.fingerprint = (0, import_ethers4.dataSlice)((0, import_ethers4.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -8329,9 +8114,9 @@ var HDWallet = class {
|
|
8329
8114
|
* @returns A new instance of HDWallet on the derived index
|
8330
8115
|
*/
|
8331
8116
|
deriveIndex(index) {
|
8332
|
-
const privateKey = this.privateKey && (0,
|
8333
|
-
const publicKey = (0,
|
8334
|
-
const chainCode = (0,
|
8117
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
8118
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
8119
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
8335
8120
|
const data = new Uint8Array(37);
|
8336
8121
|
if (index & HARDENED_INDEX) {
|
8337
8122
|
if (!privateKey) {
|
@@ -8342,15 +8127,15 @@ var HDWallet = class {
|
|
8342
8127
|
}
|
8343
8128
|
data.set(privateKey, 1);
|
8344
8129
|
} else {
|
8345
|
-
data.set((0,
|
8130
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
8346
8131
|
}
|
8347
|
-
data.set((0,
|
8348
|
-
const bytes = (0,
|
8132
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
8133
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers4.computeHmac)("sha512", chainCode, data));
|
8349
8134
|
const IL = bytes.slice(0, 32);
|
8350
8135
|
const IR = bytes.slice(32);
|
8351
8136
|
if (privateKey) {
|
8352
8137
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8353
|
-
const ki = (0,
|
8138
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8354
8139
|
return new HDWallet({
|
8355
8140
|
privateKey: ki,
|
8356
8141
|
chainCode: IR,
|
@@ -8359,7 +8144,7 @@ var HDWallet = class {
|
|
8359
8144
|
parentFingerprint: this.fingerprint
|
8360
8145
|
});
|
8361
8146
|
}
|
8362
|
-
const signer = new Signer((0,
|
8147
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
8363
8148
|
const Ki = signer.addPoint(publicKey);
|
8364
8149
|
return new HDWallet({
|
8365
8150
|
publicKey: Ki,
|
@@ -8394,12 +8179,12 @@ var HDWallet = class {
|
|
8394
8179
|
);
|
8395
8180
|
}
|
8396
8181
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8397
|
-
const depth = (0,
|
8182
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
8398
8183
|
const parentFingerprint = this.parentFingerprint;
|
8399
|
-
const index = (0,
|
8184
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
8400
8185
|
const chainCode = this.chainCode;
|
8401
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8402
|
-
const extendedKey = (0,
|
8186
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8187
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8403
8188
|
return base58check(extendedKey);
|
8404
8189
|
}
|
8405
8190
|
/**
|
@@ -8411,13 +8196,13 @@ var HDWallet = class {
|
|
8411
8196
|
static fromSeed(seed) {
|
8412
8197
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8413
8198
|
return new HDWallet({
|
8414
|
-
chainCode: (0,
|
8415
|
-
privateKey: (0,
|
8199
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
8200
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
8416
8201
|
});
|
8417
8202
|
}
|
8418
8203
|
static fromExtendedKey(extendedKey) {
|
8419
8204
|
const decoded = (0, import_ethers4.toBeHex)((0, import_ethers4.decodeBase58)(extendedKey));
|
8420
|
-
const bytes = (0,
|
8205
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
8421
8206
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8422
8207
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8423
8208
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8426,9 +8211,9 @@ var HDWallet = class {
|
|
8426
8211
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8427
8212
|
}
|
8428
8213
|
const depth = bytes[4];
|
8429
|
-
const parentFingerprint = (0,
|
8430
|
-
const index = parseInt((0,
|
8431
|
-
const chainCode = (0,
|
8214
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
8215
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8216
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
8432
8217
|
const key = bytes.slice(45, 78);
|
8433
8218
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8434
8219
|
throw new import_errors20.FuelError(
|
@@ -9033,26 +8818,25 @@ var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
|
9033
8818
|
var import_address10 = require("@fuel-ts/address");
|
9034
8819
|
var import_configs13 = require("@fuel-ts/address/configs");
|
9035
8820
|
var import_errors25 = require("@fuel-ts/errors");
|
9036
|
-
var
|
9037
|
-
var
|
8821
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
8822
|
+
var import_utils37 = require("@fuel-ts/utils");
|
9038
8823
|
|
9039
8824
|
// src/predicate/utils/getPredicateRoot.ts
|
9040
8825
|
var import_hasher7 = require("@fuel-ts/hasher");
|
9041
8826
|
var import_merkle = require("@fuel-ts/merkle");
|
9042
|
-
var
|
8827
|
+
var import_utils36 = require("@fuel-ts/utils");
|
9043
8828
|
var getPredicateRoot = (bytecode) => {
|
9044
8829
|
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,
|
8830
|
+
const bytes = (0, import_utils36.arrayify)(bytecode);
|
8831
|
+
const chunks = (0, import_utils36.chunkAndPadBytes)(bytes, chunkSize);
|
8832
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils36.hexlify)(c)));
|
8833
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils36.concat)(["0x4655454C", codeRoot]));
|
9049
8834
|
return predicateRoot;
|
9050
8835
|
};
|
9051
8836
|
|
9052
8837
|
// src/predicate/predicate.ts
|
9053
8838
|
var Predicate = class extends Account {
|
9054
8839
|
bytes;
|
9055
|
-
predicateDataBytes = Uint8Array.from([]);
|
9056
8840
|
predicateData = [];
|
9057
8841
|
interface;
|
9058
8842
|
/**
|
@@ -9082,7 +8866,6 @@ var Predicate = class extends Account {
|
|
9082
8866
|
this.interface = predicateInterface;
|
9083
8867
|
if (inputData !== void 0 && inputData.length > 0) {
|
9084
8868
|
this.predicateData = inputData;
|
9085
|
-
this.predicateDataBytes = this.getPredicateData(0);
|
9086
8869
|
}
|
9087
8870
|
}
|
9088
8871
|
/**
|
@@ -9095,9 +8878,9 @@ var Predicate = class extends Account {
|
|
9095
8878
|
const request = transactionRequestify(transactionRequestLike);
|
9096
8879
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
9097
8880
|
request.inputs?.forEach((input) => {
|
9098
|
-
if (input.type ===
|
9099
|
-
input.predicate =
|
9100
|
-
input.predicateData =
|
8881
|
+
if (input.type === import_transactions20.InputType.Coin && (0, import_utils37.hexlify)(input.owner) === this.address.toB256()) {
|
8882
|
+
input.predicate = this.bytes;
|
8883
|
+
input.predicateData = this.getPredicateData(policies.length);
|
9101
8884
|
}
|
9102
8885
|
});
|
9103
8886
|
return request;
|
@@ -9112,7 +8895,8 @@ var Predicate = class extends Account {
|
|
9112
8895
|
* @returns A promise that resolves to the prepared transaction request.
|
9113
8896
|
*/
|
9114
8897
|
async createTransfer(destination, amount, assetId = import_configs13.BaseAssetId, txParams = {}) {
|
9115
|
-
|
8898
|
+
const request = await super.createTransfer(destination, amount, assetId, txParams);
|
8899
|
+
return this.populateTransactionPredicateData(request);
|
9116
8900
|
}
|
9117
8901
|
/**
|
9118
8902
|
* Sends a transaction with the populated predicate data.
|
@@ -9120,9 +8904,9 @@ var Predicate = class extends Account {
|
|
9120
8904
|
* @param transactionRequestLike - The transaction request-like object.
|
9121
8905
|
* @returns A promise that resolves to the transaction response.
|
9122
8906
|
*/
|
9123
|
-
sendTransaction(transactionRequestLike) {
|
9124
|
-
const transactionRequest =
|
9125
|
-
return super.sendTransaction(transactionRequest,
|
8907
|
+
sendTransaction(transactionRequestLike, options) {
|
8908
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8909
|
+
return super.sendTransaction(transactionRequest, options);
|
9126
8910
|
}
|
9127
8911
|
/**
|
9128
8912
|
* Simulates a transaction with the populated predicate data.
|
@@ -9131,15 +8915,15 @@ var Predicate = class extends Account {
|
|
9131
8915
|
* @returns A promise that resolves to the call result.
|
9132
8916
|
*/
|
9133
8917
|
simulateTransaction(transactionRequestLike) {
|
9134
|
-
const transactionRequest =
|
9135
|
-
return super.simulateTransaction(transactionRequest
|
8918
|
+
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8919
|
+
return super.simulateTransaction(transactionRequest);
|
9136
8920
|
}
|
9137
8921
|
getPredicateData(policiesLength) {
|
9138
8922
|
if (!this.predicateData.length) {
|
9139
8923
|
return new Uint8Array();
|
9140
8924
|
}
|
9141
8925
|
const mainFn = this.interface?.functions.main;
|
9142
|
-
const paddedCode = new
|
8926
|
+
const paddedCode = new import_transactions20.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
9143
8927
|
const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
|
9144
8928
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
9145
8929
|
});
|
@@ -9155,7 +8939,7 @@ var Predicate = class extends Account {
|
|
9155
8939
|
* @returns An object containing the new predicate bytes and interface.
|
9156
8940
|
*/
|
9157
8941
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
9158
|
-
let predicateBytes = (0,
|
8942
|
+
let predicateBytes = (0, import_utils37.arrayify)(bytes);
|
9159
8943
|
let abiInterface;
|
9160
8944
|
if (jsonAbi) {
|
9161
8945
|
abiInterface = new import_abi_coder5.Interface(jsonAbi);
|
@@ -9178,26 +8962,6 @@ var Predicate = class extends Account {
|
|
9178
8962
|
predicateInterface: abiInterface
|
9179
8963
|
};
|
9180
8964
|
}
|
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
8965
|
/**
|
9202
8966
|
* Sets the configurable constants for the predicate.
|
9203
8967
|
*
|
@@ -9947,7 +9711,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9947
9711
|
WalletLocked,
|
9948
9712
|
WalletManager,
|
9949
9713
|
WalletUnlocked,
|
9950
|
-
|
9714
|
+
addAmountToAsset,
|
9951
9715
|
addOperation,
|
9952
9716
|
assemblePanicError,
|
9953
9717
|
assembleReceiptByType,
|
@@ -9956,10 +9720,9 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9956
9720
|
assets,
|
9957
9721
|
buildBlockExplorerUrl,
|
9958
9722
|
cacheFor,
|
9959
|
-
cacheTxInputsFromOwner,
|
9960
|
-
calculateGasFee,
|
9961
9723
|
calculateMetadataGasForTxCreate,
|
9962
9724
|
calculateMetadataGasForTxScript,
|
9725
|
+
calculatePriceWithFactor,
|
9963
9726
|
calculateTransactionFee,
|
9964
9727
|
coinQuantityfy,
|
9965
9728
|
deferPromise,
|