@fuel-ts/account 0.0.0-rc-2152-20240425194419 → 0.0.0-rc-2021-20240425202957
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 +7 -6
- 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 +1818 -696
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +796 -545
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +671 -421
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +12 -24
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +810 -359
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.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 +46 -27
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +8 -28
- 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 +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +2544 -1193
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +782 -536
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +669 -423
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.js
CHANGED
@@ -58,14 +58,15 @@ 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
65
|
var import_errors16 = require("@fuel-ts/errors");
|
66
66
|
var import_interfaces = require("@fuel-ts/interfaces");
|
67
|
-
var
|
68
|
-
var
|
67
|
+
var import_math19 = require("@fuel-ts/math");
|
68
|
+
var import_utils27 = require("@fuel-ts/utils");
|
69
|
+
var import_ramda4 = require("ramda");
|
69
70
|
|
70
71
|
// src/providers/coin-quantity.ts
|
71
72
|
var import_math = require("@fuel-ts/math");
|
@@ -73,24 +74,24 @@ var import_utils = require("@fuel-ts/utils");
|
|
73
74
|
var coinQuantityfy = (coinQuantityLike) => {
|
74
75
|
let assetId;
|
75
76
|
let amount;
|
76
|
-
let
|
77
|
+
let max;
|
77
78
|
if (Array.isArray(coinQuantityLike)) {
|
78
79
|
amount = coinQuantityLike[0];
|
79
80
|
assetId = coinQuantityLike[1];
|
80
|
-
|
81
|
+
max = coinQuantityLike[2] ?? void 0;
|
81
82
|
} else {
|
82
83
|
amount = coinQuantityLike.amount;
|
83
84
|
assetId = coinQuantityLike.assetId;
|
84
|
-
|
85
|
+
max = coinQuantityLike.max ?? void 0;
|
85
86
|
}
|
86
87
|
const bnAmount = (0, import_math.bn)(amount);
|
87
88
|
return {
|
88
89
|
assetId: (0, import_utils.hexlify)(assetId),
|
89
90
|
amount: bnAmount.lt(1) ? (0, import_math.bn)(1) : bnAmount,
|
90
|
-
max:
|
91
|
+
max: max ? (0, import_math.bn)(max) : void 0
|
91
92
|
};
|
92
93
|
};
|
93
|
-
var
|
94
|
+
var addAmountToCoinQuantities = (params) => {
|
94
95
|
const { amount, assetId } = params;
|
95
96
|
const coinQuantities = [...params.coinQuantities];
|
96
97
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -105,26 +106,31 @@ var addAmountToAsset = (params) => {
|
|
105
106
|
// src/providers/provider.ts
|
106
107
|
var import_address3 = require("@fuel-ts/address");
|
107
108
|
var import_errors14 = require("@fuel-ts/errors");
|
108
|
-
var
|
109
|
-
var
|
110
|
-
var
|
109
|
+
var import_math16 = require("@fuel-ts/math");
|
110
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
111
|
+
var import_utils22 = require("@fuel-ts/utils");
|
111
112
|
var import_versions = require("@fuel-ts/versions");
|
112
|
-
var
|
113
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
114
|
+
var import_ethers = require("ethers");
|
113
115
|
var import_graphql_request = require("graphql-request");
|
114
116
|
var import_ramda3 = require("ramda");
|
115
117
|
|
116
118
|
// src/providers/__generated__/operations.ts
|
117
119
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
120
|
+
var TransactionStatusSubscriptionFragmentFragmentDoc = import_graphql_tag.default`
|
121
|
+
fragment transactionStatusSubscriptionFragment on TransactionStatus {
|
122
|
+
type: __typename
|
123
|
+
... on SqueezedOutStatus {
|
124
|
+
reason
|
125
|
+
}
|
126
|
+
}
|
127
|
+
`;
|
118
128
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
119
129
|
fragment receiptFragment on Receipt {
|
120
|
-
|
121
|
-
id
|
122
|
-
}
|
130
|
+
id
|
123
131
|
pc
|
124
132
|
is
|
125
|
-
to
|
126
|
-
id
|
127
|
-
}
|
133
|
+
to
|
128
134
|
toAddress
|
129
135
|
amount
|
130
136
|
assetId
|
@@ -162,10 +168,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
162
168
|
id
|
163
169
|
}
|
164
170
|
time
|
171
|
+
receipts {
|
172
|
+
...receiptFragment
|
173
|
+
}
|
165
174
|
programState {
|
166
175
|
returnType
|
167
176
|
data
|
168
177
|
}
|
178
|
+
receipts {
|
179
|
+
...receiptFragment
|
180
|
+
}
|
169
181
|
}
|
170
182
|
... on FailureStatus {
|
171
183
|
block {
|
@@ -173,26 +185,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
173
185
|
}
|
174
186
|
time
|
175
187
|
reason
|
188
|
+
receipts {
|
189
|
+
...receiptFragment
|
190
|
+
}
|
176
191
|
}
|
177
192
|
... on SqueezedOutStatus {
|
178
193
|
reason
|
179
194
|
}
|
180
195
|
}
|
181
|
-
`;
|
196
|
+
${ReceiptFragmentFragmentDoc}`;
|
182
197
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
183
198
|
fragment transactionFragment on Transaction {
|
184
199
|
id
|
185
200
|
rawPayload
|
186
|
-
gasPrice
|
187
|
-
receipts {
|
188
|
-
...receiptFragment
|
189
|
-
}
|
190
201
|
status {
|
191
202
|
...transactionStatusFragment
|
192
203
|
}
|
193
204
|
}
|
194
|
-
${
|
195
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
205
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
196
206
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
197
207
|
fragment inputEstimatePredicatesFragment on Input {
|
198
208
|
... on InputCoin {
|
@@ -210,6 +220,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
210
220
|
}
|
211
221
|
}
|
212
222
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
223
|
+
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
224
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
225
|
+
reason
|
226
|
+
programState {
|
227
|
+
returnType
|
228
|
+
data
|
229
|
+
}
|
230
|
+
}
|
231
|
+
`;
|
232
|
+
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
233
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
234
|
+
programState {
|
235
|
+
returnType
|
236
|
+
data
|
237
|
+
}
|
238
|
+
}
|
239
|
+
`;
|
240
|
+
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
241
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
242
|
+
... on DryRunFailureStatus {
|
243
|
+
...dryRunFailureStatusFragment
|
244
|
+
}
|
245
|
+
... on DryRunSuccessStatus {
|
246
|
+
...dryRunSuccessStatusFragment
|
247
|
+
}
|
248
|
+
}
|
249
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
250
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
251
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
252
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
253
|
+
id
|
254
|
+
status {
|
255
|
+
...dryRunTransactionStatusFragment
|
256
|
+
}
|
257
|
+
receipts {
|
258
|
+
...receiptFragment
|
259
|
+
}
|
260
|
+
}
|
261
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
262
|
+
${ReceiptFragmentFragmentDoc}`;
|
213
263
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
214
264
|
fragment coinFragment on Coin {
|
215
265
|
__typename
|
@@ -217,7 +267,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
217
267
|
owner
|
218
268
|
amount
|
219
269
|
assetId
|
220
|
-
maturity
|
221
270
|
blockCreated
|
222
271
|
txCreatedIdx
|
223
272
|
}
|
@@ -256,26 +305,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
256
305
|
messageBlockHeader {
|
257
306
|
id
|
258
307
|
daHeight
|
308
|
+
consensusParametersVersion
|
309
|
+
stateTransitionBytecodeVersion
|
259
310
|
transactionsCount
|
311
|
+
messageReceiptCount
|
260
312
|
transactionsRoot
|
313
|
+
messageOutboxRoot
|
314
|
+
eventInboxRoot
|
261
315
|
height
|
262
316
|
prevRoot
|
263
317
|
time
|
264
318
|
applicationHash
|
265
|
-
messageReceiptRoot
|
266
|
-
messageReceiptCount
|
267
319
|
}
|
268
320
|
commitBlockHeader {
|
269
321
|
id
|
270
322
|
daHeight
|
323
|
+
consensusParametersVersion
|
324
|
+
stateTransitionBytecodeVersion
|
271
325
|
transactionsCount
|
326
|
+
messageReceiptCount
|
272
327
|
transactionsRoot
|
328
|
+
messageOutboxRoot
|
329
|
+
eventInboxRoot
|
273
330
|
height
|
274
331
|
prevRoot
|
275
332
|
time
|
276
333
|
applicationHash
|
277
|
-
messageReceiptRoot
|
278
|
-
messageReceiptCount
|
279
334
|
}
|
280
335
|
sender
|
281
336
|
recipient
|
@@ -294,8 +349,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
294
349
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
295
350
|
fragment blockFragment on Block {
|
296
351
|
id
|
352
|
+
height
|
297
353
|
header {
|
298
|
-
height
|
299
354
|
time
|
300
355
|
}
|
301
356
|
transactions {
|
@@ -305,6 +360,7 @@ var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
|
305
360
|
`;
|
306
361
|
var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
|
307
362
|
fragment TxParametersFragment on TxParameters {
|
363
|
+
version
|
308
364
|
maxInputs
|
309
365
|
maxOutputs
|
310
366
|
maxWitnesses
|
@@ -314,6 +370,7 @@ var TxParametersFragmentFragmentDoc = import_graphql_tag.default`
|
|
314
370
|
`;
|
315
371
|
var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
|
316
372
|
fragment PredicateParametersFragment on PredicateParameters {
|
373
|
+
version
|
317
374
|
maxPredicateLength
|
318
375
|
maxPredicateDataLength
|
319
376
|
maxGasPerPredicate
|
@@ -322,18 +379,21 @@ var PredicateParametersFragmentFragmentDoc = import_graphql_tag.default`
|
|
322
379
|
`;
|
323
380
|
var ScriptParametersFragmentFragmentDoc = import_graphql_tag.default`
|
324
381
|
fragment ScriptParametersFragment on ScriptParameters {
|
382
|
+
version
|
325
383
|
maxScriptLength
|
326
384
|
maxScriptDataLength
|
327
385
|
}
|
328
386
|
`;
|
329
387
|
var ContractParametersFragmentFragmentDoc = import_graphql_tag.default`
|
330
388
|
fragment ContractParametersFragment on ContractParameters {
|
389
|
+
version
|
331
390
|
contractMaxSize
|
332
391
|
maxStorageSlots
|
333
392
|
}
|
334
393
|
`;
|
335
394
|
var FeeParametersFragmentFragmentDoc = import_graphql_tag.default`
|
336
395
|
fragment FeeParametersFragment on FeeParameters {
|
396
|
+
version
|
337
397
|
gasPriceFactor
|
338
398
|
gasPerByte
|
339
399
|
}
|
@@ -353,6 +413,7 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
353
413
|
`;
|
354
414
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
355
415
|
fragment GasCostsFragment on GasCosts {
|
416
|
+
version
|
356
417
|
add
|
357
418
|
addi
|
358
419
|
aloc
|
@@ -365,7 +426,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
365
426
|
cb
|
366
427
|
cfei
|
367
428
|
cfsi
|
368
|
-
croo
|
369
429
|
div
|
370
430
|
divi
|
371
431
|
ecr1
|
@@ -448,6 +508,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
448
508
|
ccp {
|
449
509
|
...DependentCostFragment
|
450
510
|
}
|
511
|
+
croo {
|
512
|
+
...DependentCostFragment
|
513
|
+
}
|
451
514
|
csiz {
|
452
515
|
...DependentCostFragment
|
453
516
|
}
|
@@ -507,6 +570,7 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
507
570
|
${DependentCostFragmentFragmentDoc}`;
|
508
571
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
509
572
|
fragment consensusParametersFragment on ConsensusParameters {
|
573
|
+
version
|
510
574
|
txParams {
|
511
575
|
...TxParametersFragment
|
512
576
|
}
|
@@ -566,18 +630,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
566
630
|
fragment nodeInfoFragment on NodeInfo {
|
567
631
|
utxoValidation
|
568
632
|
vmBacktrace
|
569
|
-
minGasPrice
|
570
633
|
maxTx
|
571
634
|
maxDepth
|
572
635
|
nodeVersion
|
573
|
-
peers {
|
574
|
-
id
|
575
|
-
addresses
|
576
|
-
clientVersion
|
577
|
-
blockHeight
|
578
|
-
lastHeartbeatMs
|
579
|
-
appScore
|
580
|
-
}
|
581
636
|
}
|
582
637
|
`;
|
583
638
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -612,13 +667,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
612
667
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
613
668
|
transaction(id: $transactionId) {
|
614
669
|
...transactionFragment
|
615
|
-
receipts {
|
616
|
-
...receiptFragment
|
617
|
-
}
|
618
670
|
}
|
619
671
|
}
|
620
|
-
${TransactionFragmentFragmentDoc}
|
621
|
-
${ReceiptFragmentFragmentDoc}`;
|
672
|
+
${TransactionFragmentFragmentDoc}`;
|
622
673
|
var GetTransactionsDocument = import_graphql_tag.default`
|
623
674
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
624
675
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -746,6 +797,20 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
746
797
|
}
|
747
798
|
}
|
748
799
|
${BalanceFragmentFragmentDoc}`;
|
800
|
+
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
801
|
+
query getLatestGasPrice {
|
802
|
+
latestGasPrice {
|
803
|
+
gasPrice
|
804
|
+
}
|
805
|
+
}
|
806
|
+
`;
|
807
|
+
var EstimateGasPriceDocument = import_graphql_tag.default`
|
808
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
809
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
810
|
+
gasPrice
|
811
|
+
}
|
812
|
+
}
|
813
|
+
`;
|
749
814
|
var GetBalancesDocument = import_graphql_tag.default`
|
750
815
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
751
816
|
balances(
|
@@ -800,12 +865,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
800
865
|
}
|
801
866
|
`;
|
802
867
|
var DryRunDocument = import_graphql_tag.default`
|
803
|
-
mutation dryRun($
|
804
|
-
dryRun(
|
805
|
-
...
|
868
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
869
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
870
|
+
...dryRunTransactionExecutionStatusFragment
|
806
871
|
}
|
807
872
|
}
|
808
|
-
${
|
873
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
809
874
|
var SubmitDocument = import_graphql_tag.default`
|
810
875
|
mutation submit($encodedTransaction: HexString!) {
|
811
876
|
submit(tx: $encodedTransaction) {
|
@@ -824,17 +889,17 @@ var ProduceBlocksDocument = import_graphql_tag.default`
|
|
824
889
|
var SubmitAndAwaitDocument = import_graphql_tag.default`
|
825
890
|
subscription submitAndAwait($encodedTransaction: HexString!) {
|
826
891
|
submitAndAwait(tx: $encodedTransaction) {
|
827
|
-
...
|
892
|
+
...transactionStatusSubscriptionFragment
|
828
893
|
}
|
829
894
|
}
|
830
|
-
${
|
895
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
831
896
|
var StatusChangeDocument = import_graphql_tag.default`
|
832
897
|
subscription statusChange($transactionId: TransactionId!) {
|
833
898
|
statusChange(id: $transactionId) {
|
834
|
-
...
|
899
|
+
...transactionStatusSubscriptionFragment
|
835
900
|
}
|
836
901
|
}
|
837
|
-
${
|
902
|
+
${TransactionStatusSubscriptionFragmentFragmentDoc}`;
|
838
903
|
function getSdk(requester) {
|
839
904
|
return {
|
840
905
|
getVersion(variables, options) {
|
@@ -888,6 +953,12 @@ function getSdk(requester) {
|
|
888
953
|
getBalance(variables, options) {
|
889
954
|
return requester(GetBalanceDocument, variables, options);
|
890
955
|
},
|
956
|
+
getLatestGasPrice(variables, options) {
|
957
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
958
|
+
},
|
959
|
+
estimateGasPrice(variables, options) {
|
960
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
961
|
+
},
|
891
962
|
getBalances(variables, options) {
|
892
963
|
return requester(GetBalancesDocument, variables, options);
|
893
964
|
},
|
@@ -1081,10 +1152,9 @@ var inputify = (value) => {
|
|
1081
1152
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1082
1153
|
},
|
1083
1154
|
witnessIndex: value.witnessIndex,
|
1084
|
-
maturity: value.maturity ?? 0,
|
1085
1155
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1086
|
-
predicateLength: predicate.length,
|
1087
|
-
predicateDataLength: predicateData.length,
|
1156
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1157
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1088
1158
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1089
1159
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1090
1160
|
};
|
@@ -1115,8 +1185,8 @@ var inputify = (value) => {
|
|
1115
1185
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1116
1186
|
witnessIndex: value.witnessIndex,
|
1117
1187
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1118
|
-
predicateLength: predicate.length,
|
1119
|
-
predicateDataLength: predicateData.length,
|
1188
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1189
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1120
1190
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1121
1191
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1122
1192
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1232,8 +1302,8 @@ function assembleReceiptByType(receipt) {
|
|
1232
1302
|
case "CALL" /* Call */: {
|
1233
1303
|
const callReceipt = {
|
1234
1304
|
type: import_transactions3.ReceiptType.Call,
|
1235
|
-
from: hexOrZero(receipt.
|
1236
|
-
to: hexOrZero(receipt?.to
|
1305
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1306
|
+
to: hexOrZero(receipt?.to),
|
1237
1307
|
amount: (0, import_math4.bn)(receipt.amount),
|
1238
1308
|
assetId: hexOrZero(receipt.assetId),
|
1239
1309
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1247,7 +1317,7 @@ function assembleReceiptByType(receipt) {
|
|
1247
1317
|
case "RETURN" /* Return */: {
|
1248
1318
|
const returnReceipt = {
|
1249
1319
|
type: import_transactions3.ReceiptType.Return,
|
1250
|
-
id: hexOrZero(receipt.
|
1320
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1251
1321
|
val: (0, import_math4.bn)(receipt.val),
|
1252
1322
|
pc: (0, import_math4.bn)(receipt.pc),
|
1253
1323
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1257,7 +1327,7 @@ function assembleReceiptByType(receipt) {
|
|
1257
1327
|
case "RETURN_DATA" /* ReturnData */: {
|
1258
1328
|
const returnDataReceipt = {
|
1259
1329
|
type: import_transactions3.ReceiptType.ReturnData,
|
1260
|
-
id: hexOrZero(receipt.
|
1330
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1261
1331
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1262
1332
|
len: (0, import_math4.bn)(receipt.len),
|
1263
1333
|
digest: hexOrZero(receipt.digest),
|
@@ -1269,7 +1339,7 @@ function assembleReceiptByType(receipt) {
|
|
1269
1339
|
case "PANIC" /* Panic */: {
|
1270
1340
|
const panicReceipt = {
|
1271
1341
|
type: import_transactions3.ReceiptType.Panic,
|
1272
|
-
id: hexOrZero(receipt.
|
1342
|
+
id: hexOrZero(receipt.id),
|
1273
1343
|
reason: (0, import_math4.bn)(receipt.reason),
|
1274
1344
|
pc: (0, import_math4.bn)(receipt.pc),
|
1275
1345
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1280,7 +1350,7 @@ function assembleReceiptByType(receipt) {
|
|
1280
1350
|
case "REVERT" /* Revert */: {
|
1281
1351
|
const revertReceipt = {
|
1282
1352
|
type: import_transactions3.ReceiptType.Revert,
|
1283
|
-
id: hexOrZero(receipt.
|
1353
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1284
1354
|
val: (0, import_math4.bn)(receipt.ra),
|
1285
1355
|
pc: (0, import_math4.bn)(receipt.pc),
|
1286
1356
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1290,7 +1360,7 @@ function assembleReceiptByType(receipt) {
|
|
1290
1360
|
case "LOG" /* Log */: {
|
1291
1361
|
const logReceipt = {
|
1292
1362
|
type: import_transactions3.ReceiptType.Log,
|
1293
|
-
id: hexOrZero(receipt.
|
1363
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1294
1364
|
val0: (0, import_math4.bn)(receipt.ra),
|
1295
1365
|
val1: (0, import_math4.bn)(receipt.rb),
|
1296
1366
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1303,7 +1373,7 @@ function assembleReceiptByType(receipt) {
|
|
1303
1373
|
case "LOG_DATA" /* LogData */: {
|
1304
1374
|
const logDataReceipt = {
|
1305
1375
|
type: import_transactions3.ReceiptType.LogData,
|
1306
|
-
id: hexOrZero(receipt.
|
1376
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1307
1377
|
val0: (0, import_math4.bn)(receipt.ra),
|
1308
1378
|
val1: (0, import_math4.bn)(receipt.rb),
|
1309
1379
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1317,8 +1387,8 @@ function assembleReceiptByType(receipt) {
|
|
1317
1387
|
case "TRANSFER" /* Transfer */: {
|
1318
1388
|
const transferReceipt = {
|
1319
1389
|
type: import_transactions3.ReceiptType.Transfer,
|
1320
|
-
from: hexOrZero(receipt.
|
1321
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1390
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1391
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1322
1392
|
amount: (0, import_math4.bn)(receipt.amount),
|
1323
1393
|
assetId: hexOrZero(receipt.assetId),
|
1324
1394
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1329,8 +1399,8 @@ function assembleReceiptByType(receipt) {
|
|
1329
1399
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1330
1400
|
const transferOutReceipt = {
|
1331
1401
|
type: import_transactions3.ReceiptType.TransferOut,
|
1332
|
-
from: hexOrZero(receipt.
|
1333
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1402
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1403
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1334
1404
|
amount: (0, import_math4.bn)(receipt.amount),
|
1335
1405
|
assetId: hexOrZero(receipt.assetId),
|
1336
1406
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1373,7 +1443,7 @@ function assembleReceiptByType(receipt) {
|
|
1373
1443
|
return receiptMessageOut;
|
1374
1444
|
}
|
1375
1445
|
case "MINT" /* Mint */: {
|
1376
|
-
const contractId = hexOrZero(receipt.
|
1446
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1377
1447
|
const subId = hexOrZero(receipt.subId);
|
1378
1448
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1379
1449
|
const mintReceipt = {
|
@@ -1388,7 +1458,7 @@ function assembleReceiptByType(receipt) {
|
|
1388
1458
|
return mintReceipt;
|
1389
1459
|
}
|
1390
1460
|
case "BURN" /* Burn */: {
|
1391
|
-
const contractId = hexOrZero(receipt.
|
1461
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1392
1462
|
const subId = hexOrZero(receipt.subId);
|
1393
1463
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1394
1464
|
const burnReceipt = {
|
@@ -1414,7 +1484,6 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1414
1484
|
var import_math5 = require("@fuel-ts/math");
|
1415
1485
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1416
1486
|
var import_utils6 = require("@fuel-ts/utils");
|
1417
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1418
1487
|
var getGasUsedFromReceipts = (receipts) => {
|
1419
1488
|
const scriptResult = receipts.filter(
|
1420
1489
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1435,18 +1504,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1435
1504
|
}
|
1436
1505
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1437
1506
|
const witnessCache = [];
|
1438
|
-
const
|
1507
|
+
const chargeableInputs = inputs.filter((input) => {
|
1508
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1509
|
+
if (isCoinOrMessage) {
|
1510
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1511
|
+
return true;
|
1512
|
+
}
|
1513
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1514
|
+
witnessCache.push(input.witnessIndex);
|
1515
|
+
return true;
|
1516
|
+
}
|
1517
|
+
}
|
1518
|
+
return false;
|
1519
|
+
});
|
1520
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1521
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1439
1522
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1440
1523
|
return total.add(
|
1441
|
-
|
1524
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1442
1525
|
);
|
1443
1526
|
}
|
1444
|
-
|
1445
|
-
|
1446
|
-
return total.add(gasCosts.ecr1);
|
1447
|
-
}
|
1448
|
-
return total;
|
1449
|
-
}, (0, import_math5.bn)());
|
1527
|
+
return total.add(gasCosts.ecr1);
|
1528
|
+
}, (0, import_math5.bn)(0));
|
1450
1529
|
return totalGas;
|
1451
1530
|
}
|
1452
1531
|
function getMinGas(params) {
|
@@ -1458,12 +1537,20 @@ function getMinGas(params) {
|
|
1458
1537
|
return minGas;
|
1459
1538
|
}
|
1460
1539
|
function getMaxGas(params) {
|
1461
|
-
const {
|
1540
|
+
const {
|
1541
|
+
gasPerByte,
|
1542
|
+
witnessesLength,
|
1543
|
+
witnessLimit,
|
1544
|
+
minGas,
|
1545
|
+
gasLimit = (0, import_math5.bn)(0),
|
1546
|
+
maxGasPerTx
|
1547
|
+
} = params;
|
1462
1548
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1463
1549
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1464
1550
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1465
1551
|
}
|
1466
|
-
|
1552
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1553
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1467
1554
|
}
|
1468
1555
|
function calculateMetadataGasForTxCreate({
|
1469
1556
|
gasCosts,
|
@@ -1485,6 +1572,10 @@ function calculateMetadataGasForTxScript({
|
|
1485
1572
|
}) {
|
1486
1573
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1487
1574
|
}
|
1575
|
+
var calculateGasFee = (params) => {
|
1576
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1577
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1578
|
+
};
|
1488
1579
|
|
1489
1580
|
// src/providers/utils/json.ts
|
1490
1581
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1621,7 +1712,7 @@ var witnessify = (value) => {
|
|
1621
1712
|
// src/providers/transaction-request/transaction-request.ts
|
1622
1713
|
var BaseTransactionRequest = class {
|
1623
1714
|
/** Gas price for transaction */
|
1624
|
-
|
1715
|
+
tip;
|
1625
1716
|
/** Block until which tx cannot be included */
|
1626
1717
|
maturity;
|
1627
1718
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1640,7 +1731,7 @@ var BaseTransactionRequest = class {
|
|
1640
1731
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1641
1732
|
*/
|
1642
1733
|
constructor({
|
1643
|
-
|
1734
|
+
tip,
|
1644
1735
|
maturity,
|
1645
1736
|
maxFee,
|
1646
1737
|
witnessLimit,
|
@@ -1648,7 +1739,7 @@ var BaseTransactionRequest = class {
|
|
1648
1739
|
outputs,
|
1649
1740
|
witnesses
|
1650
1741
|
} = {}) {
|
1651
|
-
this.
|
1742
|
+
this.tip = (0, import_math7.bn)(tip);
|
1652
1743
|
this.maturity = maturity ?? 0;
|
1653
1744
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1654
1745
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1659,9 +1750,9 @@ var BaseTransactionRequest = class {
|
|
1659
1750
|
static getPolicyMeta(req) {
|
1660
1751
|
let policyTypes = 0;
|
1661
1752
|
const policies = [];
|
1662
|
-
if (req.
|
1663
|
-
policyTypes += import_transactions6.PolicyType.
|
1664
|
-
policies.push({ data: req.
|
1753
|
+
if (req.tip) {
|
1754
|
+
policyTypes += import_transactions6.PolicyType.Tip;
|
1755
|
+
policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
|
1665
1756
|
}
|
1666
1757
|
if (req.witnessLimit) {
|
1667
1758
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -1845,13 +1936,11 @@ var BaseTransactionRequest = class {
|
|
1845
1936
|
* assetId, if one it was not added yet.
|
1846
1937
|
*
|
1847
1938
|
* @param coin - Coin resource.
|
1848
|
-
* @param predicate - Predicate bytes.
|
1849
|
-
* @param predicateData - Predicate data bytes.
|
1850
1939
|
*/
|
1851
|
-
addCoinInput(coin
|
1940
|
+
addCoinInput(coin) {
|
1852
1941
|
const { assetId, owner, amount } = coin;
|
1853
1942
|
let witnessIndex;
|
1854
|
-
if (predicate) {
|
1943
|
+
if (coin.predicate) {
|
1855
1944
|
witnessIndex = 0;
|
1856
1945
|
} else {
|
1857
1946
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1866,8 +1955,7 @@ var BaseTransactionRequest = class {
|
|
1866
1955
|
amount,
|
1867
1956
|
assetId,
|
1868
1957
|
txPointer: "0x00000000000000000000000000000000",
|
1869
|
-
witnessIndex
|
1870
|
-
predicate: predicate?.bytes
|
1958
|
+
witnessIndex
|
1871
1959
|
};
|
1872
1960
|
this.pushInput(input);
|
1873
1961
|
this.addChangeOutput(owner, assetId);
|
@@ -1877,12 +1965,11 @@ var BaseTransactionRequest = class {
|
|
1877
1965
|
* asset against the message
|
1878
1966
|
*
|
1879
1967
|
* @param message - Message resource.
|
1880
|
-
* @param predicate - Predicate bytes.
|
1881
1968
|
*/
|
1882
|
-
addMessageInput(message
|
1969
|
+
addMessageInput(message) {
|
1883
1970
|
const { recipient, sender, amount, assetId } = message;
|
1884
1971
|
let witnessIndex;
|
1885
|
-
if (predicate) {
|
1972
|
+
if (message.predicate) {
|
1886
1973
|
witnessIndex = 0;
|
1887
1974
|
} else {
|
1888
1975
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1896,8 +1983,7 @@ var BaseTransactionRequest = class {
|
|
1896
1983
|
sender: sender.toB256(),
|
1897
1984
|
recipient: recipient.toB256(),
|
1898
1985
|
amount,
|
1899
|
-
witnessIndex
|
1900
|
-
predicate: predicate?.bytes
|
1986
|
+
witnessIndex
|
1901
1987
|
};
|
1902
1988
|
this.pushInput(input);
|
1903
1989
|
this.addChangeOutput(recipient, assetId);
|
@@ -1928,32 +2014,6 @@ var BaseTransactionRequest = class {
|
|
1928
2014
|
resources.forEach((resource) => this.addResource(resource));
|
1929
2015
|
return this;
|
1930
2016
|
}
|
1931
|
-
/**
|
1932
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1933
|
-
* outputs from the related assetIds.
|
1934
|
-
*
|
1935
|
-
* @param resources - The resources to add.
|
1936
|
-
* @returns This transaction.
|
1937
|
-
*/
|
1938
|
-
addPredicateResource(resource, predicate) {
|
1939
|
-
if (isCoin(resource)) {
|
1940
|
-
this.addCoinInput(resource, predicate);
|
1941
|
-
} else {
|
1942
|
-
this.addMessageInput(resource, predicate);
|
1943
|
-
}
|
1944
|
-
return this;
|
1945
|
-
}
|
1946
|
-
/**
|
1947
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1948
|
-
* from the related assetIds.
|
1949
|
-
*
|
1950
|
-
* @param resources - The resources to add.
|
1951
|
-
* @returns This transaction.
|
1952
|
-
*/
|
1953
|
-
addPredicateResources(resources, predicate) {
|
1954
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1955
|
-
return this;
|
1956
|
-
}
|
1957
2017
|
/**
|
1958
2018
|
* Adds a coin output to the transaction.
|
1959
2019
|
*
|
@@ -2033,7 +2093,7 @@ var BaseTransactionRequest = class {
|
|
2033
2093
|
}
|
2034
2094
|
calculateMaxGas(chainInfo, minGas) {
|
2035
2095
|
const { consensusParameters } = chainInfo;
|
2036
|
-
const { gasPerByte } = consensusParameters;
|
2096
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2037
2097
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2038
2098
|
(acc, wit) => acc + wit.dataLength,
|
2039
2099
|
0
|
@@ -2042,7 +2102,8 @@ var BaseTransactionRequest = class {
|
|
2042
2102
|
gasPerByte,
|
2043
2103
|
minGas,
|
2044
2104
|
witnessesLength,
|
2045
|
-
witnessLimit: this.witnessLimit
|
2105
|
+
witnessLimit: this.witnessLimit,
|
2106
|
+
maxGasPerTx
|
2046
2107
|
});
|
2047
2108
|
}
|
2048
2109
|
/**
|
@@ -2061,17 +2122,20 @@ var BaseTransactionRequest = class {
|
|
2061
2122
|
});
|
2062
2123
|
const updateAssetInput = (assetId, quantity) => {
|
2063
2124
|
const assetInput = findAssetInput(assetId);
|
2125
|
+
let usedQuantity = quantity;
|
2126
|
+
if (assetId === baseAssetId) {
|
2127
|
+
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2128
|
+
}
|
2064
2129
|
if (assetInput && "assetId" in assetInput) {
|
2065
2130
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2066
|
-
assetInput.amount =
|
2131
|
+
assetInput.amount = usedQuantity;
|
2067
2132
|
} else {
|
2068
2133
|
this.addResources([
|
2069
2134
|
{
|
2070
2135
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2071
|
-
amount:
|
2136
|
+
amount: usedQuantity,
|
2072
2137
|
assetId,
|
2073
2138
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2074
|
-
maturity: 0,
|
2075
2139
|
blockCreated: (0, import_math7.bn)(1),
|
2076
2140
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2077
2141
|
}
|
@@ -2103,7 +2167,7 @@ var BaseTransactionRequest = class {
|
|
2103
2167
|
toJSON() {
|
2104
2168
|
return normalizeJSON(this);
|
2105
2169
|
}
|
2106
|
-
|
2170
|
+
updatePredicateGasUsed(inputs) {
|
2107
2171
|
this.inputs.forEach((i) => {
|
2108
2172
|
let correspondingInput;
|
2109
2173
|
switch (i.type) {
|
@@ -2125,6 +2189,15 @@ var BaseTransactionRequest = class {
|
|
2125
2189
|
}
|
2126
2190
|
});
|
2127
2191
|
}
|
2192
|
+
shiftPredicateData() {
|
2193
|
+
this.inputs.forEach((input) => {
|
2194
|
+
if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
|
2195
|
+
input.predicateData = input.padPredicateData(
|
2196
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2197
|
+
);
|
2198
|
+
}
|
2199
|
+
});
|
2200
|
+
}
|
2128
2201
|
};
|
2129
2202
|
|
2130
2203
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2266,9 +2339,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2266
2339
|
return {
|
2267
2340
|
type: import_transactions8.TransactionType.Create,
|
2268
2341
|
...baseTransaction,
|
2269
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2270
2342
|
bytecodeWitnessIndex,
|
2271
|
-
storageSlotsCount: storageSlots.length,
|
2343
|
+
storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
|
2272
2344
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
|
2273
2345
|
storageSlots
|
2274
2346
|
};
|
@@ -2391,8 +2463,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2391
2463
|
type: import_transactions9.TransactionType.Script,
|
2392
2464
|
scriptGasLimit: this.gasLimit,
|
2393
2465
|
...super.getBaseTransaction(),
|
2394
|
-
scriptLength: script.length,
|
2395
|
-
scriptDataLength: scriptData.length,
|
2466
|
+
scriptLength: (0, import_math10.bn)(script.length),
|
2467
|
+
scriptDataLength: (0, import_math10.bn)(scriptData.length),
|
2396
2468
|
receiptsRoot: import_configs9.ZeroBytes32,
|
2397
2469
|
script: (0, import_utils15.hexlify)(script),
|
2398
2470
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2456,7 +2528,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2456
2528
|
}
|
2457
2529
|
calculateMaxGas(chainInfo, minGas) {
|
2458
2530
|
const { consensusParameters } = chainInfo;
|
2459
|
-
const { gasPerByte } = consensusParameters;
|
2531
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2460
2532
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2461
2533
|
(acc, wit) => acc + wit.dataLength,
|
2462
2534
|
0
|
@@ -2466,7 +2538,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2466
2538
|
minGas,
|
2467
2539
|
witnessesLength,
|
2468
2540
|
witnessLimit: this.witnessLimit,
|
2469
|
-
gasLimit: this.gasLimit
|
2541
|
+
gasLimit: this.gasLimit,
|
2542
|
+
maxGasPerTx
|
2470
2543
|
});
|
2471
2544
|
}
|
2472
2545
|
/**
|
@@ -2541,15 +2614,32 @@ var transactionRequestify = (obj) => {
|
|
2541
2614
|
}
|
2542
2615
|
}
|
2543
2616
|
};
|
2617
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2618
|
+
(acc, input) => {
|
2619
|
+
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2620
|
+
acc.utxos.push(input.id);
|
2621
|
+
}
|
2622
|
+
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2623
|
+
acc.messages.push(input.nonce);
|
2624
|
+
}
|
2625
|
+
return acc;
|
2626
|
+
},
|
2627
|
+
{
|
2628
|
+
utxos: [],
|
2629
|
+
messages: []
|
2630
|
+
}
|
2631
|
+
);
|
2544
2632
|
|
2545
2633
|
// src/providers/transaction-response/transaction-response.ts
|
2546
2634
|
var import_errors13 = require("@fuel-ts/errors");
|
2547
|
-
var
|
2548
|
-
var
|
2549
|
-
var
|
2635
|
+
var import_math15 = require("@fuel-ts/math");
|
2636
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
2637
|
+
var import_utils20 = require("@fuel-ts/utils");
|
2550
2638
|
|
2551
2639
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2552
|
-
var
|
2640
|
+
var import_math14 = require("@fuel-ts/math");
|
2641
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2642
|
+
var import_utils18 = require("@fuel-ts/utils");
|
2553
2643
|
|
2554
2644
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2555
2645
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2557,9 +2647,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2557
2647
|
var import_utils16 = require("@fuel-ts/utils");
|
2558
2648
|
var calculateTransactionFee = (params) => {
|
2559
2649
|
const {
|
2560
|
-
|
2650
|
+
gasPrice,
|
2561
2651
|
rawPayload,
|
2562
|
-
|
2652
|
+
tip,
|
2653
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2563
2654
|
} = params;
|
2564
2655
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2565
2656
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2569,8 +2660,7 @@ var calculateTransactionFee = (params) => {
|
|
2569
2660
|
return {
|
2570
2661
|
fee: (0, import_math11.bn)(0),
|
2571
2662
|
minFee: (0, import_math11.bn)(0),
|
2572
|
-
maxFee: (0, import_math11.bn)(0)
|
2573
|
-
feeFromGasUsed: (0, import_math11.bn)(0)
|
2663
|
+
maxFee: (0, import_math11.bn)(0)
|
2574
2664
|
};
|
2575
2665
|
}
|
2576
2666
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2602,7 +2692,6 @@ var calculateTransactionFee = (params) => {
|
|
2602
2692
|
metadataGas,
|
2603
2693
|
txBytesSize: transactionBytes.length
|
2604
2694
|
});
|
2605
|
-
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2606
2695
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2607
2696
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2608
2697
|
const maxGas = getMaxGas({
|
@@ -2610,17 +2699,25 @@ var calculateTransactionFee = (params) => {
|
|
2610
2699
|
minGas,
|
2611
2700
|
witnessesLength,
|
2612
2701
|
gasLimit,
|
2613
|
-
witnessLimit
|
2702
|
+
witnessLimit,
|
2703
|
+
maxGasPerTx
|
2704
|
+
});
|
2705
|
+
const minFee = calculateGasFee({
|
2706
|
+
gasPrice,
|
2707
|
+
gas: minGas,
|
2708
|
+
priceFactor: gasPriceFactor,
|
2709
|
+
tip
|
2710
|
+
});
|
2711
|
+
const maxFee = calculateGasFee({
|
2712
|
+
gasPrice,
|
2713
|
+
gas: maxGas,
|
2714
|
+
priceFactor: gasPriceFactor,
|
2715
|
+
tip
|
2614
2716
|
});
|
2615
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2616
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2617
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2618
|
-
const fee = minFee.add(feeFromGasUsed);
|
2619
2717
|
return {
|
2620
|
-
fee,
|
2621
2718
|
minFee,
|
2622
2719
|
maxFee,
|
2623
|
-
|
2720
|
+
fee: maxFee
|
2624
2721
|
};
|
2625
2722
|
};
|
2626
2723
|
|
@@ -3187,10 +3284,12 @@ function assembleTransactionSummary(params) {
|
|
3187
3284
|
gqlTransactionStatus,
|
3188
3285
|
abiMap = {},
|
3189
3286
|
maxInputs,
|
3190
|
-
gasCosts
|
3287
|
+
gasCosts,
|
3288
|
+
maxGasPerTx,
|
3289
|
+
gasPrice
|
3191
3290
|
} = params;
|
3192
3291
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3193
|
-
const rawPayload = (0,
|
3292
|
+
const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
|
3194
3293
|
const operations = getOperations({
|
3195
3294
|
transactionType: transaction.type,
|
3196
3295
|
inputs: transaction.inputs || [],
|
@@ -3201,11 +3300,14 @@ function assembleTransactionSummary(params) {
|
|
3201
3300
|
maxInputs
|
3202
3301
|
});
|
3203
3302
|
const typeName = getTransactionTypeName(transaction.type);
|
3303
|
+
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3204
3304
|
const { fee } = calculateTransactionFee({
|
3205
|
-
|
3305
|
+
gasPrice,
|
3206
3306
|
rawPayload,
|
3307
|
+
tip,
|
3207
3308
|
consensusParameters: {
|
3208
3309
|
gasCosts,
|
3310
|
+
maxGasPerTx,
|
3209
3311
|
feeParams: {
|
3210
3312
|
gasPerByte,
|
3211
3313
|
gasPriceFactor
|
@@ -3217,7 +3319,7 @@ function assembleTransactionSummary(params) {
|
|
3217
3319
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3218
3320
|
let date;
|
3219
3321
|
if (time) {
|
3220
|
-
date =
|
3322
|
+
date = import_utils18.DateTime.fromTai64(time);
|
3221
3323
|
}
|
3222
3324
|
const transactionSummary = {
|
3223
3325
|
id,
|
@@ -3245,12 +3347,12 @@ function assembleTransactionSummary(params) {
|
|
3245
3347
|
|
3246
3348
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3247
3349
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3248
|
-
var
|
3350
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
3249
3351
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3250
3352
|
return receipts.reduce((logs, receipt) => {
|
3251
|
-
if (receipt.type ===
|
3353
|
+
if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
|
3252
3354
|
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3253
|
-
const data = receipt.type ===
|
3355
|
+
const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3254
3356
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3255
3357
|
logs.push(decodedLog);
|
3256
3358
|
}
|
@@ -3265,7 +3367,7 @@ var TransactionResponse = class {
|
|
3265
3367
|
/** Current provider */
|
3266
3368
|
provider;
|
3267
3369
|
/** Gas used on the transaction */
|
3268
|
-
gasUsed = (0,
|
3370
|
+
gasUsed = (0, import_math15.bn)(0);
|
3269
3371
|
/** The graphql Transaction with receipts object. */
|
3270
3372
|
gqlTransaction;
|
3271
3373
|
abis;
|
@@ -3323,8 +3425,8 @@ var TransactionResponse = class {
|
|
3323
3425
|
* @returns The decoded transaction.
|
3324
3426
|
*/
|
3325
3427
|
decodeTransaction(transactionWithReceipts) {
|
3326
|
-
return new
|
3327
|
-
(0,
|
3428
|
+
return new import_transactions18.TransactionCoder().decode(
|
3429
|
+
(0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
|
3328
3430
|
0
|
3329
3431
|
)?.[0];
|
3330
3432
|
}
|
@@ -3343,20 +3445,27 @@ var TransactionResponse = class {
|
|
3343
3445
|
const decodedTransaction = this.decodeTransaction(
|
3344
3446
|
transaction
|
3345
3447
|
);
|
3346
|
-
|
3347
|
-
|
3448
|
+
let txReceipts = [];
|
3449
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3450
|
+
txReceipts = transaction.status.receipts;
|
3451
|
+
}
|
3452
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3453
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3454
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3348
3455
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3349
3456
|
const transactionSummary = assembleTransactionSummary({
|
3350
3457
|
id: this.id,
|
3351
3458
|
receipts,
|
3352
3459
|
transaction: decodedTransaction,
|
3353
|
-
transactionBytes: (0,
|
3460
|
+
transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
|
3354
3461
|
gqlTransactionStatus: transaction.status,
|
3355
3462
|
gasPerByte,
|
3356
3463
|
gasPriceFactor,
|
3357
3464
|
abiMap: contractsAbiMap,
|
3358
3465
|
maxInputs,
|
3359
|
-
gasCosts
|
3466
|
+
gasCosts,
|
3467
|
+
maxGasPerTx,
|
3468
|
+
gasPrice
|
3360
3469
|
});
|
3361
3470
|
return transactionSummary;
|
3362
3471
|
}
|
@@ -3482,30 +3591,30 @@ var processGqlChain = (chain) => {
|
|
3482
3591
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3483
3592
|
return {
|
3484
3593
|
name,
|
3485
|
-
baseChainHeight: (0,
|
3594
|
+
baseChainHeight: (0, import_math16.bn)(daHeight),
|
3486
3595
|
consensusParameters: {
|
3487
|
-
contractMaxSize: (0,
|
3488
|
-
maxInputs: (0,
|
3489
|
-
maxOutputs: (0,
|
3490
|
-
maxWitnesses: (0,
|
3491
|
-
maxGasPerTx: (0,
|
3492
|
-
maxScriptLength: (0,
|
3493
|
-
maxScriptDataLength: (0,
|
3494
|
-
maxStorageSlots: (0,
|
3495
|
-
maxPredicateLength: (0,
|
3496
|
-
maxPredicateDataLength: (0,
|
3497
|
-
maxGasPerPredicate: (0,
|
3498
|
-
gasPriceFactor: (0,
|
3499
|
-
gasPerByte: (0,
|
3500
|
-
maxMessageDataLength: (0,
|
3501
|
-
chainId: (0,
|
3596
|
+
contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
|
3597
|
+
maxInputs: (0, import_math16.bn)(txParams.maxInputs),
|
3598
|
+
maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
|
3599
|
+
maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
|
3600
|
+
maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
|
3601
|
+
maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
|
3602
|
+
maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
|
3603
|
+
maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
|
3604
|
+
maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
|
3605
|
+
maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
|
3606
|
+
maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
|
3607
|
+
gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
|
3608
|
+
gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
|
3609
|
+
maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
|
3610
|
+
chainId: (0, import_math16.bn)(consensusParameters.chainId),
|
3502
3611
|
baseAssetId: consensusParameters.baseAssetId,
|
3503
3612
|
gasCosts
|
3504
3613
|
},
|
3505
3614
|
gasCosts,
|
3506
3615
|
latestBlock: {
|
3507
3616
|
id: latestBlock.id,
|
3508
|
-
height: (0,
|
3617
|
+
height: (0, import_math16.bn)(latestBlock.height),
|
3509
3618
|
time: latestBlock.header.time,
|
3510
3619
|
transactions: latestBlock.transactions.map((i) => ({
|
3511
3620
|
id: i.id
|
@@ -3599,10 +3708,8 @@ var _Provider = class {
|
|
3599
3708
|
* Returns some helpful parameters related to gas fees.
|
3600
3709
|
*/
|
3601
3710
|
getGasConfig() {
|
3602
|
-
const { minGasPrice } = this.getNode();
|
3603
3711
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3604
3712
|
return {
|
3605
|
-
minGasPrice,
|
3606
3713
|
maxGasPerTx,
|
3607
3714
|
maxGasPerPredicate,
|
3608
3715
|
gasPriceFactor,
|
@@ -3678,6 +3785,21 @@ var _Provider = class {
|
|
3678
3785
|
} = await this.operations.getVersion();
|
3679
3786
|
return nodeVersion;
|
3680
3787
|
}
|
3788
|
+
/**
|
3789
|
+
* @hidden
|
3790
|
+
*
|
3791
|
+
* Returns the network configuration of the connected Fuel node.
|
3792
|
+
*
|
3793
|
+
* @returns A promise that resolves to the network configuration object
|
3794
|
+
*/
|
3795
|
+
async getNetwork() {
|
3796
|
+
const {
|
3797
|
+
name,
|
3798
|
+
consensusParameters: { chainId }
|
3799
|
+
} = await this.getChain();
|
3800
|
+
const network = new import_ethers.Network(name, chainId.toNumber());
|
3801
|
+
return Promise.resolve(network);
|
3802
|
+
}
|
3681
3803
|
/**
|
3682
3804
|
* Returns the block number.
|
3683
3805
|
*
|
@@ -3685,7 +3807,7 @@ var _Provider = class {
|
|
3685
3807
|
*/
|
3686
3808
|
async getBlockNumber() {
|
3687
3809
|
const { chain } = await this.operations.getChain();
|
3688
|
-
return (0,
|
3810
|
+
return (0, import_math16.bn)(chain.latestBlock.height, 10);
|
3689
3811
|
}
|
3690
3812
|
/**
|
3691
3813
|
* Returns the chain information.
|
@@ -3695,13 +3817,11 @@ var _Provider = class {
|
|
3695
3817
|
async fetchNode() {
|
3696
3818
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3697
3819
|
const processedNodeInfo = {
|
3698
|
-
maxDepth: (0,
|
3699
|
-
maxTx: (0,
|
3700
|
-
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3820
|
+
maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
|
3821
|
+
maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
|
3701
3822
|
nodeVersion: nodeInfo.nodeVersion,
|
3702
3823
|
utxoValidation: nodeInfo.utxoValidation,
|
3703
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3704
|
-
peers: nodeInfo.peers
|
3824
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3705
3825
|
};
|
3706
3826
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3707
3827
|
return processedNodeInfo;
|
@@ -3754,9 +3874,9 @@ var _Provider = class {
|
|
3754
3874
|
if (estimateTxDependencies) {
|
3755
3875
|
await this.estimateTxDependencies(transactionRequest);
|
3756
3876
|
}
|
3757
|
-
const encodedTransaction = (0,
|
3877
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3758
3878
|
let abis;
|
3759
|
-
if (transactionRequest.type ===
|
3879
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
3760
3880
|
abis = transactionRequest.abis;
|
3761
3881
|
}
|
3762
3882
|
if (awaitExecution) {
|
@@ -3797,15 +3917,14 @@ var _Provider = class {
|
|
3797
3917
|
if (estimateTxDependencies) {
|
3798
3918
|
return this.estimateTxDependencies(transactionRequest);
|
3799
3919
|
}
|
3800
|
-
const encodedTransaction = (0,
|
3801
|
-
const { dryRun:
|
3802
|
-
encodedTransaction,
|
3920
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3921
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3922
|
+
encodedTransactions: encodedTransaction,
|
3803
3923
|
utxoValidation: utxoValidation || false
|
3804
3924
|
});
|
3805
|
-
const receipts =
|
3806
|
-
|
3807
|
-
|
3808
|
-
};
|
3925
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3926
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3927
|
+
return { receipts, dryrunStatus: status };
|
3809
3928
|
}
|
3810
3929
|
/**
|
3811
3930
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3816,13 +3935,13 @@ var _Provider = class {
|
|
3816
3935
|
async estimatePredicates(transactionRequest) {
|
3817
3936
|
const shouldEstimatePredicates = Boolean(
|
3818
3937
|
transactionRequest.inputs.find(
|
3819
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3938
|
+
(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()
|
3820
3939
|
)
|
3821
3940
|
);
|
3822
3941
|
if (!shouldEstimatePredicates) {
|
3823
3942
|
return transactionRequest;
|
3824
3943
|
}
|
3825
|
-
const encodedTransaction = (0,
|
3944
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3826
3945
|
const response = await this.operations.estimatePredicates({
|
3827
3946
|
encodedTransaction
|
3828
3947
|
});
|
@@ -3831,7 +3950,7 @@ var _Provider = class {
|
|
3831
3950
|
} = response;
|
3832
3951
|
if (inputs) {
|
3833
3952
|
inputs.forEach((input, index) => {
|
3834
|
-
if ("predicateGasUsed" in input && (0,
|
3953
|
+
if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
|
3835
3954
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3836
3955
|
}
|
3837
3956
|
});
|
@@ -3844,31 +3963,31 @@ var _Provider = class {
|
|
3844
3963
|
* If there are missing variable outputs,
|
3845
3964
|
* `addVariableOutputs` is called on the transaction.
|
3846
3965
|
*
|
3847
|
-
* @privateRemarks
|
3848
|
-
* TODO: Investigate support for missing contract IDs
|
3849
|
-
* TODO: Add support for missing output messages
|
3850
3966
|
*
|
3851
3967
|
* @param transactionRequest - The transaction request object.
|
3852
3968
|
* @returns A promise.
|
3853
3969
|
*/
|
3854
3970
|
async estimateTxDependencies(transactionRequest) {
|
3855
|
-
if (transactionRequest.type ===
|
3971
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Create) {
|
3856
3972
|
return {
|
3857
3973
|
receipts: [],
|
3858
3974
|
outputVariables: 0,
|
3859
3975
|
missingContractIds: []
|
3860
3976
|
};
|
3861
3977
|
}
|
3862
|
-
await this.estimatePredicates(transactionRequest);
|
3863
3978
|
let receipts = [];
|
3864
3979
|
const missingContractIds = [];
|
3865
3980
|
let outputVariables = 0;
|
3981
|
+
let dryrunStatus;
|
3866
3982
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3867
|
-
const {
|
3868
|
-
|
3983
|
+
const {
|
3984
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3985
|
+
} = await this.operations.dryRun({
|
3986
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3869
3987
|
utxoValidation: false
|
3870
3988
|
});
|
3871
|
-
receipts =
|
3989
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3990
|
+
dryrunStatus = status;
|
3872
3991
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3873
3992
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3874
3993
|
if (hasMissingOutputs) {
|
@@ -3878,6 +3997,10 @@ var _Provider = class {
|
|
3878
3997
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3879
3998
|
missingContractIds.push(contractId);
|
3880
3999
|
});
|
4000
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4001
|
+
transactionRequest
|
4002
|
+
});
|
4003
|
+
transactionRequest.maxFee = maxFee;
|
3881
4004
|
} else {
|
3882
4005
|
break;
|
3883
4006
|
}
|
@@ -3885,37 +4008,136 @@ var _Provider = class {
|
|
3885
4008
|
return {
|
3886
4009
|
receipts,
|
3887
4010
|
outputVariables,
|
3888
|
-
missingContractIds
|
4011
|
+
missingContractIds,
|
4012
|
+
dryrunStatus
|
3889
4013
|
};
|
3890
4014
|
}
|
4015
|
+
/**
|
4016
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4017
|
+
*
|
4018
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4019
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4020
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4021
|
+
*
|
4022
|
+
* @param transactionRequests - Array of transaction request objects.
|
4023
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4024
|
+
*/
|
4025
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4026
|
+
const results = transactionRequests.map(() => ({
|
4027
|
+
receipts: [],
|
4028
|
+
outputVariables: 0,
|
4029
|
+
missingContractIds: [],
|
4030
|
+
dryrunStatus: void 0
|
4031
|
+
}));
|
4032
|
+
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4033
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4034
|
+
allRequests.forEach((req, index) => {
|
4035
|
+
if (req.type === import_transactions19.TransactionType.Script) {
|
4036
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4037
|
+
}
|
4038
|
+
});
|
4039
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4040
|
+
let attempt = 0;
|
4041
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4042
|
+
const encodedTransactions = transactionsToProcess.map(
|
4043
|
+
(index) => serializedTransactionsMap.get(index)
|
4044
|
+
);
|
4045
|
+
const dryRunResults = await this.operations.dryRun({
|
4046
|
+
encodedTransactions,
|
4047
|
+
utxoValidation: false
|
4048
|
+
});
|
4049
|
+
const nextRoundTransactions = [];
|
4050
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4051
|
+
const requestIdx = transactionsToProcess[i];
|
4052
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4053
|
+
const result = results[requestIdx];
|
4054
|
+
result.receipts = rawReceipts.map(processGqlReceipt);
|
4055
|
+
result.dryrunStatus = status;
|
4056
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4057
|
+
result.receipts
|
4058
|
+
);
|
4059
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4060
|
+
const request = allRequests[requestIdx];
|
4061
|
+
if (hasMissingOutputs && request?.type === import_transactions19.TransactionType.Script) {
|
4062
|
+
result.outputVariables += missingOutputVariables.length;
|
4063
|
+
request.addVariableOutputs(missingOutputVariables.length);
|
4064
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4065
|
+
request.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4066
|
+
result.missingContractIds.push(contractId);
|
4067
|
+
});
|
4068
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4069
|
+
transactionRequest: request
|
4070
|
+
});
|
4071
|
+
request.maxFee = maxFee;
|
4072
|
+
serializedTransactionsMap.set(requestIdx, (0, import_utils22.hexlify)(request.toTransactionBytes()));
|
4073
|
+
nextRoundTransactions.push(requestIdx);
|
4074
|
+
}
|
4075
|
+
}
|
4076
|
+
transactionsToProcess = nextRoundTransactions;
|
4077
|
+
attempt += 1;
|
4078
|
+
}
|
4079
|
+
return results;
|
4080
|
+
}
|
4081
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4082
|
+
if (estimateTxDependencies) {
|
4083
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4084
|
+
}
|
4085
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4086
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4087
|
+
encodedTransactions,
|
4088
|
+
utxoValidation: utxoValidation || false
|
4089
|
+
});
|
4090
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4091
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4092
|
+
return { receipts, dryrunStatus: status };
|
4093
|
+
});
|
4094
|
+
return results;
|
4095
|
+
}
|
3891
4096
|
/**
|
3892
4097
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
3893
4098
|
* @param transactionRequest - The transaction request object.
|
3894
4099
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3895
4100
|
*/
|
3896
|
-
estimateTxGasAndFee(params) {
|
4101
|
+
async estimateTxGasAndFee(params) {
|
3897
4102
|
const { transactionRequest } = params;
|
3898
|
-
|
4103
|
+
let { gasPrice } = params;
|
3899
4104
|
const chainInfo = this.getChain();
|
3900
|
-
const
|
3901
|
-
transactionRequest.gasPrice = gasPrice;
|
4105
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
3902
4106
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3903
|
-
|
3904
|
-
|
4107
|
+
if (!gasPrice) {
|
4108
|
+
gasPrice = await this.estimateGasPrice(10);
|
4109
|
+
}
|
4110
|
+
const minFee = calculateGasFee({
|
4111
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4112
|
+
gas: minGas,
|
4113
|
+
priceFactor: gasPriceFactor,
|
4114
|
+
tip: transactionRequest.tip
|
4115
|
+
}).add(1);
|
4116
|
+
let gasLimit = (0, import_math16.bn)(0);
|
4117
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4118
|
+
gasLimit = transactionRequest.gasLimit;
|
3905
4119
|
if (transactionRequest.gasLimit.eq(0)) {
|
3906
4120
|
transactionRequest.gasLimit = minGas;
|
3907
4121
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3908
4122
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3909
4123
|
);
|
4124
|
+
gasLimit = transactionRequest.gasLimit;
|
3910
4125
|
}
|
3911
4126
|
}
|
3912
4127
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3913
|
-
const maxFee =
|
4128
|
+
const maxFee = calculateGasFee({
|
4129
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4130
|
+
gas: maxGas,
|
4131
|
+
priceFactor: gasPriceFactor,
|
4132
|
+
tip: transactionRequest.tip
|
4133
|
+
}).add(1);
|
3914
4134
|
return {
|
3915
4135
|
minGas,
|
3916
4136
|
minFee,
|
3917
4137
|
maxGas,
|
3918
|
-
maxFee
|
4138
|
+
maxFee,
|
4139
|
+
gasPrice,
|
4140
|
+
gasLimit
|
3919
4141
|
};
|
3920
4142
|
}
|
3921
4143
|
/**
|
@@ -3933,15 +4155,17 @@ var _Provider = class {
|
|
3933
4155
|
if (estimateTxDependencies) {
|
3934
4156
|
return this.estimateTxDependencies(transactionRequest);
|
3935
4157
|
}
|
3936
|
-
const
|
3937
|
-
const { dryRun:
|
3938
|
-
|
4158
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4159
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4160
|
+
encodedTransactions,
|
3939
4161
|
utxoValidation: true
|
3940
4162
|
});
|
3941
|
-
const
|
3942
|
-
|
3943
|
-
receipts
|
3944
|
-
|
4163
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4164
|
+
const { id, receipts, status } = dryRunStatus;
|
4165
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4166
|
+
return { id, receipts: processedReceipts, status };
|
4167
|
+
});
|
4168
|
+
return { receipts: callResult[0].receipts };
|
3945
4169
|
}
|
3946
4170
|
/**
|
3947
4171
|
* Returns a transaction cost to enable user
|
@@ -3958,78 +4182,80 @@ var _Provider = class {
|
|
3958
4182
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3959
4183
|
* @returns A promise that resolves to the transaction cost object.
|
3960
4184
|
*/
|
3961
|
-
async getTransactionCost(transactionRequestLike,
|
3962
|
-
estimateTxDependencies = true,
|
3963
|
-
estimatePredicates = true,
|
3964
|
-
resourcesOwner,
|
3965
|
-
signatureCallback
|
3966
|
-
} = {}) {
|
4185
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3967
4186
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3968
|
-
const
|
3969
|
-
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3970
|
-
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4187
|
+
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
3971
4188
|
const baseAssetId = this.getBaseAssetId();
|
3972
4189
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3973
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4190
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3974
4191
|
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
4192
|
+
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
3975
4193
|
if (isScriptTransaction) {
|
3976
|
-
txRequestClone.gasLimit = (0,
|
4194
|
+
txRequestClone.gasLimit = (0, import_math16.bn)(0);
|
3977
4195
|
}
|
3978
|
-
if (
|
3979
|
-
|
3980
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3981
|
-
}
|
3982
|
-
await this.estimatePredicates(txRequestClone);
|
4196
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4197
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3983
4198
|
}
|
4199
|
+
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4200
|
+
let addedSignatures = 0;
|
3984
4201
|
if (signatureCallback && isScriptTransaction) {
|
3985
|
-
|
4202
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4203
|
+
await signatureCallback(signedRequest);
|
4204
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3986
4205
|
}
|
3987
|
-
|
3988
|
-
|
4206
|
+
await this.estimatePredicates(signedRequest);
|
4207
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4208
|
+
transactionRequest: signedRequest
|
3989
4209
|
});
|
3990
4210
|
let receipts = [];
|
3991
4211
|
let missingContractIds = [];
|
3992
4212
|
let outputVariables = 0;
|
3993
|
-
let gasUsed = (0,
|
3994
|
-
|
3995
|
-
|
4213
|
+
let gasUsed = (0, import_math16.bn)(0);
|
4214
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4215
|
+
txRequestClone.maxFee = maxFee;
|
4216
|
+
if (isScriptTransaction) {
|
4217
|
+
txRequestClone.gasLimit = gasLimit;
|
4218
|
+
if (signatureCallback) {
|
4219
|
+
await signatureCallback(txRequestClone);
|
4220
|
+
}
|
3996
4221
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3997
4222
|
receipts = result.receipts;
|
3998
4223
|
outputVariables = result.outputVariables;
|
3999
4224
|
missingContractIds = result.missingContractIds;
|
4000
4225
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4001
4226
|
txRequestClone.gasLimit = gasUsed;
|
4002
|
-
|
4003
|
-
|
4004
|
-
|
4227
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4228
|
+
transactionRequest: txRequestClone,
|
4229
|
+
gasPrice
|
4005
4230
|
}));
|
4006
4231
|
}
|
4007
4232
|
return {
|
4008
4233
|
requiredQuantities: allQuantities,
|
4009
4234
|
receipts,
|
4010
4235
|
gasUsed,
|
4011
|
-
|
4012
|
-
gasPrice: setGasPrice,
|
4236
|
+
gasPrice,
|
4013
4237
|
minGas,
|
4014
4238
|
maxGas,
|
4015
4239
|
minFee,
|
4016
4240
|
maxFee,
|
4017
|
-
estimatedInputs: txRequestClone.inputs,
|
4018
4241
|
outputVariables,
|
4019
|
-
missingContractIds
|
4242
|
+
missingContractIds,
|
4243
|
+
addedSignatures,
|
4244
|
+
estimatedPredicates: txRequestClone.inputs
|
4020
4245
|
};
|
4021
4246
|
}
|
4022
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4247
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4023
4248
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4024
4249
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4025
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4250
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4251
|
+
quantitiesToContract
|
4252
|
+
});
|
4026
4253
|
transactionRequest.addResources(
|
4027
4254
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4028
4255
|
);
|
4029
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4030
|
-
|
4031
|
-
|
4032
|
-
);
|
4256
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4257
|
+
quantitiesToContract
|
4258
|
+
});
|
4033
4259
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4034
4260
|
return {
|
4035
4261
|
resources,
|
@@ -4045,17 +4271,16 @@ var _Provider = class {
|
|
4045
4271
|
const result = await this.operations.getCoins({
|
4046
4272
|
first: 10,
|
4047
4273
|
...paginationArgs,
|
4048
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4274
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4049
4275
|
});
|
4050
4276
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4051
4277
|
return coins.map((coin) => ({
|
4052
4278
|
id: coin.utxoId,
|
4053
4279
|
assetId: coin.assetId,
|
4054
|
-
amount: (0,
|
4280
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4055
4281
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4056
|
-
|
4057
|
-
|
4058
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4282
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4283
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4059
4284
|
}));
|
4060
4285
|
}
|
4061
4286
|
/**
|
@@ -4069,19 +4294,19 @@ var _Provider = class {
|
|
4069
4294
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4070
4295
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4071
4296
|
const excludeInput = {
|
4072
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4073
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4297
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4298
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4074
4299
|
};
|
4075
4300
|
if (this.cache) {
|
4076
4301
|
const uniqueUtxos = new Set(
|
4077
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4302
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4078
4303
|
);
|
4079
4304
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4080
4305
|
}
|
4081
4306
|
const coinsQuery = {
|
4082
4307
|
owner: ownerAddress.toB256(),
|
4083
4308
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4084
|
-
assetId: (0,
|
4309
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4085
4310
|
amount: amount.toString(10),
|
4086
4311
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4087
4312
|
})),
|
@@ -4092,9 +4317,9 @@ var _Provider = class {
|
|
4092
4317
|
switch (coin.__typename) {
|
4093
4318
|
case "MessageCoin":
|
4094
4319
|
return {
|
4095
|
-
amount: (0,
|
4320
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4096
4321
|
assetId: coin.assetId,
|
4097
|
-
daHeight: (0,
|
4322
|
+
daHeight: (0, import_math16.bn)(coin.daHeight),
|
4098
4323
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4099
4324
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4100
4325
|
nonce: coin.nonce
|
@@ -4102,12 +4327,11 @@ var _Provider = class {
|
|
4102
4327
|
case "Coin":
|
4103
4328
|
return {
|
4104
4329
|
id: coin.utxoId,
|
4105
|
-
amount: (0,
|
4330
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4106
4331
|
assetId: coin.assetId,
|
4107
4332
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4108
|
-
|
4109
|
-
|
4110
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4333
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4334
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4111
4335
|
};
|
4112
4336
|
default:
|
4113
4337
|
return null;
|
@@ -4124,13 +4348,13 @@ var _Provider = class {
|
|
4124
4348
|
async getBlock(idOrHeight) {
|
4125
4349
|
let variables;
|
4126
4350
|
if (typeof idOrHeight === "number") {
|
4127
|
-
variables = { height: (0,
|
4351
|
+
variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4128
4352
|
} else if (idOrHeight === "latest") {
|
4129
4353
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4130
4354
|
} else if (idOrHeight.length === 66) {
|
4131
4355
|
variables = { blockId: idOrHeight };
|
4132
4356
|
} else {
|
4133
|
-
variables = { blockId: (0,
|
4357
|
+
variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4134
4358
|
}
|
4135
4359
|
const { block } = await this.operations.getBlock(variables);
|
4136
4360
|
if (!block) {
|
@@ -4138,7 +4362,7 @@ var _Provider = class {
|
|
4138
4362
|
}
|
4139
4363
|
return {
|
4140
4364
|
id: block.id,
|
4141
|
-
height: (0,
|
4365
|
+
height: (0, import_math16.bn)(block.height),
|
4142
4366
|
time: block.header.time,
|
4143
4367
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4144
4368
|
};
|
@@ -4153,7 +4377,7 @@ var _Provider = class {
|
|
4153
4377
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4154
4378
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4155
4379
|
id: block.id,
|
4156
|
-
height: (0,
|
4380
|
+
height: (0, import_math16.bn)(block.height),
|
4157
4381
|
time: block.header.time,
|
4158
4382
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4159
4383
|
}));
|
@@ -4168,7 +4392,7 @@ var _Provider = class {
|
|
4168
4392
|
async getBlockWithTransactions(idOrHeight) {
|
4169
4393
|
let variables;
|
4170
4394
|
if (typeof idOrHeight === "number") {
|
4171
|
-
variables = { blockHeight: (0,
|
4395
|
+
variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4172
4396
|
} else if (idOrHeight === "latest") {
|
4173
4397
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4174
4398
|
} else {
|
@@ -4180,11 +4404,11 @@ var _Provider = class {
|
|
4180
4404
|
}
|
4181
4405
|
return {
|
4182
4406
|
id: block.id,
|
4183
|
-
height: (0,
|
4407
|
+
height: (0, import_math16.bn)(block.height, 10),
|
4184
4408
|
time: block.header.time,
|
4185
4409
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4186
4410
|
transactions: block.transactions.map(
|
4187
|
-
(tx) => new
|
4411
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4188
4412
|
)
|
4189
4413
|
};
|
4190
4414
|
}
|
@@ -4199,8 +4423,8 @@ var _Provider = class {
|
|
4199
4423
|
if (!transaction) {
|
4200
4424
|
return null;
|
4201
4425
|
}
|
4202
|
-
return new
|
4203
|
-
(0,
|
4426
|
+
return new import_transactions19.TransactionCoder().decode(
|
4427
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4204
4428
|
0
|
4205
4429
|
)?.[0];
|
4206
4430
|
}
|
@@ -4227,9 +4451,9 @@ var _Provider = class {
|
|
4227
4451
|
async getContractBalance(contractId, assetId) {
|
4228
4452
|
const { contractBalance } = await this.operations.getContractBalance({
|
4229
4453
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4230
|
-
asset: (0,
|
4454
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4231
4455
|
});
|
4232
|
-
return (0,
|
4456
|
+
return (0, import_math16.bn)(contractBalance.amount, 10);
|
4233
4457
|
}
|
4234
4458
|
/**
|
4235
4459
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4241,9 +4465,9 @@ var _Provider = class {
|
|
4241
4465
|
async getBalance(owner, assetId) {
|
4242
4466
|
const { balance } = await this.operations.getBalance({
|
4243
4467
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4244
|
-
assetId: (0,
|
4468
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4245
4469
|
});
|
4246
|
-
return (0,
|
4470
|
+
return (0, import_math16.bn)(balance.amount, 10);
|
4247
4471
|
}
|
4248
4472
|
/**
|
4249
4473
|
* Returns balances for the given owner.
|
@@ -4261,7 +4485,7 @@ var _Provider = class {
|
|
4261
4485
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4262
4486
|
return balances.map((balance) => ({
|
4263
4487
|
assetId: balance.assetId,
|
4264
|
-
amount: (0,
|
4488
|
+
amount: (0, import_math16.bn)(balance.amount)
|
4265
4489
|
}));
|
4266
4490
|
}
|
4267
4491
|
/**
|
@@ -4279,19 +4503,19 @@ var _Provider = class {
|
|
4279
4503
|
});
|
4280
4504
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4281
4505
|
return messages.map((message) => ({
|
4282
|
-
messageId:
|
4506
|
+
messageId: import_transactions19.InputMessageCoder.getMessageId({
|
4283
4507
|
sender: message.sender,
|
4284
4508
|
recipient: message.recipient,
|
4285
4509
|
nonce: message.nonce,
|
4286
|
-
amount: (0,
|
4510
|
+
amount: (0, import_math16.bn)(message.amount),
|
4287
4511
|
data: message.data
|
4288
4512
|
}),
|
4289
4513
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4290
4514
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4291
4515
|
nonce: message.nonce,
|
4292
|
-
amount: (0,
|
4293
|
-
data:
|
4294
|
-
daHeight: (0,
|
4516
|
+
amount: (0, import_math16.bn)(message.amount),
|
4517
|
+
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4518
|
+
daHeight: (0, import_math16.bn)(message.daHeight)
|
4295
4519
|
}));
|
4296
4520
|
}
|
4297
4521
|
/**
|
@@ -4344,44 +4568,60 @@ var _Provider = class {
|
|
4344
4568
|
} = result.messageProof;
|
4345
4569
|
return {
|
4346
4570
|
messageProof: {
|
4347
|
-
proofIndex: (0,
|
4571
|
+
proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
|
4348
4572
|
proofSet: messageProof.proofSet
|
4349
4573
|
},
|
4350
4574
|
blockProof: {
|
4351
|
-
proofIndex: (0,
|
4575
|
+
proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
|
4352
4576
|
proofSet: blockProof.proofSet
|
4353
4577
|
},
|
4354
4578
|
messageBlockHeader: {
|
4355
4579
|
id: messageBlockHeader.id,
|
4356
|
-
daHeight: (0,
|
4357
|
-
transactionsCount: (0,
|
4580
|
+
daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
|
4581
|
+
transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
|
4358
4582
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4359
|
-
height: (0,
|
4583
|
+
height: (0, import_math16.bn)(messageBlockHeader.height),
|
4360
4584
|
prevRoot: messageBlockHeader.prevRoot,
|
4361
4585
|
time: messageBlockHeader.time,
|
4362
4586
|
applicationHash: messageBlockHeader.applicationHash,
|
4363
|
-
|
4364
|
-
|
4587
|
+
messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
|
4588
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4589
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4590
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4591
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4365
4592
|
},
|
4366
4593
|
commitBlockHeader: {
|
4367
4594
|
id: commitBlockHeader.id,
|
4368
|
-
daHeight: (0,
|
4369
|
-
transactionsCount: (0,
|
4595
|
+
daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
|
4596
|
+
transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
|
4370
4597
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4371
|
-
height: (0,
|
4598
|
+
height: (0, import_math16.bn)(commitBlockHeader.height),
|
4372
4599
|
prevRoot: commitBlockHeader.prevRoot,
|
4373
4600
|
time: commitBlockHeader.time,
|
4374
4601
|
applicationHash: commitBlockHeader.applicationHash,
|
4375
|
-
|
4376
|
-
|
4602
|
+
messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
|
4603
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4604
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4605
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4606
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4377
4607
|
},
|
4378
4608
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4379
4609
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4380
4610
|
nonce,
|
4381
|
-
amount: (0,
|
4611
|
+
amount: (0, import_math16.bn)(amount),
|
4382
4612
|
data
|
4383
4613
|
};
|
4384
4614
|
}
|
4615
|
+
async getLatestGasPrice() {
|
4616
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4617
|
+
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4618
|
+
}
|
4619
|
+
async estimateGasPrice(blockHorizon) {
|
4620
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4621
|
+
blockHorizon: String(blockHorizon)
|
4622
|
+
});
|
4623
|
+
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4624
|
+
}
|
4385
4625
|
/**
|
4386
4626
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4387
4627
|
*
|
@@ -4401,10 +4641,10 @@ var _Provider = class {
|
|
4401
4641
|
*/
|
4402
4642
|
async produceBlocks(amount, startTime) {
|
4403
4643
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4404
|
-
blocksToProduce: (0,
|
4405
|
-
startTimestamp: startTime ?
|
4644
|
+
blocksToProduce: (0, import_math16.bn)(amount).toString(10),
|
4645
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4406
4646
|
});
|
4407
|
-
return (0,
|
4647
|
+
return (0, import_math16.bn)(latestBlockHeight);
|
4408
4648
|
}
|
4409
4649
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4410
4650
|
async getTransactionResponse(transactionId) {
|
@@ -4418,7 +4658,7 @@ cacheInputs_fn = function(inputs) {
|
|
4418
4658
|
return;
|
4419
4659
|
}
|
4420
4660
|
inputs.forEach((input) => {
|
4421
|
-
if (input.type ===
|
4661
|
+
if (input.type === import_transactions19.InputType.Coin) {
|
4422
4662
|
this.cache?.set(input.id);
|
4423
4663
|
}
|
4424
4664
|
});
|
@@ -4428,9 +4668,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4428
4668
|
|
4429
4669
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4430
4670
|
var import_errors15 = require("@fuel-ts/errors");
|
4431
|
-
var
|
4432
|
-
var
|
4433
|
-
var
|
4671
|
+
var import_math17 = require("@fuel-ts/math");
|
4672
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
4673
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4434
4674
|
|
4435
4675
|
// src/providers/chains.ts
|
4436
4676
|
var CHAIN_IDS = {
|
@@ -4479,17 +4719,17 @@ var assets = [
|
|
4479
4719
|
|
4480
4720
|
// src/utils/formatTransferToContractScriptData.ts
|
4481
4721
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4482
|
-
var
|
4483
|
-
var
|
4722
|
+
var import_math18 = require("@fuel-ts/math");
|
4723
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4484
4724
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4485
4725
|
var formatTransferToContractScriptData = (params) => {
|
4486
4726
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4487
4727
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4488
|
-
const encoded = numberCoder.encode(new
|
4728
|
+
const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
|
4489
4729
|
const scriptData = Uint8Array.from([
|
4490
|
-
...(0,
|
4730
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4491
4731
|
...encoded,
|
4492
|
-
...(0,
|
4732
|
+
...(0, import_utils26.arrayify)(assetId)
|
4493
4733
|
]);
|
4494
4734
|
return scriptData;
|
4495
4735
|
};
|
@@ -4675,38 +4915,31 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4675
4915
|
* @param fee - The estimated transaction fee.
|
4676
4916
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4677
4917
|
*/
|
4678
|
-
async fund(request,
|
4918
|
+
async fund(request, params) {
|
4919
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4679
4920
|
const baseAssetId = this.provider.getBaseAssetId();
|
4680
|
-
const
|
4681
|
-
|
4921
|
+
const txRequest = request;
|
4922
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4923
|
+
amount: (0, import_math19.bn)(fee),
|
4682
4924
|
assetId: baseAssetId,
|
4683
|
-
coinQuantities
|
4925
|
+
coinQuantities: requiredQuantities
|
4684
4926
|
});
|
4685
4927
|
const quantitiesDict = {};
|
4686
|
-
|
4928
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4687
4929
|
quantitiesDict[assetId] = {
|
4688
4930
|
required: amount,
|
4689
|
-
owned: (0,
|
4931
|
+
owned: (0, import_math19.bn)(0)
|
4690
4932
|
};
|
4691
4933
|
});
|
4692
|
-
|
4693
|
-
const cachedMessages = [];
|
4694
|
-
const owner = this.address.toB256();
|
4695
|
-
request.inputs.forEach((input) => {
|
4934
|
+
txRequest.inputs.forEach((input) => {
|
4696
4935
|
const isResource = "amount" in input;
|
4697
|
-
if (isResource) {
|
4698
|
-
|
4699
|
-
|
4700
|
-
|
4701
|
-
|
4702
|
-
|
4703
|
-
|
4704
|
-
cachedUtxos.push(input.id);
|
4705
|
-
}
|
4706
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[baseAssetId]) {
|
4707
|
-
quantitiesDict[baseAssetId].owned = quantitiesDict[baseAssetId].owned.add(input.amount);
|
4708
|
-
cachedMessages.push(input.nonce);
|
4709
|
-
}
|
4936
|
+
if (!isResource) {
|
4937
|
+
return;
|
4938
|
+
}
|
4939
|
+
const isCoin2 = "owner" in input;
|
4940
|
+
const assetId = isCoin2 ? String(input.assetId) : baseAssetId;
|
4941
|
+
if (quantitiesDict[assetId]) {
|
4942
|
+
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(input.amount);
|
4710
4943
|
}
|
4711
4944
|
});
|
4712
4945
|
const missingQuantities = [];
|
@@ -4720,12 +4953,21 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4720
4953
|
});
|
4721
4954
|
const needsToBeFunded = missingQuantities.length;
|
4722
4955
|
if (needsToBeFunded) {
|
4723
|
-
const
|
4724
|
-
|
4725
|
-
|
4726
|
-
|
4727
|
-
|
4728
|
-
|
4956
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4957
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4958
|
+
txRequest.addResources(resources);
|
4959
|
+
}
|
4960
|
+
txRequest.shiftPredicateData();
|
4961
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4962
|
+
const requestToReestimate = (0, import_ramda4.clone)(txRequest);
|
4963
|
+
if (addedSignatures) {
|
4964
|
+
Array.from({ length: addedSignatures }).forEach(() => requestToReestimate.addEmptyWitness());
|
4965
|
+
}
|
4966
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4967
|
+
transactionRequest: requestToReestimate
|
4968
|
+
});
|
4969
|
+
txRequest.maxFee = maxFee;
|
4970
|
+
return txRequest;
|
4729
4971
|
}
|
4730
4972
|
/**
|
4731
4973
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4733,29 +4975,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4733
4975
|
* @param destination - The address of the destination.
|
4734
4976
|
* @param amount - The amount of coins to transfer.
|
4735
4977
|
* @param assetId - The asset ID of the coins to transfer.
|
4736
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4978
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4737
4979
|
* @returns A promise that resolves to the prepared transaction request.
|
4738
4980
|
*/
|
4739
4981
|
async createTransfer(destination, amount, assetId, txParams = {}) {
|
4740
|
-
const
|
4982
|
+
const request = new ScriptTransactionRequest(txParams);
|
4741
4983
|
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4742
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4743
|
-
const request = new ScriptTransactionRequest(params);
|
4744
4984
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetIdToTransfer);
|
4745
|
-
const
|
4985
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4746
4986
|
estimateTxDependencies: true,
|
4747
4987
|
resourcesOwner: this
|
4748
4988
|
});
|
4749
|
-
|
4750
|
-
|
4751
|
-
|
4752
|
-
|
4753
|
-
gasPrice: request.gasPrice,
|
4754
|
-
gasLimit: request.gasLimit,
|
4755
|
-
minGasPrice
|
4989
|
+
this.validateGasLimitAndMaxFee({
|
4990
|
+
gasUsed: txCost.gasUsed,
|
4991
|
+
maxFee: txCost.maxFee,
|
4992
|
+
txParams
|
4756
4993
|
});
|
4757
|
-
|
4758
|
-
request.
|
4994
|
+
request.gasLimit = txCost.gasUsed;
|
4995
|
+
request.maxFee = txCost.maxFee;
|
4996
|
+
await this.fund(request, txCost);
|
4759
4997
|
return request;
|
4760
4998
|
}
|
4761
4999
|
/**
|
@@ -4764,11 +5002,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4764
5002
|
* @param destination - The address of the destination.
|
4765
5003
|
* @param amount - The amount of coins to transfer.
|
4766
5004
|
* @param assetId - The asset ID of the coins to transfer.
|
4767
|
-
* @param txParams - The transaction parameters (gasLimit,
|
5005
|
+
* @param txParams - The transaction parameters (gasLimit, maturity).
|
4768
5006
|
* @returns A promise that resolves to the transaction response.
|
4769
5007
|
*/
|
4770
5008
|
async transfer(destination, amount, assetId, txParams = {}) {
|
4771
|
-
if ((0,
|
5009
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
4772
5010
|
throw new import_errors16.FuelError(
|
4773
5011
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4774
5012
|
"Transfer amount must be a positive number."
|
@@ -4788,39 +5026,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4788
5026
|
* @returns A promise that resolves to the transaction response.
|
4789
5027
|
*/
|
4790
5028
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4791
|
-
if ((0,
|
5029
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
4792
5030
|
throw new import_errors16.FuelError(
|
4793
5031
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4794
5032
|
"Transfer amount must be a positive number."
|
4795
5033
|
);
|
4796
5034
|
}
|
4797
5035
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4798
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4799
5036
|
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
4800
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4801
5037
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4802
5038
|
hexlifiedContractId: contractAddress.toB256(),
|
4803
|
-
amountToTransfer: (0,
|
5039
|
+
amountToTransfer: (0, import_math19.bn)(amount),
|
4804
5040
|
assetId: assetIdToTransfer
|
4805
5041
|
});
|
4806
5042
|
const request = new ScriptTransactionRequest({
|
4807
|
-
...
|
5043
|
+
...txParams,
|
4808
5044
|
script,
|
4809
5045
|
scriptData
|
4810
5046
|
});
|
4811
5047
|
request.addContractInputAndOutput(contractAddress);
|
4812
|
-
const
|
4813
|
-
|
4814
|
-
[{ amount: (0,
|
4815
|
-
);
|
4816
|
-
|
4817
|
-
|
4818
|
-
|
4819
|
-
|
4820
|
-
gasLimit: request.gasLimit,
|
4821
|
-
minGasPrice
|
5048
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5049
|
+
resourcesOwner: this,
|
5050
|
+
quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetIdToTransfer) }]
|
5051
|
+
});
|
5052
|
+
this.validateGasLimitAndMaxFee({
|
5053
|
+
gasUsed: txCost.gasUsed,
|
5054
|
+
maxFee: txCost.maxFee,
|
5055
|
+
txParams
|
4822
5056
|
});
|
4823
|
-
|
5057
|
+
request.gasLimit = txCost.gasUsed;
|
5058
|
+
request.maxFee = txCost.maxFee;
|
5059
|
+
await this.fund(request, txCost);
|
4824
5060
|
return this.sendTransaction(request);
|
4825
5061
|
}
|
4826
5062
|
/**
|
@@ -4832,39 +5068,31 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4832
5068
|
* @returns A promise that resolves to the transaction response.
|
4833
5069
|
*/
|
4834
5070
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4835
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4836
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
4837
5071
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4838
|
-
const recipientDataArray = (0,
|
5072
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
4839
5073
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4840
5074
|
);
|
4841
|
-
const amountDataArray = (0,
|
4842
|
-
"0x".concat((0,
|
5075
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5076
|
+
"0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4843
5077
|
);
|
4844
5078
|
const script = new Uint8Array([
|
4845
|
-
...(0,
|
5079
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
4846
5080
|
...recipientDataArray,
|
4847
5081
|
...amountDataArray
|
4848
5082
|
]);
|
4849
|
-
const params = {
|
4850
|
-
|
4851
|
-
gasPrice: minGasPrice,
|
4852
|
-
...txParams
|
4853
|
-
};
|
5083
|
+
const params = { script, ...txParams };
|
5084
|
+
const baseAssetId = this.provider.getBaseAssetId();
|
4854
5085
|
const request = new ScriptTransactionRequest(params);
|
4855
|
-
const
|
4856
|
-
const
|
4857
|
-
|
4858
|
-
|
4859
|
-
|
4860
|
-
|
4861
|
-
this.validateGas({
|
4862
|
-
gasUsed,
|
4863
|
-
gasPrice: request.gasPrice,
|
4864
|
-
gasLimit: request.gasLimit,
|
4865
|
-
minGasPrice
|
5086
|
+
const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: baseAssetId }];
|
5087
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5088
|
+
this.validateGasLimitAndMaxFee({
|
5089
|
+
gasUsed: txCost.gasUsed,
|
5090
|
+
maxFee: txCost.maxFee,
|
5091
|
+
txParams
|
4866
5092
|
});
|
4867
|
-
|
5093
|
+
request.maxFee = txCost.maxFee;
|
5094
|
+
request.gasLimit = txCost.gasUsed;
|
5095
|
+
await this.fund(request, txCost);
|
4868
5096
|
return this.sendTransaction(request);
|
4869
5097
|
}
|
4870
5098
|
async signMessage(message) {
|
@@ -4922,22 +5150,21 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4922
5150
|
}
|
4923
5151
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4924
5152
|
}
|
4925
|
-
|
5153
|
+
validateGasLimitAndMaxFee({
|
5154
|
+
txParams: { gasLimit: setGasLimit, maxFee: setMaxFee },
|
4926
5155
|
gasUsed,
|
4927
|
-
|
4928
|
-
gasLimit,
|
4929
|
-
minGasPrice
|
5156
|
+
maxFee
|
4930
5157
|
}) {
|
4931
|
-
if (
|
5158
|
+
if ((0, import_utils27.isDefined)(setGasLimit) && gasUsed.gt(setGasLimit)) {
|
4932
5159
|
throw new import_errors16.FuelError(
|
4933
|
-
import_errors16.ErrorCode.
|
4934
|
-
`Gas
|
5160
|
+
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
5161
|
+
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
4935
5162
|
);
|
4936
5163
|
}
|
4937
|
-
if (
|
5164
|
+
if ((0, import_utils27.isDefined)(setMaxFee) && maxFee.gt(setMaxFee)) {
|
4938
5165
|
throw new import_errors16.FuelError(
|
4939
|
-
import_errors16.ErrorCode.
|
4940
|
-
`
|
5166
|
+
import_errors16.ErrorCode.MAX_FEE_TOO_LOW,
|
5167
|
+
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
4941
5168
|
);
|
4942
5169
|
}
|
4943
5170
|
}
|
@@ -4947,8 +5174,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4947
5174
|
var import_address5 = require("@fuel-ts/address");
|
4948
5175
|
var import_crypto2 = require("@fuel-ts/crypto");
|
4949
5176
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4950
|
-
var
|
4951
|
-
var
|
5177
|
+
var import_math20 = require("@fuel-ts/math");
|
5178
|
+
var import_utils28 = require("@fuel-ts/utils");
|
4952
5179
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4953
5180
|
var Signer = class {
|
4954
5181
|
address;
|
@@ -4967,10 +5194,10 @@ var Signer = class {
|
|
4967
5194
|
privateKey = `0x${privateKey}`;
|
4968
5195
|
}
|
4969
5196
|
}
|
4970
|
-
const privateKeyBytes = (0,
|
4971
|
-
this.privateKey = (0,
|
4972
|
-
this.publicKey = (0,
|
4973
|
-
this.compressedPublicKey = (0,
|
5197
|
+
const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
|
5198
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5199
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5200
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
4974
5201
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
4975
5202
|
}
|
4976
5203
|
/**
|
@@ -4984,11 +5211,11 @@ var Signer = class {
|
|
4984
5211
|
* @returns hashed signature
|
4985
5212
|
*/
|
4986
5213
|
sign(data) {
|
4987
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
4988
|
-
const r = (0,
|
4989
|
-
const s = (0,
|
5214
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5215
|
+
const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5216
|
+
const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4990
5217
|
s[0] |= (signature.recovery || 0) << 7;
|
4991
|
-
return (0,
|
5218
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
4992
5219
|
}
|
4993
5220
|
/**
|
4994
5221
|
* Add point on the current elliptic curve
|
@@ -4997,8 +5224,8 @@ var Signer = class {
|
|
4997
5224
|
* @returns compressed point on the curve
|
4998
5225
|
*/
|
4999
5226
|
addPoint(point) {
|
5000
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5001
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5227
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5228
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
5002
5229
|
const result = p0.add(p1);
|
5003
5230
|
return `0x${result.toHex(true)}`;
|
5004
5231
|
}
|
@@ -5010,16 +5237,16 @@ var Signer = class {
|
|
5010
5237
|
* @returns public key from signature from the
|
5011
5238
|
*/
|
5012
5239
|
static recoverPublicKey(data, signature) {
|
5013
|
-
const signedMessageBytes = (0,
|
5240
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5014
5241
|
const r = signedMessageBytes.slice(0, 32);
|
5015
5242
|
const s = signedMessageBytes.slice(32, 64);
|
5016
5243
|
const recoveryParam = (s[0] & 128) >> 7;
|
5017
5244
|
s[0] &= 127;
|
5018
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5245
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5019
5246
|
recoveryParam
|
5020
5247
|
);
|
5021
|
-
const publicKey = sig.recoverPublicKey((0,
|
5022
|
-
return (0,
|
5248
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5249
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5023
5250
|
}
|
5024
5251
|
/**
|
5025
5252
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5038,7 +5265,7 @@ var Signer = class {
|
|
5038
5265
|
* @returns random 32-byte hashed
|
5039
5266
|
*/
|
5040
5267
|
static generatePrivateKey(entropy) {
|
5041
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5268
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5042
5269
|
}
|
5043
5270
|
/**
|
5044
5271
|
* Extended publicKey from a compact publicKey
|
@@ -5047,8 +5274,8 @@ var Signer = class {
|
|
5047
5274
|
* @returns extended publicKey
|
5048
5275
|
*/
|
5049
5276
|
static extendPublicKey(publicKey) {
|
5050
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5051
|
-
return (0,
|
5277
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5278
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5052
5279
|
}
|
5053
5280
|
};
|
5054
5281
|
|
@@ -5056,7 +5283,7 @@ var Signer = class {
|
|
5056
5283
|
var import_address6 = require("@fuel-ts/address");
|
5057
5284
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5058
5285
|
var import_errors17 = require("@fuel-ts/errors");
|
5059
|
-
var
|
5286
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5060
5287
|
var import_uuid = require("uuid");
|
5061
5288
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5062
5289
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5139,7 +5366,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5139
5366
|
);
|
5140
5367
|
}
|
5141
5368
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5142
|
-
const privateKey = (0,
|
5369
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5143
5370
|
return privateKey;
|
5144
5371
|
}
|
5145
5372
|
|
@@ -5184,7 +5411,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5184
5411
|
*/
|
5185
5412
|
async signMessage(message) {
|
5186
5413
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5187
|
-
return (0,
|
5414
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5188
5415
|
}
|
5189
5416
|
/**
|
5190
5417
|
* Signs a transaction with the wallet's private key.
|
@@ -5197,7 +5424,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5197
5424
|
const chainId = this.provider.getChainId();
|
5198
5425
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5199
5426
|
const signature = await this.signer().sign(hashedTransaction);
|
5200
|
-
return (0,
|
5427
|
+
return (0, import_utils30.hexlify)(signature);
|
5201
5428
|
}
|
5202
5429
|
/**
|
5203
5430
|
* Populates a transaction with the witnesses signature.
|
@@ -5217,7 +5444,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5217
5444
|
* @param transactionRequestLike - The transaction request to send.
|
5218
5445
|
* @returns A promise that resolves to the TransactionResponse object.
|
5219
5446
|
*/
|
5220
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5447
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5221
5448
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5222
5449
|
if (estimateTxDependencies) {
|
5223
5450
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5258,16 +5485,16 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5258
5485
|
// src/hdwallet/hdwallet.ts
|
5259
5486
|
var import_errors20 = require("@fuel-ts/errors");
|
5260
5487
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5261
|
-
var
|
5262
|
-
var
|
5263
|
-
var
|
5488
|
+
var import_math21 = require("@fuel-ts/math");
|
5489
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5490
|
+
var import_ethers3 = require("ethers");
|
5264
5491
|
|
5265
5492
|
// src/mnemonic/mnemonic.ts
|
5266
5493
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5267
5494
|
var import_errors19 = require("@fuel-ts/errors");
|
5268
5495
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5269
|
-
var
|
5270
|
-
var
|
5496
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5497
|
+
var import_ethers2 = require("ethers");
|
5271
5498
|
|
5272
5499
|
// src/wordlists/words/english.ts
|
5273
5500
|
var english = [
|
@@ -7324,7 +7551,7 @@ var english = [
|
|
7324
7551
|
// src/mnemonic/utils.ts
|
7325
7552
|
var import_errors18 = require("@fuel-ts/errors");
|
7326
7553
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7327
|
-
var
|
7554
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7328
7555
|
function toUtf8Bytes(stri) {
|
7329
7556
|
const str = stri.normalize("NFKD");
|
7330
7557
|
const result = [];
|
@@ -7391,14 +7618,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7391
7618
|
}
|
7392
7619
|
}
|
7393
7620
|
const checksumBits = entropy.length / 4;
|
7394
|
-
const checksum = (0,
|
7621
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7395
7622
|
indices[indices.length - 1] <<= checksumBits;
|
7396
7623
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7397
7624
|
return indices;
|
7398
7625
|
}
|
7399
7626
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7400
7627
|
const size = Math.ceil(11 * words.length / 8);
|
7401
|
-
const entropy = (0,
|
7628
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7402
7629
|
let offset = 0;
|
7403
7630
|
for (let i = 0; i < words.length; i += 1) {
|
7404
7631
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7418,7 +7645,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7418
7645
|
const entropyBits = 32 * words.length / 3;
|
7419
7646
|
const checksumBits = words.length / 3;
|
7420
7647
|
const checksumMask = getUpperMask(checksumBits);
|
7421
|
-
const checksum = (0,
|
7648
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7422
7649
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7423
7650
|
throw new import_errors18.FuelError(
|
7424
7651
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7493,7 +7720,7 @@ var Mnemonic = class {
|
|
7493
7720
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7494
7721
|
const words = getWords(phrase);
|
7495
7722
|
assertMnemonic(words);
|
7496
|
-
return (0,
|
7723
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7497
7724
|
}
|
7498
7725
|
/**
|
7499
7726
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7501,7 +7728,7 @@ var Mnemonic = class {
|
|
7501
7728
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7502
7729
|
*/
|
7503
7730
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7504
|
-
const entropyBytes = (0,
|
7731
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7505
7732
|
assertWordList(wordlist);
|
7506
7733
|
assertEntropy(entropyBytes);
|
7507
7734
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7515,7 +7742,7 @@ var Mnemonic = class {
|
|
7515
7742
|
assertMnemonic(getWords(phrase));
|
7516
7743
|
const phraseBytes = toUtf8Bytes(getPhrase(phrase));
|
7517
7744
|
const salt = toUtf8Bytes(`mnemonic${passphrase}`);
|
7518
|
-
return (0,
|
7745
|
+
return (0, import_ethers2.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
|
7519
7746
|
}
|
7520
7747
|
/**
|
7521
7748
|
* @param phrase - Mnemonic phrase composed by words from the provided wordlist
|
@@ -7570,14 +7797,14 @@ var Mnemonic = class {
|
|
7570
7797
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7571
7798
|
*/
|
7572
7799
|
static masterKeysFromSeed(seed) {
|
7573
|
-
const seedArray = (0,
|
7800
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
7574
7801
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7575
7802
|
throw new import_errors19.FuelError(
|
7576
7803
|
import_errors19.ErrorCode.INVALID_SEED,
|
7577
7804
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7578
7805
|
);
|
7579
7806
|
}
|
7580
|
-
return (0,
|
7807
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7581
7808
|
}
|
7582
7809
|
/**
|
7583
7810
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7588,22 +7815,22 @@ var Mnemonic = class {
|
|
7588
7815
|
*/
|
7589
7816
|
static seedToExtendedKey(seed, testnet = false) {
|
7590
7817
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7591
|
-
const prefix = (0,
|
7818
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7592
7819
|
const depth = "0x00";
|
7593
7820
|
const fingerprint = "0x00000000";
|
7594
7821
|
const index = "0x00000000";
|
7595
7822
|
const chainCode = masterKey.slice(32);
|
7596
7823
|
const privateKey = masterKey.slice(0, 32);
|
7597
|
-
const extendedKey = (0,
|
7824
|
+
const extendedKey = (0, import_utils32.concat)([
|
7598
7825
|
prefix,
|
7599
7826
|
depth,
|
7600
7827
|
fingerprint,
|
7601
7828
|
index,
|
7602
7829
|
chainCode,
|
7603
|
-
(0,
|
7830
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
7604
7831
|
]);
|
7605
|
-
const checksum = (0,
|
7606
|
-
return (0,
|
7832
|
+
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7833
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
7607
7834
|
}
|
7608
7835
|
/**
|
7609
7836
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7618,7 +7845,7 @@ var Mnemonic = class {
|
|
7618
7845
|
* @returns A randomly generated mnemonic
|
7619
7846
|
*/
|
7620
7847
|
static generate(size = 32, extraEntropy = "") {
|
7621
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7848
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
7622
7849
|
return Mnemonic.entropyToMnemonic(entropy);
|
7623
7850
|
}
|
7624
7851
|
};
|
@@ -7626,12 +7853,12 @@ var mnemonic_default = Mnemonic;
|
|
7626
7853
|
|
7627
7854
|
// src/hdwallet/hdwallet.ts
|
7628
7855
|
var HARDENED_INDEX = 2147483648;
|
7629
|
-
var MainnetPRV2 = (0,
|
7630
|
-
var MainnetPUB = (0,
|
7631
|
-
var TestnetPRV2 = (0,
|
7632
|
-
var TestnetPUB = (0,
|
7856
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
7857
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
7858
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
7859
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
7633
7860
|
function base58check(data) {
|
7634
|
-
return (0,
|
7861
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7635
7862
|
}
|
7636
7863
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7637
7864
|
if (isPublic) {
|
@@ -7640,11 +7867,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7640
7867
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7641
7868
|
}
|
7642
7869
|
function isPublicExtendedKey(extendedKey) {
|
7643
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7870
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
7644
7871
|
}
|
7645
7872
|
function isValidExtendedKey(extendedKey) {
|
7646
7873
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7647
|
-
(0,
|
7874
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
7648
7875
|
);
|
7649
7876
|
}
|
7650
7877
|
function parsePath(path2, depth = 0) {
|
@@ -7662,8 +7889,8 @@ function parsePath(path2, depth = 0) {
|
|
7662
7889
|
var HDWallet = class {
|
7663
7890
|
depth = 0;
|
7664
7891
|
index = 0;
|
7665
|
-
fingerprint = (0,
|
7666
|
-
parentFingerprint = (0,
|
7892
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7893
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7667
7894
|
privateKey;
|
7668
7895
|
publicKey;
|
7669
7896
|
chainCode;
|
@@ -7675,8 +7902,8 @@ var HDWallet = class {
|
|
7675
7902
|
constructor(config) {
|
7676
7903
|
if (config.privateKey) {
|
7677
7904
|
const signer = new Signer(config.privateKey);
|
7678
|
-
this.publicKey = (0,
|
7679
|
-
this.privateKey = (0,
|
7905
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
7906
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
7680
7907
|
} else {
|
7681
7908
|
if (!config.publicKey) {
|
7682
7909
|
throw new import_errors20.FuelError(
|
@@ -7684,10 +7911,10 @@ var HDWallet = class {
|
|
7684
7911
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7685
7912
|
);
|
7686
7913
|
}
|
7687
|
-
this.publicKey = (0,
|
7914
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
7688
7915
|
}
|
7689
7916
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7690
|
-
this.fingerprint = (0,
|
7917
|
+
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
7691
7918
|
this.depth = config.depth || this.depth;
|
7692
7919
|
this.index = config.index || this.index;
|
7693
7920
|
this.chainCode = config.chainCode;
|
@@ -7703,9 +7930,9 @@ var HDWallet = class {
|
|
7703
7930
|
* @returns A new instance of HDWallet on the derived index
|
7704
7931
|
*/
|
7705
7932
|
deriveIndex(index) {
|
7706
|
-
const privateKey = this.privateKey && (0,
|
7707
|
-
const publicKey = (0,
|
7708
|
-
const chainCode = (0,
|
7933
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
7934
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
7935
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
7709
7936
|
const data = new Uint8Array(37);
|
7710
7937
|
if (index & HARDENED_INDEX) {
|
7711
7938
|
if (!privateKey) {
|
@@ -7716,15 +7943,15 @@ var HDWallet = class {
|
|
7716
7943
|
}
|
7717
7944
|
data.set(privateKey, 1);
|
7718
7945
|
} else {
|
7719
|
-
data.set((0,
|
7946
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
7720
7947
|
}
|
7721
|
-
data.set((0,
|
7722
|
-
const bytes = (0,
|
7948
|
+
data.set((0, import_math21.toBytes)(index, 4), 33);
|
7949
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7723
7950
|
const IL = bytes.slice(0, 32);
|
7724
7951
|
const IR = bytes.slice(32);
|
7725
7952
|
if (privateKey) {
|
7726
7953
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7727
|
-
const ki = (0,
|
7954
|
+
const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7728
7955
|
return new HDWallet({
|
7729
7956
|
privateKey: ki,
|
7730
7957
|
chainCode: IR,
|
@@ -7733,7 +7960,7 @@ var HDWallet = class {
|
|
7733
7960
|
parentFingerprint: this.fingerprint
|
7734
7961
|
});
|
7735
7962
|
}
|
7736
|
-
const signer = new Signer((0,
|
7963
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
7737
7964
|
const Ki = signer.addPoint(publicKey);
|
7738
7965
|
return new HDWallet({
|
7739
7966
|
publicKey: Ki,
|
@@ -7768,12 +7995,12 @@ var HDWallet = class {
|
|
7768
7995
|
);
|
7769
7996
|
}
|
7770
7997
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7771
|
-
const depth = (0,
|
7998
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
7772
7999
|
const parentFingerprint = this.parentFingerprint;
|
7773
|
-
const index = (0,
|
8000
|
+
const index = (0, import_math21.toHex)(this.index, 4);
|
7774
8001
|
const chainCode = this.chainCode;
|
7775
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7776
|
-
const extendedKey = (0,
|
8002
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8003
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7777
8004
|
return base58check(extendedKey);
|
7778
8005
|
}
|
7779
8006
|
/**
|
@@ -7785,13 +8012,13 @@ var HDWallet = class {
|
|
7785
8012
|
static fromSeed(seed) {
|
7786
8013
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7787
8014
|
return new HDWallet({
|
7788
|
-
chainCode: (0,
|
7789
|
-
privateKey: (0,
|
8015
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
8016
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
7790
8017
|
});
|
7791
8018
|
}
|
7792
8019
|
static fromExtendedKey(extendedKey) {
|
7793
|
-
const decoded = (0,
|
7794
|
-
const bytes = (0,
|
8020
|
+
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8021
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
7795
8022
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7796
8023
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7797
8024
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -7800,9 +8027,9 @@ var HDWallet = class {
|
|
7800
8027
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7801
8028
|
}
|
7802
8029
|
const depth = bytes[4];
|
7803
|
-
const parentFingerprint = (0,
|
7804
|
-
const index = parseInt((0,
|
7805
|
-
const chainCode = (0,
|
8030
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8031
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8032
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
7806
8033
|
const key = bytes.slice(45, 78);
|
7807
8034
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7808
8035
|
throw new import_errors20.FuelError(
|
@@ -7995,14 +8222,15 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
7995
8222
|
process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
|
7996
8223
|
wallet.provider
|
7997
8224
|
);
|
7998
|
-
const
|
7999
|
-
|
8000
|
-
|
8001
|
-
|
8002
|
-
gasPrice: minGasPrice
|
8225
|
+
const request = new ScriptTransactionRequest();
|
8226
|
+
quantities.forEach((quantity) => {
|
8227
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8228
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
8003
8229
|
});
|
8004
|
-
|
8005
|
-
|
8230
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8231
|
+
request.gasLimit = txCost.gasUsed;
|
8232
|
+
request.maxFee = txCost.maxFee;
|
8233
|
+
await genesisWallet.fund(request, txCost);
|
8006
8234
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8007
8235
|
};
|
8008
8236
|
|
@@ -8016,12 +8244,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8016
8244
|
};
|
8017
8245
|
|
8018
8246
|
// src/test-utils/launchNode.ts
|
8019
|
-
var
|
8020
|
-
var
|
8021
|
-
var
|
8247
|
+
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
8248
|
+
var import_crypto6 = require("@fuel-ts/crypto");
|
8249
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8022
8250
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8023
8251
|
var import_child_process = require("child_process");
|
8024
|
-
var
|
8252
|
+
var import_crypto7 = require("crypto");
|
8025
8253
|
var import_fs = require("fs");
|
8026
8254
|
var import_os = __toESM(require("os"));
|
8027
8255
|
var import_path = __toESM(require("path"));
|
@@ -8070,13 +8298,13 @@ var launchNode = async ({
|
|
8070
8298
|
// eslint-disable-next-line no-async-promise-executor
|
8071
8299
|
new Promise(async (resolve, reject) => {
|
8072
8300
|
const remainingArgs = extractRemainingArgs(args, [
|
8073
|
-
"--
|
8301
|
+
"--snapshot",
|
8074
8302
|
"--consensus-key",
|
8075
8303
|
"--db-type",
|
8076
8304
|
"--poa-instant"
|
8077
8305
|
]);
|
8078
|
-
const
|
8079
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8306
|
+
const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
|
8307
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
|
8080
8308
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8081
8309
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8082
8310
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8091,39 +8319,57 @@ var launchNode = async ({
|
|
8091
8319
|
stopPort: 5e3
|
8092
8320
|
// don't try ports above 5000
|
8093
8321
|
})).toString();
|
8094
|
-
let
|
8322
|
+
let snapshotDirToUse;
|
8095
8323
|
const prefix = basePath || import_os.default.tmpdir();
|
8096
|
-
const suffix = basePath ? "" : (0,
|
8097
|
-
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8098
|
-
if (
|
8099
|
-
|
8324
|
+
const suffix = basePath ? "" : (0, import_crypto7.randomUUID)();
|
8325
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
|
8326
|
+
if (snapshotDir) {
|
8327
|
+
snapshotDirToUse = snapshotDir;
|
8100
8328
|
} else {
|
8101
8329
|
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8102
8330
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8103
8331
|
}
|
8104
|
-
|
8105
|
-
|
8332
|
+
let { stateConfigJson } = import_utils35.defaultSnapshotConfigs;
|
8333
|
+
const { chainConfigJson, metadataJson } = import_utils35.defaultSnapshotConfigs;
|
8334
|
+
stateConfigJson = {
|
8335
|
+
...stateConfigJson,
|
8336
|
+
coins: [
|
8337
|
+
...stateConfigJson.coins.map((coin) => ({
|
8338
|
+
...coin,
|
8339
|
+
amount: "18446744073709551615"
|
8340
|
+
}))
|
8341
|
+
],
|
8342
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8343
|
+
...message,
|
8344
|
+
amount: "18446744073709551615"
|
8345
|
+
}))
|
8346
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8347
|
+
};
|
8106
8348
|
if (!process.env.GENESIS_SECRET) {
|
8107
8349
|
const pk = Signer.generatePrivateKey();
|
8108
8350
|
const signer = new Signer(pk);
|
8109
|
-
process.env.GENESIS_SECRET = (0,
|
8110
|
-
|
8111
|
-
|
8112
|
-
|
8113
|
-
|
8114
|
-
|
8115
|
-
|
8116
|
-
|
8117
|
-
|
8118
|
-
|
8119
|
-
|
8120
|
-
}
|
8121
|
-
]
|
8122
|
-
}
|
8123
|
-
};
|
8351
|
+
process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
|
8352
|
+
stateConfigJson.coins.push({
|
8353
|
+
tx_id: (0, import_utils35.hexlify)((0, import_crypto6.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
|
8354
|
+
owner: signer.address.toHexString(),
|
8355
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8356
|
+
amount: "18446744073709551615",
|
8357
|
+
asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
|
8358
|
+
output_index: 0,
|
8359
|
+
tx_pointer_block_height: 0,
|
8360
|
+
tx_pointer_tx_idx: 0
|
8361
|
+
});
|
8124
8362
|
}
|
8125
|
-
|
8126
|
-
|
8363
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8364
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8365
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8366
|
+
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8367
|
+
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8368
|
+
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8369
|
+
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8370
|
+
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8371
|
+
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8372
|
+
snapshotDirToUse = tempDirPath;
|
8127
8373
|
}
|
8128
8374
|
const child = (0, import_child_process.spawn)(
|
8129
8375
|
command,
|
@@ -8132,10 +8378,10 @@ var launchNode = async ({
|
|
8132
8378
|
["--ip", ipToUse],
|
8133
8379
|
["--port", portToUse],
|
8134
8380
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8135
|
-
["--min-gas-price", "
|
8381
|
+
["--min-gas-price", "1"],
|
8136
8382
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8137
8383
|
["--consensus-key", consensusKey],
|
8138
|
-
["--
|
8384
|
+
["--snapshot", snapshotDirToUse],
|
8139
8385
|
"--vm-backtrace",
|
8140
8386
|
"--utxo-validation",
|
8141
8387
|
"--debug",
|
@@ -8165,7 +8411,7 @@ var launchNode = async ({
|
|
8165
8411
|
cleanup: () => killNode(cleanupConfig),
|
8166
8412
|
ip: ipToUse,
|
8167
8413
|
port: portToUse,
|
8168
|
-
|
8414
|
+
snapshotDir: snapshotDirToUse
|
8169
8415
|
});
|
8170
8416
|
}
|
8171
8417
|
if (/error/i.test(chunk)) {
|
@@ -8195,7 +8441,7 @@ var launchNodeAndGetWallets = async ({
|
|
8195
8441
|
walletCount = 10
|
8196
8442
|
} = {}) => {
|
8197
8443
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8198
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8444
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8199
8445
|
const wallets = await generateWallets(walletCount, provider);
|
8200
8446
|
const cleanup = () => {
|
8201
8447
|
closeNode();
|