@fuel-ts/account 0.0.0-rc-2021-20240411141803 → 0.0.0-rc-1976-20240411153008
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 +625 -876
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +619 -856
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +462 -698
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -10
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +328 -894
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/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 +34 -45
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +29 -9
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1128 -1593
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +618 -834
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +476 -692
- 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/test-utils.js
CHANGED
@@ -58,42 +58,39 @@ module.exports = __toCommonJS(test_utils_exports);
|
|
58
58
|
|
59
59
|
// src/wallet/base-wallet-unlocked.ts
|
60
60
|
var import_hasher3 = require("@fuel-ts/hasher");
|
61
|
-
var
|
61
|
+
var import_utils31 = require("@fuel-ts/utils");
|
62
62
|
|
63
63
|
// src/account.ts
|
64
64
|
var import_address4 = require("@fuel-ts/address");
|
65
|
-
var import_configs12 = require("@fuel-ts/address/configs");
|
66
65
|
var import_errors16 = require("@fuel-ts/errors");
|
67
66
|
var import_interfaces = require("@fuel-ts/interfaces");
|
68
|
-
var
|
69
|
-
var
|
70
|
-
var import_ramda4 = require("ramda");
|
67
|
+
var import_math18 = require("@fuel-ts/math");
|
68
|
+
var import_utils28 = require("@fuel-ts/utils");
|
71
69
|
|
72
70
|
// src/providers/coin-quantity.ts
|
73
|
-
var import_configs = require("@fuel-ts/address/configs");
|
74
71
|
var import_math = require("@fuel-ts/math");
|
75
72
|
var import_utils = require("@fuel-ts/utils");
|
76
73
|
var coinQuantityfy = (coinQuantityLike) => {
|
77
74
|
let assetId;
|
78
75
|
let amount;
|
79
|
-
let
|
76
|
+
let max2;
|
80
77
|
if (Array.isArray(coinQuantityLike)) {
|
81
78
|
amount = coinQuantityLike[0];
|
82
|
-
assetId = coinQuantityLike[1]
|
83
|
-
|
79
|
+
assetId = coinQuantityLike[1];
|
80
|
+
max2 = coinQuantityLike[2];
|
84
81
|
} else {
|
85
82
|
amount = coinQuantityLike.amount;
|
86
|
-
assetId = coinQuantityLike.assetId
|
87
|
-
|
83
|
+
assetId = coinQuantityLike.assetId;
|
84
|
+
max2 = coinQuantityLike.max ?? void 0;
|
88
85
|
}
|
89
86
|
const bnAmount = (0, import_math.bn)(amount);
|
90
87
|
return {
|
91
88
|
assetId: (0, import_utils.hexlify)(assetId),
|
92
89
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
93
|
-
max:
|
90
|
+
max: max2 ? (0, import_math.bn)(max2) : void 0
|
94
91
|
};
|
95
92
|
};
|
96
|
-
var
|
93
|
+
var addAmountToAsset = (params) => {
|
97
94
|
const { amount, assetId } = params;
|
98
95
|
const coinQuantities = [...params.coinQuantities];
|
99
96
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -108,12 +105,12 @@ var addAmountToCoinQuantities = (params) => {
|
|
108
105
|
// src/providers/provider.ts
|
109
106
|
var import_address3 = require("@fuel-ts/address");
|
110
107
|
var import_errors14 = require("@fuel-ts/errors");
|
111
|
-
var
|
112
|
-
var
|
113
|
-
var
|
108
|
+
var import_math15 = require("@fuel-ts/math");
|
109
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
110
|
+
var import_utils23 = require("@fuel-ts/utils");
|
114
111
|
var import_versions = require("@fuel-ts/versions");
|
115
|
-
var
|
116
|
-
var
|
112
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
113
|
+
var import_ethers = require("ethers");
|
117
114
|
var import_graphql_request = require("graphql-request");
|
118
115
|
var import_ramda3 = require("ramda");
|
119
116
|
|
@@ -121,10 +118,14 @@ var import_ramda3 = require("ramda");
|
|
121
118
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
122
119
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
123
120
|
fragment receiptFragment on Receipt {
|
124
|
-
|
121
|
+
contract {
|
122
|
+
id
|
123
|
+
}
|
125
124
|
pc
|
126
125
|
is
|
127
|
-
to
|
126
|
+
to {
|
127
|
+
id
|
128
|
+
}
|
128
129
|
toAddress
|
129
130
|
amount
|
130
131
|
assetId
|
@@ -162,16 +163,10 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
162
163
|
id
|
163
164
|
}
|
164
165
|
time
|
165
|
-
receipts {
|
166
|
-
...receiptFragment
|
167
|
-
}
|
168
166
|
programState {
|
169
167
|
returnType
|
170
168
|
data
|
171
169
|
}
|
172
|
-
receipts {
|
173
|
-
...receiptFragment
|
174
|
-
}
|
175
170
|
}
|
176
171
|
... on FailureStatus {
|
177
172
|
block {
|
@@ -179,24 +174,26 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
179
174
|
}
|
180
175
|
time
|
181
176
|
reason
|
182
|
-
receipts {
|
183
|
-
...receiptFragment
|
184
|
-
}
|
185
177
|
}
|
186
178
|
... on SqueezedOutStatus {
|
187
179
|
reason
|
188
180
|
}
|
189
181
|
}
|
190
|
-
|
182
|
+
`;
|
191
183
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
192
184
|
fragment transactionFragment on Transaction {
|
193
185
|
id
|
194
186
|
rawPayload
|
187
|
+
gasPrice
|
188
|
+
receipts {
|
189
|
+
...receiptFragment
|
190
|
+
}
|
195
191
|
status {
|
196
192
|
...transactionStatusFragment
|
197
193
|
}
|
198
194
|
}
|
199
|
-
${
|
195
|
+
${ReceiptFragmentFragmentDoc}
|
196
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
200
197
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
201
198
|
fragment inputEstimatePredicatesFragment on Input {
|
202
199
|
... on InputCoin {
|
@@ -214,46 +211,6 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
214
211
|
}
|
215
212
|
}
|
216
213
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
217
|
-
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
218
|
-
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
219
|
-
reason
|
220
|
-
programState {
|
221
|
-
returnType
|
222
|
-
data
|
223
|
-
}
|
224
|
-
}
|
225
|
-
`;
|
226
|
-
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
227
|
-
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
228
|
-
programState {
|
229
|
-
returnType
|
230
|
-
data
|
231
|
-
}
|
232
|
-
}
|
233
|
-
`;
|
234
|
-
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
235
|
-
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
236
|
-
... on DryRunFailureStatus {
|
237
|
-
...dryRunFailureStatusFragment
|
238
|
-
}
|
239
|
-
... on DryRunSuccessStatus {
|
240
|
-
...dryRunSuccessStatusFragment
|
241
|
-
}
|
242
|
-
}
|
243
|
-
${DryRunFailureStatusFragmentFragmentDoc}
|
244
|
-
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
245
|
-
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
246
|
-
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
247
|
-
id
|
248
|
-
status {
|
249
|
-
...dryRunTransactionStatusFragment
|
250
|
-
}
|
251
|
-
receipts {
|
252
|
-
...receiptFragment
|
253
|
-
}
|
254
|
-
}
|
255
|
-
${DryRunTransactionStatusFragmentFragmentDoc}
|
256
|
-
${ReceiptFragmentFragmentDoc}`;
|
257
214
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
258
215
|
fragment coinFragment on Coin {
|
259
216
|
__typename
|
@@ -261,6 +218,7 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
261
218
|
owner
|
262
219
|
amount
|
263
220
|
assetId
|
221
|
+
maturity
|
264
222
|
blockCreated
|
265
223
|
txCreatedIdx
|
266
224
|
}
|
@@ -305,6 +263,7 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
305
263
|
prevRoot
|
306
264
|
time
|
307
265
|
applicationHash
|
266
|
+
messageReceiptRoot
|
308
267
|
messageReceiptCount
|
309
268
|
}
|
310
269
|
commitBlockHeader {
|
@@ -316,6 +275,7 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
316
275
|
prevRoot
|
317
276
|
time
|
318
277
|
applicationHash
|
278
|
+
messageReceiptRoot
|
319
279
|
messageReceiptCount
|
320
280
|
}
|
321
281
|
sender
|
@@ -335,8 +295,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
335
295
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
336
296
|
fragment blockFragment on Block {
|
337
297
|
id
|
338
|
-
height
|
339
298
|
header {
|
299
|
+
height
|
340
300
|
time
|
341
301
|
}
|
342
302
|
transactions {
|
@@ -394,11 +354,6 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
394
354
|
`;
|
395
355
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
396
356
|
fragment GasCostsFragment on GasCosts {
|
397
|
-
version {
|
398
|
-
... on Version {
|
399
|
-
value
|
400
|
-
}
|
401
|
-
}
|
402
357
|
add
|
403
358
|
addi
|
404
359
|
aloc
|
@@ -411,6 +366,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
411
366
|
cb
|
412
367
|
cfei
|
413
368
|
cfsi
|
369
|
+
croo
|
414
370
|
div
|
415
371
|
divi
|
416
372
|
ecr1
|
@@ -493,9 +449,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
493
449
|
ccp {
|
494
450
|
...DependentCostFragment
|
495
451
|
}
|
496
|
-
croo {
|
497
|
-
...DependentCostFragment
|
498
|
-
}
|
499
452
|
csiz {
|
500
453
|
...DependentCostFragment
|
501
454
|
}
|
@@ -555,11 +508,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
555
508
|
${DependentCostFragmentFragmentDoc}`;
|
556
509
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
557
510
|
fragment consensusParametersFragment on ConsensusParameters {
|
558
|
-
version {
|
559
|
-
... on Version {
|
560
|
-
value
|
561
|
-
}
|
562
|
-
}
|
563
511
|
txParams {
|
564
512
|
...TxParametersFragment
|
565
513
|
}
|
@@ -619,9 +567,18 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
619
567
|
fragment nodeInfoFragment on NodeInfo {
|
620
568
|
utxoValidation
|
621
569
|
vmBacktrace
|
570
|
+
minGasPrice
|
622
571
|
maxTx
|
623
572
|
maxDepth
|
624
573
|
nodeVersion
|
574
|
+
peers {
|
575
|
+
id
|
576
|
+
addresses
|
577
|
+
clientVersion
|
578
|
+
blockHeight
|
579
|
+
lastHeartbeatMs
|
580
|
+
appScore
|
581
|
+
}
|
625
582
|
}
|
626
583
|
`;
|
627
584
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -656,9 +613,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
656
613
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
657
614
|
transaction(id: $transactionId) {
|
658
615
|
...transactionFragment
|
616
|
+
receipts {
|
617
|
+
...receiptFragment
|
618
|
+
}
|
659
619
|
}
|
660
620
|
}
|
661
|
-
${TransactionFragmentFragmentDoc}
|
621
|
+
${TransactionFragmentFragmentDoc}
|
622
|
+
${ReceiptFragmentFragmentDoc}`;
|
662
623
|
var GetTransactionsDocument = import_graphql_tag.default`
|
663
624
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
664
625
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -786,20 +747,6 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
786
747
|
}
|
787
748
|
}
|
788
749
|
${BalanceFragmentFragmentDoc}`;
|
789
|
-
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
790
|
-
query getLatestGasPrice {
|
791
|
-
latestGasPrice {
|
792
|
-
gasPrice
|
793
|
-
}
|
794
|
-
}
|
795
|
-
`;
|
796
|
-
var EstimateGasPriceDocument = import_graphql_tag.default`
|
797
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
798
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
799
|
-
gasPrice
|
800
|
-
}
|
801
|
-
}
|
802
|
-
`;
|
803
750
|
var GetBalancesDocument = import_graphql_tag.default`
|
804
751
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
805
752
|
balances(
|
@@ -854,12 +801,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
854
801
|
}
|
855
802
|
`;
|
856
803
|
var DryRunDocument = import_graphql_tag.default`
|
857
|
-
mutation dryRun($
|
858
|
-
dryRun(
|
859
|
-
...
|
804
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
805
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
806
|
+
...receiptFragment
|
860
807
|
}
|
861
808
|
}
|
862
|
-
${
|
809
|
+
${ReceiptFragmentFragmentDoc}`;
|
863
810
|
var SubmitDocument = import_graphql_tag.default`
|
864
811
|
mutation submit($encodedTransaction: HexString!) {
|
865
812
|
submit(tx: $encodedTransaction) {
|
@@ -942,12 +889,6 @@ function getSdk(requester) {
|
|
942
889
|
getBalance(variables, options) {
|
943
890
|
return requester(GetBalanceDocument, variables, options);
|
944
891
|
},
|
945
|
-
getLatestGasPrice(variables, options) {
|
946
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
947
|
-
},
|
948
|
-
estimateGasPrice(variables, options) {
|
949
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
950
|
-
},
|
951
892
|
getBalances(variables, options) {
|
952
893
|
return requester(GetBalancesDocument, variables, options);
|
953
894
|
},
|
@@ -1017,14 +958,11 @@ var _FuelGraphqlSubscriber = class {
|
|
1017
958
|
let data;
|
1018
959
|
let errors;
|
1019
960
|
try {
|
1020
|
-
|
1021
|
-
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
961
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
1022
962
|
} catch (e) {
|
1023
963
|
throw new import_errors.FuelError(
|
1024
964
|
import_errors.ErrorCode.STREAM_PARSING_ERROR,
|
1025
|
-
`Error while parsing stream data response: ${text}
|
1026
|
-
|
1027
|
-
Thrown error: ${e}`
|
965
|
+
`Error while parsing stream data response: ${text}`
|
1028
966
|
);
|
1029
967
|
}
|
1030
968
|
if (Array.isArray(errors)) {
|
@@ -1111,7 +1049,7 @@ var MemoryCache = class {
|
|
1111
1049
|
};
|
1112
1050
|
|
1113
1051
|
// src/providers/transaction-request/input.ts
|
1114
|
-
var
|
1052
|
+
var import_configs = require("@fuel-ts/address/configs");
|
1115
1053
|
var import_errors3 = require("@fuel-ts/errors");
|
1116
1054
|
var import_math2 = require("@fuel-ts/math");
|
1117
1055
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1125,7 +1063,7 @@ var inputify = (value) => {
|
|
1125
1063
|
return {
|
1126
1064
|
type: import_transactions.InputType.Coin,
|
1127
1065
|
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
|
1128
|
-
outputIndex: (0,
|
1066
|
+
outputIndex: (0, import_utils3.arrayify)(value.id)[32],
|
1129
1067
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1130
1068
|
amount: (0, import_math2.bn)(value.amount),
|
1131
1069
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1134,9 +1072,10 @@ var inputify = (value) => {
|
|
1134
1072
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1135
1073
|
},
|
1136
1074
|
witnessIndex: value.witnessIndex,
|
1075
|
+
maturity: value.maturity ?? 0,
|
1137
1076
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1138
|
-
predicateLength:
|
1139
|
-
predicateDataLength:
|
1077
|
+
predicateLength: predicate.length,
|
1078
|
+
predicateDataLength: predicateData.length,
|
1140
1079
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1141
1080
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1142
1081
|
};
|
@@ -1144,10 +1083,10 @@ var inputify = (value) => {
|
|
1144
1083
|
case import_transactions.InputType.Contract: {
|
1145
1084
|
return {
|
1146
1085
|
type: import_transactions.InputType.Contract,
|
1147
|
-
txID:
|
1086
|
+
txID: import_configs.ZeroBytes32,
|
1148
1087
|
outputIndex: 0,
|
1149
|
-
balanceRoot:
|
1150
|
-
stateRoot:
|
1088
|
+
balanceRoot: import_configs.ZeroBytes32,
|
1089
|
+
stateRoot: import_configs.ZeroBytes32,
|
1151
1090
|
txPointer: {
|
1152
1091
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1153
1092
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1167,8 +1106,8 @@ var inputify = (value) => {
|
|
1167
1106
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1168
1107
|
witnessIndex: value.witnessIndex,
|
1169
1108
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1170
|
-
predicateLength:
|
1171
|
-
predicateDataLength:
|
1109
|
+
predicateLength: predicate.length,
|
1110
|
+
predicateDataLength: predicateData.length,
|
1172
1111
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1173
1112
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1174
1113
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1185,7 +1124,7 @@ var inputify = (value) => {
|
|
1185
1124
|
};
|
1186
1125
|
|
1187
1126
|
// src/providers/transaction-request/output.ts
|
1188
|
-
var
|
1127
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1189
1128
|
var import_errors4 = require("@fuel-ts/errors");
|
1190
1129
|
var import_math3 = require("@fuel-ts/math");
|
1191
1130
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1205,8 +1144,8 @@ var outputify = (value) => {
|
|
1205
1144
|
return {
|
1206
1145
|
type: import_transactions2.OutputType.Contract,
|
1207
1146
|
inputIndex: value.inputIndex,
|
1208
|
-
balanceRoot:
|
1209
|
-
stateRoot:
|
1147
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1148
|
+
stateRoot: import_configs2.ZeroBytes32
|
1210
1149
|
};
|
1211
1150
|
}
|
1212
1151
|
case import_transactions2.OutputType.Change: {
|
@@ -1220,9 +1159,9 @@ var outputify = (value) => {
|
|
1220
1159
|
case import_transactions2.OutputType.Variable: {
|
1221
1160
|
return {
|
1222
1161
|
type: import_transactions2.OutputType.Variable,
|
1223
|
-
to:
|
1162
|
+
to: import_configs2.ZeroBytes32,
|
1224
1163
|
amount: (0, import_math3.bn)(0),
|
1225
|
-
assetId:
|
1164
|
+
assetId: import_configs2.ZeroBytes32
|
1226
1165
|
};
|
1227
1166
|
}
|
1228
1167
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1243,23 +1182,22 @@ var outputify = (value) => {
|
|
1243
1182
|
|
1244
1183
|
// src/providers/transaction-request/transaction-request.ts
|
1245
1184
|
var import_address = require("@fuel-ts/address");
|
1246
|
-
var
|
1185
|
+
var import_configs6 = require("@fuel-ts/address/configs");
|
1247
1186
|
var import_math7 = require("@fuel-ts/math");
|
1248
1187
|
var import_transactions6 = require("@fuel-ts/transactions");
|
1249
1188
|
var import_utils9 = require("@fuel-ts/utils");
|
1250
|
-
var import_ethers = require("ethers");
|
1251
1189
|
|
1252
1190
|
// src/providers/resource.ts
|
1253
1191
|
var isCoin = (resource) => "id" in resource;
|
1254
1192
|
|
1255
1193
|
// src/providers/utils/receipts.ts
|
1256
|
-
var
|
1194
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1257
1195
|
var import_errors5 = require("@fuel-ts/errors");
|
1258
1196
|
var import_math4 = require("@fuel-ts/math");
|
1259
1197
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1260
|
-
var
|
1198
|
+
var import_configs4 = require("@fuel-ts/transactions/configs");
|
1261
1199
|
var import_utils5 = require("@fuel-ts/utils");
|
1262
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1200
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1263
1201
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1264
1202
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1265
1203
|
(memo, receipt) => {
|
@@ -1276,15 +1214,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1276
1214
|
missingOutputContractIds: []
|
1277
1215
|
}
|
1278
1216
|
);
|
1279
|
-
var hexOrZero = (hex) => hex ||
|
1217
|
+
var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
|
1280
1218
|
function assembleReceiptByType(receipt) {
|
1281
1219
|
const { receiptType } = receipt;
|
1282
1220
|
switch (receiptType) {
|
1283
1221
|
case "CALL" /* Call */: {
|
1284
1222
|
const callReceipt = {
|
1285
1223
|
type: import_transactions3.ReceiptType.Call,
|
1286
|
-
from: hexOrZero(receipt.id
|
1287
|
-
to: hexOrZero(receipt?.to),
|
1224
|
+
from: hexOrZero(receipt.contract?.id),
|
1225
|
+
to: hexOrZero(receipt?.to?.id),
|
1288
1226
|
amount: (0, import_math4.bn)(receipt.amount),
|
1289
1227
|
assetId: hexOrZero(receipt.assetId),
|
1290
1228
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1298,7 +1236,7 @@ function assembleReceiptByType(receipt) {
|
|
1298
1236
|
case "RETURN" /* Return */: {
|
1299
1237
|
const returnReceipt = {
|
1300
1238
|
type: import_transactions3.ReceiptType.Return,
|
1301
|
-
id: hexOrZero(receipt.id
|
1239
|
+
id: hexOrZero(receipt.contract?.id),
|
1302
1240
|
val: (0, import_math4.bn)(receipt.val),
|
1303
1241
|
pc: (0, import_math4.bn)(receipt.pc),
|
1304
1242
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1308,7 +1246,7 @@ function assembleReceiptByType(receipt) {
|
|
1308
1246
|
case "RETURN_DATA" /* ReturnData */: {
|
1309
1247
|
const returnDataReceipt = {
|
1310
1248
|
type: import_transactions3.ReceiptType.ReturnData,
|
1311
|
-
id: hexOrZero(receipt.id
|
1249
|
+
id: hexOrZero(receipt.contract?.id),
|
1312
1250
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1313
1251
|
len: (0, import_math4.bn)(receipt.len),
|
1314
1252
|
digest: hexOrZero(receipt.digest),
|
@@ -1320,7 +1258,7 @@ function assembleReceiptByType(receipt) {
|
|
1320
1258
|
case "PANIC" /* Panic */: {
|
1321
1259
|
const panicReceipt = {
|
1322
1260
|
type: import_transactions3.ReceiptType.Panic,
|
1323
|
-
id: hexOrZero(receipt.id),
|
1261
|
+
id: hexOrZero(receipt.contract?.id),
|
1324
1262
|
reason: (0, import_math4.bn)(receipt.reason),
|
1325
1263
|
pc: (0, import_math4.bn)(receipt.pc),
|
1326
1264
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1331,7 +1269,7 @@ function assembleReceiptByType(receipt) {
|
|
1331
1269
|
case "REVERT" /* Revert */: {
|
1332
1270
|
const revertReceipt = {
|
1333
1271
|
type: import_transactions3.ReceiptType.Revert,
|
1334
|
-
id: hexOrZero(receipt.id
|
1272
|
+
id: hexOrZero(receipt.contract?.id),
|
1335
1273
|
val: (0, import_math4.bn)(receipt.ra),
|
1336
1274
|
pc: (0, import_math4.bn)(receipt.pc),
|
1337
1275
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1341,7 +1279,7 @@ function assembleReceiptByType(receipt) {
|
|
1341
1279
|
case "LOG" /* Log */: {
|
1342
1280
|
const logReceipt = {
|
1343
1281
|
type: import_transactions3.ReceiptType.Log,
|
1344
|
-
id: hexOrZero(receipt.id
|
1282
|
+
id: hexOrZero(receipt.contract?.id),
|
1345
1283
|
val0: (0, import_math4.bn)(receipt.ra),
|
1346
1284
|
val1: (0, import_math4.bn)(receipt.rb),
|
1347
1285
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1354,7 +1292,7 @@ function assembleReceiptByType(receipt) {
|
|
1354
1292
|
case "LOG_DATA" /* LogData */: {
|
1355
1293
|
const logDataReceipt = {
|
1356
1294
|
type: import_transactions3.ReceiptType.LogData,
|
1357
|
-
id: hexOrZero(receipt.id
|
1295
|
+
id: hexOrZero(receipt.contract?.id),
|
1358
1296
|
val0: (0, import_math4.bn)(receipt.ra),
|
1359
1297
|
val1: (0, import_math4.bn)(receipt.rb),
|
1360
1298
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1368,8 +1306,8 @@ function assembleReceiptByType(receipt) {
|
|
1368
1306
|
case "TRANSFER" /* Transfer */: {
|
1369
1307
|
const transferReceipt = {
|
1370
1308
|
type: import_transactions3.ReceiptType.Transfer,
|
1371
|
-
from: hexOrZero(receipt.id
|
1372
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1309
|
+
from: hexOrZero(receipt.contract?.id),
|
1310
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1373
1311
|
amount: (0, import_math4.bn)(receipt.amount),
|
1374
1312
|
assetId: hexOrZero(receipt.assetId),
|
1375
1313
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1380,8 +1318,8 @@ function assembleReceiptByType(receipt) {
|
|
1380
1318
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1381
1319
|
const transferOutReceipt = {
|
1382
1320
|
type: import_transactions3.ReceiptType.TransferOut,
|
1383
|
-
from: hexOrZero(receipt.id
|
1384
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1321
|
+
from: hexOrZero(receipt.contract?.id),
|
1322
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1385
1323
|
amount: (0, import_math4.bn)(receipt.amount),
|
1386
1324
|
assetId: hexOrZero(receipt.assetId),
|
1387
1325
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1424,7 +1362,7 @@ function assembleReceiptByType(receipt) {
|
|
1424
1362
|
return receiptMessageOut;
|
1425
1363
|
}
|
1426
1364
|
case "MINT" /* Mint */: {
|
1427
|
-
const contractId = hexOrZero(receipt.id
|
1365
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1428
1366
|
const subId = hexOrZero(receipt.subId);
|
1429
1367
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1430
1368
|
const mintReceipt = {
|
@@ -1439,7 +1377,7 @@ function assembleReceiptByType(receipt) {
|
|
1439
1377
|
return mintReceipt;
|
1440
1378
|
}
|
1441
1379
|
case "BURN" /* Burn */: {
|
1442
|
-
const contractId = hexOrZero(receipt.id
|
1380
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1443
1381
|
const subId = hexOrZero(receipt.subId);
|
1444
1382
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1445
1383
|
const burnReceipt = {
|
@@ -1465,6 +1403,7 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1465
1403
|
var import_math5 = require("@fuel-ts/math");
|
1466
1404
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1467
1405
|
var import_utils6 = require("@fuel-ts/utils");
|
1406
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1468
1407
|
var getGasUsedFromReceipts = (receipts) => {
|
1469
1408
|
const scriptResult = receipts.filter(
|
1470
1409
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1485,28 +1424,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1485
1424
|
}
|
1486
1425
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1487
1426
|
const witnessCache = [];
|
1488
|
-
const
|
1489
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1490
|
-
if (isCoinOrMessage) {
|
1491
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1492
|
-
return true;
|
1493
|
-
}
|
1494
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1495
|
-
witnessCache.push(input.witnessIndex);
|
1496
|
-
return true;
|
1497
|
-
}
|
1498
|
-
}
|
1499
|
-
return false;
|
1500
|
-
});
|
1501
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1502
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1427
|
+
const totalGas = inputs.reduce((total, input) => {
|
1503
1428
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1504
1429
|
return total.add(
|
1505
|
-
|
1430
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1506
1431
|
);
|
1507
1432
|
}
|
1508
|
-
|
1509
|
-
|
1433
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1434
|
+
witnessCache.push(input.witnessIndex);
|
1435
|
+
return total.add(gasCosts.ecr1);
|
1436
|
+
}
|
1437
|
+
return total;
|
1438
|
+
}, (0, import_math5.bn)());
|
1510
1439
|
return totalGas;
|
1511
1440
|
}
|
1512
1441
|
function getMinGas(params) {
|
@@ -1518,20 +1447,12 @@ function getMinGas(params) {
|
|
1518
1447
|
return minGas;
|
1519
1448
|
}
|
1520
1449
|
function getMaxGas(params) {
|
1521
|
-
const {
|
1522
|
-
gasPerByte,
|
1523
|
-
witnessesLength,
|
1524
|
-
witnessLimit,
|
1525
|
-
minGas,
|
1526
|
-
gasLimit = (0, import_math5.bn)(0),
|
1527
|
-
maxGasPerTx
|
1528
|
-
} = params;
|
1450
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
|
1529
1451
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1530
1452
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1531
1453
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1532
1454
|
}
|
1533
|
-
|
1534
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1455
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1535
1456
|
}
|
1536
1457
|
function calculateMetadataGasForTxCreate({
|
1537
1458
|
gasCosts,
|
@@ -1553,10 +1474,6 @@ function calculateMetadataGasForTxScript({
|
|
1553
1474
|
}) {
|
1554
1475
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1555
1476
|
}
|
1556
|
-
var calculateGasFee = (params) => {
|
1557
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1558
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1559
|
-
};
|
1560
1477
|
|
1561
1478
|
// src/providers/utils/json.ts
|
1562
1479
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1602,16 +1519,16 @@ function sleep(time) {
|
|
1602
1519
|
var import_errors7 = require("@fuel-ts/errors");
|
1603
1520
|
var import_math6 = require("@fuel-ts/math");
|
1604
1521
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1605
|
-
var
|
1522
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1606
1523
|
var assemblePanicError = (status) => {
|
1607
1524
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1608
1525
|
const reason = status.reason;
|
1609
|
-
if (
|
1526
|
+
if (import_configs5.PANIC_REASONS.includes(status.reason)) {
|
1610
1527
|
errorMessage = `${errorMessage}
|
1611
1528
|
|
1612
1529
|
You can read more about this error at:
|
1613
1530
|
|
1614
|
-
${
|
1531
|
+
${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
|
1615
1532
|
}
|
1616
1533
|
return { errorMessage, reason };
|
1617
1534
|
};
|
@@ -1623,28 +1540,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1623
1540
|
if (revertReceipt) {
|
1624
1541
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1625
1542
|
switch (reasonHex) {
|
1626
|
-
case
|
1543
|
+
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
1627
1544
|
reason = "require";
|
1628
1545
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1629
1546
|
break;
|
1630
1547
|
}
|
1631
|
-
case
|
1548
|
+
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
1632
1549
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1633
1550
|
reason = "assert_eq";
|
1634
1551
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1635
1552
|
break;
|
1636
1553
|
}
|
1637
|
-
case
|
1554
|
+
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
1638
1555
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1639
1556
|
reason = "assert_ne";
|
1640
1557
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1641
1558
|
break;
|
1642
1559
|
}
|
1643
|
-
case
|
1560
|
+
case import_configs5.FAILED_ASSERT_SIGNAL:
|
1644
1561
|
reason = "assert";
|
1645
1562
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1646
1563
|
break;
|
1647
|
-
case
|
1564
|
+
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1648
1565
|
reason = "MissingOutputChange";
|
1649
1566
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1650
1567
|
break;
|
@@ -1693,7 +1610,7 @@ var witnessify = (value) => {
|
|
1693
1610
|
// src/providers/transaction-request/transaction-request.ts
|
1694
1611
|
var BaseTransactionRequest = class {
|
1695
1612
|
/** Gas price for transaction */
|
1696
|
-
|
1613
|
+
gasPrice;
|
1697
1614
|
/** Block until which tx cannot be included */
|
1698
1615
|
maturity;
|
1699
1616
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1706,34 +1623,38 @@ var BaseTransactionRequest = class {
|
|
1706
1623
|
outputs = [];
|
1707
1624
|
/** List of witnesses */
|
1708
1625
|
witnesses = [];
|
1626
|
+
/** Base asset ID - should be fetched from the chain */
|
1627
|
+
baseAssetId;
|
1709
1628
|
/**
|
1710
1629
|
* Constructor for initializing a base transaction request.
|
1711
1630
|
*
|
1712
1631
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1713
1632
|
*/
|
1714
1633
|
constructor({
|
1715
|
-
|
1634
|
+
gasPrice,
|
1716
1635
|
maturity,
|
1717
1636
|
maxFee,
|
1718
1637
|
witnessLimit,
|
1719
1638
|
inputs,
|
1720
1639
|
outputs,
|
1721
|
-
witnesses
|
1722
|
-
|
1723
|
-
|
1640
|
+
witnesses,
|
1641
|
+
baseAssetId
|
1642
|
+
}) {
|
1643
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1724
1644
|
this.maturity = maturity ?? 0;
|
1725
1645
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1726
1646
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1727
1647
|
this.inputs = inputs ?? [];
|
1728
1648
|
this.outputs = outputs ?? [];
|
1729
1649
|
this.witnesses = witnesses ?? [];
|
1650
|
+
this.baseAssetId = baseAssetId;
|
1730
1651
|
}
|
1731
1652
|
static getPolicyMeta(req) {
|
1732
1653
|
let policyTypes = 0;
|
1733
1654
|
const policies = [];
|
1734
|
-
if (req.
|
1735
|
-
policyTypes += import_transactions6.PolicyType.
|
1736
|
-
policies.push({ data: req.
|
1655
|
+
if (req.gasPrice) {
|
1656
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1657
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1737
1658
|
}
|
1738
1659
|
if (req.witnessLimit) {
|
1739
1660
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -1819,7 +1740,7 @@ var BaseTransactionRequest = class {
|
|
1819
1740
|
* @returns The index of the created witness.
|
1820
1741
|
*/
|
1821
1742
|
addEmptyWitness() {
|
1822
|
-
this.addWitness((0, import_utils9.concat)([
|
1743
|
+
this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
1823
1744
|
return this.witnesses.length - 1;
|
1824
1745
|
}
|
1825
1746
|
/**
|
@@ -1920,10 +1841,10 @@ var BaseTransactionRequest = class {
|
|
1920
1841
|
* @param predicate - Predicate bytes.
|
1921
1842
|
* @param predicateData - Predicate data bytes.
|
1922
1843
|
*/
|
1923
|
-
addCoinInput(coin) {
|
1844
|
+
addCoinInput(coin, predicate) {
|
1924
1845
|
const { assetId, owner, amount } = coin;
|
1925
1846
|
let witnessIndex;
|
1926
|
-
if (
|
1847
|
+
if (predicate) {
|
1927
1848
|
witnessIndex = 0;
|
1928
1849
|
} else {
|
1929
1850
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1938,7 +1859,8 @@ var BaseTransactionRequest = class {
|
|
1938
1859
|
amount,
|
1939
1860
|
assetId,
|
1940
1861
|
txPointer: "0x00000000000000000000000000000000",
|
1941
|
-
witnessIndex
|
1862
|
+
witnessIndex,
|
1863
|
+
predicate: predicate?.bytes
|
1942
1864
|
};
|
1943
1865
|
this.pushInput(input);
|
1944
1866
|
this.addChangeOutput(owner, assetId);
|
@@ -1949,13 +1871,11 @@ var BaseTransactionRequest = class {
|
|
1949
1871
|
*
|
1950
1872
|
* @param message - Message resource.
|
1951
1873
|
* @param predicate - Predicate bytes.
|
1952
|
-
* @param predicateData - Predicate data bytes.
|
1953
1874
|
*/
|
1954
|
-
addMessageInput(message) {
|
1875
|
+
addMessageInput(message, predicate) {
|
1955
1876
|
const { recipient, sender, amount } = message;
|
1956
|
-
const assetId = import_configs7.BaseAssetId;
|
1957
1877
|
let witnessIndex;
|
1958
|
-
if (
|
1878
|
+
if (predicate) {
|
1959
1879
|
witnessIndex = 0;
|
1960
1880
|
} else {
|
1961
1881
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1969,10 +1889,11 @@ var BaseTransactionRequest = class {
|
|
1969
1889
|
sender: sender.toB256(),
|
1970
1890
|
recipient: recipient.toB256(),
|
1971
1891
|
amount,
|
1972
|
-
witnessIndex
|
1892
|
+
witnessIndex,
|
1893
|
+
predicate: predicate?.bytes
|
1973
1894
|
};
|
1974
1895
|
this.pushInput(input);
|
1975
|
-
this.addChangeOutput(recipient,
|
1896
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1976
1897
|
}
|
1977
1898
|
/**
|
1978
1899
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2000,6 +1921,32 @@ var BaseTransactionRequest = class {
|
|
2000
1921
|
resources.forEach((resource) => this.addResource(resource));
|
2001
1922
|
return this;
|
2002
1923
|
}
|
1924
|
+
/**
|
1925
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1926
|
+
* outputs from the related assetIds.
|
1927
|
+
*
|
1928
|
+
* @param resources - The resources to add.
|
1929
|
+
* @returns This transaction.
|
1930
|
+
*/
|
1931
|
+
addPredicateResource(resource, predicate) {
|
1932
|
+
if (isCoin(resource)) {
|
1933
|
+
this.addCoinInput(resource, predicate);
|
1934
|
+
} else {
|
1935
|
+
this.addMessageInput(resource, predicate);
|
1936
|
+
}
|
1937
|
+
return this;
|
1938
|
+
}
|
1939
|
+
/**
|
1940
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1941
|
+
* from the related assetIds.
|
1942
|
+
*
|
1943
|
+
* @param resources - The resources to add.
|
1944
|
+
* @returns This transaction.
|
1945
|
+
*/
|
1946
|
+
addPredicateResources(resources, predicate) {
|
1947
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1948
|
+
return this;
|
1949
|
+
}
|
2003
1950
|
/**
|
2004
1951
|
* Adds a coin output to the transaction.
|
2005
1952
|
*
|
@@ -2007,12 +1954,12 @@ var BaseTransactionRequest = class {
|
|
2007
1954
|
* @param amount - Amount of coin.
|
2008
1955
|
* @param assetId - Asset ID of coin.
|
2009
1956
|
*/
|
2010
|
-
addCoinOutput(to, amount, assetId
|
1957
|
+
addCoinOutput(to, amount, assetId) {
|
2011
1958
|
this.pushOutput({
|
2012
1959
|
type: import_transactions6.OutputType.Coin,
|
2013
1960
|
to: (0, import_address.addressify)(to).toB256(),
|
2014
1961
|
amount,
|
2015
|
-
assetId
|
1962
|
+
assetId: assetId ?? this.baseAssetId
|
2016
1963
|
});
|
2017
1964
|
return this;
|
2018
1965
|
}
|
@@ -2039,7 +1986,7 @@ var BaseTransactionRequest = class {
|
|
2039
1986
|
* @param to - Address of the owner.
|
2040
1987
|
* @param assetId - Asset ID of coin.
|
2041
1988
|
*/
|
2042
|
-
addChangeOutput(to, assetId
|
1989
|
+
addChangeOutput(to, assetId) {
|
2043
1990
|
const changeOutput = this.getChangeOutputs().find(
|
2044
1991
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
2045
1992
|
);
|
@@ -2047,7 +1994,7 @@ var BaseTransactionRequest = class {
|
|
2047
1994
|
this.pushOutput({
|
2048
1995
|
type: import_transactions6.OutputType.Change,
|
2049
1996
|
to: (0, import_address.addressify)(to).toB256(),
|
2050
|
-
assetId
|
1997
|
+
assetId: assetId ?? this.baseAssetId
|
2051
1998
|
});
|
2052
1999
|
}
|
2053
2000
|
}
|
@@ -2079,7 +2026,7 @@ var BaseTransactionRequest = class {
|
|
2079
2026
|
}
|
2080
2027
|
calculateMaxGas(chainInfo, minGas) {
|
2081
2028
|
const { consensusParameters } = chainInfo;
|
2082
|
-
const { gasPerByte
|
2029
|
+
const { gasPerByte } = consensusParameters;
|
2083
2030
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2084
2031
|
(acc, wit) => acc + wit.dataLength,
|
2085
2032
|
0
|
@@ -2088,8 +2035,7 @@ var BaseTransactionRequest = class {
|
|
2088
2035
|
gasPerByte,
|
2089
2036
|
minGas,
|
2090
2037
|
witnessesLength,
|
2091
|
-
witnessLimit: this.witnessLimit
|
2092
|
-
maxGasPerTx
|
2038
|
+
witnessLimit: this.witnessLimit
|
2093
2039
|
});
|
2094
2040
|
}
|
2095
2041
|
/**
|
@@ -2099,6 +2045,12 @@ var BaseTransactionRequest = class {
|
|
2099
2045
|
* @param quantities - CoinQuantity Array.
|
2100
2046
|
*/
|
2101
2047
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2048
|
+
let idCounter = 0;
|
2049
|
+
const generateId = () => {
|
2050
|
+
const counterString = String(idCounter++);
|
2051
|
+
const id = import_configs6.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2052
|
+
return id;
|
2053
|
+
};
|
2102
2054
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2103
2055
|
if ("assetId" in input) {
|
2104
2056
|
return input.assetId === assetId;
|
@@ -2107,27 +2059,24 @@ var BaseTransactionRequest = class {
|
|
2107
2059
|
});
|
2108
2060
|
const updateAssetInput = (assetId, quantity) => {
|
2109
2061
|
const assetInput = findAssetInput(assetId);
|
2110
|
-
let usedQuantity = quantity;
|
2111
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2112
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2113
|
-
}
|
2114
2062
|
if (assetInput && "assetId" in assetInput) {
|
2115
|
-
assetInput.id = (
|
2116
|
-
assetInput.amount =
|
2063
|
+
assetInput.id = generateId();
|
2064
|
+
assetInput.amount = quantity;
|
2117
2065
|
} else {
|
2118
2066
|
this.addResources([
|
2119
2067
|
{
|
2120
|
-
id: (
|
2121
|
-
amount:
|
2068
|
+
id: generateId(),
|
2069
|
+
amount: quantity,
|
2122
2070
|
assetId,
|
2123
2071
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2072
|
+
maturity: 0,
|
2124
2073
|
blockCreated: (0, import_math7.bn)(1),
|
2125
2074
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2126
2075
|
}
|
2127
2076
|
]);
|
2128
2077
|
}
|
2129
2078
|
};
|
2130
|
-
updateAssetInput(
|
2079
|
+
updateAssetInput(this.baseAssetId, (0, import_math7.bn)(1e11));
|
2131
2080
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2132
2081
|
}
|
2133
2082
|
/**
|
@@ -2152,7 +2101,7 @@ var BaseTransactionRequest = class {
|
|
2152
2101
|
toJSON() {
|
2153
2102
|
return normalizeJSON(this);
|
2154
2103
|
}
|
2155
|
-
|
2104
|
+
updatePredicateInputs(inputs) {
|
2156
2105
|
this.inputs.forEach((i) => {
|
2157
2106
|
let correspondingInput;
|
2158
2107
|
switch (i.type) {
|
@@ -2174,25 +2123,16 @@ var BaseTransactionRequest = class {
|
|
2174
2123
|
}
|
2175
2124
|
});
|
2176
2125
|
}
|
2177
|
-
shiftPredicateData() {
|
2178
|
-
this.inputs.forEach((input) => {
|
2179
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2180
|
-
input.predicateData = input.paddPredicateData(
|
2181
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2182
|
-
);
|
2183
|
-
}
|
2184
|
-
});
|
2185
|
-
}
|
2186
2126
|
};
|
2187
2127
|
|
2188
2128
|
// src/providers/transaction-request/create-transaction-request.ts
|
2189
|
-
var
|
2129
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2190
2130
|
var import_math9 = require("@fuel-ts/math");
|
2191
2131
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2192
2132
|
var import_utils13 = require("@fuel-ts/utils");
|
2193
2133
|
|
2194
2134
|
// src/providers/transaction-request/hash-transaction.ts
|
2195
|
-
var
|
2135
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
2196
2136
|
var import_hasher = require("@fuel-ts/hasher");
|
2197
2137
|
var import_math8 = require("@fuel-ts/math");
|
2198
2138
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2201,7 +2141,7 @@ var import_ramda2 = require("ramda");
|
|
2201
2141
|
function hashTransaction(transactionRequest, chainId) {
|
2202
2142
|
const transaction = transactionRequest.toTransaction();
|
2203
2143
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2204
|
-
transaction.receiptsRoot =
|
2144
|
+
transaction.receiptsRoot = import_configs7.ZeroBytes32;
|
2205
2145
|
}
|
2206
2146
|
transaction.inputs = transaction.inputs.map((input) => {
|
2207
2147
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2223,10 +2163,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2223
2163
|
blockHeight: 0,
|
2224
2164
|
txIndex: 0
|
2225
2165
|
};
|
2226
|
-
inputClone.txID =
|
2166
|
+
inputClone.txID = import_configs7.ZeroBytes32;
|
2227
2167
|
inputClone.outputIndex = 0;
|
2228
|
-
inputClone.balanceRoot =
|
2229
|
-
inputClone.stateRoot =
|
2168
|
+
inputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2169
|
+
inputClone.stateRoot = import_configs7.ZeroBytes32;
|
2230
2170
|
return inputClone;
|
2231
2171
|
}
|
2232
2172
|
default:
|
@@ -2237,8 +2177,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2237
2177
|
const outputClone = (0, import_ramda2.clone)(output);
|
2238
2178
|
switch (outputClone.type) {
|
2239
2179
|
case import_transactions7.OutputType.Contract: {
|
2240
|
-
outputClone.balanceRoot =
|
2241
|
-
outputClone.stateRoot =
|
2180
|
+
outputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2181
|
+
outputClone.stateRoot = import_configs7.ZeroBytes32;
|
2242
2182
|
return outputClone;
|
2243
2183
|
}
|
2244
2184
|
case import_transactions7.OutputType.Change: {
|
@@ -2246,9 +2186,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2246
2186
|
return outputClone;
|
2247
2187
|
}
|
2248
2188
|
case import_transactions7.OutputType.Variable: {
|
2249
|
-
outputClone.to =
|
2189
|
+
outputClone.to = import_configs7.ZeroBytes32;
|
2250
2190
|
outputClone.amount = (0, import_math8.bn)(0);
|
2251
|
-
outputClone.assetId =
|
2191
|
+
outputClone.assetId = import_configs7.ZeroBytes32;
|
2252
2192
|
return outputClone;
|
2253
2193
|
}
|
2254
2194
|
default:
|
@@ -2306,15 +2246,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2306
2246
|
*
|
2307
2247
|
* @param createTransactionRequestLike - The initial values for the instance
|
2308
2248
|
*/
|
2309
|
-
constructor({
|
2310
|
-
bytecodeWitnessIndex,
|
2311
|
-
salt,
|
2312
|
-
storageSlots,
|
2313
|
-
...rest
|
2314
|
-
} = {}) {
|
2249
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2315
2250
|
super(rest);
|
2316
2251
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2317
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2252
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
|
2318
2253
|
this.storageSlots = [...storageSlots ?? []];
|
2319
2254
|
}
|
2320
2255
|
/**
|
@@ -2329,9 +2264,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2329
2264
|
return {
|
2330
2265
|
type: import_transactions8.TransactionType.Create,
|
2331
2266
|
...baseTransaction,
|
2267
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2332
2268
|
bytecodeWitnessIndex,
|
2333
|
-
storageSlotsCount:
|
2334
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2269
|
+
storageSlotsCount: storageSlots.length,
|
2270
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
|
2335
2271
|
storageSlots
|
2336
2272
|
};
|
2337
2273
|
}
|
@@ -2381,7 +2317,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2381
2317
|
// src/providers/transaction-request/script-transaction-request.ts
|
2382
2318
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2383
2319
|
var import_address2 = require("@fuel-ts/address");
|
2384
|
-
var
|
2320
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2385
2321
|
var import_math10 = require("@fuel-ts/math");
|
2386
2322
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2387
2323
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2434,7 +2370,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2434
2370
|
*
|
2435
2371
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2436
2372
|
*/
|
2437
|
-
constructor({ script, scriptData, gasLimit, ...rest }
|
2373
|
+
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2438
2374
|
super(rest);
|
2439
2375
|
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2440
2376
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
@@ -2453,9 +2389,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2453
2389
|
type: import_transactions9.TransactionType.Script,
|
2454
2390
|
scriptGasLimit: this.gasLimit,
|
2455
2391
|
...super.getBaseTransaction(),
|
2456
|
-
scriptLength:
|
2457
|
-
scriptDataLength:
|
2458
|
-
receiptsRoot:
|
2392
|
+
scriptLength: script.length,
|
2393
|
+
scriptDataLength: scriptData.length,
|
2394
|
+
receiptsRoot: import_configs9.ZeroBytes32,
|
2459
2395
|
script: (0, import_utils15.hexlify)(script),
|
2460
2396
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2461
2397
|
};
|
@@ -2518,7 +2454,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2518
2454
|
}
|
2519
2455
|
calculateMaxGas(chainInfo, minGas) {
|
2520
2456
|
const { consensusParameters } = chainInfo;
|
2521
|
-
const { gasPerByte
|
2457
|
+
const { gasPerByte } = consensusParameters;
|
2522
2458
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2523
2459
|
(acc, wit) => acc + wit.dataLength,
|
2524
2460
|
0
|
@@ -2528,8 +2464,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2528
2464
|
minGas,
|
2529
2465
|
witnessesLength,
|
2530
2466
|
witnessLimit: this.witnessLimit,
|
2531
|
-
gasLimit: this.gasLimit
|
2532
|
-
maxGasPerTx
|
2467
|
+
gasLimit: this.gasLimit
|
2533
2468
|
});
|
2534
2469
|
}
|
2535
2470
|
/**
|
@@ -2604,32 +2539,15 @@ var transactionRequestify = (obj) => {
|
|
2604
2539
|
}
|
2605
2540
|
}
|
2606
2541
|
};
|
2607
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2608
|
-
(acc, input) => {
|
2609
|
-
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2610
|
-
acc.utxos.push(input.id);
|
2611
|
-
}
|
2612
|
-
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2613
|
-
acc.messages.push(input.nonce);
|
2614
|
-
}
|
2615
|
-
return acc;
|
2616
|
-
},
|
2617
|
-
{
|
2618
|
-
utxos: [],
|
2619
|
-
messages: []
|
2620
|
-
}
|
2621
|
-
);
|
2622
2542
|
|
2623
2543
|
// src/providers/transaction-response/transaction-response.ts
|
2624
2544
|
var import_errors13 = require("@fuel-ts/errors");
|
2625
|
-
var
|
2626
|
-
var
|
2627
|
-
var
|
2545
|
+
var import_math14 = require("@fuel-ts/math");
|
2546
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2547
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2628
2548
|
|
2629
2549
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2630
|
-
var
|
2631
|
-
var import_transactions16 = require("@fuel-ts/transactions");
|
2632
|
-
var import_utils18 = require("@fuel-ts/utils");
|
2550
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2633
2551
|
|
2634
2552
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2635
2553
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2637,10 +2555,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2637
2555
|
var import_utils16 = require("@fuel-ts/utils");
|
2638
2556
|
var calculateTransactionFee = (params) => {
|
2639
2557
|
const {
|
2640
|
-
|
2558
|
+
gasUsed,
|
2641
2559
|
rawPayload,
|
2642
|
-
|
2643
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2560
|
+
consensusParameters: { gasCosts, feeParams }
|
2644
2561
|
} = params;
|
2645
2562
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2646
2563
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2650,7 +2567,8 @@ var calculateTransactionFee = (params) => {
|
|
2650
2567
|
return {
|
2651
2568
|
fee: (0, import_math11.bn)(0),
|
2652
2569
|
minFee: (0, import_math11.bn)(0),
|
2653
|
-
maxFee: (0, import_math11.bn)(0)
|
2570
|
+
maxFee: (0, import_math11.bn)(0),
|
2571
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2654
2572
|
};
|
2655
2573
|
}
|
2656
2574
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2682,6 +2600,7 @@ var calculateTransactionFee = (params) => {
|
|
2682
2600
|
metadataGas,
|
2683
2601
|
txBytesSize: transactionBytes.length
|
2684
2602
|
});
|
2603
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2685
2604
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2686
2605
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2687
2606
|
const maxGas = getMaxGas({
|
@@ -2689,30 +2608,22 @@ var calculateTransactionFee = (params) => {
|
|
2689
2608
|
minGas,
|
2690
2609
|
witnessesLength,
|
2691
2610
|
gasLimit,
|
2692
|
-
witnessLimit
|
2693
|
-
maxGasPerTx
|
2694
|
-
});
|
2695
|
-
const minFee = calculateGasFee({
|
2696
|
-
gasPrice,
|
2697
|
-
gas: minGas,
|
2698
|
-
priceFactor: gasPriceFactor,
|
2699
|
-
tip
|
2700
|
-
});
|
2701
|
-
const maxFee = calculateGasFee({
|
2702
|
-
gasPrice,
|
2703
|
-
gas: maxGas,
|
2704
|
-
priceFactor: gasPriceFactor,
|
2705
|
-
tip
|
2611
|
+
witnessLimit
|
2706
2612
|
});
|
2613
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2614
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2615
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2616
|
+
const fee = minFee.add(feeFromGasUsed);
|
2707
2617
|
return {
|
2618
|
+
fee,
|
2708
2619
|
minFee,
|
2709
2620
|
maxFee,
|
2710
|
-
|
2621
|
+
feeFromGasUsed
|
2711
2622
|
};
|
2712
2623
|
};
|
2713
2624
|
|
2714
2625
|
// src/providers/transaction-summary/operations.ts
|
2715
|
-
var
|
2626
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2716
2627
|
var import_errors11 = require("@fuel-ts/errors");
|
2717
2628
|
var import_math13 = require("@fuel-ts/math");
|
2718
2629
|
var import_transactions14 = require("@fuel-ts/transactions");
|
@@ -3010,7 +2921,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3010
2921
|
const { to: toAddress, assetId, amount } = receipt;
|
3011
2922
|
let { from: fromAddress } = receipt;
|
3012
2923
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3013
|
-
if (
|
2924
|
+
if (import_configs10.ZeroBytes32 === fromAddress) {
|
3014
2925
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3015
2926
|
fromAddress = change?.to || fromAddress;
|
3016
2927
|
}
|
@@ -3274,12 +3185,10 @@ function assembleTransactionSummary(params) {
|
|
3274
3185
|
gqlTransactionStatus,
|
3275
3186
|
abiMap = {},
|
3276
3187
|
maxInputs,
|
3277
|
-
gasCosts
|
3278
|
-
maxGasPerTx,
|
3279
|
-
gasPrice
|
3188
|
+
gasCosts
|
3280
3189
|
} = params;
|
3281
3190
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3282
|
-
const rawPayload = (0,
|
3191
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3283
3192
|
const operations = getOperations({
|
3284
3193
|
transactionType: transaction.type,
|
3285
3194
|
inputs: transaction.inputs || [],
|
@@ -3290,14 +3199,11 @@ function assembleTransactionSummary(params) {
|
|
3290
3199
|
maxInputs
|
3291
3200
|
});
|
3292
3201
|
const typeName = getTransactionTypeName(transaction.type);
|
3293
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3294
3202
|
const { fee } = calculateTransactionFee({
|
3295
|
-
|
3203
|
+
gasUsed,
|
3296
3204
|
rawPayload,
|
3297
|
-
tip,
|
3298
3205
|
consensusParameters: {
|
3299
3206
|
gasCosts,
|
3300
|
-
maxGasPerTx,
|
3301
3207
|
feeParams: {
|
3302
3208
|
gasPerByte,
|
3303
3209
|
gasPriceFactor
|
@@ -3309,7 +3215,7 @@ function assembleTransactionSummary(params) {
|
|
3309
3215
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3310
3216
|
let date;
|
3311
3217
|
if (time) {
|
3312
|
-
date =
|
3218
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3313
3219
|
}
|
3314
3220
|
const transactionSummary = {
|
3315
3221
|
id,
|
@@ -3337,12 +3243,12 @@ function assembleTransactionSummary(params) {
|
|
3337
3243
|
|
3338
3244
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3339
3245
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3340
|
-
var
|
3246
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3341
3247
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3342
3248
|
return receipts.reduce((logs, receipt) => {
|
3343
|
-
if (receipt.type ===
|
3249
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3344
3250
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3345
|
-
const data = receipt.type ===
|
3251
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3346
3252
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3347
3253
|
logs.push(decodedLog);
|
3348
3254
|
}
|
@@ -3357,7 +3263,7 @@ var TransactionResponse = class {
|
|
3357
3263
|
/** Current provider */
|
3358
3264
|
provider;
|
3359
3265
|
/** Gas used on the transaction */
|
3360
|
-
gasUsed = (0,
|
3266
|
+
gasUsed = (0, import_math14.bn)(0);
|
3361
3267
|
/** The graphql Transaction with receipts object. */
|
3362
3268
|
gqlTransaction;
|
3363
3269
|
abis;
|
@@ -3415,8 +3321,8 @@ var TransactionResponse = class {
|
|
3415
3321
|
* @returns The decoded transaction.
|
3416
3322
|
*/
|
3417
3323
|
decodeTransaction(transactionWithReceipts) {
|
3418
|
-
return new
|
3419
|
-
(0,
|
3324
|
+
return new import_transactions17.TransactionCoder().decode(
|
3325
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3420
3326
|
0
|
3421
3327
|
)?.[0];
|
3422
3328
|
}
|
@@ -3435,27 +3341,20 @@ var TransactionResponse = class {
|
|
3435
3341
|
const decodedTransaction = this.decodeTransaction(
|
3436
3342
|
transaction
|
3437
3343
|
);
|
3438
|
-
|
3439
|
-
|
3440
|
-
txReceipts = transaction.status.receipts;
|
3441
|
-
}
|
3442
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3443
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3444
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3344
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3345
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3445
3346
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3446
3347
|
const transactionSummary = assembleTransactionSummary({
|
3447
3348
|
id: this.id,
|
3448
3349
|
receipts,
|
3449
3350
|
transaction: decodedTransaction,
|
3450
|
-
transactionBytes: (0,
|
3351
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3451
3352
|
gqlTransactionStatus: transaction.status,
|
3452
3353
|
gasPerByte,
|
3453
3354
|
gasPriceFactor,
|
3454
3355
|
abiMap: contractsAbiMap,
|
3455
3356
|
maxInputs,
|
3456
|
-
gasCosts
|
3457
|
-
maxGasPerTx,
|
3458
|
-
gasPrice
|
3357
|
+
gasCosts
|
3459
3358
|
});
|
3460
3359
|
return transactionSummary;
|
3461
3360
|
}
|
@@ -3582,29 +3481,30 @@ var processGqlChain = (chain) => {
|
|
3582
3481
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3583
3482
|
return {
|
3584
3483
|
name,
|
3585
|
-
baseChainHeight: (0,
|
3484
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3586
3485
|
consensusParameters: {
|
3587
|
-
contractMaxSize: (0,
|
3588
|
-
maxInputs: (0,
|
3589
|
-
maxOutputs: (0,
|
3590
|
-
maxWitnesses: (0,
|
3591
|
-
maxGasPerTx: (0,
|
3592
|
-
maxScriptLength: (0,
|
3593
|
-
maxScriptDataLength: (0,
|
3594
|
-
maxStorageSlots: (0,
|
3595
|
-
maxPredicateLength: (0,
|
3596
|
-
maxPredicateDataLength: (0,
|
3597
|
-
maxGasPerPredicate: (0,
|
3598
|
-
gasPriceFactor: (0,
|
3599
|
-
gasPerByte: (0,
|
3600
|
-
maxMessageDataLength: (0,
|
3601
|
-
chainId: (0,
|
3486
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3487
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3488
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3489
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3490
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3491
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3492
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3493
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3494
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3495
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3496
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3497
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3498
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3499
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3500
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3501
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3602
3502
|
gasCosts
|
3603
3503
|
},
|
3604
3504
|
gasCosts,
|
3605
3505
|
latestBlock: {
|
3606
3506
|
id: latestBlock.id,
|
3607
|
-
height: (0,
|
3507
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3608
3508
|
time: latestBlock.header.time,
|
3609
3509
|
transactions: latestBlock.transactions.map((i) => ({
|
3610
3510
|
id: i.id
|
@@ -3698,8 +3598,10 @@ var _Provider = class {
|
|
3698
3598
|
* Returns some helpful parameters related to gas fees.
|
3699
3599
|
*/
|
3700
3600
|
getGasConfig() {
|
3601
|
+
const { minGasPrice } = this.getNode();
|
3701
3602
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3702
3603
|
return {
|
3604
|
+
minGasPrice,
|
3703
3605
|
maxGasPerTx,
|
3704
3606
|
maxGasPerPredicate,
|
3705
3607
|
gasPriceFactor,
|
@@ -3787,7 +3689,7 @@ var _Provider = class {
|
|
3787
3689
|
name,
|
3788
3690
|
consensusParameters: { chainId }
|
3789
3691
|
} = await this.getChain();
|
3790
|
-
const network = new
|
3692
|
+
const network = new import_ethers.Network(name, chainId.toNumber());
|
3791
3693
|
return Promise.resolve(network);
|
3792
3694
|
}
|
3793
3695
|
/**
|
@@ -3797,7 +3699,7 @@ var _Provider = class {
|
|
3797
3699
|
*/
|
3798
3700
|
async getBlockNumber() {
|
3799
3701
|
const { chain } = await this.operations.getChain();
|
3800
|
-
return (0,
|
3702
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
3801
3703
|
}
|
3802
3704
|
/**
|
3803
3705
|
* Returns the chain information.
|
@@ -3807,11 +3709,13 @@ var _Provider = class {
|
|
3807
3709
|
async fetchNode() {
|
3808
3710
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3809
3711
|
const processedNodeInfo = {
|
3810
|
-
maxDepth: (0,
|
3811
|
-
maxTx: (0,
|
3712
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3713
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3714
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3812
3715
|
nodeVersion: nodeInfo.nodeVersion,
|
3813
3716
|
utxoValidation: nodeInfo.utxoValidation,
|
3814
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3717
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3718
|
+
peers: nodeInfo.peers
|
3815
3719
|
};
|
3816
3720
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3817
3721
|
return processedNodeInfo;
|
@@ -3837,6 +3741,17 @@ var _Provider = class {
|
|
3837
3741
|
} = this.getChain();
|
3838
3742
|
return chainId.toNumber();
|
3839
3743
|
}
|
3744
|
+
/**
|
3745
|
+
* Returns the base asset ID
|
3746
|
+
*
|
3747
|
+
* @returns A promise that resolves to the base asset ID
|
3748
|
+
*/
|
3749
|
+
getBaseAssetId() {
|
3750
|
+
const {
|
3751
|
+
consensusParameters: { baseAssetId }
|
3752
|
+
} = this.getChain();
|
3753
|
+
return baseAssetId;
|
3754
|
+
}
|
3840
3755
|
/**
|
3841
3756
|
* Submits a transaction to the chain to be executed.
|
3842
3757
|
*
|
@@ -3853,9 +3768,9 @@ var _Provider = class {
|
|
3853
3768
|
if (estimateTxDependencies) {
|
3854
3769
|
await this.estimateTxDependencies(transactionRequest);
|
3855
3770
|
}
|
3856
|
-
const encodedTransaction = (0,
|
3771
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3857
3772
|
let abis;
|
3858
|
-
if (transactionRequest.type ===
|
3773
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3859
3774
|
abis = transactionRequest.abis;
|
3860
3775
|
}
|
3861
3776
|
if (awaitExecution) {
|
@@ -3896,14 +3811,15 @@ var _Provider = class {
|
|
3896
3811
|
if (estimateTxDependencies) {
|
3897
3812
|
return this.estimateTxDependencies(transactionRequest);
|
3898
3813
|
}
|
3899
|
-
const encodedTransaction = (0,
|
3900
|
-
const { dryRun:
|
3901
|
-
|
3814
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3815
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3816
|
+
encodedTransaction,
|
3902
3817
|
utxoValidation: utxoValidation || false
|
3903
3818
|
});
|
3904
|
-
const
|
3905
|
-
|
3906
|
-
|
3819
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3820
|
+
return {
|
3821
|
+
receipts
|
3822
|
+
};
|
3907
3823
|
}
|
3908
3824
|
/**
|
3909
3825
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3914,13 +3830,13 @@ var _Provider = class {
|
|
3914
3830
|
async estimatePredicates(transactionRequest) {
|
3915
3831
|
const shouldEstimatePredicates = Boolean(
|
3916
3832
|
transactionRequest.inputs.find(
|
3917
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3833
|
+
(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()
|
3918
3834
|
)
|
3919
3835
|
);
|
3920
3836
|
if (!shouldEstimatePredicates) {
|
3921
3837
|
return transactionRequest;
|
3922
3838
|
}
|
3923
|
-
const encodedTransaction = (0,
|
3839
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3924
3840
|
const response = await this.operations.estimatePredicates({
|
3925
3841
|
encodedTransaction
|
3926
3842
|
});
|
@@ -3929,7 +3845,7 @@ var _Provider = class {
|
|
3929
3845
|
} = response;
|
3930
3846
|
if (inputs) {
|
3931
3847
|
inputs.forEach((input, index) => {
|
3932
|
-
if ("predicateGasUsed" in input && (0,
|
3848
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
3933
3849
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3934
3850
|
}
|
3935
3851
|
});
|
@@ -3942,31 +3858,31 @@ var _Provider = class {
|
|
3942
3858
|
* If there are missing variable outputs,
|
3943
3859
|
* `addVariableOutputs` is called on the transaction.
|
3944
3860
|
*
|
3861
|
+
* @privateRemarks
|
3862
|
+
* TODO: Investigate support for missing contract IDs
|
3863
|
+
* TODO: Add support for missing output messages
|
3945
3864
|
*
|
3946
3865
|
* @param transactionRequest - The transaction request object.
|
3947
3866
|
* @returns A promise.
|
3948
3867
|
*/
|
3949
3868
|
async estimateTxDependencies(transactionRequest) {
|
3950
|
-
if (transactionRequest.type ===
|
3869
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
3951
3870
|
return {
|
3952
3871
|
receipts: [],
|
3953
3872
|
outputVariables: 0,
|
3954
3873
|
missingContractIds: []
|
3955
3874
|
};
|
3956
3875
|
}
|
3876
|
+
await this.estimatePredicates(transactionRequest);
|
3957
3877
|
let receipts = [];
|
3958
3878
|
const missingContractIds = [];
|
3959
3879
|
let outputVariables = 0;
|
3960
|
-
let dryrunStatus;
|
3961
3880
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3962
|
-
const {
|
3963
|
-
|
3964
|
-
} = await this.operations.dryRun({
|
3965
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3881
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3882
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
3966
3883
|
utxoValidation: false
|
3967
3884
|
});
|
3968
|
-
receipts =
|
3969
|
-
dryrunStatus = status;
|
3885
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3970
3886
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3971
3887
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3972
3888
|
if (hasMissingOutputs) {
|
@@ -3976,11 +3892,6 @@ var _Provider = class {
|
|
3976
3892
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3977
3893
|
missingContractIds.push(contractId);
|
3978
3894
|
});
|
3979
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3980
|
-
transactionRequest,
|
3981
|
-
optimizeGas: false
|
3982
|
-
});
|
3983
|
-
transactionRequest.maxFee = maxFee;
|
3984
3895
|
} else {
|
3985
3896
|
break;
|
3986
3897
|
}
|
@@ -3988,133 +3899,7 @@ var _Provider = class {
|
|
3988
3899
|
return {
|
3989
3900
|
receipts,
|
3990
3901
|
outputVariables,
|
3991
|
-
missingContractIds
|
3992
|
-
dryrunStatus
|
3993
|
-
};
|
3994
|
-
}
|
3995
|
-
/**
|
3996
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
3997
|
-
*
|
3998
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
3999
|
-
* further modifications are identified. The method iteratively updates these transactions
|
4000
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4001
|
-
*
|
4002
|
-
* @param transactionRequests - Array of transaction request objects.
|
4003
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4004
|
-
*/
|
4005
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4006
|
-
const results = transactionRequests.map(() => ({
|
4007
|
-
receipts: [],
|
4008
|
-
outputVariables: 0,
|
4009
|
-
missingContractIds: [],
|
4010
|
-
dryrunStatus: void 0
|
4011
|
-
}));
|
4012
|
-
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4013
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4014
|
-
allRequests.forEach((req, index) => {
|
4015
|
-
if (req.type === import_transactions19.TransactionType.Script) {
|
4016
|
-
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4017
|
-
}
|
4018
|
-
});
|
4019
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4020
|
-
let attempt = 0;
|
4021
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4022
|
-
const encodedTransactions = transactionsToProcess.map(
|
4023
|
-
(index) => serializedTransactionsMap.get(index)
|
4024
|
-
);
|
4025
|
-
const dryRunResults = await this.operations.dryRun({
|
4026
|
-
encodedTransactions,
|
4027
|
-
utxoValidation: false
|
4028
|
-
});
|
4029
|
-
const nextRoundTransactions = [];
|
4030
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4031
|
-
const currentResultIndex = transactionsToProcess[i];
|
4032
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4033
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4034
|
-
results[currentResultIndex].dryrunStatus = status;
|
4035
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4036
|
-
results[currentResultIndex].receipts
|
4037
|
-
);
|
4038
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4039
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4040
|
-
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4041
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4042
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4043
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4044
|
-
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4045
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4046
|
-
});
|
4047
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4048
|
-
transactionRequest: requestToProcess,
|
4049
|
-
optimizeGas: false
|
4050
|
-
});
|
4051
|
-
requestToProcess.maxFee = maxFee;
|
4052
|
-
serializedTransactionsMap.set(
|
4053
|
-
currentResultIndex,
|
4054
|
-
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4055
|
-
);
|
4056
|
-
nextRoundTransactions.push(currentResultIndex);
|
4057
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4058
|
-
}
|
4059
|
-
}
|
4060
|
-
transactionsToProcess = nextRoundTransactions;
|
4061
|
-
attempt += 1;
|
4062
|
-
}
|
4063
|
-
return results;
|
4064
|
-
}
|
4065
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4066
|
-
if (estimateTxDependencies) {
|
4067
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4068
|
-
}
|
4069
|
-
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4070
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4071
|
-
encodedTransactions,
|
4072
|
-
utxoValidation: utxoValidation || false
|
4073
|
-
});
|
4074
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4075
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4076
|
-
return { receipts, dryrunStatus: status };
|
4077
|
-
});
|
4078
|
-
return results;
|
4079
|
-
}
|
4080
|
-
async estimateTxGasAndFee(params) {
|
4081
|
-
const { transactionRequest, optimizeGas = true } = params;
|
4082
|
-
let { gasPrice } = params;
|
4083
|
-
const chainInfo = this.getChain();
|
4084
|
-
const { gasPriceFactor } = this.getGasConfig();
|
4085
|
-
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4086
|
-
if (!gasPrice) {
|
4087
|
-
gasPrice = await this.estimateGasPrice(10);
|
4088
|
-
}
|
4089
|
-
const minFee = calculateGasFee({
|
4090
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4091
|
-
gas: minGas,
|
4092
|
-
priceFactor: gasPriceFactor,
|
4093
|
-
tip: transactionRequest.tip
|
4094
|
-
}).add(1);
|
4095
|
-
let gasLimit = (0, import_math16.bn)(0);
|
4096
|
-
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4097
|
-
gasLimit = transactionRequest.gasLimit;
|
4098
|
-
if (!optimizeGas) {
|
4099
|
-
transactionRequest.gasLimit = minGas;
|
4100
|
-
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4101
|
-
transactionRequest.gasLimit = gasLimit;
|
4102
|
-
}
|
4103
|
-
}
|
4104
|
-
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4105
|
-
const maxFee = calculateGasFee({
|
4106
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4107
|
-
gas: maxGas,
|
4108
|
-
priceFactor: gasPriceFactor,
|
4109
|
-
tip: transactionRequest.tip
|
4110
|
-
}).add(1);
|
4111
|
-
return {
|
4112
|
-
minGas,
|
4113
|
-
minFee,
|
4114
|
-
maxGas,
|
4115
|
-
maxFee,
|
4116
|
-
gasPrice,
|
4117
|
-
gasLimit
|
3902
|
+
missingContractIds
|
4118
3903
|
};
|
4119
3904
|
}
|
4120
3905
|
/**
|
@@ -4132,17 +3917,15 @@ var _Provider = class {
|
|
4132
3917
|
if (estimateTxDependencies) {
|
4133
3918
|
return this.estimateTxDependencies(transactionRequest);
|
4134
3919
|
}
|
4135
|
-
const
|
4136
|
-
const { dryRun:
|
4137
|
-
|
3920
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3921
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3922
|
+
encodedTransaction,
|
4138
3923
|
utxoValidation: true
|
4139
3924
|
});
|
4140
|
-
const
|
4141
|
-
|
4142
|
-
|
4143
|
-
|
4144
|
-
});
|
4145
|
-
return { receipts: callResult[0].receipts };
|
3925
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3926
|
+
return {
|
3927
|
+
receipts
|
3928
|
+
};
|
4146
3929
|
}
|
4147
3930
|
/**
|
4148
3931
|
* Returns a transaction cost to enable user
|
@@ -4159,80 +3942,80 @@ var _Provider = class {
|
|
4159
3942
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4160
3943
|
* @returns A promise that resolves to the transaction cost object.
|
4161
3944
|
*/
|
4162
|
-
async getTransactionCost(transactionRequestLike,
|
3945
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3946
|
+
estimateTxDependencies = true,
|
3947
|
+
estimatePredicates = true,
|
3948
|
+
resourcesOwner,
|
3949
|
+
signatureCallback
|
3950
|
+
} = {}) {
|
4163
3951
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4164
|
-
const
|
3952
|
+
const chainInfo = this.getChain();
|
3953
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3954
|
+
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3955
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4165
3956
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4166
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3957
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4167
3958
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4168
|
-
|
4169
|
-
|
4170
|
-
|
4171
|
-
|
4172
|
-
|
4173
|
-
|
3959
|
+
if (estimatePredicates) {
|
3960
|
+
if (isScriptTransaction) {
|
3961
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3962
|
+
}
|
3963
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3964
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3965
|
+
}
|
3966
|
+
await this.estimatePredicates(txRequestClone);
|
4174
3967
|
}
|
4175
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4176
|
-
let addedSignatures = 0;
|
4177
3968
|
if (signatureCallback && isScriptTransaction) {
|
4178
|
-
|
4179
|
-
|
4180
|
-
|
4181
|
-
|
4182
|
-
await this.estimatePredicates(signedRequest);
|
4183
|
-
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4184
|
-
transactionRequest: signedRequest,
|
4185
|
-
optimizeGas: false
|
4186
|
-
});
|
4187
|
-
txRequestClone.maxFee = maxFee;
|
3969
|
+
await signatureCallback(txRequestClone);
|
3970
|
+
}
|
3971
|
+
const minGas = txRequestClone.calculateMinGas(chainInfo);
|
3972
|
+
const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
|
4188
3973
|
let receipts = [];
|
4189
3974
|
let missingContractIds = [];
|
4190
3975
|
let outputVariables = 0;
|
4191
|
-
|
4192
|
-
|
4193
|
-
|
4194
|
-
if (signatureCallback) {
|
4195
|
-
await signatureCallback(txRequestClone);
|
4196
|
-
}
|
4197
|
-
txRequestClone.gasLimit = gasLimit;
|
3976
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
3977
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
3978
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4198
3979
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4199
3980
|
receipts = result.receipts;
|
4200
3981
|
outputVariables = result.outputVariables;
|
4201
3982
|
missingContractIds = result.missingContractIds;
|
4202
|
-
gasUsed = getGasUsedFromReceipts(receipts);
|
4203
|
-
txRequestClone.gasLimit = gasUsed;
|
4204
|
-
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4205
|
-
transactionRequest: txRequestClone,
|
4206
|
-
gasPrice
|
4207
|
-
}));
|
4208
3983
|
}
|
3984
|
+
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3985
|
+
const usedFee = calculatePriceWithFactor(
|
3986
|
+
gasUsed,
|
3987
|
+
gasPrice,
|
3988
|
+
gasPriceFactor
|
3989
|
+
).normalizeZeroToOne();
|
3990
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3991
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4209
3992
|
return {
|
4210
3993
|
requiredQuantities: allQuantities,
|
4211
3994
|
receipts,
|
4212
3995
|
gasUsed,
|
3996
|
+
minGasPrice,
|
4213
3997
|
gasPrice,
|
4214
3998
|
minGas,
|
4215
3999
|
maxGas,
|
4000
|
+
usedFee,
|
4216
4001
|
minFee,
|
4217
4002
|
maxFee,
|
4003
|
+
estimatedInputs: txRequestClone.inputs,
|
4218
4004
|
outputVariables,
|
4219
|
-
missingContractIds
|
4220
|
-
addedSignatures,
|
4221
|
-
estimatedPredicates: txRequestClone.inputs
|
4005
|
+
missingContractIds
|
4222
4006
|
};
|
4223
4007
|
}
|
4224
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4008
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4225
4009
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4226
4010
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4227
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4228
|
-
quantitiesToContract
|
4229
|
-
});
|
4011
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4230
4012
|
transactionRequest.addResources(
|
4231
4013
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4232
4014
|
);
|
4233
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4234
|
-
|
4235
|
-
|
4015
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4016
|
+
transactionRequest,
|
4017
|
+
forwardingQuantities
|
4018
|
+
);
|
4236
4019
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4237
4020
|
return {
|
4238
4021
|
resources,
|
@@ -4248,16 +4031,17 @@ var _Provider = class {
|
|
4248
4031
|
const result = await this.operations.getCoins({
|
4249
4032
|
first: 10,
|
4250
4033
|
...paginationArgs,
|
4251
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4034
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4252
4035
|
});
|
4253
4036
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4254
4037
|
return coins.map((coin) => ({
|
4255
4038
|
id: coin.utxoId,
|
4256
4039
|
assetId: coin.assetId,
|
4257
|
-
amount: (0,
|
4040
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4258
4041
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4259
|
-
|
4260
|
-
|
4042
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4043
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4044
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4261
4045
|
}));
|
4262
4046
|
}
|
4263
4047
|
/**
|
@@ -4271,19 +4055,19 @@ var _Provider = class {
|
|
4271
4055
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4272
4056
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4273
4057
|
const excludeInput = {
|
4274
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4275
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4058
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4059
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4276
4060
|
};
|
4277
4061
|
if (this.cache) {
|
4278
4062
|
const uniqueUtxos = new Set(
|
4279
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4063
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4280
4064
|
);
|
4281
4065
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4282
4066
|
}
|
4283
4067
|
const coinsQuery = {
|
4284
4068
|
owner: ownerAddress.toB256(),
|
4285
4069
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4286
|
-
assetId: (0,
|
4070
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4287
4071
|
amount: amount.toString(10),
|
4288
4072
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4289
4073
|
})),
|
@@ -4294,9 +4078,9 @@ var _Provider = class {
|
|
4294
4078
|
switch (coin.__typename) {
|
4295
4079
|
case "MessageCoin":
|
4296
4080
|
return {
|
4297
|
-
amount: (0,
|
4081
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4298
4082
|
assetId: coin.assetId,
|
4299
|
-
daHeight: (0,
|
4083
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4300
4084
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4301
4085
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4302
4086
|
nonce: coin.nonce
|
@@ -4304,11 +4088,12 @@ var _Provider = class {
|
|
4304
4088
|
case "Coin":
|
4305
4089
|
return {
|
4306
4090
|
id: coin.utxoId,
|
4307
|
-
amount: (0,
|
4091
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4308
4092
|
assetId: coin.assetId,
|
4309
4093
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4310
|
-
|
4311
|
-
|
4094
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4095
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4096
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4312
4097
|
};
|
4313
4098
|
default:
|
4314
4099
|
return null;
|
@@ -4325,13 +4110,13 @@ var _Provider = class {
|
|
4325
4110
|
async getBlock(idOrHeight) {
|
4326
4111
|
let variables;
|
4327
4112
|
if (typeof idOrHeight === "number") {
|
4328
|
-
variables = { height: (0,
|
4113
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4329
4114
|
} else if (idOrHeight === "latest") {
|
4330
4115
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4331
4116
|
} else if (idOrHeight.length === 66) {
|
4332
4117
|
variables = { blockId: idOrHeight };
|
4333
4118
|
} else {
|
4334
|
-
variables = { blockId: (0,
|
4119
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4335
4120
|
}
|
4336
4121
|
const { block } = await this.operations.getBlock(variables);
|
4337
4122
|
if (!block) {
|
@@ -4339,7 +4124,7 @@ var _Provider = class {
|
|
4339
4124
|
}
|
4340
4125
|
return {
|
4341
4126
|
id: block.id,
|
4342
|
-
height: (0,
|
4127
|
+
height: (0, import_math15.bn)(block.header.height),
|
4343
4128
|
time: block.header.time,
|
4344
4129
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4345
4130
|
};
|
@@ -4354,7 +4139,7 @@ var _Provider = class {
|
|
4354
4139
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4355
4140
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4356
4141
|
id: block.id,
|
4357
|
-
height: (0,
|
4142
|
+
height: (0, import_math15.bn)(block.header.height),
|
4358
4143
|
time: block.header.time,
|
4359
4144
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4360
4145
|
}));
|
@@ -4369,7 +4154,7 @@ var _Provider = class {
|
|
4369
4154
|
async getBlockWithTransactions(idOrHeight) {
|
4370
4155
|
let variables;
|
4371
4156
|
if (typeof idOrHeight === "number") {
|
4372
|
-
variables = { blockHeight: (0,
|
4157
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4373
4158
|
} else if (idOrHeight === "latest") {
|
4374
4159
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4375
4160
|
} else {
|
@@ -4381,11 +4166,11 @@ var _Provider = class {
|
|
4381
4166
|
}
|
4382
4167
|
return {
|
4383
4168
|
id: block.id,
|
4384
|
-
height: (0,
|
4169
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4385
4170
|
time: block.header.time,
|
4386
4171
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4387
4172
|
transactions: block.transactions.map(
|
4388
|
-
(tx) => new
|
4173
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4389
4174
|
)
|
4390
4175
|
};
|
4391
4176
|
}
|
@@ -4400,8 +4185,8 @@ var _Provider = class {
|
|
4400
4185
|
if (!transaction) {
|
4401
4186
|
return null;
|
4402
4187
|
}
|
4403
|
-
return new
|
4404
|
-
(0,
|
4188
|
+
return new import_transactions18.TransactionCoder().decode(
|
4189
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4405
4190
|
0
|
4406
4191
|
)?.[0];
|
4407
4192
|
}
|
@@ -4428,9 +4213,9 @@ var _Provider = class {
|
|
4428
4213
|
async getContractBalance(contractId, assetId) {
|
4429
4214
|
const { contractBalance } = await this.operations.getContractBalance({
|
4430
4215
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4431
|
-
asset: (0,
|
4216
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4432
4217
|
});
|
4433
|
-
return (0,
|
4218
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4434
4219
|
}
|
4435
4220
|
/**
|
4436
4221
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4442,9 +4227,9 @@ var _Provider = class {
|
|
4442
4227
|
async getBalance(owner, assetId) {
|
4443
4228
|
const { balance } = await this.operations.getBalance({
|
4444
4229
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4445
|
-
assetId: (0,
|
4230
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4446
4231
|
});
|
4447
|
-
return (0,
|
4232
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4448
4233
|
}
|
4449
4234
|
/**
|
4450
4235
|
* Returns balances for the given owner.
|
@@ -4462,7 +4247,7 @@ var _Provider = class {
|
|
4462
4247
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4463
4248
|
return balances.map((balance) => ({
|
4464
4249
|
assetId: balance.assetId,
|
4465
|
-
amount: (0,
|
4250
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4466
4251
|
}));
|
4467
4252
|
}
|
4468
4253
|
/**
|
@@ -4480,19 +4265,19 @@ var _Provider = class {
|
|
4480
4265
|
});
|
4481
4266
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4482
4267
|
return messages.map((message) => ({
|
4483
|
-
messageId:
|
4268
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4484
4269
|
sender: message.sender,
|
4485
4270
|
recipient: message.recipient,
|
4486
4271
|
nonce: message.nonce,
|
4487
|
-
amount: (0,
|
4272
|
+
amount: (0, import_math15.bn)(message.amount),
|
4488
4273
|
data: message.data
|
4489
4274
|
}),
|
4490
4275
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4491
4276
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4492
4277
|
nonce: message.nonce,
|
4493
|
-
amount: (0,
|
4494
|
-
data:
|
4495
|
-
daHeight: (0,
|
4278
|
+
amount: (0, import_math15.bn)(message.amount),
|
4279
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4280
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4496
4281
|
}));
|
4497
4282
|
}
|
4498
4283
|
/**
|
@@ -4545,52 +4330,44 @@ var _Provider = class {
|
|
4545
4330
|
} = result.messageProof;
|
4546
4331
|
return {
|
4547
4332
|
messageProof: {
|
4548
|
-
proofIndex: (0,
|
4333
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4549
4334
|
proofSet: messageProof.proofSet
|
4550
4335
|
},
|
4551
4336
|
blockProof: {
|
4552
|
-
proofIndex: (0,
|
4337
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4553
4338
|
proofSet: blockProof.proofSet
|
4554
4339
|
},
|
4555
4340
|
messageBlockHeader: {
|
4556
4341
|
id: messageBlockHeader.id,
|
4557
|
-
daHeight: (0,
|
4558
|
-
transactionsCount: (0,
|
4342
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4343
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4559
4344
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4560
|
-
height: (0,
|
4345
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4561
4346
|
prevRoot: messageBlockHeader.prevRoot,
|
4562
4347
|
time: messageBlockHeader.time,
|
4563
4348
|
applicationHash: messageBlockHeader.applicationHash,
|
4564
|
-
|
4349
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4350
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4565
4351
|
},
|
4566
4352
|
commitBlockHeader: {
|
4567
4353
|
id: commitBlockHeader.id,
|
4568
|
-
daHeight: (0,
|
4569
|
-
transactionsCount: (0,
|
4354
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4355
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4570
4356
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4571
|
-
height: (0,
|
4357
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4572
4358
|
prevRoot: commitBlockHeader.prevRoot,
|
4573
4359
|
time: commitBlockHeader.time,
|
4574
4360
|
applicationHash: commitBlockHeader.applicationHash,
|
4575
|
-
|
4361
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4362
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4576
4363
|
},
|
4577
4364
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4578
4365
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4579
4366
|
nonce,
|
4580
|
-
amount: (0,
|
4367
|
+
amount: (0, import_math15.bn)(amount),
|
4581
4368
|
data
|
4582
4369
|
};
|
4583
4370
|
}
|
4584
|
-
async getLatestGasPrice() {
|
4585
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4586
|
-
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4587
|
-
}
|
4588
|
-
async estimateGasPrice(blockHorizon) {
|
4589
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4590
|
-
blockHorizon: String(blockHorizon)
|
4591
|
-
});
|
4592
|
-
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4593
|
-
}
|
4594
4371
|
/**
|
4595
4372
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4596
4373
|
*
|
@@ -4610,10 +4387,10 @@ var _Provider = class {
|
|
4610
4387
|
*/
|
4611
4388
|
async produceBlocks(amount, startTime) {
|
4612
4389
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4613
|
-
blocksToProduce: (0,
|
4614
|
-
startTimestamp: startTime ?
|
4390
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4391
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4615
4392
|
});
|
4616
|
-
return (0,
|
4393
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4617
4394
|
}
|
4618
4395
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4619
4396
|
async getTransactionResponse(transactionId) {
|
@@ -4627,7 +4404,7 @@ cacheInputs_fn = function(inputs) {
|
|
4627
4404
|
return;
|
4628
4405
|
}
|
4629
4406
|
inputs.forEach((input) => {
|
4630
|
-
if (input.type ===
|
4407
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4631
4408
|
this.cache?.set(input.id);
|
4632
4409
|
}
|
4633
4410
|
});
|
@@ -4637,9 +4414,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4637
4414
|
|
4638
4415
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4639
4416
|
var import_errors15 = require("@fuel-ts/errors");
|
4640
|
-
var
|
4641
|
-
var
|
4642
|
-
var
|
4417
|
+
var import_math16 = require("@fuel-ts/math");
|
4418
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4419
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4643
4420
|
|
4644
4421
|
// src/providers/chains.ts
|
4645
4422
|
var CHAIN_IDS = {
|
@@ -4688,17 +4465,17 @@ var assets = [
|
|
4688
4465
|
|
4689
4466
|
// src/utils/formatTransferToContractScriptData.ts
|
4690
4467
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4691
|
-
var
|
4692
|
-
var
|
4468
|
+
var import_math17 = require("@fuel-ts/math");
|
4469
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4693
4470
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4694
4471
|
var formatTransferToContractScriptData = (params) => {
|
4695
4472
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4696
4473
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4697
|
-
const encoded = numberCoder.encode(new
|
4474
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4698
4475
|
const scriptData = Uint8Array.from([
|
4699
|
-
...(0,
|
4476
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4700
4477
|
...encoded,
|
4701
|
-
...(0,
|
4478
|
+
...(0, import_utils27.arrayify)(assetId)
|
4702
4479
|
]);
|
4703
4480
|
return scriptData;
|
4704
4481
|
};
|
@@ -4845,8 +4622,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4845
4622
|
* @param assetId - The asset ID to check the balance for.
|
4846
4623
|
* @returns A promise that resolves to the balance amount.
|
4847
4624
|
*/
|
4848
|
-
async getBalance(assetId
|
4849
|
-
const
|
4625
|
+
async getBalance(assetId) {
|
4626
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4627
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4850
4628
|
return amount;
|
4851
4629
|
}
|
4852
4630
|
/**
|
@@ -4883,33 +4661,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4883
4661
|
* @param fee - The estimated transaction fee.
|
4884
4662
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4885
4663
|
*/
|
4886
|
-
async fund(request,
|
4887
|
-
const
|
4888
|
-
const
|
4889
|
-
|
4890
|
-
|
4891
|
-
|
4892
|
-
coinQuantities: requiredQuantities
|
4664
|
+
async fund(request, coinQuantities, fee) {
|
4665
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4666
|
+
const updatedQuantities = addAmountToAsset({
|
4667
|
+
amount: (0, import_math18.bn)(fee),
|
4668
|
+
assetId: baseAssetId,
|
4669
|
+
coinQuantities
|
4893
4670
|
});
|
4894
4671
|
const quantitiesDict = {};
|
4895
|
-
|
4672
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4896
4673
|
quantitiesDict[assetId] = {
|
4897
4674
|
required: amount,
|
4898
|
-
owned: (0,
|
4675
|
+
owned: (0, import_math18.bn)(0)
|
4899
4676
|
};
|
4900
4677
|
});
|
4901
|
-
|
4678
|
+
const cachedUtxos = [];
|
4679
|
+
const cachedMessages = [];
|
4680
|
+
const owner = this.address.toB256();
|
4681
|
+
request.inputs.forEach((input) => {
|
4902
4682
|
const isResource = "amount" in input;
|
4903
4683
|
if (isResource) {
|
4904
4684
|
const isCoin2 = "owner" in input;
|
4905
4685
|
if (isCoin2) {
|
4906
4686
|
const assetId = String(input.assetId);
|
4907
|
-
if (quantitiesDict[assetId]) {
|
4908
|
-
const amount = (0,
|
4687
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4688
|
+
const amount = (0, import_math18.bn)(input.amount);
|
4909
4689
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4690
|
+
cachedUtxos.push(input.id);
|
4910
4691
|
}
|
4911
|
-
} else if (input.amount && quantitiesDict[
|
4912
|
-
quantitiesDict[
|
4692
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4693
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4694
|
+
cachedMessages.push(input.nonce);
|
4913
4695
|
}
|
4914
4696
|
}
|
4915
4697
|
});
|
@@ -4924,23 +4706,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4924
4706
|
});
|
4925
4707
|
const needsToBeFunded = missingQuantities.length;
|
4926
4708
|
if (needsToBeFunded) {
|
4927
|
-
const
|
4928
|
-
|
4929
|
-
|
4930
|
-
|
4931
|
-
|
4932
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4933
|
-
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
4934
|
-
if (addedSignatures) {
|
4935
|
-
Array.from({ length: addedSignatures }).forEach(
|
4936
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
4937
|
-
);
|
4709
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4710
|
+
messages: cachedMessages,
|
4711
|
+
utxos: cachedUtxos
|
4712
|
+
});
|
4713
|
+
request.addResources(resources);
|
4938
4714
|
}
|
4939
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4940
|
-
transactionRequest: requestToBeReEstimate
|
4941
|
-
});
|
4942
|
-
txRequest.maxFee = maxFee;
|
4943
|
-
return txRequest;
|
4944
4715
|
}
|
4945
4716
|
/**
|
4946
4717
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4948,25 +4719,30 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4948
4719
|
* @param destination - The address of the destination.
|
4949
4720
|
* @param amount - The amount of coins to transfer.
|
4950
4721
|
* @param assetId - The asset ID of the coins to transfer.
|
4951
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4722
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4952
4723
|
* @returns A promise that resolves to the prepared transaction request.
|
4953
4724
|
*/
|
4954
|
-
async createTransfer(destination, amount, assetId
|
4955
|
-
const
|
4956
|
-
|
4957
|
-
const
|
4725
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4726
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4727
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4728
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4729
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4730
|
+
const request = new ScriptTransactionRequest(params);
|
4731
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4732
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4958
4733
|
estimateTxDependencies: true,
|
4959
4734
|
resourcesOwner: this
|
4960
4735
|
});
|
4961
|
-
|
4962
|
-
|
4963
|
-
|
4964
|
-
|
4965
|
-
|
4966
|
-
|
4967
|
-
|
4968
|
-
|
4969
|
-
await this.fund(request,
|
4736
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
4737
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
4738
|
+
this.validateGas({
|
4739
|
+
gasUsed,
|
4740
|
+
gasPrice: request.gasPrice,
|
4741
|
+
gasLimit: request.gasLimit,
|
4742
|
+
minGasPrice
|
4743
|
+
});
|
4744
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4745
|
+
request.updatePredicateInputs(estimatedInputs);
|
4970
4746
|
return request;
|
4971
4747
|
}
|
4972
4748
|
/**
|
@@ -4978,14 +4754,15 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4978
4754
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4979
4755
|
* @returns A promise that resolves to the transaction response.
|
4980
4756
|
*/
|
4981
|
-
async transfer(destination, amount, assetId
|
4982
|
-
if ((0,
|
4757
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4758
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
4983
4759
|
throw new import_errors16.FuelError(
|
4984
4760
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4985
4761
|
"Transfer amount must be a positive number."
|
4986
4762
|
);
|
4987
4763
|
}
|
4988
|
-
const
|
4764
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4765
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
4989
4766
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4990
4767
|
}
|
4991
4768
|
/**
|
@@ -4997,38 +4774,41 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4997
4774
|
* @param txParams - The optional transaction parameters.
|
4998
4775
|
* @returns A promise that resolves to the transaction response.
|
4999
4776
|
*/
|
5000
|
-
async transferToContract(contractId, amount, assetId
|
5001
|
-
if ((0,
|
4777
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4778
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5002
4779
|
throw new import_errors16.FuelError(
|
5003
4780
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5004
4781
|
"Transfer amount must be a positive number."
|
5005
4782
|
);
|
5006
4783
|
}
|
5007
4784
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4785
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4786
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4787
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4788
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5008
4789
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5009
4790
|
hexlifiedContractId: contractAddress.toB256(),
|
5010
|
-
amountToTransfer: (0,
|
5011
|
-
assetId
|
4791
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
4792
|
+
assetId: assetIdToTransfer
|
5012
4793
|
});
|
5013
4794
|
const request = new ScriptTransactionRequest({
|
5014
|
-
...
|
4795
|
+
...params,
|
5015
4796
|
script,
|
5016
4797
|
scriptData
|
5017
4798
|
});
|
5018
4799
|
request.addContractInputAndOutput(contractAddress);
|
5019
|
-
const
|
5020
|
-
|
5021
|
-
|
4800
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4801
|
+
request,
|
4802
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
|
4803
|
+
);
|
4804
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4805
|
+
this.validateGas({
|
4806
|
+
gasUsed,
|
4807
|
+
gasPrice: request.gasPrice,
|
4808
|
+
gasLimit: request.gasLimit,
|
4809
|
+
minGasPrice
|
5022
4810
|
});
|
5023
|
-
|
5024
|
-
this.validateGas({
|
5025
|
-
gasUsed: txCost.gasUsed,
|
5026
|
-
gasLimit: request.gasLimit
|
5027
|
-
});
|
5028
|
-
}
|
5029
|
-
request.gasLimit = txCost.gasUsed;
|
5030
|
-
request.maxFee = txCost.maxFee;
|
5031
|
-
await this.fund(request, txCost);
|
4811
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5032
4812
|
return this.sendTransaction(request);
|
5033
4813
|
}
|
5034
4814
|
/**
|
@@ -5040,31 +4820,40 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5040
4820
|
* @returns A promise that resolves to the transaction response.
|
5041
4821
|
*/
|
5042
4822
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4823
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4824
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5043
4825
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5044
|
-
const recipientDataArray = (0,
|
4826
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5045
4827
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5046
4828
|
);
|
5047
|
-
const amountDataArray = (0,
|
5048
|
-
"0x".concat((0,
|
4829
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
4830
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5049
4831
|
);
|
5050
4832
|
const script = new Uint8Array([
|
5051
|
-
...(0,
|
4833
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5052
4834
|
...recipientDataArray,
|
5053
4835
|
...amountDataArray
|
5054
4836
|
]);
|
5055
|
-
const params = {
|
4837
|
+
const params = {
|
4838
|
+
script,
|
4839
|
+
gasPrice: minGasPrice,
|
4840
|
+
baseAssetId,
|
4841
|
+
...txParams
|
4842
|
+
};
|
5056
4843
|
const request = new ScriptTransactionRequest(params);
|
5057
|
-
const
|
5058
|
-
const
|
5059
|
-
|
5060
|
-
|
5061
|
-
|
5062
|
-
|
5063
|
-
|
5064
|
-
|
5065
|
-
|
5066
|
-
|
5067
|
-
|
4844
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: baseAssetId }];
|
4845
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4846
|
+
request,
|
4847
|
+
forwardingQuantities
|
4848
|
+
);
|
4849
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4850
|
+
this.validateGas({
|
4851
|
+
gasUsed,
|
4852
|
+
gasPrice: request.gasPrice,
|
4853
|
+
gasLimit: request.gasLimit,
|
4854
|
+
minGasPrice
|
4855
|
+
});
|
4856
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5068
4857
|
return this.sendTransaction(request);
|
5069
4858
|
}
|
5070
4859
|
async signMessage(message) {
|
@@ -5122,7 +4911,18 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5122
4911
|
}
|
5123
4912
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5124
4913
|
}
|
5125
|
-
validateGas({
|
4914
|
+
validateGas({
|
4915
|
+
gasUsed,
|
4916
|
+
gasPrice,
|
4917
|
+
gasLimit,
|
4918
|
+
minGasPrice
|
4919
|
+
}) {
|
4920
|
+
if (minGasPrice.gt(gasPrice)) {
|
4921
|
+
throw new import_errors16.FuelError(
|
4922
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4923
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4924
|
+
);
|
4925
|
+
}
|
5126
4926
|
if (gasUsed.gt(gasLimit)) {
|
5127
4927
|
throw new import_errors16.FuelError(
|
5128
4928
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5136,8 +4936,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5136
4936
|
var import_address5 = require("@fuel-ts/address");
|
5137
4937
|
var import_crypto = require("@fuel-ts/crypto");
|
5138
4938
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5139
|
-
var
|
5140
|
-
var
|
4939
|
+
var import_math19 = require("@fuel-ts/math");
|
4940
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5141
4941
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5142
4942
|
var Signer = class {
|
5143
4943
|
address;
|
@@ -5156,10 +4956,10 @@ var Signer = class {
|
|
5156
4956
|
privateKey = `0x${privateKey}`;
|
5157
4957
|
}
|
5158
4958
|
}
|
5159
|
-
const privateKeyBytes = (0,
|
5160
|
-
this.privateKey = (0,
|
5161
|
-
this.publicKey = (0,
|
5162
|
-
this.compressedPublicKey = (0,
|
4959
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
4960
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
4961
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4962
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5163
4963
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5164
4964
|
}
|
5165
4965
|
/**
|
@@ -5173,11 +4973,11 @@ var Signer = class {
|
|
5173
4973
|
* @returns hashed signature
|
5174
4974
|
*/
|
5175
4975
|
sign(data) {
|
5176
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5177
|
-
const r = (0,
|
5178
|
-
const s = (0,
|
4976
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
4977
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
4978
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5179
4979
|
s[0] |= (signature.recovery || 0) << 7;
|
5180
|
-
return (0,
|
4980
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5181
4981
|
}
|
5182
4982
|
/**
|
5183
4983
|
* Add point on the current elliptic curve
|
@@ -5186,8 +4986,8 @@ var Signer = class {
|
|
5186
4986
|
* @returns compressed point on the curve
|
5187
4987
|
*/
|
5188
4988
|
addPoint(point) {
|
5189
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5190
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4989
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
4990
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5191
4991
|
const result = p0.add(p1);
|
5192
4992
|
return `0x${result.toHex(true)}`;
|
5193
4993
|
}
|
@@ -5199,16 +4999,16 @@ var Signer = class {
|
|
5199
4999
|
* @returns public key from signature from the
|
5200
5000
|
*/
|
5201
5001
|
static recoverPublicKey(data, signature) {
|
5202
|
-
const signedMessageBytes = (0,
|
5002
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5203
5003
|
const r = signedMessageBytes.slice(0, 32);
|
5204
5004
|
const s = signedMessageBytes.slice(32, 64);
|
5205
5005
|
const recoveryParam = (s[0] & 128) >> 7;
|
5206
5006
|
s[0] &= 127;
|
5207
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5007
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5208
5008
|
recoveryParam
|
5209
5009
|
);
|
5210
|
-
const publicKey = sig.recoverPublicKey((0,
|
5211
|
-
return (0,
|
5010
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5011
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5212
5012
|
}
|
5213
5013
|
/**
|
5214
5014
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5227,7 +5027,7 @@ var Signer = class {
|
|
5227
5027
|
* @returns random 32-byte hashed
|
5228
5028
|
*/
|
5229
5029
|
static generatePrivateKey(entropy) {
|
5230
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5030
|
+
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);
|
5231
5031
|
}
|
5232
5032
|
/**
|
5233
5033
|
* Extended publicKey from a compact publicKey
|
@@ -5236,8 +5036,8 @@ var Signer = class {
|
|
5236
5036
|
* @returns extended publicKey
|
5237
5037
|
*/
|
5238
5038
|
static extendPublicKey(publicKey) {
|
5239
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5240
|
-
return (0,
|
5039
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5040
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5241
5041
|
}
|
5242
5042
|
};
|
5243
5043
|
|
@@ -5245,7 +5045,7 @@ var Signer = class {
|
|
5245
5045
|
var import_address6 = require("@fuel-ts/address");
|
5246
5046
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5247
5047
|
var import_errors17 = require("@fuel-ts/errors");
|
5248
|
-
var
|
5048
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5249
5049
|
var import_uuid = require("uuid");
|
5250
5050
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5251
5051
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5328,7 +5128,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5328
5128
|
);
|
5329
5129
|
}
|
5330
5130
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5331
|
-
const privateKey = (0,
|
5131
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5332
5132
|
return privateKey;
|
5333
5133
|
}
|
5334
5134
|
|
@@ -5373,7 +5173,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5373
5173
|
*/
|
5374
5174
|
async signMessage(message) {
|
5375
5175
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5376
|
-
return (0,
|
5176
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5377
5177
|
}
|
5378
5178
|
/**
|
5379
5179
|
* Signs a transaction with the wallet's private key.
|
@@ -5386,7 +5186,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5386
5186
|
const chainId = this.provider.getChainId();
|
5387
5187
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5388
5188
|
const signature = await this.signer().sign(hashedTransaction);
|
5389
|
-
return (0,
|
5189
|
+
return (0, import_utils31.hexlify)(signature);
|
5390
5190
|
}
|
5391
5191
|
/**
|
5392
5192
|
* Populates a transaction with the witnesses signature.
|
@@ -5406,7 +5206,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5406
5206
|
* @param transactionRequestLike - The transaction request to send.
|
5407
5207
|
* @returns A promise that resolves to the TransactionResponse object.
|
5408
5208
|
*/
|
5409
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5209
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5410
5210
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5411
5211
|
if (estimateTxDependencies) {
|
5412
5212
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5447,16 +5247,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5447
5247
|
// src/hdwallet/hdwallet.ts
|
5448
5248
|
var import_errors20 = require("@fuel-ts/errors");
|
5449
5249
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5450
|
-
var
|
5451
|
-
var
|
5452
|
-
var
|
5250
|
+
var import_math20 = require("@fuel-ts/math");
|
5251
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5252
|
+
var import_ethers3 = require("ethers");
|
5453
5253
|
|
5454
5254
|
// src/mnemonic/mnemonic.ts
|
5455
5255
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5456
5256
|
var import_errors19 = require("@fuel-ts/errors");
|
5457
5257
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5458
|
-
var
|
5459
|
-
var
|
5258
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5259
|
+
var import_ethers2 = require("ethers");
|
5460
5260
|
|
5461
5261
|
// src/wordlists/words/english.ts
|
5462
5262
|
var english = [
|
@@ -7513,7 +7313,7 @@ var english = [
|
|
7513
7313
|
// src/mnemonic/utils.ts
|
7514
7314
|
var import_errors18 = require("@fuel-ts/errors");
|
7515
7315
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7516
|
-
var
|
7316
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7517
7317
|
function toUtf8Bytes(stri) {
|
7518
7318
|
const str = stri.normalize("NFKD");
|
7519
7319
|
const result = [];
|
@@ -7580,14 +7380,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7580
7380
|
}
|
7581
7381
|
}
|
7582
7382
|
const checksumBits = entropy.length / 4;
|
7583
|
-
const checksum = (0,
|
7383
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7584
7384
|
indices[indices.length - 1] <<= checksumBits;
|
7585
7385
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7586
7386
|
return indices;
|
7587
7387
|
}
|
7588
7388
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7589
7389
|
const size = Math.ceil(11 * words.length / 8);
|
7590
|
-
const entropy = (0,
|
7390
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7591
7391
|
let offset = 0;
|
7592
7392
|
for (let i = 0; i < words.length; i += 1) {
|
7593
7393
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7607,7 +7407,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7607
7407
|
const entropyBits = 32 * words.length / 3;
|
7608
7408
|
const checksumBits = words.length / 3;
|
7609
7409
|
const checksumMask = getUpperMask(checksumBits);
|
7610
|
-
const checksum = (0,
|
7410
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7611
7411
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7612
7412
|
throw new import_errors18.FuelError(
|
7613
7413
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7682,7 +7482,7 @@ var Mnemonic = class {
|
|
7682
7482
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7683
7483
|
const words = getWords(phrase);
|
7684
7484
|
assertMnemonic(words);
|
7685
|
-
return (0,
|
7485
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7686
7486
|
}
|
7687
7487
|
/**
|
7688
7488
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7690,7 +7490,7 @@ var Mnemonic = class {
|
|
7690
7490
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7691
7491
|
*/
|
7692
7492
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7693
|
-
const entropyBytes = (0,
|
7493
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7694
7494
|
assertWordList(wordlist);
|
7695
7495
|
assertEntropy(entropyBytes);
|
7696
7496
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7704,7 +7504,7 @@ var Mnemonic = class {
|
|
7704
7504
|
assertMnemonic(getWords(phrase));
|
7705
7505
|
const phraseBytes = toUtf8Bytes(getPhrase(phrase));
|
7706
7506
|
const salt = toUtf8Bytes(`mnemonic${passphrase}`);
|
7707
|
-
return (0,
|
7507
|
+
return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
7708
7508
|
}
|
7709
7509
|
/**
|
7710
7510
|
* @param phrase - Mnemonic phrase composed by words from the provided wordlist
|
@@ -7759,14 +7559,14 @@ var Mnemonic = class {
|
|
7759
7559
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7760
7560
|
*/
|
7761
7561
|
static masterKeysFromSeed(seed) {
|
7762
|
-
const seedArray = (0,
|
7562
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7763
7563
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7764
7564
|
throw new import_errors19.FuelError(
|
7765
7565
|
import_errors19.ErrorCode.INVALID_SEED,
|
7766
7566
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7767
7567
|
);
|
7768
7568
|
}
|
7769
|
-
return (0,
|
7569
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7770
7570
|
}
|
7771
7571
|
/**
|
7772
7572
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7777,22 +7577,22 @@ var Mnemonic = class {
|
|
7777
7577
|
*/
|
7778
7578
|
static seedToExtendedKey(seed, testnet = false) {
|
7779
7579
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7780
|
-
const prefix = (0,
|
7580
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7781
7581
|
const depth = "0x00";
|
7782
7582
|
const fingerprint = "0x00000000";
|
7783
7583
|
const index = "0x00000000";
|
7784
7584
|
const chainCode = masterKey.slice(32);
|
7785
7585
|
const privateKey = masterKey.slice(0, 32);
|
7786
|
-
const extendedKey = (0,
|
7586
|
+
const extendedKey = (0, import_utils33.concat)([
|
7787
7587
|
prefix,
|
7788
7588
|
depth,
|
7789
7589
|
fingerprint,
|
7790
7590
|
index,
|
7791
7591
|
chainCode,
|
7792
|
-
(0,
|
7592
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
7793
7593
|
]);
|
7794
|
-
const checksum = (0,
|
7795
|
-
return (0,
|
7594
|
+
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7595
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
7796
7596
|
}
|
7797
7597
|
/**
|
7798
7598
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7807,7 +7607,7 @@ var Mnemonic = class {
|
|
7807
7607
|
* @returns A randomly generated mnemonic
|
7808
7608
|
*/
|
7809
7609
|
static generate(size = 32, extraEntropy = "") {
|
7810
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7610
|
+
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);
|
7811
7611
|
return Mnemonic.entropyToMnemonic(entropy);
|
7812
7612
|
}
|
7813
7613
|
};
|
@@ -7815,12 +7615,12 @@ var mnemonic_default = Mnemonic;
|
|
7815
7615
|
|
7816
7616
|
// src/hdwallet/hdwallet.ts
|
7817
7617
|
var HARDENED_INDEX = 2147483648;
|
7818
|
-
var MainnetPRV2 = (0,
|
7819
|
-
var MainnetPUB = (0,
|
7820
|
-
var TestnetPRV2 = (0,
|
7821
|
-
var TestnetPUB = (0,
|
7618
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
7619
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
7620
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
7621
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
7822
7622
|
function base58check(data) {
|
7823
|
-
return (0,
|
7623
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7824
7624
|
}
|
7825
7625
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7826
7626
|
if (isPublic) {
|
@@ -7829,11 +7629,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7829
7629
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7830
7630
|
}
|
7831
7631
|
function isPublicExtendedKey(extendedKey) {
|
7832
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7632
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
7833
7633
|
}
|
7834
7634
|
function isValidExtendedKey(extendedKey) {
|
7835
7635
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7836
|
-
(0,
|
7636
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
7837
7637
|
);
|
7838
7638
|
}
|
7839
7639
|
function parsePath(path2, depth = 0) {
|
@@ -7851,8 +7651,8 @@ function parsePath(path2, depth = 0) {
|
|
7851
7651
|
var HDWallet = class {
|
7852
7652
|
depth = 0;
|
7853
7653
|
index = 0;
|
7854
|
-
fingerprint = (0,
|
7855
|
-
parentFingerprint = (0,
|
7654
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7655
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7856
7656
|
privateKey;
|
7857
7657
|
publicKey;
|
7858
7658
|
chainCode;
|
@@ -7864,8 +7664,8 @@ var HDWallet = class {
|
|
7864
7664
|
constructor(config) {
|
7865
7665
|
if (config.privateKey) {
|
7866
7666
|
const signer = new Signer(config.privateKey);
|
7867
|
-
this.publicKey = (0,
|
7868
|
-
this.privateKey = (0,
|
7667
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
7668
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
7869
7669
|
} else {
|
7870
7670
|
if (!config.publicKey) {
|
7871
7671
|
throw new import_errors20.FuelError(
|
@@ -7873,10 +7673,10 @@ var HDWallet = class {
|
|
7873
7673
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7874
7674
|
);
|
7875
7675
|
}
|
7876
|
-
this.publicKey = (0,
|
7676
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
7877
7677
|
}
|
7878
7678
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7879
|
-
this.fingerprint = (0,
|
7679
|
+
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
7880
7680
|
this.depth = config.depth || this.depth;
|
7881
7681
|
this.index = config.index || this.index;
|
7882
7682
|
this.chainCode = config.chainCode;
|
@@ -7892,9 +7692,9 @@ var HDWallet = class {
|
|
7892
7692
|
* @returns A new instance of HDWallet on the derived index
|
7893
7693
|
*/
|
7894
7694
|
deriveIndex(index) {
|
7895
|
-
const privateKey = this.privateKey && (0,
|
7896
|
-
const publicKey = (0,
|
7897
|
-
const chainCode = (0,
|
7695
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
7696
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
7697
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
7898
7698
|
const data = new Uint8Array(37);
|
7899
7699
|
if (index & HARDENED_INDEX) {
|
7900
7700
|
if (!privateKey) {
|
@@ -7905,15 +7705,15 @@ var HDWallet = class {
|
|
7905
7705
|
}
|
7906
7706
|
data.set(privateKey, 1);
|
7907
7707
|
} else {
|
7908
|
-
data.set((0,
|
7708
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
7909
7709
|
}
|
7910
|
-
data.set((0,
|
7911
|
-
const bytes = (0,
|
7710
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
7711
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7912
7712
|
const IL = bytes.slice(0, 32);
|
7913
7713
|
const IR = bytes.slice(32);
|
7914
7714
|
if (privateKey) {
|
7915
7715
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7916
|
-
const ki = (0,
|
7716
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7917
7717
|
return new HDWallet({
|
7918
7718
|
privateKey: ki,
|
7919
7719
|
chainCode: IR,
|
@@ -7922,7 +7722,7 @@ var HDWallet = class {
|
|
7922
7722
|
parentFingerprint: this.fingerprint
|
7923
7723
|
});
|
7924
7724
|
}
|
7925
|
-
const signer = new Signer((0,
|
7725
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
7926
7726
|
const Ki = signer.addPoint(publicKey);
|
7927
7727
|
return new HDWallet({
|
7928
7728
|
publicKey: Ki,
|
@@ -7957,12 +7757,12 @@ var HDWallet = class {
|
|
7957
7757
|
);
|
7958
7758
|
}
|
7959
7759
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7960
|
-
const depth = (0,
|
7760
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
7961
7761
|
const parentFingerprint = this.parentFingerprint;
|
7962
|
-
const index = (0,
|
7762
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
7963
7763
|
const chainCode = this.chainCode;
|
7964
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7965
|
-
const extendedKey = (0,
|
7764
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7765
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7966
7766
|
return base58check(extendedKey);
|
7967
7767
|
}
|
7968
7768
|
/**
|
@@ -7974,13 +7774,13 @@ var HDWallet = class {
|
|
7974
7774
|
static fromSeed(seed) {
|
7975
7775
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7976
7776
|
return new HDWallet({
|
7977
|
-
chainCode: (0,
|
7978
|
-
privateKey: (0,
|
7777
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
7778
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
7979
7779
|
});
|
7980
7780
|
}
|
7981
7781
|
static fromExtendedKey(extendedKey) {
|
7982
|
-
const decoded = (0,
|
7983
|
-
const bytes = (0,
|
7782
|
+
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
7783
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
7984
7784
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7985
7785
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7986
7786
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -7989,9 +7789,9 @@ var HDWallet = class {
|
|
7989
7789
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7990
7790
|
}
|
7991
7791
|
const depth = bytes[4];
|
7992
|
-
const parentFingerprint = (0,
|
7993
|
-
const index = parseInt((0,
|
7994
|
-
const chainCode = (0,
|
7792
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
7793
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7794
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
7995
7795
|
const key = bytes.slice(45, 78);
|
7996
7796
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7997
7797
|
throw new import_errors20.FuelError(
|
@@ -8184,15 +7984,16 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8184
7984
|
process.env.GENESIS_SECRET || (0, import_crypto4.randomBytes)(32),
|
8185
7985
|
wallet.provider
|
8186
7986
|
);
|
8187
|
-
const
|
8188
|
-
|
8189
|
-
|
8190
|
-
|
7987
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
7988
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
7989
|
+
const baseAssetId = genesisWallet.provider.getBaseAssetId();
|
7990
|
+
const request = new ScriptTransactionRequest({
|
7991
|
+
baseAssetId,
|
7992
|
+
gasLimit: 1e4,
|
7993
|
+
gasPrice: minGasPrice
|
8191
7994
|
});
|
8192
|
-
|
8193
|
-
request.
|
8194
|
-
request.maxFee = txCost.maxFee;
|
8195
|
-
await genesisWallet.fund(request, txCost);
|
7995
|
+
request.addResources(resources);
|
7996
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8196
7997
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8197
7998
|
};
|
8198
7999
|
|
@@ -8206,12 +8007,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8206
8007
|
};
|
8207
8008
|
|
8208
8009
|
// src/test-utils/launchNode.ts
|
8209
|
-
var
|
8210
|
-
var
|
8010
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
8011
|
+
var import_math21 = require("@fuel-ts/math");
|
8012
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8211
8013
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8212
8014
|
var import_child_process = require("child_process");
|
8213
8015
|
var import_crypto5 = require("crypto");
|
8214
|
-
var import_ethers5 = require("ethers");
|
8215
8016
|
var import_fs = require("fs");
|
8216
8017
|
var import_os = __toESM(require("os"));
|
8217
8018
|
var import_path = __toESM(require("path"));
|
@@ -8260,13 +8061,13 @@ var launchNode = async ({
|
|
8260
8061
|
// eslint-disable-next-line no-async-promise-executor
|
8261
8062
|
new Promise(async (resolve, reject) => {
|
8262
8063
|
const remainingArgs = extractRemainingArgs(args, [
|
8263
|
-
"--
|
8064
|
+
"--chain",
|
8264
8065
|
"--consensus-key",
|
8265
8066
|
"--db-type",
|
8266
8067
|
"--poa-instant"
|
8267
8068
|
]);
|
8268
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8269
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8069
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8070
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
8270
8071
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8271
8072
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8272
8073
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8284,54 +8085,36 @@ var launchNode = async ({
|
|
8284
8085
|
let chainConfigPathToUse;
|
8285
8086
|
const prefix = basePath || import_os.default.tmpdir();
|
8286
8087
|
const suffix = basePath ? "" : (0, import_crypto5.randomUUID)();
|
8287
|
-
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix
|
8088
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8288
8089
|
if (chainConfigPath) {
|
8289
8090
|
chainConfigPathToUse = chainConfigPath;
|
8290
8091
|
} else {
|
8291
8092
|
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8292
8093
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8293
8094
|
}
|
8294
|
-
|
8295
|
-
|
8296
|
-
stateConfigJson = {
|
8297
|
-
...stateConfigJson,
|
8298
|
-
coins: [
|
8299
|
-
...stateConfigJson.coins.map((coin) => ({
|
8300
|
-
...coin,
|
8301
|
-
amount: "18446744073709551615"
|
8302
|
-
}))
|
8303
|
-
],
|
8304
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8305
|
-
...message,
|
8306
|
-
amount: "18446744073709551615"
|
8307
|
-
}))
|
8308
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8309
|
-
};
|
8095
|
+
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8096
|
+
let chainConfig = import_utils36.defaultChainConfig;
|
8310
8097
|
if (!process.env.GENESIS_SECRET) {
|
8311
8098
|
const pk = Signer.generatePrivateKey();
|
8312
8099
|
const signer = new Signer(pk);
|
8313
|
-
process.env.GENESIS_SECRET = (0,
|
8314
|
-
|
8315
|
-
|
8316
|
-
|
8317
|
-
|
8318
|
-
|
8319
|
-
|
8320
|
-
|
8321
|
-
|
8322
|
-
|
8323
|
-
|
8100
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8101
|
+
chainConfig = {
|
8102
|
+
...import_utils36.defaultChainConfig,
|
8103
|
+
initial_state: {
|
8104
|
+
...import_utils36.defaultChainConfig.initial_state,
|
8105
|
+
coins: [
|
8106
|
+
...import_utils36.defaultChainConfig.initial_state.coins,
|
8107
|
+
{
|
8108
|
+
owner: signer.address.toHexString(),
|
8109
|
+
amount: (0, import_math21.toHex)(1e9),
|
8110
|
+
asset_id: import_utils36.defaultChainConfig?.consensus_parameters?.base_asset_id ?? import_configs11.ZeroBytes32
|
8111
|
+
}
|
8112
|
+
]
|
8113
|
+
}
|
8114
|
+
};
|
8324
8115
|
}
|
8325
|
-
|
8326
|
-
|
8327
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8328
|
-
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8329
|
-
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8330
|
-
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8331
|
-
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8332
|
-
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8333
|
-
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8334
|
-
chainConfigPathToUse = tempDirPath;
|
8116
|
+
(0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8117
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8335
8118
|
}
|
8336
8119
|
const child = (0, import_child_process.spawn)(
|
8337
8120
|
command,
|
@@ -8340,10 +8123,10 @@ var launchNode = async ({
|
|
8340
8123
|
["--ip", ipToUse],
|
8341
8124
|
["--port", portToUse],
|
8342
8125
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8343
|
-
["--min-gas-price", "
|
8126
|
+
["--min-gas-price", "0"],
|
8344
8127
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8345
8128
|
["--consensus-key", consensusKey],
|
8346
|
-
["--
|
8129
|
+
["--chain", chainConfigPathToUse],
|
8347
8130
|
"--vm-backtrace",
|
8348
8131
|
"--utxo-validation",
|
8349
8132
|
"--debug",
|
@@ -8390,9 +8173,10 @@ var launchNode = async ({
|
|
8390
8173
|
})
|
8391
8174
|
);
|
8392
8175
|
var generateWallets = async (count, provider) => {
|
8176
|
+
const baseAssetId = provider.getBaseAssetId();
|
8393
8177
|
const wallets = [];
|
8394
8178
|
for (let i = 0; i < count; i += 1) {
|
8395
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8179
|
+
const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
|
8396
8180
|
wallets.push(wallet);
|
8397
8181
|
}
|
8398
8182
|
return wallets;
|
@@ -8402,7 +8186,7 @@ var launchNodeAndGetWallets = async ({
|
|
8402
8186
|
walletCount = 10
|
8403
8187
|
} = {}) => {
|
8404
8188
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8405
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8189
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8406
8190
|
const wallets = await generateWallets(walletCount, provider);
|
8407
8191
|
const cleanup = () => {
|
8408
8192
|
closeNode();
|