@fuel-ts/account 0.0.0-rc-2021-20240415193305 → 0.0.0-rc-1976-20240416161016
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 +600 -829
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +600 -835
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +443 -677
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +2 -10
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +329 -911
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +3 -3
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +2 -4
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -7
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +34 -37
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +29 -9
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +0 -3
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -2
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +2 -3
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +2 -8
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
- package/dist/test-utils.global.js +1114 -1578
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +599 -813
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +455 -669
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +22 -27
package/dist/test-utils.js
CHANGED
@@ -58,19 +58,16 @@ 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) => {
|
@@ -79,11 +76,11 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
79
76
|
let max2;
|
80
77
|
if (Array.isArray(coinQuantityLike)) {
|
81
78
|
amount = coinQuantityLike[0];
|
82
|
-
assetId = coinQuantityLike[1]
|
83
|
-
max2 = coinQuantityLike[2]
|
79
|
+
assetId = coinQuantityLike[1];
|
80
|
+
max2 = coinQuantityLike[2];
|
84
81
|
} else {
|
85
82
|
amount = coinQuantityLike.amount;
|
86
|
-
assetId = coinQuantityLike.assetId
|
83
|
+
assetId = coinQuantityLike.assetId;
|
87
84
|
max2 = coinQuantityLike.max ?? void 0;
|
88
85
|
}
|
89
86
|
const bnAmount = (0, import_math.bn)(amount);
|
@@ -93,7 +90,7 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
93
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,11 +105,11 @@ 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
|
112
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
116
113
|
var import_ethers = require("ethers");
|
117
114
|
var import_graphql_request = require("graphql-request");
|
118
115
|
var import_ramda3 = require("ramda");
|
@@ -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
|
}
|
@@ -299,32 +257,26 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
299
257
|
messageBlockHeader {
|
300
258
|
id
|
301
259
|
daHeight
|
302
|
-
consensusParametersVersion
|
303
|
-
stateTransitionBytecodeVersion
|
304
260
|
transactionsCount
|
305
|
-
messageReceiptCount
|
306
261
|
transactionsRoot
|
307
|
-
messageOutboxRoot
|
308
|
-
eventInboxRoot
|
309
262
|
height
|
310
263
|
prevRoot
|
311
264
|
time
|
312
265
|
applicationHash
|
266
|
+
messageReceiptRoot
|
267
|
+
messageReceiptCount
|
313
268
|
}
|
314
269
|
commitBlockHeader {
|
315
270
|
id
|
316
271
|
daHeight
|
317
|
-
consensusParametersVersion
|
318
|
-
stateTransitionBytecodeVersion
|
319
272
|
transactionsCount
|
320
|
-
messageReceiptCount
|
321
273
|
transactionsRoot
|
322
|
-
messageOutboxRoot
|
323
|
-
eventInboxRoot
|
324
274
|
height
|
325
275
|
prevRoot
|
326
276
|
time
|
327
277
|
applicationHash
|
278
|
+
messageReceiptRoot
|
279
|
+
messageReceiptCount
|
328
280
|
}
|
329
281
|
sender
|
330
282
|
recipient
|
@@ -343,8 +295,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
343
295
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
344
296
|
fragment blockFragment on Block {
|
345
297
|
id
|
346
|
-
height
|
347
298
|
header {
|
299
|
+
height
|
348
300
|
time
|
349
301
|
}
|
350
302
|
transactions {
|
@@ -402,11 +354,6 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
402
354
|
`;
|
403
355
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
404
356
|
fragment GasCostsFragment on GasCosts {
|
405
|
-
version {
|
406
|
-
... on Version {
|
407
|
-
value
|
408
|
-
}
|
409
|
-
}
|
410
357
|
add
|
411
358
|
addi
|
412
359
|
aloc
|
@@ -419,6 +366,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
419
366
|
cb
|
420
367
|
cfei
|
421
368
|
cfsi
|
369
|
+
croo
|
422
370
|
div
|
423
371
|
divi
|
424
372
|
ecr1
|
@@ -501,9 +449,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
501
449
|
ccp {
|
502
450
|
...DependentCostFragment
|
503
451
|
}
|
504
|
-
croo {
|
505
|
-
...DependentCostFragment
|
506
|
-
}
|
507
452
|
csiz {
|
508
453
|
...DependentCostFragment
|
509
454
|
}
|
@@ -563,11 +508,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
563
508
|
${DependentCostFragmentFragmentDoc}`;
|
564
509
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
565
510
|
fragment consensusParametersFragment on ConsensusParameters {
|
566
|
-
version {
|
567
|
-
... on Version {
|
568
|
-
value
|
569
|
-
}
|
570
|
-
}
|
571
511
|
txParams {
|
572
512
|
...TxParametersFragment
|
573
513
|
}
|
@@ -627,9 +567,18 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
627
567
|
fragment nodeInfoFragment on NodeInfo {
|
628
568
|
utxoValidation
|
629
569
|
vmBacktrace
|
570
|
+
minGasPrice
|
630
571
|
maxTx
|
631
572
|
maxDepth
|
632
573
|
nodeVersion
|
574
|
+
peers {
|
575
|
+
id
|
576
|
+
addresses
|
577
|
+
clientVersion
|
578
|
+
blockHeight
|
579
|
+
lastHeartbeatMs
|
580
|
+
appScore
|
581
|
+
}
|
633
582
|
}
|
634
583
|
`;
|
635
584
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -664,9 +613,13 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
664
613
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
665
614
|
transaction(id: $transactionId) {
|
666
615
|
...transactionFragment
|
616
|
+
receipts {
|
617
|
+
...receiptFragment
|
618
|
+
}
|
667
619
|
}
|
668
620
|
}
|
669
|
-
${TransactionFragmentFragmentDoc}
|
621
|
+
${TransactionFragmentFragmentDoc}
|
622
|
+
${ReceiptFragmentFragmentDoc}`;
|
670
623
|
var GetTransactionsDocument = import_graphql_tag.default`
|
671
624
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
672
625
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -794,20 +747,6 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
794
747
|
}
|
795
748
|
}
|
796
749
|
${BalanceFragmentFragmentDoc}`;
|
797
|
-
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
798
|
-
query getLatestGasPrice {
|
799
|
-
latestGasPrice {
|
800
|
-
gasPrice
|
801
|
-
}
|
802
|
-
}
|
803
|
-
`;
|
804
|
-
var EstimateGasPriceDocument = import_graphql_tag.default`
|
805
|
-
query estimateGasPrice($blockHorizon: U32!) {
|
806
|
-
estimateGasPrice(blockHorizon: $blockHorizon) {
|
807
|
-
gasPrice
|
808
|
-
}
|
809
|
-
}
|
810
|
-
`;
|
811
750
|
var GetBalancesDocument = import_graphql_tag.default`
|
812
751
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
813
752
|
balances(
|
@@ -862,12 +801,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
862
801
|
}
|
863
802
|
`;
|
864
803
|
var DryRunDocument = import_graphql_tag.default`
|
865
|
-
mutation dryRun($
|
866
|
-
dryRun(
|
867
|
-
...
|
804
|
+
mutation dryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
|
805
|
+
dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
|
806
|
+
...receiptFragment
|
868
807
|
}
|
869
808
|
}
|
870
|
-
${
|
809
|
+
${ReceiptFragmentFragmentDoc}`;
|
871
810
|
var SubmitDocument = import_graphql_tag.default`
|
872
811
|
mutation submit($encodedTransaction: HexString!) {
|
873
812
|
submit(tx: $encodedTransaction) {
|
@@ -950,12 +889,6 @@ function getSdk(requester) {
|
|
950
889
|
getBalance(variables, options) {
|
951
890
|
return requester(GetBalanceDocument, variables, options);
|
952
891
|
},
|
953
|
-
getLatestGasPrice(variables, options) {
|
954
|
-
return requester(GetLatestGasPriceDocument, variables, options);
|
955
|
-
},
|
956
|
-
estimateGasPrice(variables, options) {
|
957
|
-
return requester(EstimateGasPriceDocument, variables, options);
|
958
|
-
},
|
959
892
|
getBalances(variables, options) {
|
960
893
|
return requester(GetBalancesDocument, variables, options);
|
961
894
|
},
|
@@ -1025,14 +958,11 @@ var _FuelGraphqlSubscriber = class {
|
|
1025
958
|
let data;
|
1026
959
|
let errors;
|
1027
960
|
try {
|
1028
|
-
|
1029
|
-
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
961
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
1030
962
|
} catch (e) {
|
1031
963
|
throw new import_errors.FuelError(
|
1032
964
|
import_errors.ErrorCode.STREAM_PARSING_ERROR,
|
1033
|
-
`Error while parsing stream data response: ${text}
|
1034
|
-
|
1035
|
-
Thrown error: ${e}`
|
965
|
+
`Error while parsing stream data response: ${text}`
|
1036
966
|
);
|
1037
967
|
}
|
1038
968
|
if (Array.isArray(errors)) {
|
@@ -1120,7 +1050,7 @@ var MemoryCache = class {
|
|
1120
1050
|
|
1121
1051
|
// src/providers/transaction-request/input.ts
|
1122
1052
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
1123
|
-
var
|
1053
|
+
var import_configs = require("@fuel-ts/address/configs");
|
1124
1054
|
var import_errors3 = require("@fuel-ts/errors");
|
1125
1055
|
var import_math2 = require("@fuel-ts/math");
|
1126
1056
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1143,9 +1073,10 @@ var inputify = (value) => {
|
|
1143
1073
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1144
1074
|
},
|
1145
1075
|
witnessIndex: value.witnessIndex,
|
1076
|
+
maturity: value.maturity ?? 0,
|
1146
1077
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1147
|
-
predicateLength:
|
1148
|
-
predicateDataLength:
|
1078
|
+
predicateLength: predicate.length,
|
1079
|
+
predicateDataLength: predicateData.length,
|
1149
1080
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1150
1081
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1151
1082
|
};
|
@@ -1153,10 +1084,10 @@ var inputify = (value) => {
|
|
1153
1084
|
case import_transactions.InputType.Contract: {
|
1154
1085
|
return {
|
1155
1086
|
type: import_transactions.InputType.Contract,
|
1156
|
-
txID:
|
1087
|
+
txID: import_configs.ZeroBytes32,
|
1157
1088
|
outputIndex: 0,
|
1158
|
-
balanceRoot:
|
1159
|
-
stateRoot:
|
1089
|
+
balanceRoot: import_configs.ZeroBytes32,
|
1090
|
+
stateRoot: import_configs.ZeroBytes32,
|
1160
1091
|
txPointer: {
|
1161
1092
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1162
1093
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1176,8 +1107,8 @@ var inputify = (value) => {
|
|
1176
1107
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1177
1108
|
witnessIndex: value.witnessIndex,
|
1178
1109
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1179
|
-
predicateLength:
|
1180
|
-
predicateDataLength:
|
1110
|
+
predicateLength: predicate.length,
|
1111
|
+
predicateDataLength: predicateData.length,
|
1181
1112
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1182
1113
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1183
1114
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1194,7 +1125,7 @@ var inputify = (value) => {
|
|
1194
1125
|
};
|
1195
1126
|
|
1196
1127
|
// src/providers/transaction-request/output.ts
|
1197
|
-
var
|
1128
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1198
1129
|
var import_errors4 = require("@fuel-ts/errors");
|
1199
1130
|
var import_math3 = require("@fuel-ts/math");
|
1200
1131
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1214,8 +1145,8 @@ var outputify = (value) => {
|
|
1214
1145
|
return {
|
1215
1146
|
type: import_transactions2.OutputType.Contract,
|
1216
1147
|
inputIndex: value.inputIndex,
|
1217
|
-
balanceRoot:
|
1218
|
-
stateRoot:
|
1148
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1149
|
+
stateRoot: import_configs2.ZeroBytes32
|
1219
1150
|
};
|
1220
1151
|
}
|
1221
1152
|
case import_transactions2.OutputType.Change: {
|
@@ -1229,9 +1160,9 @@ var outputify = (value) => {
|
|
1229
1160
|
case import_transactions2.OutputType.Variable: {
|
1230
1161
|
return {
|
1231
1162
|
type: import_transactions2.OutputType.Variable,
|
1232
|
-
to:
|
1163
|
+
to: import_configs2.ZeroBytes32,
|
1233
1164
|
amount: (0, import_math3.bn)(0),
|
1234
|
-
assetId:
|
1165
|
+
assetId: import_configs2.ZeroBytes32
|
1235
1166
|
};
|
1236
1167
|
}
|
1237
1168
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1253,7 +1184,7 @@ var outputify = (value) => {
|
|
1253
1184
|
// src/providers/transaction-request/transaction-request.ts
|
1254
1185
|
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
1255
1186
|
var import_address = require("@fuel-ts/address");
|
1256
|
-
var
|
1187
|
+
var import_configs6 = require("@fuel-ts/address/configs");
|
1257
1188
|
var import_crypto = require("@fuel-ts/crypto");
|
1258
1189
|
var import_math7 = require("@fuel-ts/math");
|
1259
1190
|
var import_transactions6 = require("@fuel-ts/transactions");
|
@@ -1263,13 +1194,13 @@ var import_utils9 = require("@fuel-ts/utils");
|
|
1263
1194
|
var isCoin = (resource) => "id" in resource;
|
1264
1195
|
|
1265
1196
|
// src/providers/utils/receipts.ts
|
1266
|
-
var
|
1197
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1267
1198
|
var import_errors5 = require("@fuel-ts/errors");
|
1268
1199
|
var import_math4 = require("@fuel-ts/math");
|
1269
1200
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1270
|
-
var
|
1201
|
+
var import_configs4 = require("@fuel-ts/transactions/configs");
|
1271
1202
|
var import_utils5 = require("@fuel-ts/utils");
|
1272
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1203
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs4.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1273
1204
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1274
1205
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1275
1206
|
(memo, receipt) => {
|
@@ -1286,15 +1217,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1286
1217
|
missingOutputContractIds: []
|
1287
1218
|
}
|
1288
1219
|
);
|
1289
|
-
var hexOrZero = (hex) => hex ||
|
1220
|
+
var hexOrZero = (hex) => hex || import_configs3.ZeroBytes32;
|
1290
1221
|
function assembleReceiptByType(receipt) {
|
1291
1222
|
const { receiptType } = receipt;
|
1292
1223
|
switch (receiptType) {
|
1293
1224
|
case "CALL" /* Call */: {
|
1294
1225
|
const callReceipt = {
|
1295
1226
|
type: import_transactions3.ReceiptType.Call,
|
1296
|
-
from: hexOrZero(receipt.id
|
1297
|
-
to: hexOrZero(receipt?.to),
|
1227
|
+
from: hexOrZero(receipt.contract?.id),
|
1228
|
+
to: hexOrZero(receipt?.to?.id),
|
1298
1229
|
amount: (0, import_math4.bn)(receipt.amount),
|
1299
1230
|
assetId: hexOrZero(receipt.assetId),
|
1300
1231
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1308,7 +1239,7 @@ function assembleReceiptByType(receipt) {
|
|
1308
1239
|
case "RETURN" /* Return */: {
|
1309
1240
|
const returnReceipt = {
|
1310
1241
|
type: import_transactions3.ReceiptType.Return,
|
1311
|
-
id: hexOrZero(receipt.id
|
1242
|
+
id: hexOrZero(receipt.contract?.id),
|
1312
1243
|
val: (0, import_math4.bn)(receipt.val),
|
1313
1244
|
pc: (0, import_math4.bn)(receipt.pc),
|
1314
1245
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1318,7 +1249,7 @@ function assembleReceiptByType(receipt) {
|
|
1318
1249
|
case "RETURN_DATA" /* ReturnData */: {
|
1319
1250
|
const returnDataReceipt = {
|
1320
1251
|
type: import_transactions3.ReceiptType.ReturnData,
|
1321
|
-
id: hexOrZero(receipt.id
|
1252
|
+
id: hexOrZero(receipt.contract?.id),
|
1322
1253
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1323
1254
|
len: (0, import_math4.bn)(receipt.len),
|
1324
1255
|
digest: hexOrZero(receipt.digest),
|
@@ -1330,7 +1261,7 @@ function assembleReceiptByType(receipt) {
|
|
1330
1261
|
case "PANIC" /* Panic */: {
|
1331
1262
|
const panicReceipt = {
|
1332
1263
|
type: import_transactions3.ReceiptType.Panic,
|
1333
|
-
id: hexOrZero(receipt.id),
|
1264
|
+
id: hexOrZero(receipt.contract?.id),
|
1334
1265
|
reason: (0, import_math4.bn)(receipt.reason),
|
1335
1266
|
pc: (0, import_math4.bn)(receipt.pc),
|
1336
1267
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1341,7 +1272,7 @@ function assembleReceiptByType(receipt) {
|
|
1341
1272
|
case "REVERT" /* Revert */: {
|
1342
1273
|
const revertReceipt = {
|
1343
1274
|
type: import_transactions3.ReceiptType.Revert,
|
1344
|
-
id: hexOrZero(receipt.id
|
1275
|
+
id: hexOrZero(receipt.contract?.id),
|
1345
1276
|
val: (0, import_math4.bn)(receipt.ra),
|
1346
1277
|
pc: (0, import_math4.bn)(receipt.pc),
|
1347
1278
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1351,7 +1282,7 @@ function assembleReceiptByType(receipt) {
|
|
1351
1282
|
case "LOG" /* Log */: {
|
1352
1283
|
const logReceipt = {
|
1353
1284
|
type: import_transactions3.ReceiptType.Log,
|
1354
|
-
id: hexOrZero(receipt.id
|
1285
|
+
id: hexOrZero(receipt.contract?.id),
|
1355
1286
|
val0: (0, import_math4.bn)(receipt.ra),
|
1356
1287
|
val1: (0, import_math4.bn)(receipt.rb),
|
1357
1288
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1364,7 +1295,7 @@ function assembleReceiptByType(receipt) {
|
|
1364
1295
|
case "LOG_DATA" /* LogData */: {
|
1365
1296
|
const logDataReceipt = {
|
1366
1297
|
type: import_transactions3.ReceiptType.LogData,
|
1367
|
-
id: hexOrZero(receipt.id
|
1298
|
+
id: hexOrZero(receipt.contract?.id),
|
1368
1299
|
val0: (0, import_math4.bn)(receipt.ra),
|
1369
1300
|
val1: (0, import_math4.bn)(receipt.rb),
|
1370
1301
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1378,8 +1309,8 @@ function assembleReceiptByType(receipt) {
|
|
1378
1309
|
case "TRANSFER" /* Transfer */: {
|
1379
1310
|
const transferReceipt = {
|
1380
1311
|
type: import_transactions3.ReceiptType.Transfer,
|
1381
|
-
from: hexOrZero(receipt.id
|
1382
|
-
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1312
|
+
from: hexOrZero(receipt.contract?.id),
|
1313
|
+
to: hexOrZero(receipt.toAddress || receipt?.to?.id),
|
1383
1314
|
amount: (0, import_math4.bn)(receipt.amount),
|
1384
1315
|
assetId: hexOrZero(receipt.assetId),
|
1385
1316
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1390,8 +1321,8 @@ function assembleReceiptByType(receipt) {
|
|
1390
1321
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1391
1322
|
const transferOutReceipt = {
|
1392
1323
|
type: import_transactions3.ReceiptType.TransferOut,
|
1393
|
-
from: hexOrZero(receipt.id
|
1394
|
-
to: hexOrZero(receipt.toAddress || receipt.to),
|
1324
|
+
from: hexOrZero(receipt.contract?.id),
|
1325
|
+
to: hexOrZero(receipt.toAddress || receipt.to?.id),
|
1395
1326
|
amount: (0, import_math4.bn)(receipt.amount),
|
1396
1327
|
assetId: hexOrZero(receipt.assetId),
|
1397
1328
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1434,7 +1365,7 @@ function assembleReceiptByType(receipt) {
|
|
1434
1365
|
return receiptMessageOut;
|
1435
1366
|
}
|
1436
1367
|
case "MINT" /* Mint */: {
|
1437
|
-
const contractId = hexOrZero(receipt.id
|
1368
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1438
1369
|
const subId = hexOrZero(receipt.subId);
|
1439
1370
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1440
1371
|
const mintReceipt = {
|
@@ -1449,7 +1380,7 @@ function assembleReceiptByType(receipt) {
|
|
1449
1380
|
return mintReceipt;
|
1450
1381
|
}
|
1451
1382
|
case "BURN" /* Burn */: {
|
1452
|
-
const contractId = hexOrZero(receipt.id
|
1383
|
+
const contractId = hexOrZero(receipt.contract?.id);
|
1453
1384
|
const subId = hexOrZero(receipt.subId);
|
1454
1385
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1455
1386
|
const burnReceipt = {
|
@@ -1475,6 +1406,7 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1475
1406
|
var import_math5 = require("@fuel-ts/math");
|
1476
1407
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1477
1408
|
var import_utils6 = require("@fuel-ts/utils");
|
1409
|
+
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1478
1410
|
var getGasUsedFromReceipts = (receipts) => {
|
1479
1411
|
const scriptResult = receipts.filter(
|
1480
1412
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1495,28 +1427,18 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1495
1427
|
}
|
1496
1428
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1497
1429
|
const witnessCache = [];
|
1498
|
-
const
|
1499
|
-
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1500
|
-
if (isCoinOrMessage) {
|
1501
|
-
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1502
|
-
return true;
|
1503
|
-
}
|
1504
|
-
if (!witnessCache.includes(input.witnessIndex)) {
|
1505
|
-
witnessCache.push(input.witnessIndex);
|
1506
|
-
return true;
|
1507
|
-
}
|
1508
|
-
}
|
1509
|
-
return false;
|
1510
|
-
});
|
1511
|
-
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1512
|
-
const totalGas = chargeableInputs.reduce((total, input) => {
|
1430
|
+
const totalGas = inputs.reduce((total, input) => {
|
1513
1431
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1514
1432
|
return total.add(
|
1515
|
-
|
1433
|
+
resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization).add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1516
1434
|
);
|
1517
1435
|
}
|
1518
|
-
|
1519
|
-
|
1436
|
+
if ("witnessIndex" in input && !witnessCache.includes(input.witnessIndex)) {
|
1437
|
+
witnessCache.push(input.witnessIndex);
|
1438
|
+
return total.add(gasCosts.ecr1);
|
1439
|
+
}
|
1440
|
+
return total;
|
1441
|
+
}, (0, import_math5.bn)());
|
1520
1442
|
return totalGas;
|
1521
1443
|
}
|
1522
1444
|
function getMinGas(params) {
|
@@ -1528,20 +1450,12 @@ function getMinGas(params) {
|
|
1528
1450
|
return minGas;
|
1529
1451
|
}
|
1530
1452
|
function getMaxGas(params) {
|
1531
|
-
const {
|
1532
|
-
gasPerByte,
|
1533
|
-
witnessesLength,
|
1534
|
-
witnessLimit,
|
1535
|
-
minGas,
|
1536
|
-
gasLimit = (0, import_math5.bn)(0),
|
1537
|
-
maxGasPerTx
|
1538
|
-
} = params;
|
1453
|
+
const { gasPerByte, witnessesLength, witnessLimit, minGas, gasLimit = (0, import_math5.bn)(0) } = params;
|
1539
1454
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1540
1455
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1541
1456
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1542
1457
|
}
|
1543
|
-
|
1544
|
-
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1458
|
+
return remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1545
1459
|
}
|
1546
1460
|
function calculateMetadataGasForTxCreate({
|
1547
1461
|
gasCosts,
|
@@ -1563,10 +1477,6 @@ function calculateMetadataGasForTxScript({
|
|
1563
1477
|
}) {
|
1564
1478
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1565
1479
|
}
|
1566
|
-
var calculateGasFee = (params) => {
|
1567
|
-
const { gas, gasPrice, priceFactor, tip } = params;
|
1568
|
-
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1569
|
-
};
|
1570
1480
|
|
1571
1481
|
// src/providers/utils/json.ts
|
1572
1482
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1612,16 +1522,16 @@ function sleep(time) {
|
|
1612
1522
|
var import_errors7 = require("@fuel-ts/errors");
|
1613
1523
|
var import_math6 = require("@fuel-ts/math");
|
1614
1524
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1615
|
-
var
|
1525
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1616
1526
|
var assemblePanicError = (status) => {
|
1617
1527
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1618
1528
|
const reason = status.reason;
|
1619
|
-
if (
|
1529
|
+
if (import_configs5.PANIC_REASONS.includes(status.reason)) {
|
1620
1530
|
errorMessage = `${errorMessage}
|
1621
1531
|
|
1622
1532
|
You can read more about this error at:
|
1623
1533
|
|
1624
|
-
${
|
1534
|
+
${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
|
1625
1535
|
}
|
1626
1536
|
return { errorMessage, reason };
|
1627
1537
|
};
|
@@ -1633,28 +1543,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1633
1543
|
if (revertReceipt) {
|
1634
1544
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1635
1545
|
switch (reasonHex) {
|
1636
|
-
case
|
1546
|
+
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
1637
1547
|
reason = "require";
|
1638
1548
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1639
1549
|
break;
|
1640
1550
|
}
|
1641
|
-
case
|
1551
|
+
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
1642
1552
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1643
1553
|
reason = "assert_eq";
|
1644
1554
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1645
1555
|
break;
|
1646
1556
|
}
|
1647
|
-
case
|
1557
|
+
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
1648
1558
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1649
1559
|
reason = "assert_ne";
|
1650
1560
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1651
1561
|
break;
|
1652
1562
|
}
|
1653
|
-
case
|
1563
|
+
case import_configs5.FAILED_ASSERT_SIGNAL:
|
1654
1564
|
reason = "assert";
|
1655
1565
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1656
1566
|
break;
|
1657
|
-
case
|
1567
|
+
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1658
1568
|
reason = "MissingOutputChange";
|
1659
1569
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1660
1570
|
break;
|
@@ -1703,7 +1613,7 @@ var witnessify = (value) => {
|
|
1703
1613
|
// src/providers/transaction-request/transaction-request.ts
|
1704
1614
|
var BaseTransactionRequest = class {
|
1705
1615
|
/** Gas price for transaction */
|
1706
|
-
|
1616
|
+
gasPrice;
|
1707
1617
|
/** Block until which tx cannot be included */
|
1708
1618
|
maturity;
|
1709
1619
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1716,34 +1626,38 @@ var BaseTransactionRequest = class {
|
|
1716
1626
|
outputs = [];
|
1717
1627
|
/** List of witnesses */
|
1718
1628
|
witnesses = [];
|
1629
|
+
/** Base asset ID - should be fetched from the chain */
|
1630
|
+
baseAssetId;
|
1719
1631
|
/**
|
1720
1632
|
* Constructor for initializing a base transaction request.
|
1721
1633
|
*
|
1722
1634
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1723
1635
|
*/
|
1724
1636
|
constructor({
|
1725
|
-
|
1637
|
+
gasPrice,
|
1726
1638
|
maturity,
|
1727
1639
|
maxFee,
|
1728
1640
|
witnessLimit,
|
1729
1641
|
inputs,
|
1730
1642
|
outputs,
|
1731
|
-
witnesses
|
1732
|
-
|
1733
|
-
|
1643
|
+
witnesses,
|
1644
|
+
baseAssetId
|
1645
|
+
}) {
|
1646
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1734
1647
|
this.maturity = maturity ?? 0;
|
1735
1648
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1736
1649
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1737
1650
|
this.inputs = inputs ?? [];
|
1738
1651
|
this.outputs = outputs ?? [];
|
1739
1652
|
this.witnesses = witnesses ?? [];
|
1653
|
+
this.baseAssetId = baseAssetId;
|
1740
1654
|
}
|
1741
1655
|
static getPolicyMeta(req) {
|
1742
1656
|
let policyTypes = 0;
|
1743
1657
|
const policies = [];
|
1744
|
-
if (req.
|
1745
|
-
policyTypes += import_transactions6.PolicyType.
|
1746
|
-
policies.push({ data: req.
|
1658
|
+
if (req.gasPrice) {
|
1659
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1660
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1747
1661
|
}
|
1748
1662
|
if (req.witnessLimit) {
|
1749
1663
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -1829,7 +1743,7 @@ var BaseTransactionRequest = class {
|
|
1829
1743
|
* @returns The index of the created witness.
|
1830
1744
|
*/
|
1831
1745
|
addEmptyWitness() {
|
1832
|
-
this.addWitness((0, import_utils9.concat)([
|
1746
|
+
this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
1833
1747
|
return this.witnesses.length - 1;
|
1834
1748
|
}
|
1835
1749
|
/**
|
@@ -1930,10 +1844,10 @@ var BaseTransactionRequest = class {
|
|
1930
1844
|
* @param predicate - Predicate bytes.
|
1931
1845
|
* @param predicateData - Predicate data bytes.
|
1932
1846
|
*/
|
1933
|
-
addCoinInput(coin) {
|
1847
|
+
addCoinInput(coin, predicate) {
|
1934
1848
|
const { assetId, owner, amount } = coin;
|
1935
1849
|
let witnessIndex;
|
1936
|
-
if (
|
1850
|
+
if (predicate) {
|
1937
1851
|
witnessIndex = 0;
|
1938
1852
|
} else {
|
1939
1853
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1948,7 +1862,8 @@ var BaseTransactionRequest = class {
|
|
1948
1862
|
amount,
|
1949
1863
|
assetId,
|
1950
1864
|
txPointer: "0x00000000000000000000000000000000",
|
1951
|
-
witnessIndex
|
1865
|
+
witnessIndex,
|
1866
|
+
predicate: predicate?.bytes
|
1952
1867
|
};
|
1953
1868
|
this.pushInput(input);
|
1954
1869
|
this.addChangeOutput(owner, assetId);
|
@@ -1959,13 +1874,11 @@ var BaseTransactionRequest = class {
|
|
1959
1874
|
*
|
1960
1875
|
* @param message - Message resource.
|
1961
1876
|
* @param predicate - Predicate bytes.
|
1962
|
-
* @param predicateData - Predicate data bytes.
|
1963
1877
|
*/
|
1964
|
-
addMessageInput(message) {
|
1878
|
+
addMessageInput(message, predicate) {
|
1965
1879
|
const { recipient, sender, amount } = message;
|
1966
|
-
const assetId = import_configs7.BaseAssetId;
|
1967
1880
|
let witnessIndex;
|
1968
|
-
if (
|
1881
|
+
if (predicate) {
|
1969
1882
|
witnessIndex = 0;
|
1970
1883
|
} else {
|
1971
1884
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1979,10 +1892,11 @@ var BaseTransactionRequest = class {
|
|
1979
1892
|
sender: sender.toB256(),
|
1980
1893
|
recipient: recipient.toB256(),
|
1981
1894
|
amount,
|
1982
|
-
witnessIndex
|
1895
|
+
witnessIndex,
|
1896
|
+
predicate: predicate?.bytes
|
1983
1897
|
};
|
1984
1898
|
this.pushInput(input);
|
1985
|
-
this.addChangeOutput(recipient,
|
1899
|
+
this.addChangeOutput(recipient, this.baseAssetId);
|
1986
1900
|
}
|
1987
1901
|
/**
|
1988
1902
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -2010,6 +1924,32 @@ var BaseTransactionRequest = class {
|
|
2010
1924
|
resources.forEach((resource) => this.addResource(resource));
|
2011
1925
|
return this;
|
2012
1926
|
}
|
1927
|
+
/**
|
1928
|
+
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1929
|
+
* outputs from the related assetIds.
|
1930
|
+
*
|
1931
|
+
* @param resources - The resources to add.
|
1932
|
+
* @returns This transaction.
|
1933
|
+
*/
|
1934
|
+
addPredicateResource(resource, predicate) {
|
1935
|
+
if (isCoin(resource)) {
|
1936
|
+
this.addCoinInput(resource, predicate);
|
1937
|
+
} else {
|
1938
|
+
this.addMessageInput(resource, predicate);
|
1939
|
+
}
|
1940
|
+
return this;
|
1941
|
+
}
|
1942
|
+
/**
|
1943
|
+
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1944
|
+
* from the related assetIds.
|
1945
|
+
*
|
1946
|
+
* @param resources - The resources to add.
|
1947
|
+
* @returns This transaction.
|
1948
|
+
*/
|
1949
|
+
addPredicateResources(resources, predicate) {
|
1950
|
+
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1951
|
+
return this;
|
1952
|
+
}
|
2013
1953
|
/**
|
2014
1954
|
* Adds a coin output to the transaction.
|
2015
1955
|
*
|
@@ -2017,12 +1957,12 @@ var BaseTransactionRequest = class {
|
|
2017
1957
|
* @param amount - Amount of coin.
|
2018
1958
|
* @param assetId - Asset ID of coin.
|
2019
1959
|
*/
|
2020
|
-
addCoinOutput(to, amount, assetId
|
1960
|
+
addCoinOutput(to, amount, assetId) {
|
2021
1961
|
this.pushOutput({
|
2022
1962
|
type: import_transactions6.OutputType.Coin,
|
2023
1963
|
to: (0, import_address.addressify)(to).toB256(),
|
2024
1964
|
amount,
|
2025
|
-
assetId
|
1965
|
+
assetId: assetId ?? this.baseAssetId
|
2026
1966
|
});
|
2027
1967
|
return this;
|
2028
1968
|
}
|
@@ -2049,7 +1989,7 @@ var BaseTransactionRequest = class {
|
|
2049
1989
|
* @param to - Address of the owner.
|
2050
1990
|
* @param assetId - Asset ID of coin.
|
2051
1991
|
*/
|
2052
|
-
addChangeOutput(to, assetId
|
1992
|
+
addChangeOutput(to, assetId) {
|
2053
1993
|
const changeOutput = this.getChangeOutputs().find(
|
2054
1994
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
2055
1995
|
);
|
@@ -2057,7 +1997,7 @@ var BaseTransactionRequest = class {
|
|
2057
1997
|
this.pushOutput({
|
2058
1998
|
type: import_transactions6.OutputType.Change,
|
2059
1999
|
to: (0, import_address.addressify)(to).toB256(),
|
2060
|
-
assetId
|
2000
|
+
assetId: assetId ?? this.baseAssetId
|
2061
2001
|
});
|
2062
2002
|
}
|
2063
2003
|
}
|
@@ -2089,7 +2029,7 @@ var BaseTransactionRequest = class {
|
|
2089
2029
|
}
|
2090
2030
|
calculateMaxGas(chainInfo, minGas) {
|
2091
2031
|
const { consensusParameters } = chainInfo;
|
2092
|
-
const { gasPerByte
|
2032
|
+
const { gasPerByte } = consensusParameters;
|
2093
2033
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2094
2034
|
(acc, wit) => acc + wit.dataLength,
|
2095
2035
|
0
|
@@ -2098,8 +2038,7 @@ var BaseTransactionRequest = class {
|
|
2098
2038
|
gasPerByte,
|
2099
2039
|
minGas,
|
2100
2040
|
witnessesLength,
|
2101
|
-
witnessLimit: this.witnessLimit
|
2102
|
-
maxGasPerTx
|
2041
|
+
witnessLimit: this.witnessLimit
|
2103
2042
|
});
|
2104
2043
|
}
|
2105
2044
|
/**
|
@@ -2117,27 +2056,24 @@ var BaseTransactionRequest = class {
|
|
2117
2056
|
});
|
2118
2057
|
const updateAssetInput = (assetId, quantity) => {
|
2119
2058
|
const assetInput = findAssetInput(assetId);
|
2120
|
-
let usedQuantity = quantity;
|
2121
|
-
if (assetId === import_configs7.BaseAssetId) {
|
2122
|
-
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2123
|
-
}
|
2124
2059
|
if (assetInput && "assetId" in assetInput) {
|
2125
2060
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2126
|
-
assetInput.amount =
|
2061
|
+
assetInput.amount = quantity;
|
2127
2062
|
} else {
|
2128
2063
|
this.addResources([
|
2129
2064
|
{
|
2130
2065
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2131
|
-
amount:
|
2066
|
+
amount: quantity,
|
2132
2067
|
assetId,
|
2133
2068
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2069
|
+
maturity: 0,
|
2134
2070
|
blockCreated: (0, import_math7.bn)(1),
|
2135
2071
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2136
2072
|
}
|
2137
2073
|
]);
|
2138
2074
|
}
|
2139
2075
|
};
|
2140
|
-
updateAssetInput(
|
2076
|
+
updateAssetInput(this.baseAssetId, (0, import_math7.bn)(1e11));
|
2141
2077
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2142
2078
|
}
|
2143
2079
|
/**
|
@@ -2162,7 +2098,7 @@ var BaseTransactionRequest = class {
|
|
2162
2098
|
toJSON() {
|
2163
2099
|
return normalizeJSON(this);
|
2164
2100
|
}
|
2165
|
-
|
2101
|
+
updatePredicateInputs(inputs) {
|
2166
2102
|
this.inputs.forEach((i) => {
|
2167
2103
|
let correspondingInput;
|
2168
2104
|
switch (i.type) {
|
@@ -2184,25 +2120,16 @@ var BaseTransactionRequest = class {
|
|
2184
2120
|
}
|
2185
2121
|
});
|
2186
2122
|
}
|
2187
|
-
shiftPredicateData() {
|
2188
|
-
this.inputs.forEach((input) => {
|
2189
|
-
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2190
|
-
input.predicateData = input.paddPredicateData(
|
2191
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2192
|
-
);
|
2193
|
-
}
|
2194
|
-
});
|
2195
|
-
}
|
2196
2123
|
};
|
2197
2124
|
|
2198
2125
|
// src/providers/transaction-request/create-transaction-request.ts
|
2199
|
-
var
|
2126
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2200
2127
|
var import_math9 = require("@fuel-ts/math");
|
2201
2128
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2202
2129
|
var import_utils13 = require("@fuel-ts/utils");
|
2203
2130
|
|
2204
2131
|
// src/providers/transaction-request/hash-transaction.ts
|
2205
|
-
var
|
2132
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
2206
2133
|
var import_hasher = require("@fuel-ts/hasher");
|
2207
2134
|
var import_math8 = require("@fuel-ts/math");
|
2208
2135
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2211,7 +2138,7 @@ var import_ramda2 = require("ramda");
|
|
2211
2138
|
function hashTransaction(transactionRequest, chainId) {
|
2212
2139
|
const transaction = transactionRequest.toTransaction();
|
2213
2140
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2214
|
-
transaction.receiptsRoot =
|
2141
|
+
transaction.receiptsRoot = import_configs7.ZeroBytes32;
|
2215
2142
|
}
|
2216
2143
|
transaction.inputs = transaction.inputs.map((input) => {
|
2217
2144
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2233,10 +2160,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2233
2160
|
blockHeight: 0,
|
2234
2161
|
txIndex: 0
|
2235
2162
|
};
|
2236
|
-
inputClone.txID =
|
2163
|
+
inputClone.txID = import_configs7.ZeroBytes32;
|
2237
2164
|
inputClone.outputIndex = 0;
|
2238
|
-
inputClone.balanceRoot =
|
2239
|
-
inputClone.stateRoot =
|
2165
|
+
inputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2166
|
+
inputClone.stateRoot = import_configs7.ZeroBytes32;
|
2240
2167
|
return inputClone;
|
2241
2168
|
}
|
2242
2169
|
default:
|
@@ -2247,8 +2174,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2247
2174
|
const outputClone = (0, import_ramda2.clone)(output);
|
2248
2175
|
switch (outputClone.type) {
|
2249
2176
|
case import_transactions7.OutputType.Contract: {
|
2250
|
-
outputClone.balanceRoot =
|
2251
|
-
outputClone.stateRoot =
|
2177
|
+
outputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2178
|
+
outputClone.stateRoot = import_configs7.ZeroBytes32;
|
2252
2179
|
return outputClone;
|
2253
2180
|
}
|
2254
2181
|
case import_transactions7.OutputType.Change: {
|
@@ -2256,9 +2183,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2256
2183
|
return outputClone;
|
2257
2184
|
}
|
2258
2185
|
case import_transactions7.OutputType.Variable: {
|
2259
|
-
outputClone.to =
|
2186
|
+
outputClone.to = import_configs7.ZeroBytes32;
|
2260
2187
|
outputClone.amount = (0, import_math8.bn)(0);
|
2261
|
-
outputClone.assetId =
|
2188
|
+
outputClone.assetId = import_configs7.ZeroBytes32;
|
2262
2189
|
return outputClone;
|
2263
2190
|
}
|
2264
2191
|
default:
|
@@ -2316,15 +2243,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2316
2243
|
*
|
2317
2244
|
* @param createTransactionRequestLike - The initial values for the instance
|
2318
2245
|
*/
|
2319
|
-
constructor({
|
2320
|
-
bytecodeWitnessIndex,
|
2321
|
-
salt,
|
2322
|
-
storageSlots,
|
2323
|
-
...rest
|
2324
|
-
} = {}) {
|
2246
|
+
constructor({ bytecodeWitnessIndex, salt, storageSlots, ...rest }) {
|
2325
2247
|
super(rest);
|
2326
2248
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2327
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2249
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
|
2328
2250
|
this.storageSlots = [...storageSlots ?? []];
|
2329
2251
|
}
|
2330
2252
|
/**
|
@@ -2339,9 +2261,10 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2339
2261
|
return {
|
2340
2262
|
type: import_transactions8.TransactionType.Create,
|
2341
2263
|
...baseTransaction,
|
2264
|
+
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2342
2265
|
bytecodeWitnessIndex,
|
2343
|
-
storageSlotsCount:
|
2344
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2266
|
+
storageSlotsCount: storageSlots.length,
|
2267
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
|
2345
2268
|
storageSlots
|
2346
2269
|
};
|
2347
2270
|
}
|
@@ -2391,7 +2314,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2391
2314
|
// src/providers/transaction-request/script-transaction-request.ts
|
2392
2315
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
2393
2316
|
var import_address2 = require("@fuel-ts/address");
|
2394
|
-
var
|
2317
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2395
2318
|
var import_math10 = require("@fuel-ts/math");
|
2396
2319
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2397
2320
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2444,7 +2367,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2444
2367
|
*
|
2445
2368
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2446
2369
|
*/
|
2447
|
-
constructor({ script, scriptData, gasLimit, ...rest }
|
2370
|
+
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2448
2371
|
super(rest);
|
2449
2372
|
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2450
2373
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
@@ -2463,9 +2386,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2463
2386
|
type: import_transactions9.TransactionType.Script,
|
2464
2387
|
scriptGasLimit: this.gasLimit,
|
2465
2388
|
...super.getBaseTransaction(),
|
2466
|
-
scriptLength:
|
2467
|
-
scriptDataLength:
|
2468
|
-
receiptsRoot:
|
2389
|
+
scriptLength: script.length,
|
2390
|
+
scriptDataLength: scriptData.length,
|
2391
|
+
receiptsRoot: import_configs9.ZeroBytes32,
|
2469
2392
|
script: (0, import_utils15.hexlify)(script),
|
2470
2393
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2471
2394
|
};
|
@@ -2528,7 +2451,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2528
2451
|
}
|
2529
2452
|
calculateMaxGas(chainInfo, minGas) {
|
2530
2453
|
const { consensusParameters } = chainInfo;
|
2531
|
-
const { gasPerByte
|
2454
|
+
const { gasPerByte } = consensusParameters;
|
2532
2455
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2533
2456
|
(acc, wit) => acc + wit.dataLength,
|
2534
2457
|
0
|
@@ -2538,8 +2461,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2538
2461
|
minGas,
|
2539
2462
|
witnessesLength,
|
2540
2463
|
witnessLimit: this.witnessLimit,
|
2541
|
-
gasLimit: this.gasLimit
|
2542
|
-
maxGasPerTx
|
2464
|
+
gasLimit: this.gasLimit
|
2543
2465
|
});
|
2544
2466
|
}
|
2545
2467
|
/**
|
@@ -2614,32 +2536,15 @@ var transactionRequestify = (obj) => {
|
|
2614
2536
|
}
|
2615
2537
|
}
|
2616
2538
|
};
|
2617
|
-
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2618
|
-
(acc, input) => {
|
2619
|
-
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2620
|
-
acc.utxos.push(input.id);
|
2621
|
-
}
|
2622
|
-
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2623
|
-
acc.messages.push(input.nonce);
|
2624
|
-
}
|
2625
|
-
return acc;
|
2626
|
-
},
|
2627
|
-
{
|
2628
|
-
utxos: [],
|
2629
|
-
messages: []
|
2630
|
-
}
|
2631
|
-
);
|
2632
2539
|
|
2633
2540
|
// src/providers/transaction-response/transaction-response.ts
|
2634
2541
|
var import_errors13 = require("@fuel-ts/errors");
|
2635
|
-
var
|
2636
|
-
var
|
2637
|
-
var
|
2542
|
+
var import_math14 = require("@fuel-ts/math");
|
2543
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2544
|
+
var import_utils21 = require("@fuel-ts/utils");
|
2638
2545
|
|
2639
2546
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2640
|
-
var
|
2641
|
-
var import_transactions16 = require("@fuel-ts/transactions");
|
2642
|
-
var import_utils18 = require("@fuel-ts/utils");
|
2547
|
+
var import_utils19 = require("@fuel-ts/utils");
|
2643
2548
|
|
2644
2549
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2645
2550
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2647,10 +2552,9 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2647
2552
|
var import_utils16 = require("@fuel-ts/utils");
|
2648
2553
|
var calculateTransactionFee = (params) => {
|
2649
2554
|
const {
|
2650
|
-
|
2555
|
+
gasUsed,
|
2651
2556
|
rawPayload,
|
2652
|
-
|
2653
|
-
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2557
|
+
consensusParameters: { gasCosts, feeParams }
|
2654
2558
|
} = params;
|
2655
2559
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2656
2560
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2660,7 +2564,8 @@ var calculateTransactionFee = (params) => {
|
|
2660
2564
|
return {
|
2661
2565
|
fee: (0, import_math11.bn)(0),
|
2662
2566
|
minFee: (0, import_math11.bn)(0),
|
2663
|
-
maxFee: (0, import_math11.bn)(0)
|
2567
|
+
maxFee: (0, import_math11.bn)(0),
|
2568
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2664
2569
|
};
|
2665
2570
|
}
|
2666
2571
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2692,6 +2597,7 @@ var calculateTransactionFee = (params) => {
|
|
2692
2597
|
metadataGas,
|
2693
2598
|
txBytesSize: transactionBytes.length
|
2694
2599
|
});
|
2600
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2695
2601
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2696
2602
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2697
2603
|
const maxGas = getMaxGas({
|
@@ -2699,30 +2605,22 @@ var calculateTransactionFee = (params) => {
|
|
2699
2605
|
minGas,
|
2700
2606
|
witnessesLength,
|
2701
2607
|
gasLimit,
|
2702
|
-
witnessLimit
|
2703
|
-
maxGasPerTx
|
2704
|
-
});
|
2705
|
-
const minFee = calculateGasFee({
|
2706
|
-
gasPrice,
|
2707
|
-
gas: minGas,
|
2708
|
-
priceFactor: gasPriceFactor,
|
2709
|
-
tip
|
2710
|
-
});
|
2711
|
-
const maxFee = calculateGasFee({
|
2712
|
-
gasPrice,
|
2713
|
-
gas: maxGas,
|
2714
|
-
priceFactor: gasPriceFactor,
|
2715
|
-
tip
|
2608
|
+
witnessLimit
|
2716
2609
|
});
|
2610
|
+
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2611
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2612
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2613
|
+
const fee = minFee.add(feeFromGasUsed);
|
2717
2614
|
return {
|
2615
|
+
fee,
|
2718
2616
|
minFee,
|
2719
2617
|
maxFee,
|
2720
|
-
|
2618
|
+
feeFromGasUsed
|
2721
2619
|
};
|
2722
2620
|
};
|
2723
2621
|
|
2724
2622
|
// src/providers/transaction-summary/operations.ts
|
2725
|
-
var
|
2623
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2726
2624
|
var import_errors11 = require("@fuel-ts/errors");
|
2727
2625
|
var import_math13 = require("@fuel-ts/math");
|
2728
2626
|
var import_transactions14 = require("@fuel-ts/transactions");
|
@@ -3020,7 +2918,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3020
2918
|
const { to: toAddress, assetId, amount } = receipt;
|
3021
2919
|
let { from: fromAddress } = receipt;
|
3022
2920
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3023
|
-
if (
|
2921
|
+
if (import_configs10.ZeroBytes32 === fromAddress) {
|
3024
2922
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3025
2923
|
fromAddress = change?.to || fromAddress;
|
3026
2924
|
}
|
@@ -3284,12 +3182,10 @@ function assembleTransactionSummary(params) {
|
|
3284
3182
|
gqlTransactionStatus,
|
3285
3183
|
abiMap = {},
|
3286
3184
|
maxInputs,
|
3287
|
-
gasCosts
|
3288
|
-
maxGasPerTx,
|
3289
|
-
gasPrice
|
3185
|
+
gasCosts
|
3290
3186
|
} = params;
|
3291
3187
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3292
|
-
const rawPayload = (0,
|
3188
|
+
const rawPayload = (0, import_utils19.hexlify)(transactionBytes);
|
3293
3189
|
const operations = getOperations({
|
3294
3190
|
transactionType: transaction.type,
|
3295
3191
|
inputs: transaction.inputs || [],
|
@@ -3300,14 +3196,11 @@ function assembleTransactionSummary(params) {
|
|
3300
3196
|
maxInputs
|
3301
3197
|
});
|
3302
3198
|
const typeName = getTransactionTypeName(transaction.type);
|
3303
|
-
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3304
3199
|
const { fee } = calculateTransactionFee({
|
3305
|
-
|
3200
|
+
gasUsed,
|
3306
3201
|
rawPayload,
|
3307
|
-
tip,
|
3308
3202
|
consensusParameters: {
|
3309
3203
|
gasCosts,
|
3310
|
-
maxGasPerTx,
|
3311
3204
|
feeParams: {
|
3312
3205
|
gasPerByte,
|
3313
3206
|
gasPriceFactor
|
@@ -3319,7 +3212,7 @@ function assembleTransactionSummary(params) {
|
|
3319
3212
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3320
3213
|
let date;
|
3321
3214
|
if (time) {
|
3322
|
-
date =
|
3215
|
+
date = import_utils19.DateTime.fromTai64(time);
|
3323
3216
|
}
|
3324
3217
|
const transactionSummary = {
|
3325
3218
|
id,
|
@@ -3347,12 +3240,12 @@ function assembleTransactionSummary(params) {
|
|
3347
3240
|
|
3348
3241
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3349
3242
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3350
|
-
var
|
3243
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3351
3244
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3352
3245
|
return receipts.reduce((logs, receipt) => {
|
3353
|
-
if (receipt.type ===
|
3246
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3354
3247
|
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3355
|
-
const data = receipt.type ===
|
3248
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3356
3249
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3357
3250
|
logs.push(decodedLog);
|
3358
3251
|
}
|
@@ -3367,7 +3260,7 @@ var TransactionResponse = class {
|
|
3367
3260
|
/** Current provider */
|
3368
3261
|
provider;
|
3369
3262
|
/** Gas used on the transaction */
|
3370
|
-
gasUsed = (0,
|
3263
|
+
gasUsed = (0, import_math14.bn)(0);
|
3371
3264
|
/** The graphql Transaction with receipts object. */
|
3372
3265
|
gqlTransaction;
|
3373
3266
|
abis;
|
@@ -3425,8 +3318,8 @@ var TransactionResponse = class {
|
|
3425
3318
|
* @returns The decoded transaction.
|
3426
3319
|
*/
|
3427
3320
|
decodeTransaction(transactionWithReceipts) {
|
3428
|
-
return new
|
3429
|
-
(0,
|
3321
|
+
return new import_transactions17.TransactionCoder().decode(
|
3322
|
+
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3430
3323
|
0
|
3431
3324
|
)?.[0];
|
3432
3325
|
}
|
@@ -3445,27 +3338,20 @@ var TransactionResponse = class {
|
|
3445
3338
|
const decodedTransaction = this.decodeTransaction(
|
3446
3339
|
transaction
|
3447
3340
|
);
|
3448
|
-
|
3449
|
-
|
3450
|
-
txReceipts = transaction.status.receipts;
|
3451
|
-
}
|
3452
|
-
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3453
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3454
|
-
const gasPrice = await this.provider.getLatestGasPrice();
|
3341
|
+
const receipts = transaction.receipts?.map(processGqlReceipt) || [];
|
3342
|
+
const { gasPerByte, gasPriceFactor, gasCosts } = this.provider.getGasConfig();
|
3455
3343
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3456
3344
|
const transactionSummary = assembleTransactionSummary({
|
3457
3345
|
id: this.id,
|
3458
3346
|
receipts,
|
3459
3347
|
transaction: decodedTransaction,
|
3460
|
-
transactionBytes: (0,
|
3348
|
+
transactionBytes: (0, import_utils21.arrayify)(transaction.rawPayload),
|
3461
3349
|
gqlTransactionStatus: transaction.status,
|
3462
3350
|
gasPerByte,
|
3463
3351
|
gasPriceFactor,
|
3464
3352
|
abiMap: contractsAbiMap,
|
3465
3353
|
maxInputs,
|
3466
|
-
gasCosts
|
3467
|
-
maxGasPerTx,
|
3468
|
-
gasPrice
|
3354
|
+
gasCosts
|
3469
3355
|
});
|
3470
3356
|
return transactionSummary;
|
3471
3357
|
}
|
@@ -3592,29 +3478,30 @@ var processGqlChain = (chain) => {
|
|
3592
3478
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3593
3479
|
return {
|
3594
3480
|
name,
|
3595
|
-
baseChainHeight: (0,
|
3481
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3596
3482
|
consensusParameters: {
|
3597
|
-
contractMaxSize: (0,
|
3598
|
-
maxInputs: (0,
|
3599
|
-
maxOutputs: (0,
|
3600
|
-
maxWitnesses: (0,
|
3601
|
-
maxGasPerTx: (0,
|
3602
|
-
maxScriptLength: (0,
|
3603
|
-
maxScriptDataLength: (0,
|
3604
|
-
maxStorageSlots: (0,
|
3605
|
-
maxPredicateLength: (0,
|
3606
|
-
maxPredicateDataLength: (0,
|
3607
|
-
maxGasPerPredicate: (0,
|
3608
|
-
gasPriceFactor: (0,
|
3609
|
-
gasPerByte: (0,
|
3610
|
-
maxMessageDataLength: (0,
|
3611
|
-
chainId: (0,
|
3483
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3484
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3485
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3486
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3487
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3488
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3489
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3490
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3491
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3492
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3493
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3494
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3495
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3496
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3497
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3498
|
+
baseAssetId: consensusParameters.baseAssetId,
|
3612
3499
|
gasCosts
|
3613
3500
|
},
|
3614
3501
|
gasCosts,
|
3615
3502
|
latestBlock: {
|
3616
3503
|
id: latestBlock.id,
|
3617
|
-
height: (0,
|
3504
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3618
3505
|
time: latestBlock.header.time,
|
3619
3506
|
transactions: latestBlock.transactions.map((i) => ({
|
3620
3507
|
id: i.id
|
@@ -3708,8 +3595,10 @@ var _Provider = class {
|
|
3708
3595
|
* Returns some helpful parameters related to gas fees.
|
3709
3596
|
*/
|
3710
3597
|
getGasConfig() {
|
3598
|
+
const { minGasPrice } = this.getNode();
|
3711
3599
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3712
3600
|
return {
|
3601
|
+
minGasPrice,
|
3713
3602
|
maxGasPerTx,
|
3714
3603
|
maxGasPerPredicate,
|
3715
3604
|
gasPriceFactor,
|
@@ -3807,7 +3696,7 @@ var _Provider = class {
|
|
3807
3696
|
*/
|
3808
3697
|
async getBlockNumber() {
|
3809
3698
|
const { chain } = await this.operations.getChain();
|
3810
|
-
return (0,
|
3699
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
3811
3700
|
}
|
3812
3701
|
/**
|
3813
3702
|
* Returns the chain information.
|
@@ -3817,11 +3706,13 @@ var _Provider = class {
|
|
3817
3706
|
async fetchNode() {
|
3818
3707
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3819
3708
|
const processedNodeInfo = {
|
3820
|
-
maxDepth: (0,
|
3821
|
-
maxTx: (0,
|
3709
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3710
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3711
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3822
3712
|
nodeVersion: nodeInfo.nodeVersion,
|
3823
3713
|
utxoValidation: nodeInfo.utxoValidation,
|
3824
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3714
|
+
vmBacktrace: nodeInfo.vmBacktrace,
|
3715
|
+
peers: nodeInfo.peers
|
3825
3716
|
};
|
3826
3717
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3827
3718
|
return processedNodeInfo;
|
@@ -3847,6 +3738,17 @@ var _Provider = class {
|
|
3847
3738
|
} = this.getChain();
|
3848
3739
|
return chainId.toNumber();
|
3849
3740
|
}
|
3741
|
+
/**
|
3742
|
+
* Returns the base asset ID
|
3743
|
+
*
|
3744
|
+
* @returns A promise that resolves to the base asset ID
|
3745
|
+
*/
|
3746
|
+
getBaseAssetId() {
|
3747
|
+
const {
|
3748
|
+
consensusParameters: { baseAssetId }
|
3749
|
+
} = this.getChain();
|
3750
|
+
return baseAssetId;
|
3751
|
+
}
|
3850
3752
|
/**
|
3851
3753
|
* Submits a transaction to the chain to be executed.
|
3852
3754
|
*
|
@@ -3863,9 +3765,9 @@ var _Provider = class {
|
|
3863
3765
|
if (estimateTxDependencies) {
|
3864
3766
|
await this.estimateTxDependencies(transactionRequest);
|
3865
3767
|
}
|
3866
|
-
const encodedTransaction = (0,
|
3768
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3867
3769
|
let abis;
|
3868
|
-
if (transactionRequest.type ===
|
3770
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3869
3771
|
abis = transactionRequest.abis;
|
3870
3772
|
}
|
3871
3773
|
if (awaitExecution) {
|
@@ -3906,14 +3808,15 @@ var _Provider = class {
|
|
3906
3808
|
if (estimateTxDependencies) {
|
3907
3809
|
return this.estimateTxDependencies(transactionRequest);
|
3908
3810
|
}
|
3909
|
-
const encodedTransaction = (0,
|
3910
|
-
const { dryRun:
|
3911
|
-
|
3811
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3812
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3813
|
+
encodedTransaction,
|
3912
3814
|
utxoValidation: utxoValidation || false
|
3913
3815
|
});
|
3914
|
-
const
|
3915
|
-
|
3916
|
-
|
3816
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3817
|
+
return {
|
3818
|
+
receipts
|
3819
|
+
};
|
3917
3820
|
}
|
3918
3821
|
/**
|
3919
3822
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3924,13 +3827,13 @@ var _Provider = class {
|
|
3924
3827
|
async estimatePredicates(transactionRequest) {
|
3925
3828
|
const shouldEstimatePredicates = Boolean(
|
3926
3829
|
transactionRequest.inputs.find(
|
3927
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3830
|
+
(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()
|
3928
3831
|
)
|
3929
3832
|
);
|
3930
3833
|
if (!shouldEstimatePredicates) {
|
3931
3834
|
return transactionRequest;
|
3932
3835
|
}
|
3933
|
-
const encodedTransaction = (0,
|
3836
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3934
3837
|
const response = await this.operations.estimatePredicates({
|
3935
3838
|
encodedTransaction
|
3936
3839
|
});
|
@@ -3939,7 +3842,7 @@ var _Provider = class {
|
|
3939
3842
|
} = response;
|
3940
3843
|
if (inputs) {
|
3941
3844
|
inputs.forEach((input, index) => {
|
3942
|
-
if ("predicateGasUsed" in input && (0,
|
3845
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
3943
3846
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3944
3847
|
}
|
3945
3848
|
});
|
@@ -3952,31 +3855,31 @@ var _Provider = class {
|
|
3952
3855
|
* If there are missing variable outputs,
|
3953
3856
|
* `addVariableOutputs` is called on the transaction.
|
3954
3857
|
*
|
3858
|
+
* @privateRemarks
|
3859
|
+
* TODO: Investigate support for missing contract IDs
|
3860
|
+
* TODO: Add support for missing output messages
|
3955
3861
|
*
|
3956
3862
|
* @param transactionRequest - The transaction request object.
|
3957
3863
|
* @returns A promise.
|
3958
3864
|
*/
|
3959
3865
|
async estimateTxDependencies(transactionRequest) {
|
3960
|
-
if (transactionRequest.type ===
|
3866
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
3961
3867
|
return {
|
3962
3868
|
receipts: [],
|
3963
3869
|
outputVariables: 0,
|
3964
3870
|
missingContractIds: []
|
3965
3871
|
};
|
3966
3872
|
}
|
3873
|
+
await this.estimatePredicates(transactionRequest);
|
3967
3874
|
let receipts = [];
|
3968
3875
|
const missingContractIds = [];
|
3969
3876
|
let outputVariables = 0;
|
3970
|
-
let dryrunStatus;
|
3971
3877
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3972
|
-
const {
|
3973
|
-
|
3974
|
-
} = await this.operations.dryRun({
|
3975
|
-
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3878
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3879
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
3976
3880
|
utxoValidation: false
|
3977
3881
|
});
|
3978
|
-
receipts =
|
3979
|
-
dryrunStatus = status;
|
3882
|
+
receipts = gqlReceipts.map(processGqlReceipt);
|
3980
3883
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3981
3884
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3982
3885
|
if (hasMissingOutputs) {
|
@@ -3986,10 +3889,6 @@ var _Provider = class {
|
|
3986
3889
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3987
3890
|
missingContractIds.push(contractId);
|
3988
3891
|
});
|
3989
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
3990
|
-
transactionRequest
|
3991
|
-
});
|
3992
|
-
transactionRequest.maxFee = maxFee;
|
3993
3892
|
} else {
|
3994
3893
|
break;
|
3995
3894
|
}
|
@@ -3997,139 +3896,37 @@ var _Provider = class {
|
|
3997
3896
|
return {
|
3998
3897
|
receipts,
|
3999
3898
|
outputVariables,
|
4000
|
-
missingContractIds
|
4001
|
-
dryrunStatus
|
3899
|
+
missingContractIds
|
4002
3900
|
};
|
4003
3901
|
}
|
4004
|
-
/**
|
4005
|
-
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4006
|
-
*
|
4007
|
-
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4008
|
-
* further modifications are identified. The method iteratively updates these transactions
|
4009
|
-
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4010
|
-
*
|
4011
|
-
* @param transactionRequests - Array of transaction request objects.
|
4012
|
-
* @returns A promise that resolves to an array of results for each transaction.
|
4013
|
-
*/
|
4014
|
-
async estimateMultipleTxDependencies(transactionRequests) {
|
4015
|
-
const results = transactionRequests.map(() => ({
|
4016
|
-
receipts: [],
|
4017
|
-
outputVariables: 0,
|
4018
|
-
missingContractIds: [],
|
4019
|
-
dryrunStatus: void 0
|
4020
|
-
}));
|
4021
|
-
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4022
|
-
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4023
|
-
allRequests.forEach((req, index) => {
|
4024
|
-
if (req.type === import_transactions19.TransactionType.Script) {
|
4025
|
-
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4026
|
-
}
|
4027
|
-
});
|
4028
|
-
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4029
|
-
let attempt = 0;
|
4030
|
-
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4031
|
-
const encodedTransactions = transactionsToProcess.map(
|
4032
|
-
(index) => serializedTransactionsMap.get(index)
|
4033
|
-
);
|
4034
|
-
const dryRunResults = await this.operations.dryRun({
|
4035
|
-
encodedTransactions,
|
4036
|
-
utxoValidation: false
|
4037
|
-
});
|
4038
|
-
const nextRoundTransactions = [];
|
4039
|
-
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4040
|
-
const currentResultIndex = transactionsToProcess[i];
|
4041
|
-
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4042
|
-
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4043
|
-
results[currentResultIndex].dryrunStatus = status;
|
4044
|
-
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4045
|
-
results[currentResultIndex].receipts
|
4046
|
-
);
|
4047
|
-
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4048
|
-
const requestToProcess = allRequests[currentResultIndex];
|
4049
|
-
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4050
|
-
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4051
|
-
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4052
|
-
missingOutputContractIds.forEach(({ contractId }) => {
|
4053
|
-
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4054
|
-
results[currentResultIndex].missingContractIds.push(contractId);
|
4055
|
-
});
|
4056
|
-
const { maxFee } = await this.estimateTxGasAndFee({
|
4057
|
-
transactionRequest: requestToProcess
|
4058
|
-
});
|
4059
|
-
requestToProcess.maxFee = maxFee;
|
4060
|
-
serializedTransactionsMap.set(
|
4061
|
-
currentResultIndex,
|
4062
|
-
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4063
|
-
);
|
4064
|
-
nextRoundTransactions.push(currentResultIndex);
|
4065
|
-
allRequests[currentResultIndex] = requestToProcess;
|
4066
|
-
}
|
4067
|
-
}
|
4068
|
-
transactionsToProcess = nextRoundTransactions;
|
4069
|
-
attempt += 1;
|
4070
|
-
}
|
4071
|
-
return results;
|
4072
|
-
}
|
4073
|
-
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4074
|
-
if (estimateTxDependencies) {
|
4075
|
-
return this.estimateMultipleTxDependencies(transactionRequests);
|
4076
|
-
}
|
4077
|
-
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4078
|
-
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4079
|
-
encodedTransactions,
|
4080
|
-
utxoValidation: utxoValidation || false
|
4081
|
-
});
|
4082
|
-
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4083
|
-
const receipts = rawReceipts.map(processGqlReceipt);
|
4084
|
-
return { receipts, dryrunStatus: status };
|
4085
|
-
});
|
4086
|
-
return results;
|
4087
|
-
}
|
4088
3902
|
/**
|
4089
3903
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
4090
3904
|
* @param transactionRequest - The transaction request object.
|
4091
3905
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
4092
3906
|
*/
|
4093
|
-
|
3907
|
+
estimateTxGasAndFee(params) {
|
4094
3908
|
const { transactionRequest } = params;
|
4095
|
-
|
3909
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4096
3910
|
const chainInfo = this.getChain();
|
4097
|
-
const
|
3911
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3912
|
+
transactionRequest.gasPrice = gasPrice;
|
4098
3913
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4099
|
-
|
4100
|
-
|
4101
|
-
}
|
4102
|
-
const minFee = calculateGasFee({
|
4103
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4104
|
-
gas: minGas,
|
4105
|
-
priceFactor: gasPriceFactor,
|
4106
|
-
tip: transactionRequest.tip
|
4107
|
-
}).add(1);
|
4108
|
-
let gasLimit = (0, import_math16.bn)(0);
|
4109
|
-
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4110
|
-
gasLimit = transactionRequest.gasLimit;
|
3914
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3915
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
4111
3916
|
if (transactionRequest.gasLimit.eq(0)) {
|
4112
3917
|
transactionRequest.gasLimit = minGas;
|
4113
3918
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
4114
3919
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
4115
3920
|
);
|
4116
|
-
gasLimit = transactionRequest.gasLimit;
|
4117
3921
|
}
|
4118
3922
|
}
|
4119
3923
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4120
|
-
const maxFee =
|
4121
|
-
gasPrice: (0, import_math16.bn)(gasPrice),
|
4122
|
-
gas: maxGas,
|
4123
|
-
priceFactor: gasPriceFactor,
|
4124
|
-
tip: transactionRequest.tip
|
4125
|
-
}).add(1);
|
3924
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
4126
3925
|
return {
|
4127
3926
|
minGas,
|
4128
3927
|
minFee,
|
4129
3928
|
maxGas,
|
4130
|
-
maxFee
|
4131
|
-
gasPrice,
|
4132
|
-
gasLimit
|
3929
|
+
maxFee
|
4133
3930
|
};
|
4134
3931
|
}
|
4135
3932
|
/**
|
@@ -4147,17 +3944,15 @@ var _Provider = class {
|
|
4147
3944
|
if (estimateTxDependencies) {
|
4148
3945
|
return this.estimateTxDependencies(transactionRequest);
|
4149
3946
|
}
|
4150
|
-
const
|
4151
|
-
const { dryRun:
|
4152
|
-
|
3947
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3948
|
+
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3949
|
+
encodedTransaction,
|
4153
3950
|
utxoValidation: true
|
4154
3951
|
});
|
4155
|
-
const
|
4156
|
-
|
4157
|
-
|
4158
|
-
|
4159
|
-
});
|
4160
|
-
return { receipts: callResult[0].receipts };
|
3952
|
+
const receipts = gqlReceipts.map(processGqlReceipt);
|
3953
|
+
return {
|
3954
|
+
receipts
|
3955
|
+
};
|
4161
3956
|
}
|
4162
3957
|
/**
|
4163
3958
|
* Returns a transaction cost to enable user
|
@@ -4174,79 +3969,77 @@ var _Provider = class {
|
|
4174
3969
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
4175
3970
|
* @returns A promise that resolves to the transaction cost object.
|
4176
3971
|
*/
|
4177
|
-
async getTransactionCost(transactionRequestLike,
|
3972
|
+
async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
|
3973
|
+
estimateTxDependencies = true,
|
3974
|
+
estimatePredicates = true,
|
3975
|
+
resourcesOwner,
|
3976
|
+
signatureCallback
|
3977
|
+
} = {}) {
|
4178
3978
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4179
|
-
const
|
3979
|
+
const { minGasPrice } = this.getGasConfig();
|
3980
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3981
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4180
3982
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4181
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
3983
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4182
3984
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4183
|
-
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4184
3985
|
if (isScriptTransaction) {
|
4185
|
-
txRequestClone.gasLimit = (0,
|
3986
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
4186
3987
|
}
|
4187
|
-
if (
|
4188
|
-
resourcesOwner
|
3988
|
+
if (estimatePredicates) {
|
3989
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3990
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3991
|
+
}
|
3992
|
+
await this.estimatePredicates(txRequestClone);
|
4189
3993
|
}
|
4190
|
-
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4191
|
-
let addedSignatures = 0;
|
4192
3994
|
if (signatureCallback && isScriptTransaction) {
|
4193
|
-
|
4194
|
-
await signatureCallback(signedRequest);
|
4195
|
-
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3995
|
+
await signatureCallback(txRequestClone);
|
4196
3996
|
}
|
4197
|
-
|
4198
|
-
|
4199
|
-
transactionRequest: signedRequest
|
3997
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3998
|
+
transactionRequest: txRequestClone
|
4200
3999
|
});
|
4201
4000
|
let receipts = [];
|
4202
4001
|
let missingContractIds = [];
|
4203
4002
|
let outputVariables = 0;
|
4204
|
-
let gasUsed = (0,
|
4205
|
-
|
4206
|
-
|
4207
|
-
if (isScriptTransaction) {
|
4208
|
-
txRequestClone.gasLimit = gasLimit;
|
4209
|
-
if (signatureCallback) {
|
4210
|
-
await signatureCallback(txRequestClone);
|
4211
|
-
}
|
4003
|
+
let gasUsed = (0, import_math15.bn)(0);
|
4004
|
+
if (isScriptTransaction && estimateTxDependencies) {
|
4005
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
4212
4006
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4213
4007
|
receipts = result.receipts;
|
4214
4008
|
outputVariables = result.outputVariables;
|
4215
4009
|
missingContractIds = result.missingContractIds;
|
4216
4010
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4217
4011
|
txRequestClone.gasLimit = gasUsed;
|
4218
|
-
|
4219
|
-
|
4220
|
-
|
4012
|
+
txRequestClone.gasPrice = setGasPrice;
|
4013
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4014
|
+
transactionRequest: txRequestClone
|
4221
4015
|
}));
|
4222
4016
|
}
|
4223
4017
|
return {
|
4224
4018
|
requiredQuantities: allQuantities,
|
4225
4019
|
receipts,
|
4226
4020
|
gasUsed,
|
4227
|
-
|
4021
|
+
minGasPrice,
|
4022
|
+
gasPrice: setGasPrice,
|
4228
4023
|
minGas,
|
4229
4024
|
maxGas,
|
4230
4025
|
minFee,
|
4231
4026
|
maxFee,
|
4027
|
+
estimatedInputs: txRequestClone.inputs,
|
4232
4028
|
outputVariables,
|
4233
|
-
missingContractIds
|
4234
|
-
addedSignatures,
|
4235
|
-
estimatedPredicates: txRequestClone.inputs
|
4029
|
+
missingContractIds
|
4236
4030
|
};
|
4237
4031
|
}
|
4238
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4032
|
+
async getResourcesForTransaction(owner, transactionRequestLike, forwardingQuantities = []) {
|
4239
4033
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4240
4034
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4241
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4242
|
-
quantitiesToContract
|
4243
|
-
});
|
4035
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, forwardingQuantities);
|
4244
4036
|
transactionRequest.addResources(
|
4245
4037
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4246
4038
|
);
|
4247
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4248
|
-
|
4249
|
-
|
4039
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4040
|
+
transactionRequest,
|
4041
|
+
forwardingQuantities
|
4042
|
+
);
|
4250
4043
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4251
4044
|
return {
|
4252
4045
|
resources,
|
@@ -4262,16 +4055,17 @@ var _Provider = class {
|
|
4262
4055
|
const result = await this.operations.getCoins({
|
4263
4056
|
first: 10,
|
4264
4057
|
...paginationArgs,
|
4265
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4058
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
4266
4059
|
});
|
4267
4060
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4268
4061
|
return coins.map((coin) => ({
|
4269
4062
|
id: coin.utxoId,
|
4270
4063
|
assetId: coin.assetId,
|
4271
|
-
amount: (0,
|
4064
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4272
4065
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4273
|
-
|
4274
|
-
|
4066
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4067
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4068
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4275
4069
|
}));
|
4276
4070
|
}
|
4277
4071
|
/**
|
@@ -4285,19 +4079,19 @@ var _Provider = class {
|
|
4285
4079
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4286
4080
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4287
4081
|
const excludeInput = {
|
4288
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4289
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4082
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4083
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
4290
4084
|
};
|
4291
4085
|
if (this.cache) {
|
4292
4086
|
const uniqueUtxos = new Set(
|
4293
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4087
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
4294
4088
|
);
|
4295
4089
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4296
4090
|
}
|
4297
4091
|
const coinsQuery = {
|
4298
4092
|
owner: ownerAddress.toB256(),
|
4299
4093
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4300
|
-
assetId: (0,
|
4094
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4301
4095
|
amount: amount.toString(10),
|
4302
4096
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4303
4097
|
})),
|
@@ -4308,9 +4102,9 @@ var _Provider = class {
|
|
4308
4102
|
switch (coin.__typename) {
|
4309
4103
|
case "MessageCoin":
|
4310
4104
|
return {
|
4311
|
-
amount: (0,
|
4105
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4312
4106
|
assetId: coin.assetId,
|
4313
|
-
daHeight: (0,
|
4107
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4314
4108
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4315
4109
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4316
4110
|
nonce: coin.nonce
|
@@ -4318,11 +4112,12 @@ var _Provider = class {
|
|
4318
4112
|
case "Coin":
|
4319
4113
|
return {
|
4320
4114
|
id: coin.utxoId,
|
4321
|
-
amount: (0,
|
4115
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4322
4116
|
assetId: coin.assetId,
|
4323
4117
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4324
|
-
|
4325
|
-
|
4118
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4119
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4120
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4326
4121
|
};
|
4327
4122
|
default:
|
4328
4123
|
return null;
|
@@ -4339,13 +4134,13 @@ var _Provider = class {
|
|
4339
4134
|
async getBlock(idOrHeight) {
|
4340
4135
|
let variables;
|
4341
4136
|
if (typeof idOrHeight === "number") {
|
4342
|
-
variables = { height: (0,
|
4137
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4343
4138
|
} else if (idOrHeight === "latest") {
|
4344
4139
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4345
4140
|
} else if (idOrHeight.length === 66) {
|
4346
4141
|
variables = { blockId: idOrHeight };
|
4347
4142
|
} else {
|
4348
|
-
variables = { blockId: (0,
|
4143
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4349
4144
|
}
|
4350
4145
|
const { block } = await this.operations.getBlock(variables);
|
4351
4146
|
if (!block) {
|
@@ -4353,7 +4148,7 @@ var _Provider = class {
|
|
4353
4148
|
}
|
4354
4149
|
return {
|
4355
4150
|
id: block.id,
|
4356
|
-
height: (0,
|
4151
|
+
height: (0, import_math15.bn)(block.header.height),
|
4357
4152
|
time: block.header.time,
|
4358
4153
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4359
4154
|
};
|
@@ -4368,7 +4163,7 @@ var _Provider = class {
|
|
4368
4163
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4369
4164
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4370
4165
|
id: block.id,
|
4371
|
-
height: (0,
|
4166
|
+
height: (0, import_math15.bn)(block.header.height),
|
4372
4167
|
time: block.header.time,
|
4373
4168
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4374
4169
|
}));
|
@@ -4383,7 +4178,7 @@ var _Provider = class {
|
|
4383
4178
|
async getBlockWithTransactions(idOrHeight) {
|
4384
4179
|
let variables;
|
4385
4180
|
if (typeof idOrHeight === "number") {
|
4386
|
-
variables = { blockHeight: (0,
|
4181
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4387
4182
|
} else if (idOrHeight === "latest") {
|
4388
4183
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4389
4184
|
} else {
|
@@ -4395,11 +4190,11 @@ var _Provider = class {
|
|
4395
4190
|
}
|
4396
4191
|
return {
|
4397
4192
|
id: block.id,
|
4398
|
-
height: (0,
|
4193
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4399
4194
|
time: block.header.time,
|
4400
4195
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4401
4196
|
transactions: block.transactions.map(
|
4402
|
-
(tx) => new
|
4197
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4403
4198
|
)
|
4404
4199
|
};
|
4405
4200
|
}
|
@@ -4414,8 +4209,8 @@ var _Provider = class {
|
|
4414
4209
|
if (!transaction) {
|
4415
4210
|
return null;
|
4416
4211
|
}
|
4417
|
-
return new
|
4418
|
-
(0,
|
4212
|
+
return new import_transactions18.TransactionCoder().decode(
|
4213
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4419
4214
|
0
|
4420
4215
|
)?.[0];
|
4421
4216
|
}
|
@@ -4442,9 +4237,9 @@ var _Provider = class {
|
|
4442
4237
|
async getContractBalance(contractId, assetId) {
|
4443
4238
|
const { contractBalance } = await this.operations.getContractBalance({
|
4444
4239
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4445
|
-
asset: (0,
|
4240
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4446
4241
|
});
|
4447
|
-
return (0,
|
4242
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4448
4243
|
}
|
4449
4244
|
/**
|
4450
4245
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4456,9 +4251,9 @@ var _Provider = class {
|
|
4456
4251
|
async getBalance(owner, assetId) {
|
4457
4252
|
const { balance } = await this.operations.getBalance({
|
4458
4253
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4459
|
-
assetId: (0,
|
4254
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4460
4255
|
});
|
4461
|
-
return (0,
|
4256
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4462
4257
|
}
|
4463
4258
|
/**
|
4464
4259
|
* Returns balances for the given owner.
|
@@ -4476,7 +4271,7 @@ var _Provider = class {
|
|
4476
4271
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4477
4272
|
return balances.map((balance) => ({
|
4478
4273
|
assetId: balance.assetId,
|
4479
|
-
amount: (0,
|
4274
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4480
4275
|
}));
|
4481
4276
|
}
|
4482
4277
|
/**
|
@@ -4494,19 +4289,19 @@ var _Provider = class {
|
|
4494
4289
|
});
|
4495
4290
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4496
4291
|
return messages.map((message) => ({
|
4497
|
-
messageId:
|
4292
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4498
4293
|
sender: message.sender,
|
4499
4294
|
recipient: message.recipient,
|
4500
4295
|
nonce: message.nonce,
|
4501
|
-
amount: (0,
|
4296
|
+
amount: (0, import_math15.bn)(message.amount),
|
4502
4297
|
data: message.data
|
4503
4298
|
}),
|
4504
4299
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4505
4300
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4506
4301
|
nonce: message.nonce,
|
4507
|
-
amount: (0,
|
4508
|
-
data:
|
4509
|
-
daHeight: (0,
|
4302
|
+
amount: (0, import_math15.bn)(message.amount),
|
4303
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4304
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4510
4305
|
}));
|
4511
4306
|
}
|
4512
4307
|
/**
|
@@ -4559,60 +4354,44 @@ var _Provider = class {
|
|
4559
4354
|
} = result.messageProof;
|
4560
4355
|
return {
|
4561
4356
|
messageProof: {
|
4562
|
-
proofIndex: (0,
|
4357
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4563
4358
|
proofSet: messageProof.proofSet
|
4564
4359
|
},
|
4565
4360
|
blockProof: {
|
4566
|
-
proofIndex: (0,
|
4361
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4567
4362
|
proofSet: blockProof.proofSet
|
4568
4363
|
},
|
4569
4364
|
messageBlockHeader: {
|
4570
4365
|
id: messageBlockHeader.id,
|
4571
|
-
daHeight: (0,
|
4572
|
-
transactionsCount: (0,
|
4366
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4367
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4573
4368
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4574
|
-
height: (0,
|
4369
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4575
4370
|
prevRoot: messageBlockHeader.prevRoot,
|
4576
4371
|
time: messageBlockHeader.time,
|
4577
4372
|
applicationHash: messageBlockHeader.applicationHash,
|
4578
|
-
|
4579
|
-
|
4580
|
-
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4581
|
-
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4582
|
-
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4373
|
+
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4374
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4583
4375
|
},
|
4584
4376
|
commitBlockHeader: {
|
4585
4377
|
id: commitBlockHeader.id,
|
4586
|
-
daHeight: (0,
|
4587
|
-
transactionsCount: (0,
|
4378
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4379
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4588
4380
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4589
|
-
height: (0,
|
4381
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4590
4382
|
prevRoot: commitBlockHeader.prevRoot,
|
4591
4383
|
time: commitBlockHeader.time,
|
4592
4384
|
applicationHash: commitBlockHeader.applicationHash,
|
4593
|
-
|
4594
|
-
|
4595
|
-
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4596
|
-
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4597
|
-
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4385
|
+
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4386
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4598
4387
|
},
|
4599
4388
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4600
4389
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4601
4390
|
nonce,
|
4602
|
-
amount: (0,
|
4391
|
+
amount: (0, import_math15.bn)(amount),
|
4603
4392
|
data
|
4604
4393
|
};
|
4605
4394
|
}
|
4606
|
-
async getLatestGasPrice() {
|
4607
|
-
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4608
|
-
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4609
|
-
}
|
4610
|
-
async estimateGasPrice(blockHorizon) {
|
4611
|
-
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4612
|
-
blockHorizon: String(blockHorizon)
|
4613
|
-
});
|
4614
|
-
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4615
|
-
}
|
4616
4395
|
/**
|
4617
4396
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4618
4397
|
*
|
@@ -4632,10 +4411,10 @@ var _Provider = class {
|
|
4632
4411
|
*/
|
4633
4412
|
async produceBlocks(amount, startTime) {
|
4634
4413
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4635
|
-
blocksToProduce: (0,
|
4636
|
-
startTimestamp: startTime ?
|
4414
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4415
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4637
4416
|
});
|
4638
|
-
return (0,
|
4417
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4639
4418
|
}
|
4640
4419
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4641
4420
|
async getTransactionResponse(transactionId) {
|
@@ -4649,7 +4428,7 @@ cacheInputs_fn = function(inputs) {
|
|
4649
4428
|
return;
|
4650
4429
|
}
|
4651
4430
|
inputs.forEach((input) => {
|
4652
|
-
if (input.type ===
|
4431
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4653
4432
|
this.cache?.set(input.id);
|
4654
4433
|
}
|
4655
4434
|
});
|
@@ -4659,9 +4438,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4659
4438
|
|
4660
4439
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4661
4440
|
var import_errors15 = require("@fuel-ts/errors");
|
4662
|
-
var
|
4663
|
-
var
|
4664
|
-
var
|
4441
|
+
var import_math16 = require("@fuel-ts/math");
|
4442
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4443
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4665
4444
|
|
4666
4445
|
// src/providers/chains.ts
|
4667
4446
|
var CHAIN_IDS = {
|
@@ -4710,17 +4489,17 @@ var assets = [
|
|
4710
4489
|
|
4711
4490
|
// src/utils/formatTransferToContractScriptData.ts
|
4712
4491
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4713
|
-
var
|
4714
|
-
var
|
4492
|
+
var import_math17 = require("@fuel-ts/math");
|
4493
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4715
4494
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4716
4495
|
var formatTransferToContractScriptData = (params) => {
|
4717
4496
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4718
4497
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4719
|
-
const encoded = numberCoder.encode(new
|
4498
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4720
4499
|
const scriptData = Uint8Array.from([
|
4721
|
-
...(0,
|
4500
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4722
4501
|
...encoded,
|
4723
|
-
...(0,
|
4502
|
+
...(0, import_utils27.arrayify)(assetId)
|
4724
4503
|
]);
|
4725
4504
|
return scriptData;
|
4726
4505
|
};
|
@@ -4867,8 +4646,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4867
4646
|
* @param assetId - The asset ID to check the balance for.
|
4868
4647
|
* @returns A promise that resolves to the balance amount.
|
4869
4648
|
*/
|
4870
|
-
async getBalance(assetId
|
4871
|
-
const
|
4649
|
+
async getBalance(assetId) {
|
4650
|
+
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
4651
|
+
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4872
4652
|
return amount;
|
4873
4653
|
}
|
4874
4654
|
/**
|
@@ -4905,33 +4685,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4905
4685
|
* @param fee - The estimated transaction fee.
|
4906
4686
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4907
4687
|
*/
|
4908
|
-
async fund(request,
|
4909
|
-
const
|
4910
|
-
const
|
4911
|
-
|
4912
|
-
|
4913
|
-
|
4914
|
-
coinQuantities: requiredQuantities
|
4688
|
+
async fund(request, coinQuantities, fee) {
|
4689
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4690
|
+
const updatedQuantities = addAmountToAsset({
|
4691
|
+
amount: (0, import_math18.bn)(fee),
|
4692
|
+
assetId: baseAssetId,
|
4693
|
+
coinQuantities
|
4915
4694
|
});
|
4916
4695
|
const quantitiesDict = {};
|
4917
|
-
|
4696
|
+
updatedQuantities.forEach(({ amount, assetId }) => {
|
4918
4697
|
quantitiesDict[assetId] = {
|
4919
4698
|
required: amount,
|
4920
|
-
owned: (0,
|
4699
|
+
owned: (0, import_math18.bn)(0)
|
4921
4700
|
};
|
4922
4701
|
});
|
4923
|
-
|
4702
|
+
const cachedUtxos = [];
|
4703
|
+
const cachedMessages = [];
|
4704
|
+
const owner = this.address.toB256();
|
4705
|
+
request.inputs.forEach((input) => {
|
4924
4706
|
const isResource = "amount" in input;
|
4925
4707
|
if (isResource) {
|
4926
4708
|
const isCoin2 = "owner" in input;
|
4927
4709
|
if (isCoin2) {
|
4928
4710
|
const assetId = String(input.assetId);
|
4929
|
-
if (quantitiesDict[assetId]) {
|
4930
|
-
const amount = (0,
|
4711
|
+
if (input.owner === owner && quantitiesDict[assetId]) {
|
4712
|
+
const amount = (0, import_math18.bn)(input.amount);
|
4931
4713
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4714
|
+
cachedUtxos.push(input.id);
|
4932
4715
|
}
|
4933
|
-
} else if (input.amount && quantitiesDict[
|
4934
|
-
quantitiesDict[
|
4716
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4717
|
+
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4718
|
+
cachedMessages.push(input.nonce);
|
4935
4719
|
}
|
4936
4720
|
}
|
4937
4721
|
});
|
@@ -4946,23 +4730,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4946
4730
|
});
|
4947
4731
|
const needsToBeFunded = missingQuantities.length;
|
4948
4732
|
if (needsToBeFunded) {
|
4949
|
-
const
|
4950
|
-
|
4951
|
-
|
4952
|
-
|
4953
|
-
|
4954
|
-
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4955
|
-
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
4956
|
-
if (addedSignatures) {
|
4957
|
-
Array.from({ length: addedSignatures }).forEach(
|
4958
|
-
() => requestToBeReEstimate.addEmptyWitness()
|
4959
|
-
);
|
4733
|
+
const resources = await this.getResourcesToSpend(missingQuantities, {
|
4734
|
+
messages: cachedMessages,
|
4735
|
+
utxos: cachedUtxos
|
4736
|
+
});
|
4737
|
+
request.addResources(resources);
|
4960
4738
|
}
|
4961
|
-
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4962
|
-
transactionRequest: requestToBeReEstimate
|
4963
|
-
});
|
4964
|
-
txRequest.maxFee = maxFee;
|
4965
|
-
return txRequest;
|
4966
4739
|
}
|
4967
4740
|
/**
|
4968
4741
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4970,25 +4743,30 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4970
4743
|
* @param destination - The address of the destination.
|
4971
4744
|
* @param amount - The amount of coins to transfer.
|
4972
4745
|
* @param assetId - The asset ID of the coins to transfer.
|
4973
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4746
|
+
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4974
4747
|
* @returns A promise that resolves to the prepared transaction request.
|
4975
4748
|
*/
|
4976
|
-
async createTransfer(destination, amount, assetId
|
4977
|
-
const
|
4978
|
-
|
4979
|
-
const
|
4749
|
+
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4750
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4751
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4752
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4753
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4754
|
+
const request = new ScriptTransactionRequest(params);
|
4755
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4756
|
+
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4980
4757
|
estimateTxDependencies: true,
|
4981
4758
|
resourcesOwner: this
|
4982
4759
|
});
|
4983
|
-
|
4984
|
-
|
4985
|
-
|
4986
|
-
|
4987
|
-
|
4988
|
-
|
4989
|
-
|
4990
|
-
|
4991
|
-
await this.fund(request,
|
4760
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
4761
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
4762
|
+
this.validateGas({
|
4763
|
+
gasUsed,
|
4764
|
+
gasPrice: request.gasPrice,
|
4765
|
+
gasLimit: request.gasLimit,
|
4766
|
+
minGasPrice
|
4767
|
+
});
|
4768
|
+
await this.fund(request, requiredQuantities, maxFee);
|
4769
|
+
request.updatePredicateInputs(estimatedInputs);
|
4992
4770
|
return request;
|
4993
4771
|
}
|
4994
4772
|
/**
|
@@ -5000,14 +4778,15 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5000
4778
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5001
4779
|
* @returns A promise that resolves to the transaction response.
|
5002
4780
|
*/
|
5003
|
-
async transfer(destination, amount, assetId
|
5004
|
-
if ((0,
|
4781
|
+
async transfer(destination, amount, assetId, txParams = {}) {
|
4782
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5005
4783
|
throw new import_errors16.FuelError(
|
5006
4784
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5007
4785
|
"Transfer amount must be a positive number."
|
5008
4786
|
);
|
5009
4787
|
}
|
5010
|
-
const
|
4788
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4789
|
+
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5011
4790
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
5012
4791
|
}
|
5013
4792
|
/**
|
@@ -5019,38 +4798,41 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5019
4798
|
* @param txParams - The optional transaction parameters.
|
5020
4799
|
* @returns A promise that resolves to the transaction response.
|
5021
4800
|
*/
|
5022
|
-
async transferToContract(contractId, amount, assetId
|
5023
|
-
if ((0,
|
4801
|
+
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4802
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
5024
4803
|
throw new import_errors16.FuelError(
|
5025
4804
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5026
4805
|
"Transfer amount must be a positive number."
|
5027
4806
|
);
|
5028
4807
|
}
|
5029
4808
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4809
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4810
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4811
|
+
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4812
|
+
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
5030
4813
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5031
4814
|
hexlifiedContractId: contractAddress.toB256(),
|
5032
|
-
amountToTransfer: (0,
|
5033
|
-
assetId
|
4815
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
4816
|
+
assetId: assetIdToTransfer
|
5034
4817
|
});
|
5035
4818
|
const request = new ScriptTransactionRequest({
|
5036
|
-
...
|
4819
|
+
...params,
|
5037
4820
|
script,
|
5038
4821
|
scriptData
|
5039
4822
|
});
|
5040
4823
|
request.addContractInputAndOutput(contractAddress);
|
5041
|
-
const
|
5042
|
-
|
5043
|
-
|
4824
|
+
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4825
|
+
request,
|
4826
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
|
4827
|
+
);
|
4828
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4829
|
+
this.validateGas({
|
4830
|
+
gasUsed,
|
4831
|
+
gasPrice: request.gasPrice,
|
4832
|
+
gasLimit: request.gasLimit,
|
4833
|
+
minGasPrice
|
5044
4834
|
});
|
5045
|
-
|
5046
|
-
this.validateGas({
|
5047
|
-
gasUsed: txCost.gasUsed,
|
5048
|
-
gasLimit: request.gasLimit
|
5049
|
-
});
|
5050
|
-
}
|
5051
|
-
request.gasLimit = txCost.gasUsed;
|
5052
|
-
request.maxFee = txCost.maxFee;
|
5053
|
-
await this.fund(request, txCost);
|
4835
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5054
4836
|
return this.sendTransaction(request);
|
5055
4837
|
}
|
5056
4838
|
/**
|
@@ -5062,31 +4844,40 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5062
4844
|
* @returns A promise that resolves to the transaction response.
|
5063
4845
|
*/
|
5064
4846
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4847
|
+
const { minGasPrice } = this.provider.getGasConfig();
|
4848
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
5065
4849
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5066
|
-
const recipientDataArray = (0,
|
4850
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
5067
4851
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5068
4852
|
);
|
5069
|
-
const amountDataArray = (0,
|
5070
|
-
"0x".concat((0,
|
4853
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
4854
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5071
4855
|
);
|
5072
4856
|
const script = new Uint8Array([
|
5073
|
-
...(0,
|
4857
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
5074
4858
|
...recipientDataArray,
|
5075
4859
|
...amountDataArray
|
5076
4860
|
]);
|
5077
|
-
const params = {
|
4861
|
+
const params = {
|
4862
|
+
script,
|
4863
|
+
gasPrice: minGasPrice,
|
4864
|
+
baseAssetId,
|
4865
|
+
...txParams
|
4866
|
+
};
|
5078
4867
|
const request = new ScriptTransactionRequest(params);
|
5079
|
-
const
|
5080
|
-
const
|
5081
|
-
|
5082
|
-
|
5083
|
-
|
5084
|
-
|
5085
|
-
|
5086
|
-
|
5087
|
-
|
5088
|
-
|
5089
|
-
|
4868
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: baseAssetId }];
|
4869
|
+
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4870
|
+
request,
|
4871
|
+
forwardingQuantities
|
4872
|
+
);
|
4873
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4874
|
+
this.validateGas({
|
4875
|
+
gasUsed,
|
4876
|
+
gasPrice: request.gasPrice,
|
4877
|
+
gasLimit: request.gasLimit,
|
4878
|
+
minGasPrice
|
4879
|
+
});
|
4880
|
+
await this.fund(request, requiredQuantities, maxFee);
|
5090
4881
|
return this.sendTransaction(request);
|
5091
4882
|
}
|
5092
4883
|
async signMessage(message) {
|
@@ -5144,7 +4935,18 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5144
4935
|
}
|
5145
4936
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5146
4937
|
}
|
5147
|
-
validateGas({
|
4938
|
+
validateGas({
|
4939
|
+
gasUsed,
|
4940
|
+
gasPrice,
|
4941
|
+
gasLimit,
|
4942
|
+
minGasPrice
|
4943
|
+
}) {
|
4944
|
+
if (minGasPrice.gt(gasPrice)) {
|
4945
|
+
throw new import_errors16.FuelError(
|
4946
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4947
|
+
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4948
|
+
);
|
4949
|
+
}
|
5148
4950
|
if (gasUsed.gt(gasLimit)) {
|
5149
4951
|
throw new import_errors16.FuelError(
|
5150
4952
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -5158,8 +4960,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5158
4960
|
var import_address5 = require("@fuel-ts/address");
|
5159
4961
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5160
4962
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5161
|
-
var
|
5162
|
-
var
|
4963
|
+
var import_math19 = require("@fuel-ts/math");
|
4964
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5163
4965
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5164
4966
|
var Signer = class {
|
5165
4967
|
address;
|
@@ -5178,10 +4980,10 @@ var Signer = class {
|
|
5178
4980
|
privateKey = `0x${privateKey}`;
|
5179
4981
|
}
|
5180
4982
|
}
|
5181
|
-
const privateKeyBytes = (0,
|
5182
|
-
this.privateKey = (0,
|
5183
|
-
this.publicKey = (0,
|
5184
|
-
this.compressedPublicKey = (0,
|
4983
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
4984
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
4985
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4986
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5185
4987
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5186
4988
|
}
|
5187
4989
|
/**
|
@@ -5195,11 +4997,11 @@ var Signer = class {
|
|
5195
4997
|
* @returns hashed signature
|
5196
4998
|
*/
|
5197
4999
|
sign(data) {
|
5198
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5199
|
-
const r = (0,
|
5200
|
-
const s = (0,
|
5000
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
5001
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5002
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5201
5003
|
s[0] |= (signature.recovery || 0) << 7;
|
5202
|
-
return (0,
|
5004
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
5203
5005
|
}
|
5204
5006
|
/**
|
5205
5007
|
* Add point on the current elliptic curve
|
@@ -5208,8 +5010,8 @@ var Signer = class {
|
|
5208
5010
|
* @returns compressed point on the curve
|
5209
5011
|
*/
|
5210
5012
|
addPoint(point) {
|
5211
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5212
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5013
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
5014
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
5213
5015
|
const result = p0.add(p1);
|
5214
5016
|
return `0x${result.toHex(true)}`;
|
5215
5017
|
}
|
@@ -5221,16 +5023,16 @@ var Signer = class {
|
|
5221
5023
|
* @returns public key from signature from the
|
5222
5024
|
*/
|
5223
5025
|
static recoverPublicKey(data, signature) {
|
5224
|
-
const signedMessageBytes = (0,
|
5026
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
5225
5027
|
const r = signedMessageBytes.slice(0, 32);
|
5226
5028
|
const s = signedMessageBytes.slice(32, 64);
|
5227
5029
|
const recoveryParam = (s[0] & 128) >> 7;
|
5228
5030
|
s[0] &= 127;
|
5229
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5031
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
5230
5032
|
recoveryParam
|
5231
5033
|
);
|
5232
|
-
const publicKey = sig.recoverPublicKey((0,
|
5233
|
-
return (0,
|
5034
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5035
|
+
return (0, import_utils29.hexlify)(publicKey);
|
5234
5036
|
}
|
5235
5037
|
/**
|
5236
5038
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5249,7 +5051,7 @@ var Signer = class {
|
|
5249
5051
|
* @returns random 32-byte hashed
|
5250
5052
|
*/
|
5251
5053
|
static generatePrivateKey(entropy) {
|
5252
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5054
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5253
5055
|
}
|
5254
5056
|
/**
|
5255
5057
|
* Extended publicKey from a compact publicKey
|
@@ -5258,8 +5060,8 @@ var Signer = class {
|
|
5258
5060
|
* @returns extended publicKey
|
5259
5061
|
*/
|
5260
5062
|
static extendPublicKey(publicKey) {
|
5261
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5262
|
-
return (0,
|
5063
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5064
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
5263
5065
|
}
|
5264
5066
|
};
|
5265
5067
|
|
@@ -5267,7 +5069,7 @@ var Signer = class {
|
|
5267
5069
|
var import_address6 = require("@fuel-ts/address");
|
5268
5070
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5269
5071
|
var import_errors17 = require("@fuel-ts/errors");
|
5270
|
-
var
|
5072
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5271
5073
|
var import_uuid = require("uuid");
|
5272
5074
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5273
5075
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5350,7 +5152,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5350
5152
|
);
|
5351
5153
|
}
|
5352
5154
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5353
|
-
const privateKey = (0,
|
5155
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5354
5156
|
return privateKey;
|
5355
5157
|
}
|
5356
5158
|
|
@@ -5395,7 +5197,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5395
5197
|
*/
|
5396
5198
|
async signMessage(message) {
|
5397
5199
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5398
|
-
return (0,
|
5200
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5399
5201
|
}
|
5400
5202
|
/**
|
5401
5203
|
* Signs a transaction with the wallet's private key.
|
@@ -5408,7 +5210,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5408
5210
|
const chainId = this.provider.getChainId();
|
5409
5211
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5410
5212
|
const signature = await this.signer().sign(hashedTransaction);
|
5411
|
-
return (0,
|
5213
|
+
return (0, import_utils31.hexlify)(signature);
|
5412
5214
|
}
|
5413
5215
|
/**
|
5414
5216
|
* Populates a transaction with the witnesses signature.
|
@@ -5428,7 +5230,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5428
5230
|
* @param transactionRequestLike - The transaction request to send.
|
5429
5231
|
* @returns A promise that resolves to the TransactionResponse object.
|
5430
5232
|
*/
|
5431
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5233
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, awaitExecution } = {}) {
|
5432
5234
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5433
5235
|
if (estimateTxDependencies) {
|
5434
5236
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5469,15 +5271,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5469
5271
|
// src/hdwallet/hdwallet.ts
|
5470
5272
|
var import_errors20 = require("@fuel-ts/errors");
|
5471
5273
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5472
|
-
var
|
5473
|
-
var
|
5274
|
+
var import_math20 = require("@fuel-ts/math");
|
5275
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5474
5276
|
var import_ethers3 = require("ethers");
|
5475
5277
|
|
5476
5278
|
// src/mnemonic/mnemonic.ts
|
5477
5279
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5478
5280
|
var import_errors19 = require("@fuel-ts/errors");
|
5479
5281
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5480
|
-
var
|
5282
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5481
5283
|
var import_ethers2 = require("ethers");
|
5482
5284
|
|
5483
5285
|
// src/wordlists/words/english.ts
|
@@ -7535,7 +7337,7 @@ var english = [
|
|
7535
7337
|
// src/mnemonic/utils.ts
|
7536
7338
|
var import_errors18 = require("@fuel-ts/errors");
|
7537
7339
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7538
|
-
var
|
7340
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7539
7341
|
function toUtf8Bytes(stri) {
|
7540
7342
|
const str = stri.normalize("NFKD");
|
7541
7343
|
const result = [];
|
@@ -7602,14 +7404,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7602
7404
|
}
|
7603
7405
|
}
|
7604
7406
|
const checksumBits = entropy.length / 4;
|
7605
|
-
const checksum = (0,
|
7407
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7606
7408
|
indices[indices.length - 1] <<= checksumBits;
|
7607
7409
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7608
7410
|
return indices;
|
7609
7411
|
}
|
7610
7412
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7611
7413
|
const size = Math.ceil(11 * words.length / 8);
|
7612
|
-
const entropy = (0,
|
7414
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7613
7415
|
let offset = 0;
|
7614
7416
|
for (let i = 0; i < words.length; i += 1) {
|
7615
7417
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7629,7 +7431,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7629
7431
|
const entropyBits = 32 * words.length / 3;
|
7630
7432
|
const checksumBits = words.length / 3;
|
7631
7433
|
const checksumMask = getUpperMask(checksumBits);
|
7632
|
-
const checksum = (0,
|
7434
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7633
7435
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7634
7436
|
throw new import_errors18.FuelError(
|
7635
7437
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7704,7 +7506,7 @@ var Mnemonic = class {
|
|
7704
7506
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7705
7507
|
const words = getWords(phrase);
|
7706
7508
|
assertMnemonic(words);
|
7707
|
-
return (0,
|
7509
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7708
7510
|
}
|
7709
7511
|
/**
|
7710
7512
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7712,7 +7514,7 @@ var Mnemonic = class {
|
|
7712
7514
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7713
7515
|
*/
|
7714
7516
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7715
|
-
const entropyBytes = (0,
|
7517
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7716
7518
|
assertWordList(wordlist);
|
7717
7519
|
assertEntropy(entropyBytes);
|
7718
7520
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7781,14 +7583,14 @@ var Mnemonic = class {
|
|
7781
7583
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7782
7584
|
*/
|
7783
7585
|
static masterKeysFromSeed(seed) {
|
7784
|
-
const seedArray = (0,
|
7586
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7785
7587
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7786
7588
|
throw new import_errors19.FuelError(
|
7787
7589
|
import_errors19.ErrorCode.INVALID_SEED,
|
7788
7590
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7789
7591
|
);
|
7790
7592
|
}
|
7791
|
-
return (0,
|
7593
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7792
7594
|
}
|
7793
7595
|
/**
|
7794
7596
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7799,22 +7601,22 @@ var Mnemonic = class {
|
|
7799
7601
|
*/
|
7800
7602
|
static seedToExtendedKey(seed, testnet = false) {
|
7801
7603
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7802
|
-
const prefix = (0,
|
7604
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7803
7605
|
const depth = "0x00";
|
7804
7606
|
const fingerprint = "0x00000000";
|
7805
7607
|
const index = "0x00000000";
|
7806
7608
|
const chainCode = masterKey.slice(32);
|
7807
7609
|
const privateKey = masterKey.slice(0, 32);
|
7808
|
-
const extendedKey = (0,
|
7610
|
+
const extendedKey = (0, import_utils33.concat)([
|
7809
7611
|
prefix,
|
7810
7612
|
depth,
|
7811
7613
|
fingerprint,
|
7812
7614
|
index,
|
7813
7615
|
chainCode,
|
7814
|
-
(0,
|
7616
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
7815
7617
|
]);
|
7816
7618
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7817
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7619
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
7818
7620
|
}
|
7819
7621
|
/**
|
7820
7622
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7829,7 +7631,7 @@ var Mnemonic = class {
|
|
7829
7631
|
* @returns A randomly generated mnemonic
|
7830
7632
|
*/
|
7831
7633
|
static generate(size = 32, extraEntropy = "") {
|
7832
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7634
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
7833
7635
|
return Mnemonic.entropyToMnemonic(entropy);
|
7834
7636
|
}
|
7835
7637
|
};
|
@@ -7837,12 +7639,12 @@ var mnemonic_default = Mnemonic;
|
|
7837
7639
|
|
7838
7640
|
// src/hdwallet/hdwallet.ts
|
7839
7641
|
var HARDENED_INDEX = 2147483648;
|
7840
|
-
var MainnetPRV2 = (0,
|
7841
|
-
var MainnetPUB = (0,
|
7842
|
-
var TestnetPRV2 = (0,
|
7843
|
-
var TestnetPUB = (0,
|
7642
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
7643
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
7644
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
7645
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
7844
7646
|
function base58check(data) {
|
7845
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7647
|
+
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)]));
|
7846
7648
|
}
|
7847
7649
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7848
7650
|
if (isPublic) {
|
@@ -7851,11 +7653,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7851
7653
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7852
7654
|
}
|
7853
7655
|
function isPublicExtendedKey(extendedKey) {
|
7854
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7656
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
7855
7657
|
}
|
7856
7658
|
function isValidExtendedKey(extendedKey) {
|
7857
7659
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7858
|
-
(0,
|
7660
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
7859
7661
|
);
|
7860
7662
|
}
|
7861
7663
|
function parsePath(path2, depth = 0) {
|
@@ -7873,8 +7675,8 @@ function parsePath(path2, depth = 0) {
|
|
7873
7675
|
var HDWallet = class {
|
7874
7676
|
depth = 0;
|
7875
7677
|
index = 0;
|
7876
|
-
fingerprint = (0,
|
7877
|
-
parentFingerprint = (0,
|
7678
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7679
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7878
7680
|
privateKey;
|
7879
7681
|
publicKey;
|
7880
7682
|
chainCode;
|
@@ -7886,8 +7688,8 @@ var HDWallet = class {
|
|
7886
7688
|
constructor(config) {
|
7887
7689
|
if (config.privateKey) {
|
7888
7690
|
const signer = new Signer(config.privateKey);
|
7889
|
-
this.publicKey = (0,
|
7890
|
-
this.privateKey = (0,
|
7691
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
7692
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
7891
7693
|
} else {
|
7892
7694
|
if (!config.publicKey) {
|
7893
7695
|
throw new import_errors20.FuelError(
|
@@ -7895,7 +7697,7 @@ var HDWallet = class {
|
|
7895
7697
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7896
7698
|
);
|
7897
7699
|
}
|
7898
|
-
this.publicKey = (0,
|
7700
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
7899
7701
|
}
|
7900
7702
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7901
7703
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7914,9 +7716,9 @@ var HDWallet = class {
|
|
7914
7716
|
* @returns A new instance of HDWallet on the derived index
|
7915
7717
|
*/
|
7916
7718
|
deriveIndex(index) {
|
7917
|
-
const privateKey = this.privateKey && (0,
|
7918
|
-
const publicKey = (0,
|
7919
|
-
const chainCode = (0,
|
7719
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
7720
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
7721
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
7920
7722
|
const data = new Uint8Array(37);
|
7921
7723
|
if (index & HARDENED_INDEX) {
|
7922
7724
|
if (!privateKey) {
|
@@ -7927,15 +7729,15 @@ var HDWallet = class {
|
|
7927
7729
|
}
|
7928
7730
|
data.set(privateKey, 1);
|
7929
7731
|
} else {
|
7930
|
-
data.set((0,
|
7732
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
7931
7733
|
}
|
7932
|
-
data.set((0,
|
7933
|
-
const bytes = (0,
|
7734
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
7735
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7934
7736
|
const IL = bytes.slice(0, 32);
|
7935
7737
|
const IR = bytes.slice(32);
|
7936
7738
|
if (privateKey) {
|
7937
7739
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7938
|
-
const ki = (0,
|
7740
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7939
7741
|
return new HDWallet({
|
7940
7742
|
privateKey: ki,
|
7941
7743
|
chainCode: IR,
|
@@ -7944,7 +7746,7 @@ var HDWallet = class {
|
|
7944
7746
|
parentFingerprint: this.fingerprint
|
7945
7747
|
});
|
7946
7748
|
}
|
7947
|
-
const signer = new Signer((0,
|
7749
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
7948
7750
|
const Ki = signer.addPoint(publicKey);
|
7949
7751
|
return new HDWallet({
|
7950
7752
|
publicKey: Ki,
|
@@ -7979,12 +7781,12 @@ var HDWallet = class {
|
|
7979
7781
|
);
|
7980
7782
|
}
|
7981
7783
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7982
|
-
const depth = (0,
|
7784
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
7983
7785
|
const parentFingerprint = this.parentFingerprint;
|
7984
|
-
const index = (0,
|
7786
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
7985
7787
|
const chainCode = this.chainCode;
|
7986
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7987
|
-
const extendedKey = (0,
|
7788
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7789
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7988
7790
|
return base58check(extendedKey);
|
7989
7791
|
}
|
7990
7792
|
/**
|
@@ -7996,13 +7798,13 @@ var HDWallet = class {
|
|
7996
7798
|
static fromSeed(seed) {
|
7997
7799
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7998
7800
|
return new HDWallet({
|
7999
|
-
chainCode: (0,
|
8000
|
-
privateKey: (0,
|
7801
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
7802
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
8001
7803
|
});
|
8002
7804
|
}
|
8003
7805
|
static fromExtendedKey(extendedKey) {
|
8004
7806
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8005
|
-
const bytes = (0,
|
7807
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
8006
7808
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8007
7809
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8008
7810
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -8011,9 +7813,9 @@ var HDWallet = class {
|
|
8011
7813
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8012
7814
|
}
|
8013
7815
|
const depth = bytes[4];
|
8014
|
-
const parentFingerprint = (0,
|
8015
|
-
const index = parseInt((0,
|
8016
|
-
const chainCode = (0,
|
7816
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
7817
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7818
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
8017
7819
|
const key = bytes.slice(45, 78);
|
8018
7820
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8019
7821
|
throw new import_errors20.FuelError(
|
@@ -8206,15 +8008,16 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
8206
8008
|
process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
|
8207
8009
|
wallet.provider
|
8208
8010
|
);
|
8209
|
-
const
|
8210
|
-
|
8211
|
-
|
8212
|
-
|
8011
|
+
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
8012
|
+
const { minGasPrice } = genesisWallet.provider.getGasConfig();
|
8013
|
+
const baseAssetId = genesisWallet.provider.getBaseAssetId();
|
8014
|
+
const request = new ScriptTransactionRequest({
|
8015
|
+
baseAssetId,
|
8016
|
+
gasLimit: 1e4,
|
8017
|
+
gasPrice: minGasPrice
|
8213
8018
|
});
|
8214
|
-
|
8215
|
-
request.
|
8216
|
-
request.maxFee = txCost.maxFee;
|
8217
|
-
await genesisWallet.fund(request, txCost);
|
8019
|
+
request.addResources(resources);
|
8020
|
+
quantities.map(coinQuantityfy).forEach(({ amount, assetId }) => request.addCoinOutput(wallet.address, amount, assetId));
|
8218
8021
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8219
8022
|
};
|
8220
8023
|
|
@@ -8228,12 +8031,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8228
8031
|
};
|
8229
8032
|
|
8230
8033
|
// src/test-utils/launchNode.ts
|
8231
|
-
var
|
8232
|
-
var
|
8034
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
8035
|
+
var import_math21 = require("@fuel-ts/math");
|
8036
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8233
8037
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8234
8038
|
var import_child_process = require("child_process");
|
8235
8039
|
var import_crypto6 = require("crypto");
|
8236
|
-
var import_ethers4 = require("ethers");
|
8237
8040
|
var import_fs = require("fs");
|
8238
8041
|
var import_os = __toESM(require("os"));
|
8239
8042
|
var import_path = __toESM(require("path"));
|
@@ -8282,13 +8085,13 @@ var launchNode = async ({
|
|
8282
8085
|
// eslint-disable-next-line no-async-promise-executor
|
8283
8086
|
new Promise(async (resolve, reject) => {
|
8284
8087
|
const remainingArgs = extractRemainingArgs(args, [
|
8285
|
-
"--
|
8088
|
+
"--chain",
|
8286
8089
|
"--consensus-key",
|
8287
8090
|
"--db-type",
|
8288
8091
|
"--poa-instant"
|
8289
8092
|
]);
|
8290
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8291
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8093
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
8094
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
8292
8095
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8293
8096
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8294
8097
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8306,54 +8109,36 @@ var launchNode = async ({
|
|
8306
8109
|
let chainConfigPathToUse;
|
8307
8110
|
const prefix = basePath || import_os.default.tmpdir();
|
8308
8111
|
const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
|
8309
|
-
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix
|
8112
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8310
8113
|
if (chainConfigPath) {
|
8311
8114
|
chainConfigPathToUse = chainConfigPath;
|
8312
8115
|
} else {
|
8313
8116
|
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8314
8117
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8315
8118
|
}
|
8316
|
-
|
8317
|
-
|
8318
|
-
stateConfigJson = {
|
8319
|
-
...stateConfigJson,
|
8320
|
-
coins: [
|
8321
|
-
...stateConfigJson.coins.map((coin) => ({
|
8322
|
-
...coin,
|
8323
|
-
amount: "18446744073709551615"
|
8324
|
-
}))
|
8325
|
-
],
|
8326
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8327
|
-
...message,
|
8328
|
-
amount: "18446744073709551615"
|
8329
|
-
}))
|
8330
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8331
|
-
};
|
8119
|
+
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8120
|
+
let chainConfig = import_utils36.defaultChainConfig;
|
8332
8121
|
if (!process.env.GENESIS_SECRET) {
|
8333
8122
|
const pk = Signer.generatePrivateKey();
|
8334
8123
|
const signer = new Signer(pk);
|
8335
|
-
process.env.GENESIS_SECRET = (0,
|
8336
|
-
|
8337
|
-
|
8338
|
-
|
8339
|
-
|
8340
|
-
|
8341
|
-
|
8342
|
-
|
8343
|
-
|
8344
|
-
|
8345
|
-
|
8124
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8125
|
+
chainConfig = {
|
8126
|
+
...import_utils36.defaultChainConfig,
|
8127
|
+
initial_state: {
|
8128
|
+
...import_utils36.defaultChainConfig.initial_state,
|
8129
|
+
coins: [
|
8130
|
+
...import_utils36.defaultChainConfig.initial_state.coins,
|
8131
|
+
{
|
8132
|
+
owner: signer.address.toHexString(),
|
8133
|
+
amount: (0, import_math21.toHex)(1e9),
|
8134
|
+
asset_id: import_utils36.defaultChainConfig?.consensus_parameters?.base_asset_id ?? import_configs11.ZeroBytes32
|
8135
|
+
}
|
8136
|
+
]
|
8137
|
+
}
|
8138
|
+
};
|
8346
8139
|
}
|
8347
|
-
|
8348
|
-
|
8349
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8350
|
-
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8351
|
-
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8352
|
-
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8353
|
-
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8354
|
-
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8355
|
-
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8356
|
-
chainConfigPathToUse = tempDirPath;
|
8140
|
+
(0, import_fs.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
|
8141
|
+
chainConfigPathToUse = tempChainConfigFilePath;
|
8357
8142
|
}
|
8358
8143
|
const child = (0, import_child_process.spawn)(
|
8359
8144
|
command,
|
@@ -8362,10 +8147,10 @@ var launchNode = async ({
|
|
8362
8147
|
["--ip", ipToUse],
|
8363
8148
|
["--port", portToUse],
|
8364
8149
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8365
|
-
["--min-gas-price", "
|
8150
|
+
["--min-gas-price", "0"],
|
8366
8151
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8367
8152
|
["--consensus-key", consensusKey],
|
8368
|
-
["--
|
8153
|
+
["--chain", chainConfigPathToUse],
|
8369
8154
|
"--vm-backtrace",
|
8370
8155
|
"--utxo-validation",
|
8371
8156
|
"--debug",
|
@@ -8412,9 +8197,10 @@ var launchNode = async ({
|
|
8412
8197
|
})
|
8413
8198
|
);
|
8414
8199
|
var generateWallets = async (count, provider) => {
|
8200
|
+
const baseAssetId = provider.getBaseAssetId();
|
8415
8201
|
const wallets = [];
|
8416
8202
|
for (let i = 0; i < count; i += 1) {
|
8417
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8203
|
+
const wallet = await generateTestWallet(provider, [[1e3, baseAssetId]]);
|
8418
8204
|
wallets.push(wallet);
|
8419
8205
|
}
|
8420
8206
|
return wallets;
|
@@ -8424,7 +8210,7 @@ var launchNodeAndGetWallets = async ({
|
|
8424
8210
|
walletCount = 10
|
8425
8211
|
} = {}) => {
|
8426
8212
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8427
|
-
const provider = await Provider.create(`http://${ip}:${port}/
|
8213
|
+
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8428
8214
|
const wallets = await generateWallets(walletCount, provider);
|
8429
8215
|
const cleanup = () => {
|
8430
8216
|
closeNode();
|