@fuel-ts/account 0.0.0-rc-1976-20240411153008 → 0.0.0-rc-2021-20240411154255
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 +5 -4
- 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 +896 -629
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +874 -621
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +716 -464
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +906 -324
- 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 +4 -2
- 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 +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +45 -34
- 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 +9 -29
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- 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 +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- 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 +8 -2
- 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 +1613 -1132
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +852 -620
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +710 -478
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/test-utils.js
CHANGED
@@ -58,39 +58,42 @@ 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_utils30 = 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");
|
65
66
|
var import_errors16 = require("@fuel-ts/errors");
|
66
67
|
var import_interfaces = require("@fuel-ts/interfaces");
|
67
|
-
var
|
68
|
-
var
|
68
|
+
var import_math19 = require("@fuel-ts/math");
|
69
|
+
var import_utils27 = require("@fuel-ts/utils");
|
70
|
+
var import_ramda4 = require("ramda");
|
69
71
|
|
70
72
|
// src/providers/coin-quantity.ts
|
73
|
+
var import_configs = require("@fuel-ts/address/configs");
|
71
74
|
var import_math = require("@fuel-ts/math");
|
72
75
|
var import_utils = require("@fuel-ts/utils");
|
73
76
|
var coinQuantityfy = (coinQuantityLike) => {
|
74
77
|
let assetId;
|
75
78
|
let amount;
|
76
|
-
let
|
79
|
+
let max;
|
77
80
|
if (Array.isArray(coinQuantityLike)) {
|
78
81
|
amount = coinQuantityLike[0];
|
79
|
-
assetId = coinQuantityLike[1];
|
80
|
-
|
82
|
+
assetId = coinQuantityLike[1] ?? import_configs.BaseAssetId;
|
83
|
+
max = coinQuantityLike[2] ?? void 0;
|
81
84
|
} else {
|
82
85
|
amount = coinQuantityLike.amount;
|
83
|
-
assetId = coinQuantityLike.assetId;
|
84
|
-
|
86
|
+
assetId = coinQuantityLike.assetId ?? import_configs.BaseAssetId;
|
87
|
+
max = coinQuantityLike.max ?? void 0;
|
85
88
|
}
|
86
89
|
const bnAmount = (0, import_math.bn)(amount);
|
87
90
|
return {
|
88
91
|
assetId: (0, import_utils.hexlify)(assetId),
|
89
92
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
90
|
-
max:
|
93
|
+
max: max ? (0, import_math.bn)(max) : void 0
|
91
94
|
};
|
92
95
|
};
|
93
|
-
var
|
96
|
+
var addAmountToCoinQuantities = (params) => {
|
94
97
|
const { amount, assetId } = params;
|
95
98
|
const coinQuantities = [...params.coinQuantities];
|
96
99
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -105,12 +108,12 @@ var addAmountToAsset = (params) => {
|
|
105
108
|
// src/providers/provider.ts
|
106
109
|
var import_address3 = require("@fuel-ts/address");
|
107
110
|
var import_errors14 = require("@fuel-ts/errors");
|
108
|
-
var
|
109
|
-
var
|
110
|
-
var
|
111
|
+
var import_math16 = require("@fuel-ts/math");
|
112
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
113
|
+
var import_utils22 = require("@fuel-ts/utils");
|
111
114
|
var import_versions = require("@fuel-ts/versions");
|
112
|
-
var
|
113
|
-
var
|
115
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
116
|
+
var import_ethers2 = require("ethers");
|
114
117
|
var import_graphql_request = require("graphql-request");
|
115
118
|
var import_ramda3 = require("ramda");
|
116
119
|
|
@@ -118,14 +121,10 @@ var import_ramda3 = require("ramda");
|
|
118
121
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
119
122
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
120
123
|
fragment receiptFragment on Receipt {
|
121
|
-
|
122
|
-
id
|
123
|
-
}
|
124
|
+
id
|
124
125
|
pc
|
125
126
|
is
|
126
|
-
to
|
127
|
-
id
|
128
|
-
}
|
127
|
+
to
|
129
128
|
toAddress
|
130
129
|
amount
|
131
130
|
assetId
|
@@ -163,10 +162,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
163
162
|
id
|
164
163
|
}
|
165
164
|
time
|
165
|
+
receipts {
|
166
|
+
...receiptFragment
|
167
|
+
}
|
166
168
|
programState {
|
167
169
|
returnType
|
168
170
|
data
|
169
171
|
}
|
172
|
+
receipts {
|
173
|
+
...receiptFragment
|
174
|
+
}
|
170
175
|
}
|
171
176
|
... on FailureStatus {
|
172
177
|
block {
|
@@ -174,26 +179,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
174
179
|
}
|
175
180
|
time
|
176
181
|
reason
|
182
|
+
receipts {
|
183
|
+
...receiptFragment
|
184
|
+
}
|
177
185
|
}
|
178
186
|
... on SqueezedOutStatus {
|
179
187
|
reason
|
180
188
|
}
|
181
189
|
}
|
182
|
-
`;
|
190
|
+
${ReceiptFragmentFragmentDoc}`;
|
183
191
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
184
192
|
fragment transactionFragment on Transaction {
|
185
193
|
id
|
186
194
|
rawPayload
|
187
|
-
gasPrice
|
188
|
-
receipts {
|
189
|
-
...receiptFragment
|
190
|
-
}
|
191
195
|
status {
|
192
196
|
...transactionStatusFragment
|
193
197
|
}
|
194
198
|
}
|
195
|
-
${
|
196
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
199
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
197
200
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
198
201
|
fragment inputEstimatePredicatesFragment on Input {
|
199
202
|
... on InputCoin {
|
@@ -211,6 +214,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
211
214
|
}
|
212
215
|
}
|
213
216
|
${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}`;
|
214
257
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
215
258
|
fragment coinFragment on Coin {
|
216
259
|
__typename
|
@@ -218,7 +261,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
218
261
|
owner
|
219
262
|
amount
|
220
263
|
assetId
|
221
|
-
maturity
|
222
264
|
blockCreated
|
223
265
|
txCreatedIdx
|
224
266
|
}
|
@@ -257,26 +299,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
257
299
|
messageBlockHeader {
|
258
300
|
id
|
259
301
|
daHeight
|
302
|
+
consensusParametersVersion
|
303
|
+
stateTransitionBytecodeVersion
|
260
304
|
transactionsCount
|
305
|
+
messageReceiptCount
|
261
306
|
transactionsRoot
|
307
|
+
messageOutboxRoot
|
308
|
+
eventInboxRoot
|
262
309
|
height
|
263
310
|
prevRoot
|
264
311
|
time
|
265
312
|
applicationHash
|
266
|
-
messageReceiptRoot
|
267
|
-
messageReceiptCount
|
268
313
|
}
|
269
314
|
commitBlockHeader {
|
270
315
|
id
|
271
316
|
daHeight
|
317
|
+
consensusParametersVersion
|
318
|
+
stateTransitionBytecodeVersion
|
272
319
|
transactionsCount
|
320
|
+
messageReceiptCount
|
273
321
|
transactionsRoot
|
322
|
+
messageOutboxRoot
|
323
|
+
eventInboxRoot
|
274
324
|
height
|
275
325
|
prevRoot
|
276
326
|
time
|
277
327
|
applicationHash
|
278
|
-
messageReceiptRoot
|
279
|
-
messageReceiptCount
|
280
328
|
}
|
281
329
|
sender
|
282
330
|
recipient
|
@@ -295,8 +343,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
295
343
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
296
344
|
fragment blockFragment on Block {
|
297
345
|
id
|
346
|
+
height
|
298
347
|
header {
|
299
|
-
height
|
300
348
|
time
|
301
349
|
}
|
302
350
|
transactions {
|
@@ -354,6 +402,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
354
402
|
`;
|
355
403
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
356
404
|
fragment GasCostsFragment on GasCosts {
|
405
|
+
version {
|
406
|
+
... on Version {
|
407
|
+
value
|
408
|
+
}
|
409
|
+
}
|
357
410
|
add
|
358
411
|
addi
|
359
412
|
aloc
|
@@ -366,7 +419,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
366
419
|
cb
|
367
420
|
cfei
|
368
421
|
cfsi
|
369
|
-
croo
|
370
422
|
div
|
371
423
|
divi
|
372
424
|
ecr1
|
@@ -449,6 +501,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
449
501
|
ccp {
|
450
502
|
...DependentCostFragment
|
451
503
|
}
|
504
|
+
croo {
|
505
|
+
...DependentCostFragment
|
506
|
+
}
|
452
507
|
csiz {
|
453
508
|
...DependentCostFragment
|
454
509
|
}
|
@@ -508,6 +563,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
508
563
|
${DependentCostFragmentFragmentDoc}`;
|
509
564
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
510
565
|
fragment consensusParametersFragment on ConsensusParameters {
|
566
|
+
version {
|
567
|
+
... on Version {
|
568
|
+
value
|
569
|
+
}
|
570
|
+
}
|
511
571
|
txParams {
|
512
572
|
...TxParametersFragment
|
513
573
|
}
|
@@ -567,18 +627,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
567
627
|
fragment nodeInfoFragment on NodeInfo {
|
568
628
|
utxoValidation
|
569
629
|
vmBacktrace
|
570
|
-
minGasPrice
|
571
630
|
maxTx
|
572
631
|
maxDepth
|
573
632
|
nodeVersion
|
574
|
-
peers {
|
575
|
-
id
|
576
|
-
addresses
|
577
|
-
clientVersion
|
578
|
-
blockHeight
|
579
|
-
lastHeartbeatMs
|
580
|
-
appScore
|
581
|
-
}
|
582
633
|
}
|
583
634
|
`;
|
584
635
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -613,13 +664,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
613
664
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
614
665
|
transaction(id: $transactionId) {
|
615
666
|
...transactionFragment
|
616
|
-
receipts {
|
617
|
-
...receiptFragment
|
618
|
-
}
|
619
667
|
}
|
620
668
|
}
|
621
|
-
${TransactionFragmentFragmentDoc}
|
622
|
-
${ReceiptFragmentFragmentDoc}`;
|
669
|
+
${TransactionFragmentFragmentDoc}`;
|
623
670
|
var GetTransactionsDocument = import_graphql_tag.default`
|
624
671
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
625
672
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -747,6 +794,20 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
747
794
|
}
|
748
795
|
}
|
749
796
|
${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
|
+
`;
|
750
811
|
var GetBalancesDocument = import_graphql_tag.default`
|
751
812
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
752
813
|
balances(
|
@@ -801,12 +862,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
801
862
|
}
|
802
863
|
`;
|
803
864
|
var DryRunDocument = import_graphql_tag.default`
|
804
|
-
mutation dryRun($
|
805
|
-
dryRun(
|
806
|
-
...
|
865
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
866
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
867
|
+
...dryRunTransactionExecutionStatusFragment
|
807
868
|
}
|
808
869
|
}
|
809
|
-
${
|
870
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
810
871
|
var SubmitDocument = import_graphql_tag.default`
|
811
872
|
mutation submit($encodedTransaction: HexString!) {
|
812
873
|
submit(tx: $encodedTransaction) {
|
@@ -889,6 +950,12 @@ function getSdk(requester) {
|
|
889
950
|
getBalance(variables, options) {
|
890
951
|
return requester(GetBalanceDocument, variables, options);
|
891
952
|
},
|
953
|
+
getLatestGasPrice(variables, options) {
|
954
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
955
|
+
},
|
956
|
+
estimateGasPrice(variables, options) {
|
957
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
958
|
+
},
|
892
959
|
getBalances(variables, options) {
|
893
960
|
return requester(GetBalancesDocument, variables, options);
|
894
961
|
},
|
@@ -958,11 +1025,14 @@ var _FuelGraphqlSubscriber = class {
|
|
958
1025
|
let data;
|
959
1026
|
let errors;
|
960
1027
|
try {
|
961
|
-
|
1028
|
+
const sanitizedText = text.replace(/\s/g, "");
|
1029
|
+
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
962
1030
|
} catch (e) {
|
963
1031
|
throw new import_errors.FuelError(
|
964
1032
|
import_errors.ErrorCode.STREAM_PARSING_ERROR,
|
965
|
-
`Error while parsing stream data response: ${text}
|
1033
|
+
`Error while parsing stream data response: ${text}
|
1034
|
+
|
1035
|
+
Thrown error: ${e}`
|
966
1036
|
);
|
967
1037
|
}
|
968
1038
|
if (Array.isArray(errors)) {
|
@@ -1049,7 +1119,7 @@ var MemoryCache = class {
|
|
1049
1119
|
};
|
1050
1120
|
|
1051
1121
|
// src/providers/transaction-request/input.ts
|
1052
|
-
var
|
1122
|
+
var import_configs2 = require("@fuel-ts/address/configs");
|
1053
1123
|
var import_errors3 = require("@fuel-ts/errors");
|
1054
1124
|
var import_math2 = require("@fuel-ts/math");
|
1055
1125
|
var import_transactions = require("@fuel-ts/transactions");
|
@@ -1063,7 +1133,7 @@ var inputify = (value) => {
|
|
1063
1133
|
return {
|
1064
1134
|
type: import_transactions.InputType.Coin,
|
1065
1135
|
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, 32)),
|
1066
|
-
outputIndex: (0, import_utils3.arrayify)(value.id)
|
1136
|
+
outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(32, 34)),
|
1067
1137
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1068
1138
|
amount: (0, import_math2.bn)(value.amount),
|
1069
1139
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1072,10 +1142,9 @@ var inputify = (value) => {
|
|
1072
1142
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1073
1143
|
},
|
1074
1144
|
witnessIndex: value.witnessIndex,
|
1075
|
-
maturity: value.maturity ?? 0,
|
1076
1145
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1077
|
-
predicateLength: predicate.length,
|
1078
|
-
predicateDataLength: predicateData.length,
|
1146
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1147
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1079
1148
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1080
1149
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1081
1150
|
};
|
@@ -1083,10 +1152,10 @@ var inputify = (value) => {
|
|
1083
1152
|
case import_transactions.InputType.Contract: {
|
1084
1153
|
return {
|
1085
1154
|
type: import_transactions.InputType.Contract,
|
1086
|
-
txID:
|
1155
|
+
txID: import_configs2.ZeroBytes32,
|
1087
1156
|
outputIndex: 0,
|
1088
|
-
balanceRoot:
|
1089
|
-
stateRoot:
|
1157
|
+
balanceRoot: import_configs2.ZeroBytes32,
|
1158
|
+
stateRoot: import_configs2.ZeroBytes32,
|
1090
1159
|
txPointer: {
|
1091
1160
|
blockHeight: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(0, 8)),
|
1092
1161
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
@@ -1106,8 +1175,8 @@ var inputify = (value) => {
|
|
1106
1175
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1107
1176
|
witnessIndex: value.witnessIndex,
|
1108
1177
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1109
|
-
predicateLength: predicate.length,
|
1110
|
-
predicateDataLength: predicateData.length,
|
1178
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1179
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1111
1180
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1112
1181
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1113
1182
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1124,7 +1193,7 @@ var inputify = (value) => {
|
|
1124
1193
|
};
|
1125
1194
|
|
1126
1195
|
// src/providers/transaction-request/output.ts
|
1127
|
-
var
|
1196
|
+
var import_configs3 = require("@fuel-ts/address/configs");
|
1128
1197
|
var import_errors4 = require("@fuel-ts/errors");
|
1129
1198
|
var import_math3 = require("@fuel-ts/math");
|
1130
1199
|
var import_transactions2 = require("@fuel-ts/transactions");
|
@@ -1144,8 +1213,8 @@ var outputify = (value) => {
|
|
1144
1213
|
return {
|
1145
1214
|
type: import_transactions2.OutputType.Contract,
|
1146
1215
|
inputIndex: value.inputIndex,
|
1147
|
-
balanceRoot:
|
1148
|
-
stateRoot:
|
1216
|
+
balanceRoot: import_configs3.ZeroBytes32,
|
1217
|
+
stateRoot: import_configs3.ZeroBytes32
|
1149
1218
|
};
|
1150
1219
|
}
|
1151
1220
|
case import_transactions2.OutputType.Change: {
|
@@ -1159,9 +1228,9 @@ var outputify = (value) => {
|
|
1159
1228
|
case import_transactions2.OutputType.Variable: {
|
1160
1229
|
return {
|
1161
1230
|
type: import_transactions2.OutputType.Variable,
|
1162
|
-
to:
|
1231
|
+
to: import_configs3.ZeroBytes32,
|
1163
1232
|
amount: (0, import_math3.bn)(0),
|
1164
|
-
assetId:
|
1233
|
+
assetId: import_configs3.ZeroBytes32
|
1165
1234
|
};
|
1166
1235
|
}
|
1167
1236
|
case import_transactions2.OutputType.ContractCreated: {
|
@@ -1182,22 +1251,23 @@ var outputify = (value) => {
|
|
1182
1251
|
|
1183
1252
|
// src/providers/transaction-request/transaction-request.ts
|
1184
1253
|
var import_address = require("@fuel-ts/address");
|
1185
|
-
var
|
1254
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
1186
1255
|
var import_math7 = require("@fuel-ts/math");
|
1187
1256
|
var import_transactions6 = require("@fuel-ts/transactions");
|
1188
1257
|
var import_utils9 = require("@fuel-ts/utils");
|
1258
|
+
var import_ethers = require("ethers");
|
1189
1259
|
|
1190
1260
|
// src/providers/resource.ts
|
1191
1261
|
var isCoin = (resource) => "id" in resource;
|
1192
1262
|
|
1193
1263
|
// src/providers/utils/receipts.ts
|
1194
|
-
var
|
1264
|
+
var import_configs4 = require("@fuel-ts/address/configs");
|
1195
1265
|
var import_errors5 = require("@fuel-ts/errors");
|
1196
1266
|
var import_math4 = require("@fuel-ts/math");
|
1197
1267
|
var import_transactions3 = require("@fuel-ts/transactions");
|
1198
|
-
var
|
1268
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1199
1269
|
var import_utils5 = require("@fuel-ts/utils");
|
1200
|
-
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") ===
|
1270
|
+
var doesReceiptHaveMissingOutputVariables = (receipt) => receipt.type === import_transactions3.ReceiptType.Revert && receipt.val.toString("hex") === import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL;
|
1201
1271
|
var doesReceiptHaveMissingContractId = (receipt) => receipt.type === import_transactions3.ReceiptType.Panic && receipt.contractId !== "0x0000000000000000000000000000000000000000000000000000000000000000";
|
1202
1272
|
var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
1203
1273
|
(memo, receipt) => {
|
@@ -1214,15 +1284,15 @@ var getReceiptsWithMissingData = (receipts) => receipts.reduce(
|
|
1214
1284
|
missingOutputContractIds: []
|
1215
1285
|
}
|
1216
1286
|
);
|
1217
|
-
var hexOrZero = (hex) => hex ||
|
1287
|
+
var hexOrZero = (hex) => hex || import_configs4.ZeroBytes32;
|
1218
1288
|
function assembleReceiptByType(receipt) {
|
1219
1289
|
const { receiptType } = receipt;
|
1220
1290
|
switch (receiptType) {
|
1221
1291
|
case "CALL" /* Call */: {
|
1222
1292
|
const callReceipt = {
|
1223
1293
|
type: import_transactions3.ReceiptType.Call,
|
1224
|
-
from: hexOrZero(receipt.
|
1225
|
-
to: hexOrZero(receipt?.to
|
1294
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1295
|
+
to: hexOrZero(receipt?.to),
|
1226
1296
|
amount: (0, import_math4.bn)(receipt.amount),
|
1227
1297
|
assetId: hexOrZero(receipt.assetId),
|
1228
1298
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1236,7 +1306,7 @@ function assembleReceiptByType(receipt) {
|
|
1236
1306
|
case "RETURN" /* Return */: {
|
1237
1307
|
const returnReceipt = {
|
1238
1308
|
type: import_transactions3.ReceiptType.Return,
|
1239
|
-
id: hexOrZero(receipt.
|
1309
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1240
1310
|
val: (0, import_math4.bn)(receipt.val),
|
1241
1311
|
pc: (0, import_math4.bn)(receipt.pc),
|
1242
1312
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1246,7 +1316,7 @@ function assembleReceiptByType(receipt) {
|
|
1246
1316
|
case "RETURN_DATA" /* ReturnData */: {
|
1247
1317
|
const returnDataReceipt = {
|
1248
1318
|
type: import_transactions3.ReceiptType.ReturnData,
|
1249
|
-
id: hexOrZero(receipt.
|
1319
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1250
1320
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1251
1321
|
len: (0, import_math4.bn)(receipt.len),
|
1252
1322
|
digest: hexOrZero(receipt.digest),
|
@@ -1258,7 +1328,7 @@ function assembleReceiptByType(receipt) {
|
|
1258
1328
|
case "PANIC" /* Panic */: {
|
1259
1329
|
const panicReceipt = {
|
1260
1330
|
type: import_transactions3.ReceiptType.Panic,
|
1261
|
-
id: hexOrZero(receipt.
|
1331
|
+
id: hexOrZero(receipt.id),
|
1262
1332
|
reason: (0, import_math4.bn)(receipt.reason),
|
1263
1333
|
pc: (0, import_math4.bn)(receipt.pc),
|
1264
1334
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1269,7 +1339,7 @@ function assembleReceiptByType(receipt) {
|
|
1269
1339
|
case "REVERT" /* Revert */: {
|
1270
1340
|
const revertReceipt = {
|
1271
1341
|
type: import_transactions3.ReceiptType.Revert,
|
1272
|
-
id: hexOrZero(receipt.
|
1342
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1273
1343
|
val: (0, import_math4.bn)(receipt.ra),
|
1274
1344
|
pc: (0, import_math4.bn)(receipt.pc),
|
1275
1345
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1279,7 +1349,7 @@ function assembleReceiptByType(receipt) {
|
|
1279
1349
|
case "LOG" /* Log */: {
|
1280
1350
|
const logReceipt = {
|
1281
1351
|
type: import_transactions3.ReceiptType.Log,
|
1282
|
-
id: hexOrZero(receipt.
|
1352
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1283
1353
|
val0: (0, import_math4.bn)(receipt.ra),
|
1284
1354
|
val1: (0, import_math4.bn)(receipt.rb),
|
1285
1355
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1292,7 +1362,7 @@ function assembleReceiptByType(receipt) {
|
|
1292
1362
|
case "LOG_DATA" /* LogData */: {
|
1293
1363
|
const logDataReceipt = {
|
1294
1364
|
type: import_transactions3.ReceiptType.LogData,
|
1295
|
-
id: hexOrZero(receipt.
|
1365
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1296
1366
|
val0: (0, import_math4.bn)(receipt.ra),
|
1297
1367
|
val1: (0, import_math4.bn)(receipt.rb),
|
1298
1368
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1306,8 +1376,8 @@ function assembleReceiptByType(receipt) {
|
|
1306
1376
|
case "TRANSFER" /* Transfer */: {
|
1307
1377
|
const transferReceipt = {
|
1308
1378
|
type: import_transactions3.ReceiptType.Transfer,
|
1309
|
-
from: hexOrZero(receipt.
|
1310
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1379
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1380
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1311
1381
|
amount: (0, import_math4.bn)(receipt.amount),
|
1312
1382
|
assetId: hexOrZero(receipt.assetId),
|
1313
1383
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1318,8 +1388,8 @@ function assembleReceiptByType(receipt) {
|
|
1318
1388
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1319
1389
|
const transferOutReceipt = {
|
1320
1390
|
type: import_transactions3.ReceiptType.TransferOut,
|
1321
|
-
from: hexOrZero(receipt.
|
1322
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1391
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1392
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1323
1393
|
amount: (0, import_math4.bn)(receipt.amount),
|
1324
1394
|
assetId: hexOrZero(receipt.assetId),
|
1325
1395
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1362,7 +1432,7 @@ function assembleReceiptByType(receipt) {
|
|
1362
1432
|
return receiptMessageOut;
|
1363
1433
|
}
|
1364
1434
|
case "MINT" /* Mint */: {
|
1365
|
-
const contractId = hexOrZero(receipt.
|
1435
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1366
1436
|
const subId = hexOrZero(receipt.subId);
|
1367
1437
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1368
1438
|
const mintReceipt = {
|
@@ -1377,7 +1447,7 @@ function assembleReceiptByType(receipt) {
|
|
1377
1447
|
return mintReceipt;
|
1378
1448
|
}
|
1379
1449
|
case "BURN" /* Burn */: {
|
1380
|
-
const contractId = hexOrZero(receipt.
|
1450
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1381
1451
|
const subId = hexOrZero(receipt.subId);
|
1382
1452
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1383
1453
|
const burnReceipt = {
|
@@ -1403,7 +1473,6 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1403
1473
|
var import_math5 = require("@fuel-ts/math");
|
1404
1474
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1405
1475
|
var import_utils6 = require("@fuel-ts/utils");
|
1406
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1407
1476
|
var getGasUsedFromReceipts = (receipts) => {
|
1408
1477
|
const scriptResult = receipts.filter(
|
1409
1478
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1424,18 +1493,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1424
1493
|
}
|
1425
1494
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1426
1495
|
const witnessCache = [];
|
1427
|
-
const
|
1496
|
+
const chargeableInputs = inputs.filter((input) => {
|
1497
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1498
|
+
if (isCoinOrMessage) {
|
1499
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1500
|
+
return true;
|
1501
|
+
}
|
1502
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1503
|
+
witnessCache.push(input.witnessIndex);
|
1504
|
+
return true;
|
1505
|
+
}
|
1506
|
+
}
|
1507
|
+
return false;
|
1508
|
+
});
|
1509
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1510
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1428
1511
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1429
1512
|
return total.add(
|
1430
|
-
|
1513
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1431
1514
|
);
|
1432
1515
|
}
|
1433
|
-
|
1434
|
-
|
1435
|
-
return total.add(gasCosts.ecr1);
|
1436
|
-
}
|
1437
|
-
return total;
|
1438
|
-
}, (0, import_math5.bn)());
|
1516
|
+
return total.add(gasCosts.ecr1);
|
1517
|
+
}, (0, import_math5.bn)(0));
|
1439
1518
|
return totalGas;
|
1440
1519
|
}
|
1441
1520
|
function getMinGas(params) {
|
@@ -1447,12 +1526,20 @@ function getMinGas(params) {
|
|
1447
1526
|
return minGas;
|
1448
1527
|
}
|
1449
1528
|
function getMaxGas(params) {
|
1450
|
-
const {
|
1529
|
+
const {
|
1530
|
+
gasPerByte,
|
1531
|
+
witnessesLength,
|
1532
|
+
witnessLimit,
|
1533
|
+
minGas,
|
1534
|
+
gasLimit = (0, import_math5.bn)(0),
|
1535
|
+
maxGasPerTx
|
1536
|
+
} = params;
|
1451
1537
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1452
1538
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1453
1539
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1454
1540
|
}
|
1455
|
-
|
1541
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1542
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1456
1543
|
}
|
1457
1544
|
function calculateMetadataGasForTxCreate({
|
1458
1545
|
gasCosts,
|
@@ -1474,6 +1561,10 @@ function calculateMetadataGasForTxScript({
|
|
1474
1561
|
}) {
|
1475
1562
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1476
1563
|
}
|
1564
|
+
var calculateGasFee = (params) => {
|
1565
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1566
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1567
|
+
};
|
1477
1568
|
|
1478
1569
|
// src/providers/utils/json.ts
|
1479
1570
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1519,16 +1610,16 @@ function sleep(time) {
|
|
1519
1610
|
var import_errors7 = require("@fuel-ts/errors");
|
1520
1611
|
var import_math6 = require("@fuel-ts/math");
|
1521
1612
|
var import_transactions5 = require("@fuel-ts/transactions");
|
1522
|
-
var
|
1613
|
+
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1523
1614
|
var assemblePanicError = (status) => {
|
1524
1615
|
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1525
1616
|
const reason = status.reason;
|
1526
|
-
if (
|
1617
|
+
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1527
1618
|
errorMessage = `${errorMessage}
|
1528
1619
|
|
1529
1620
|
You can read more about this error at:
|
1530
1621
|
|
1531
|
-
${
|
1622
|
+
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1532
1623
|
}
|
1533
1624
|
return { errorMessage, reason };
|
1534
1625
|
};
|
@@ -1540,28 +1631,28 @@ var assembleRevertError = (receipts, logs) => {
|
|
1540
1631
|
if (revertReceipt) {
|
1541
1632
|
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1542
1633
|
switch (reasonHex) {
|
1543
|
-
case
|
1634
|
+
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1544
1635
|
reason = "require";
|
1545
1636
|
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1546
1637
|
break;
|
1547
1638
|
}
|
1548
|
-
case
|
1639
|
+
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1549
1640
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1550
1641
|
reason = "assert_eq";
|
1551
1642
|
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1552
1643
|
break;
|
1553
1644
|
}
|
1554
|
-
case
|
1645
|
+
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1555
1646
|
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1556
1647
|
reason = "assert_ne";
|
1557
1648
|
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1558
1649
|
break;
|
1559
1650
|
}
|
1560
|
-
case
|
1651
|
+
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1561
1652
|
reason = "assert";
|
1562
1653
|
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1563
1654
|
break;
|
1564
|
-
case
|
1655
|
+
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1565
1656
|
reason = "MissingOutputChange";
|
1566
1657
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1567
1658
|
break;
|
@@ -1610,7 +1701,7 @@ var witnessify = (value) => {
|
|
1610
1701
|
// src/providers/transaction-request/transaction-request.ts
|
1611
1702
|
var BaseTransactionRequest = class {
|
1612
1703
|
/** Gas price for transaction */
|
1613
|
-
|
1704
|
+
tip;
|
1614
1705
|
/** Block until which tx cannot be included */
|
1615
1706
|
maturity;
|
1616
1707
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1623,38 +1714,34 @@ var BaseTransactionRequest = class {
|
|
1623
1714
|
outputs = [];
|
1624
1715
|
/** List of witnesses */
|
1625
1716
|
witnesses = [];
|
1626
|
-
/** Base asset ID - should be fetched from the chain */
|
1627
|
-
baseAssetId;
|
1628
1717
|
/**
|
1629
1718
|
* Constructor for initializing a base transaction request.
|
1630
1719
|
*
|
1631
1720
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1632
1721
|
*/
|
1633
1722
|
constructor({
|
1634
|
-
|
1723
|
+
tip,
|
1635
1724
|
maturity,
|
1636
1725
|
maxFee,
|
1637
1726
|
witnessLimit,
|
1638
1727
|
inputs,
|
1639
1728
|
outputs,
|
1640
|
-
witnesses
|
1641
|
-
|
1642
|
-
|
1643
|
-
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1729
|
+
witnesses
|
1730
|
+
} = {}) {
|
1731
|
+
this.tip = (0, import_math7.bn)(tip);
|
1644
1732
|
this.maturity = maturity ?? 0;
|
1645
1733
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1646
1734
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1647
1735
|
this.inputs = inputs ?? [];
|
1648
1736
|
this.outputs = outputs ?? [];
|
1649
1737
|
this.witnesses = witnesses ?? [];
|
1650
|
-
this.baseAssetId = baseAssetId;
|
1651
1738
|
}
|
1652
1739
|
static getPolicyMeta(req) {
|
1653
1740
|
let policyTypes = 0;
|
1654
1741
|
const policies = [];
|
1655
|
-
if (req.
|
1656
|
-
policyTypes += import_transactions6.PolicyType.
|
1657
|
-
policies.push({ data: req.
|
1742
|
+
if (req.tip) {
|
1743
|
+
policyTypes += import_transactions6.PolicyType.Tip;
|
1744
|
+
policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
|
1658
1745
|
}
|
1659
1746
|
if (req.witnessLimit) {
|
1660
1747
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -1740,7 +1827,7 @@ var BaseTransactionRequest = class {
|
|
1740
1827
|
* @returns The index of the created witness.
|
1741
1828
|
*/
|
1742
1829
|
addEmptyWitness() {
|
1743
|
-
this.addWitness((0, import_utils9.concat)([
|
1830
|
+
this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
|
1744
1831
|
return this.witnesses.length - 1;
|
1745
1832
|
}
|
1746
1833
|
/**
|
@@ -1841,10 +1928,10 @@ var BaseTransactionRequest = class {
|
|
1841
1928
|
* @param predicate - Predicate bytes.
|
1842
1929
|
* @param predicateData - Predicate data bytes.
|
1843
1930
|
*/
|
1844
|
-
addCoinInput(coin
|
1931
|
+
addCoinInput(coin) {
|
1845
1932
|
const { assetId, owner, amount } = coin;
|
1846
1933
|
let witnessIndex;
|
1847
|
-
if (predicate) {
|
1934
|
+
if (coin.predicate) {
|
1848
1935
|
witnessIndex = 0;
|
1849
1936
|
} else {
|
1850
1937
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1859,8 +1946,7 @@ var BaseTransactionRequest = class {
|
|
1859
1946
|
amount,
|
1860
1947
|
assetId,
|
1861
1948
|
txPointer: "0x00000000000000000000000000000000",
|
1862
|
-
witnessIndex
|
1863
|
-
predicate: predicate?.bytes
|
1949
|
+
witnessIndex
|
1864
1950
|
};
|
1865
1951
|
this.pushInput(input);
|
1866
1952
|
this.addChangeOutput(owner, assetId);
|
@@ -1871,11 +1957,13 @@ var BaseTransactionRequest = class {
|
|
1871
1957
|
*
|
1872
1958
|
* @param message - Message resource.
|
1873
1959
|
* @param predicate - Predicate bytes.
|
1960
|
+
* @param predicateData - Predicate data bytes.
|
1874
1961
|
*/
|
1875
|
-
addMessageInput(message
|
1962
|
+
addMessageInput(message) {
|
1876
1963
|
const { recipient, sender, amount } = message;
|
1964
|
+
const assetId = import_configs7.BaseAssetId;
|
1877
1965
|
let witnessIndex;
|
1878
|
-
if (predicate) {
|
1966
|
+
if (message.predicate) {
|
1879
1967
|
witnessIndex = 0;
|
1880
1968
|
} else {
|
1881
1969
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1889,11 +1977,10 @@ var BaseTransactionRequest = class {
|
|
1889
1977
|
sender: sender.toB256(),
|
1890
1978
|
recipient: recipient.toB256(),
|
1891
1979
|
amount,
|
1892
|
-
witnessIndex
|
1893
|
-
predicate: predicate?.bytes
|
1980
|
+
witnessIndex
|
1894
1981
|
};
|
1895
1982
|
this.pushInput(input);
|
1896
|
-
this.addChangeOutput(recipient,
|
1983
|
+
this.addChangeOutput(recipient, assetId);
|
1897
1984
|
}
|
1898
1985
|
/**
|
1899
1986
|
* Adds a single resource to the transaction by adding a coin/message input and a
|
@@ -1921,32 +2008,6 @@ var BaseTransactionRequest = class {
|
|
1921
2008
|
resources.forEach((resource) => this.addResource(resource));
|
1922
2009
|
return this;
|
1923
2010
|
}
|
1924
|
-
/**
|
1925
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1926
|
-
* outputs from the related assetIds.
|
1927
|
-
*
|
1928
|
-
* @param resources - The resources to add.
|
1929
|
-
* @returns This transaction.
|
1930
|
-
*/
|
1931
|
-
addPredicateResource(resource, predicate) {
|
1932
|
-
if (isCoin(resource)) {
|
1933
|
-
this.addCoinInput(resource, predicate);
|
1934
|
-
} else {
|
1935
|
-
this.addMessageInput(resource, predicate);
|
1936
|
-
}
|
1937
|
-
return this;
|
1938
|
-
}
|
1939
|
-
/**
|
1940
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1941
|
-
* from the related assetIds.
|
1942
|
-
*
|
1943
|
-
* @param resources - The resources to add.
|
1944
|
-
* @returns This transaction.
|
1945
|
-
*/
|
1946
|
-
addPredicateResources(resources, predicate) {
|
1947
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1948
|
-
return this;
|
1949
|
-
}
|
1950
2011
|
/**
|
1951
2012
|
* Adds a coin output to the transaction.
|
1952
2013
|
*
|
@@ -1954,12 +2015,12 @@ var BaseTransactionRequest = class {
|
|
1954
2015
|
* @param amount - Amount of coin.
|
1955
2016
|
* @param assetId - Asset ID of coin.
|
1956
2017
|
*/
|
1957
|
-
addCoinOutput(to, amount, assetId) {
|
2018
|
+
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
1958
2019
|
this.pushOutput({
|
1959
2020
|
type: import_transactions6.OutputType.Coin,
|
1960
2021
|
to: (0, import_address.addressify)(to).toB256(),
|
1961
2022
|
amount,
|
1962
|
-
assetId
|
2023
|
+
assetId
|
1963
2024
|
});
|
1964
2025
|
return this;
|
1965
2026
|
}
|
@@ -1986,7 +2047,7 @@ var BaseTransactionRequest = class {
|
|
1986
2047
|
* @param to - Address of the owner.
|
1987
2048
|
* @param assetId - Asset ID of coin.
|
1988
2049
|
*/
|
1989
|
-
addChangeOutput(to, assetId) {
|
2050
|
+
addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
|
1990
2051
|
const changeOutput = this.getChangeOutputs().find(
|
1991
2052
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
1992
2053
|
);
|
@@ -1994,7 +2055,7 @@ var BaseTransactionRequest = class {
|
|
1994
2055
|
this.pushOutput({
|
1995
2056
|
type: import_transactions6.OutputType.Change,
|
1996
2057
|
to: (0, import_address.addressify)(to).toB256(),
|
1997
|
-
assetId
|
2058
|
+
assetId
|
1998
2059
|
});
|
1999
2060
|
}
|
2000
2061
|
}
|
@@ -2026,7 +2087,7 @@ var BaseTransactionRequest = class {
|
|
2026
2087
|
}
|
2027
2088
|
calculateMaxGas(chainInfo, minGas) {
|
2028
2089
|
const { consensusParameters } = chainInfo;
|
2029
|
-
const { gasPerByte } = consensusParameters;
|
2090
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2030
2091
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2031
2092
|
(acc, wit) => acc + wit.dataLength,
|
2032
2093
|
0
|
@@ -2035,7 +2096,8 @@ var BaseTransactionRequest = class {
|
|
2035
2096
|
gasPerByte,
|
2036
2097
|
minGas,
|
2037
2098
|
witnessesLength,
|
2038
|
-
witnessLimit: this.witnessLimit
|
2099
|
+
witnessLimit: this.witnessLimit,
|
2100
|
+
maxGasPerTx
|
2039
2101
|
});
|
2040
2102
|
}
|
2041
2103
|
/**
|
@@ -2045,12 +2107,6 @@ var BaseTransactionRequest = class {
|
|
2045
2107
|
* @param quantities - CoinQuantity Array.
|
2046
2108
|
*/
|
2047
2109
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
2048
|
-
let idCounter = 0;
|
2049
|
-
const generateId = () => {
|
2050
|
-
const counterString = String(idCounter++);
|
2051
|
-
const id = import_configs6.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2052
|
-
return id;
|
2053
|
-
};
|
2054
2110
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
2055
2111
|
if ("assetId" in input) {
|
2056
2112
|
return input.assetId === assetId;
|
@@ -2059,24 +2115,27 @@ var BaseTransactionRequest = class {
|
|
2059
2115
|
});
|
2060
2116
|
const updateAssetInput = (assetId, quantity) => {
|
2061
2117
|
const assetInput = findAssetInput(assetId);
|
2118
|
+
let usedQuantity = quantity;
|
2119
|
+
if (assetId === import_configs7.BaseAssetId) {
|
2120
|
+
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2121
|
+
}
|
2062
2122
|
if (assetInput && "assetId" in assetInput) {
|
2063
|
-
assetInput.id =
|
2064
|
-
assetInput.amount =
|
2123
|
+
assetInput.id = (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(34));
|
2124
|
+
assetInput.amount = usedQuantity;
|
2065
2125
|
} else {
|
2066
2126
|
this.addResources([
|
2067
2127
|
{
|
2068
|
-
id:
|
2069
|
-
amount:
|
2128
|
+
id: (0, import_utils9.hexlify)((0, import_ethers.randomBytes)(34)),
|
2129
|
+
amount: usedQuantity,
|
2070
2130
|
assetId,
|
2071
2131
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2072
|
-
maturity: 0,
|
2073
2132
|
blockCreated: (0, import_math7.bn)(1),
|
2074
2133
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2075
2134
|
}
|
2076
2135
|
]);
|
2077
2136
|
}
|
2078
2137
|
};
|
2079
|
-
updateAssetInput(
|
2138
|
+
updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
|
2080
2139
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2081
2140
|
}
|
2082
2141
|
/**
|
@@ -2101,7 +2160,7 @@ var BaseTransactionRequest = class {
|
|
2101
2160
|
toJSON() {
|
2102
2161
|
return normalizeJSON(this);
|
2103
2162
|
}
|
2104
|
-
|
2163
|
+
updatePredicateGasUsed(inputs) {
|
2105
2164
|
this.inputs.forEach((i) => {
|
2106
2165
|
let correspondingInput;
|
2107
2166
|
switch (i.type) {
|
@@ -2123,16 +2182,25 @@ var BaseTransactionRequest = class {
|
|
2123
2182
|
}
|
2124
2183
|
});
|
2125
2184
|
}
|
2185
|
+
shiftPredicateData() {
|
2186
|
+
this.inputs.forEach((input) => {
|
2187
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2188
|
+
input.predicateData = input.paddPredicateData(
|
2189
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2190
|
+
);
|
2191
|
+
}
|
2192
|
+
});
|
2193
|
+
}
|
2126
2194
|
};
|
2127
2195
|
|
2128
2196
|
// src/providers/transaction-request/create-transaction-request.ts
|
2129
|
-
var
|
2197
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2130
2198
|
var import_math9 = require("@fuel-ts/math");
|
2131
2199
|
var import_transactions8 = require("@fuel-ts/transactions");
|
2132
2200
|
var import_utils13 = require("@fuel-ts/utils");
|
2133
2201
|
|
2134
2202
|
// src/providers/transaction-request/hash-transaction.ts
|
2135
|
-
var
|
2203
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2136
2204
|
var import_hasher = require("@fuel-ts/hasher");
|
2137
2205
|
var import_math8 = require("@fuel-ts/math");
|
2138
2206
|
var import_transactions7 = require("@fuel-ts/transactions");
|
@@ -2141,7 +2209,7 @@ var import_ramda2 = require("ramda");
|
|
2141
2209
|
function hashTransaction(transactionRequest, chainId) {
|
2142
2210
|
const transaction = transactionRequest.toTransaction();
|
2143
2211
|
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2144
|
-
transaction.receiptsRoot =
|
2212
|
+
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2145
2213
|
}
|
2146
2214
|
transaction.inputs = transaction.inputs.map((input) => {
|
2147
2215
|
const inputClone = (0, import_ramda2.clone)(input);
|
@@ -2163,10 +2231,10 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2163
2231
|
blockHeight: 0,
|
2164
2232
|
txIndex: 0
|
2165
2233
|
};
|
2166
|
-
inputClone.txID =
|
2234
|
+
inputClone.txID = import_configs8.ZeroBytes32;
|
2167
2235
|
inputClone.outputIndex = 0;
|
2168
|
-
inputClone.balanceRoot =
|
2169
|
-
inputClone.stateRoot =
|
2236
|
+
inputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2237
|
+
inputClone.stateRoot = import_configs8.ZeroBytes32;
|
2170
2238
|
return inputClone;
|
2171
2239
|
}
|
2172
2240
|
default:
|
@@ -2177,8 +2245,8 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2177
2245
|
const outputClone = (0, import_ramda2.clone)(output);
|
2178
2246
|
switch (outputClone.type) {
|
2179
2247
|
case import_transactions7.OutputType.Contract: {
|
2180
|
-
outputClone.balanceRoot =
|
2181
|
-
outputClone.stateRoot =
|
2248
|
+
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2249
|
+
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2182
2250
|
return outputClone;
|
2183
2251
|
}
|
2184
2252
|
case import_transactions7.OutputType.Change: {
|
@@ -2186,9 +2254,9 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2186
2254
|
return outputClone;
|
2187
2255
|
}
|
2188
2256
|
case import_transactions7.OutputType.Variable: {
|
2189
|
-
outputClone.to =
|
2257
|
+
outputClone.to = import_configs8.ZeroBytes32;
|
2190
2258
|
outputClone.amount = (0, import_math8.bn)(0);
|
2191
|
-
outputClone.assetId =
|
2259
|
+
outputClone.assetId = import_configs8.ZeroBytes32;
|
2192
2260
|
return outputClone;
|
2193
2261
|
}
|
2194
2262
|
default:
|
@@ -2246,10 +2314,15 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2246
2314
|
*
|
2247
2315
|
* @param createTransactionRequestLike - The initial values for the instance
|
2248
2316
|
*/
|
2249
|
-
constructor({
|
2317
|
+
constructor({
|
2318
|
+
bytecodeWitnessIndex,
|
2319
|
+
salt,
|
2320
|
+
storageSlots,
|
2321
|
+
...rest
|
2322
|
+
} = {}) {
|
2250
2323
|
super(rest);
|
2251
2324
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2252
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2325
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
|
2253
2326
|
this.storageSlots = [...storageSlots ?? []];
|
2254
2327
|
}
|
2255
2328
|
/**
|
@@ -2264,10 +2337,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2264
2337
|
return {
|
2265
2338
|
type: import_transactions8.TransactionType.Create,
|
2266
2339
|
...baseTransaction,
|
2267
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2268
2340
|
bytecodeWitnessIndex,
|
2269
|
-
storageSlotsCount: storageSlots.length,
|
2270
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2341
|
+
storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
|
2342
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2271
2343
|
storageSlots
|
2272
2344
|
};
|
2273
2345
|
}
|
@@ -2317,7 +2389,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2317
2389
|
// src/providers/transaction-request/script-transaction-request.ts
|
2318
2390
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2319
2391
|
var import_address2 = require("@fuel-ts/address");
|
2320
|
-
var
|
2392
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2321
2393
|
var import_math10 = require("@fuel-ts/math");
|
2322
2394
|
var import_transactions9 = require("@fuel-ts/transactions");
|
2323
2395
|
var import_utils15 = require("@fuel-ts/utils");
|
@@ -2370,7 +2442,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2370
2442
|
*
|
2371
2443
|
* @param scriptTransactionRequestLike - The initial values for the instance.
|
2372
2444
|
*/
|
2373
|
-
constructor({ script, scriptData, gasLimit, ...rest }) {
|
2445
|
+
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2374
2446
|
super(rest);
|
2375
2447
|
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2376
2448
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
@@ -2389,9 +2461,9 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2389
2461
|
type: import_transactions9.TransactionType.Script,
|
2390
2462
|
scriptGasLimit: this.gasLimit,
|
2391
2463
|
...super.getBaseTransaction(),
|
2392
|
-
scriptLength: script.length,
|
2393
|
-
scriptDataLength: scriptData.length,
|
2394
|
-
receiptsRoot:
|
2464
|
+
scriptLength: (0, import_math10.bn)(script.length),
|
2465
|
+
scriptDataLength: (0, import_math10.bn)(scriptData.length),
|
2466
|
+
receiptsRoot: import_configs10.ZeroBytes32,
|
2395
2467
|
script: (0, import_utils15.hexlify)(script),
|
2396
2468
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2397
2469
|
};
|
@@ -2454,7 +2526,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2454
2526
|
}
|
2455
2527
|
calculateMaxGas(chainInfo, minGas) {
|
2456
2528
|
const { consensusParameters } = chainInfo;
|
2457
|
-
const { gasPerByte } = consensusParameters;
|
2529
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2458
2530
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2459
2531
|
(acc, wit) => acc + wit.dataLength,
|
2460
2532
|
0
|
@@ -2464,7 +2536,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2464
2536
|
minGas,
|
2465
2537
|
witnessesLength,
|
2466
2538
|
witnessLimit: this.witnessLimit,
|
2467
|
-
gasLimit: this.gasLimit
|
2539
|
+
gasLimit: this.gasLimit,
|
2540
|
+
maxGasPerTx
|
2468
2541
|
});
|
2469
2542
|
}
|
2470
2543
|
/**
|
@@ -2539,15 +2612,32 @@ var transactionRequestify = (obj) => {
|
|
2539
2612
|
}
|
2540
2613
|
}
|
2541
2614
|
};
|
2615
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2616
|
+
(acc, input) => {
|
2617
|
+
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2618
|
+
acc.utxos.push(input.id);
|
2619
|
+
}
|
2620
|
+
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2621
|
+
acc.messages.push(input.nonce);
|
2622
|
+
}
|
2623
|
+
return acc;
|
2624
|
+
},
|
2625
|
+
{
|
2626
|
+
utxos: [],
|
2627
|
+
messages: []
|
2628
|
+
}
|
2629
|
+
);
|
2542
2630
|
|
2543
2631
|
// src/providers/transaction-response/transaction-response.ts
|
2544
2632
|
var import_errors13 = require("@fuel-ts/errors");
|
2545
|
-
var
|
2546
|
-
var
|
2547
|
-
var
|
2633
|
+
var import_math15 = require("@fuel-ts/math");
|
2634
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
2635
|
+
var import_utils20 = require("@fuel-ts/utils");
|
2548
2636
|
|
2549
2637
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2550
|
-
var
|
2638
|
+
var import_math14 = require("@fuel-ts/math");
|
2639
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2640
|
+
var import_utils18 = require("@fuel-ts/utils");
|
2551
2641
|
|
2552
2642
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2553
2643
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2555,9 +2645,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2555
2645
|
var import_utils16 = require("@fuel-ts/utils");
|
2556
2646
|
var calculateTransactionFee = (params) => {
|
2557
2647
|
const {
|
2558
|
-
|
2648
|
+
gasPrice,
|
2559
2649
|
rawPayload,
|
2560
|
-
|
2650
|
+
tip,
|
2651
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2561
2652
|
} = params;
|
2562
2653
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2563
2654
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2567,8 +2658,7 @@ var calculateTransactionFee = (params) => {
|
|
2567
2658
|
return {
|
2568
2659
|
fee: (0, import_math11.bn)(0),
|
2569
2660
|
minFee: (0, import_math11.bn)(0),
|
2570
|
-
maxFee: (0, import_math11.bn)(0)
|
2571
|
-
feeFromGasUsed: (0, import_math11.bn)(0)
|
2661
|
+
maxFee: (0, import_math11.bn)(0)
|
2572
2662
|
};
|
2573
2663
|
}
|
2574
2664
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2600,7 +2690,6 @@ var calculateTransactionFee = (params) => {
|
|
2600
2690
|
metadataGas,
|
2601
2691
|
txBytesSize: transactionBytes.length
|
2602
2692
|
});
|
2603
|
-
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2604
2693
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2605
2694
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2606
2695
|
const maxGas = getMaxGas({
|
@@ -2608,22 +2697,30 @@ var calculateTransactionFee = (params) => {
|
|
2608
2697
|
minGas,
|
2609
2698
|
witnessesLength,
|
2610
2699
|
gasLimit,
|
2611
|
-
witnessLimit
|
2700
|
+
witnessLimit,
|
2701
|
+
maxGasPerTx
|
2702
|
+
});
|
2703
|
+
const minFee = calculateGasFee({
|
2704
|
+
gasPrice,
|
2705
|
+
gas: minGas,
|
2706
|
+
priceFactor: gasPriceFactor,
|
2707
|
+
tip
|
2708
|
+
});
|
2709
|
+
const maxFee = calculateGasFee({
|
2710
|
+
gasPrice,
|
2711
|
+
gas: maxGas,
|
2712
|
+
priceFactor: gasPriceFactor,
|
2713
|
+
tip
|
2612
2714
|
});
|
2613
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2614
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2615
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2616
|
-
const fee = minFee.add(feeFromGasUsed);
|
2617
2715
|
return {
|
2618
|
-
fee,
|
2619
2716
|
minFee,
|
2620
2717
|
maxFee,
|
2621
|
-
|
2718
|
+
fee: maxFee
|
2622
2719
|
};
|
2623
2720
|
};
|
2624
2721
|
|
2625
2722
|
// src/providers/transaction-summary/operations.ts
|
2626
|
-
var
|
2723
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
2627
2724
|
var import_errors11 = require("@fuel-ts/errors");
|
2628
2725
|
var import_math13 = require("@fuel-ts/math");
|
2629
2726
|
var import_transactions14 = require("@fuel-ts/transactions");
|
@@ -2921,7 +3018,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
2921
3018
|
const { to: toAddress, assetId, amount } = receipt;
|
2922
3019
|
let { from: fromAddress } = receipt;
|
2923
3020
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2924
|
-
if (
|
3021
|
+
if (import_configs11.ZeroBytes32 === fromAddress) {
|
2925
3022
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2926
3023
|
fromAddress = change?.to || fromAddress;
|
2927
3024
|
}
|
@@ -3185,10 +3282,12 @@ function assembleTransactionSummary(params) {
|
|
3185
3282
|
gqlTransactionStatus,
|
3186
3283
|
abiMap = {},
|
3187
3284
|
maxInputs,
|
3188
|
-
gasCosts
|
3285
|
+
gasCosts,
|
3286
|
+
maxGasPerTx,
|
3287
|
+
gasPrice
|
3189
3288
|
} = params;
|
3190
3289
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3191
|
-
const rawPayload = (0,
|
3290
|
+
const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
|
3192
3291
|
const operations = getOperations({
|
3193
3292
|
transactionType: transaction.type,
|
3194
3293
|
inputs: transaction.inputs || [],
|
@@ -3199,11 +3298,14 @@ function assembleTransactionSummary(params) {
|
|
3199
3298
|
maxInputs
|
3200
3299
|
});
|
3201
3300
|
const typeName = getTransactionTypeName(transaction.type);
|
3301
|
+
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3202
3302
|
const { fee } = calculateTransactionFee({
|
3203
|
-
|
3303
|
+
gasPrice,
|
3204
3304
|
rawPayload,
|
3305
|
+
tip,
|
3205
3306
|
consensusParameters: {
|
3206
3307
|
gasCosts,
|
3308
|
+
maxGasPerTx,
|
3207
3309
|
feeParams: {
|
3208
3310
|
gasPerByte,
|
3209
3311
|
gasPriceFactor
|
@@ -3215,7 +3317,7 @@ function assembleTransactionSummary(params) {
|
|
3215
3317
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3216
3318
|
let date;
|
3217
3319
|
if (time) {
|
3218
|
-
date =
|
3320
|
+
date = import_utils18.DateTime.fromTai64(time);
|
3219
3321
|
}
|
3220
3322
|
const transactionSummary = {
|
3221
3323
|
id,
|
@@ -3243,12 +3345,12 @@ function assembleTransactionSummary(params) {
|
|
3243
3345
|
|
3244
3346
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3245
3347
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3246
|
-
var
|
3348
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
3247
3349
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3248
3350
|
return receipts.reduce((logs, receipt) => {
|
3249
|
-
if (receipt.type ===
|
3351
|
+
if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
|
3250
3352
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3251
|
-
const data = receipt.type ===
|
3353
|
+
const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3252
3354
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3253
3355
|
logs.push(decodedLog);
|
3254
3356
|
}
|
@@ -3263,7 +3365,7 @@ var TransactionResponse = class {
|
|
3263
3365
|
/** Current provider */
|
3264
3366
|
provider;
|
3265
3367
|
/** Gas used on the transaction */
|
3266
|
-
gasUsed = (0,
|
3368
|
+
gasUsed = (0, import_math15.bn)(0);
|
3267
3369
|
/** The graphql Transaction with receipts object. */
|
3268
3370
|
gqlTransaction;
|
3269
3371
|
abis;
|
@@ -3321,8 +3423,8 @@ var TransactionResponse = class {
|
|
3321
3423
|
* @returns The decoded transaction.
|
3322
3424
|
*/
|
3323
3425
|
decodeTransaction(transactionWithReceipts) {
|
3324
|
-
return new
|
3325
|
-
(0,
|
3426
|
+
return new import_transactions18.TransactionCoder().decode(
|
3427
|
+
(0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
|
3326
3428
|
0
|
3327
3429
|
)?.[0];
|
3328
3430
|
}
|
@@ -3341,20 +3443,27 @@ var TransactionResponse = class {
|
|
3341
3443
|
const decodedTransaction = this.decodeTransaction(
|
3342
3444
|
transaction
|
3343
3445
|
);
|
3344
|
-
|
3345
|
-
|
3446
|
+
let txReceipts = [];
|
3447
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3448
|
+
txReceipts = transaction.status.receipts;
|
3449
|
+
}
|
3450
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3451
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3452
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3346
3453
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3347
3454
|
const transactionSummary = assembleTransactionSummary({
|
3348
3455
|
id: this.id,
|
3349
3456
|
receipts,
|
3350
3457
|
transaction: decodedTransaction,
|
3351
|
-
transactionBytes: (0,
|
3458
|
+
transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
|
3352
3459
|
gqlTransactionStatus: transaction.status,
|
3353
3460
|
gasPerByte,
|
3354
3461
|
gasPriceFactor,
|
3355
3462
|
abiMap: contractsAbiMap,
|
3356
3463
|
maxInputs,
|
3357
|
-
gasCosts
|
3464
|
+
gasCosts,
|
3465
|
+
maxGasPerTx,
|
3466
|
+
gasPrice
|
3358
3467
|
});
|
3359
3468
|
return transactionSummary;
|
3360
3469
|
}
|
@@ -3481,30 +3590,29 @@ var processGqlChain = (chain) => {
|
|
3481
3590
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3482
3591
|
return {
|
3483
3592
|
name,
|
3484
|
-
baseChainHeight: (0,
|
3593
|
+
baseChainHeight: (0, import_math16.bn)(daHeight),
|
3485
3594
|
consensusParameters: {
|
3486
|
-
contractMaxSize: (0,
|
3487
|
-
maxInputs: (0,
|
3488
|
-
maxOutputs: (0,
|
3489
|
-
maxWitnesses: (0,
|
3490
|
-
maxGasPerTx: (0,
|
3491
|
-
maxScriptLength: (0,
|
3492
|
-
maxScriptDataLength: (0,
|
3493
|
-
maxStorageSlots: (0,
|
3494
|
-
maxPredicateLength: (0,
|
3495
|
-
maxPredicateDataLength: (0,
|
3496
|
-
maxGasPerPredicate: (0,
|
3497
|
-
gasPriceFactor: (0,
|
3498
|
-
gasPerByte: (0,
|
3499
|
-
maxMessageDataLength: (0,
|
3500
|
-
chainId: (0,
|
3501
|
-
baseAssetId: consensusParameters.baseAssetId,
|
3595
|
+
contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
|
3596
|
+
maxInputs: (0, import_math16.bn)(txParams.maxInputs),
|
3597
|
+
maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
|
3598
|
+
maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
|
3599
|
+
maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
|
3600
|
+
maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
|
3601
|
+
maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
|
3602
|
+
maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
|
3603
|
+
maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
|
3604
|
+
maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
|
3605
|
+
maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
|
3606
|
+
gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
|
3607
|
+
gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
|
3608
|
+
maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
|
3609
|
+
chainId: (0, import_math16.bn)(consensusParameters.chainId),
|
3502
3610
|
gasCosts
|
3503
3611
|
},
|
3504
3612
|
gasCosts,
|
3505
3613
|
latestBlock: {
|
3506
3614
|
id: latestBlock.id,
|
3507
|
-
height: (0,
|
3615
|
+
height: (0, import_math16.bn)(latestBlock.height),
|
3508
3616
|
time: latestBlock.header.time,
|
3509
3617
|
transactions: latestBlock.transactions.map((i) => ({
|
3510
3618
|
id: i.id
|
@@ -3598,10 +3706,8 @@ var _Provider = class {
|
|
3598
3706
|
* Returns some helpful parameters related to gas fees.
|
3599
3707
|
*/
|
3600
3708
|
getGasConfig() {
|
3601
|
-
const { minGasPrice } = this.getNode();
|
3602
3709
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3603
3710
|
return {
|
3604
|
-
minGasPrice,
|
3605
3711
|
maxGasPerTx,
|
3606
3712
|
maxGasPerPredicate,
|
3607
3713
|
gasPriceFactor,
|
@@ -3689,7 +3795,7 @@ var _Provider = class {
|
|
3689
3795
|
name,
|
3690
3796
|
consensusParameters: { chainId }
|
3691
3797
|
} = await this.getChain();
|
3692
|
-
const network = new
|
3798
|
+
const network = new import_ethers2.Network(name, chainId.toNumber());
|
3693
3799
|
return Promise.resolve(network);
|
3694
3800
|
}
|
3695
3801
|
/**
|
@@ -3699,7 +3805,7 @@ var _Provider = class {
|
|
3699
3805
|
*/
|
3700
3806
|
async getBlockNumber() {
|
3701
3807
|
const { chain } = await this.operations.getChain();
|
3702
|
-
return (0,
|
3808
|
+
return (0, import_math16.bn)(chain.latestBlock.height, 10);
|
3703
3809
|
}
|
3704
3810
|
/**
|
3705
3811
|
* Returns the chain information.
|
@@ -3709,13 +3815,11 @@ var _Provider = class {
|
|
3709
3815
|
async fetchNode() {
|
3710
3816
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3711
3817
|
const processedNodeInfo = {
|
3712
|
-
maxDepth: (0,
|
3713
|
-
maxTx: (0,
|
3714
|
-
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3818
|
+
maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
|
3819
|
+
maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
|
3715
3820
|
nodeVersion: nodeInfo.nodeVersion,
|
3716
3821
|
utxoValidation: nodeInfo.utxoValidation,
|
3717
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3718
|
-
peers: nodeInfo.peers
|
3822
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3719
3823
|
};
|
3720
3824
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3721
3825
|
return processedNodeInfo;
|
@@ -3741,17 +3845,6 @@ var _Provider = class {
|
|
3741
3845
|
} = this.getChain();
|
3742
3846
|
return chainId.toNumber();
|
3743
3847
|
}
|
3744
|
-
/**
|
3745
|
-
* Returns the base asset ID
|
3746
|
-
*
|
3747
|
-
* @returns A promise that resolves to the base asset ID
|
3748
|
-
*/
|
3749
|
-
getBaseAssetId() {
|
3750
|
-
const {
|
3751
|
-
consensusParameters: { baseAssetId }
|
3752
|
-
} = this.getChain();
|
3753
|
-
return baseAssetId;
|
3754
|
-
}
|
3755
3848
|
/**
|
3756
3849
|
* Submits a transaction to the chain to be executed.
|
3757
3850
|
*
|
@@ -3768,9 +3861,9 @@ var _Provider = class {
|
|
3768
3861
|
if (estimateTxDependencies) {
|
3769
3862
|
await this.estimateTxDependencies(transactionRequest);
|
3770
3863
|
}
|
3771
|
-
const encodedTransaction = (0,
|
3864
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3772
3865
|
let abis;
|
3773
|
-
if (transactionRequest.type ===
|
3866
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
3774
3867
|
abis = transactionRequest.abis;
|
3775
3868
|
}
|
3776
3869
|
if (awaitExecution) {
|
@@ -3811,15 +3904,14 @@ var _Provider = class {
|
|
3811
3904
|
if (estimateTxDependencies) {
|
3812
3905
|
return this.estimateTxDependencies(transactionRequest);
|
3813
3906
|
}
|
3814
|
-
const encodedTransaction = (0,
|
3815
|
-
const { dryRun:
|
3816
|
-
encodedTransaction,
|
3907
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3908
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3909
|
+
encodedTransactions: encodedTransaction,
|
3817
3910
|
utxoValidation: utxoValidation || false
|
3818
3911
|
});
|
3819
|
-
const receipts =
|
3820
|
-
|
3821
|
-
|
3822
|
-
};
|
3912
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3913
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3914
|
+
return { receipts, dryrunStatus: status };
|
3823
3915
|
}
|
3824
3916
|
/**
|
3825
3917
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3830,13 +3922,13 @@ var _Provider = class {
|
|
3830
3922
|
async estimatePredicates(transactionRequest) {
|
3831
3923
|
const shouldEstimatePredicates = Boolean(
|
3832
3924
|
transactionRequest.inputs.find(
|
3833
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3925
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math16.BN(input.predicateGasUsed).isZero()
|
3834
3926
|
)
|
3835
3927
|
);
|
3836
3928
|
if (!shouldEstimatePredicates) {
|
3837
3929
|
return transactionRequest;
|
3838
3930
|
}
|
3839
|
-
const encodedTransaction = (0,
|
3931
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3840
3932
|
const response = await this.operations.estimatePredicates({
|
3841
3933
|
encodedTransaction
|
3842
3934
|
});
|
@@ -3845,7 +3937,7 @@ var _Provider = class {
|
|
3845
3937
|
} = response;
|
3846
3938
|
if (inputs) {
|
3847
3939
|
inputs.forEach((input, index) => {
|
3848
|
-
if ("predicateGasUsed" in input && (0,
|
3940
|
+
if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
|
3849
3941
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3850
3942
|
}
|
3851
3943
|
});
|
@@ -3858,31 +3950,31 @@ var _Provider = class {
|
|
3858
3950
|
* If there are missing variable outputs,
|
3859
3951
|
* `addVariableOutputs` is called on the transaction.
|
3860
3952
|
*
|
3861
|
-
* @privateRemarks
|
3862
|
-
* TODO: Investigate support for missing contract IDs
|
3863
|
-
* TODO: Add support for missing output messages
|
3864
3953
|
*
|
3865
3954
|
* @param transactionRequest - The transaction request object.
|
3866
3955
|
* @returns A promise.
|
3867
3956
|
*/
|
3868
3957
|
async estimateTxDependencies(transactionRequest) {
|
3869
|
-
if (transactionRequest.type ===
|
3958
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Create) {
|
3870
3959
|
return {
|
3871
3960
|
receipts: [],
|
3872
3961
|
outputVariables: 0,
|
3873
3962
|
missingContractIds: []
|
3874
3963
|
};
|
3875
3964
|
}
|
3876
|
-
await this.estimatePredicates(transactionRequest);
|
3877
3965
|
let receipts = [];
|
3878
3966
|
const missingContractIds = [];
|
3879
3967
|
let outputVariables = 0;
|
3968
|
+
let dryrunStatus;
|
3880
3969
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3881
|
-
const {
|
3882
|
-
|
3970
|
+
const {
|
3971
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3972
|
+
} = await this.operations.dryRun({
|
3973
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3883
3974
|
utxoValidation: false
|
3884
3975
|
});
|
3885
|
-
receipts =
|
3976
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3977
|
+
dryrunStatus = status;
|
3886
3978
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3887
3979
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3888
3980
|
if (hasMissingOutputs) {
|
@@ -3892,6 +3984,11 @@ var _Provider = class {
|
|
3892
3984
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3893
3985
|
missingContractIds.push(contractId);
|
3894
3986
|
});
|
3987
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
3988
|
+
transactionRequest,
|
3989
|
+
optimizeGas: false
|
3990
|
+
});
|
3991
|
+
transactionRequest.maxFee = maxFee;
|
3895
3992
|
} else {
|
3896
3993
|
break;
|
3897
3994
|
}
|
@@ -3899,7 +3996,133 @@ var _Provider = class {
|
|
3899
3996
|
return {
|
3900
3997
|
receipts,
|
3901
3998
|
outputVariables,
|
3902
|
-
missingContractIds
|
3999
|
+
missingContractIds,
|
4000
|
+
dryrunStatus
|
4001
|
+
};
|
4002
|
+
}
|
4003
|
+
/**
|
4004
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4005
|
+
*
|
4006
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4007
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4008
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4009
|
+
*
|
4010
|
+
* @param transactionRequests - Array of transaction request objects.
|
4011
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4012
|
+
*/
|
4013
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4014
|
+
const results = transactionRequests.map(() => ({
|
4015
|
+
receipts: [],
|
4016
|
+
outputVariables: 0,
|
4017
|
+
missingContractIds: [],
|
4018
|
+
dryrunStatus: void 0
|
4019
|
+
}));
|
4020
|
+
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4021
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4022
|
+
allRequests.forEach((req, index) => {
|
4023
|
+
if (req.type === import_transactions19.TransactionType.Script) {
|
4024
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4025
|
+
}
|
4026
|
+
});
|
4027
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4028
|
+
let attempt = 0;
|
4029
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4030
|
+
const encodedTransactions = transactionsToProcess.map(
|
4031
|
+
(index) => serializedTransactionsMap.get(index)
|
4032
|
+
);
|
4033
|
+
const dryRunResults = await this.operations.dryRun({
|
4034
|
+
encodedTransactions,
|
4035
|
+
utxoValidation: false
|
4036
|
+
});
|
4037
|
+
const nextRoundTransactions = [];
|
4038
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4039
|
+
const currentResultIndex = transactionsToProcess[i];
|
4040
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4041
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4042
|
+
results[currentResultIndex].dryrunStatus = status;
|
4043
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4044
|
+
results[currentResultIndex].receipts
|
4045
|
+
);
|
4046
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4047
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4048
|
+
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4049
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4050
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4051
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4052
|
+
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4053
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4054
|
+
});
|
4055
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4056
|
+
transactionRequest: requestToProcess,
|
4057
|
+
optimizeGas: false
|
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
|
+
async estimateTxGasAndFee(params) {
|
4089
|
+
const { transactionRequest, optimizeGas = true } = params;
|
4090
|
+
let { gasPrice } = params;
|
4091
|
+
const chainInfo = this.getChain();
|
4092
|
+
const { gasPriceFactor } = this.getGasConfig();
|
4093
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
4094
|
+
if (!gasPrice) {
|
4095
|
+
gasPrice = await this.estimateGasPrice(10);
|
4096
|
+
}
|
4097
|
+
const minFee = calculateGasFee({
|
4098
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4099
|
+
gas: minGas,
|
4100
|
+
priceFactor: gasPriceFactor,
|
4101
|
+
tip: transactionRequest.tip
|
4102
|
+
}).add(1);
|
4103
|
+
let gasLimit = (0, import_math16.bn)(0);
|
4104
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4105
|
+
gasLimit = transactionRequest.gasLimit;
|
4106
|
+
if (!optimizeGas) {
|
4107
|
+
transactionRequest.gasLimit = minGas;
|
4108
|
+
gasLimit = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4109
|
+
transactionRequest.gasLimit = gasLimit;
|
4110
|
+
}
|
4111
|
+
}
|
4112
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4113
|
+
const maxFee = calculateGasFee({
|
4114
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4115
|
+
gas: maxGas,
|
4116
|
+
priceFactor: gasPriceFactor,
|
4117
|
+
tip: transactionRequest.tip
|
4118
|
+
}).add(1);
|
4119
|
+
return {
|
4120
|
+
minGas,
|
4121
|
+
minFee,
|
4122
|
+
maxGas,
|
4123
|
+
maxFee,
|
4124
|
+
gasPrice,
|
4125
|
+
gasLimit
|
3903
4126
|
};
|
3904
4127
|
}
|
3905
4128
|
/**
|
@@ -3917,15 +4140,17 @@ var _Provider = class {
|
|
3917
4140
|
if (estimateTxDependencies) {
|
3918
4141
|
return this.estimateTxDependencies(transactionRequest);
|
3919
4142
|
}
|
3920
|
-
const
|
3921
|
-
const { dryRun:
|
3922
|
-
|
4143
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4144
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4145
|
+
encodedTransactions,
|
3923
4146
|
utxoValidation: true
|
3924
4147
|
});
|
3925
|
-
const
|
3926
|
-
|
3927
|
-
receipts
|
3928
|
-
|
4148
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4149
|
+
const { id, receipts, status } = dryRunStatus;
|
4150
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4151
|
+
return { id, receipts: processedReceipts, status };
|
4152
|
+
});
|
4153
|
+
return { receipts: callResult[0].receipts };
|
3929
4154
|
}
|
3930
4155
|
/**
|
3931
4156
|
* Returns a transaction cost to enable user
|
@@ -3942,80 +4167,80 @@ var _Provider = class {
|
|
3942
4167
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3943
4168
|
* @returns A promise that resolves to the transaction cost object.
|
3944
4169
|
*/
|
3945
|
-
async getTransactionCost(transactionRequestLike,
|
3946
|
-
estimateTxDependencies = true,
|
3947
|
-
estimatePredicates = true,
|
3948
|
-
resourcesOwner,
|
3949
|
-
signatureCallback
|
3950
|
-
} = {}) {
|
4170
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3951
4171
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3952
|
-
const
|
3953
|
-
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3954
|
-
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3955
|
-
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4172
|
+
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
3956
4173
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3957
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4174
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3958
4175
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3959
|
-
|
3960
|
-
|
3961
|
-
|
3962
|
-
}
|
3963
|
-
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3964
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3965
|
-
}
|
3966
|
-
await this.estimatePredicates(txRequestClone);
|
4176
|
+
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
4177
|
+
if (isScriptTransaction) {
|
4178
|
+
txRequestClone.gasLimit = (0, import_math16.bn)(0);
|
3967
4179
|
}
|
3968
|
-
if (
|
3969
|
-
|
4180
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4181
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3970
4182
|
}
|
3971
|
-
const
|
3972
|
-
|
4183
|
+
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4184
|
+
let addedSignatures = 0;
|
4185
|
+
if (signatureCallback && isScriptTransaction) {
|
4186
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4187
|
+
await signatureCallback(signedRequest);
|
4188
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
4189
|
+
}
|
4190
|
+
await this.estimatePredicates(signedRequest);
|
4191
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4192
|
+
transactionRequest: signedRequest,
|
4193
|
+
optimizeGas: false
|
4194
|
+
});
|
4195
|
+
txRequestClone.maxFee = maxFee;
|
3973
4196
|
let receipts = [];
|
3974
4197
|
let missingContractIds = [];
|
3975
4198
|
let outputVariables = 0;
|
3976
|
-
|
3977
|
-
|
3978
|
-
|
4199
|
+
let gasUsed = (0, import_math16.bn)(0);
|
4200
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4201
|
+
if (isScriptTransaction) {
|
4202
|
+
if (signatureCallback) {
|
4203
|
+
await signatureCallback(txRequestClone);
|
4204
|
+
}
|
4205
|
+
txRequestClone.gasLimit = gasLimit;
|
3979
4206
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3980
4207
|
receipts = result.receipts;
|
3981
4208
|
outputVariables = result.outputVariables;
|
3982
4209
|
missingContractIds = result.missingContractIds;
|
4210
|
+
gasUsed = getGasUsedFromReceipts(receipts);
|
4211
|
+
txRequestClone.gasLimit = gasUsed;
|
4212
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4213
|
+
transactionRequest: txRequestClone,
|
4214
|
+
gasPrice
|
4215
|
+
}));
|
3983
4216
|
}
|
3984
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3985
|
-
const usedFee = calculatePriceWithFactor(
|
3986
|
-
gasUsed,
|
3987
|
-
gasPrice,
|
3988
|
-
gasPriceFactor
|
3989
|
-
).normalizeZeroToOne();
|
3990
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3991
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3992
4217
|
return {
|
3993
4218
|
requiredQuantities: allQuantities,
|
3994
4219
|
receipts,
|
3995
4220
|
gasUsed,
|
3996
|
-
minGasPrice,
|
3997
4221
|
gasPrice,
|
3998
4222
|
minGas,
|
3999
4223
|
maxGas,
|
4000
|
-
usedFee,
|
4001
4224
|
minFee,
|
4002
4225
|
maxFee,
|
4003
|
-
estimatedInputs: txRequestClone.inputs,
|
4004
4226
|
outputVariables,
|
4005
|
-
missingContractIds
|
4227
|
+
missingContractIds,
|
4228
|
+
addedSignatures,
|
4229
|
+
estimatedPredicates: txRequestClone.inputs
|
4006
4230
|
};
|
4007
4231
|
}
|
4008
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4232
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4009
4233
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4010
4234
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4011
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4235
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4236
|
+
quantitiesToContract
|
4237
|
+
});
|
4012
4238
|
transactionRequest.addResources(
|
4013
4239
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4014
4240
|
);
|
4015
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4016
|
-
|
4017
|
-
|
4018
|
-
);
|
4241
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4242
|
+
quantitiesToContract
|
4243
|
+
});
|
4019
4244
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4020
4245
|
return {
|
4021
4246
|
resources,
|
@@ -4031,17 +4256,16 @@ var _Provider = class {
|
|
4031
4256
|
const result = await this.operations.getCoins({
|
4032
4257
|
first: 10,
|
4033
4258
|
...paginationArgs,
|
4034
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4259
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4035
4260
|
});
|
4036
4261
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4037
4262
|
return coins.map((coin) => ({
|
4038
4263
|
id: coin.utxoId,
|
4039
4264
|
assetId: coin.assetId,
|
4040
|
-
amount: (0,
|
4265
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4041
4266
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4042
|
-
|
4043
|
-
|
4044
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4267
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4268
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4045
4269
|
}));
|
4046
4270
|
}
|
4047
4271
|
/**
|
@@ -4055,19 +4279,19 @@ var _Provider = class {
|
|
4055
4279
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4056
4280
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4057
4281
|
const excludeInput = {
|
4058
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4059
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4282
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4283
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4060
4284
|
};
|
4061
4285
|
if (this.cache) {
|
4062
4286
|
const uniqueUtxos = new Set(
|
4063
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4287
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4064
4288
|
);
|
4065
4289
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4066
4290
|
}
|
4067
4291
|
const coinsQuery = {
|
4068
4292
|
owner: ownerAddress.toB256(),
|
4069
4293
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4070
|
-
assetId: (0,
|
4294
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4071
4295
|
amount: amount.toString(10),
|
4072
4296
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4073
4297
|
})),
|
@@ -4078,9 +4302,9 @@ var _Provider = class {
|
|
4078
4302
|
switch (coin.__typename) {
|
4079
4303
|
case "MessageCoin":
|
4080
4304
|
return {
|
4081
|
-
amount: (0,
|
4305
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4082
4306
|
assetId: coin.assetId,
|
4083
|
-
daHeight: (0,
|
4307
|
+
daHeight: (0, import_math16.bn)(coin.daHeight),
|
4084
4308
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4085
4309
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4086
4310
|
nonce: coin.nonce
|
@@ -4088,12 +4312,11 @@ var _Provider = class {
|
|
4088
4312
|
case "Coin":
|
4089
4313
|
return {
|
4090
4314
|
id: coin.utxoId,
|
4091
|
-
amount: (0,
|
4315
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4092
4316
|
assetId: coin.assetId,
|
4093
4317
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4094
|
-
|
4095
|
-
|
4096
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4318
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4319
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4097
4320
|
};
|
4098
4321
|
default:
|
4099
4322
|
return null;
|
@@ -4110,13 +4333,13 @@ var _Provider = class {
|
|
4110
4333
|
async getBlock(idOrHeight) {
|
4111
4334
|
let variables;
|
4112
4335
|
if (typeof idOrHeight === "number") {
|
4113
|
-
variables = { height: (0,
|
4336
|
+
variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4114
4337
|
} else if (idOrHeight === "latest") {
|
4115
4338
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4116
4339
|
} else if (idOrHeight.length === 66) {
|
4117
4340
|
variables = { blockId: idOrHeight };
|
4118
4341
|
} else {
|
4119
|
-
variables = { blockId: (0,
|
4342
|
+
variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4120
4343
|
}
|
4121
4344
|
const { block } = await this.operations.getBlock(variables);
|
4122
4345
|
if (!block) {
|
@@ -4124,7 +4347,7 @@ var _Provider = class {
|
|
4124
4347
|
}
|
4125
4348
|
return {
|
4126
4349
|
id: block.id,
|
4127
|
-
height: (0,
|
4350
|
+
height: (0, import_math16.bn)(block.height),
|
4128
4351
|
time: block.header.time,
|
4129
4352
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4130
4353
|
};
|
@@ -4139,7 +4362,7 @@ var _Provider = class {
|
|
4139
4362
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4140
4363
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4141
4364
|
id: block.id,
|
4142
|
-
height: (0,
|
4365
|
+
height: (0, import_math16.bn)(block.height),
|
4143
4366
|
time: block.header.time,
|
4144
4367
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4145
4368
|
}));
|
@@ -4154,7 +4377,7 @@ var _Provider = class {
|
|
4154
4377
|
async getBlockWithTransactions(idOrHeight) {
|
4155
4378
|
let variables;
|
4156
4379
|
if (typeof idOrHeight === "number") {
|
4157
|
-
variables = { blockHeight: (0,
|
4380
|
+
variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4158
4381
|
} else if (idOrHeight === "latest") {
|
4159
4382
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4160
4383
|
} else {
|
@@ -4166,11 +4389,11 @@ var _Provider = class {
|
|
4166
4389
|
}
|
4167
4390
|
return {
|
4168
4391
|
id: block.id,
|
4169
|
-
height: (0,
|
4392
|
+
height: (0, import_math16.bn)(block.height, 10),
|
4170
4393
|
time: block.header.time,
|
4171
4394
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4172
4395
|
transactions: block.transactions.map(
|
4173
|
-
(tx) => new
|
4396
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4174
4397
|
)
|
4175
4398
|
};
|
4176
4399
|
}
|
@@ -4185,8 +4408,8 @@ var _Provider = class {
|
|
4185
4408
|
if (!transaction) {
|
4186
4409
|
return null;
|
4187
4410
|
}
|
4188
|
-
return new
|
4189
|
-
(0,
|
4411
|
+
return new import_transactions19.TransactionCoder().decode(
|
4412
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4190
4413
|
0
|
4191
4414
|
)?.[0];
|
4192
4415
|
}
|
@@ -4213,9 +4436,9 @@ var _Provider = class {
|
|
4213
4436
|
async getContractBalance(contractId, assetId) {
|
4214
4437
|
const { contractBalance } = await this.operations.getContractBalance({
|
4215
4438
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4216
|
-
asset: (0,
|
4439
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4217
4440
|
});
|
4218
|
-
return (0,
|
4441
|
+
return (0, import_math16.bn)(contractBalance.amount, 10);
|
4219
4442
|
}
|
4220
4443
|
/**
|
4221
4444
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4227,9 +4450,9 @@ var _Provider = class {
|
|
4227
4450
|
async getBalance(owner, assetId) {
|
4228
4451
|
const { balance } = await this.operations.getBalance({
|
4229
4452
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4230
|
-
assetId: (0,
|
4453
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4231
4454
|
});
|
4232
|
-
return (0,
|
4455
|
+
return (0, import_math16.bn)(balance.amount, 10);
|
4233
4456
|
}
|
4234
4457
|
/**
|
4235
4458
|
* Returns balances for the given owner.
|
@@ -4247,7 +4470,7 @@ var _Provider = class {
|
|
4247
4470
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4248
4471
|
return balances.map((balance) => ({
|
4249
4472
|
assetId: balance.assetId,
|
4250
|
-
amount: (0,
|
4473
|
+
amount: (0, import_math16.bn)(balance.amount)
|
4251
4474
|
}));
|
4252
4475
|
}
|
4253
4476
|
/**
|
@@ -4265,19 +4488,19 @@ var _Provider = class {
|
|
4265
4488
|
});
|
4266
4489
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4267
4490
|
return messages.map((message) => ({
|
4268
|
-
messageId:
|
4491
|
+
messageId: import_transactions19.InputMessageCoder.getMessageId({
|
4269
4492
|
sender: message.sender,
|
4270
4493
|
recipient: message.recipient,
|
4271
4494
|
nonce: message.nonce,
|
4272
|
-
amount: (0,
|
4495
|
+
amount: (0, import_math16.bn)(message.amount),
|
4273
4496
|
data: message.data
|
4274
4497
|
}),
|
4275
4498
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4276
4499
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4277
4500
|
nonce: message.nonce,
|
4278
|
-
amount: (0,
|
4279
|
-
data:
|
4280
|
-
daHeight: (0,
|
4501
|
+
amount: (0, import_math16.bn)(message.amount),
|
4502
|
+
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4503
|
+
daHeight: (0, import_math16.bn)(message.daHeight)
|
4281
4504
|
}));
|
4282
4505
|
}
|
4283
4506
|
/**
|
@@ -4330,44 +4553,60 @@ var _Provider = class {
|
|
4330
4553
|
} = result.messageProof;
|
4331
4554
|
return {
|
4332
4555
|
messageProof: {
|
4333
|
-
proofIndex: (0,
|
4556
|
+
proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
|
4334
4557
|
proofSet: messageProof.proofSet
|
4335
4558
|
},
|
4336
4559
|
blockProof: {
|
4337
|
-
proofIndex: (0,
|
4560
|
+
proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
|
4338
4561
|
proofSet: blockProof.proofSet
|
4339
4562
|
},
|
4340
4563
|
messageBlockHeader: {
|
4341
4564
|
id: messageBlockHeader.id,
|
4342
|
-
daHeight: (0,
|
4343
|
-
transactionsCount: (0,
|
4565
|
+
daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
|
4566
|
+
transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
|
4344
4567
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4345
|
-
height: (0,
|
4568
|
+
height: (0, import_math16.bn)(messageBlockHeader.height),
|
4346
4569
|
prevRoot: messageBlockHeader.prevRoot,
|
4347
4570
|
time: messageBlockHeader.time,
|
4348
4571
|
applicationHash: messageBlockHeader.applicationHash,
|
4349
|
-
|
4350
|
-
|
4572
|
+
messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
|
4573
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4574
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4575
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4576
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4351
4577
|
},
|
4352
4578
|
commitBlockHeader: {
|
4353
4579
|
id: commitBlockHeader.id,
|
4354
|
-
daHeight: (0,
|
4355
|
-
transactionsCount: (0,
|
4580
|
+
daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
|
4581
|
+
transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
|
4356
4582
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4357
|
-
height: (0,
|
4583
|
+
height: (0, import_math16.bn)(commitBlockHeader.height),
|
4358
4584
|
prevRoot: commitBlockHeader.prevRoot,
|
4359
4585
|
time: commitBlockHeader.time,
|
4360
4586
|
applicationHash: commitBlockHeader.applicationHash,
|
4361
|
-
|
4362
|
-
|
4587
|
+
messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
|
4588
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4589
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4590
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4591
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4363
4592
|
},
|
4364
4593
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4365
4594
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4366
4595
|
nonce,
|
4367
|
-
amount: (0,
|
4596
|
+
amount: (0, import_math16.bn)(amount),
|
4368
4597
|
data
|
4369
4598
|
};
|
4370
4599
|
}
|
4600
|
+
async getLatestGasPrice() {
|
4601
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4602
|
+
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4603
|
+
}
|
4604
|
+
async estimateGasPrice(blockHorizon) {
|
4605
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4606
|
+
blockHorizon: String(blockHorizon)
|
4607
|
+
});
|
4608
|
+
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4609
|
+
}
|
4371
4610
|
/**
|
4372
4611
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4373
4612
|
*
|
@@ -4387,10 +4626,10 @@ var _Provider = class {
|
|
4387
4626
|
*/
|
4388
4627
|
async produceBlocks(amount, startTime) {
|
4389
4628
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4390
|
-
blocksToProduce: (0,
|
4391
|
-
startTimestamp: startTime ?
|
4629
|
+
blocksToProduce: (0, import_math16.bn)(amount).toString(10),
|
4630
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4392
4631
|
});
|
4393
|
-
return (0,
|
4632
|
+
return (0, import_math16.bn)(latestBlockHeight);
|
4394
4633
|
}
|
4395
4634
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4396
4635
|
async getTransactionResponse(transactionId) {
|
@@ -4404,7 +4643,7 @@ cacheInputs_fn = function(inputs) {
|
|
4404
4643
|
return;
|
4405
4644
|
}
|
4406
4645
|
inputs.forEach((input) => {
|
4407
|
-
if (input.type ===
|
4646
|
+
if (input.type === import_transactions19.InputType.Coin) {
|
4408
4647
|
this.cache?.set(input.id);
|
4409
4648
|
}
|
4410
4649
|
});
|
@@ -4414,9 +4653,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4414
4653
|
|
4415
4654
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4416
4655
|
var import_errors15 = require("@fuel-ts/errors");
|
4417
|
-
var
|
4418
|
-
var
|
4419
|
-
var
|
4656
|
+
var import_math17 = require("@fuel-ts/math");
|
4657
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
4658
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4420
4659
|
|
4421
4660
|
// src/providers/chains.ts
|
4422
4661
|
var CHAIN_IDS = {
|
@@ -4465,17 +4704,17 @@ var assets = [
|
|
4465
4704
|
|
4466
4705
|
// src/utils/formatTransferToContractScriptData.ts
|
4467
4706
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4468
|
-
var
|
4469
|
-
var
|
4707
|
+
var import_math18 = require("@fuel-ts/math");
|
4708
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4470
4709
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4471
4710
|
var formatTransferToContractScriptData = (params) => {
|
4472
4711
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4473
4712
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4474
|
-
const encoded = numberCoder.encode(new
|
4713
|
+
const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
|
4475
4714
|
const scriptData = Uint8Array.from([
|
4476
|
-
...(0,
|
4715
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4477
4716
|
...encoded,
|
4478
|
-
...(0,
|
4717
|
+
...(0, import_utils26.arrayify)(assetId)
|
4479
4718
|
]);
|
4480
4719
|
return scriptData;
|
4481
4720
|
};
|
@@ -4622,9 +4861,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4622
4861
|
* @param assetId - The asset ID to check the balance for.
|
4623
4862
|
* @returns A promise that resolves to the balance amount.
|
4624
4863
|
*/
|
4625
|
-
async getBalance(assetId) {
|
4626
|
-
const
|
4627
|
-
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
4864
|
+
async getBalance(assetId = import_configs12.BaseAssetId) {
|
4865
|
+
const amount = await this.provider.getBalance(this.address, assetId);
|
4628
4866
|
return amount;
|
4629
4867
|
}
|
4630
4868
|
/**
|
@@ -4661,37 +4899,33 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4661
4899
|
* @param fee - The estimated transaction fee.
|
4662
4900
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4663
4901
|
*/
|
4664
|
-
async fund(request,
|
4665
|
-
const
|
4666
|
-
const
|
4667
|
-
|
4668
|
-
|
4669
|
-
|
4902
|
+
async fund(request, params) {
|
4903
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4904
|
+
const txRequest = request;
|
4905
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4906
|
+
amount: (0, import_math19.bn)(fee),
|
4907
|
+
assetId: import_configs12.BaseAssetId,
|
4908
|
+
coinQuantities: requiredQuantities
|
4670
4909
|
});
|
4671
4910
|
const quantitiesDict = {};
|
4672
|
-
|
4911
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4673
4912
|
quantitiesDict[assetId] = {
|
4674
4913
|
required: amount,
|
4675
|
-
owned: (0,
|
4914
|
+
owned: (0, import_math19.bn)(0)
|
4676
4915
|
};
|
4677
4916
|
});
|
4678
|
-
|
4679
|
-
const cachedMessages = [];
|
4680
|
-
const owner = this.address.toB256();
|
4681
|
-
request.inputs.forEach((input) => {
|
4917
|
+
txRequest.inputs.forEach((input) => {
|
4682
4918
|
const isResource = "amount" in input;
|
4683
4919
|
if (isResource) {
|
4684
4920
|
const isCoin2 = "owner" in input;
|
4685
4921
|
if (isCoin2) {
|
4686
4922
|
const assetId = String(input.assetId);
|
4687
|
-
if (
|
4688
|
-
const amount = (0,
|
4923
|
+
if (quantitiesDict[assetId]) {
|
4924
|
+
const amount = (0, import_math19.bn)(input.amount);
|
4689
4925
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4690
|
-
cachedUtxos.push(input.id);
|
4691
4926
|
}
|
4692
|
-
} else if (input.
|
4693
|
-
quantitiesDict[
|
4694
|
-
cachedMessages.push(input.nonce);
|
4927
|
+
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4928
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4695
4929
|
}
|
4696
4930
|
}
|
4697
4931
|
});
|
@@ -4706,12 +4940,23 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4706
4940
|
});
|
4707
4941
|
const needsToBeFunded = missingQuantities.length;
|
4708
4942
|
if (needsToBeFunded) {
|
4709
|
-
const
|
4710
|
-
|
4711
|
-
|
4712
|
-
|
4713
|
-
|
4943
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4944
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4945
|
+
txRequest.addResources(resources);
|
4946
|
+
}
|
4947
|
+
txRequest.shiftPredicateData();
|
4948
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4949
|
+
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
4950
|
+
if (addedSignatures) {
|
4951
|
+
Array.from({ length: addedSignatures }).forEach(
|
4952
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
4953
|
+
);
|
4714
4954
|
}
|
4955
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4956
|
+
transactionRequest: requestToBeReEstimate
|
4957
|
+
});
|
4958
|
+
txRequest.maxFee = maxFee;
|
4959
|
+
return txRequest;
|
4715
4960
|
}
|
4716
4961
|
/**
|
4717
4962
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4719,30 +4964,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4719
4964
|
* @param destination - The address of the destination.
|
4720
4965
|
* @param amount - The amount of coins to transfer.
|
4721
4966
|
* @param assetId - The asset ID of the coins to transfer.
|
4722
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4967
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4723
4968
|
* @returns A promise that resolves to the prepared transaction request.
|
4724
4969
|
*/
|
4725
|
-
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4726
|
-
const
|
4727
|
-
|
4728
|
-
const
|
4729
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4730
|
-
const request = new ScriptTransactionRequest(params);
|
4731
|
-
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4732
|
-
const { maxFee, requiredQuantities, gasUsed, estimatedInputs } = await this.provider.getTransactionCost(request, [], {
|
4970
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4971
|
+
const request = new ScriptTransactionRequest(txParams);
|
4972
|
+
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4973
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4733
4974
|
estimateTxDependencies: true,
|
4734
4975
|
resourcesOwner: this
|
4735
4976
|
});
|
4736
|
-
|
4737
|
-
|
4738
|
-
|
4739
|
-
|
4740
|
-
|
4741
|
-
|
4742
|
-
|
4743
|
-
|
4744
|
-
await this.fund(request,
|
4745
|
-
request.updatePredicateInputs(estimatedInputs);
|
4977
|
+
if ("gasLimit" in txParams) {
|
4978
|
+
this.validateGas({
|
4979
|
+
gasUsed: txCost.gasUsed,
|
4980
|
+
gasLimit: request.gasLimit
|
4981
|
+
});
|
4982
|
+
}
|
4983
|
+
request.gasLimit = txCost.gasUsed;
|
4984
|
+
request.maxFee = txCost.maxFee;
|
4985
|
+
await this.fund(request, txCost);
|
4746
4986
|
return request;
|
4747
4987
|
}
|
4748
4988
|
/**
|
@@ -4754,15 +4994,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4754
4994
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4755
4995
|
* @returns A promise that resolves to the transaction response.
|
4756
4996
|
*/
|
4757
|
-
async transfer(destination, amount, assetId, txParams = {}) {
|
4758
|
-
if ((0,
|
4997
|
+
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4998
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
4759
4999
|
throw new import_errors16.FuelError(
|
4760
5000
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4761
5001
|
"Transfer amount must be a positive number."
|
4762
5002
|
);
|
4763
5003
|
}
|
4764
|
-
const
|
4765
|
-
const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
|
5004
|
+
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4766
5005
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4767
5006
|
}
|
4768
5007
|
/**
|
@@ -4774,41 +5013,38 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4774
5013
|
* @param txParams - The optional transaction parameters.
|
4775
5014
|
* @returns A promise that resolves to the transaction response.
|
4776
5015
|
*/
|
4777
|
-
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4778
|
-
if ((0,
|
5016
|
+
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
5017
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
4779
5018
|
throw new import_errors16.FuelError(
|
4780
5019
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4781
5020
|
"Transfer amount must be a positive number."
|
4782
5021
|
);
|
4783
5022
|
}
|
4784
5023
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4785
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4786
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4787
|
-
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4788
|
-
const params = { gasPrice: minGasPrice, baseAssetId, ...txParams };
|
4789
5024
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4790
5025
|
hexlifiedContractId: contractAddress.toB256(),
|
4791
|
-
amountToTransfer: (0,
|
4792
|
-
assetId
|
5026
|
+
amountToTransfer: (0, import_math19.bn)(amount),
|
5027
|
+
assetId
|
4793
5028
|
});
|
4794
5029
|
const request = new ScriptTransactionRequest({
|
4795
|
-
...
|
5030
|
+
...txParams,
|
4796
5031
|
script,
|
4797
5032
|
scriptData
|
4798
5033
|
});
|
4799
5034
|
request.addContractInputAndOutput(contractAddress);
|
4800
|
-
const
|
4801
|
-
|
4802
|
-
[{ amount: (0,
|
4803
|
-
);
|
4804
|
-
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4805
|
-
this.validateGas({
|
4806
|
-
gasUsed,
|
4807
|
-
gasPrice: request.gasPrice,
|
4808
|
-
gasLimit: request.gasLimit,
|
4809
|
-
minGasPrice
|
5035
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5036
|
+
resourcesOwner: this,
|
5037
|
+
quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
|
4810
5038
|
});
|
4811
|
-
|
5039
|
+
if (txParams.gasLimit) {
|
5040
|
+
this.validateGas({
|
5041
|
+
gasUsed: txCost.gasUsed,
|
5042
|
+
gasLimit: request.gasLimit
|
5043
|
+
});
|
5044
|
+
}
|
5045
|
+
request.gasLimit = txCost.gasUsed;
|
5046
|
+
request.maxFee = txCost.maxFee;
|
5047
|
+
await this.fund(request, txCost);
|
4812
5048
|
return this.sendTransaction(request);
|
4813
5049
|
}
|
4814
5050
|
/**
|
@@ -4820,40 +5056,31 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4820
5056
|
* @returns A promise that resolves to the transaction response.
|
4821
5057
|
*/
|
4822
5058
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4823
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4824
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4825
5059
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4826
|
-
const recipientDataArray = (0,
|
5060
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
4827
5061
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4828
5062
|
);
|
4829
|
-
const amountDataArray = (0,
|
4830
|
-
"0x".concat((0,
|
5063
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5064
|
+
"0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4831
5065
|
);
|
4832
5066
|
const script = new Uint8Array([
|
4833
|
-
...(0,
|
5067
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
4834
5068
|
...recipientDataArray,
|
4835
5069
|
...amountDataArray
|
4836
5070
|
]);
|
4837
|
-
const params = {
|
4838
|
-
script,
|
4839
|
-
gasPrice: minGasPrice,
|
4840
|
-
baseAssetId,
|
4841
|
-
...txParams
|
4842
|
-
};
|
5071
|
+
const params = { script, ...txParams };
|
4843
5072
|
const request = new ScriptTransactionRequest(params);
|
4844
|
-
const
|
4845
|
-
const
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4849
|
-
|
4850
|
-
|
4851
|
-
|
4852
|
-
|
4853
|
-
|
4854
|
-
|
4855
|
-
});
|
4856
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5073
|
+
const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5074
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5075
|
+
if (txParams.gasLimit) {
|
5076
|
+
this.validateGas({
|
5077
|
+
gasUsed: txCost.gasUsed,
|
5078
|
+
gasLimit: request.gasLimit
|
5079
|
+
});
|
5080
|
+
}
|
5081
|
+
request.maxFee = txCost.maxFee;
|
5082
|
+
request.gasLimit = txCost.gasUsed;
|
5083
|
+
await this.fund(request, txCost);
|
4857
5084
|
return this.sendTransaction(request);
|
4858
5085
|
}
|
4859
5086
|
async signMessage(message) {
|
@@ -4911,18 +5138,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4911
5138
|
}
|
4912
5139
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4913
5140
|
}
|
4914
|
-
validateGas({
|
4915
|
-
gasUsed,
|
4916
|
-
gasPrice,
|
4917
|
-
gasLimit,
|
4918
|
-
minGasPrice
|
4919
|
-
}) {
|
4920
|
-
if (minGasPrice.gt(gasPrice)) {
|
4921
|
-
throw new import_errors16.FuelError(
|
4922
|
-
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4923
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4924
|
-
);
|
4925
|
-
}
|
5141
|
+
validateGas({ gasUsed, gasLimit }) {
|
4926
5142
|
if (gasUsed.gt(gasLimit)) {
|
4927
5143
|
throw new import_errors16.FuelError(
|
4928
5144
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -4936,8 +5152,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4936
5152
|
var import_address5 = require("@fuel-ts/address");
|
4937
5153
|
var import_crypto = require("@fuel-ts/crypto");
|
4938
5154
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4939
|
-
var
|
4940
|
-
var
|
5155
|
+
var import_math20 = require("@fuel-ts/math");
|
5156
|
+
var import_utils28 = require("@fuel-ts/utils");
|
4941
5157
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4942
5158
|
var Signer = class {
|
4943
5159
|
address;
|
@@ -4956,10 +5172,10 @@ var Signer = class {
|
|
4956
5172
|
privateKey = `0x${privateKey}`;
|
4957
5173
|
}
|
4958
5174
|
}
|
4959
|
-
const privateKeyBytes = (0,
|
4960
|
-
this.privateKey = (0,
|
4961
|
-
this.publicKey = (0,
|
4962
|
-
this.compressedPublicKey = (0,
|
5175
|
+
const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
|
5176
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5177
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5178
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
4963
5179
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
4964
5180
|
}
|
4965
5181
|
/**
|
@@ -4973,11 +5189,11 @@ var Signer = class {
|
|
4973
5189
|
* @returns hashed signature
|
4974
5190
|
*/
|
4975
5191
|
sign(data) {
|
4976
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
4977
|
-
const r = (0,
|
4978
|
-
const s = (0,
|
5192
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5193
|
+
const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5194
|
+
const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4979
5195
|
s[0] |= (signature.recovery || 0) << 7;
|
4980
|
-
return (0,
|
5196
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
4981
5197
|
}
|
4982
5198
|
/**
|
4983
5199
|
* Add point on the current elliptic curve
|
@@ -4986,8 +5202,8 @@ var Signer = class {
|
|
4986
5202
|
* @returns compressed point on the curve
|
4987
5203
|
*/
|
4988
5204
|
addPoint(point) {
|
4989
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4990
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5205
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5206
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
4991
5207
|
const result = p0.add(p1);
|
4992
5208
|
return `0x${result.toHex(true)}`;
|
4993
5209
|
}
|
@@ -4999,16 +5215,16 @@ var Signer = class {
|
|
4999
5215
|
* @returns public key from signature from the
|
5000
5216
|
*/
|
5001
5217
|
static recoverPublicKey(data, signature) {
|
5002
|
-
const signedMessageBytes = (0,
|
5218
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5003
5219
|
const r = signedMessageBytes.slice(0, 32);
|
5004
5220
|
const s = signedMessageBytes.slice(32, 64);
|
5005
5221
|
const recoveryParam = (s[0] & 128) >> 7;
|
5006
5222
|
s[0] &= 127;
|
5007
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5223
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5008
5224
|
recoveryParam
|
5009
5225
|
);
|
5010
|
-
const publicKey = sig.recoverPublicKey((0,
|
5011
|
-
return (0,
|
5226
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5227
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5012
5228
|
}
|
5013
5229
|
/**
|
5014
5230
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5027,7 +5243,7 @@ var Signer = class {
|
|
5027
5243
|
* @returns random 32-byte hashed
|
5028
5244
|
*/
|
5029
5245
|
static generatePrivateKey(entropy) {
|
5030
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5246
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
5031
5247
|
}
|
5032
5248
|
/**
|
5033
5249
|
* Extended publicKey from a compact publicKey
|
@@ -5036,8 +5252,8 @@ var Signer = class {
|
|
5036
5252
|
* @returns extended publicKey
|
5037
5253
|
*/
|
5038
5254
|
static extendPublicKey(publicKey) {
|
5039
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5040
|
-
return (0,
|
5255
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5256
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5041
5257
|
}
|
5042
5258
|
};
|
5043
5259
|
|
@@ -5045,7 +5261,7 @@ var Signer = class {
|
|
5045
5261
|
var import_address6 = require("@fuel-ts/address");
|
5046
5262
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5047
5263
|
var import_errors17 = require("@fuel-ts/errors");
|
5048
|
-
var
|
5264
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5049
5265
|
var import_uuid = require("uuid");
|
5050
5266
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5051
5267
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5128,7 +5344,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5128
5344
|
);
|
5129
5345
|
}
|
5130
5346
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5131
|
-
const privateKey = (0,
|
5347
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5132
5348
|
return privateKey;
|
5133
5349
|
}
|
5134
5350
|
|
@@ -5173,7 +5389,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5173
5389
|
*/
|
5174
5390
|
async signMessage(message) {
|
5175
5391
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5176
|
-
return (0,
|
5392
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5177
5393
|
}
|
5178
5394
|
/**
|
5179
5395
|
* Signs a transaction with the wallet's private key.
|
@@ -5186,7 +5402,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5186
5402
|
const chainId = this.provider.getChainId();
|
5187
5403
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5188
5404
|
const signature = await this.signer().sign(hashedTransaction);
|
5189
|
-
return (0,
|
5405
|
+
return (0, import_utils30.hexlify)(signature);
|
5190
5406
|
}
|
5191
5407
|
/**
|
5192
5408
|
* Populates a transaction with the witnesses signature.
|
@@ -5206,7 +5422,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5206
5422
|
* @param transactionRequestLike - The transaction request to send.
|
5207
5423
|
* @returns A promise that resolves to the TransactionResponse object.
|
5208
5424
|
*/
|
5209
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5425
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5210
5426
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5211
5427
|
if (estimateTxDependencies) {
|
5212
5428
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5247,16 +5463,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5247
5463
|
// src/hdwallet/hdwallet.ts
|
5248
5464
|
var import_errors20 = require("@fuel-ts/errors");
|
5249
5465
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5250
|
-
var
|
5251
|
-
var
|
5252
|
-
var
|
5466
|
+
var import_math21 = require("@fuel-ts/math");
|
5467
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5468
|
+
var import_ethers4 = require("ethers");
|
5253
5469
|
|
5254
5470
|
// src/mnemonic/mnemonic.ts
|
5255
5471
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5256
5472
|
var import_errors19 = require("@fuel-ts/errors");
|
5257
5473
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5258
|
-
var
|
5259
|
-
var
|
5474
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5475
|
+
var import_ethers3 = require("ethers");
|
5260
5476
|
|
5261
5477
|
// src/wordlists/words/english.ts
|
5262
5478
|
var english = [
|
@@ -7313,7 +7529,7 @@ var english = [
|
|
7313
7529
|
// src/mnemonic/utils.ts
|
7314
7530
|
var import_errors18 = require("@fuel-ts/errors");
|
7315
7531
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7316
|
-
var
|
7532
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7317
7533
|
function toUtf8Bytes(stri) {
|
7318
7534
|
const str = stri.normalize("NFKD");
|
7319
7535
|
const result = [];
|
@@ -7380,14 +7596,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7380
7596
|
}
|
7381
7597
|
}
|
7382
7598
|
const checksumBits = entropy.length / 4;
|
7383
|
-
const checksum = (0,
|
7599
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7384
7600
|
indices[indices.length - 1] <<= checksumBits;
|
7385
7601
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7386
7602
|
return indices;
|
7387
7603
|
}
|
7388
7604
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7389
7605
|
const size = Math.ceil(11 * words.length / 8);
|
7390
|
-
const entropy = (0,
|
7606
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7391
7607
|
let offset = 0;
|
7392
7608
|
for (let i = 0; i < words.length; i += 1) {
|
7393
7609
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7407,7 +7623,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7407
7623
|
const entropyBits = 32 * words.length / 3;
|
7408
7624
|
const checksumBits = words.length / 3;
|
7409
7625
|
const checksumMask = getUpperMask(checksumBits);
|
7410
|
-
const checksum = (0,
|
7626
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7411
7627
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7412
7628
|
throw new import_errors18.FuelError(
|
7413
7629
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7482,7 +7698,7 @@ var Mnemonic = class {
|
|
7482
7698
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7483
7699
|
const words = getWords(phrase);
|
7484
7700
|
assertMnemonic(words);
|
7485
|
-
return (0,
|
7701
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7486
7702
|
}
|
7487
7703
|
/**
|
7488
7704
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7490,7 +7706,7 @@ var Mnemonic = class {
|
|
7490
7706
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7491
7707
|
*/
|
7492
7708
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7493
|
-
const entropyBytes = (0,
|
7709
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7494
7710
|
assertWordList(wordlist);
|
7495
7711
|
assertEntropy(entropyBytes);
|
7496
7712
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7504,7 +7720,7 @@ var Mnemonic = class {
|
|
7504
7720
|
assertMnemonic(getWords(phrase));
|
7505
7721
|
const phraseBytes = toUtf8Bytes(getPhrase(phrase));
|
7506
7722
|
const salt = toUtf8Bytes(`mnemonic${passphrase}`);
|
7507
|
-
return (0,
|
7723
|
+
return (0, import_ethers3.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
7508
7724
|
}
|
7509
7725
|
/**
|
7510
7726
|
* @param phrase - Mnemonic phrase composed by words from the provided wordlist
|
@@ -7559,14 +7775,14 @@ var Mnemonic = class {
|
|
7559
7775
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7560
7776
|
*/
|
7561
7777
|
static masterKeysFromSeed(seed) {
|
7562
|
-
const seedArray = (0,
|
7778
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
7563
7779
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7564
7780
|
throw new import_errors19.FuelError(
|
7565
7781
|
import_errors19.ErrorCode.INVALID_SEED,
|
7566
7782
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7567
7783
|
);
|
7568
7784
|
}
|
7569
|
-
return (0,
|
7785
|
+
return (0, import_utils32.arrayify)((0, import_ethers3.computeHmac)("sha512", MasterSecret, seedArray));
|
7570
7786
|
}
|
7571
7787
|
/**
|
7572
7788
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7577,22 +7793,22 @@ var Mnemonic = class {
|
|
7577
7793
|
*/
|
7578
7794
|
static seedToExtendedKey(seed, testnet = false) {
|
7579
7795
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7580
|
-
const prefix = (0,
|
7796
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7581
7797
|
const depth = "0x00";
|
7582
7798
|
const fingerprint = "0x00000000";
|
7583
7799
|
const index = "0x00000000";
|
7584
7800
|
const chainCode = masterKey.slice(32);
|
7585
7801
|
const privateKey = masterKey.slice(0, 32);
|
7586
|
-
const extendedKey = (0,
|
7802
|
+
const extendedKey = (0, import_utils32.concat)([
|
7587
7803
|
prefix,
|
7588
7804
|
depth,
|
7589
7805
|
fingerprint,
|
7590
7806
|
index,
|
7591
7807
|
chainCode,
|
7592
|
-
(0,
|
7808
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
7593
7809
|
]);
|
7594
|
-
const checksum = (0,
|
7595
|
-
return (0,
|
7810
|
+
const checksum = (0, import_ethers3.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7811
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
7596
7812
|
}
|
7597
7813
|
/**
|
7598
7814
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7607,7 +7823,7 @@ var Mnemonic = class {
|
|
7607
7823
|
* @returns A randomly generated mnemonic
|
7608
7824
|
*/
|
7609
7825
|
static generate(size = 32, extraEntropy = "") {
|
7610
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7826
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
7611
7827
|
return Mnemonic.entropyToMnemonic(entropy);
|
7612
7828
|
}
|
7613
7829
|
};
|
@@ -7615,12 +7831,12 @@ var mnemonic_default = Mnemonic;
|
|
7615
7831
|
|
7616
7832
|
// src/hdwallet/hdwallet.ts
|
7617
7833
|
var HARDENED_INDEX = 2147483648;
|
7618
|
-
var MainnetPRV2 = (0,
|
7619
|
-
var MainnetPUB = (0,
|
7620
|
-
var TestnetPRV2 = (0,
|
7621
|
-
var TestnetPUB = (0,
|
7834
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
7835
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
7836
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
7837
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
7622
7838
|
function base58check(data) {
|
7623
|
-
return (0,
|
7839
|
+
return (0, import_ethers4.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers4.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7624
7840
|
}
|
7625
7841
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7626
7842
|
if (isPublic) {
|
@@ -7629,11 +7845,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7629
7845
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7630
7846
|
}
|
7631
7847
|
function isPublicExtendedKey(extendedKey) {
|
7632
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7848
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
7633
7849
|
}
|
7634
7850
|
function isValidExtendedKey(extendedKey) {
|
7635
7851
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7636
|
-
(0,
|
7852
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
7637
7853
|
);
|
7638
7854
|
}
|
7639
7855
|
function parsePath(path2, depth = 0) {
|
@@ -7651,8 +7867,8 @@ function parsePath(path2, depth = 0) {
|
|
7651
7867
|
var HDWallet = class {
|
7652
7868
|
depth = 0;
|
7653
7869
|
index = 0;
|
7654
|
-
fingerprint = (0,
|
7655
|
-
parentFingerprint = (0,
|
7870
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7871
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7656
7872
|
privateKey;
|
7657
7873
|
publicKey;
|
7658
7874
|
chainCode;
|
@@ -7664,8 +7880,8 @@ var HDWallet = class {
|
|
7664
7880
|
constructor(config) {
|
7665
7881
|
if (config.privateKey) {
|
7666
7882
|
const signer = new Signer(config.privateKey);
|
7667
|
-
this.publicKey = (0,
|
7668
|
-
this.privateKey = (0,
|
7883
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
7884
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
7669
7885
|
} else {
|
7670
7886
|
if (!config.publicKey) {
|
7671
7887
|
throw new import_errors20.FuelError(
|
@@ -7673,10 +7889,10 @@ var HDWallet = class {
|
|
7673
7889
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7674
7890
|
);
|
7675
7891
|
}
|
7676
|
-
this.publicKey = (0,
|
7892
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
7677
7893
|
}
|
7678
7894
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7679
|
-
this.fingerprint = (0,
|
7895
|
+
this.fingerprint = (0, import_ethers4.dataSlice)((0, import_ethers4.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
7680
7896
|
this.depth = config.depth || this.depth;
|
7681
7897
|
this.index = config.index || this.index;
|
7682
7898
|
this.chainCode = config.chainCode;
|
@@ -7692,9 +7908,9 @@ var HDWallet = class {
|
|
7692
7908
|
* @returns A new instance of HDWallet on the derived index
|
7693
7909
|
*/
|
7694
7910
|
deriveIndex(index) {
|
7695
|
-
const privateKey = this.privateKey && (0,
|
7696
|
-
const publicKey = (0,
|
7697
|
-
const chainCode = (0,
|
7911
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
7912
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
7913
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
7698
7914
|
const data = new Uint8Array(37);
|
7699
7915
|
if (index & HARDENED_INDEX) {
|
7700
7916
|
if (!privateKey) {
|
@@ -7705,15 +7921,15 @@ var HDWallet = class {
|
|
7705
7921
|
}
|
7706
7922
|
data.set(privateKey, 1);
|
7707
7923
|
} else {
|
7708
|
-
data.set((0,
|
7924
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
7709
7925
|
}
|
7710
|
-
data.set((0,
|
7711
|
-
const bytes = (0,
|
7926
|
+
data.set((0, import_math21.toBytes)(index, 4), 33);
|
7927
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers4.computeHmac)("sha512", chainCode, data));
|
7712
7928
|
const IL = bytes.slice(0, 32);
|
7713
7929
|
const IR = bytes.slice(32);
|
7714
7930
|
if (privateKey) {
|
7715
7931
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7716
|
-
const ki = (0,
|
7932
|
+
const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7717
7933
|
return new HDWallet({
|
7718
7934
|
privateKey: ki,
|
7719
7935
|
chainCode: IR,
|
@@ -7722,7 +7938,7 @@ var HDWallet = class {
|
|
7722
7938
|
parentFingerprint: this.fingerprint
|
7723
7939
|
});
|
7724
7940
|
}
|
7725
|
-
const signer = new Signer((0,
|
7941
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
7726
7942
|
const Ki = signer.addPoint(publicKey);
|
7727
7943
|
return new HDWallet({
|
7728
7944
|
publicKey: Ki,
|
@@ -7757,12 +7973,12 @@ var HDWallet = class {
|
|
7757
7973
|
);
|
7758
7974
|
}
|
7759
7975
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7760
|
-
const depth = (0,
|
7976
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
7761
7977
|
const parentFingerprint = this.parentFingerprint;
|
7762
|
-
const index = (0,
|
7978
|
+
const index = (0, import_math21.toHex)(this.index, 4);
|
7763
7979
|
const chainCode = this.chainCode;
|
7764
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7765
|
-
const extendedKey = (0,
|
7980
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7981
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7766
7982
|
return base58check(extendedKey);
|
7767
7983
|
}
|
7768
7984
|
/**
|
@@ -7774,13 +7990,13 @@ var HDWallet = class {
|
|
7774
7990
|
static fromSeed(seed) {
|
7775
7991
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7776
7992
|
return new HDWallet({
|
7777
|
-
chainCode: (0,
|
7778
|
-
privateKey: (0,
|
7993
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
7994
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
7779
7995
|
});
|
7780
7996
|
}
|
7781
7997
|
static fromExtendedKey(extendedKey) {
|
7782
|
-
const decoded = (0,
|
7783
|
-
const bytes = (0,
|
7998
|
+
const decoded = (0, import_ethers4.toBeHex)((0, import_ethers4.decodeBase58)(extendedKey));
|
7999
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
7784
8000
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7785
8001
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7786
8002
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -7789,9 +8005,9 @@ var HDWallet = class {
|
|
7789
8005
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7790
8006
|
}
|
7791
8007
|
const depth = bytes[4];
|
7792
|
-
const parentFingerprint = (0,
|
7793
|
-
const index = parseInt((0,
|
7794
|
-
const chainCode = (0,
|
8008
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8009
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8010
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
7795
8011
|
const key = bytes.slice(45, 78);
|
7796
8012
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7797
8013
|
throw new import_errors20.FuelError(
|
@@ -7984,16 +8200,15 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
7984
8200
|
process.env.GENESIS_SECRET || (0, import_crypto4.randomBytes)(32),
|
7985
8201
|
wallet.provider
|
7986
8202
|
);
|
7987
|
-
const
|
7988
|
-
|
7989
|
-
|
7990
|
-
|
7991
|
-
baseAssetId,
|
7992
|
-
gasLimit: 1e4,
|
7993
|
-
gasPrice: minGasPrice
|
8203
|
+
const request = new ScriptTransactionRequest();
|
8204
|
+
quantities.forEach((quantity) => {
|
8205
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8206
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
7994
8207
|
});
|
7995
|
-
|
7996
|
-
|
8208
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8209
|
+
request.gasLimit = txCost.gasUsed;
|
8210
|
+
request.maxFee = txCost.maxFee;
|
8211
|
+
await genesisWallet.fund(request, txCost);
|
7997
8212
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
7998
8213
|
};
|
7999
8214
|
|
@@ -8007,12 +8222,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8007
8222
|
};
|
8008
8223
|
|
8009
8224
|
// src/test-utils/launchNode.ts
|
8010
|
-
var
|
8011
|
-
var
|
8012
|
-
var import_utils36 = require("@fuel-ts/utils");
|
8225
|
+
var import_configs13 = require("@fuel-ts/address/configs");
|
8226
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8013
8227
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8014
8228
|
var import_child_process = require("child_process");
|
8015
8229
|
var import_crypto5 = require("crypto");
|
8230
|
+
var import_ethers5 = require("ethers");
|
8016
8231
|
var import_fs = require("fs");
|
8017
8232
|
var import_os = __toESM(require("os"));
|
8018
8233
|
var import_path = __toESM(require("path"));
|
@@ -8061,13 +8276,13 @@ var launchNode = async ({
|
|
8061
8276
|
// eslint-disable-next-line no-async-promise-executor
|
8062
8277
|
new Promise(async (resolve, reject) => {
|
8063
8278
|
const remainingArgs = extractRemainingArgs(args, [
|
8064
|
-
"--
|
8279
|
+
"--snapshot",
|
8065
8280
|
"--consensus-key",
|
8066
8281
|
"--db-type",
|
8067
8282
|
"--poa-instant"
|
8068
8283
|
]);
|
8069
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8070
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8284
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
|
8285
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
|
8071
8286
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8072
8287
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8073
8288
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8085,36 +8300,54 @@ var launchNode = async ({
|
|
8085
8300
|
let chainConfigPathToUse;
|
8086
8301
|
const prefix = basePath || import_os.default.tmpdir();
|
8087
8302
|
const suffix = basePath ? "" : (0, import_crypto5.randomUUID)();
|
8088
|
-
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8303
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "chainConfigs");
|
8089
8304
|
if (chainConfigPath) {
|
8090
8305
|
chainConfigPathToUse = chainConfigPath;
|
8091
8306
|
} else {
|
8092
8307
|
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8093
8308
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8094
8309
|
}
|
8095
|
-
|
8096
|
-
|
8310
|
+
let { stateConfigJson } = import_utils35.defaultChainConfigs;
|
8311
|
+
const { chainConfigJson, metadataJson } = import_utils35.defaultChainConfigs;
|
8312
|
+
stateConfigJson = {
|
8313
|
+
...stateConfigJson,
|
8314
|
+
coins: [
|
8315
|
+
...stateConfigJson.coins.map((coin) => ({
|
8316
|
+
...coin,
|
8317
|
+
amount: "18446744073709551615"
|
8318
|
+
}))
|
8319
|
+
],
|
8320
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8321
|
+
...message,
|
8322
|
+
amount: "18446744073709551615"
|
8323
|
+
}))
|
8324
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8325
|
+
};
|
8097
8326
|
if (!process.env.GENESIS_SECRET) {
|
8098
8327
|
const pk = Signer.generatePrivateKey();
|
8099
8328
|
const signer = new Signer(pk);
|
8100
|
-
process.env.GENESIS_SECRET = (0,
|
8101
|
-
|
8102
|
-
|
8103
|
-
|
8104
|
-
|
8105
|
-
|
8106
|
-
|
8107
|
-
|
8108
|
-
|
8109
|
-
|
8110
|
-
|
8111
|
-
}
|
8112
|
-
]
|
8113
|
-
}
|
8114
|
-
};
|
8329
|
+
process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
|
8330
|
+
stateConfigJson.coins.push({
|
8331
|
+
tx_id: (0, import_utils35.hexlify)((0, import_ethers5.randomBytes)(34)),
|
8332
|
+
owner: signer.address.toHexString(),
|
8333
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8334
|
+
amount: "18446744073709551615",
|
8335
|
+
asset_id: import_configs13.BaseAssetId,
|
8336
|
+
output_index: 0,
|
8337
|
+
tx_pointer_block_height: 0,
|
8338
|
+
tx_pointer_tx_idx: 0
|
8339
|
+
});
|
8115
8340
|
}
|
8116
|
-
|
8117
|
-
|
8341
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8342
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8343
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8344
|
+
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8345
|
+
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8346
|
+
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8347
|
+
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8348
|
+
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8349
|
+
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8350
|
+
chainConfigPathToUse = tempDirPath;
|
8118
8351
|
}
|
8119
8352
|
const child = (0, import_child_process.spawn)(
|
8120
8353
|
command,
|
@@ -8123,10 +8356,10 @@ var launchNode = async ({
|
|
8123
8356
|
["--ip", ipToUse],
|
8124
8357
|
["--port", portToUse],
|
8125
8358
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8126
|
-
["--min-gas-price", "
|
8359
|
+
["--min-gas-price", "1"],
|
8127
8360
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8128
8361
|
["--consensus-key", consensusKey],
|
8129
|
-
["--
|
8362
|
+
["--snapshot", chainConfigPathToUse],
|
8130
8363
|
"--vm-backtrace",
|
8131
8364
|
"--utxo-validation",
|
8132
8365
|
"--debug",
|
@@ -8173,10 +8406,9 @@ var launchNode = async ({
|
|
8173
8406
|
})
|
8174
8407
|
);
|
8175
8408
|
var generateWallets = async (count, provider) => {
|
8176
|
-
const baseAssetId = provider.getBaseAssetId();
|
8177
8409
|
const wallets = [];
|
8178
8410
|
for (let i = 0; i < count; i += 1) {
|
8179
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8411
|
+
const wallet = await generateTestWallet(provider, [[1e3, import_configs13.BaseAssetId]]);
|
8180
8412
|
wallets.push(wallet);
|
8181
8413
|
}
|
8182
8414
|
return wallets;
|
@@ -8186,7 +8418,7 @@ var launchNodeAndGetWallets = async ({
|
|
8186
8418
|
walletCount = 10
|
8187
8419
|
} = {}) => {
|
8188
8420
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8189
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8421
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8190
8422
|
const wallets = await generateWallets(walletCount, provider);
|
8191
8423
|
const cleanup = () => {
|
8192
8424
|
closeNode();
|