@fuel-ts/account 0.0.0-rc-2034-20240415163000 → 0.0.0-rc-2021-20240415193305
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/README.md +1 -1
- package/dist/account.d.ts +5 -4
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -1
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +1 -1
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +1 -1
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +795 -544
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +762 -507
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +642 -388
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +10 -2
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +906 -324
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +4 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/message.d.ts +7 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +37 -27
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +8 -25
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/utils.d.ts +3 -0
- package/dist/providers/transaction-request/utils.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +2 -0
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts +3 -2
- package/dist/providers/transaction-summary/calculate-transaction-fee.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/utils/gas.d.ts +8 -2
- package/dist/providers/utils/gas.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +1545 -1056
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +740 -503
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +634 -397
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -17
package/dist/test-utils.js
CHANGED
@@ -58,15 +58,16 @@ module.exports = __toCommonJS(test_utils_exports);
|
|
58
58
|
|
59
59
|
// src/wallet/base-wallet-unlocked.ts
|
60
60
|
var import_hasher3 = require("@fuel-ts/hasher");
|
61
|
-
var
|
61
|
+
var import_utils30 = require("@fuel-ts/utils");
|
62
62
|
|
63
63
|
// src/account.ts
|
64
64
|
var import_address4 = require("@fuel-ts/address");
|
65
65
|
var import_configs12 = require("@fuel-ts/address/configs");
|
66
66
|
var import_errors16 = require("@fuel-ts/errors");
|
67
67
|
var import_interfaces = require("@fuel-ts/interfaces");
|
68
|
-
var
|
69
|
-
var
|
68
|
+
var import_math19 = require("@fuel-ts/math");
|
69
|
+
var import_utils27 = require("@fuel-ts/utils");
|
70
|
+
var import_ramda4 = require("ramda");
|
70
71
|
|
71
72
|
// src/providers/coin-quantity.ts
|
72
73
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -92,7 +93,7 @@ var coinQuantityfy = (coinQuantityLike) => {
|
|
92
93
|
max: max2 ? (0, import_math.bn)(max2) : void 0
|
93
94
|
};
|
94
95
|
};
|
95
|
-
var
|
96
|
+
var addAmountToCoinQuantities = (params) => {
|
96
97
|
const { amount, assetId } = params;
|
97
98
|
const coinQuantities = [...params.coinQuantities];
|
98
99
|
const assetIdx = coinQuantities.findIndex((coinQuantity) => coinQuantity.assetId === assetId);
|
@@ -107,11 +108,11 @@ var addAmountToAsset = (params) => {
|
|
107
108
|
// src/providers/provider.ts
|
108
109
|
var import_address3 = require("@fuel-ts/address");
|
109
110
|
var import_errors14 = require("@fuel-ts/errors");
|
110
|
-
var
|
111
|
-
var
|
112
|
-
var
|
111
|
+
var import_math16 = require("@fuel-ts/math");
|
112
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
113
|
+
var import_utils22 = require("@fuel-ts/utils");
|
113
114
|
var import_versions = require("@fuel-ts/versions");
|
114
|
-
var
|
115
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
115
116
|
var import_ethers = require("ethers");
|
116
117
|
var import_graphql_request = require("graphql-request");
|
117
118
|
var import_ramda3 = require("ramda");
|
@@ -120,14 +121,10 @@ var import_ramda3 = require("ramda");
|
|
120
121
|
var import_graphql_tag = __toESM(require("graphql-tag"));
|
121
122
|
var ReceiptFragmentFragmentDoc = import_graphql_tag.default`
|
122
123
|
fragment receiptFragment on Receipt {
|
123
|
-
|
124
|
-
id
|
125
|
-
}
|
124
|
+
id
|
126
125
|
pc
|
127
126
|
is
|
128
|
-
to
|
129
|
-
id
|
130
|
-
}
|
127
|
+
to
|
131
128
|
toAddress
|
132
129
|
amount
|
133
130
|
assetId
|
@@ -165,10 +162,16 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
165
162
|
id
|
166
163
|
}
|
167
164
|
time
|
165
|
+
receipts {
|
166
|
+
...receiptFragment
|
167
|
+
}
|
168
168
|
programState {
|
169
169
|
returnType
|
170
170
|
data
|
171
171
|
}
|
172
|
+
receipts {
|
173
|
+
...receiptFragment
|
174
|
+
}
|
172
175
|
}
|
173
176
|
... on FailureStatus {
|
174
177
|
block {
|
@@ -176,26 +179,24 @@ var TransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
|
176
179
|
}
|
177
180
|
time
|
178
181
|
reason
|
182
|
+
receipts {
|
183
|
+
...receiptFragment
|
184
|
+
}
|
179
185
|
}
|
180
186
|
... on SqueezedOutStatus {
|
181
187
|
reason
|
182
188
|
}
|
183
189
|
}
|
184
|
-
`;
|
190
|
+
${ReceiptFragmentFragmentDoc}`;
|
185
191
|
var TransactionFragmentFragmentDoc = import_graphql_tag.default`
|
186
192
|
fragment transactionFragment on Transaction {
|
187
193
|
id
|
188
194
|
rawPayload
|
189
|
-
gasPrice
|
190
|
-
receipts {
|
191
|
-
...receiptFragment
|
192
|
-
}
|
193
195
|
status {
|
194
196
|
...transactionStatusFragment
|
195
197
|
}
|
196
198
|
}
|
197
|
-
${
|
198
|
-
${TransactionStatusFragmentFragmentDoc}`;
|
199
|
+
${TransactionStatusFragmentFragmentDoc}`;
|
199
200
|
var InputEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.default`
|
200
201
|
fragment inputEstimatePredicatesFragment on Input {
|
201
202
|
... on InputCoin {
|
@@ -213,6 +214,46 @@ var TransactionEstimatePredicatesFragmentFragmentDoc = import_graphql_tag.defaul
|
|
213
214
|
}
|
214
215
|
}
|
215
216
|
${InputEstimatePredicatesFragmentFragmentDoc}`;
|
217
|
+
var DryRunFailureStatusFragmentFragmentDoc = import_graphql_tag.default`
|
218
|
+
fragment dryRunFailureStatusFragment on DryRunFailureStatus {
|
219
|
+
reason
|
220
|
+
programState {
|
221
|
+
returnType
|
222
|
+
data
|
223
|
+
}
|
224
|
+
}
|
225
|
+
`;
|
226
|
+
var DryRunSuccessStatusFragmentFragmentDoc = import_graphql_tag.default`
|
227
|
+
fragment dryRunSuccessStatusFragment on DryRunSuccessStatus {
|
228
|
+
programState {
|
229
|
+
returnType
|
230
|
+
data
|
231
|
+
}
|
232
|
+
}
|
233
|
+
`;
|
234
|
+
var DryRunTransactionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
235
|
+
fragment dryRunTransactionStatusFragment on DryRunTransactionStatus {
|
236
|
+
... on DryRunFailureStatus {
|
237
|
+
...dryRunFailureStatusFragment
|
238
|
+
}
|
239
|
+
... on DryRunSuccessStatus {
|
240
|
+
...dryRunSuccessStatusFragment
|
241
|
+
}
|
242
|
+
}
|
243
|
+
${DryRunFailureStatusFragmentFragmentDoc}
|
244
|
+
${DryRunSuccessStatusFragmentFragmentDoc}`;
|
245
|
+
var DryRunTransactionExecutionStatusFragmentFragmentDoc = import_graphql_tag.default`
|
246
|
+
fragment dryRunTransactionExecutionStatusFragment on DryRunTransactionExecutionStatus {
|
247
|
+
id
|
248
|
+
status {
|
249
|
+
...dryRunTransactionStatusFragment
|
250
|
+
}
|
251
|
+
receipts {
|
252
|
+
...receiptFragment
|
253
|
+
}
|
254
|
+
}
|
255
|
+
${DryRunTransactionStatusFragmentFragmentDoc}
|
256
|
+
${ReceiptFragmentFragmentDoc}`;
|
216
257
|
var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
217
258
|
fragment coinFragment on Coin {
|
218
259
|
__typename
|
@@ -220,7 +261,6 @@ var CoinFragmentFragmentDoc = import_graphql_tag.default`
|
|
220
261
|
owner
|
221
262
|
amount
|
222
263
|
assetId
|
223
|
-
maturity
|
224
264
|
blockCreated
|
225
265
|
txCreatedIdx
|
226
266
|
}
|
@@ -259,26 +299,32 @@ var MessageProofFragmentFragmentDoc = import_graphql_tag.default`
|
|
259
299
|
messageBlockHeader {
|
260
300
|
id
|
261
301
|
daHeight
|
302
|
+
consensusParametersVersion
|
303
|
+
stateTransitionBytecodeVersion
|
262
304
|
transactionsCount
|
305
|
+
messageReceiptCount
|
263
306
|
transactionsRoot
|
307
|
+
messageOutboxRoot
|
308
|
+
eventInboxRoot
|
264
309
|
height
|
265
310
|
prevRoot
|
266
311
|
time
|
267
312
|
applicationHash
|
268
|
-
messageReceiptRoot
|
269
|
-
messageReceiptCount
|
270
313
|
}
|
271
314
|
commitBlockHeader {
|
272
315
|
id
|
273
316
|
daHeight
|
317
|
+
consensusParametersVersion
|
318
|
+
stateTransitionBytecodeVersion
|
274
319
|
transactionsCount
|
320
|
+
messageReceiptCount
|
275
321
|
transactionsRoot
|
322
|
+
messageOutboxRoot
|
323
|
+
eventInboxRoot
|
276
324
|
height
|
277
325
|
prevRoot
|
278
326
|
time
|
279
327
|
applicationHash
|
280
|
-
messageReceiptRoot
|
281
|
-
messageReceiptCount
|
282
328
|
}
|
283
329
|
sender
|
284
330
|
recipient
|
@@ -297,8 +343,8 @@ var BalanceFragmentFragmentDoc = import_graphql_tag.default`
|
|
297
343
|
var BlockFragmentFragmentDoc = import_graphql_tag.default`
|
298
344
|
fragment blockFragment on Block {
|
299
345
|
id
|
346
|
+
height
|
300
347
|
header {
|
301
|
-
height
|
302
348
|
time
|
303
349
|
}
|
304
350
|
transactions {
|
@@ -356,6 +402,11 @@ var DependentCostFragmentFragmentDoc = import_graphql_tag.default`
|
|
356
402
|
`;
|
357
403
|
var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
358
404
|
fragment GasCostsFragment on GasCosts {
|
405
|
+
version {
|
406
|
+
... on Version {
|
407
|
+
value
|
408
|
+
}
|
409
|
+
}
|
359
410
|
add
|
360
411
|
addi
|
361
412
|
aloc
|
@@ -368,7 +419,6 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
368
419
|
cb
|
369
420
|
cfei
|
370
421
|
cfsi
|
371
|
-
croo
|
372
422
|
div
|
373
423
|
divi
|
374
424
|
ecr1
|
@@ -451,6 +501,9 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
451
501
|
ccp {
|
452
502
|
...DependentCostFragment
|
453
503
|
}
|
504
|
+
croo {
|
505
|
+
...DependentCostFragment
|
506
|
+
}
|
454
507
|
csiz {
|
455
508
|
...DependentCostFragment
|
456
509
|
}
|
@@ -510,6 +563,11 @@ var GasCostsFragmentFragmentDoc = import_graphql_tag.default`
|
|
510
563
|
${DependentCostFragmentFragmentDoc}`;
|
511
564
|
var ConsensusParametersFragmentFragmentDoc = import_graphql_tag.default`
|
512
565
|
fragment consensusParametersFragment on ConsensusParameters {
|
566
|
+
version {
|
567
|
+
... on Version {
|
568
|
+
value
|
569
|
+
}
|
570
|
+
}
|
513
571
|
txParams {
|
514
572
|
...TxParametersFragment
|
515
573
|
}
|
@@ -569,18 +627,9 @@ var NodeInfoFragmentFragmentDoc = import_graphql_tag.default`
|
|
569
627
|
fragment nodeInfoFragment on NodeInfo {
|
570
628
|
utxoValidation
|
571
629
|
vmBacktrace
|
572
|
-
minGasPrice
|
573
630
|
maxTx
|
574
631
|
maxDepth
|
575
632
|
nodeVersion
|
576
|
-
peers {
|
577
|
-
id
|
578
|
-
addresses
|
579
|
-
clientVersion
|
580
|
-
blockHeight
|
581
|
-
lastHeartbeatMs
|
582
|
-
appScore
|
583
|
-
}
|
584
633
|
}
|
585
634
|
`;
|
586
635
|
var GetVersionDocument = import_graphql_tag.default`
|
@@ -615,13 +664,9 @@ var GetTransactionWithReceiptsDocument = import_graphql_tag.default`
|
|
615
664
|
query getTransactionWithReceipts($transactionId: TransactionId!) {
|
616
665
|
transaction(id: $transactionId) {
|
617
666
|
...transactionFragment
|
618
|
-
receipts {
|
619
|
-
...receiptFragment
|
620
|
-
}
|
621
667
|
}
|
622
668
|
}
|
623
|
-
${TransactionFragmentFragmentDoc}
|
624
|
-
${ReceiptFragmentFragmentDoc}`;
|
669
|
+
${TransactionFragmentFragmentDoc}`;
|
625
670
|
var GetTransactionsDocument = import_graphql_tag.default`
|
626
671
|
query getTransactions($after: String, $before: String, $first: Int, $last: Int) {
|
627
672
|
transactions(after: $after, before: $before, first: $first, last: $last) {
|
@@ -749,6 +794,20 @@ var GetBalanceDocument = import_graphql_tag.default`
|
|
749
794
|
}
|
750
795
|
}
|
751
796
|
${BalanceFragmentFragmentDoc}`;
|
797
|
+
var GetLatestGasPriceDocument = import_graphql_tag.default`
|
798
|
+
query getLatestGasPrice {
|
799
|
+
latestGasPrice {
|
800
|
+
gasPrice
|
801
|
+
}
|
802
|
+
}
|
803
|
+
`;
|
804
|
+
var EstimateGasPriceDocument = import_graphql_tag.default`
|
805
|
+
query estimateGasPrice($blockHorizon: U32!) {
|
806
|
+
estimateGasPrice(blockHorizon: $blockHorizon) {
|
807
|
+
gasPrice
|
808
|
+
}
|
809
|
+
}
|
810
|
+
`;
|
752
811
|
var GetBalancesDocument = import_graphql_tag.default`
|
753
812
|
query getBalances($filter: BalanceFilterInput!, $after: String, $before: String, $first: Int, $last: Int) {
|
754
813
|
balances(
|
@@ -803,12 +862,12 @@ var GetMessageStatusDocument = import_graphql_tag.default`
|
|
803
862
|
}
|
804
863
|
`;
|
805
864
|
var DryRunDocument = import_graphql_tag.default`
|
806
|
-
mutation dryRun($
|
807
|
-
dryRun(
|
808
|
-
...
|
865
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
866
|
+
dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
|
867
|
+
...dryRunTransactionExecutionStatusFragment
|
809
868
|
}
|
810
869
|
}
|
811
|
-
${
|
870
|
+
${DryRunTransactionExecutionStatusFragmentFragmentDoc}`;
|
812
871
|
var SubmitDocument = import_graphql_tag.default`
|
813
872
|
mutation submit($encodedTransaction: HexString!) {
|
814
873
|
submit(tx: $encodedTransaction) {
|
@@ -891,6 +950,12 @@ function getSdk(requester) {
|
|
891
950
|
getBalance(variables, options) {
|
892
951
|
return requester(GetBalanceDocument, variables, options);
|
893
952
|
},
|
953
|
+
getLatestGasPrice(variables, options) {
|
954
|
+
return requester(GetLatestGasPriceDocument, variables, options);
|
955
|
+
},
|
956
|
+
estimateGasPrice(variables, options) {
|
957
|
+
return requester(EstimateGasPriceDocument, variables, options);
|
958
|
+
},
|
894
959
|
getBalances(variables, options) {
|
895
960
|
return requester(GetBalancesDocument, variables, options);
|
896
961
|
},
|
@@ -960,11 +1025,14 @@ var _FuelGraphqlSubscriber = class {
|
|
960
1025
|
let data;
|
961
1026
|
let errors;
|
962
1027
|
try {
|
963
|
-
|
1028
|
+
const sanitizedText = text.replace(/\s/g, "");
|
1029
|
+
({ data, errors } = JSON.parse(sanitizedText.replace(/^data:/, "")));
|
964
1030
|
} catch (e) {
|
965
1031
|
throw new import_errors.FuelError(
|
966
1032
|
import_errors.ErrorCode.STREAM_PARSING_ERROR,
|
967
|
-
`Error while parsing stream data response: ${text}
|
1033
|
+
`Error while parsing stream data response: ${text}
|
1034
|
+
|
1035
|
+
Thrown error: ${e}`
|
968
1036
|
);
|
969
1037
|
}
|
970
1038
|
if (Array.isArray(errors)) {
|
@@ -1075,10 +1143,9 @@ var inputify = (value) => {
|
|
1075
1143
|
txIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.txPointer).slice(8, 16))
|
1076
1144
|
},
|
1077
1145
|
witnessIndex: value.witnessIndex,
|
1078
|
-
maturity: value.maturity ?? 0,
|
1079
1146
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1080
|
-
predicateLength: predicate.length,
|
1081
|
-
predicateDataLength: predicateData.length,
|
1147
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1148
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1082
1149
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1083
1150
|
predicateData: (0, import_utils3.hexlify)(predicateData)
|
1084
1151
|
};
|
@@ -1109,8 +1176,8 @@ var inputify = (value) => {
|
|
1109
1176
|
nonce: (0, import_utils3.hexlify)(value.nonce),
|
1110
1177
|
witnessIndex: value.witnessIndex,
|
1111
1178
|
predicateGasUsed: (0, import_math2.bn)(value.predicateGasUsed),
|
1112
|
-
predicateLength: predicate.length,
|
1113
|
-
predicateDataLength: predicateData.length,
|
1179
|
+
predicateLength: (0, import_math2.bn)(predicate.length),
|
1180
|
+
predicateDataLength: (0, import_math2.bn)(predicateData.length),
|
1114
1181
|
predicate: (0, import_utils3.hexlify)(predicate),
|
1115
1182
|
predicateData: (0, import_utils3.hexlify)(predicateData),
|
1116
1183
|
data: (0, import_utils3.hexlify)(data),
|
@@ -1226,8 +1293,8 @@ function assembleReceiptByType(receipt) {
|
|
1226
1293
|
case "CALL" /* Call */: {
|
1227
1294
|
const callReceipt = {
|
1228
1295
|
type: import_transactions3.ReceiptType.Call,
|
1229
|
-
from: hexOrZero(receipt.
|
1230
|
-
to: hexOrZero(receipt?.to
|
1296
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1297
|
+
to: hexOrZero(receipt?.to),
|
1231
1298
|
amount: (0, import_math4.bn)(receipt.amount),
|
1232
1299
|
assetId: hexOrZero(receipt.assetId),
|
1233
1300
|
gas: (0, import_math4.bn)(receipt.gas),
|
@@ -1241,7 +1308,7 @@ function assembleReceiptByType(receipt) {
|
|
1241
1308
|
case "RETURN" /* Return */: {
|
1242
1309
|
const returnReceipt = {
|
1243
1310
|
type: import_transactions3.ReceiptType.Return,
|
1244
|
-
id: hexOrZero(receipt.
|
1311
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1245
1312
|
val: (0, import_math4.bn)(receipt.val),
|
1246
1313
|
pc: (0, import_math4.bn)(receipt.pc),
|
1247
1314
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1251,7 +1318,7 @@ function assembleReceiptByType(receipt) {
|
|
1251
1318
|
case "RETURN_DATA" /* ReturnData */: {
|
1252
1319
|
const returnDataReceipt = {
|
1253
1320
|
type: import_transactions3.ReceiptType.ReturnData,
|
1254
|
-
id: hexOrZero(receipt.
|
1321
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1255
1322
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
1256
1323
|
len: (0, import_math4.bn)(receipt.len),
|
1257
1324
|
digest: hexOrZero(receipt.digest),
|
@@ -1263,7 +1330,7 @@ function assembleReceiptByType(receipt) {
|
|
1263
1330
|
case "PANIC" /* Panic */: {
|
1264
1331
|
const panicReceipt = {
|
1265
1332
|
type: import_transactions3.ReceiptType.Panic,
|
1266
|
-
id: hexOrZero(receipt.
|
1333
|
+
id: hexOrZero(receipt.id),
|
1267
1334
|
reason: (0, import_math4.bn)(receipt.reason),
|
1268
1335
|
pc: (0, import_math4.bn)(receipt.pc),
|
1269
1336
|
is: (0, import_math4.bn)(receipt.is),
|
@@ -1274,7 +1341,7 @@ function assembleReceiptByType(receipt) {
|
|
1274
1341
|
case "REVERT" /* Revert */: {
|
1275
1342
|
const revertReceipt = {
|
1276
1343
|
type: import_transactions3.ReceiptType.Revert,
|
1277
|
-
id: hexOrZero(receipt.
|
1344
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1278
1345
|
val: (0, import_math4.bn)(receipt.ra),
|
1279
1346
|
pc: (0, import_math4.bn)(receipt.pc),
|
1280
1347
|
is: (0, import_math4.bn)(receipt.is)
|
@@ -1284,7 +1351,7 @@ function assembleReceiptByType(receipt) {
|
|
1284
1351
|
case "LOG" /* Log */: {
|
1285
1352
|
const logReceipt = {
|
1286
1353
|
type: import_transactions3.ReceiptType.Log,
|
1287
|
-
id: hexOrZero(receipt.
|
1354
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1288
1355
|
val0: (0, import_math4.bn)(receipt.ra),
|
1289
1356
|
val1: (0, import_math4.bn)(receipt.rb),
|
1290
1357
|
val2: (0, import_math4.bn)(receipt.rc),
|
@@ -1297,7 +1364,7 @@ function assembleReceiptByType(receipt) {
|
|
1297
1364
|
case "LOG_DATA" /* LogData */: {
|
1298
1365
|
const logDataReceipt = {
|
1299
1366
|
type: import_transactions3.ReceiptType.LogData,
|
1300
|
-
id: hexOrZero(receipt.
|
1367
|
+
id: hexOrZero(receipt.id || receipt.contractId),
|
1301
1368
|
val0: (0, import_math4.bn)(receipt.ra),
|
1302
1369
|
val1: (0, import_math4.bn)(receipt.rb),
|
1303
1370
|
ptr: (0, import_math4.bn)(receipt.ptr),
|
@@ -1311,8 +1378,8 @@ function assembleReceiptByType(receipt) {
|
|
1311
1378
|
case "TRANSFER" /* Transfer */: {
|
1312
1379
|
const transferReceipt = {
|
1313
1380
|
type: import_transactions3.ReceiptType.Transfer,
|
1314
|
-
from: hexOrZero(receipt.
|
1315
|
-
to: hexOrZero(receipt.toAddress || receipt?.to
|
1381
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1382
|
+
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1316
1383
|
amount: (0, import_math4.bn)(receipt.amount),
|
1317
1384
|
assetId: hexOrZero(receipt.assetId),
|
1318
1385
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1323,8 +1390,8 @@ function assembleReceiptByType(receipt) {
|
|
1323
1390
|
case "TRANSFER_OUT" /* TransferOut */: {
|
1324
1391
|
const transferOutReceipt = {
|
1325
1392
|
type: import_transactions3.ReceiptType.TransferOut,
|
1326
|
-
from: hexOrZero(receipt.
|
1327
|
-
to: hexOrZero(receipt.toAddress || receipt.to
|
1393
|
+
from: hexOrZero(receipt.id || receipt.contractId),
|
1394
|
+
to: hexOrZero(receipt.toAddress || receipt.to),
|
1328
1395
|
amount: (0, import_math4.bn)(receipt.amount),
|
1329
1396
|
assetId: hexOrZero(receipt.assetId),
|
1330
1397
|
pc: (0, import_math4.bn)(receipt.pc),
|
@@ -1367,7 +1434,7 @@ function assembleReceiptByType(receipt) {
|
|
1367
1434
|
return receiptMessageOut;
|
1368
1435
|
}
|
1369
1436
|
case "MINT" /* Mint */: {
|
1370
|
-
const contractId = hexOrZero(receipt.
|
1437
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1371
1438
|
const subId = hexOrZero(receipt.subId);
|
1372
1439
|
const assetId = import_transactions3.ReceiptMintCoder.getAssetId(contractId, subId);
|
1373
1440
|
const mintReceipt = {
|
@@ -1382,7 +1449,7 @@ function assembleReceiptByType(receipt) {
|
|
1382
1449
|
return mintReceipt;
|
1383
1450
|
}
|
1384
1451
|
case "BURN" /* Burn */: {
|
1385
|
-
const contractId = hexOrZero(receipt.
|
1452
|
+
const contractId = hexOrZero(receipt.id || receipt.contractId);
|
1386
1453
|
const subId = hexOrZero(receipt.subId);
|
1387
1454
|
const assetId = import_transactions3.ReceiptBurnCoder.getAssetId(contractId, subId);
|
1388
1455
|
const burnReceipt = {
|
@@ -1408,7 +1475,6 @@ var import_errors6 = require("@fuel-ts/errors");
|
|
1408
1475
|
var import_math5 = require("@fuel-ts/math");
|
1409
1476
|
var import_transactions4 = require("@fuel-ts/transactions");
|
1410
1477
|
var import_utils6 = require("@fuel-ts/utils");
|
1411
|
-
var calculatePriceWithFactor = (gas, gasPrice, priceFactor) => (0, import_math5.bn)(Math.ceil(gas.mul(gasPrice).toNumber() / priceFactor.toNumber()));
|
1412
1478
|
var getGasUsedFromReceipts = (receipts) => {
|
1413
1479
|
const scriptResult = receipts.filter(
|
1414
1480
|
(receipt) => receipt.type === import_transactions4.ReceiptType.ScriptResult
|
@@ -1429,18 +1495,28 @@ function resolveGasDependentCosts(byteSize, gasDependentCost) {
|
|
1429
1495
|
}
|
1430
1496
|
function gasUsedByInputs(inputs, txBytesSize, gasCosts) {
|
1431
1497
|
const witnessCache = [];
|
1432
|
-
const
|
1498
|
+
const chargeableInputs = inputs.filter((input) => {
|
1499
|
+
const isCoinOrMessage = "owner" in input || "sender" in input;
|
1500
|
+
if (isCoinOrMessage) {
|
1501
|
+
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1502
|
+
return true;
|
1503
|
+
}
|
1504
|
+
if (!witnessCache.includes(input.witnessIndex)) {
|
1505
|
+
witnessCache.push(input.witnessIndex);
|
1506
|
+
return true;
|
1507
|
+
}
|
1508
|
+
}
|
1509
|
+
return false;
|
1510
|
+
});
|
1511
|
+
const vmInitializationCost = resolveGasDependentCosts(txBytesSize, gasCosts.vmInitialization);
|
1512
|
+
const totalGas = chargeableInputs.reduce((total, input) => {
|
1433
1513
|
if ("predicate" in input && input.predicate && input.predicate !== "0x") {
|
1434
1514
|
return total.add(
|
1435
|
-
|
1515
|
+
vmInitializationCost.add(resolveGasDependentCosts((0, import_utils6.arrayify)(input.predicate).length, gasCosts.contractRoot)).add((0, import_math5.bn)(input.predicateGasUsed))
|
1436
1516
|
);
|
1437
1517
|
}
|
1438
|
-
|
1439
|
-
|
1440
|
-
return total.add(gasCosts.ecr1);
|
1441
|
-
}
|
1442
|
-
return total;
|
1443
|
-
}, (0, import_math5.bn)());
|
1518
|
+
return total.add(gasCosts.ecr1);
|
1519
|
+
}, (0, import_math5.bn)(0));
|
1444
1520
|
return totalGas;
|
1445
1521
|
}
|
1446
1522
|
function getMinGas(params) {
|
@@ -1452,12 +1528,20 @@ function getMinGas(params) {
|
|
1452
1528
|
return minGas;
|
1453
1529
|
}
|
1454
1530
|
function getMaxGas(params) {
|
1455
|
-
const {
|
1531
|
+
const {
|
1532
|
+
gasPerByte,
|
1533
|
+
witnessesLength,
|
1534
|
+
witnessLimit,
|
1535
|
+
minGas,
|
1536
|
+
gasLimit = (0, import_math5.bn)(0),
|
1537
|
+
maxGasPerTx
|
1538
|
+
} = params;
|
1456
1539
|
let remainingAllowedWitnessGas = (0, import_math5.bn)(0);
|
1457
1540
|
if (witnessLimit?.gt(0) && witnessLimit.gte(witnessesLength)) {
|
1458
1541
|
remainingAllowedWitnessGas = (0, import_math5.bn)(witnessLimit).sub(witnessesLength).mul(gasPerByte);
|
1459
1542
|
}
|
1460
|
-
|
1543
|
+
const maxGas = remainingAllowedWitnessGas.add(minGas).add(gasLimit);
|
1544
|
+
return maxGas.gte(maxGasPerTx) ? maxGasPerTx : maxGas;
|
1461
1545
|
}
|
1462
1546
|
function calculateMetadataGasForTxCreate({
|
1463
1547
|
gasCosts,
|
@@ -1479,6 +1563,10 @@ function calculateMetadataGasForTxScript({
|
|
1479
1563
|
}) {
|
1480
1564
|
return resolveGasDependentCosts(txBytesSize, gasCosts.s256);
|
1481
1565
|
}
|
1566
|
+
var calculateGasFee = (params) => {
|
1567
|
+
const { gas, gasPrice, priceFactor, tip } = params;
|
1568
|
+
return gas.mul(gasPrice).div(priceFactor).add(tip);
|
1569
|
+
};
|
1482
1570
|
|
1483
1571
|
// src/providers/utils/json.ts
|
1484
1572
|
var import_utils7 = require("@fuel-ts/utils");
|
@@ -1615,7 +1703,7 @@ var witnessify = (value) => {
|
|
1615
1703
|
// src/providers/transaction-request/transaction-request.ts
|
1616
1704
|
var BaseTransactionRequest = class {
|
1617
1705
|
/** Gas price for transaction */
|
1618
|
-
|
1706
|
+
tip;
|
1619
1707
|
/** Block until which tx cannot be included */
|
1620
1708
|
maturity;
|
1621
1709
|
/** The maximum fee payable by this transaction using BASE_ASSET. */
|
@@ -1634,7 +1722,7 @@ var BaseTransactionRequest = class {
|
|
1634
1722
|
* @param baseTransactionRequest - Optional object containing properties to initialize the transaction request.
|
1635
1723
|
*/
|
1636
1724
|
constructor({
|
1637
|
-
|
1725
|
+
tip,
|
1638
1726
|
maturity,
|
1639
1727
|
maxFee,
|
1640
1728
|
witnessLimit,
|
@@ -1642,7 +1730,7 @@ var BaseTransactionRequest = class {
|
|
1642
1730
|
outputs,
|
1643
1731
|
witnesses
|
1644
1732
|
} = {}) {
|
1645
|
-
this.
|
1733
|
+
this.tip = (0, import_math7.bn)(tip);
|
1646
1734
|
this.maturity = maturity ?? 0;
|
1647
1735
|
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1648
1736
|
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
@@ -1653,9 +1741,9 @@ var BaseTransactionRequest = class {
|
|
1653
1741
|
static getPolicyMeta(req) {
|
1654
1742
|
let policyTypes = 0;
|
1655
1743
|
const policies = [];
|
1656
|
-
if (req.
|
1657
|
-
policyTypes += import_transactions6.PolicyType.
|
1658
|
-
policies.push({ data: req.
|
1744
|
+
if (req.tip) {
|
1745
|
+
policyTypes += import_transactions6.PolicyType.Tip;
|
1746
|
+
policies.push({ data: req.tip, type: import_transactions6.PolicyType.Tip });
|
1659
1747
|
}
|
1660
1748
|
if (req.witnessLimit) {
|
1661
1749
|
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
@@ -1842,10 +1930,10 @@ var BaseTransactionRequest = class {
|
|
1842
1930
|
* @param predicate - Predicate bytes.
|
1843
1931
|
* @param predicateData - Predicate data bytes.
|
1844
1932
|
*/
|
1845
|
-
addCoinInput(coin
|
1933
|
+
addCoinInput(coin) {
|
1846
1934
|
const { assetId, owner, amount } = coin;
|
1847
1935
|
let witnessIndex;
|
1848
|
-
if (predicate) {
|
1936
|
+
if (coin.predicate) {
|
1849
1937
|
witnessIndex = 0;
|
1850
1938
|
} else {
|
1851
1939
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
@@ -1860,8 +1948,7 @@ var BaseTransactionRequest = class {
|
|
1860
1948
|
amount,
|
1861
1949
|
assetId,
|
1862
1950
|
txPointer: "0x00000000000000000000000000000000",
|
1863
|
-
witnessIndex
|
1864
|
-
predicate: predicate?.bytes
|
1951
|
+
witnessIndex
|
1865
1952
|
};
|
1866
1953
|
this.pushInput(input);
|
1867
1954
|
this.addChangeOutput(owner, assetId);
|
@@ -1874,11 +1961,11 @@ var BaseTransactionRequest = class {
|
|
1874
1961
|
* @param predicate - Predicate bytes.
|
1875
1962
|
* @param predicateData - Predicate data bytes.
|
1876
1963
|
*/
|
1877
|
-
addMessageInput(message
|
1964
|
+
addMessageInput(message) {
|
1878
1965
|
const { recipient, sender, amount } = message;
|
1879
1966
|
const assetId = import_configs7.BaseAssetId;
|
1880
1967
|
let witnessIndex;
|
1881
|
-
if (predicate) {
|
1968
|
+
if (message.predicate) {
|
1882
1969
|
witnessIndex = 0;
|
1883
1970
|
} else {
|
1884
1971
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
@@ -1892,8 +1979,7 @@ var BaseTransactionRequest = class {
|
|
1892
1979
|
sender: sender.toB256(),
|
1893
1980
|
recipient: recipient.toB256(),
|
1894
1981
|
amount,
|
1895
|
-
witnessIndex
|
1896
|
-
predicate: predicate?.bytes
|
1982
|
+
witnessIndex
|
1897
1983
|
};
|
1898
1984
|
this.pushInput(input);
|
1899
1985
|
this.addChangeOutput(recipient, assetId);
|
@@ -1924,32 +2010,6 @@ var BaseTransactionRequest = class {
|
|
1924
2010
|
resources.forEach((resource) => this.addResource(resource));
|
1925
2011
|
return this;
|
1926
2012
|
}
|
1927
|
-
/**
|
1928
|
-
* Adds multiple resources to the transaction by adding coin/message inputs and change
|
1929
|
-
* outputs from the related assetIds.
|
1930
|
-
*
|
1931
|
-
* @param resources - The resources to add.
|
1932
|
-
* @returns This transaction.
|
1933
|
-
*/
|
1934
|
-
addPredicateResource(resource, predicate) {
|
1935
|
-
if (isCoin(resource)) {
|
1936
|
-
this.addCoinInput(resource, predicate);
|
1937
|
-
} else {
|
1938
|
-
this.addMessageInput(resource, predicate);
|
1939
|
-
}
|
1940
|
-
return this;
|
1941
|
-
}
|
1942
|
-
/**
|
1943
|
-
* Adds multiple predicate coin/message inputs to the transaction and change outputs
|
1944
|
-
* from the related assetIds.
|
1945
|
-
*
|
1946
|
-
* @param resources - The resources to add.
|
1947
|
-
* @returns This transaction.
|
1948
|
-
*/
|
1949
|
-
addPredicateResources(resources, predicate) {
|
1950
|
-
resources.forEach((resource) => this.addPredicateResource(resource, predicate));
|
1951
|
-
return this;
|
1952
|
-
}
|
1953
2013
|
/**
|
1954
2014
|
* Adds a coin output to the transaction.
|
1955
2015
|
*
|
@@ -2029,7 +2089,7 @@ var BaseTransactionRequest = class {
|
|
2029
2089
|
}
|
2030
2090
|
calculateMaxGas(chainInfo, minGas) {
|
2031
2091
|
const { consensusParameters } = chainInfo;
|
2032
|
-
const { gasPerByte } = consensusParameters;
|
2092
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2033
2093
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2034
2094
|
(acc, wit) => acc + wit.dataLength,
|
2035
2095
|
0
|
@@ -2038,7 +2098,8 @@ var BaseTransactionRequest = class {
|
|
2038
2098
|
gasPerByte,
|
2039
2099
|
minGas,
|
2040
2100
|
witnessesLength,
|
2041
|
-
witnessLimit: this.witnessLimit
|
2101
|
+
witnessLimit: this.witnessLimit,
|
2102
|
+
maxGasPerTx
|
2042
2103
|
});
|
2043
2104
|
}
|
2044
2105
|
/**
|
@@ -2056,17 +2117,20 @@ var BaseTransactionRequest = class {
|
|
2056
2117
|
});
|
2057
2118
|
const updateAssetInput = (assetId, quantity) => {
|
2058
2119
|
const assetInput = findAssetInput(assetId);
|
2120
|
+
let usedQuantity = quantity;
|
2121
|
+
if (assetId === import_configs7.BaseAssetId) {
|
2122
|
+
usedQuantity = (0, import_math7.bn)("1000000000000000000");
|
2123
|
+
}
|
2059
2124
|
if (assetInput && "assetId" in assetInput) {
|
2060
2125
|
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
2061
|
-
assetInput.amount =
|
2126
|
+
assetInput.amount = usedQuantity;
|
2062
2127
|
} else {
|
2063
2128
|
this.addResources([
|
2064
2129
|
{
|
2065
2130
|
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
2066
|
-
amount:
|
2131
|
+
amount: usedQuantity,
|
2067
2132
|
assetId,
|
2068
2133
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2069
|
-
maturity: 0,
|
2070
2134
|
blockCreated: (0, import_math7.bn)(1),
|
2071
2135
|
txCreatedIdx: (0, import_math7.bn)(1)
|
2072
2136
|
}
|
@@ -2098,7 +2162,7 @@ var BaseTransactionRequest = class {
|
|
2098
2162
|
toJSON() {
|
2099
2163
|
return normalizeJSON(this);
|
2100
2164
|
}
|
2101
|
-
|
2165
|
+
updatePredicateGasUsed(inputs) {
|
2102
2166
|
this.inputs.forEach((i) => {
|
2103
2167
|
let correspondingInput;
|
2104
2168
|
switch (i.type) {
|
@@ -2120,6 +2184,15 @@ var BaseTransactionRequest = class {
|
|
2120
2184
|
}
|
2121
2185
|
});
|
2122
2186
|
}
|
2187
|
+
shiftPredicateData() {
|
2188
|
+
this.inputs.forEach((input) => {
|
2189
|
+
if ("predicateData" in input && "paddPredicateData" in input && typeof input.paddPredicateData === "function") {
|
2190
|
+
input.predicateData = input.paddPredicateData(
|
2191
|
+
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2192
|
+
);
|
2193
|
+
}
|
2194
|
+
});
|
2195
|
+
}
|
2123
2196
|
};
|
2124
2197
|
|
2125
2198
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2266,9 +2339,8 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2266
2339
|
return {
|
2267
2340
|
type: import_transactions8.TransactionType.Create,
|
2268
2341
|
...baseTransaction,
|
2269
|
-
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2270
2342
|
bytecodeWitnessIndex,
|
2271
|
-
storageSlotsCount: storageSlots.length,
|
2343
|
+
storageSlotsCount: (0, import_math9.bn)(storageSlots.length),
|
2272
2344
|
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2273
2345
|
storageSlots
|
2274
2346
|
};
|
@@ -2391,8 +2463,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2391
2463
|
type: import_transactions9.TransactionType.Script,
|
2392
2464
|
scriptGasLimit: this.gasLimit,
|
2393
2465
|
...super.getBaseTransaction(),
|
2394
|
-
scriptLength: script.length,
|
2395
|
-
scriptDataLength: scriptData.length,
|
2466
|
+
scriptLength: (0, import_math10.bn)(script.length),
|
2467
|
+
scriptDataLength: (0, import_math10.bn)(scriptData.length),
|
2396
2468
|
receiptsRoot: import_configs10.ZeroBytes32,
|
2397
2469
|
script: (0, import_utils15.hexlify)(script),
|
2398
2470
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
@@ -2456,7 +2528,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2456
2528
|
}
|
2457
2529
|
calculateMaxGas(chainInfo, minGas) {
|
2458
2530
|
const { consensusParameters } = chainInfo;
|
2459
|
-
const { gasPerByte } = consensusParameters;
|
2531
|
+
const { gasPerByte, maxGasPerTx } = consensusParameters;
|
2460
2532
|
const witnessesLength = this.toTransaction().witnesses.reduce(
|
2461
2533
|
(acc, wit) => acc + wit.dataLength,
|
2462
2534
|
0
|
@@ -2466,7 +2538,8 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2466
2538
|
minGas,
|
2467
2539
|
witnessesLength,
|
2468
2540
|
witnessLimit: this.witnessLimit,
|
2469
|
-
gasLimit: this.gasLimit
|
2541
|
+
gasLimit: this.gasLimit,
|
2542
|
+
maxGasPerTx
|
2470
2543
|
});
|
2471
2544
|
}
|
2472
2545
|
/**
|
@@ -2541,15 +2614,32 @@ var transactionRequestify = (obj) => {
|
|
2541
2614
|
}
|
2542
2615
|
}
|
2543
2616
|
};
|
2617
|
+
var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
|
2618
|
+
(acc, input) => {
|
2619
|
+
if (input.type === import_transactions10.InputType.Coin && input.owner === owner) {
|
2620
|
+
acc.utxos.push(input.id);
|
2621
|
+
}
|
2622
|
+
if (input.type === import_transactions10.InputType.Message && input.recipient === owner) {
|
2623
|
+
acc.messages.push(input.nonce);
|
2624
|
+
}
|
2625
|
+
return acc;
|
2626
|
+
},
|
2627
|
+
{
|
2628
|
+
utxos: [],
|
2629
|
+
messages: []
|
2630
|
+
}
|
2631
|
+
);
|
2544
2632
|
|
2545
2633
|
// src/providers/transaction-response/transaction-response.ts
|
2546
2634
|
var import_errors13 = require("@fuel-ts/errors");
|
2547
|
-
var
|
2548
|
-
var
|
2549
|
-
var
|
2635
|
+
var import_math15 = require("@fuel-ts/math");
|
2636
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
2637
|
+
var import_utils20 = require("@fuel-ts/utils");
|
2550
2638
|
|
2551
2639
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2552
|
-
var
|
2640
|
+
var import_math14 = require("@fuel-ts/math");
|
2641
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2642
|
+
var import_utils18 = require("@fuel-ts/utils");
|
2553
2643
|
|
2554
2644
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2555
2645
|
var import_math11 = require("@fuel-ts/math");
|
@@ -2557,9 +2647,10 @@ var import_transactions11 = require("@fuel-ts/transactions");
|
|
2557
2647
|
var import_utils16 = require("@fuel-ts/utils");
|
2558
2648
|
var calculateTransactionFee = (params) => {
|
2559
2649
|
const {
|
2560
|
-
|
2650
|
+
gasPrice,
|
2561
2651
|
rawPayload,
|
2562
|
-
|
2652
|
+
tip,
|
2653
|
+
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
2563
2654
|
} = params;
|
2564
2655
|
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2565
2656
|
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
@@ -2569,8 +2660,7 @@ var calculateTransactionFee = (params) => {
|
|
2569
2660
|
return {
|
2570
2661
|
fee: (0, import_math11.bn)(0),
|
2571
2662
|
minFee: (0, import_math11.bn)(0),
|
2572
|
-
maxFee: (0, import_math11.bn)(0)
|
2573
|
-
feeFromGasUsed: (0, import_math11.bn)(0)
|
2663
|
+
maxFee: (0, import_math11.bn)(0)
|
2574
2664
|
};
|
2575
2665
|
}
|
2576
2666
|
const { type, witnesses, inputs, policies } = transaction;
|
@@ -2602,7 +2692,6 @@ var calculateTransactionFee = (params) => {
|
|
2602
2692
|
metadataGas,
|
2603
2693
|
txBytesSize: transactionBytes.length
|
2604
2694
|
});
|
2605
|
-
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2606
2695
|
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2607
2696
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2608
2697
|
const maxGas = getMaxGas({
|
@@ -2610,17 +2699,25 @@ var calculateTransactionFee = (params) => {
|
|
2610
2699
|
minGas,
|
2611
2700
|
witnessesLength,
|
2612
2701
|
gasLimit,
|
2613
|
-
witnessLimit
|
2702
|
+
witnessLimit,
|
2703
|
+
maxGasPerTx
|
2704
|
+
});
|
2705
|
+
const minFee = calculateGasFee({
|
2706
|
+
gasPrice,
|
2707
|
+
gas: minGas,
|
2708
|
+
priceFactor: gasPriceFactor,
|
2709
|
+
tip
|
2710
|
+
});
|
2711
|
+
const maxFee = calculateGasFee({
|
2712
|
+
gasPrice,
|
2713
|
+
gas: maxGas,
|
2714
|
+
priceFactor: gasPriceFactor,
|
2715
|
+
tip
|
2614
2716
|
});
|
2615
|
-
const feeFromGasUsed = calculatePriceWithFactor(gasUsed, gasPrice, gasPriceFactor);
|
2616
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor);
|
2617
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor);
|
2618
|
-
const fee = minFee.add(feeFromGasUsed);
|
2619
2717
|
return {
|
2620
|
-
fee,
|
2621
2718
|
minFee,
|
2622
2719
|
maxFee,
|
2623
|
-
|
2720
|
+
fee: maxFee
|
2624
2721
|
};
|
2625
2722
|
};
|
2626
2723
|
|
@@ -3187,10 +3284,12 @@ function assembleTransactionSummary(params) {
|
|
3187
3284
|
gqlTransactionStatus,
|
3188
3285
|
abiMap = {},
|
3189
3286
|
maxInputs,
|
3190
|
-
gasCosts
|
3287
|
+
gasCosts,
|
3288
|
+
maxGasPerTx,
|
3289
|
+
gasPrice
|
3191
3290
|
} = params;
|
3192
3291
|
const gasUsed = getGasUsedFromReceipts(receipts);
|
3193
|
-
const rawPayload = (0,
|
3292
|
+
const rawPayload = (0, import_utils18.hexlify)(transactionBytes);
|
3194
3293
|
const operations = getOperations({
|
3195
3294
|
transactionType: transaction.type,
|
3196
3295
|
inputs: transaction.inputs || [],
|
@@ -3201,11 +3300,14 @@ function assembleTransactionSummary(params) {
|
|
3201
3300
|
maxInputs
|
3202
3301
|
});
|
3203
3302
|
const typeName = getTransactionTypeName(transaction.type);
|
3303
|
+
const tip = (0, import_math14.bn)(transaction.policies?.find((policy) => policy.type === import_transactions16.PolicyType.Tip)?.data);
|
3204
3304
|
const { fee } = calculateTransactionFee({
|
3205
|
-
|
3305
|
+
gasPrice,
|
3206
3306
|
rawPayload,
|
3307
|
+
tip,
|
3207
3308
|
consensusParameters: {
|
3208
3309
|
gasCosts,
|
3310
|
+
maxGasPerTx,
|
3209
3311
|
feeParams: {
|
3210
3312
|
gasPerByte,
|
3211
3313
|
gasPriceFactor
|
@@ -3217,7 +3319,7 @@ function assembleTransactionSummary(params) {
|
|
3217
3319
|
const burnedAssets = extractBurnedAssetsFromReceipts(receipts);
|
3218
3320
|
let date;
|
3219
3321
|
if (time) {
|
3220
|
-
date =
|
3322
|
+
date = import_utils18.DateTime.fromTai64(time);
|
3221
3323
|
}
|
3222
3324
|
const transactionSummary = {
|
3223
3325
|
id,
|
@@ -3245,12 +3347,12 @@ function assembleTransactionSummary(params) {
|
|
3245
3347
|
|
3246
3348
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3247
3349
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3248
|
-
var
|
3350
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
3249
3351
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3250
3352
|
return receipts.reduce((logs, receipt) => {
|
3251
|
-
if (receipt.type ===
|
3353
|
+
if (receipt.type === import_transactions17.ReceiptType.LogData || receipt.type === import_transactions17.ReceiptType.Log) {
|
3252
3354
|
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3253
|
-
const data = receipt.type ===
|
3355
|
+
const data = receipt.type === import_transactions17.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3254
3356
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3255
3357
|
logs.push(decodedLog);
|
3256
3358
|
}
|
@@ -3265,7 +3367,7 @@ var TransactionResponse = class {
|
|
3265
3367
|
/** Current provider */
|
3266
3368
|
provider;
|
3267
3369
|
/** Gas used on the transaction */
|
3268
|
-
gasUsed = (0,
|
3370
|
+
gasUsed = (0, import_math15.bn)(0);
|
3269
3371
|
/** The graphql Transaction with receipts object. */
|
3270
3372
|
gqlTransaction;
|
3271
3373
|
abis;
|
@@ -3323,8 +3425,8 @@ var TransactionResponse = class {
|
|
3323
3425
|
* @returns The decoded transaction.
|
3324
3426
|
*/
|
3325
3427
|
decodeTransaction(transactionWithReceipts) {
|
3326
|
-
return new
|
3327
|
-
(0,
|
3428
|
+
return new import_transactions18.TransactionCoder().decode(
|
3429
|
+
(0, import_utils20.arrayify)(transactionWithReceipts.rawPayload),
|
3328
3430
|
0
|
3329
3431
|
)?.[0];
|
3330
3432
|
}
|
@@ -3343,20 +3445,27 @@ var TransactionResponse = class {
|
|
3343
3445
|
const decodedTransaction = this.decodeTransaction(
|
3344
3446
|
transaction
|
3345
3447
|
);
|
3346
|
-
|
3347
|
-
|
3448
|
+
let txReceipts = [];
|
3449
|
+
if (transaction?.status && "receipts" in transaction.status) {
|
3450
|
+
txReceipts = transaction.status.receipts;
|
3451
|
+
}
|
3452
|
+
const receipts = txReceipts.map(processGqlReceipt) || [];
|
3453
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
3454
|
+
const gasPrice = await this.provider.getLatestGasPrice();
|
3348
3455
|
const maxInputs = this.provider.getChain().consensusParameters.maxInputs;
|
3349
3456
|
const transactionSummary = assembleTransactionSummary({
|
3350
3457
|
id: this.id,
|
3351
3458
|
receipts,
|
3352
3459
|
transaction: decodedTransaction,
|
3353
|
-
transactionBytes: (0,
|
3460
|
+
transactionBytes: (0, import_utils20.arrayify)(transaction.rawPayload),
|
3354
3461
|
gqlTransactionStatus: transaction.status,
|
3355
3462
|
gasPerByte,
|
3356
3463
|
gasPriceFactor,
|
3357
3464
|
abiMap: contractsAbiMap,
|
3358
3465
|
maxInputs,
|
3359
|
-
gasCosts
|
3466
|
+
gasCosts,
|
3467
|
+
maxGasPerTx,
|
3468
|
+
gasPrice
|
3360
3469
|
});
|
3361
3470
|
return transactionSummary;
|
3362
3471
|
}
|
@@ -3483,29 +3592,29 @@ var processGqlChain = (chain) => {
|
|
3483
3592
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3484
3593
|
return {
|
3485
3594
|
name,
|
3486
|
-
baseChainHeight: (0,
|
3595
|
+
baseChainHeight: (0, import_math16.bn)(daHeight),
|
3487
3596
|
consensusParameters: {
|
3488
|
-
contractMaxSize: (0,
|
3489
|
-
maxInputs: (0,
|
3490
|
-
maxOutputs: (0,
|
3491
|
-
maxWitnesses: (0,
|
3492
|
-
maxGasPerTx: (0,
|
3493
|
-
maxScriptLength: (0,
|
3494
|
-
maxScriptDataLength: (0,
|
3495
|
-
maxStorageSlots: (0,
|
3496
|
-
maxPredicateLength: (0,
|
3497
|
-
maxPredicateDataLength: (0,
|
3498
|
-
maxGasPerPredicate: (0,
|
3499
|
-
gasPriceFactor: (0,
|
3500
|
-
gasPerByte: (0,
|
3501
|
-
maxMessageDataLength: (0,
|
3502
|
-
chainId: (0,
|
3597
|
+
contractMaxSize: (0, import_math16.bn)(contractParams.contractMaxSize),
|
3598
|
+
maxInputs: (0, import_math16.bn)(txParams.maxInputs),
|
3599
|
+
maxOutputs: (0, import_math16.bn)(txParams.maxOutputs),
|
3600
|
+
maxWitnesses: (0, import_math16.bn)(txParams.maxWitnesses),
|
3601
|
+
maxGasPerTx: (0, import_math16.bn)(txParams.maxGasPerTx),
|
3602
|
+
maxScriptLength: (0, import_math16.bn)(scriptParams.maxScriptLength),
|
3603
|
+
maxScriptDataLength: (0, import_math16.bn)(scriptParams.maxScriptDataLength),
|
3604
|
+
maxStorageSlots: (0, import_math16.bn)(contractParams.maxStorageSlots),
|
3605
|
+
maxPredicateLength: (0, import_math16.bn)(predicateParams.maxPredicateLength),
|
3606
|
+
maxPredicateDataLength: (0, import_math16.bn)(predicateParams.maxPredicateDataLength),
|
3607
|
+
maxGasPerPredicate: (0, import_math16.bn)(predicateParams.maxGasPerPredicate),
|
3608
|
+
gasPriceFactor: (0, import_math16.bn)(feeParams.gasPriceFactor),
|
3609
|
+
gasPerByte: (0, import_math16.bn)(feeParams.gasPerByte),
|
3610
|
+
maxMessageDataLength: (0, import_math16.bn)(predicateParams.maxMessageDataLength),
|
3611
|
+
chainId: (0, import_math16.bn)(consensusParameters.chainId),
|
3503
3612
|
gasCosts
|
3504
3613
|
},
|
3505
3614
|
gasCosts,
|
3506
3615
|
latestBlock: {
|
3507
3616
|
id: latestBlock.id,
|
3508
|
-
height: (0,
|
3617
|
+
height: (0, import_math16.bn)(latestBlock.height),
|
3509
3618
|
time: latestBlock.header.time,
|
3510
3619
|
transactions: latestBlock.transactions.map((i) => ({
|
3511
3620
|
id: i.id
|
@@ -3599,10 +3708,8 @@ var _Provider = class {
|
|
3599
3708
|
* Returns some helpful parameters related to gas fees.
|
3600
3709
|
*/
|
3601
3710
|
getGasConfig() {
|
3602
|
-
const { minGasPrice } = this.getNode();
|
3603
3711
|
const { maxGasPerTx, maxGasPerPredicate, gasPriceFactor, gasPerByte, gasCosts } = this.getChain().consensusParameters;
|
3604
3712
|
return {
|
3605
|
-
minGasPrice,
|
3606
3713
|
maxGasPerTx,
|
3607
3714
|
maxGasPerPredicate,
|
3608
3715
|
gasPriceFactor,
|
@@ -3700,7 +3807,7 @@ var _Provider = class {
|
|
3700
3807
|
*/
|
3701
3808
|
async getBlockNumber() {
|
3702
3809
|
const { chain } = await this.operations.getChain();
|
3703
|
-
return (0,
|
3810
|
+
return (0, import_math16.bn)(chain.latestBlock.height, 10);
|
3704
3811
|
}
|
3705
3812
|
/**
|
3706
3813
|
* Returns the chain information.
|
@@ -3710,13 +3817,11 @@ var _Provider = class {
|
|
3710
3817
|
async fetchNode() {
|
3711
3818
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3712
3819
|
const processedNodeInfo = {
|
3713
|
-
maxDepth: (0,
|
3714
|
-
maxTx: (0,
|
3715
|
-
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3820
|
+
maxDepth: (0, import_math16.bn)(nodeInfo.maxDepth),
|
3821
|
+
maxTx: (0, import_math16.bn)(nodeInfo.maxTx),
|
3716
3822
|
nodeVersion: nodeInfo.nodeVersion,
|
3717
3823
|
utxoValidation: nodeInfo.utxoValidation,
|
3718
|
-
vmBacktrace: nodeInfo.vmBacktrace
|
3719
|
-
peers: nodeInfo.peers
|
3824
|
+
vmBacktrace: nodeInfo.vmBacktrace
|
3720
3825
|
};
|
3721
3826
|
_Provider.nodeInfoCache[this.url] = processedNodeInfo;
|
3722
3827
|
return processedNodeInfo;
|
@@ -3758,9 +3863,9 @@ var _Provider = class {
|
|
3758
3863
|
if (estimateTxDependencies) {
|
3759
3864
|
await this.estimateTxDependencies(transactionRequest);
|
3760
3865
|
}
|
3761
|
-
const encodedTransaction = (0,
|
3866
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3762
3867
|
let abis;
|
3763
|
-
if (transactionRequest.type ===
|
3868
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
3764
3869
|
abis = transactionRequest.abis;
|
3765
3870
|
}
|
3766
3871
|
if (awaitExecution) {
|
@@ -3801,15 +3906,14 @@ var _Provider = class {
|
|
3801
3906
|
if (estimateTxDependencies) {
|
3802
3907
|
return this.estimateTxDependencies(transactionRequest);
|
3803
3908
|
}
|
3804
|
-
const encodedTransaction = (0,
|
3805
|
-
const { dryRun:
|
3806
|
-
encodedTransaction,
|
3909
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3910
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
3911
|
+
encodedTransactions: encodedTransaction,
|
3807
3912
|
utxoValidation: utxoValidation || false
|
3808
3913
|
});
|
3809
|
-
const receipts =
|
3810
|
-
|
3811
|
-
|
3812
|
-
};
|
3914
|
+
const [{ receipts: rawReceipts, status }] = dryRunStatuses;
|
3915
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
3916
|
+
return { receipts, dryrunStatus: status };
|
3813
3917
|
}
|
3814
3918
|
/**
|
3815
3919
|
* Verifies whether enough gas is available to complete transaction.
|
@@ -3820,13 +3924,13 @@ var _Provider = class {
|
|
3820
3924
|
async estimatePredicates(transactionRequest) {
|
3821
3925
|
const shouldEstimatePredicates = Boolean(
|
3822
3926
|
transactionRequest.inputs.find(
|
3823
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3927
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math16.BN(input.predicateGasUsed).isZero()
|
3824
3928
|
)
|
3825
3929
|
);
|
3826
3930
|
if (!shouldEstimatePredicates) {
|
3827
3931
|
return transactionRequest;
|
3828
3932
|
}
|
3829
|
-
const encodedTransaction = (0,
|
3933
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
3830
3934
|
const response = await this.operations.estimatePredicates({
|
3831
3935
|
encodedTransaction
|
3832
3936
|
});
|
@@ -3835,7 +3939,7 @@ var _Provider = class {
|
|
3835
3939
|
} = response;
|
3836
3940
|
if (inputs) {
|
3837
3941
|
inputs.forEach((input, index) => {
|
3838
|
-
if ("predicateGasUsed" in input && (0,
|
3942
|
+
if ("predicateGasUsed" in input && (0, import_math16.bn)(input.predicateGasUsed).gt(0)) {
|
3839
3943
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3840
3944
|
}
|
3841
3945
|
});
|
@@ -3848,31 +3952,31 @@ var _Provider = class {
|
|
3848
3952
|
* If there are missing variable outputs,
|
3849
3953
|
* `addVariableOutputs` is called on the transaction.
|
3850
3954
|
*
|
3851
|
-
* @privateRemarks
|
3852
|
-
* TODO: Investigate support for missing contract IDs
|
3853
|
-
* TODO: Add support for missing output messages
|
3854
3955
|
*
|
3855
3956
|
* @param transactionRequest - The transaction request object.
|
3856
3957
|
* @returns A promise.
|
3857
3958
|
*/
|
3858
3959
|
async estimateTxDependencies(transactionRequest) {
|
3859
|
-
if (transactionRequest.type ===
|
3960
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Create) {
|
3860
3961
|
return {
|
3861
3962
|
receipts: [],
|
3862
3963
|
outputVariables: 0,
|
3863
3964
|
missingContractIds: []
|
3864
3965
|
};
|
3865
3966
|
}
|
3866
|
-
await this.estimatePredicates(transactionRequest);
|
3867
3967
|
let receipts = [];
|
3868
3968
|
const missingContractIds = [];
|
3869
3969
|
let outputVariables = 0;
|
3970
|
+
let dryrunStatus;
|
3870
3971
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3871
|
-
const {
|
3872
|
-
|
3972
|
+
const {
|
3973
|
+
dryRun: [{ receipts: rawReceipts, status }]
|
3974
|
+
} = await this.operations.dryRun({
|
3975
|
+
encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
|
3873
3976
|
utxoValidation: false
|
3874
3977
|
});
|
3875
|
-
receipts =
|
3978
|
+
receipts = rawReceipts.map(processGqlReceipt);
|
3979
|
+
dryrunStatus = status;
|
3876
3980
|
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(receipts);
|
3877
3981
|
const hasMissingOutputs = missingOutputVariables.length !== 0 || missingOutputContractIds.length !== 0;
|
3878
3982
|
if (hasMissingOutputs) {
|
@@ -3882,6 +3986,10 @@ var _Provider = class {
|
|
3882
3986
|
transactionRequest.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
3883
3987
|
missingContractIds.push(contractId);
|
3884
3988
|
});
|
3989
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
3990
|
+
transactionRequest
|
3991
|
+
});
|
3992
|
+
transactionRequest.maxFee = maxFee;
|
3885
3993
|
} else {
|
3886
3994
|
break;
|
3887
3995
|
}
|
@@ -3889,37 +3997,139 @@ var _Provider = class {
|
|
3889
3997
|
return {
|
3890
3998
|
receipts,
|
3891
3999
|
outputVariables,
|
3892
|
-
missingContractIds
|
4000
|
+
missingContractIds,
|
4001
|
+
dryrunStatus
|
3893
4002
|
};
|
3894
4003
|
}
|
4004
|
+
/**
|
4005
|
+
* Dry runs multiple transactions and checks for missing dependencies in batches.
|
4006
|
+
*
|
4007
|
+
* Transactions are dry run in batches. After each dry run, transactions requiring
|
4008
|
+
* further modifications are identified. The method iteratively updates these transactions
|
4009
|
+
* and performs subsequent dry runs until all dependencies for each transaction are satisfied.
|
4010
|
+
*
|
4011
|
+
* @param transactionRequests - Array of transaction request objects.
|
4012
|
+
* @returns A promise that resolves to an array of results for each transaction.
|
4013
|
+
*/
|
4014
|
+
async estimateMultipleTxDependencies(transactionRequests) {
|
4015
|
+
const results = transactionRequests.map(() => ({
|
4016
|
+
receipts: [],
|
4017
|
+
outputVariables: 0,
|
4018
|
+
missingContractIds: [],
|
4019
|
+
dryrunStatus: void 0
|
4020
|
+
}));
|
4021
|
+
const allRequests = (0, import_ramda3.clone)(transactionRequests);
|
4022
|
+
const serializedTransactionsMap = /* @__PURE__ */ new Map();
|
4023
|
+
allRequests.forEach((req, index) => {
|
4024
|
+
if (req.type === import_transactions19.TransactionType.Script) {
|
4025
|
+
serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
|
4026
|
+
}
|
4027
|
+
});
|
4028
|
+
let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
|
4029
|
+
let attempt = 0;
|
4030
|
+
while (transactionsToProcess.length > 0 && attempt < MAX_RETRIES) {
|
4031
|
+
const encodedTransactions = transactionsToProcess.map(
|
4032
|
+
(index) => serializedTransactionsMap.get(index)
|
4033
|
+
);
|
4034
|
+
const dryRunResults = await this.operations.dryRun({
|
4035
|
+
encodedTransactions,
|
4036
|
+
utxoValidation: false
|
4037
|
+
});
|
4038
|
+
const nextRoundTransactions = [];
|
4039
|
+
for (let i = 0; i < dryRunResults.dryRun.length; i++) {
|
4040
|
+
const currentResultIndex = transactionsToProcess[i];
|
4041
|
+
const { receipts: rawReceipts, status } = dryRunResults.dryRun[i];
|
4042
|
+
results[currentResultIndex].receipts = rawReceipts.map(processGqlReceipt);
|
4043
|
+
results[currentResultIndex].dryrunStatus = status;
|
4044
|
+
const { missingOutputVariables, missingOutputContractIds } = getReceiptsWithMissingData(
|
4045
|
+
results[currentResultIndex].receipts
|
4046
|
+
);
|
4047
|
+
const hasMissingOutputs = missingOutputVariables.length > 0 || missingOutputContractIds.length > 0;
|
4048
|
+
const requestToProcess = allRequests[currentResultIndex];
|
4049
|
+
if (hasMissingOutputs && requestToProcess?.type === import_transactions19.TransactionType.Script) {
|
4050
|
+
results[currentResultIndex].outputVariables += missingOutputVariables.length;
|
4051
|
+
requestToProcess.addVariableOutputs(missingOutputVariables.length);
|
4052
|
+
missingOutputContractIds.forEach(({ contractId }) => {
|
4053
|
+
requestToProcess.addContractInputAndOutput(import_address3.Address.fromString(contractId));
|
4054
|
+
results[currentResultIndex].missingContractIds.push(contractId);
|
4055
|
+
});
|
4056
|
+
const { maxFee } = await this.estimateTxGasAndFee({
|
4057
|
+
transactionRequest: requestToProcess
|
4058
|
+
});
|
4059
|
+
requestToProcess.maxFee = maxFee;
|
4060
|
+
serializedTransactionsMap.set(
|
4061
|
+
currentResultIndex,
|
4062
|
+
(0, import_utils22.hexlify)(requestToProcess.toTransactionBytes())
|
4063
|
+
);
|
4064
|
+
nextRoundTransactions.push(currentResultIndex);
|
4065
|
+
allRequests[currentResultIndex] = requestToProcess;
|
4066
|
+
}
|
4067
|
+
}
|
4068
|
+
transactionsToProcess = nextRoundTransactions;
|
4069
|
+
attempt += 1;
|
4070
|
+
}
|
4071
|
+
return results;
|
4072
|
+
}
|
4073
|
+
async dryRunMultipleTransactions(transactionRequests, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4074
|
+
if (estimateTxDependencies) {
|
4075
|
+
return this.estimateMultipleTxDependencies(transactionRequests);
|
4076
|
+
}
|
4077
|
+
const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
|
4078
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4079
|
+
encodedTransactions,
|
4080
|
+
utxoValidation: utxoValidation || false
|
4081
|
+
});
|
4082
|
+
const results = dryRunStatuses.map(({ receipts: rawReceipts, status }) => {
|
4083
|
+
const receipts = rawReceipts.map(processGqlReceipt);
|
4084
|
+
return { receipts, dryrunStatus: status };
|
4085
|
+
});
|
4086
|
+
return results;
|
4087
|
+
}
|
3895
4088
|
/**
|
3896
4089
|
* Estimates the transaction gas and fee based on the provided transaction request.
|
3897
4090
|
* @param transactionRequest - The transaction request object.
|
3898
4091
|
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3899
4092
|
*/
|
3900
|
-
estimateTxGasAndFee(params) {
|
4093
|
+
async estimateTxGasAndFee(params) {
|
3901
4094
|
const { transactionRequest } = params;
|
3902
|
-
|
4095
|
+
let { gasPrice } = params;
|
3903
4096
|
const chainInfo = this.getChain();
|
3904
|
-
const
|
3905
|
-
transactionRequest.gasPrice = gasPrice;
|
4097
|
+
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
3906
4098
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3907
|
-
|
3908
|
-
|
4099
|
+
if (!gasPrice) {
|
4100
|
+
gasPrice = await this.estimateGasPrice(10);
|
4101
|
+
}
|
4102
|
+
const minFee = calculateGasFee({
|
4103
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4104
|
+
gas: minGas,
|
4105
|
+
priceFactor: gasPriceFactor,
|
4106
|
+
tip: transactionRequest.tip
|
4107
|
+
}).add(1);
|
4108
|
+
let gasLimit = (0, import_math16.bn)(0);
|
4109
|
+
if (transactionRequest.type === import_transactions19.TransactionType.Script) {
|
4110
|
+
gasLimit = transactionRequest.gasLimit;
|
3909
4111
|
if (transactionRequest.gasLimit.eq(0)) {
|
3910
4112
|
transactionRequest.gasLimit = minGas;
|
3911
4113
|
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3912
4114
|
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3913
4115
|
);
|
4116
|
+
gasLimit = transactionRequest.gasLimit;
|
3914
4117
|
}
|
3915
4118
|
}
|
3916
4119
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3917
|
-
const maxFee =
|
4120
|
+
const maxFee = calculateGasFee({
|
4121
|
+
gasPrice: (0, import_math16.bn)(gasPrice),
|
4122
|
+
gas: maxGas,
|
4123
|
+
priceFactor: gasPriceFactor,
|
4124
|
+
tip: transactionRequest.tip
|
4125
|
+
}).add(1);
|
3918
4126
|
return {
|
3919
4127
|
minGas,
|
3920
4128
|
minFee,
|
3921
4129
|
maxGas,
|
3922
|
-
maxFee
|
4130
|
+
maxFee,
|
4131
|
+
gasPrice,
|
4132
|
+
gasLimit
|
3923
4133
|
};
|
3924
4134
|
}
|
3925
4135
|
/**
|
@@ -3937,15 +4147,17 @@ var _Provider = class {
|
|
3937
4147
|
if (estimateTxDependencies) {
|
3938
4148
|
return this.estimateTxDependencies(transactionRequest);
|
3939
4149
|
}
|
3940
|
-
const
|
3941
|
-
const { dryRun:
|
3942
|
-
|
4150
|
+
const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
|
4151
|
+
const { dryRun: dryRunStatuses } = await this.operations.dryRun({
|
4152
|
+
encodedTransactions,
|
3943
4153
|
utxoValidation: true
|
3944
4154
|
});
|
3945
|
-
const
|
3946
|
-
|
3947
|
-
receipts
|
3948
|
-
|
4155
|
+
const callResult = dryRunStatuses.map((dryRunStatus) => {
|
4156
|
+
const { id, receipts, status } = dryRunStatus;
|
4157
|
+
const processedReceipts = receipts.map(processGqlReceipt);
|
4158
|
+
return { id, receipts: processedReceipts, status };
|
4159
|
+
});
|
4160
|
+
return { receipts: callResult[0].receipts };
|
3949
4161
|
}
|
3950
4162
|
/**
|
3951
4163
|
* Returns a transaction cost to enable user
|
@@ -3962,77 +4174,79 @@ var _Provider = class {
|
|
3962
4174
|
* @param tolerance - The tolerance to add on top of the gasUsed.
|
3963
4175
|
* @returns A promise that resolves to the transaction cost object.
|
3964
4176
|
*/
|
3965
|
-
async getTransactionCost(transactionRequestLike,
|
3966
|
-
estimateTxDependencies = true,
|
3967
|
-
estimatePredicates = true,
|
3968
|
-
resourcesOwner,
|
3969
|
-
signatureCallback
|
3970
|
-
} = {}) {
|
4177
|
+
async getTransactionCost(transactionRequestLike, { resourcesOwner, signatureCallback, quantitiesToContract = [] } = {}) {
|
3971
4178
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3972
|
-
const
|
3973
|
-
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3974
|
-
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
4179
|
+
const isScriptTransaction = txRequestClone.type === import_transactions19.TransactionType.Script;
|
3975
4180
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3976
|
-
const allQuantities = mergeQuantities(coinOutputsQuantities,
|
4181
|
+
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
3977
4182
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4183
|
+
txRequestClone.maxFee = (0, import_math16.bn)(0);
|
3978
4184
|
if (isScriptTransaction) {
|
3979
|
-
txRequestClone.gasLimit = (0,
|
4185
|
+
txRequestClone.gasLimit = (0, import_math16.bn)(0);
|
3980
4186
|
}
|
3981
|
-
if (
|
3982
|
-
|
3983
|
-
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3984
|
-
}
|
3985
|
-
await this.estimatePredicates(txRequestClone);
|
4187
|
+
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4188
|
+
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3986
4189
|
}
|
4190
|
+
const signedRequest = (0, import_ramda3.clone)(txRequestClone);
|
4191
|
+
let addedSignatures = 0;
|
3987
4192
|
if (signatureCallback && isScriptTransaction) {
|
3988
|
-
|
4193
|
+
const lengthBefore = signedRequest.witnesses.length;
|
4194
|
+
await signatureCallback(signedRequest);
|
4195
|
+
addedSignatures = signedRequest.witnesses.length - lengthBefore;
|
3989
4196
|
}
|
3990
|
-
|
3991
|
-
|
4197
|
+
await this.estimatePredicates(signedRequest);
|
4198
|
+
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
|
4199
|
+
transactionRequest: signedRequest
|
3992
4200
|
});
|
3993
4201
|
let receipts = [];
|
3994
4202
|
let missingContractIds = [];
|
3995
4203
|
let outputVariables = 0;
|
3996
|
-
let gasUsed = (0,
|
3997
|
-
|
3998
|
-
|
4204
|
+
let gasUsed = (0, import_math16.bn)(0);
|
4205
|
+
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);
|
4206
|
+
txRequestClone.maxFee = maxFee;
|
4207
|
+
if (isScriptTransaction) {
|
4208
|
+
txRequestClone.gasLimit = gasLimit;
|
4209
|
+
if (signatureCallback) {
|
4210
|
+
await signatureCallback(txRequestClone);
|
4211
|
+
}
|
3999
4212
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4000
4213
|
receipts = result.receipts;
|
4001
4214
|
outputVariables = result.outputVariables;
|
4002
4215
|
missingContractIds = result.missingContractIds;
|
4003
4216
|
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4004
4217
|
txRequestClone.gasLimit = gasUsed;
|
4005
|
-
|
4006
|
-
|
4007
|
-
|
4218
|
+
({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
|
4219
|
+
transactionRequest: txRequestClone,
|
4220
|
+
gasPrice
|
4008
4221
|
}));
|
4009
4222
|
}
|
4010
4223
|
return {
|
4011
4224
|
requiredQuantities: allQuantities,
|
4012
4225
|
receipts,
|
4013
4226
|
gasUsed,
|
4014
|
-
|
4015
|
-
gasPrice: setGasPrice,
|
4227
|
+
gasPrice,
|
4016
4228
|
minGas,
|
4017
4229
|
maxGas,
|
4018
4230
|
minFee,
|
4019
4231
|
maxFee,
|
4020
|
-
estimatedInputs: txRequestClone.inputs,
|
4021
4232
|
outputVariables,
|
4022
|
-
missingContractIds
|
4233
|
+
missingContractIds,
|
4234
|
+
addedSignatures,
|
4235
|
+
estimatedPredicates: txRequestClone.inputs
|
4023
4236
|
};
|
4024
4237
|
}
|
4025
|
-
async getResourcesForTransaction(owner, transactionRequestLike,
|
4238
|
+
async getResourcesForTransaction(owner, transactionRequestLike, quantitiesToContract = []) {
|
4026
4239
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4027
4240
|
const transactionRequest = transactionRequestify((0, import_ramda3.clone)(transactionRequestLike));
|
4028
|
-
const transactionCost = await this.getTransactionCost(transactionRequest,
|
4241
|
+
const transactionCost = await this.getTransactionCost(transactionRequest, {
|
4242
|
+
quantitiesToContract
|
4243
|
+
});
|
4029
4244
|
transactionRequest.addResources(
|
4030
4245
|
await this.getResourcesToSpend(ownerAddress, transactionCost.requiredQuantities)
|
4031
4246
|
);
|
4032
|
-
const { requiredQuantities, ...txCost } = await this.getTransactionCost(
|
4033
|
-
|
4034
|
-
|
4035
|
-
);
|
4247
|
+
const { requiredQuantities, ...txCost } = await this.getTransactionCost(transactionRequest, {
|
4248
|
+
quantitiesToContract
|
4249
|
+
});
|
4036
4250
|
const resources = await this.getResourcesToSpend(ownerAddress, requiredQuantities);
|
4037
4251
|
return {
|
4038
4252
|
resources,
|
@@ -4048,17 +4262,16 @@ var _Provider = class {
|
|
4048
4262
|
const result = await this.operations.getCoins({
|
4049
4263
|
first: 10,
|
4050
4264
|
...paginationArgs,
|
4051
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4265
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4052
4266
|
});
|
4053
4267
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4054
4268
|
return coins.map((coin) => ({
|
4055
4269
|
id: coin.utxoId,
|
4056
4270
|
assetId: coin.assetId,
|
4057
|
-
amount: (0,
|
4271
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4058
4272
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4059
|
-
|
4060
|
-
|
4061
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4273
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4274
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4062
4275
|
}));
|
4063
4276
|
}
|
4064
4277
|
/**
|
@@ -4072,19 +4285,19 @@ var _Provider = class {
|
|
4072
4285
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4073
4286
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4074
4287
|
const excludeInput = {
|
4075
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4076
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4288
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4289
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4077
4290
|
};
|
4078
4291
|
if (this.cache) {
|
4079
4292
|
const uniqueUtxos = new Set(
|
4080
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4293
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4081
4294
|
);
|
4082
4295
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4083
4296
|
}
|
4084
4297
|
const coinsQuery = {
|
4085
4298
|
owner: ownerAddress.toB256(),
|
4086
4299
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4087
|
-
assetId: (0,
|
4300
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4088
4301
|
amount: amount.toString(10),
|
4089
4302
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4090
4303
|
})),
|
@@ -4095,9 +4308,9 @@ var _Provider = class {
|
|
4095
4308
|
switch (coin.__typename) {
|
4096
4309
|
case "MessageCoin":
|
4097
4310
|
return {
|
4098
|
-
amount: (0,
|
4311
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4099
4312
|
assetId: coin.assetId,
|
4100
|
-
daHeight: (0,
|
4313
|
+
daHeight: (0, import_math16.bn)(coin.daHeight),
|
4101
4314
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4102
4315
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4103
4316
|
nonce: coin.nonce
|
@@ -4105,12 +4318,11 @@ var _Provider = class {
|
|
4105
4318
|
case "Coin":
|
4106
4319
|
return {
|
4107
4320
|
id: coin.utxoId,
|
4108
|
-
amount: (0,
|
4321
|
+
amount: (0, import_math16.bn)(coin.amount),
|
4109
4322
|
assetId: coin.assetId,
|
4110
4323
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4111
|
-
|
4112
|
-
|
4113
|
-
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4324
|
+
blockCreated: (0, import_math16.bn)(coin.blockCreated),
|
4325
|
+
txCreatedIdx: (0, import_math16.bn)(coin.txCreatedIdx)
|
4114
4326
|
};
|
4115
4327
|
default:
|
4116
4328
|
return null;
|
@@ -4127,13 +4339,13 @@ var _Provider = class {
|
|
4127
4339
|
async getBlock(idOrHeight) {
|
4128
4340
|
let variables;
|
4129
4341
|
if (typeof idOrHeight === "number") {
|
4130
|
-
variables = { height: (0,
|
4342
|
+
variables = { height: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4131
4343
|
} else if (idOrHeight === "latest") {
|
4132
4344
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4133
4345
|
} else if (idOrHeight.length === 66) {
|
4134
4346
|
variables = { blockId: idOrHeight };
|
4135
4347
|
} else {
|
4136
|
-
variables = { blockId: (0,
|
4348
|
+
variables = { blockId: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4137
4349
|
}
|
4138
4350
|
const { block } = await this.operations.getBlock(variables);
|
4139
4351
|
if (!block) {
|
@@ -4141,7 +4353,7 @@ var _Provider = class {
|
|
4141
4353
|
}
|
4142
4354
|
return {
|
4143
4355
|
id: block.id,
|
4144
|
-
height: (0,
|
4356
|
+
height: (0, import_math16.bn)(block.height),
|
4145
4357
|
time: block.header.time,
|
4146
4358
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4147
4359
|
};
|
@@ -4156,7 +4368,7 @@ var _Provider = class {
|
|
4156
4368
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4157
4369
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4158
4370
|
id: block.id,
|
4159
|
-
height: (0,
|
4371
|
+
height: (0, import_math16.bn)(block.height),
|
4160
4372
|
time: block.header.time,
|
4161
4373
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4162
4374
|
}));
|
@@ -4171,7 +4383,7 @@ var _Provider = class {
|
|
4171
4383
|
async getBlockWithTransactions(idOrHeight) {
|
4172
4384
|
let variables;
|
4173
4385
|
if (typeof idOrHeight === "number") {
|
4174
|
-
variables = { blockHeight: (0,
|
4386
|
+
variables = { blockHeight: (0, import_math16.bn)(idOrHeight).toString(10) };
|
4175
4387
|
} else if (idOrHeight === "latest") {
|
4176
4388
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4177
4389
|
} else {
|
@@ -4183,11 +4395,11 @@ var _Provider = class {
|
|
4183
4395
|
}
|
4184
4396
|
return {
|
4185
4397
|
id: block.id,
|
4186
|
-
height: (0,
|
4398
|
+
height: (0, import_math16.bn)(block.height, 10),
|
4187
4399
|
time: block.header.time,
|
4188
4400
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4189
4401
|
transactions: block.transactions.map(
|
4190
|
-
(tx) => new
|
4402
|
+
(tx) => new import_transactions19.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4191
4403
|
)
|
4192
4404
|
};
|
4193
4405
|
}
|
@@ -4202,8 +4414,8 @@ var _Provider = class {
|
|
4202
4414
|
if (!transaction) {
|
4203
4415
|
return null;
|
4204
4416
|
}
|
4205
|
-
return new
|
4206
|
-
(0,
|
4417
|
+
return new import_transactions19.TransactionCoder().decode(
|
4418
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4207
4419
|
0
|
4208
4420
|
)?.[0];
|
4209
4421
|
}
|
@@ -4230,9 +4442,9 @@ var _Provider = class {
|
|
4230
4442
|
async getContractBalance(contractId, assetId) {
|
4231
4443
|
const { contractBalance } = await this.operations.getContractBalance({
|
4232
4444
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4233
|
-
asset: (0,
|
4445
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4234
4446
|
});
|
4235
|
-
return (0,
|
4447
|
+
return (0, import_math16.bn)(contractBalance.amount, 10);
|
4236
4448
|
}
|
4237
4449
|
/**
|
4238
4450
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4244,9 +4456,9 @@ var _Provider = class {
|
|
4244
4456
|
async getBalance(owner, assetId) {
|
4245
4457
|
const { balance } = await this.operations.getBalance({
|
4246
4458
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4247
|
-
assetId: (0,
|
4459
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4248
4460
|
});
|
4249
|
-
return (0,
|
4461
|
+
return (0, import_math16.bn)(balance.amount, 10);
|
4250
4462
|
}
|
4251
4463
|
/**
|
4252
4464
|
* Returns balances for the given owner.
|
@@ -4264,7 +4476,7 @@ var _Provider = class {
|
|
4264
4476
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4265
4477
|
return balances.map((balance) => ({
|
4266
4478
|
assetId: balance.assetId,
|
4267
|
-
amount: (0,
|
4479
|
+
amount: (0, import_math16.bn)(balance.amount)
|
4268
4480
|
}));
|
4269
4481
|
}
|
4270
4482
|
/**
|
@@ -4282,19 +4494,19 @@ var _Provider = class {
|
|
4282
4494
|
});
|
4283
4495
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4284
4496
|
return messages.map((message) => ({
|
4285
|
-
messageId:
|
4497
|
+
messageId: import_transactions19.InputMessageCoder.getMessageId({
|
4286
4498
|
sender: message.sender,
|
4287
4499
|
recipient: message.recipient,
|
4288
4500
|
nonce: message.nonce,
|
4289
|
-
amount: (0,
|
4501
|
+
amount: (0, import_math16.bn)(message.amount),
|
4290
4502
|
data: message.data
|
4291
4503
|
}),
|
4292
4504
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4293
4505
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4294
4506
|
nonce: message.nonce,
|
4295
|
-
amount: (0,
|
4296
|
-
data:
|
4297
|
-
daHeight: (0,
|
4507
|
+
amount: (0, import_math16.bn)(message.amount),
|
4508
|
+
data: import_transactions19.InputMessageCoder.decodeData(message.data),
|
4509
|
+
daHeight: (0, import_math16.bn)(message.daHeight)
|
4298
4510
|
}));
|
4299
4511
|
}
|
4300
4512
|
/**
|
@@ -4347,44 +4559,60 @@ var _Provider = class {
|
|
4347
4559
|
} = result.messageProof;
|
4348
4560
|
return {
|
4349
4561
|
messageProof: {
|
4350
|
-
proofIndex: (0,
|
4562
|
+
proofIndex: (0, import_math16.bn)(messageProof.proofIndex),
|
4351
4563
|
proofSet: messageProof.proofSet
|
4352
4564
|
},
|
4353
4565
|
blockProof: {
|
4354
|
-
proofIndex: (0,
|
4566
|
+
proofIndex: (0, import_math16.bn)(blockProof.proofIndex),
|
4355
4567
|
proofSet: blockProof.proofSet
|
4356
4568
|
},
|
4357
4569
|
messageBlockHeader: {
|
4358
4570
|
id: messageBlockHeader.id,
|
4359
|
-
daHeight: (0,
|
4360
|
-
transactionsCount: (0,
|
4571
|
+
daHeight: (0, import_math16.bn)(messageBlockHeader.daHeight),
|
4572
|
+
transactionsCount: (0, import_math16.bn)(messageBlockHeader.transactionsCount),
|
4361
4573
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4362
|
-
height: (0,
|
4574
|
+
height: (0, import_math16.bn)(messageBlockHeader.height),
|
4363
4575
|
prevRoot: messageBlockHeader.prevRoot,
|
4364
4576
|
time: messageBlockHeader.time,
|
4365
4577
|
applicationHash: messageBlockHeader.applicationHash,
|
4366
|
-
|
4367
|
-
|
4578
|
+
messageReceiptCount: (0, import_math16.bn)(messageBlockHeader.messageReceiptCount),
|
4579
|
+
messageOutboxRoot: messageBlockHeader.messageOutboxRoot,
|
4580
|
+
consensusParametersVersion: messageBlockHeader.consensusParametersVersion,
|
4581
|
+
eventInboxRoot: messageBlockHeader.eventInboxRoot,
|
4582
|
+
stateTransitionBytecodeVersion: messageBlockHeader.stateTransitionBytecodeVersion
|
4368
4583
|
},
|
4369
4584
|
commitBlockHeader: {
|
4370
4585
|
id: commitBlockHeader.id,
|
4371
|
-
daHeight: (0,
|
4372
|
-
transactionsCount: (0,
|
4586
|
+
daHeight: (0, import_math16.bn)(commitBlockHeader.daHeight),
|
4587
|
+
transactionsCount: (0, import_math16.bn)(commitBlockHeader.transactionsCount),
|
4373
4588
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4374
|
-
height: (0,
|
4589
|
+
height: (0, import_math16.bn)(commitBlockHeader.height),
|
4375
4590
|
prevRoot: commitBlockHeader.prevRoot,
|
4376
4591
|
time: commitBlockHeader.time,
|
4377
4592
|
applicationHash: commitBlockHeader.applicationHash,
|
4378
|
-
|
4379
|
-
|
4593
|
+
messageReceiptCount: (0, import_math16.bn)(commitBlockHeader.messageReceiptCount),
|
4594
|
+
messageOutboxRoot: commitBlockHeader.messageOutboxRoot,
|
4595
|
+
consensusParametersVersion: commitBlockHeader.consensusParametersVersion,
|
4596
|
+
eventInboxRoot: commitBlockHeader.eventInboxRoot,
|
4597
|
+
stateTransitionBytecodeVersion: commitBlockHeader.stateTransitionBytecodeVersion
|
4380
4598
|
},
|
4381
4599
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4382
4600
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4383
4601
|
nonce,
|
4384
|
-
amount: (0,
|
4602
|
+
amount: (0, import_math16.bn)(amount),
|
4385
4603
|
data
|
4386
4604
|
};
|
4387
4605
|
}
|
4606
|
+
async getLatestGasPrice() {
|
4607
|
+
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4608
|
+
return (0, import_math16.bn)(latestGasPrice.gasPrice);
|
4609
|
+
}
|
4610
|
+
async estimateGasPrice(blockHorizon) {
|
4611
|
+
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4612
|
+
blockHorizon: String(blockHorizon)
|
4613
|
+
});
|
4614
|
+
return (0, import_math16.bn)(estimateGasPrice.gasPrice);
|
4615
|
+
}
|
4388
4616
|
/**
|
4389
4617
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
4390
4618
|
*
|
@@ -4404,10 +4632,10 @@ var _Provider = class {
|
|
4404
4632
|
*/
|
4405
4633
|
async produceBlocks(amount, startTime) {
|
4406
4634
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4407
|
-
blocksToProduce: (0,
|
4408
|
-
startTimestamp: startTime ?
|
4635
|
+
blocksToProduce: (0, import_math16.bn)(amount).toString(10),
|
4636
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4409
4637
|
});
|
4410
|
-
return (0,
|
4638
|
+
return (0, import_math16.bn)(latestBlockHeight);
|
4411
4639
|
}
|
4412
4640
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4413
4641
|
async getTransactionResponse(transactionId) {
|
@@ -4421,7 +4649,7 @@ cacheInputs_fn = function(inputs) {
|
|
4421
4649
|
return;
|
4422
4650
|
}
|
4423
4651
|
inputs.forEach((input) => {
|
4424
|
-
if (input.type ===
|
4652
|
+
if (input.type === import_transactions19.InputType.Coin) {
|
4425
4653
|
this.cache?.set(input.id);
|
4426
4654
|
}
|
4427
4655
|
});
|
@@ -4431,9 +4659,9 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4431
4659
|
|
4432
4660
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4433
4661
|
var import_errors15 = require("@fuel-ts/errors");
|
4434
|
-
var
|
4435
|
-
var
|
4436
|
-
var
|
4662
|
+
var import_math17 = require("@fuel-ts/math");
|
4663
|
+
var import_transactions20 = require("@fuel-ts/transactions");
|
4664
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4437
4665
|
|
4438
4666
|
// src/providers/chains.ts
|
4439
4667
|
var CHAIN_IDS = {
|
@@ -4482,17 +4710,17 @@ var assets = [
|
|
4482
4710
|
|
4483
4711
|
// src/utils/formatTransferToContractScriptData.ts
|
4484
4712
|
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4485
|
-
var
|
4486
|
-
var
|
4713
|
+
var import_math18 = require("@fuel-ts/math");
|
4714
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4487
4715
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4488
4716
|
var formatTransferToContractScriptData = (params) => {
|
4489
4717
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4490
4718
|
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4491
|
-
const encoded = numberCoder.encode(new
|
4719
|
+
const encoded = numberCoder.encode(new import_math18.BN(amountToTransfer).toNumber());
|
4492
4720
|
const scriptData = Uint8Array.from([
|
4493
|
-
...(0,
|
4721
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4494
4722
|
...encoded,
|
4495
|
-
...(0,
|
4723
|
+
...(0, import_utils26.arrayify)(assetId)
|
4496
4724
|
]);
|
4497
4725
|
return scriptData;
|
4498
4726
|
};
|
@@ -4677,36 +4905,33 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4677
4905
|
* @param fee - The estimated transaction fee.
|
4678
4906
|
* @returns A promise that resolves when the resources are added to the transaction.
|
4679
4907
|
*/
|
4680
|
-
async fund(request,
|
4681
|
-
const
|
4682
|
-
|
4908
|
+
async fund(request, params) {
|
4909
|
+
const { addedSignatures, estimatedPredicates, maxFee: fee, requiredQuantities } = params;
|
4910
|
+
const txRequest = request;
|
4911
|
+
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
4912
|
+
amount: (0, import_math19.bn)(fee),
|
4683
4913
|
assetId: import_configs12.BaseAssetId,
|
4684
|
-
coinQuantities
|
4914
|
+
coinQuantities: requiredQuantities
|
4685
4915
|
});
|
4686
4916
|
const quantitiesDict = {};
|
4687
|
-
|
4917
|
+
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
4688
4918
|
quantitiesDict[assetId] = {
|
4689
4919
|
required: amount,
|
4690
|
-
owned: (0,
|
4920
|
+
owned: (0, import_math19.bn)(0)
|
4691
4921
|
};
|
4692
4922
|
});
|
4693
|
-
|
4694
|
-
const cachedMessages = [];
|
4695
|
-
const owner = this.address.toB256();
|
4696
|
-
request.inputs.forEach((input) => {
|
4923
|
+
txRequest.inputs.forEach((input) => {
|
4697
4924
|
const isResource = "amount" in input;
|
4698
4925
|
if (isResource) {
|
4699
4926
|
const isCoin2 = "owner" in input;
|
4700
4927
|
if (isCoin2) {
|
4701
4928
|
const assetId = String(input.assetId);
|
4702
|
-
if (
|
4703
|
-
const amount = (0,
|
4929
|
+
if (quantitiesDict[assetId]) {
|
4930
|
+
const amount = (0, import_math19.bn)(input.amount);
|
4704
4931
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4705
|
-
cachedUtxos.push(input.id);
|
4706
4932
|
}
|
4707
|
-
} else if (input.
|
4933
|
+
} else if (input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4708
4934
|
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4709
|
-
cachedMessages.push(input.nonce);
|
4710
4935
|
}
|
4711
4936
|
}
|
4712
4937
|
});
|
@@ -4721,12 +4946,23 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4721
4946
|
});
|
4722
4947
|
const needsToBeFunded = missingQuantities.length;
|
4723
4948
|
if (needsToBeFunded) {
|
4724
|
-
const
|
4725
|
-
|
4726
|
-
|
4727
|
-
|
4728
|
-
|
4949
|
+
const excludedIds = cacheTxInputsFromOwner(txRequest.inputs, this.address.toB256());
|
4950
|
+
const resources = await this.getResourcesToSpend(missingQuantities, excludedIds);
|
4951
|
+
txRequest.addResources(resources);
|
4952
|
+
}
|
4953
|
+
txRequest.shiftPredicateData();
|
4954
|
+
txRequest.updatePredicateGasUsed(estimatedPredicates);
|
4955
|
+
const requestToBeReEstimate = (0, import_ramda4.clone)(txRequest);
|
4956
|
+
if (addedSignatures) {
|
4957
|
+
Array.from({ length: addedSignatures }).forEach(
|
4958
|
+
() => requestToBeReEstimate.addEmptyWitness()
|
4959
|
+
);
|
4729
4960
|
}
|
4961
|
+
const { maxFee } = await this.provider.estimateTxGasAndFee({
|
4962
|
+
transactionRequest: requestToBeReEstimate
|
4963
|
+
});
|
4964
|
+
txRequest.maxFee = maxFee;
|
4965
|
+
return txRequest;
|
4730
4966
|
}
|
4731
4967
|
/**
|
4732
4968
|
* A helper that creates a transfer transaction request and returns it.
|
@@ -4734,28 +4970,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4734
4970
|
* @param destination - The address of the destination.
|
4735
4971
|
* @param amount - The amount of coins to transfer.
|
4736
4972
|
* @param assetId - The asset ID of the coins to transfer.
|
4737
|
-
* @param txParams - The transaction parameters (gasLimit,
|
4973
|
+
* @param txParams - The transaction parameters (gasLimit, tip, maturity, maxFee, witnessLimit).
|
4738
4974
|
* @returns A promise that resolves to the prepared transaction request.
|
4739
4975
|
*/
|
4740
4976
|
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4741
|
-
const
|
4742
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4743
|
-
const request = new ScriptTransactionRequest(params);
|
4977
|
+
const request = new ScriptTransactionRequest(txParams);
|
4744
4978
|
request.addCoinOutput(import_address4.Address.fromAddressOrString(destination), amount, assetId);
|
4745
|
-
const
|
4979
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
4746
4980
|
estimateTxDependencies: true,
|
4747
4981
|
resourcesOwner: this
|
4748
4982
|
});
|
4749
|
-
|
4750
|
-
|
4751
|
-
|
4752
|
-
|
4753
|
-
|
4754
|
-
|
4755
|
-
|
4756
|
-
|
4757
|
-
await this.fund(request,
|
4758
|
-
request.updatePredicateInputs(estimatedInputs);
|
4983
|
+
if ("gasLimit" in txParams) {
|
4984
|
+
this.validateGas({
|
4985
|
+
gasUsed: txCost.gasUsed,
|
4986
|
+
gasLimit: request.gasLimit
|
4987
|
+
});
|
4988
|
+
}
|
4989
|
+
request.gasLimit = txCost.gasUsed;
|
4990
|
+
request.maxFee = txCost.maxFee;
|
4991
|
+
await this.fund(request, txCost);
|
4759
4992
|
return request;
|
4760
4993
|
}
|
4761
4994
|
/**
|
@@ -4768,7 +5001,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4768
5001
|
* @returns A promise that resolves to the transaction response.
|
4769
5002
|
*/
|
4770
5003
|
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4771
|
-
if ((0,
|
5004
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
4772
5005
|
throw new import_errors16.FuelError(
|
4773
5006
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4774
5007
|
"Transfer amount must be a positive number."
|
@@ -4787,38 +5020,37 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4787
5020
|
* @returns A promise that resolves to the transaction response.
|
4788
5021
|
*/
|
4789
5022
|
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4790
|
-
if ((0,
|
5023
|
+
if ((0, import_math19.bn)(amount).lte(0)) {
|
4791
5024
|
throw new import_errors16.FuelError(
|
4792
5025
|
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4793
5026
|
"Transfer amount must be a positive number."
|
4794
5027
|
);
|
4795
5028
|
}
|
4796
5029
|
const contractAddress = import_address4.Address.fromAddressOrString(contractId);
|
4797
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4798
|
-
const params = { gasPrice: minGasPrice, ...txParams };
|
4799
5030
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4800
5031
|
hexlifiedContractId: contractAddress.toB256(),
|
4801
|
-
amountToTransfer: (0,
|
5032
|
+
amountToTransfer: (0, import_math19.bn)(amount),
|
4802
5033
|
assetId
|
4803
5034
|
});
|
4804
5035
|
const request = new ScriptTransactionRequest({
|
4805
|
-
...
|
5036
|
+
...txParams,
|
4806
5037
|
script,
|
4807
5038
|
scriptData
|
4808
5039
|
});
|
4809
5040
|
request.addContractInputAndOutput(contractAddress);
|
4810
|
-
const
|
4811
|
-
|
4812
|
-
[{ amount: (0,
|
4813
|
-
);
|
4814
|
-
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4815
|
-
this.validateGas({
|
4816
|
-
gasUsed,
|
4817
|
-
gasPrice: request.gasPrice,
|
4818
|
-
gasLimit: request.gasLimit,
|
4819
|
-
minGasPrice
|
5041
|
+
const txCost = await this.provider.getTransactionCost(request, {
|
5042
|
+
resourcesOwner: this,
|
5043
|
+
quantitiesToContract: [{ amount: (0, import_math19.bn)(amount), assetId: String(assetId) }]
|
4820
5044
|
});
|
4821
|
-
|
5045
|
+
if (txParams.gasLimit) {
|
5046
|
+
this.validateGas({
|
5047
|
+
gasUsed: txCost.gasUsed,
|
5048
|
+
gasLimit: request.gasLimit
|
5049
|
+
});
|
5050
|
+
}
|
5051
|
+
request.gasLimit = txCost.gasUsed;
|
5052
|
+
request.maxFee = txCost.maxFee;
|
5053
|
+
await this.fund(request, txCost);
|
4822
5054
|
return this.sendTransaction(request);
|
4823
5055
|
}
|
4824
5056
|
/**
|
@@ -4830,34 +5062,31 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4830
5062
|
* @returns A promise that resolves to the transaction response.
|
4831
5063
|
*/
|
4832
5064
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4833
|
-
const { minGasPrice } = this.provider.getGasConfig();
|
4834
5065
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4835
|
-
const recipientDataArray = (0,
|
5066
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
4836
5067
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4837
5068
|
);
|
4838
|
-
const amountDataArray = (0,
|
4839
|
-
"0x".concat((0,
|
5069
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5070
|
+
"0x".concat((0, import_math19.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4840
5071
|
);
|
4841
5072
|
const script = new Uint8Array([
|
4842
|
-
...(0,
|
5073
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
4843
5074
|
...recipientDataArray,
|
4844
5075
|
...amountDataArray
|
4845
5076
|
]);
|
4846
|
-
const params = { script,
|
5077
|
+
const params = { script, ...txParams };
|
4847
5078
|
const request = new ScriptTransactionRequest(params);
|
4848
|
-
const
|
4849
|
-
const
|
4850
|
-
|
4851
|
-
|
4852
|
-
|
4853
|
-
|
4854
|
-
|
4855
|
-
|
4856
|
-
|
4857
|
-
|
4858
|
-
|
4859
|
-
});
|
4860
|
-
await this.fund(request, requiredQuantities, maxFee);
|
5079
|
+
const quantitiesToContract = [{ amount: (0, import_math19.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
5080
|
+
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5081
|
+
if (txParams.gasLimit) {
|
5082
|
+
this.validateGas({
|
5083
|
+
gasUsed: txCost.gasUsed,
|
5084
|
+
gasLimit: request.gasLimit
|
5085
|
+
});
|
5086
|
+
}
|
5087
|
+
request.maxFee = txCost.maxFee;
|
5088
|
+
request.gasLimit = txCost.gasUsed;
|
5089
|
+
await this.fund(request, txCost);
|
4861
5090
|
return this.sendTransaction(request);
|
4862
5091
|
}
|
4863
5092
|
async signMessage(message) {
|
@@ -4915,18 +5144,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4915
5144
|
}
|
4916
5145
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
4917
5146
|
}
|
4918
|
-
validateGas({
|
4919
|
-
gasUsed,
|
4920
|
-
gasPrice,
|
4921
|
-
gasLimit,
|
4922
|
-
minGasPrice
|
4923
|
-
}) {
|
4924
|
-
if (minGasPrice.gt(gasPrice)) {
|
4925
|
-
throw new import_errors16.FuelError(
|
4926
|
-
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4927
|
-
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4928
|
-
);
|
4929
|
-
}
|
5147
|
+
validateGas({ gasUsed, gasLimit }) {
|
4930
5148
|
if (gasUsed.gt(gasLimit)) {
|
4931
5149
|
throw new import_errors16.FuelError(
|
4932
5150
|
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
@@ -4940,8 +5158,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4940
5158
|
var import_address5 = require("@fuel-ts/address");
|
4941
5159
|
var import_crypto2 = require("@fuel-ts/crypto");
|
4942
5160
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4943
|
-
var
|
4944
|
-
var
|
5161
|
+
var import_math20 = require("@fuel-ts/math");
|
5162
|
+
var import_utils28 = require("@fuel-ts/utils");
|
4945
5163
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4946
5164
|
var Signer = class {
|
4947
5165
|
address;
|
@@ -4960,10 +5178,10 @@ var Signer = class {
|
|
4960
5178
|
privateKey = `0x${privateKey}`;
|
4961
5179
|
}
|
4962
5180
|
}
|
4963
|
-
const privateKeyBytes = (0,
|
4964
|
-
this.privateKey = (0,
|
4965
|
-
this.publicKey = (0,
|
4966
|
-
this.compressedPublicKey = (0,
|
5181
|
+
const privateKeyBytes = (0, import_math20.toBytes)(privateKey, 32);
|
5182
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5183
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5184
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
4967
5185
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
4968
5186
|
}
|
4969
5187
|
/**
|
@@ -4977,11 +5195,11 @@ var Signer = class {
|
|
4977
5195
|
* @returns hashed signature
|
4978
5196
|
*/
|
4979
5197
|
sign(data) {
|
4980
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
4981
|
-
const r = (0,
|
4982
|
-
const s = (0,
|
5198
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5199
|
+
const r = (0, import_math20.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5200
|
+
const s = (0, import_math20.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4983
5201
|
s[0] |= (signature.recovery || 0) << 7;
|
4984
|
-
return (0,
|
5202
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
4985
5203
|
}
|
4986
5204
|
/**
|
4987
5205
|
* Add point on the current elliptic curve
|
@@ -4990,8 +5208,8 @@ var Signer = class {
|
|
4990
5208
|
* @returns compressed point on the curve
|
4991
5209
|
*/
|
4992
5210
|
addPoint(point) {
|
4993
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4994
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5211
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5212
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
4995
5213
|
const result = p0.add(p1);
|
4996
5214
|
return `0x${result.toHex(true)}`;
|
4997
5215
|
}
|
@@ -5003,16 +5221,16 @@ var Signer = class {
|
|
5003
5221
|
* @returns public key from signature from the
|
5004
5222
|
*/
|
5005
5223
|
static recoverPublicKey(data, signature) {
|
5006
|
-
const signedMessageBytes = (0,
|
5224
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5007
5225
|
const r = signedMessageBytes.slice(0, 32);
|
5008
5226
|
const s = signedMessageBytes.slice(32, 64);
|
5009
5227
|
const recoveryParam = (s[0] & 128) >> 7;
|
5010
5228
|
s[0] &= 127;
|
5011
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5229
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5012
5230
|
recoveryParam
|
5013
5231
|
);
|
5014
|
-
const publicKey = sig.recoverPublicKey((0,
|
5015
|
-
return (0,
|
5232
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5233
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5016
5234
|
}
|
5017
5235
|
/**
|
5018
5236
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5031,7 +5249,7 @@ var Signer = class {
|
|
5031
5249
|
* @returns random 32-byte hashed
|
5032
5250
|
*/
|
5033
5251
|
static generatePrivateKey(entropy) {
|
5034
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5252
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
5035
5253
|
}
|
5036
5254
|
/**
|
5037
5255
|
* Extended publicKey from a compact publicKey
|
@@ -5040,8 +5258,8 @@ var Signer = class {
|
|
5040
5258
|
* @returns extended publicKey
|
5041
5259
|
*/
|
5042
5260
|
static extendPublicKey(publicKey) {
|
5043
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5044
|
-
return (0,
|
5261
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5262
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5045
5263
|
}
|
5046
5264
|
};
|
5047
5265
|
|
@@ -5049,7 +5267,7 @@ var Signer = class {
|
|
5049
5267
|
var import_address6 = require("@fuel-ts/address");
|
5050
5268
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5051
5269
|
var import_errors17 = require("@fuel-ts/errors");
|
5052
|
-
var
|
5270
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5053
5271
|
var import_uuid = require("uuid");
|
5054
5272
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5055
5273
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5132,7 +5350,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5132
5350
|
);
|
5133
5351
|
}
|
5134
5352
|
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5135
|
-
const privateKey = (0,
|
5353
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5136
5354
|
return privateKey;
|
5137
5355
|
}
|
5138
5356
|
|
@@ -5177,7 +5395,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5177
5395
|
*/
|
5178
5396
|
async signMessage(message) {
|
5179
5397
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5180
|
-
return (0,
|
5398
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5181
5399
|
}
|
5182
5400
|
/**
|
5183
5401
|
* Signs a transaction with the wallet's private key.
|
@@ -5190,7 +5408,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5190
5408
|
const chainId = this.provider.getChainId();
|
5191
5409
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5192
5410
|
const signature = await this.signer().sign(hashedTransaction);
|
5193
|
-
return (0,
|
5411
|
+
return (0, import_utils30.hexlify)(signature);
|
5194
5412
|
}
|
5195
5413
|
/**
|
5196
5414
|
* Populates a transaction with the witnesses signature.
|
@@ -5210,7 +5428,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5210
5428
|
* @param transactionRequestLike - The transaction request to send.
|
5211
5429
|
* @returns A promise that resolves to the TransactionResponse object.
|
5212
5430
|
*/
|
5213
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies =
|
5431
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, awaitExecution } = {}) {
|
5214
5432
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5215
5433
|
if (estimateTxDependencies) {
|
5216
5434
|
await this.provider.estimateTxDependencies(transactionRequest);
|
@@ -5251,15 +5469,15 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5251
5469
|
// src/hdwallet/hdwallet.ts
|
5252
5470
|
var import_errors20 = require("@fuel-ts/errors");
|
5253
5471
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5254
|
-
var
|
5255
|
-
var
|
5472
|
+
var import_math21 = require("@fuel-ts/math");
|
5473
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5256
5474
|
var import_ethers3 = require("ethers");
|
5257
5475
|
|
5258
5476
|
// src/mnemonic/mnemonic.ts
|
5259
5477
|
var import_crypto4 = require("@fuel-ts/crypto");
|
5260
5478
|
var import_errors19 = require("@fuel-ts/errors");
|
5261
5479
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5262
|
-
var
|
5480
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5263
5481
|
var import_ethers2 = require("ethers");
|
5264
5482
|
|
5265
5483
|
// src/wordlists/words/english.ts
|
@@ -7317,7 +7535,7 @@ var english = [
|
|
7317
7535
|
// src/mnemonic/utils.ts
|
7318
7536
|
var import_errors18 = require("@fuel-ts/errors");
|
7319
7537
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7320
|
-
var
|
7538
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7321
7539
|
function toUtf8Bytes(stri) {
|
7322
7540
|
const str = stri.normalize("NFKD");
|
7323
7541
|
const result = [];
|
@@ -7384,14 +7602,14 @@ function entropyToMnemonicIndices(entropy) {
|
|
7384
7602
|
}
|
7385
7603
|
}
|
7386
7604
|
const checksumBits = entropy.length / 4;
|
7387
|
-
const checksum = (0,
|
7605
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7388
7606
|
indices[indices.length - 1] <<= checksumBits;
|
7389
7607
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7390
7608
|
return indices;
|
7391
7609
|
}
|
7392
7610
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7393
7611
|
const size = Math.ceil(11 * words.length / 8);
|
7394
|
-
const entropy = (0,
|
7612
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7395
7613
|
let offset = 0;
|
7396
7614
|
for (let i = 0; i < words.length; i += 1) {
|
7397
7615
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
@@ -7411,7 +7629,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7411
7629
|
const entropyBits = 32 * words.length / 3;
|
7412
7630
|
const checksumBits = words.length / 3;
|
7413
7631
|
const checksumMask = getUpperMask(checksumBits);
|
7414
|
-
const checksum = (0,
|
7632
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7415
7633
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7416
7634
|
throw new import_errors18.FuelError(
|
7417
7635
|
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
@@ -7486,7 +7704,7 @@ var Mnemonic = class {
|
|
7486
7704
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7487
7705
|
const words = getWords(phrase);
|
7488
7706
|
assertMnemonic(words);
|
7489
|
-
return (0,
|
7707
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7490
7708
|
}
|
7491
7709
|
/**
|
7492
7710
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7494,7 +7712,7 @@ var Mnemonic = class {
|
|
7494
7712
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7495
7713
|
*/
|
7496
7714
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7497
|
-
const entropyBytes = (0,
|
7715
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7498
7716
|
assertWordList(wordlist);
|
7499
7717
|
assertEntropy(entropyBytes);
|
7500
7718
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7563,14 +7781,14 @@ var Mnemonic = class {
|
|
7563
7781
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7564
7782
|
*/
|
7565
7783
|
static masterKeysFromSeed(seed) {
|
7566
|
-
const seedArray = (0,
|
7784
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
7567
7785
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7568
7786
|
throw new import_errors19.FuelError(
|
7569
7787
|
import_errors19.ErrorCode.INVALID_SEED,
|
7570
7788
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7571
7789
|
);
|
7572
7790
|
}
|
7573
|
-
return (0,
|
7791
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7574
7792
|
}
|
7575
7793
|
/**
|
7576
7794
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7581,22 +7799,22 @@ var Mnemonic = class {
|
|
7581
7799
|
*/
|
7582
7800
|
static seedToExtendedKey(seed, testnet = false) {
|
7583
7801
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7584
|
-
const prefix = (0,
|
7802
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7585
7803
|
const depth = "0x00";
|
7586
7804
|
const fingerprint = "0x00000000";
|
7587
7805
|
const index = "0x00000000";
|
7588
7806
|
const chainCode = masterKey.slice(32);
|
7589
7807
|
const privateKey = masterKey.slice(0, 32);
|
7590
|
-
const extendedKey = (0,
|
7808
|
+
const extendedKey = (0, import_utils32.concat)([
|
7591
7809
|
prefix,
|
7592
7810
|
depth,
|
7593
7811
|
fingerprint,
|
7594
7812
|
index,
|
7595
7813
|
chainCode,
|
7596
|
-
(0,
|
7814
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
7597
7815
|
]);
|
7598
7816
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7599
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7817
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
7600
7818
|
}
|
7601
7819
|
/**
|
7602
7820
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7611,7 +7829,7 @@ var Mnemonic = class {
|
|
7611
7829
|
* @returns A randomly generated mnemonic
|
7612
7830
|
*/
|
7613
7831
|
static generate(size = 32, extraEntropy = "") {
|
7614
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7832
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
7615
7833
|
return Mnemonic.entropyToMnemonic(entropy);
|
7616
7834
|
}
|
7617
7835
|
};
|
@@ -7619,12 +7837,12 @@ var mnemonic_default = Mnemonic;
|
|
7619
7837
|
|
7620
7838
|
// src/hdwallet/hdwallet.ts
|
7621
7839
|
var HARDENED_INDEX = 2147483648;
|
7622
|
-
var MainnetPRV2 = (0,
|
7623
|
-
var MainnetPUB = (0,
|
7624
|
-
var TestnetPRV2 = (0,
|
7625
|
-
var TestnetPUB = (0,
|
7840
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
7841
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
7842
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
7843
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
7626
7844
|
function base58check(data) {
|
7627
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7845
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7628
7846
|
}
|
7629
7847
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7630
7848
|
if (isPublic) {
|
@@ -7633,11 +7851,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7633
7851
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7634
7852
|
}
|
7635
7853
|
function isPublicExtendedKey(extendedKey) {
|
7636
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7854
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
7637
7855
|
}
|
7638
7856
|
function isValidExtendedKey(extendedKey) {
|
7639
7857
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7640
|
-
(0,
|
7858
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
7641
7859
|
);
|
7642
7860
|
}
|
7643
7861
|
function parsePath(path2, depth = 0) {
|
@@ -7655,8 +7873,8 @@ function parsePath(path2, depth = 0) {
|
|
7655
7873
|
var HDWallet = class {
|
7656
7874
|
depth = 0;
|
7657
7875
|
index = 0;
|
7658
|
-
fingerprint = (0,
|
7659
|
-
parentFingerprint = (0,
|
7876
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7877
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7660
7878
|
privateKey;
|
7661
7879
|
publicKey;
|
7662
7880
|
chainCode;
|
@@ -7668,8 +7886,8 @@ var HDWallet = class {
|
|
7668
7886
|
constructor(config) {
|
7669
7887
|
if (config.privateKey) {
|
7670
7888
|
const signer = new Signer(config.privateKey);
|
7671
|
-
this.publicKey = (0,
|
7672
|
-
this.privateKey = (0,
|
7889
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
7890
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
7673
7891
|
} else {
|
7674
7892
|
if (!config.publicKey) {
|
7675
7893
|
throw new import_errors20.FuelError(
|
@@ -7677,7 +7895,7 @@ var HDWallet = class {
|
|
7677
7895
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7678
7896
|
);
|
7679
7897
|
}
|
7680
|
-
this.publicKey = (0,
|
7898
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
7681
7899
|
}
|
7682
7900
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7683
7901
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7696,9 +7914,9 @@ var HDWallet = class {
|
|
7696
7914
|
* @returns A new instance of HDWallet on the derived index
|
7697
7915
|
*/
|
7698
7916
|
deriveIndex(index) {
|
7699
|
-
const privateKey = this.privateKey && (0,
|
7700
|
-
const publicKey = (0,
|
7701
|
-
const chainCode = (0,
|
7917
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
7918
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
7919
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
7702
7920
|
const data = new Uint8Array(37);
|
7703
7921
|
if (index & HARDENED_INDEX) {
|
7704
7922
|
if (!privateKey) {
|
@@ -7709,15 +7927,15 @@ var HDWallet = class {
|
|
7709
7927
|
}
|
7710
7928
|
data.set(privateKey, 1);
|
7711
7929
|
} else {
|
7712
|
-
data.set((0,
|
7930
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
7713
7931
|
}
|
7714
|
-
data.set((0,
|
7715
|
-
const bytes = (0,
|
7932
|
+
data.set((0, import_math21.toBytes)(index, 4), 33);
|
7933
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7716
7934
|
const IL = bytes.slice(0, 32);
|
7717
7935
|
const IR = bytes.slice(32);
|
7718
7936
|
if (privateKey) {
|
7719
7937
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7720
|
-
const ki = (0,
|
7938
|
+
const ki = (0, import_math21.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7721
7939
|
return new HDWallet({
|
7722
7940
|
privateKey: ki,
|
7723
7941
|
chainCode: IR,
|
@@ -7726,7 +7944,7 @@ var HDWallet = class {
|
|
7726
7944
|
parentFingerprint: this.fingerprint
|
7727
7945
|
});
|
7728
7946
|
}
|
7729
|
-
const signer = new Signer((0,
|
7947
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
7730
7948
|
const Ki = signer.addPoint(publicKey);
|
7731
7949
|
return new HDWallet({
|
7732
7950
|
publicKey: Ki,
|
@@ -7761,12 +7979,12 @@ var HDWallet = class {
|
|
7761
7979
|
);
|
7762
7980
|
}
|
7763
7981
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7764
|
-
const depth = (0,
|
7982
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
7765
7983
|
const parentFingerprint = this.parentFingerprint;
|
7766
|
-
const index = (0,
|
7984
|
+
const index = (0, import_math21.toHex)(this.index, 4);
|
7767
7985
|
const chainCode = this.chainCode;
|
7768
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7769
|
-
const extendedKey = (0,
|
7986
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7987
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7770
7988
|
return base58check(extendedKey);
|
7771
7989
|
}
|
7772
7990
|
/**
|
@@ -7778,13 +7996,13 @@ var HDWallet = class {
|
|
7778
7996
|
static fromSeed(seed) {
|
7779
7997
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7780
7998
|
return new HDWallet({
|
7781
|
-
chainCode: (0,
|
7782
|
-
privateKey: (0,
|
7999
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
8000
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
7783
8001
|
});
|
7784
8002
|
}
|
7785
8003
|
static fromExtendedKey(extendedKey) {
|
7786
8004
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
7787
|
-
const bytes = (0,
|
8005
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
7788
8006
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7789
8007
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7790
8008
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
@@ -7793,9 +8011,9 @@ var HDWallet = class {
|
|
7793
8011
|
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7794
8012
|
}
|
7795
8013
|
const depth = bytes[4];
|
7796
|
-
const parentFingerprint = (0,
|
7797
|
-
const index = parseInt((0,
|
7798
|
-
const chainCode = (0,
|
8014
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8015
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8016
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
7799
8017
|
const key = bytes.slice(45, 78);
|
7800
8018
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7801
8019
|
throw new import_errors20.FuelError(
|
@@ -7988,14 +8206,15 @@ var seedTestWallet = async (wallet, quantities) => {
|
|
7988
8206
|
process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
|
7989
8207
|
wallet.provider
|
7990
8208
|
);
|
7991
|
-
const
|
7992
|
-
|
7993
|
-
|
7994
|
-
|
7995
|
-
gasPrice: minGasPrice
|
8209
|
+
const request = new ScriptTransactionRequest();
|
8210
|
+
quantities.forEach((quantity) => {
|
8211
|
+
const { amount, assetId } = coinQuantityfy(quantity);
|
8212
|
+
request.addCoinOutput(wallet.address, amount, assetId);
|
7996
8213
|
});
|
7997
|
-
|
7998
|
-
|
8214
|
+
const txCost = await genesisWallet.provider.getTransactionCost(request);
|
8215
|
+
request.gasLimit = txCost.gasUsed;
|
8216
|
+
request.maxFee = txCost.maxFee;
|
8217
|
+
await genesisWallet.fund(request, txCost);
|
7999
8218
|
await genesisWallet.sendTransaction(request, { awaitExecution: true });
|
8000
8219
|
};
|
8001
8220
|
|
@@ -8010,11 +8229,11 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8010
8229
|
|
8011
8230
|
// src/test-utils/launchNode.ts
|
8012
8231
|
var import_configs13 = require("@fuel-ts/address/configs");
|
8013
|
-
var
|
8014
|
-
var import_utils36 = require("@fuel-ts/utils");
|
8232
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8015
8233
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
8016
8234
|
var import_child_process = require("child_process");
|
8017
8235
|
var import_crypto6 = require("crypto");
|
8236
|
+
var import_ethers4 = require("ethers");
|
8018
8237
|
var import_fs = require("fs");
|
8019
8238
|
var import_os = __toESM(require("os"));
|
8020
8239
|
var import_path = __toESM(require("path"));
|
@@ -8063,13 +8282,13 @@ var launchNode = async ({
|
|
8063
8282
|
// eslint-disable-next-line no-async-promise-executor
|
8064
8283
|
new Promise(async (resolve, reject) => {
|
8065
8284
|
const remainingArgs = extractRemainingArgs(args, [
|
8066
|
-
"--
|
8285
|
+
"--snapshot",
|
8067
8286
|
"--consensus-key",
|
8068
8287
|
"--db-type",
|
8069
8288
|
"--poa-instant"
|
8070
8289
|
]);
|
8071
|
-
const chainConfigPath = getFlagValueFromArgs(args, "--
|
8072
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8290
|
+
const chainConfigPath = getFlagValueFromArgs(args, "--snapshot");
|
8291
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils35.defaultConsensusKey;
|
8073
8292
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
8074
8293
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
8075
8294
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8087,36 +8306,54 @@ var launchNode = async ({
|
|
8087
8306
|
let chainConfigPathToUse;
|
8088
8307
|
const prefix = basePath || import_os.default.tmpdir();
|
8089
8308
|
const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
|
8090
|
-
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
8309
|
+
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "chainConfigs");
|
8091
8310
|
if (chainConfigPath) {
|
8092
8311
|
chainConfigPathToUse = chainConfigPath;
|
8093
8312
|
} else {
|
8094
8313
|
if (!(0, import_fs.existsSync)(tempDirPath)) {
|
8095
8314
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8096
8315
|
}
|
8097
|
-
|
8098
|
-
|
8316
|
+
let { stateConfigJson } = import_utils35.defaultChainConfigs;
|
8317
|
+
const { chainConfigJson, metadataJson } = import_utils35.defaultChainConfigs;
|
8318
|
+
stateConfigJson = {
|
8319
|
+
...stateConfigJson,
|
8320
|
+
coins: [
|
8321
|
+
...stateConfigJson.coins.map((coin) => ({
|
8322
|
+
...coin,
|
8323
|
+
amount: "18446744073709551615"
|
8324
|
+
}))
|
8325
|
+
],
|
8326
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8327
|
+
...message,
|
8328
|
+
amount: "18446744073709551615"
|
8329
|
+
}))
|
8330
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8331
|
+
};
|
8099
8332
|
if (!process.env.GENESIS_SECRET) {
|
8100
8333
|
const pk = Signer.generatePrivateKey();
|
8101
8334
|
const signer = new Signer(pk);
|
8102
|
-
process.env.GENESIS_SECRET = (0,
|
8103
|
-
|
8104
|
-
|
8105
|
-
|
8106
|
-
|
8107
|
-
|
8108
|
-
|
8109
|
-
|
8110
|
-
|
8111
|
-
|
8112
|
-
|
8113
|
-
}
|
8114
|
-
]
|
8115
|
-
}
|
8116
|
-
};
|
8335
|
+
process.env.GENESIS_SECRET = (0, import_utils35.hexlify)(pk);
|
8336
|
+
stateConfigJson.coins.push({
|
8337
|
+
tx_id: (0, import_utils35.hexlify)((0, import_ethers4.randomBytes)(34)),
|
8338
|
+
owner: signer.address.toHexString(),
|
8339
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8340
|
+
amount: "18446744073709551615",
|
8341
|
+
asset_id: import_configs13.BaseAssetId,
|
8342
|
+
output_index: 0,
|
8343
|
+
tx_pointer_block_height: 0,
|
8344
|
+
tx_pointer_tx_idx: 0
|
8345
|
+
});
|
8117
8346
|
}
|
8118
|
-
|
8119
|
-
|
8347
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8348
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8349
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8350
|
+
const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8351
|
+
const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
|
8352
|
+
const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
|
8353
|
+
(0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8354
|
+
(0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8355
|
+
(0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8356
|
+
chainConfigPathToUse = tempDirPath;
|
8120
8357
|
}
|
8121
8358
|
const child = (0, import_child_process.spawn)(
|
8122
8359
|
command,
|
@@ -8125,10 +8362,10 @@ var launchNode = async ({
|
|
8125
8362
|
["--ip", ipToUse],
|
8126
8363
|
["--port", portToUse],
|
8127
8364
|
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8128
|
-
["--min-gas-price", "
|
8365
|
+
["--min-gas-price", "1"],
|
8129
8366
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8130
8367
|
["--consensus-key", consensusKey],
|
8131
|
-
["--
|
8368
|
+
["--snapshot", chainConfigPathToUse],
|
8132
8369
|
"--vm-backtrace",
|
8133
8370
|
"--utxo-validation",
|
8134
8371
|
"--debug",
|
@@ -8187,7 +8424,7 @@ var launchNodeAndGetWallets = async ({
|
|
8187
8424
|
walletCount = 10
|
8188
8425
|
} = {}) => {
|
8189
8426
|
const { cleanup: closeNode, ip, port } = await launchNode(launchNodeOptions || {});
|
8190
|
-
const provider = await Provider.create(`http://${ip}:${port}/graphql`);
|
8427
|
+
const provider = await Provider.create(`http://${ip}:${port}/v1/graphql`);
|
8191
8428
|
const wallets = await generateWallets(walletCount, provider);
|
8192
8429
|
const cleanup = () => {
|
8193
8430
|
closeNode();
|