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